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