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