0671ddb9150b23b61e0079828839a46ffa8039fe
[vlc.git] / modules / gui / wxwindows / open.cpp
1 /*****************************************************************************
2  * open.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2001 VideoLAN
5  * $Id: open.cpp,v 1.34 2003/07/26 12:41:52 gbazin Exp $
6  *
7  * Authors: Gildas Bazin <gbazin@netcourrier.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <string.h>                                            /* strerror() */
30 #include <stdio.h>
31
32 #include <vlc/vlc.h>
33
34 #ifdef WIN32                                                 /* mingw32 hack */
35 #undef Yield
36 #undef CreateDialog
37 #endif
38
39 /* Let vlc take care of the i18n stuff */
40 #define WXINTL_NO_GETTEXT_MACRO
41
42 #include <wx/wxprec.h>
43 #include <wx/wx.h>
44 #include <wx/notebook.h>
45 #include <wx/textctrl.h>
46 #include <wx/combobox.h>
47 #include <wx/spinctrl.h>
48 #include <wx/statline.h>
49 #include <wx/tokenzr.h>
50
51 #include <vlc/intf.h>
52
53 #include "wxwindows.h"
54
55 #ifndef wxRB_SINGLE
56 #   define wxRB_SINGLE 0
57 #endif
58
59 /*****************************************************************************
60  * Event Table.
61  *****************************************************************************/
62
63 /* IDs for the controls and the menu commands */
64 enum
65 {
66     Notebook_Event = wxID_HIGHEST,
67     MRL_Event,
68
69     FileBrowse_Event,
70     FileName_Event,
71
72     DiscType_Event,
73     DiscDevice_Event,
74     DiscTitle_Event,
75     DiscChapter_Event,
76
77     NetType_Event,
78     NetRadio1_Event, NetRadio2_Event, NetRadio3_Event,
79     NetPort1_Event, NetPort2_Event, NetPort3_Event,
80     NetAddr1_Event, NetAddr2_Event, NetAddr3_Event,
81
82     SubsFileEnable_Event,
83     SubsFileSettings_Event,
84
85     SoutEnable_Event,
86     SoutSettings_Event,
87
88     DemuxDump_Event,
89     DemuxDumpEnable_Event,
90     DemuxDumpBrowse_Event,
91 };
92
93 BEGIN_EVENT_TABLE(OpenDialog, wxFrame)
94     /* Button events */
95     EVT_BUTTON(wxID_OK, OpenDialog::OnOk)
96     EVT_BUTTON(wxID_CANCEL, OpenDialog::OnCancel)
97
98     EVT_NOTEBOOK_PAGE_CHANGED(Notebook_Event, OpenDialog::OnPageChange)
99
100     EVT_TEXT(MRL_Event, OpenDialog::OnMRLChange) 
101
102     /* Events generated by the file panel */
103     EVT_TEXT(FileName_Event, OpenDialog::OnFilePanelChange)
104     EVT_BUTTON(FileBrowse_Event, OpenDialog::OnFileBrowse)
105
106     /* Events generated by the disc panel */
107     EVT_RADIOBOX(DiscType_Event, OpenDialog::OnDiscTypeChange)
108     EVT_TEXT(DiscDevice_Event, OpenDialog::OnDiscPanelChange)
109     EVT_TEXT(DiscTitle_Event, OpenDialog::OnDiscPanelChange)
110     EVT_SPINCTRL(DiscTitle_Event, OpenDialog::OnDiscPanelChange)
111     EVT_TEXT(DiscChapter_Event, OpenDialog::OnDiscPanelChange)
112     EVT_SPINCTRL(DiscChapter_Event, OpenDialog::OnDiscPanelChange)
113
114     /* Events generated by the net panel */
115     EVT_RADIOBUTTON(NetRadio1_Event, OpenDialog::OnNetTypeChange)
116     EVT_RADIOBUTTON(NetRadio2_Event, OpenDialog::OnNetTypeChange)
117     EVT_RADIOBUTTON(NetRadio3_Event, OpenDialog::OnNetTypeChange)
118     EVT_TEXT(NetPort1_Event, OpenDialog::OnNetPanelChange)
119     EVT_SPINCTRL(NetPort1_Event, OpenDialog::OnNetPanelChange)
120     EVT_TEXT(NetPort2_Event, OpenDialog::OnNetPanelChange)
121     EVT_SPINCTRL(NetPort2_Event, OpenDialog::OnNetPanelChange)
122     EVT_TEXT(NetPort3_Event, OpenDialog::OnNetPanelChange)
123     EVT_SPINCTRL(NetPort3_Event, OpenDialog::OnNetPanelChange)
124     EVT_TEXT(NetAddr2_Event, OpenDialog::OnNetPanelChange)
125     EVT_TEXT(NetAddr3_Event, OpenDialog::OnNetPanelChange)
126
127     /* Events generated by the subtitle file buttons */
128     EVT_CHECKBOX(SubsFileEnable_Event, OpenDialog::OnSubsFileEnable)
129     EVT_BUTTON(SubsFileSettings_Event, OpenDialog::OnSubsFileSettings)
130
131     /* Events generated by the stream output buttons */
132     EVT_CHECKBOX(SoutEnable_Event, OpenDialog::OnSoutEnable)
133     EVT_BUTTON(SoutSettings_Event, OpenDialog::OnSoutSettings)
134
135     /* Events generated by the demux dump buttons */
136     EVT_CHECKBOX(DemuxDumpEnable_Event, OpenDialog::OnDemuxDumpEnable)
137     EVT_TEXT(DemuxDump_Event, OpenDialog::OnDemuxDumpChange)
138     EVT_BUTTON(DemuxDumpBrowse_Event, OpenDialog::OnDemuxDumpBrowse)
139
140     /* Hide the window when the user closes the window */
141     EVT_CLOSE(OpenDialog::OnCancel)
142
143 END_EVENT_TABLE()
144
145 /*****************************************************************************
146  * Constructor.
147  *****************************************************************************/
148 OpenDialog::OpenDialog( intf_thread_t *_p_intf, wxWindow *_p_parent,
149                         int i_access_method, int i_arg ):
150     wxFrame( _p_parent, -1, wxU(_("Open Target")), wxDefaultPosition,
151              wxDefaultSize, wxDEFAULT_FRAME_STYLE )
152 {
153     /* Initializations */
154     p_intf = _p_intf;
155     p_parent = _p_parent;
156     SetIcon( *p_intf->p_sys->p_icon );
157     file_dialog = NULL;
158     sout_dialog = NULL;
159     subsfile_dialog = NULL;
160     demuxdump_dialog = NULL;
161
162     /* Create a panel to put everything in */
163     wxPanel *panel = new wxPanel( this, -1 );
164     panel->SetAutoLayout( TRUE );
165
166     /* Create MRL combobox */
167     wxBoxSizer *mrl_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
168     wxStaticBox *mrl_box = new wxStaticBox( panel, -1,
169                                wxU(_("Media Resource Locator (MRL)")) );
170     wxStaticBoxSizer *mrl_sizer = new wxStaticBoxSizer( mrl_box,
171                                                         wxHORIZONTAL );
172     wxStaticText *mrl_label = new wxStaticText( panel, -1,
173                                                 wxU(_("Open Target:")) );
174     mrl_combo = new wxComboBox( panel, MRL_Event, wxT(""),
175                                 wxPoint(20,25), wxSize(120, -1),
176                                 0, NULL );
177     mrl_combo->SetToolTip( wxU(_("You can use this field directly by typing "
178         "the full MRL you want to open.\n""Alternatively, the field will be "
179         "filled automatically when you use the controls below.")) );
180
181     mrl_sizer->Add( mrl_label, 0, wxALL | wxALIGN_CENTER, 5 );
182     mrl_sizer->Add( mrl_combo, 1, wxALL | wxALIGN_CENTER, 5 );
183     mrl_sizer_sizer->Add( mrl_sizer, 1, wxEXPAND | wxALL, 5 );
184
185
186     /* Create Static Text */
187     wxStaticText *label = new wxStaticText( panel, -1,
188         wxU(_("Alternatively, you can build an MRL using one of the "
189               "following predefined targets:")) );
190
191     /* Create Subtitles File checkox */
192     wxFlexGridSizer *subsfile_sizer = new wxFlexGridSizer( 2, 1, 20 );
193     subsfile_checkbox = new wxCheckBox( panel, SubsFileEnable_Event,
194                                         wxU(_("Subtitles file")) );
195     subsfile_checkbox->SetToolTip( wxU(_("Load an additional subtitles file. "
196                                    "Currently only works with AVI files.")) );
197     subsfile_sizer->Add( subsfile_checkbox, 0,
198                          wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
199     subsfile_button = new wxButton( panel, SubsFileSettings_Event,
200                                     wxU(_("Settings...")) );
201     subsfile_button->Disable();
202
203     char *psz_subsfile = config_GetPsz( p_intf, "sub-file" );
204     if( psz_subsfile && *psz_subsfile )
205     {
206         subsfile_checkbox->SetValue(TRUE);
207         subsfile_button->Enable();
208         subsfile_mrl.Add( wxString(wxT("sub-file=")) + wxU(psz_subsfile) );
209     }
210     if( psz_subsfile ) free( psz_subsfile );
211
212     subsfile_sizer->Add( subsfile_button, 1,
213                          wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
214
215     /* Create Stream Output checkox */
216     wxFlexGridSizer *sout_sizer = new wxFlexGridSizer( 2, 1, 20 );
217     sout_checkbox = new wxCheckBox( panel, SoutEnable_Event,
218                                     wxU(_("Stream output")) );
219     sout_checkbox->SetToolTip( wxU(_("Use VLC as a stream server")) );
220     sout_sizer->Add( sout_checkbox, 0,
221                      wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
222     sout_button = new wxButton( panel, SoutSettings_Event,
223                                 wxU(_("Settings...")) );
224     sout_button->Disable();
225
226     char *psz_sout = config_GetPsz( p_intf, "sout" );
227     if( psz_sout && *psz_sout )
228     {
229         sout_checkbox->SetValue(TRUE);
230         sout_button->Enable();
231         subsfile_mrl.Add( wxString(wxT("sout=")) + wxU(psz_sout) );
232     }
233     if( psz_sout ) free( psz_sout );
234
235     sout_sizer->Add( sout_button, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
236
237     /* Create Demux Dump checkox */
238     wxBoxSizer *demuxdump_sizer = new wxBoxSizer( wxHORIZONTAL );
239     demuxdump_checkbox = new wxCheckBox( panel, DemuxDumpEnable_Event,
240                                wxU(_("Capture input stream")) );
241     demuxdump_checkbox->SetToolTip(
242         wxU(_("Capture the stream you are playing to a file")) );
243     demuxdump_textctrl = new wxTextCtrl( panel, DemuxDump_Event, wxT(""),
244                                          wxDefaultPosition, wxDefaultSize,
245                                          wxTE_PROCESS_ENTER);
246     demuxdump_button = new wxButton( panel, DemuxDumpBrowse_Event,
247                                      wxU(_("Browse...")) );
248
249     char *psz_demuxdump = config_GetPsz( p_intf, "demuxdump-file" );
250     if( psz_demuxdump && *psz_demuxdump )
251     {
252         demuxdump_textctrl->SetValue( wxU(psz_demuxdump) );
253     }
254     if( psz_demuxdump ) free( psz_demuxdump );
255
256     demuxdump_textctrl->Disable();
257     demuxdump_button->Disable();
258     demuxdump_sizer->Add( demuxdump_checkbox, 0,
259                           wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
260     demuxdump_sizer->Add( demuxdump_button, 0,
261                           wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, 10 );
262     demuxdump_sizer->Add( demuxdump_textctrl, 1, wxRIGHT, 10 );
263
264     /* Separation */
265     wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
266
267     /* Create the buttons */
268     wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
269     ok_button->SetDefault();
270     wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
271                                             wxU(_("Cancel")) );
272
273     /* Create notebook */
274     notebook = new wxNotebook( panel, Notebook_Event );
275     wxNotebookSizer *notebook_sizer = new wxNotebookSizer( notebook );
276
277     notebook->AddPage( FilePanel( notebook ), wxU(_("File")),
278                        i_access_method == FILE_ACCESS );
279     notebook->AddPage( DiscPanel( notebook ), wxU(_("Disc")),
280                        i_access_method == DISC_ACCESS );
281     notebook->AddPage( NetPanel( notebook ), wxU(_("Network")),
282                        i_access_method == NET_ACCESS );
283 #ifndef WIN32
284     notebook->AddPage( SatPanel( notebook ), wxU(_("Satellite")),
285                        i_access_method == SAT_ACCESS );
286 #endif
287
288     /* Update Disc panel */
289     wxCommandEvent dummy_event;
290     OnDiscTypeChange( dummy_event );
291
292     /* Update Net panel */
293     dummy_event.SetId( NetRadio1_Event );
294     OnNetTypeChange( dummy_event );
295
296     /* Update MRL */
297     wxNotebookEvent event( wxEVT_NULL, 0, i_access_method );
298     OnPageChange( event );
299
300     /* Place everything in sizers */
301     wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
302     button_sizer->Add( ok_button, 0, wxALL, 5 );
303     button_sizer->Add( cancel_button, 0, wxALL, 5 );
304     button_sizer->Layout();
305     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
306     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
307     panel_sizer->Add( mrl_sizer_sizer, 0, wxEXPAND, 5 );
308     panel_sizer->Add( label, 0, wxEXPAND | wxALL, 5 );
309     panel_sizer->Add( notebook_sizer, 1, wxEXPAND | wxALL, 5 );
310     panel_sizer->Add( subsfile_sizer, 0, wxALIGN_LEFT | wxALL, 5 );
311     panel_sizer->Add( sout_sizer, 0, wxALIGN_LEFT | wxALL, 5 );
312     panel_sizer->Add( demuxdump_sizer, 0, wxEXPAND | wxALIGN_LEFT | wxALL, 5 );
313     panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
314     panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALL, 5 );
315     panel_sizer->Layout();
316     panel->SetSizerAndFit( panel_sizer );
317     main_sizer->Add( panel, 1, wxGROW, 0 );
318     main_sizer->Layout();
319     SetSizerAndFit( main_sizer );
320 }
321
322 OpenDialog::~OpenDialog()
323 {
324     /* Clean up */
325     if( file_dialog ) delete file_dialog;
326     if( sout_dialog ) delete sout_dialog;
327     if( subsfile_dialog ) delete subsfile_dialog;
328     if( demuxdump_dialog ) delete demuxdump_dialog;
329 }
330
331 int OpenDialog::Show( int i_access_method, int i_arg )
332 {
333     int i_ret;
334     notebook->SetSelection( i_access_method );
335     i_ret = wxFrame::Show();
336     Raise();
337     SetFocus();
338     return i_ret;
339 }
340
341 int OpenDialog::Show()
342 {
343     int i_ret;
344     i_ret = wxFrame::Show();
345     Raise();
346     SetFocus();
347     return i_ret;
348 }
349
350 /*****************************************************************************
351  * Private methods.
352  *****************************************************************************/
353 wxPanel *OpenDialog::FilePanel( wxWindow* parent )
354 {
355     wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
356                                   wxSize(200, 200) );
357
358     wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
359
360     file_combo = new wxComboBox( panel, FileName_Event, wxT(""),
361                                  wxPoint(20,25), wxSize(200, -1), 0, NULL );
362     wxButton *browse_button = new wxButton( panel, FileBrowse_Event,
363                                             wxU(_("Browse...")) );
364     sizer->Add( file_combo, 1, wxALL, 5 );
365     sizer->Add( browse_button, 0, wxALL, 5 );
366
367     panel->SetSizerAndFit( sizer );
368     return panel;
369 }
370
371 wxPanel *OpenDialog::DiscPanel( wxWindow* parent )
372 {
373     wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
374                                   wxSize(200, 200) );
375
376     wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
377     wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 3, 20 );
378
379     static const wxString disc_type_array[] =
380     {
381         wxU(_("DVD (menus support)")),
382         wxU(_("DVD")),
383         wxU(_("VCD")),
384         wxU(_("CD Audio"))
385
386     };
387
388     disc_type = new wxRadioBox( panel, DiscType_Event, wxU(_("Disc type")),
389                                 wxDefaultPosition, wxDefaultSize,
390                                 WXSIZEOF(disc_type_array), disc_type_array,
391                                 WXSIZEOF(disc_type_array), wxRA_SPECIFY_COLS );
392     sizer_row->Add( disc_type, 0, wxEXPAND | wxALL, 5 );
393
394     wxStaticText *label = new wxStaticText( panel, -1, wxU(_("Device name")) );
395     disc_device = new wxTextCtrl( panel, DiscDevice_Event, wxT(""),
396                                   wxDefaultPosition, wxDefaultSize,
397                                   wxTE_PROCESS_ENTER);
398
399     sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
400     sizer->Add( disc_device, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
401
402     label = new wxStaticText( panel, -1, wxU(_("Title")) );
403     disc_title = new wxSpinCtrl( panel, DiscTitle_Event );
404
405     sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
406     sizer->Add( disc_title, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
407
408     label = new wxStaticText( panel, -1, wxU(_("Chapter")) );
409     disc_chapter = new wxSpinCtrl( panel, DiscChapter_Event );
410     sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
411     sizer->Add( disc_chapter, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
412     sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
413
414     panel->SetSizerAndFit( sizer_row );
415     return panel;
416 }
417
418 wxPanel *OpenDialog::NetPanel( wxWindow* parent )
419 {
420     int i;
421     wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
422                                   wxSize(200, 200) );
423
424     wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
425     wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 3, 20 );
426
427     static const wxString net_type_array[] =
428     {
429         wxU(_("UDP/RTP")),
430         wxU(_("UDP/RTP Multicast")),
431         wxU(_("HTTP/FTP/MMS"))
432     };
433
434     for( i=0; i<3; i++ )
435     {
436         net_radios[i] = new wxRadioButton( panel, NetRadio1_Event + i,
437                                            net_type_array[i],
438                                            wxDefaultPosition, wxDefaultSize,
439                                            wxRB_SINGLE );
440
441         net_subpanels[i] = new wxPanel( panel, -1,
442                                         wxDefaultPosition, wxDefaultSize );
443     }
444
445     /* UDP/RTP row */
446     wxFlexGridSizer *subpanel_sizer;
447     wxStaticText *label;
448     i_net_ports[0] = config_GetInt( p_intf, "server-port" );
449     subpanel_sizer = new wxFlexGridSizer( 2, 1, 20 );
450     label = new wxStaticText( net_subpanels[0], -1, wxU(_("Port")) );
451     net_ports[0] = new wxSpinCtrl( net_subpanels[0], NetPort1_Event,
452                                    wxString::Format(wxT("%d"), i_net_ports[0]),
453                                    wxDefaultPosition, wxDefaultSize,
454                                    wxSP_ARROW_KEYS,
455                                    0, 16000, i_net_ports[0] );
456
457     subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
458     subpanel_sizer->Add( net_ports[0], 1,
459                          wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
460     net_subpanels[0]->SetSizerAndFit( subpanel_sizer );
461     net_radios[0]->SetValue( TRUE );
462
463     /* UDP/RTP Multicast row */
464     subpanel_sizer = new wxFlexGridSizer( 4, 1, 20 );
465     label = new wxStaticText( net_subpanels[1], -1, wxU(_("Address")) );
466     net_addrs[1] = new wxTextCtrl( net_subpanels[1], NetAddr2_Event, wxT(""),
467                                    wxDefaultPosition, wxDefaultSize,
468                                    wxTE_PROCESS_ENTER);
469     subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
470     subpanel_sizer->Add( net_addrs[1], 1,
471                          wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
472
473     label = new wxStaticText( net_subpanels[1], -1, wxU(_("Port")) );
474     i_net_ports[1] = i_net_ports[0];
475     net_ports[1] = new wxSpinCtrl( net_subpanels[1], NetPort2_Event,
476                                    wxString::Format(wxT("%d"), i_net_ports[1]),
477                                    wxDefaultPosition, wxDefaultSize,
478                                    wxSP_ARROW_KEYS,
479                                    0, 16000, i_net_ports[1] );
480
481     subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
482     subpanel_sizer->Add( net_ports[1], 1,
483                          wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
484     net_subpanels[1]->SetSizerAndFit( subpanel_sizer );
485
486     /* HTTP row */
487     subpanel_sizer = new wxFlexGridSizer( 2, 1, 20 );
488     label = new wxStaticText( net_subpanels[2], -1, wxU(_("URL")) );
489     net_addrs[2] = new wxTextCtrl( net_subpanels[2], NetAddr3_Event, wxT(""),
490                                    wxDefaultPosition, wxSize( 200, -1 ),
491                                    wxTE_PROCESS_ENTER);
492     subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
493     subpanel_sizer->Add( net_addrs[2], 1,
494                          wxEXPAND | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
495     net_subpanels[2]->SetSizerAndFit( subpanel_sizer );
496
497     /* Stuff everything into the main panel */
498     for( i=0; i<3; i++ )
499     {
500         sizer->Add( net_radios[i], 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
501                     wxALL, 5 );
502         sizer->Add( net_subpanels[i], 1, wxEXPAND | wxALIGN_LEFT |
503                     wxALIGN_CENTER_VERTICAL | wxALL, 5  );
504     }
505
506     sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
507
508     panel->SetSizerAndFit( sizer_row );
509     return panel;
510 }
511
512 wxPanel *OpenDialog::SatPanel( wxWindow* parent )
513 {
514     wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
515                                   wxSize(200, 200) );
516     return panel;
517 }
518
519 void OpenDialog::UpdateMRL( int i_access_method )
520 {
521     wxString demux, mrltemp;
522
523     i_current_access_method = i_access_method;
524
525     /* Check if the user asked for demuxdump */
526     if( demuxdump_checkbox->GetValue() )
527     {
528         demux = wxT("/demuxdump");
529     }
530
531     switch( i_access_method )
532     {
533     case FILE_ACCESS:
534         //mrltemp = wxT("file") + demux + wxT(":") + file_combo->GetValue();
535         mrltemp = file_combo->GetValue();
536         break;
537     case DISC_ACCESS:
538         mrltemp = ( disc_type->GetSelection() == 0 ? wxT("dvd") :
539                 disc_type->GetSelection() == 1 ? wxT("dvdsimple") :
540                 disc_type->GetSelection() == 2 ? wxT("vcd") : wxT("cdda") )
541                   + demux + wxT(":")
542                   + disc_device->GetLineText(0)
543                   + wxString::Format( wxT("@%d:%d"),
544                                       i_disc_title, i_disc_chapter );
545         break;
546     case NET_ACCESS:
547         switch( i_net_type )
548         {
549         case 0:
550             if( i_net_ports[0] !=
551                 config_GetInt( p_intf, "server-port" ) )
552             {
553                 mrltemp = wxT("udp") + demux +
554                           wxString::Format( wxT("://@:%d"),
555                                             i_net_ports[0] );
556             }
557             else
558             {
559                 mrltemp = wxT("udp") + demux + wxT("://");
560             }
561             break;
562
563         case 1:
564             mrltemp = wxT("udp") + demux + wxT("://@") +
565                       net_addrs[1]->GetLineText(0);
566             if( i_net_ports[1] !=
567                 config_GetInt( p_intf, "server-port" ) )
568             {
569                 mrltemp = mrltemp + wxString::Format( wxT(":%d"),
570                                               i_net_ports[1] );
571             }
572             break;
573
574         case 2:
575             /* http access */     
576             mrltemp = wxT("http") + demux + wxT("://") +
577                       net_addrs[2]->GetLineText(0);
578             break;
579         }
580         break;
581     case SAT_ACCESS:
582         mrltemp = wxT("satellite") + demux + wxT("://");
583         break;
584     default:
585         break;
586     }
587
588     mrl_combo->SetValue( mrltemp );
589 }
590
591 /*****************************************************************************
592  * Events methods.
593  *****************************************************************************/
594 void OpenDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
595 {
596     mrl = SeparateEntries( mrl_combo->GetValue() );
597     mrl_combo->Append( mrl_combo->GetValue() );
598     if( mrl_combo->GetCount() > 10 ) mrl_combo->Delete( 0 );
599     mrl_combo->SetSelection( mrl_combo->GetCount() - 1 );
600
601     /* Update the playlist */
602     playlist_t *p_playlist =
603         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
604                                        FIND_ANYWHERE );
605     if( p_playlist == NULL ) return;
606
607     for( int i = 0; i < (int)mrl.GetCount(); i++ )
608     {
609         int i_options = 0, i_total_options;
610         char **ppsz_options = NULL;
611
612         /* Count the input options */
613         while( i + i_options + 1 < (int)mrl.GetCount() &&
614                ((const char *)mrl[i + i_options + 1].mb_str())[0] == ':' )
615         {
616             i_options++;
617         }
618
619         /* Allocate ppsz_options */
620         for( int j = 0; j < i_options; j++ )
621         {
622             if( !ppsz_options )
623                 ppsz_options = (char **)malloc( sizeof(char *) * i_options );
624
625             ppsz_options[j] = strdup( mrl[i + j  + 1].mb_str() );
626         }
627
628         i_total_options = i_options;
629
630         /* Get the options from the subtitles dialog */
631         if( subsfile_checkbox->IsChecked() && subsfile_mrl.GetCount() )
632         {
633             ppsz_options = (char **)realloc( ppsz_options, sizeof(char *) *
634                                (i_total_options + subsfile_mrl.GetCount()) );
635
636             for( int j = 0; j < (int)subsfile_mrl.GetCount(); j++ )
637             {
638                 ppsz_options[i_total_options + j] =
639                     strdup( subsfile_mrl[j].mb_str() );
640             }
641
642             i_total_options += subsfile_mrl.GetCount();
643         }
644
645         /* Get the options from the stream output dialog */
646         if( sout_checkbox->IsChecked() && sout_mrl.GetCount() )
647         {
648             ppsz_options = (char **)realloc( ppsz_options, sizeof(char *) *
649                                (i_total_options + sout_mrl.GetCount()) );
650
651             for( int j = 0; j < (int)sout_mrl.GetCount(); j++ )
652             {
653                 ppsz_options[i_total_options + j] =
654                     strdup( sout_mrl[j].mb_str() );
655             }
656
657             i_total_options += sout_mrl.GetCount();
658         }
659
660         playlist_Add( p_playlist, (const char *)mrl[i].mb_str(),
661                       (const char **)ppsz_options, i_total_options,
662                       PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );
663
664         /* clean up */
665         for( int j = 0; j < i_total_options; j++ )
666             free( ppsz_options[j] );
667         if( ppsz_options ) free( ppsz_options );
668
669         i += i_options;
670    }
671
672     //TogglePlayButton( PLAYING_S );
673
674     vlc_object_release( p_playlist );
675
676     Hide();
677 }
678
679 void OpenDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
680 {
681     Hide();
682 }
683
684 void OpenDialog::OnPageChange( wxNotebookEvent& event )
685 {
686     UpdateMRL( event.GetSelection() );
687 }
688
689 void OpenDialog::OnMRLChange( wxCommandEvent& event )
690 {
691     //mrl = SeparateEntries( event.GetString() );
692 }
693
694 /*****************************************************************************
695  * File panel event methods.
696  *****************************************************************************/
697 void OpenDialog::OnFilePanelChange( wxCommandEvent& WXUNUSED(event) )
698 {
699     UpdateMRL( FILE_ACCESS );
700 }
701
702 void OpenDialog::OnFileBrowse( wxCommandEvent& WXUNUSED(event) )
703 {
704     if( file_dialog == NULL )
705         file_dialog = new wxFileDialog( this, wxU(_("Open file")),
706             wxT(""), wxT(""), wxT("*"), wxOPEN | wxMULTIPLE );
707
708     if( file_dialog && file_dialog->ShowModal() == wxID_OK )
709     {
710         wxArrayString paths;
711         wxString path;
712
713         file_dialog->GetPaths( paths );
714
715         for( size_t i = 0; i < paths.GetCount(); i++ )
716         {
717             if( paths[i].Find( wxT(' ') ) >= 0 )
718                 path += wxT("\"") + paths[i] + wxT("\" ");
719             else
720                 path += paths[i] + wxT(" ");
721         }
722
723         file_combo->SetValue( path );
724         file_combo->Append( path );
725         if( file_combo->GetCount() > 10 ) file_combo->Delete( 0 );
726         UpdateMRL( FILE_ACCESS );
727     }
728 }
729
730 /*****************************************************************************
731  * Disc panel event methods.
732  *****************************************************************************/
733 void OpenDialog::OnDiscPanelChange( wxCommandEvent& event )
734 {
735     if( event.GetId() == DiscTitle_Event )
736         i_disc_title = event.GetInt();
737     else if( event.GetId() == DiscChapter_Event )
738         i_disc_chapter = event.GetInt();
739
740     UpdateMRL( DISC_ACCESS );
741 }
742
743 void OpenDialog::OnDiscTypeChange( wxCommandEvent& WXUNUSED(event) )
744 {
745     char *psz_device;
746
747     switch( disc_type->GetSelection() )
748     {
749     case 2:
750         psz_device = config_GetPsz( p_intf, "vcd" );
751         disc_device->SetValue( psz_device ? wxU(psz_device) : wxT("") );
752         break;
753
754     default:
755         psz_device = config_GetPsz( p_intf, "dvd" );
756         disc_device->SetValue( psz_device ? wxU(psz_device) : wxT("") );
757         break;
758     }
759
760     if( psz_device ) free( psz_device );
761
762     switch( disc_type->GetSelection() )
763     {
764     case 0:
765         disc_title->SetRange( 0, 255 );
766         disc_title->SetValue( 0 );
767         i_disc_title = 0;
768         break;
769
770     default:
771         disc_title->SetRange( 1, 255 );
772         disc_title->SetValue( 1 );
773         i_disc_title = 1;
774         break;
775     }
776
777     i_disc_chapter = 1;
778     disc_chapter->SetRange( 1, 255 );
779     disc_chapter->SetValue( 1 );
780
781     UpdateMRL( DISC_ACCESS );
782 }
783
784 /*****************************************************************************
785  * Net panel event methods.
786  *****************************************************************************/
787 void OpenDialog::OnNetPanelChange( wxCommandEvent& event )
788 {
789     if( event.GetId() >= NetPort1_Event && event.GetId() <= NetPort3_Event )
790     {
791         i_net_ports[event.GetId() - NetPort1_Event] = event.GetInt();
792     }
793
794     UpdateMRL( NET_ACCESS );
795 }
796
797 void OpenDialog::OnNetTypeChange( wxCommandEvent& event )
798 {
799     int i;
800
801     i_net_type = event.GetId() - NetRadio1_Event;
802
803     for(i=0; i<3; i++)
804     {
805         net_radios[i]->SetValue( event.GetId() == (NetRadio1_Event+i) );
806         net_subpanels[i]->Enable( event.GetId() == (NetRadio1_Event+i) );
807     }
808
809     UpdateMRL( NET_ACCESS );
810 }
811
812 /*****************************************************************************
813  * Subtitles file event methods.
814  *****************************************************************************/
815 void OpenDialog::OnSubsFileEnable( wxCommandEvent& event )
816 {
817     subsfile_button->Enable( event.GetInt() != 0 );
818     if( event.GetInt() && demuxdump_checkbox->IsChecked() )
819     {
820         demuxdump_checkbox->SetValue( 0 );
821         wxCommandEvent event = wxCommandEvent( wxEVT_NULL );
822         event.SetInt( 0 );
823         OnDemuxDumpEnable( event );
824     }
825 }
826
827 void OpenDialog::OnSubsFileSettings( wxCommandEvent& WXUNUSED(event) )
828 {
829     /* Show/hide the open dialog */
830     if( subsfile_dialog == NULL )
831         subsfile_dialog = new SubsFileDialog( p_intf, this );
832
833     if( subsfile_dialog && subsfile_dialog->ShowModal() == wxID_OK )
834     {
835         subsfile_mrl.Empty();
836         subsfile_mrl.Add( wxString(wxT("sub-file=")) +
837                           subsfile_dialog->file_combo->GetValue() );
838         subsfile_mrl.Add( wxString::Format( wxT("sub-delay=%i"),
839                           subsfile_dialog->delay_spinctrl->GetValue() ) );
840         subsfile_mrl.Add( wxString::Format( wxT("sub-fps=%i"),
841                           subsfile_dialog->fps_spinctrl->GetValue() ) );
842     }
843 }
844
845 /*****************************************************************************
846  * Stream output event methods.
847  *****************************************************************************/
848 void OpenDialog::OnSoutEnable( wxCommandEvent& event )
849 {
850     sout_button->Enable( event.GetInt() != 0 );
851     if( event.GetInt() && demuxdump_checkbox->IsChecked() )
852     {
853         demuxdump_checkbox->SetValue( 0 );
854         wxCommandEvent event = wxCommandEvent( wxEVT_NULL );
855         event.SetInt( 0 );
856         OnDemuxDumpEnable( event );
857     }
858 }
859
860 void OpenDialog::OnSoutSettings( wxCommandEvent& WXUNUSED(event) )
861 {
862     /* Show/hide the open dialog */
863     if( sout_dialog == NULL )
864         sout_dialog = new SoutDialog( p_intf, this );
865
866     if( sout_dialog && sout_dialog->ShowModal() == wxID_OK )
867     {
868         sout_mrl = sout_dialog->GetOptions();
869     }
870 }
871
872 /*****************************************************************************
873  * Demux dump event methods.
874  *****************************************************************************/
875 void OpenDialog::OnDemuxDumpEnable( wxCommandEvent& event )
876 {
877     demuxdump_textctrl->Enable( event.GetInt() != 0 );
878     demuxdump_button->Enable( event.GetInt() != 0 );
879
880     if( event.GetInt() )
881     {
882         sout_checkbox->SetValue( 0 );
883         subsfile_checkbox->SetValue( 0 );
884         wxCommandEvent event = wxCommandEvent( wxEVT_NULL );
885         event.SetInt( 0 );
886         OnSoutEnable( event );
887         OnSubsFileEnable( event );
888     }
889
890     UpdateMRL( i_current_access_method );
891 }
892
893 void OpenDialog::OnDemuxDumpBrowse( wxCommandEvent& WXUNUSED(event) )
894 {
895     if( demuxdump_dialog == NULL )
896         demuxdump_dialog = new wxFileDialog( this, wxU(_("Save file")),
897                                wxT(""), wxT(""), wxT("*"), wxSAVE );
898
899     if( demuxdump_dialog && demuxdump_dialog->ShowModal() == wxID_OK )
900     {
901         demuxdump_textctrl->SetValue( demuxdump_dialog->GetPath() );
902         wxCommandEvent event = wxCommandEvent( wxEVT_NULL );
903         OnDemuxDumpChange( event );
904     }
905 }
906
907 void OpenDialog::OnDemuxDumpChange( wxCommandEvent& WXUNUSED(event) )
908 {
909     config_PutPsz( p_intf, "demuxdump-file",
910                    demuxdump_textctrl->GetValue().mb_str() );
911 }
912
913 /*****************************************************************************
914  * Utility functions.
915  *****************************************************************************/
916 wxArrayString SeparateEntries( wxString entries )
917 {
918     vlc_bool_t b_quotes_mode = VLC_FALSE;
919
920     wxArrayString entries_array;
921     wxString entry;
922
923     wxStringTokenizer token( entries, wxT(" \t\r\n\""), wxTOKEN_RET_DELIMS );
924
925     while( token.HasMoreTokens() )
926     {
927         entry += token.GetNextToken();
928
929         if( entry.IsEmpty() ) continue;
930
931         if( !b_quotes_mode && entry.Last() == wxT('\"') )
932         {
933             /* Enters quotes mode */
934             entry.RemoveLast();
935             b_quotes_mode = VLC_TRUE;
936         }
937         else if( b_quotes_mode && entry.Last() == wxT('\"') )
938         {
939             /* Finished the quotes mode */
940             entry.RemoveLast();
941             if( !entry.IsEmpty() ) entries_array.Add( entry );
942             entry.Empty();
943             b_quotes_mode = VLC_FALSE;
944         }
945         else if( !b_quotes_mode && entry.Last() != wxT('\"') )
946         {
947             /* we found a non-quoted standalone string */
948             if( token.HasMoreTokens() ||
949                 entry.Last() == wxT(' ') || entry.Last() == wxT('\t') ||
950                 entry.Last() == wxT('\r') || entry.Last() == wxT('\n') )
951                 entry.RemoveLast();
952             if( !entry.IsEmpty() ) entries_array.Add( entry );
953             entry.Empty();
954         }
955         else
956         {;}
957     }
958
959     if( !entry.IsEmpty() ) entries_array.Add( entry );
960
961     return entries_array;
962 }