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