]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/open.cpp
71fae1d65270d38729bc751d0ea379a0174d5f12
[vlc] / modules / gui / wxwindows / open.cpp
1 /*****************************************************************************
2  * open.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2004 VideoLAN
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.org>
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 #include <wx/combobox.h>
35 #include <wx/statline.h>
36 #include <wx/tokenzr.h>
37
38 #include <vlc/intf.h>
39
40 #include "wxwindows.h"
41 #include "preferences_widgets.h"
42
43 #ifndef wxRB_SINGLE
44 #   define wxRB_SINGLE 0
45 #endif
46
47 /*****************************************************************************
48  * Event Table.
49  *****************************************************************************/
50
51 /* IDs for the controls and the menu commands */
52 enum
53 {
54     Notebook_Event = wxID_HIGHEST,
55     MRL_Event,
56
57     FileBrowse_Event,
58     FileName_Event,
59
60     DiscType_Event,
61     DiscDevice_Event,
62     DiscTitle_Event,
63     DiscChapter_Event,
64
65     NetType_Event,
66     NetRadio1_Event, NetRadio2_Event, NetRadio3_Event, NetRadio4_Event,
67     NetPort1_Event, NetPort2_Event, NetPort3_Event,
68     NetAddr1_Event, NetAddr2_Event, NetAddr3_Event, NetAddr4_Event,
69     NetForceIPv6_Event,
70
71     SubsFileEnable_Event,
72     SubsFileSettings_Event,
73
74     SoutEnable_Event,
75     SoutSettings_Event,
76
77     AdvancedOptions_Event
78 };
79
80 BEGIN_EVENT_TABLE(OpenDialog, wxFrame)
81     /* Button events */
82     EVT_BUTTON(wxID_OK, OpenDialog::OnOk)
83     EVT_BUTTON(wxID_CANCEL, OpenDialog::OnCancel)
84
85     EVT_NOTEBOOK_PAGE_CHANGED(Notebook_Event, OpenDialog::OnPageChange)
86
87     EVT_TEXT(MRL_Event, OpenDialog::OnMRLChange)
88
89     /* Events generated by the file panel */
90     EVT_TEXT(FileName_Event, OpenDialog::OnFilePanelChange)
91     EVT_BUTTON(FileBrowse_Event, OpenDialog::OnFileBrowse)
92
93     /* Events generated by the disc panel */
94     EVT_RADIOBOX(DiscType_Event, OpenDialog::OnDiscTypeChange)
95     EVT_TEXT(DiscDevice_Event, OpenDialog::OnDiscDeviceChange)
96     EVT_TEXT(DiscDevice_Event, OpenDialog::OnDiscPanelChange)
97     EVT_TEXT(DiscTitle_Event, OpenDialog::OnDiscPanelChange)
98     EVT_SPINCTRL(DiscTitle_Event, OpenDialog::OnDiscPanelChange)
99     EVT_TEXT(DiscChapter_Event, OpenDialog::OnDiscPanelChange)
100     EVT_SPINCTRL(DiscChapter_Event, OpenDialog::OnDiscPanelChange)
101
102     /* Events generated by the net panel */
103     EVT_RADIOBUTTON(NetRadio1_Event, OpenDialog::OnNetTypeChange)
104     EVT_RADIOBUTTON(NetRadio2_Event, OpenDialog::OnNetTypeChange)
105     EVT_RADIOBUTTON(NetRadio3_Event, OpenDialog::OnNetTypeChange)
106     EVT_RADIOBUTTON(NetRadio4_Event, OpenDialog::OnNetTypeChange)
107     EVT_TEXT(NetPort1_Event, OpenDialog::OnNetPanelChange)
108     EVT_SPINCTRL(NetPort1_Event, OpenDialog::OnNetPanelChange)
109     EVT_TEXT(NetPort2_Event, OpenDialog::OnNetPanelChange)
110     EVT_SPINCTRL(NetPort2_Event, OpenDialog::OnNetPanelChange)
111     EVT_TEXT(NetPort3_Event, OpenDialog::OnNetPanelChange)
112     EVT_SPINCTRL(NetPort3_Event, OpenDialog::OnNetPanelChange)
113     EVT_TEXT(NetAddr2_Event, OpenDialog::OnNetPanelChange)
114     EVT_TEXT(NetAddr3_Event, OpenDialog::OnNetPanelChange)
115     EVT_TEXT(NetAddr4_Event, OpenDialog::OnNetPanelChange)
116     EVT_CHECKBOX(NetForceIPv6_Event, OpenDialog::OnNetPanelChange)
117
118     /* Events generated by the subtitle file buttons */
119     EVT_CHECKBOX(SubsFileEnable_Event, OpenDialog::OnSubsFileEnable)
120     EVT_BUTTON(SubsFileSettings_Event, OpenDialog::OnSubsFileSettings)
121
122     /* Events generated by the stream output buttons */
123     EVT_CHECKBOX(SoutEnable_Event, OpenDialog::OnSoutEnable)
124     EVT_BUTTON(SoutSettings_Event, OpenDialog::OnSoutSettings)
125
126     /* Hide the window when the user closes the window */
127     EVT_CLOSE(OpenDialog::OnCancel)
128
129 END_EVENT_TABLE()
130
131 /*****************************************************************************
132  * AutoBuiltPanel.
133  *****************************************************************************/
134 WX_DEFINE_ARRAY(ConfigControl *, ArrayOfConfigControls);
135
136 class AutoBuiltPanel : public wxPanel
137 {
138 public:
139
140     AutoBuiltPanel() { }
141     AutoBuiltPanel( wxWindow *, OpenDialog *, intf_thread_t *,
142                     const module_t * );
143
144     virtual ~AutoBuiltPanel() {}
145
146     void UpdateAdvancedMRL();
147
148     wxString name;
149     ArrayOfConfigControls config_array;
150     ArrayOfConfigControls advanced_config_array;
151     wxComboBox *p_advanced_mrl_combo;
152
153 private:
154     intf_thread_t *p_intf;
155     OpenDialog *p_open_dialog;
156
157     void OnAdvanced( wxCommandEvent& event );
158     wxDialog *p_advanced_dialog;
159
160     DECLARE_EVENT_TABLE();
161 };
162
163 BEGIN_EVENT_TABLE(AutoBuiltPanel, wxPanel)
164     EVT_BUTTON(wxID_OK, AutoBuiltPanel::OnAdvanced)
165     EVT_BUTTON(AdvancedOptions_Event, AutoBuiltPanel::OnAdvanced)
166 END_EVENT_TABLE()
167
168 static void AutoBuildCallback( void *p_data )
169 {
170     ((OpenDialog *)p_data)->UpdateMRL();
171 }
172
173 static void AutoBuildAdvancedCallback( void *p_data )
174 {
175     ((AutoBuiltPanel *)p_data)->UpdateAdvancedMRL();
176 }
177
178 AutoBuiltPanel::AutoBuiltPanel( wxWindow *parent, OpenDialog *dialog,
179                                 intf_thread_t *_p_intf,
180                                 const module_t *p_module )
181   : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize ),
182     name( wxU(p_module->psz_object_name) ),
183     p_advanced_mrl_combo( NULL ),
184     p_intf( _p_intf ), p_open_dialog( dialog ), p_advanced_dialog( NULL )
185 {
186     wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
187     module_config_t *p_item = p_module->p_config;
188     bool b_advanced = false;
189
190     if( p_item ) do
191     {
192         if( !(p_item->i_type & CONFIG_HINT) && p_item->b_advanced )
193             b_advanced = true;
194
195         if( p_item->i_type & CONFIG_HINT || p_item->b_advanced )
196             continue;
197
198         ConfigControl *control =
199             CreateConfigControl( VLC_OBJECT(p_intf), p_item, this );
200
201         config_array.Add( control );
202
203         /* Don't add items that were not recognized */
204         if( control == NULL ) continue;
205
206         control->SetUpdateCallback( AutoBuildCallback, (void *)dialog );
207
208         sizer->Add( control, 0, wxEXPAND | wxALL, 2 );
209     }
210     while( p_item->i_type != CONFIG_HINT_END && p_item++ );
211
212     if( b_advanced )
213     {
214         wxPanel *dummy_panel = new wxPanel( this, -1 );
215         sizer->Add( dummy_panel, 1 );
216
217         wxButton *button =
218             new wxButton( this, AdvancedOptions_Event,
219                           wxU(_("Advanced options...")) );
220         sizer->Add( button, 0, wxALL, 5 );
221
222         /* Build the advanced dialog */
223         p_advanced_dialog =
224             new wxDialog( this, -1, ((wxString)wxU(_("Advanced options"))) +
225                           wxT(" (") + wxU( p_module->psz_longname ) + wxT(")"),
226                           wxDefaultPosition, wxDefaultSize,
227                           wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER );
228
229         wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
230
231         /* Create MRL combobox */
232         wxBoxSizer *mrl_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
233         wxStaticBox *mrl_box =
234             new wxStaticBox( p_advanced_dialog, -1,
235                              wxU(_("Advanced options")) );
236         wxStaticBoxSizer *mrl_sizer =
237             new wxStaticBoxSizer( mrl_box, wxHORIZONTAL );
238         wxStaticText *mrl_label =
239             new wxStaticText( p_advanced_dialog, -1, wxU(_("Options:")) );
240         p_advanced_mrl_combo =
241             new wxComboBox( p_advanced_dialog, MRL_Event, wxT(""),
242                             wxDefaultPosition, wxDefaultSize );
243         mrl_sizer->Add( mrl_label, 0, wxALL | wxALIGN_CENTER, 5 );
244         mrl_sizer->Add( p_advanced_mrl_combo, 1, wxALL | wxALIGN_CENTER, 5 );
245         mrl_sizer_sizer->Add( mrl_sizer, 1, wxEXPAND | wxALL, 5 );
246         sizer->Add( mrl_sizer_sizer, 0, wxEXPAND | wxALL, 2 );
247
248         /* Add advanced options to panel */
249         module_config_t *p_item = p_module->p_config;
250         if( p_item ) do
251         {
252             if( p_item->i_type & CONFIG_HINT || !p_item->b_advanced )
253                 continue;
254
255             ConfigControl *control =
256                 CreateConfigControl( VLC_OBJECT(p_intf), p_item,
257                                      p_advanced_dialog );
258
259             advanced_config_array.Add( control );
260
261             /* Don't add items that were not recognized */
262             if( control == NULL ) continue;
263
264             control->SetUpdateCallback( AutoBuildAdvancedCallback,
265                                         (void *)this );
266
267             sizer->Add( control, 0, wxEXPAND | wxALL, 2 );
268         }
269         while( p_item->i_type != CONFIG_HINT_END && p_item++ );
270
271         /* Separation */
272         dummy_panel = new wxPanel( p_advanced_dialog, -1 );
273         sizer->Add( dummy_panel, 1 );
274         wxStaticLine *static_line =
275             new wxStaticLine( p_advanced_dialog, wxID_OK );
276         sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
277
278         /* Create OK button */
279         wxButton *ok_button =
280             new wxButton( p_advanced_dialog, wxID_OK, wxU(_("OK")) );
281         ok_button->SetDefault();
282         sizer->Add( ok_button, 0, wxALL, 5 );
283
284         sizer->SetMinSize( 400, -1 );
285         p_advanced_dialog->SetSizerAndFit( sizer );
286     }
287
288     this->SetSizerAndFit( sizer );
289 }
290
291 void AutoBuiltPanel::OnAdvanced( wxCommandEvent& event )
292 {
293     p_advanced_dialog->Show( !p_advanced_dialog->IsShown() );
294     UpdateAdvancedMRL();
295     p_open_dialog->UpdateMRL();
296 }
297
298 void AutoBuiltPanel::UpdateAdvancedMRL()
299 {
300     wxString mrltemp;
301
302     for( int i = 0; i < (int)advanced_config_array.GetCount(); i++ )
303     {
304         ConfigControl *control = advanced_config_array.Item(i);
305
306         mrltemp += wxT(":");
307
308         if( control->GetType() == CONFIG_ITEM_BOOL &&
309             !control->GetIntValue() ) mrltemp += wxT("no-");
310
311         mrltemp += control->GetName();
312
313         switch( control->GetType() )
314         {
315         case CONFIG_ITEM_STRING:
316         case CONFIG_ITEM_FILE:
317         case CONFIG_ITEM_DIRECTORY:
318         case CONFIG_ITEM_MODULE:
319             mrltemp += wxT("=\"") + control->GetPszValue() + wxT("\"");
320             break;
321         case CONFIG_ITEM_INTEGER:
322             mrltemp +=
323                 wxString::Format( wxT("=%i"), control->GetIntValue() );
324             break;
325         case CONFIG_ITEM_FLOAT:
326             mrltemp +=
327                 wxString::Format(wxT("=%f"), control->GetFloatValue());
328             break;
329         }
330     }
331
332     p_advanced_mrl_combo->SetValue( mrltemp );
333 }
334
335 /*****************************************************************************
336  * Constructor.
337  *****************************************************************************/
338 OpenDialog::OpenDialog( intf_thread_t *_p_intf, wxWindow *_p_parent,
339                         int i_access_method, int i_arg ):
340     wxFrame( _p_parent, -1, wxU(_("Open...")), wxDefaultPosition,
341              wxDefaultSize, wxDEFAULT_FRAME_STYLE )
342 {
343     OpenDialog( _p_intf, _p_parent, i_access_method, i_arg, OPEN_NORMAL );
344 }
345
346 OpenDialog::OpenDialog( intf_thread_t *_p_intf, wxWindow *_p_parent,
347                         int i_access_method, int i_arg, int _i_method ):
348     wxFrame( _p_parent, -1, wxU(_("Open...")), wxDefaultPosition,
349              wxDefaultSize, wxDEFAULT_FRAME_STYLE )
350 {
351     /* Initializations */
352     i_method = _i_method;
353     p_intf = _p_intf;
354     p_parent = _p_parent;
355     SetIcon( *p_intf->p_sys->p_icon );
356     file_dialog = NULL;
357     i_disc_type_selection = 0;
358     i_open_arg = i_arg;
359
360     sout_dialog = NULL;
361     subsfile_dialog = NULL;
362     b_disc_device_changed = false;
363
364     /* Create a panel to put everything in */
365     wxPanel *panel = new wxPanel( this, -1 );
366     panel->SetAutoLayout( TRUE );
367
368     /* Create MRL combobox */
369     wxBoxSizer *mrl_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
370     wxStaticBox *mrl_box = new wxStaticBox( panel, -1,
371                                wxU(_("Media Resource Locator (MRL)")) );
372     wxStaticBoxSizer *mrl_sizer = new wxStaticBoxSizer( mrl_box,
373                                                         wxHORIZONTAL );
374     wxStaticText *mrl_label = new wxStaticText( panel, -1,
375                                                 wxU(_("Open:")) );
376     mrl_combo = new wxComboBox( panel, MRL_Event, wxT(""),
377                                 wxPoint(20,25), wxSize(120, -1),
378                                 0, NULL );
379     mrl_combo->SetToolTip( wxU(_("You can use this field directly by typing "
380         "the full MRL you want to open.\n""Alternatively, the field will be "
381         "filled automatically when you use the controls below.")) );
382
383     mrl_sizer->Add( mrl_label, 0, wxALL | wxALIGN_CENTER, 5 );
384     mrl_sizer->Add( mrl_combo, 1, wxALL | wxALIGN_CENTER, 5 );
385     mrl_sizer_sizer->Add( mrl_sizer, 1, wxEXPAND | wxALL, 5 );
386
387
388     /* Create Static Text */
389     wxStaticText *label = new wxStaticText( panel, -1,
390         wxU(_("Alternatively, you can build an MRL using one of the "
391               "following predefined targets:")) );
392
393     wxFlexGridSizer *sout_sizer = NULL;
394     wxStaticLine *static_line = NULL;
395
396     if( i_method == OPEN_NORMAL )
397     {
398         /* Create Stream Output checkox */
399         sout_sizer = new wxFlexGridSizer( 2, 1, 20 );
400
401
402         sout_checkbox = new wxCheckBox( panel, SoutEnable_Event,
403                                          wxU(_("Stream output")) );
404         sout_checkbox->SetToolTip( wxU(_("Use VLC as a server of streams")) );
405         sout_sizer->Add( sout_checkbox, 0,
406                          wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
407         sout_button = new wxButton( panel, SoutSettings_Event,
408                                     wxU(_("Settings...")) );
409         sout_button->Disable();
410
411         char *psz_sout = config_GetPsz( p_intf, "sout" );
412         if( psz_sout && *psz_sout )
413         {
414             sout_checkbox->SetValue(TRUE);
415             sout_button->Enable();
416             subsfile_mrl.Add( wxString(wxT("sout=")) + wxL2U(psz_sout) );
417         }
418         if( psz_sout ) free( psz_sout );
419
420         sout_sizer->Add( sout_button, 1, wxALIGN_LEFT |
421                          wxALIGN_CENTER_VERTICAL );
422
423         /* Separation */
424         static_line = new wxStaticLine( panel, wxID_OK );
425     }
426
427     /* Create the buttons */
428     wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
429     ok_button->SetDefault();
430     wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
431                                             wxU(_("Cancel")) );
432
433     /* Create notebook */
434     notebook = new wxNotebook( panel, Notebook_Event );
435     wxNotebookSizer *notebook_sizer = new wxNotebookSizer( notebook );
436
437     notebook->AddPage( FilePanel( notebook ), wxU(_("File")),
438                        i_access_method == FILE_ACCESS );
439     notebook->AddPage( DiscPanel( notebook ), wxU(_("Disc")),
440                        i_access_method == DISC_ACCESS );
441     notebook->AddPage( NetPanel( notebook ), wxU(_("Network")),
442                        i_access_method == NET_ACCESS );
443
444     module_t *p_module = config_FindModule( VLC_OBJECT(p_intf), "v4l" );
445     if( p_module )
446     {
447         AutoBuiltPanel *autopanel =
448             new AutoBuiltPanel( notebook, this, p_intf, p_module );
449         input_tab_array.Add( autopanel );
450         notebook->AddPage( autopanel, wxU( p_module->psz_longname ),
451                            i_access_method == CAPTURE_ACCESS );
452     }
453
454     p_module = config_FindModule( VLC_OBJECT(p_intf), "pvr" );
455     if( p_module )
456     {
457         AutoBuiltPanel *autopanel =
458             new AutoBuiltPanel( notebook, this, p_intf, p_module );
459         input_tab_array.Add( autopanel );
460         notebook->AddPage( autopanel, wxU( p_module->psz_longname ),
461                            i_access_method == CAPTURE_ACCESS );
462     }
463
464     p_module = config_FindModule( VLC_OBJECT(p_intf), "dshow" );
465     if( p_module )
466     {
467         AutoBuiltPanel *autopanel =
468             new AutoBuiltPanel( notebook, this, p_intf, p_module );
469         input_tab_array.Add( autopanel );
470         notebook->AddPage( autopanel, wxU( p_module->psz_longname ),
471                            i_access_method == CAPTURE_ACCESS );
472     }
473
474     /* Update Disc panel */
475     wxCommandEvent dummy_event;
476     OnDiscTypeChange( dummy_event );
477
478     /* Update Net panel */
479     dummy_event.SetId( NetRadio1_Event );
480     OnNetTypeChange( dummy_event );
481
482     /* Update MRL */
483     wxNotebookEvent event( wxEVT_NULL, 0, i_access_method );
484     OnPageChange( event );
485
486     /* Place everything in sizers */
487     wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
488     button_sizer->Add( ok_button, 0, wxALL, 5 );
489     button_sizer->Add( cancel_button, 0, wxALL, 5 );
490     button_sizer->Layout();
491     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
492     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
493     panel_sizer->Add( mrl_sizer_sizer, 0, wxEXPAND, 5 );
494     panel_sizer->Add( label, 0, wxEXPAND | wxALL, 5 );
495     panel_sizer->Add( notebook_sizer, 1, wxEXPAND | wxALL, 5 );
496     if( i_method == OPEN_NORMAL)
497     {
498         panel_sizer->Add( sout_sizer, 0, wxALIGN_LEFT | wxALL, 5 );
499         panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
500     }
501     panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALL, 5 );
502     panel_sizer->Layout();
503     panel->SetSizerAndFit( panel_sizer );
504     main_sizer->Add( panel, 1, wxGROW, 0 );
505     main_sizer->Layout();
506     SetSizerAndFit( main_sizer );
507 }
508
509 OpenDialog::~OpenDialog()
510 {
511     /* Clean up */
512     if( file_dialog ) delete file_dialog;
513     if( sout_dialog ) delete sout_dialog;
514     if( subsfile_dialog ) delete subsfile_dialog;
515 }
516
517 int OpenDialog::Show( int i_access_method, int i_arg )
518 {
519     int i_ret;
520     notebook->SetSelection( i_access_method );
521     i_ret = wxFrame::Show();
522     Raise();
523     SetFocus();
524     i_open_arg = i_arg;
525     return i_ret;
526 }
527
528 int OpenDialog::Show()
529 {
530     int i_ret;
531     i_ret = wxFrame::Show();
532     Raise();
533     SetFocus();
534     return i_ret;
535 }
536
537 /*****************************************************************************
538  * Private methods.
539  *****************************************************************************/
540 wxPanel *OpenDialog::FilePanel( wxWindow* parent )
541 {
542     wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
543                                   wxSize(200, 200) );
544
545     wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
546
547     /* Create browse file line */
548     wxBoxSizer *file_sizer = new wxBoxSizer( wxHORIZONTAL );
549
550     file_combo = new wxComboBox( panel, FileName_Event, wxT(""),
551                                  wxPoint(20,25), wxSize(200, -1), 0, NULL );
552     wxButton *browse_button = new wxButton( panel, FileBrowse_Event,
553                                             wxU(_("Browse...")) );
554     file_sizer->Add( file_combo, 1, wxALL, 5 );
555     file_sizer->Add( browse_button, 0, wxALL, 5 );
556
557     /* Create Subtitles File checkox */
558     wxFlexGridSizer *subsfile_sizer = new wxFlexGridSizer( 2, 1, 20 );
559     subsfile_checkbox = new wxCheckBox( panel, SubsFileEnable_Event,
560                                         wxU(_("Subtitle options")) );
561     subsfile_checkbox->SetToolTip( wxU(_("Force options for separate subtitle files.")) );
562     subsfile_sizer->Add( subsfile_checkbox, 0,
563                          wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
564     subsfile_button = new wxButton( panel, SubsFileSettings_Event,
565                                     wxU(_("Settings...")) );
566     subsfile_button->Disable();
567
568     char *psz_subsfile = config_GetPsz( p_intf, "sub-file" );
569     if( psz_subsfile && *psz_subsfile )
570     {
571         subsfile_checkbox->SetValue(TRUE);
572         subsfile_button->Enable();
573         subsfile_mrl.Add( wxString(wxT("sub-file=")) + wxL2U(psz_subsfile) );
574     }
575     if( psz_subsfile ) free( psz_subsfile );
576
577     subsfile_sizer->Add( subsfile_button, 1,
578                          wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
579
580     sizer->Add( file_sizer, 0, wxEXPAND | wxALL, 5 );
581     sizer->Add( subsfile_sizer, 0, wxEXPAND | wxALL, 5 );
582     panel->SetSizerAndFit( sizer );
583     return panel;
584 }
585
586 wxPanel *OpenDialog::DiscPanel( wxWindow* parent )
587 {
588     wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
589                                   wxSize(200, 200) );
590
591     wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
592     wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 3, 20 );
593
594     static const wxString disc_type_array[] =
595     {
596         wxU(_("DVD (menus support)")),
597         wxU(_("DVD")),
598         wxU(_("VCD")),
599         wxU(_("Audio CD"))
600
601     };
602
603     disc_type = new wxRadioBox( panel, DiscType_Event, wxU(_("Disc type")),
604                                 wxDefaultPosition, wxDefaultSize,
605                                 WXSIZEOF(disc_type_array), disc_type_array,
606                                 WXSIZEOF(disc_type_array), wxRA_SPECIFY_COLS );
607
608     sizer_row->Add( disc_type, i_disc_type_selection, wxEXPAND | wxALL, 5 );
609
610     wxStaticText *label = new wxStaticText( panel, -1, wxU(_("Device name")) );
611     disc_device = new wxTextCtrl( panel, DiscDevice_Event, wxT(""),
612                                   wxDefaultPosition, wxDefaultSize,
613                                   wxTE_PROCESS_ENTER);
614
615     sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
616     sizer->Add( disc_device, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
617
618     disc_title_label = new wxStaticText( panel, -1, wxU(_("Title")) );
619     disc_title = new wxSpinCtrl( panel, DiscTitle_Event );
620
621     sizer->Add( disc_title_label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
622     sizer->Add( disc_title, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
623
624     disc_chapter_label = new wxStaticText( panel, -1, wxU(_("Chapter")) );
625     disc_chapter = new wxSpinCtrl( panel, DiscChapter_Event );
626     sizer->Add( disc_chapter_label, 0,
627                 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
628     sizer->Add( disc_chapter, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
629     sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
630
631     panel->SetSizerAndFit( sizer_row );
632     return panel;
633 }
634
635 wxPanel *OpenDialog::NetPanel( wxWindow* parent )
636 {
637     int i;
638     wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
639                                   wxSize(200, 200) );
640
641     wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
642     wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 4, 20 );
643
644     static const wxString net_type_array[] =
645     {
646         wxU(_("UDP/RTP")),
647         wxU(_("UDP/RTP Multicast")),
648         wxU(_("HTTP/FTP/MMS")),
649         wxU(_("RTSP"))
650     };
651
652     for( i=0; i<4; i++ )
653     {
654         net_radios[i] = new wxRadioButton( panel, NetRadio1_Event + i,
655                                            net_type_array[i],
656                                            wxDefaultPosition, wxDefaultSize,
657                                            wxRB_SINGLE );
658
659         net_subpanels[i] = new wxPanel( panel, -1,
660                                         wxDefaultPosition, wxDefaultSize );
661     }
662
663     /* UDP/RTP row */
664     wxFlexGridSizer *subpanel_sizer;
665     wxStaticText *label;
666     i_net_ports[0] = config_GetInt( p_intf, "server-port" );
667     subpanel_sizer = new wxFlexGridSizer( 3, 1, 20 );
668     label = new wxStaticText( net_subpanels[0], -1, wxU(_("Port")) );
669     net_ports[0] = new wxSpinCtrl( net_subpanels[0], NetPort1_Event,
670                                    wxString::Format(wxT("%d"), i_net_ports[0]),
671                                    wxDefaultPosition, wxDefaultSize,
672                                    wxSP_ARROW_KEYS,
673                                    0, 16000, i_net_ports[0] );
674
675     subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
676     subpanel_sizer->Add( net_ports[0], 1,
677                          wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
678     net_ipv6 = new wxCheckBox( net_subpanels[0], NetForceIPv6_Event,
679                                wxU(_("Force IPv6")));
680     subpanel_sizer->Add( net_ipv6, 0,
681                          wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
682     net_subpanels[0]->SetSizerAndFit( subpanel_sizer );
683     net_radios[0]->SetValue( TRUE );
684
685     /* UDP/RTP Multicast row */
686     subpanel_sizer = new wxFlexGridSizer( 4, 1, 20 );
687     label = new wxStaticText( net_subpanels[1], -1, wxU(_("Address")) );
688     net_addrs[1] = new wxTextCtrl( net_subpanels[1], NetAddr2_Event, wxT(""),
689                                    wxDefaultPosition, wxDefaultSize,
690                                    wxTE_PROCESS_ENTER);
691     subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
692     subpanel_sizer->Add( net_addrs[1], 1,
693                          wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
694
695     label = new wxStaticText( net_subpanels[1], -1, wxU(_("Port")) );
696     i_net_ports[1] = i_net_ports[0];
697     net_ports[1] = new wxSpinCtrl( net_subpanels[1], NetPort2_Event,
698                                    wxString::Format(wxT("%d"), i_net_ports[1]),
699                                    wxDefaultPosition, wxDefaultSize,
700                                    wxSP_ARROW_KEYS,
701                                    0, 16000, i_net_ports[1] );
702
703     subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
704     subpanel_sizer->Add( net_ports[1], 1,
705                          wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
706     net_subpanels[1]->SetSizerAndFit( subpanel_sizer );
707
708     /* HTTP and RTSP rows */
709     for( i=2; i<4; i++ )
710     {
711         subpanel_sizer = new wxFlexGridSizer( 2, 1, 20 );
712         label = new wxStaticText( net_subpanels[i], -1, wxU(_("URL")) );
713         net_addrs[i] = new wxTextCtrl( net_subpanels[i], NetAddr1_Event + i,
714                                        (i == 2) ? wxT("") : wxT("rtsp://"),
715                                        wxDefaultPosition, wxSize( 200, -1 ),
716                                        wxTE_PROCESS_ENTER);
717         subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
718         subpanel_sizer->Add( net_addrs[i], 1,
719                              wxEXPAND | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
720         net_subpanels[i]->SetSizerAndFit( subpanel_sizer );
721     }
722
723     /* Stuff everything into the main panel */
724     for( i=0; i<4; i++ )
725     {
726         sizer->Add( net_radios[i], 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
727                     wxALL, 5 );
728         sizer->Add( net_subpanels[i], 1, wxEXPAND | wxALIGN_LEFT |
729                     wxALIGN_CENTER_VERTICAL | wxALL, 5  );
730     }
731
732     sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
733
734     panel->SetSizerAndFit( sizer_row );
735     return panel;
736 }
737
738 void OpenDialog::UpdateMRL()
739 {
740     UpdateMRL( i_current_access_method );
741 }
742
743 void OpenDialog::UpdateMRL( int i_access_method )
744 {
745     wxString demux, mrltemp;
746
747     i_current_access_method = i_access_method;
748
749     switch( i_access_method )
750     {
751     case FILE_ACCESS:
752         //mrltemp = wxT("file") + demux + wxT(":") + file_combo->GetValue();
753         mrltemp = file_combo->GetValue();
754         break;
755     case DISC_ACCESS:
756       i_disc_type_selection = disc_type->GetSelection();
757
758       switch ( i_disc_type_selection )
759         {
760         case 0: /* DVD with menues */
761           disc_chapter->Enable();
762           disc_chapter_label->Enable();
763           mrltemp = wxT("dvd://")
764                   + disc_device->GetValue()
765                   + wxString::Format( wxT("@%d:%d"),
766                                       disc_title->GetValue(),
767                                       disc_chapter->GetValue() );
768           break;
769
770         case 1: /* DVD of some sort */
771           disc_chapter->Enable();
772           disc_chapter_label->Enable();
773           mrltemp = wxT("dvdsimple://")
774                   + disc_device->GetValue()
775                   + wxString::Format( wxT("@%d:%d"),
776                                       disc_title->GetValue(),
777                                       disc_chapter->GetValue() );
778           break;
779
780         case 2:  /* VCD of some sort */
781           {
782             /* The chapter object is used for subtitles */
783
784             int i_subtitle = disc_chapter->GetValue();
785             config_PutInt( p_intf, "spu-channel", i_subtitle );
786             
787             disc_chapter->Enable();
788             disc_chapter_label->Enable();
789 #ifdef HAVE_VCDX
790           if ( disc_title->GetValue() )
791             mrltemp = wxT("vcdx://")
792               + disc_device->GetValue()
793               + wxString::Format( wxT("@%c%d"),
794                                   config_GetInt( p_intf, "vcdx-PBC"  )
795                                   ? 'P' : 'E',
796                                   disc_title->GetValue()
797                                   );
798           else
799             mrltemp = wxT("vcdx://")
800               + disc_device->GetValue();
801 #else
802           mrltemp = wxT("vcd://")
803             + disc_device->GetValue()
804             + wxString::Format( wxT("@%d"),
805                                 disc_title->GetValue() );
806 #endif
807           break;
808           }
809           
810
811         case 3: /* CD-DA */
812           disc_chapter->Disable();
813           disc_chapter_label->Disable();
814 #ifdef HAVE_CDDAX
815           if ( disc_title->GetValue() )
816             mrltemp =  wxT("cddax://")
817                   + disc_device->GetValue()
818                   + wxString::Format( wxT("@T%d"),
819                                       disc_title->GetValue() );
820           else
821             mrltemp = wxT("cddax://")
822                   + disc_device->GetValue();
823
824 #else
825           mrltemp =  wxT("cdda://")
826                   + disc_device->GetValue()
827                   + wxString::Format( wxT("@%d"),
828                                       disc_title->GetValue() );
829 #endif
830           break;
831         default: ;
832           msg_Err( p_intf, "invalid selection (%d)",
833                    disc_type->GetSelection() );
834         }
835
836         break;
837     case NET_ACCESS:
838         switch( i_net_type )
839         {
840         case 0:
841             mrltemp = wxT("udp") + demux + wxT("://");
842             if ( net_ipv6->GetValue() )
843             {
844                 mrltemp += wxT("@[::]");
845             }
846             if( i_net_ports[0] !=
847                 config_GetInt( p_intf, "server-port" ) )
848             {
849                 mrltemp += wxString::Format( wxT("@:%d"), i_net_ports[0] );
850             }
851             break;
852
853         case 1:
854             mrltemp = wxT("udp") + demux + wxT("://@");
855             if ((net_addrs[1]->GetLineText(0).Find (':') != -1)
856                 && (net_addrs[1]->GetLineText(0)[0u] != '['))
857             {
858                 /* automatically adds '[' and ']' to IPv6 addresses */
859                 mrltemp += wxT("[") + net_addrs[1]->GetLineText(0)
860                          + wxT("]");
861             }
862             else
863             {
864                 mrltemp += net_addrs[1]->GetLineText(0);
865             }
866             if( i_net_ports[1] != config_GetInt( p_intf, "server-port" ) )
867             {
868                 mrltemp += wxString::Format( wxT(":%d"), i_net_ports[1] );
869             }
870             break;
871
872         case 2:
873             /* http access */
874             if( net_addrs[2]->GetLineText(0).Find(wxT("http://")) )
875             {
876                 mrltemp = wxT("http") + demux + wxT("://");
877             }
878             mrltemp += net_addrs[2]->GetLineText(0);
879             break;
880
881         case 3:
882             /* RTSP access */
883             if( net_addrs[3]->GetLineText(0).Find(wxT("rtsp://")) != 0 )
884             {
885                 mrltemp = wxT("rtsp") + demux + wxT("://");
886             }
887             mrltemp += net_addrs[3]->GetLineText(0);
888             break;
889         }
890         break;
891
892     default:
893         {
894             int i_item = i_access_method - MAX_ACCESS;
895
896             if( i_item < 0 || i_item >= (int)input_tab_array.GetCount() )
897                 break;
898
899             AutoBuiltPanel *input_panel = input_tab_array.Item( i_item );
900
901             mrltemp = input_panel->name + wxT("://");
902
903             for( int i=0; i < (int)input_panel->config_array.GetCount(); i++ )
904             {
905                 ConfigControl *control = input_panel->config_array.Item(i);
906
907                 mrltemp += wxT(" :");
908
909                 if( control->GetType() == CONFIG_ITEM_BOOL &&
910                     !control->GetIntValue() ) mrltemp += wxT("no-");
911
912                 mrltemp += control->GetName();
913
914                 switch( control->GetType() )
915                 {
916                 case CONFIG_ITEM_STRING:
917                 case CONFIG_ITEM_FILE:
918                 case CONFIG_ITEM_DIRECTORY:
919                 case CONFIG_ITEM_MODULE:
920                     mrltemp += wxT("=\"") + control->GetPszValue() + wxT("\"");
921                     break;
922                 case CONFIG_ITEM_INTEGER:
923                     mrltemp +=
924                         wxString::Format( wxT("=%i"), control->GetIntValue() );
925                     break;
926                 case CONFIG_ITEM_FLOAT:
927                     mrltemp +=
928                         wxString::Format(wxT("=%f"), control->GetFloatValue());
929                     break;
930                 }
931             }
932
933             if( input_panel->p_advanced_mrl_combo &&
934                 input_panel->p_advanced_mrl_combo->GetValue() )
935             {
936                 mrltemp += wxT(" ") +
937                     input_panel->p_advanced_mrl_combo->GetValue();
938             }
939         }
940         break;
941     }
942
943     mrl_combo->SetValue( mrltemp );
944 }
945
946 /*****************************************************************************
947  * Events methods.
948  *****************************************************************************/
949 void OpenDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
950 {
951     mrl = SeparateEntries( mrl_combo->GetValue() );
952     mrl_combo->Append( mrl_combo->GetValue() );
953     if( mrl_combo->GetCount() > 10 ) mrl_combo->Delete( 0 );
954     mrl_combo->SetSelection( mrl_combo->GetCount() - 1 );
955
956     if( i_method == OPEN_STREAM )
957     {
958         Hide();
959         return;
960     }
961
962     /* Update the playlist */
963     playlist_t *p_playlist =
964         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
965                                        FIND_ANYWHERE );
966     if( p_playlist == NULL ) return;
967
968     for( int i = 0; i < (int)mrl.GetCount(); i++ )
969     {
970         vlc_bool_t b_start = !i && i_open_arg;
971         playlist_item_t *p_item =
972             playlist_ItemNew( p_intf, (const char*)mrl[i].mb_str(),
973                               (const char *)mrl[i].mb_str() );
974
975         /* Insert options */
976         while( i + 1 < (int)mrl.GetCount() &&
977                ((const char *)mrl[i + 1].mb_str())[0] == ':' )
978         {
979             playlist_ItemAddOption( p_item, mrl[i + 1].mb_str() );
980             i++;
981         }
982
983         /* Get the options from the subtitles dialog */
984         if( subsfile_checkbox->IsChecked() && subsfile_mrl.GetCount() )
985         {
986             for( int j = 0; j < (int)subsfile_mrl.GetCount(); j++ )
987             {
988                 playlist_ItemAddOption( p_item, subsfile_mrl[j].mb_str() );
989             }
990         }
991
992         /* Get the options from the stream output dialog */
993         if( sout_checkbox->IsChecked() && sout_mrl.GetCount() )
994         {
995             for( int j = 0; j < (int)sout_mrl.GetCount(); j++ )
996             {
997                 playlist_ItemAddOption( p_item, sout_mrl[j].mb_str() );
998             }
999         }
1000
1001         int i_id = playlist_AddItem( p_playlist, p_item,
1002                                      PLAYLIST_APPEND, PLAYLIST_END );
1003
1004         if( b_start )
1005         {
1006             int i_pos = playlist_GetPositionById( p_playlist , i_id );
1007             playlist_Command( p_playlist, PLAYLIST_GOTO, i_pos );
1008         }
1009     }
1010
1011     vlc_object_release( p_playlist );
1012
1013     Hide();
1014 }
1015
1016 void OpenDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
1017 {
1018     Hide();
1019 }
1020
1021 void OpenDialog::OnPageChange( wxNotebookEvent& event )
1022 {
1023     UpdateMRL( event.GetSelection() );
1024 }
1025
1026 void OpenDialog::OnMRLChange( wxCommandEvent& event )
1027 {
1028     //mrl = SeparateEntries( event.GetString() );
1029 }
1030
1031 /*****************************************************************************
1032  * File panel event methods.
1033  *****************************************************************************/
1034 void OpenDialog::OnFilePanelChange( wxCommandEvent& WXUNUSED(event) )
1035 {
1036     UpdateMRL( FILE_ACCESS );
1037 }
1038
1039 void OpenDialog::OnFileBrowse( wxCommandEvent& WXUNUSED(event) )
1040 {
1041     if( file_dialog == NULL )
1042         file_dialog = new wxFileDialog( this, wxU(_("Open File")),
1043             wxT(""), wxT(""), wxT("*"), wxOPEN | wxMULTIPLE );
1044
1045     if( file_dialog && file_dialog->ShowModal() == wxID_OK )
1046     {
1047         wxArrayString paths;
1048         wxString path;
1049
1050         file_dialog->GetPaths( paths );
1051
1052         for( size_t i = 0; i < paths.GetCount(); i++ )
1053         {
1054             if( paths[i].Find( wxT(' ') ) >= 0 )
1055                 path += wxT("\"") + paths[i] + wxT("\" ");
1056             else
1057                 path += paths[i] + wxT(" ");
1058         }
1059
1060         file_combo->SetValue( path );
1061         file_combo->Append( path );
1062         if( file_combo->GetCount() > 10 ) file_combo->Delete( 0 );
1063         UpdateMRL( FILE_ACCESS );
1064     }
1065 }
1066
1067 /*****************************************************************************
1068  * Disc panel event methods.
1069  *****************************************************************************/
1070 void OpenDialog::OnDiscPanelChange( wxCommandEvent& event )
1071 {
1072     UpdateMRL( DISC_ACCESS );
1073 }
1074
1075 void OpenDialog::OnDiscDeviceChange( wxCommandEvent& event )
1076 {
1077     char *psz_device;
1078
1079     switch( disc_type->GetSelection() )
1080     {
1081         case 3:
1082             psz_device = config_GetPsz( p_intf, "cd-audio" );
1083             break;
1084
1085         case 2:
1086             psz_device = config_GetPsz( p_intf, "vcd" );
1087             break;
1088
1089         default:
1090             psz_device = config_GetPsz( p_intf, "dvd" );
1091             break;
1092     }
1093
1094     if ( !psz_device ) psz_device = "";
1095
1096     if( disc_device->GetValue().Cmp( wxL2U( psz_device ) ) )
1097     {
1098         b_disc_device_changed = true;
1099     }
1100
1101     UpdateMRL( DISC_ACCESS );
1102 }
1103
1104 void OpenDialog::OnDiscTypeChange( wxCommandEvent& WXUNUSED(event) )
1105 {
1106     char *psz_device = NULL;
1107     int  i_selection = 1; /* Default Title/Track selection number*/
1108
1109     switch( disc_type->GetSelection() )
1110     {
1111
1112     case 0: /* DVD with menues */
1113       i_selection=0;
1114       /* Fall through... */
1115
1116     case 1: /* DVD of some sort */
1117         psz_device = config_GetPsz( p_intf, "dvd" );
1118         if( !b_disc_device_changed )
1119         {
1120             if( psz_device )
1121                 disc_device->SetValue( wxL2U(psz_device) );
1122             else
1123                 disc_device->SetValue( wxT("") );
1124
1125             disc_title_label->SetLabel ( wxU(_("Title")) );
1126         }
1127         disc_title->SetRange( i_selection, 255 );
1128         disc_title->SetValue( i_selection );
1129
1130         disc_chapter->SetRange( 1, 255 );
1131         disc_chapter->SetValue( 1 );
1132         disc_chapter_label->SetLabel ( wxU(_("Chapter")) );
1133
1134         break;
1135
1136     case 2:  /* VCD of some sort */
1137         psz_device = config_GetPsz( p_intf, "vcd" );
1138         if( !b_disc_device_changed )
1139         {
1140             if( psz_device )
1141                 disc_device->SetValue( wxL2U(psz_device) );
1142             else
1143                 disc_device->SetValue( wxT("") );
1144         }
1145
1146         /* There are at most 98, tracks in a VCD, 999 Segments, 500 entries
1147            I don't know what the limit is for LIDs, 999 is probably safe
1148            though.
1149
1150            FIXME: it would be better however to get the information for
1151            this particular Media possibly from the General Info area.
1152          */
1153 #ifdef HAVE_VCDX
1154         disc_title_label->SetLabel ( config_GetInt( p_intf, "vcdx-PBC"  )
1155                                      ? wxT("Playback LID") : wxT("Entry") );
1156         disc_title->SetRange( 0, 999 );
1157         i_selection = 0;
1158 #else
1159         disc_title_label->SetLabel ( wxU(_("Track")) );
1160         disc_title->SetRange( 1, 98 );
1161 #endif
1162         disc_title->SetValue( i_selection );
1163
1164         /* We use the chapter to set subtitle number */
1165         disc_chapter_label->SetLabel ( wxU(_("Subtitle")) );
1166         disc_chapter->SetRange( -1, 4 );
1167         disc_chapter->SetValue( config_GetInt( p_intf, "spu-channel" ) );
1168         break;
1169
1170     case 3: /* CD-DA */
1171         psz_device = config_GetPsz( p_intf, "cd-audio" );
1172         if( !b_disc_device_changed )
1173         {
1174             if( psz_device )
1175                 disc_device->SetValue( wxL2U(psz_device) );
1176             else
1177                 disc_device->SetValue( wxT("") );
1178         }
1179         disc_title_label->SetLabel ( wxU(_("Track")) );
1180 #ifdef HAVE_CDDAX
1181         i_selection = 0;
1182 #endif
1183        /* There are at most 99 tracks in a CD-DA */
1184         disc_title->SetRange( i_selection, 99 );
1185         disc_title->SetValue( i_selection );
1186         break;
1187     default:
1188         msg_Err( p_intf, "invalid Disc type selection (%d)",
1189                  disc_type->GetSelection() );
1190         break;
1191     }
1192
1193     if( psz_device ) free( psz_device );
1194
1195     UpdateMRL( DISC_ACCESS );
1196 }
1197
1198 /*****************************************************************************
1199  * Net panel event methods.
1200  *****************************************************************************/
1201 void OpenDialog::OnNetPanelChange( wxCommandEvent& event )
1202 {
1203     if( event.GetId() >= NetPort1_Event && event.GetId() <= NetPort3_Event )
1204     {
1205         i_net_ports[event.GetId() - NetPort1_Event] = event.GetInt();
1206     }
1207
1208     UpdateMRL( NET_ACCESS );
1209 }
1210
1211 void OpenDialog::OnNetTypeChange( wxCommandEvent& event )
1212 {
1213     int i;
1214
1215     i_net_type = event.GetId() - NetRadio1_Event;
1216
1217     for(i=0; i<4; i++)
1218     {
1219         net_radios[i]->SetValue( event.GetId() == (NetRadio1_Event+i) );
1220         net_subpanels[i]->Enable( event.GetId() == (NetRadio1_Event+i) );
1221     }
1222
1223     UpdateMRL( NET_ACCESS );
1224 }
1225
1226 /*****************************************************************************
1227  * Subtitles file event methods.
1228  *****************************************************************************/
1229 void OpenDialog::OnSubsFileEnable( wxCommandEvent& event )
1230 {
1231     subsfile_button->Enable( event.GetInt() != 0 );
1232 }
1233
1234 void OpenDialog::OnSubsFileSettings( wxCommandEvent& WXUNUSED(event) )
1235 {
1236     /* Show/hide the open dialog */
1237     if( subsfile_dialog == NULL )
1238         subsfile_dialog = new SubsFileDialog( p_intf, this );
1239
1240     if( subsfile_dialog && subsfile_dialog->ShowModal() == wxID_OK )
1241     {
1242         subsfile_mrl.Empty();
1243         subsfile_mrl.Add( wxString(wxT("sub-file=")) +
1244                           subsfile_dialog->file_combo->GetValue() );
1245         if( subsfile_dialog->encoding_combo )
1246             subsfile_mrl.Add( wxString(wxT("subsdec-encoding=")) +
1247                               subsfile_dialog->encoding_combo->GetValue() );
1248         subsfile_mrl.Add( wxString::Format( wxT("sub-delay=%i"),
1249                           subsfile_dialog->delay_spinctrl->GetValue() ) );
1250         subsfile_mrl.Add( wxString::Format( wxT("sub-fps=%i"),
1251                           subsfile_dialog->fps_spinctrl->GetValue() ) );
1252     }
1253 }
1254
1255 /*****************************************************************************
1256  * Stream output event methods.
1257  *****************************************************************************/
1258 void OpenDialog::OnSoutEnable( wxCommandEvent& event )
1259 {
1260     sout_button->Enable( event.GetInt() != 0 );
1261 }
1262
1263 void OpenDialog::OnSoutSettings( wxCommandEvent& WXUNUSED(event) )
1264 {
1265     /* Show/hide the open dialog */
1266     if( sout_dialog == NULL )
1267         sout_dialog = new SoutDialog( p_intf, this );
1268
1269     if( sout_dialog && sout_dialog->ShowModal() == wxID_OK )
1270     {
1271         sout_mrl = sout_dialog->GetOptions();
1272     }
1273 }
1274
1275 /*****************************************************************************
1276  * Utility functions.
1277  *****************************************************************************/
1278 wxArrayString SeparateEntries( wxString entries )
1279 {
1280     vlc_bool_t b_quotes_mode = VLC_FALSE;
1281
1282     wxArrayString entries_array;
1283     wxString entry;
1284
1285     wxStringTokenizer token( entries, wxT(" \t\r\n\""), wxTOKEN_RET_DELIMS );
1286
1287     while( token.HasMoreTokens() )
1288     {
1289         entry += token.GetNextToken();
1290
1291         if( entry.IsEmpty() ) continue;
1292
1293         if( !b_quotes_mode && entry.Last() == wxT('\"') )
1294         {
1295             /* Enters quotes mode */
1296             entry.RemoveLast();
1297             b_quotes_mode = VLC_TRUE;
1298         }
1299         else if( b_quotes_mode && entry.Last() == wxT('\"') )
1300         {
1301             /* Finished the quotes mode */
1302             entry.RemoveLast();
1303             if( !entry.IsEmpty() ) entries_array.Add( entry );
1304             entry.Empty();
1305             b_quotes_mode = VLC_FALSE;
1306         }
1307         else if( !b_quotes_mode && entry.Last() != wxT('\"') )
1308         {
1309             /* we found a non-quoted standalone string */
1310             if( token.HasMoreTokens() ||
1311                 entry.Last() == wxT(' ') || entry.Last() == wxT('\t') ||
1312                 entry.Last() == wxT('\r') || entry.Last() == wxT('\n') )
1313                 entry.RemoveLast();
1314             if( !entry.IsEmpty() ) entries_array.Add( entry );
1315             entry.Empty();
1316         }
1317         else
1318         {;}
1319     }
1320
1321     if( !entry.IsEmpty() ) entries_array.Add( entry );
1322
1323     return entries_array;
1324 }