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