]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/open.cpp
* modules/gui/wxwindows/open.cpp: mrl parsing fix.
[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_longname ),
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_longname ),
468                            i_access_method == CAPTURE_ACCESS );
469     }
470
471     p_module = config_FindModule( VLC_OBJECT(p_intf), "dshow" );
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_longname ),
478                            i_access_method == CAPTURE_ACCESS );
479     }
480
481     /* Update Disc panel */
482     wxCommandEvent dummy_event;
483     OnDiscTypeChange( dummy_event );
484
485     /* Update Net panel */
486     dummy_event.SetId( NetRadio1_Event );
487     OnNetTypeChange( dummy_event );
488
489     /* Update MRL */
490     wxNotebookEvent event( wxEVT_NULL, 0, i_access_method );
491     OnPageChange( event );
492
493     /* Place everything in sizers */
494     wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
495     button_sizer->Add( ok_button, 0, wxALL, 5 );
496     button_sizer->Add( cancel_button, 0, wxALL, 5 );
497     button_sizer->Layout();
498     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
499     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
500     panel_sizer->Add( mrl_sizer_sizer, 0, wxEXPAND, 5 );
501     panel_sizer->Add( label, 0, wxEXPAND | wxALL, 5 );
502     panel_sizer->Add( notebook_sizer, 1, wxEXPAND | wxALL, 5 );
503     if( i_method == OPEN_NORMAL)
504     {
505         panel_sizer->Add( sout_sizer, 0, wxALIGN_LEFT | wxALL, 5 );
506         panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
507     }
508     panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALL, 5 );
509     panel_sizer->Layout();
510     panel->SetSizerAndFit( panel_sizer );
511     main_sizer->Add( panel, 1, wxGROW, 0 );
512     main_sizer->Layout();
513     SetSizerAndFit( main_sizer );
514 }
515
516 OpenDialog::~OpenDialog()
517 {
518     /* Clean up */
519     if( file_dialog ) delete file_dialog;
520     if( sout_dialog ) delete sout_dialog;
521     if( subsfile_dialog ) delete subsfile_dialog;
522 }
523
524 int OpenDialog::Show( int i_access_method, int i_arg )
525 {
526     notebook->SetSelection( i_access_method );
527     int i_ret = wxDialog::Show();
528     Raise();
529     SetFocus();
530     i_open_arg = i_arg;
531     return i_ret;
532 }
533
534 int OpenDialog::Show()
535 {
536     int i_ret = wxDialog::Show();
537     Raise();
538     SetFocus();
539     return i_ret;
540 }
541
542 /*****************************************************************************
543  * Private methods.
544  *****************************************************************************/
545 wxPanel *OpenDialog::FilePanel( wxWindow* parent )
546 {
547     wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
548                                   wxSize(200, 200) );
549
550     wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
551
552     /* Create browse file line */
553     wxBoxSizer *file_sizer = new wxBoxSizer( wxHORIZONTAL );
554
555     file_combo = new wxComboBox( panel, FileName_Event, wxT(""),
556                                  wxPoint(20,25), wxSize(200, -1), 0, NULL );
557     wxButton *browse_button = new wxButton( panel, FileBrowse_Event,
558                                             wxU(_("Browse...")) );
559     file_sizer->Add( file_combo, 1, wxALL, 5 );
560     file_sizer->Add( browse_button, 0, wxALL, 5 );
561
562     /* Create Subtitles File checkox */
563     wxFlexGridSizer *subsfile_sizer = new wxFlexGridSizer( 2, 1, 20 );
564     subsfile_checkbox = new wxCheckBox( panel, SubsFileEnable_Event,
565                                         wxU(_("Subtitle options")) );
566     subsfile_checkbox->SetToolTip( wxU(_("Force options for separate subtitle files.")) );
567     subsfile_sizer->Add( subsfile_checkbox, 0,
568                          wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
569     subsfile_button = new wxButton( panel, SubsFileSettings_Event,
570                                     wxU(_("Settings...")) );
571     subsfile_button->Disable();
572
573     char *psz_subsfile = config_GetPsz( p_intf, "sub-file" );
574     if( psz_subsfile && *psz_subsfile )
575     {
576         subsfile_checkbox->SetValue(TRUE);
577         subsfile_button->Enable();
578         subsfile_mrl.Add( wxString(wxT("sub-file=")) + wxL2U(psz_subsfile) );
579     }
580     if( psz_subsfile ) free( psz_subsfile );
581
582     subsfile_sizer->Add( subsfile_button, 1,
583                          wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
584
585     sizer->Add( file_sizer, 0, wxEXPAND | wxALL, 5 );
586     sizer->Add( subsfile_sizer, 0, wxEXPAND | wxALL, 5 );
587     panel->SetSizerAndFit( sizer );
588     return panel;
589 }
590
591 wxPanel *OpenDialog::DiscPanel( wxWindow* parent )
592 {
593     wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
594                                   wxSize(200, 200) );
595
596     wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
597     wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 3, 20 );
598
599     static const wxString disc_type_array[] =
600     {
601         wxU(_("DVD (menus support)")),
602         wxU(_("DVD")),
603         wxU(_("VCD")),
604         wxU(_("Audio CD")),
605         wxU(_("DVD (experimental)"))
606     };
607
608     disc_type = new wxRadioBox( panel, DiscType_Event, wxU(_("Disc type")),
609                                 wxDefaultPosition, wxDefaultSize,
610                                 WXSIZEOF(disc_type_array), disc_type_array,
611                                 WXSIZEOF(disc_type_array), wxRA_SPECIFY_COLS );
612
613     sizer_row->Add( disc_type, i_disc_type_selection, wxEXPAND | wxALL, 5 );
614
615     wxStaticText *label = new wxStaticText( panel, -1, wxU(_("Device name")) );
616     disc_device = new wxTextCtrl( panel, DiscDevice_Event, wxT(""),
617                                   wxDefaultPosition, wxDefaultSize,
618                                   wxTE_PROCESS_ENTER);
619
620     sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
621     sizer->Add( disc_device, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
622
623     disc_title_label = new wxStaticText( panel, -1, wxU(_("Title")) );
624     disc_title = new wxSpinCtrl( panel, DiscTitle_Event );
625
626     sizer->Add( disc_title_label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
627     sizer->Add( disc_title, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
628
629     disc_chapter_label = new wxStaticText( panel, -1, wxU(_("Chapter")) );
630     disc_chapter = new wxSpinCtrl( panel, DiscChapter_Event );
631     sizer->Add( disc_chapter_label, 0,
632                 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
633     sizer->Add( disc_chapter, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
634     sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
635
636     panel->SetSizerAndFit( sizer_row );
637     return panel;
638 }
639
640 wxPanel *OpenDialog::NetPanel( wxWindow* parent )
641 {
642     int i;
643     wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
644                                   wxSize(200, 200) );
645
646     wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
647     wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 4, 20 );
648
649     static const wxString net_type_array[] =
650     {
651         wxU(_("UDP/RTP")),
652         wxU(_("UDP/RTP Multicast")),
653         wxU(_("HTTP/FTP/MMS")),
654         wxU(_("RTSP"))
655     };
656
657     for( i=0; i<4; i++ )
658     {
659         net_radios[i] = new wxRadioButton( panel, NetRadio1_Event + i,
660                                            net_type_array[i],
661                                            wxDefaultPosition, wxDefaultSize,
662                                            wxRB_SINGLE );
663
664         net_subpanels[i] = new wxPanel( panel, -1,
665                                         wxDefaultPosition, wxDefaultSize );
666     }
667
668     /* UDP/RTP row */
669     wxFlexGridSizer *subpanel_sizer;
670     wxStaticText *label;
671     i_net_ports[0] = config_GetInt( p_intf, "server-port" );
672     subpanel_sizer = new wxFlexGridSizer( 3, 1, 20 );
673     label = new wxStaticText( net_subpanels[0], -1, wxU(_("Port")) );
674     net_ports[0] = new wxSpinCtrl( net_subpanels[0], NetPort1_Event,
675                                    wxString::Format(wxT("%d"), i_net_ports[0]),
676                                    wxDefaultPosition, wxDefaultSize,
677                                    wxSP_ARROW_KEYS,
678                                    0, 16000, i_net_ports[0] );
679
680     subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
681     subpanel_sizer->Add( net_ports[0], 1,
682                          wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
683     net_ipv6 = new wxCheckBox( net_subpanels[0], NetForceIPv6_Event,
684                                wxU(_("Force IPv6")));
685     subpanel_sizer->Add( net_ipv6, 0,
686                          wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
687     net_subpanels[0]->SetSizerAndFit( subpanel_sizer );
688     net_radios[0]->SetValue( TRUE );
689
690     /* UDP/RTP Multicast row */
691     subpanel_sizer = new wxFlexGridSizer( 4, 1, 20 );
692     label = new wxStaticText( net_subpanels[1], -1, wxU(_("Address")) );
693     net_addrs[1] = new wxTextCtrl( net_subpanels[1], NetAddr2_Event, wxT(""),
694                                    wxDefaultPosition, wxDefaultSize,
695                                    wxTE_PROCESS_ENTER);
696     subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
697     subpanel_sizer->Add( net_addrs[1], 1,
698                          wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
699
700     label = new wxStaticText( net_subpanels[1], -1, wxU(_("Port")) );
701     i_net_ports[1] = i_net_ports[0];
702     net_ports[1] = new wxSpinCtrl( net_subpanels[1], NetPort2_Event,
703                                    wxString::Format(wxT("%d"), i_net_ports[1]),
704                                    wxDefaultPosition, wxDefaultSize,
705                                    wxSP_ARROW_KEYS,
706                                    0, 16000, i_net_ports[1] );
707
708     subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
709     subpanel_sizer->Add( net_ports[1], 1,
710                          wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
711     net_subpanels[1]->SetSizerAndFit( subpanel_sizer );
712
713     /* HTTP and RTSP rows */
714     for( i=2; i<4; i++ )
715     {
716         subpanel_sizer = new wxFlexGridSizer( 2, 1, 20 );
717         label = new wxStaticText( net_subpanels[i], -1, wxU(_("URL")) );
718         net_addrs[i] = new wxTextCtrl( net_subpanels[i], NetAddr1_Event + i,
719                                        (i == 2) ? wxT("") : wxT("rtsp://"),
720                                        wxDefaultPosition, wxSize( 200, -1 ),
721                                        wxTE_PROCESS_ENTER);
722         subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
723         subpanel_sizer->Add( net_addrs[i], 1,
724                              wxEXPAND | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
725         net_subpanels[i]->SetSizerAndFit( subpanel_sizer );
726     }
727
728     /* Stuff everything into the main panel */
729     for( i=0; i<4; i++ )
730     {
731         sizer->Add( net_radios[i], 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
732                     wxALL, 5 );
733         sizer->Add( net_subpanels[i], 1, wxEXPAND | wxALIGN_LEFT |
734                     wxALIGN_CENTER_VERTICAL | wxALL, 5  );
735     }
736
737     sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
738
739     panel->SetSizerAndFit( sizer_row );
740     return panel;
741 }
742
743 void OpenDialog::UpdateMRL()
744 {
745     UpdateMRL( i_current_access_method );
746 }
747
748 void OpenDialog::UpdateMRL( int i_access_method )
749 {
750     wxString demux, mrltemp;
751
752     i_current_access_method = i_access_method;
753
754     switch( i_access_method )
755     {
756     case FILE_ACCESS:
757         //mrltemp = wxT("file") + demux + wxT(":") + file_combo->GetValue();
758         mrltemp = file_combo->GetValue();
759         break;
760     case DISC_ACCESS:
761       i_disc_type_selection = disc_type->GetSelection();
762
763       switch ( i_disc_type_selection )
764         {
765         case 0: /* DVD with menues */
766           disc_chapter->Enable();
767           disc_chapter_label->Enable();
768           mrltemp = wxT("dvd://")
769                   + disc_device->GetValue()
770                   + wxString::Format( wxT("@%d:%d"),
771                                       disc_title->GetValue(),
772                                       disc_chapter->GetValue() );
773           break;
774
775         case 1: /* DVD of some sort */
776           disc_chapter->Enable();
777           disc_chapter_label->Enable();
778           mrltemp = wxT("dvdsimple://")
779                   + disc_device->GetValue()
780                   + wxString::Format( wxT("@%d:%d"),
781                                       disc_title->GetValue(),
782                                       disc_chapter->GetValue() );
783           break;
784
785         case 2:  /* VCD of some sort */
786           {
787             /* The chapter object is used for subtitles */
788
789             int i_subtitle = disc_chapter->GetValue();
790             config_PutInt( p_intf, "spu-channel", i_subtitle );
791             
792             disc_chapter->Enable();
793             disc_chapter_label->Enable();
794 #ifdef HAVE_VCDX
795           if ( disc_title->GetValue() )
796             mrltemp = wxT("vcdx://")
797               + disc_device->GetValue()
798               + wxString::Format( wxT("@%c%d"),
799                                   config_GetInt( p_intf, "vcdx-PBC"  )
800                                   ? 'P' : 'E',
801                                   disc_title->GetValue()
802                                   );
803           else
804             mrltemp = wxT("vcdx://")
805               + disc_device->GetValue();
806 #else
807           mrltemp = wxT("vcd://")
808             + disc_device->GetValue()
809             + wxString::Format( wxT("@%d"),
810                                 disc_title->GetValue() );
811 #endif
812           break;
813           }
814           
815
816         case 3: /* CD-DA */
817           disc_chapter->Disable();
818           disc_chapter_label->Disable();
819 #ifdef HAVE_CDDAX
820           if ( disc_title->GetValue() )
821             mrltemp =  wxT("cddax://")
822                   + disc_device->GetValue()
823                   + wxString::Format( wxT("@T%d"),
824                                       disc_title->GetValue() );
825           else
826             mrltemp = wxT("cddax://")
827                   + disc_device->GetValue();
828
829 #else
830           mrltemp =  wxT("cdda://")
831                   + disc_device->GetValue()
832                   + wxString::Format( wxT("@%d"),
833                                       disc_title->GetValue() );
834 #endif
835           break;
836
837         case 4: /* DVD of some sort */
838           disc_chapter->Enable();
839           disc_chapter_label->Enable();
840           mrltemp = wxT("dvdnav://")
841                   + disc_device->GetValue()
842                   + wxString::Format( wxT("@%d:%d"),
843                                       disc_title->GetValue(),
844                                       disc_chapter->GetValue() );
845           break;
846
847         default: ;
848           msg_Err( p_intf, "invalid selection (%d)",
849                    disc_type->GetSelection() );
850         }
851
852         break;
853     case NET_ACCESS:
854         switch( i_net_type )
855         {
856         case 0:
857             mrltemp = wxT("udp") + demux + wxT("://");
858             if ( net_ipv6->GetValue() )
859             {
860                 mrltemp += wxT("@[::]");
861             }
862             if( i_net_ports[0] !=
863                 config_GetInt( p_intf, "server-port" ) )
864             {
865                 mrltemp += wxString::Format( wxT("@:%d"), i_net_ports[0] );
866             }
867             break;
868
869         case 1:
870             mrltemp = wxT("udp") + demux + wxT("://@");
871             if ((net_addrs[1]->GetLineText(0).Find (':') != -1)
872                 && (net_addrs[1]->GetLineText(0)[0u] != '['))
873             {
874                 /* automatically adds '[' and ']' to IPv6 addresses */
875                 mrltemp += wxT("[") + net_addrs[1]->GetLineText(0)
876                          + wxT("]");
877             }
878             else
879             {
880                 mrltemp += net_addrs[1]->GetLineText(0);
881             }
882             if( i_net_ports[1] != config_GetInt( p_intf, "server-port" ) )
883             {
884                 mrltemp += wxString::Format( wxT(":%d"), i_net_ports[1] );
885             }
886             break;
887
888         case 2:
889             /* http access */
890             if( net_addrs[2]->GetLineText(0).Find(wxT("http://")) )
891             {
892                 mrltemp = wxT("http") + demux + wxT("://");
893             }
894             mrltemp += net_addrs[2]->GetLineText(0);
895             break;
896
897         case 3:
898             /* RTSP access */
899             if( net_addrs[3]->GetLineText(0).Find(wxT("rtsp://")) != 0 )
900             {
901                 mrltemp = wxT("rtsp") + demux + wxT("://");
902             }
903             mrltemp += net_addrs[3]->GetLineText(0);
904             break;
905         }
906         break;
907
908     default:
909         {
910             int i_item = i_access_method - MAX_ACCESS;
911
912             if( i_item < 0 || i_item >= (int)input_tab_array.GetCount() )
913                 break;
914
915             AutoBuiltPanel *input_panel = input_tab_array.Item( i_item );
916
917             mrltemp = input_panel->name + wxT("://");
918
919             for( int i=0; i < (int)input_panel->config_array.GetCount(); i++ )
920             {
921                 ConfigControl *control = input_panel->config_array.Item(i);
922
923                 mrltemp += wxT(" :");
924
925                 if( control->GetType() == CONFIG_ITEM_BOOL &&
926                     !control->GetIntValue() ) mrltemp += wxT("no-");
927
928                 mrltemp += control->GetName();
929
930                 switch( control->GetType() )
931                 {
932                 case CONFIG_ITEM_STRING:
933                 case CONFIG_ITEM_FILE:
934                 case CONFIG_ITEM_DIRECTORY:
935                 case CONFIG_ITEM_MODULE:
936                     mrltemp += wxT("=\"") + control->GetPszValue() + wxT("\"");
937                     break;
938                 case CONFIG_ITEM_INTEGER:
939                     mrltemp +=
940                         wxString::Format( wxT("=%i"), control->GetIntValue() );
941                     break;
942                 case CONFIG_ITEM_FLOAT:
943                     mrltemp +=
944                         wxString::Format(wxT("=%f"), control->GetFloatValue());
945                     break;
946                 }
947             }
948
949             if( input_panel->p_advanced_mrl_combo &&
950                 input_panel->p_advanced_mrl_combo->GetValue() )
951             {
952                 mrltemp += wxT(" ") +
953                     input_panel->p_advanced_mrl_combo->GetValue();
954             }
955         }
956         break;
957     }
958
959     mrl_combo->SetValue( mrltemp );
960 }
961
962 /*****************************************************************************
963  * Events methods.
964  *****************************************************************************/
965 void OpenDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
966 {
967     mrl = SeparateEntries( mrl_combo->GetValue() );
968     mrl_combo->Append( mrl_combo->GetValue() );
969     if( mrl_combo->GetCount() > 10 ) mrl_combo->Delete( 0 );
970     mrl_combo->SetSelection( mrl_combo->GetCount() - 1 );
971
972     if( i_method == OPEN_STREAM )
973     {
974         Hide();
975         if( IsModal() ) EndModal( wxID_OK );
976         return;
977     }
978
979     /* Update the playlist */
980     playlist_t *p_playlist =
981         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
982                                        FIND_ANYWHERE );
983     if( p_playlist == NULL ) return;
984
985     for( int i = 0; i < (int)mrl.GetCount(); i++ )
986     {
987         vlc_bool_t b_start = !i && i_open_arg;
988         playlist_item_t *p_item =
989             playlist_ItemNew( p_intf, (const char*)mrl[i].mb_str(),
990                               (const char *)mrl[i].mb_str() );
991
992         /* Insert options */
993         while( i + 1 < (int)mrl.GetCount() &&
994                ((const char *)mrl[i + 1].mb_str())[0] == ':' )
995         {
996             playlist_ItemAddOption( p_item, mrl[i + 1].mb_str() );
997             i++;
998         }
999
1000         /* Get the options from the subtitles dialog */
1001         if( subsfile_checkbox->IsChecked() && subsfile_mrl.GetCount() )
1002         {
1003             for( int j = 0; j < (int)subsfile_mrl.GetCount(); j++ )
1004             {
1005                 playlist_ItemAddOption( p_item, subsfile_mrl[j].mb_str() );
1006             }
1007         }
1008
1009         /* Get the options from the stream output dialog */
1010         if( sout_checkbox->IsChecked() && sout_mrl.GetCount() )
1011         {
1012             for( int j = 0; j < (int)sout_mrl.GetCount(); j++ )
1013             {
1014                 playlist_ItemAddOption( p_item, sout_mrl[j].mb_str() );
1015             }
1016         }
1017
1018         int i_id = playlist_AddItem( p_playlist, p_item,
1019                                      PLAYLIST_APPEND, PLAYLIST_END );
1020
1021         if( b_start )
1022         {
1023             int i_pos = playlist_GetPositionById( p_playlist , i_id );
1024             playlist_Command( p_playlist, PLAYLIST_GOTO, i_pos );
1025         }
1026     }
1027
1028     vlc_object_release( p_playlist );
1029
1030     Hide();
1031
1032     if( IsModal() ) EndModal( wxID_OK );
1033 }
1034
1035 void OpenDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
1036 {
1037     Hide();
1038
1039     if( IsModal() ) EndModal( wxID_CANCEL );
1040 }
1041
1042 void OpenDialog::OnPageChange( wxNotebookEvent& event )
1043 {
1044     UpdateMRL( event.GetSelection() );
1045 }
1046
1047 void OpenDialog::OnMRLChange( wxCommandEvent& event )
1048 {
1049     //mrl = SeparateEntries( event.GetString() );
1050 }
1051
1052 /*****************************************************************************
1053  * File panel event methods.
1054  *****************************************************************************/
1055 void OpenDialog::OnFilePanelChange( wxCommandEvent& WXUNUSED(event) )
1056 {
1057     UpdateMRL( FILE_ACCESS );
1058 }
1059
1060 void OpenDialog::OnFileBrowse( wxCommandEvent& WXUNUSED(event) )
1061 {
1062     if( file_dialog == NULL )
1063         file_dialog = new wxFileDialog( this, wxU(_("Open File")),
1064             wxT(""), wxT(""), wxT("*"), wxOPEN | wxMULTIPLE );
1065
1066     if( file_dialog && file_dialog->ShowModal() == wxID_OK )
1067     {
1068         wxArrayString paths;
1069         wxString path;
1070
1071         file_dialog->GetPaths( paths );
1072
1073         for( size_t i = 0; i < paths.GetCount(); i++ )
1074         {
1075             if( paths[i].Find( wxT(' ') ) >= 0 )
1076                 path += wxT("\"") + paths[i] + wxT("\" ");
1077             else
1078                 path += paths[i] + wxT(" ");
1079         }
1080
1081         file_combo->SetValue( path );
1082         file_combo->Append( path );
1083         if( file_combo->GetCount() > 10 ) file_combo->Delete( 0 );
1084         UpdateMRL( FILE_ACCESS );
1085     }
1086 }
1087
1088 /*****************************************************************************
1089  * Disc panel event methods.
1090  *****************************************************************************/
1091 void OpenDialog::OnDiscPanelChange( wxCommandEvent& event )
1092 {
1093     UpdateMRL( DISC_ACCESS );
1094 }
1095
1096 void OpenDialog::OnDiscDeviceChange( wxCommandEvent& event )
1097 {
1098     char *psz_device;
1099
1100     switch( disc_type->GetSelection() )
1101     {
1102         case 3:
1103             psz_device = config_GetPsz( p_intf, "cd-audio" );
1104             break;
1105
1106         case 2:
1107             psz_device = config_GetPsz( p_intf, "vcd" );
1108             break;
1109
1110         default:
1111             psz_device = config_GetPsz( p_intf, "dvd" );
1112             break;
1113     }
1114
1115     if ( !psz_device ) psz_device = "";
1116
1117     if( disc_device->GetValue().Cmp( wxL2U( psz_device ) ) )
1118     {
1119         b_disc_device_changed = true;
1120     }
1121
1122     UpdateMRL( DISC_ACCESS );
1123 }
1124
1125 void OpenDialog::OnDiscTypeChange( wxCommandEvent& WXUNUSED(event) )
1126 {
1127     char *psz_device = NULL;
1128     int  i_selection = 1; /* Default Title/Track selection number*/
1129
1130     switch( disc_type->GetSelection() )
1131     {
1132
1133     case 0: /* DVD with menus */
1134     case 4: /* DVD with menus (dvdnav) */
1135         i_selection=0;
1136         /* Fall through... */
1137
1138     case 1: /* DVD of some sort */
1139         psz_device = config_GetPsz( p_intf, "dvd" );
1140         if( !b_disc_device_changed )
1141         {
1142             if( psz_device )
1143                 disc_device->SetValue( wxL2U(psz_device) );
1144             else
1145                 disc_device->SetValue( wxT("") );
1146
1147             disc_title_label->SetLabel ( wxU(_("Title")) );
1148         }
1149         disc_title->SetRange( i_selection, 255 );
1150         disc_title->SetValue( i_selection );
1151
1152         disc_chapter->SetRange( 1, 255 );
1153         disc_chapter->SetValue( 1 );
1154         disc_chapter_label->SetLabel ( wxU(_("Chapter")) );
1155
1156         break;
1157
1158     case 2:  /* VCD of some sort */
1159         psz_device = config_GetPsz( p_intf, "vcd" );
1160         if( !b_disc_device_changed )
1161         {
1162             if( psz_device )
1163                 disc_device->SetValue( wxL2U(psz_device) );
1164             else
1165                 disc_device->SetValue( wxT("") );
1166         }
1167
1168         /* There are at most 98, tracks in a VCD, 999 Segments, 500 entries
1169            I don't know what the limit is for LIDs, 999 is probably safe
1170            though.
1171
1172            FIXME: it would be better however to get the information for
1173            this particular Media possibly from the General Info area.
1174          */
1175 #ifdef HAVE_VCDX
1176         disc_title_label->SetLabel ( config_GetInt( p_intf, "vcdx-PBC"  )
1177                                      ? wxT("Playback LID") : wxT("Entry") );
1178         disc_title->SetRange( 0, 999 );
1179         i_selection = 0;
1180 #else
1181         disc_title_label->SetLabel ( wxU(_("Track")) );
1182         disc_title->SetRange( 1, 98 );
1183 #endif
1184         disc_title->SetValue( i_selection );
1185
1186         /* We use the chapter to set subtitle number */
1187         disc_chapter_label->SetLabel ( wxU(_("Subtitle")) );
1188         disc_chapter->SetRange( -1, 4 );
1189         disc_chapter->SetValue( config_GetInt( p_intf, "spu-channel" ) );
1190         break;
1191
1192     case 3: /* CD-DA */
1193         psz_device = config_GetPsz( p_intf, "cd-audio" );
1194         if( !b_disc_device_changed )
1195         {
1196             if( psz_device )
1197                 disc_device->SetValue( wxL2U(psz_device) );
1198             else
1199                 disc_device->SetValue( wxT("") );
1200         }
1201         disc_title_label->SetLabel ( wxU(_("Track")) );
1202 #ifdef HAVE_CDDAX
1203         i_selection = 0;
1204 #endif
1205        /* There are at most 99 tracks in a CD-DA */
1206         disc_title->SetRange( i_selection, 99 );
1207         disc_title->SetValue( i_selection );
1208         break;
1209     default:
1210         msg_Err( p_intf, "invalid Disc type selection (%d)",
1211                  disc_type->GetSelection() );
1212         break;
1213     }
1214
1215     if( psz_device ) free( psz_device );
1216
1217     UpdateMRL( DISC_ACCESS );
1218 }
1219
1220 /*****************************************************************************
1221  * Net panel event methods.
1222  *****************************************************************************/
1223 void OpenDialog::OnNetPanelChange( wxCommandEvent& event )
1224 {
1225     if( event.GetId() >= NetPort1_Event && event.GetId() <= NetPort3_Event )
1226     {
1227         i_net_ports[event.GetId() - NetPort1_Event] = event.GetInt();
1228     }
1229
1230     UpdateMRL( NET_ACCESS );
1231 }
1232
1233 void OpenDialog::OnNetTypeChange( wxCommandEvent& event )
1234 {
1235     int i;
1236
1237     i_net_type = event.GetId() - NetRadio1_Event;
1238
1239     for(i=0; i<4; i++)
1240     {
1241         net_radios[i]->SetValue( event.GetId() == (NetRadio1_Event+i) );
1242         net_subpanels[i]->Enable( event.GetId() == (NetRadio1_Event+i) );
1243     }
1244
1245     UpdateMRL( NET_ACCESS );
1246 }
1247
1248 /*****************************************************************************
1249  * Subtitles file event methods.
1250  *****************************************************************************/
1251 void OpenDialog::OnSubsFileEnable( wxCommandEvent& event )
1252 {
1253     subsfile_button->Enable( event.GetInt() != 0 );
1254 }
1255
1256 void OpenDialog::OnSubsFileSettings( wxCommandEvent& WXUNUSED(event) )
1257 {
1258     /* Show/hide the open dialog */
1259     if( subsfile_dialog == NULL )
1260         subsfile_dialog = new SubsFileDialog( p_intf, this );
1261
1262     if( subsfile_dialog && subsfile_dialog->ShowModal() == wxID_OK )
1263     {
1264         subsfile_mrl.Empty();
1265         subsfile_mrl.Add( wxString(wxT("sub-file=")) +
1266                           subsfile_dialog->file_combo->GetValue() );
1267         if( subsfile_dialog->encoding_combo )
1268             subsfile_mrl.Add( wxString(wxT("subsdec-encoding=")) +
1269                               subsfile_dialog->encoding_combo->GetValue() );
1270         subsfile_mrl.Add( wxString::Format( wxT("sub-delay=%i"),
1271                           subsfile_dialog->delay_spinctrl->GetValue() ) );
1272         subsfile_mrl.Add( wxString::Format( wxT("sub-fps=%i"),
1273                           subsfile_dialog->fps_spinctrl->GetValue() ) );
1274     }
1275 }
1276
1277 /*****************************************************************************
1278  * Stream output event methods.
1279  *****************************************************************************/
1280 void OpenDialog::OnSoutEnable( wxCommandEvent& event )
1281 {
1282     sout_button->Enable( event.GetInt() != 0 );
1283 }
1284
1285 void OpenDialog::OnSoutSettings( wxCommandEvent& WXUNUSED(event) )
1286 {
1287     /* Show/hide the open dialog */
1288     if( sout_dialog == NULL )
1289         sout_dialog = new SoutDialog( p_intf, this );
1290
1291     if( sout_dialog && sout_dialog->ShowModal() == wxID_OK )
1292     {
1293         sout_mrl = sout_dialog->GetOptions();
1294     }
1295 }
1296
1297 /*****************************************************************************
1298  * Utility functions.
1299  *****************************************************************************/
1300 wxArrayString SeparateEntries( wxString entries )
1301 {
1302     vlc_bool_t b_quotes_mode = VLC_FALSE;
1303
1304     wxArrayString entries_array;
1305     wxString entry;
1306
1307     wxStringTokenizer token( entries, wxT(" \t\r\n\""), wxTOKEN_RET_DELIMS );
1308
1309     while( token.HasMoreTokens() )
1310     {
1311         entry += token.GetNextToken();
1312
1313         if( entry.IsEmpty() ) continue;
1314
1315         if( !b_quotes_mode && entry.Last() == wxT('\"') )
1316         {
1317             /* Enters quotes mode */
1318             entry.RemoveLast();
1319             b_quotes_mode = VLC_TRUE;
1320         }
1321         else if( b_quotes_mode && entry.Last() == wxT('\"') )
1322         {
1323             /* Finished the quotes mode */
1324             entry.RemoveLast();
1325             b_quotes_mode = VLC_FALSE;
1326         }
1327         else if( !b_quotes_mode && entry.Last() != wxT('\"') )
1328         {
1329             /* we found a non-quoted standalone string */
1330             if( token.HasMoreTokens() ||
1331                 entry.Last() == wxT(' ') || entry.Last() == wxT('\t') ||
1332                 entry.Last() == wxT('\r') || entry.Last() == wxT('\n') )
1333                 entry.RemoveLast();
1334             if( !entry.IsEmpty() ) entries_array.Add( entry );
1335             entry.Empty();
1336         }
1337         else
1338         {;}
1339     }
1340
1341     if( !entry.IsEmpty() ) entries_array.Add( entry );
1342
1343     return entries_array;
1344 }