]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/open.cpp
String review, as promised :)
[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:
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         case 1:
692           disc_chapter->Enable();
693           disc_chapter_label->Enable();
694           mrltemp = wxT("dvdsimple://")
695                   + disc_device->GetValue()
696                   + wxString::Format( wxT("@%d:%d"),
697                                       disc_title->GetValue(),
698                                       disc_chapter->GetValue() );
699           break;
700         case 2:
701           disc_chapter->Disable();
702           disc_chapter_label->Disable();
703 #ifdef HAVE_VCDX
704           if ( disc_title->GetValue() )
705             mrltemp = wxT("vcdx://")
706               + disc_device->GetValue()
707               + wxString::Format( wxT("@%c%d"),
708                                   config_GetInt( p_intf, "vcdx-PBC"  )
709                                   ? 'P' : 'E',
710                                   disc_title->GetValue()
711                                   );
712           else
713             mrltemp = wxT("vcdx://")
714                   + disc_device->GetValue();
715 #else
716           mrltemp = wxT("vcd://")
717                   + disc_device->GetValue()
718                   + wxString::Format( wxT("@%d"),
719                                       disc_title->GetValue() );
720 #endif
721           break;
722         case 3:
723           disc_chapter->Disable();
724           disc_chapter_label->Disable();
725 #ifdef HAVE_CDDAX
726           if ( disc_title->GetValue() )
727             mrltemp =  wxT("cddax://")
728                   + disc_device->GetValue()
729                   + wxString::Format( wxT("@T%d"),
730                                       disc_title->GetValue() );
731           else
732             mrltemp = wxT("cddax://")
733                   + disc_device->GetValue();
734
735 #else
736           mrltemp =  wxT("cdda://")
737                   + disc_device->GetValue()
738                   + wxString::Format( wxT("@%d"),
739                                       disc_title->GetValue() );
740 #endif
741           break;
742         default: ;
743           msg_Err( p_intf, "invalid selection (%d)",
744                    disc_type->GetSelection() );
745         }
746
747         break;
748     case NET_ACCESS:
749         switch( i_net_type )
750         {
751         case 0:
752             mrltemp = wxT("udp") + demux + wxT("://");
753             if ( net_ipv6->GetValue() )
754             {
755                 mrltemp += wxT("@[::]");
756             }
757             if( i_net_ports[0] !=
758                 config_GetInt( p_intf, "server-port" ) )
759             {
760                 mrltemp += wxString::Format( wxT("@:%d"), i_net_ports[0] );
761             }
762             break;
763
764         case 1:
765             mrltemp = wxT("udp") + demux + wxT("://@");
766             if ((net_addrs[1]->GetLineText(0).Find (':') != -1)
767                 && (net_addrs[1]->GetLineText(0)[0u] != '['))
768             {
769                 /* automatically adds '[' and ']' to IPv6 addresses */
770                 mrltemp += wxT("[") + net_addrs[1]->GetLineText(0)
771                          + wxT("]");
772             }
773             else
774             {
775                 mrltemp += net_addrs[1]->GetLineText(0);
776             }
777             if( i_net_ports[1] != config_GetInt( p_intf, "server-port" ) )
778             {
779                 mrltemp += wxString::Format( wxT(":%d"), i_net_ports[1] );
780             }
781             break;
782
783         case 2:
784             /* http access */
785             if( net_addrs[2]->GetLineText(0).Find(wxT("http://")) )
786             {
787                 mrltemp = wxT("http") + demux + wxT("://");
788             }
789             mrltemp += net_addrs[2]->GetLineText(0);
790             break;
791
792         case 3:
793             /* RTSP access */
794             if( net_addrs[3]->GetLineText(0).Find(wxT("rtsp://")) != 0 )
795             {
796                 mrltemp = wxT("rtsp") + demux + wxT("://");
797             }
798             mrltemp += net_addrs[3]->GetLineText(0);
799             break;
800         }
801         break;
802
803 #ifndef WIN32
804     case V4L_ACCESS:
805         mrltemp = ( video_type->GetSelection() == 0 ? wxT("v4l") :
806                     video_type->GetSelection() == 1 ? wxT("v4l") :
807                     video_type->GetSelection() == 2 ? wxT("pvr") :
808                                                       wxT("kfir") )
809             + demux + wxT(":")
810             + video_device->GetLineText( 0 );
811
812         if( video_type->GetSelection() == 1 )
813         {
814             mrltemp += wxString::Format( wxT(":channel=%d"),
815                                          video_channel->GetValue() );
816         }
817
818         if ( /* v4l_dialog != NULL && */ !v4l_mrl.IsEmpty() )
819         {
820             mrltemp += v4l_mrl[0];
821         }
822
823         break;
824 #endif
825
826     default:
827         {
828             int i_item = i_access_method - MAX_ACCESS;
829
830             if( i_item < 0 || i_item >= (int)input_tab_array.GetCount() )
831                 break;
832
833             AutoBuiltPanel *input_panel = input_tab_array.Item( i_item );
834
835             mrltemp = input_panel->name + wxT("://");
836
837             for( int i=0; i < (int)input_panel->config_array.GetCount(); i++ )
838             {
839                 ConfigControl *control = input_panel->config_array.Item(i);
840                 mrltemp += wxT(" :") + control->GetName() + wxT("=");
841
842                 switch( control->GetType() )
843                 {
844                 case CONFIG_ITEM_STRING:
845                 case CONFIG_ITEM_FILE:
846                 case CONFIG_ITEM_DIRECTORY:
847                 case CONFIG_ITEM_MODULE:
848                     mrltemp += wxT("\"") + control->GetPszValue() + wxT("\"");
849                     break;
850                 case CONFIG_ITEM_INTEGER:
851                 case CONFIG_ITEM_BOOL:
852                     mrltemp +=
853                         wxString::Format( wxT("%i"), control->GetIntValue() );
854                     break;
855                 case CONFIG_ITEM_FLOAT:
856                     mrltemp +=
857                         wxString::Format( wxT("%f"), control->GetFloatValue());
858                     break;
859                 }
860             }
861         }
862         break;
863     }
864
865     mrl_combo->SetValue( mrltemp );
866 }
867
868 /*****************************************************************************
869  * Events methods.
870  *****************************************************************************/
871 void OpenDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
872 {
873     mrl = SeparateEntries( mrl_combo->GetValue() );
874     mrl_combo->Append( mrl_combo->GetValue() );
875     if( mrl_combo->GetCount() > 10 ) mrl_combo->Delete( 0 );
876     mrl_combo->SetSelection( mrl_combo->GetCount() - 1 );
877
878     if( i_method == OPEN_STREAM )
879     {
880         Hide();
881         return;
882     }
883
884     /* Update the playlist */
885     playlist_t *p_playlist =
886         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
887                                        FIND_ANYWHERE );
888     if( p_playlist == NULL ) return;
889
890     for( int i = 0; i < (int)mrl.GetCount(); i++ )
891     {
892         vlc_bool_t b_start = !i && i_open_arg;
893         playlist_item_t *p_item =
894             playlist_ItemNew( p_intf, (const char*)mrl[i].mb_str(),
895                               (const char *)mrl[i].mb_str() );
896
897         /* Insert options */
898         while( i + 1 < (int)mrl.GetCount() &&
899                ((const char *)mrl[i + 1].mb_str())[0] == ':' )
900         {
901             playlist_ItemAddOption( p_item, mrl[i + 1].mb_str() );
902             i++;
903         }
904
905         /* Get the options from the subtitles dialog */
906         if( subsfile_checkbox->IsChecked() && subsfile_mrl.GetCount() )
907         {
908             for( int j = 0; j < (int)subsfile_mrl.GetCount(); j++ )
909             {
910                 playlist_ItemAddOption( p_item, subsfile_mrl[j].mb_str() );
911             }
912         }
913
914         /* Get the options from the stream output dialog */
915         if( sout_checkbox->IsChecked() && sout_mrl.GetCount() )
916         {
917             for( int j = 0; j < (int)sout_mrl.GetCount(); j++ )
918             {
919                 playlist_ItemAddOption( p_item, sout_mrl[j].mb_str() );
920             }
921         }
922
923         int i_id = playlist_AddItem( p_playlist, p_item,
924                                      PLAYLIST_APPEND, PLAYLIST_END );
925
926         if( b_start )
927         {
928             int i_pos = playlist_GetPositionById( p_playlist , i_id );
929             playlist_Command( p_playlist, PLAYLIST_GOTO, i_pos );
930         }
931     }
932
933     //TogglePlayButton( PLAYING_S );
934
935     vlc_object_release( p_playlist );
936
937     Hide();
938 }
939
940 void OpenDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
941 {
942     Hide();
943 }
944
945 void OpenDialog::OnPageChange( wxNotebookEvent& event )
946 {
947     UpdateMRL( event.GetSelection() );
948 }
949
950 void OpenDialog::OnMRLChange( wxCommandEvent& event )
951 {
952     //mrl = SeparateEntries( event.GetString() );
953 }
954
955 /*****************************************************************************
956  * File panel event methods.
957  *****************************************************************************/
958 void OpenDialog::OnFilePanelChange( wxCommandEvent& WXUNUSED(event) )
959 {
960     UpdateMRL( FILE_ACCESS );
961 }
962
963 void OpenDialog::OnFileBrowse( wxCommandEvent& WXUNUSED(event) )
964 {
965     if( file_dialog == NULL )
966         file_dialog = new wxFileDialog( this, wxU(_("Open File")),
967             wxT(""), wxT(""), wxT("*"), wxOPEN | wxMULTIPLE );
968
969     if( file_dialog && file_dialog->ShowModal() == wxID_OK )
970     {
971         wxArrayString paths;
972         wxString path;
973
974         file_dialog->GetPaths( paths );
975
976         for( size_t i = 0; i < paths.GetCount(); i++ )
977         {
978             if( paths[i].Find( wxT(' ') ) >= 0 )
979                 path += wxT("\"") + paths[i] + wxT("\" ");
980             else
981                 path += paths[i] + wxT(" ");
982         }
983
984         file_combo->SetValue( path );
985         file_combo->Append( path );
986         if( file_combo->GetCount() > 10 ) file_combo->Delete( 0 );
987         UpdateMRL( FILE_ACCESS );
988     }
989 }
990
991 /*****************************************************************************
992  * Disc panel event methods.
993  *****************************************************************************/
994 void OpenDialog::OnDiscPanelChange( wxCommandEvent& event )
995 {
996     UpdateMRL( DISC_ACCESS );
997 }
998
999 void OpenDialog::OnDiscDeviceChange( wxCommandEvent& event )
1000 {
1001     char *psz_device;
1002
1003     switch( disc_type->GetSelection() )
1004     {
1005         case 3:
1006             psz_device = config_GetPsz( p_intf, "cd-audio" );
1007             break;
1008
1009         case 2:
1010             psz_device = config_GetPsz( p_intf, "vcd" );
1011             break;
1012
1013         default:
1014             psz_device = config_GetPsz( p_intf, "dvd" );
1015             break;
1016     }
1017
1018     if ( !psz_device ) psz_device = "";
1019
1020     if( disc_device->GetValue().Cmp( wxL2U( psz_device ) ) )
1021     {
1022         b_disc_device_changed = true;
1023     }
1024
1025     UpdateMRL( DISC_ACCESS );
1026 }
1027
1028 void OpenDialog::OnDiscTypeChange( wxCommandEvent& WXUNUSED(event) )
1029 {
1030     char *psz_device = NULL;
1031     int  i_selection = 1; /* Default Title/Track selection number*/
1032
1033     switch( disc_type->GetSelection() )
1034     {
1035
1036     case 0: /* DVD with menues */
1037       i_selection=0;
1038       /* Fall through... */
1039
1040     case 1: /* DVD of some sort */
1041         psz_device = config_GetPsz( p_intf, "dvd" );
1042         if( !b_disc_device_changed )
1043         {
1044             if( psz_device )
1045                 disc_device->SetValue( wxL2U(psz_device) );
1046             else
1047                 disc_device->SetValue( wxT("") );
1048
1049             disc_title_label->SetLabel ( wxU(_("Title")) );
1050         }
1051         disc_title->SetRange( i_selection, 255 );
1052         disc_title->SetValue( i_selection );
1053         break;
1054
1055     case 2:  /* VCD of some sort */
1056         psz_device = config_GetPsz( p_intf, "vcd" );
1057         if( !b_disc_device_changed )
1058         {
1059             if( psz_device )
1060                 disc_device->SetValue( wxL2U(psz_device) );
1061             else
1062                 disc_device->SetValue( wxT("") );
1063         }
1064
1065         /* There are at most 98, tracks in a VCD, 999 Segments, 500 entries
1066            I don't know what the limit is for LIDs, 999 is probably safe
1067            though.
1068
1069            FIXME: it would be better however to get the information for
1070            this particular Media possibly from the General Info area.
1071          */
1072 #ifdef HAVE_VCDX
1073         disc_title_label->SetLabel ( config_GetInt( p_intf, "vcdx-PBC"  )
1074                                      ? wxT("Playback LID") : wxT("Entry") );
1075         disc_title->SetRange( 0, 999 );
1076         i_selection = 0;
1077 #else
1078         disc_title_label->SetLabel ( wxU(_("Track")) );
1079         disc_title->SetRange( 1, 98 );
1080 #endif
1081         disc_title->SetValue( i_selection );
1082         break;
1083
1084     case 3: /* CD-DA */
1085         psz_device = config_GetPsz( p_intf, "cd-audio" );
1086         if( !b_disc_device_changed )
1087         {
1088             if( psz_device )
1089                 disc_device->SetValue( wxL2U(psz_device) );
1090             else
1091                 disc_device->SetValue( wxT("") );
1092         }
1093         disc_title_label->SetLabel ( wxU(_("Track")) );
1094 #ifdef HAVE_CDDAX
1095         i_selection = 0;
1096 #endif
1097        /* There are at most 99 tracks in a CD-DA */
1098         disc_title->SetRange( i_selection, 99 );
1099         disc_title->SetValue( i_selection );
1100         break;
1101     default:
1102         msg_Err( p_intf, "invalid Disc type selection (%d)",
1103                  disc_type->GetSelection() );
1104         break;
1105     }
1106
1107     if( psz_device ) free( psz_device );
1108
1109     disc_chapter->SetRange( 1, 255 );
1110     disc_chapter->SetValue( 1 );
1111
1112     UpdateMRL( DISC_ACCESS );
1113 }
1114
1115 /*****************************************************************************
1116  * Net panel event methods.
1117  *****************************************************************************/
1118 void OpenDialog::OnNetPanelChange( wxCommandEvent& event )
1119 {
1120     if( event.GetId() >= NetPort1_Event && event.GetId() <= NetPort3_Event )
1121     {
1122         i_net_ports[event.GetId() - NetPort1_Event] = event.GetInt();
1123     }
1124
1125     UpdateMRL( NET_ACCESS );
1126 }
1127
1128 void OpenDialog::OnNetTypeChange( wxCommandEvent& event )
1129 {
1130     int i;
1131
1132     i_net_type = event.GetId() - NetRadio1_Event;
1133
1134     for(i=0; i<4; i++)
1135     {
1136         net_radios[i]->SetValue( event.GetId() == (NetRadio1_Event+i) );
1137         net_subpanels[i]->Enable( event.GetId() == (NetRadio1_Event+i) );
1138     }
1139
1140     UpdateMRL( NET_ACCESS );
1141 }
1142
1143 #ifndef WIN32
1144 /*****************************************************************************
1145  * v4l panel event methods.
1146  *****************************************************************************/
1147 void OpenDialog::OnV4LPanelChange( wxCommandEvent& WXUNUSED(event) )
1148 {
1149     UpdateMRL( V4L_ACCESS );
1150 }
1151
1152 void OpenDialog::OnV4LTypeChange( wxCommandEvent& WXUNUSED(event) )
1153 {
1154     video_device->SetValue( wxT( "/dev/video" ) );
1155
1156     v4l_button->Enable();
1157     video_channel->Disable();
1158
1159     switch( video_type->GetSelection() )
1160     {
1161         case 1:
1162             video_channel->Enable();
1163             video_channel->SetRange( 0, 255 );
1164            break;
1165         case 3:
1166             v4l_button->Disable();
1167             break;
1168         default:
1169             break;
1170     }
1171
1172     UpdateMRL( V4L_ACCESS );
1173 }
1174
1175 void OpenDialog::OnV4LSettingsChange( wxCommandEvent& WXUNUSED(event) )
1176 {
1177     /* Show/hide the open dialog */
1178     if( v4l_dialog == NULL )
1179         v4l_dialog = new V4LDialog( p_intf, this );
1180
1181     if( v4l_dialog && v4l_dialog->ShowModal() == wxID_OK )
1182     {
1183         v4l_mrl = v4l_dialog->GetOptions();
1184     }
1185
1186     UpdateMRL( V4L_ACCESS );
1187 }
1188 #endif
1189
1190 /*****************************************************************************
1191  * Subtitles file event methods.
1192  *****************************************************************************/
1193 void OpenDialog::OnSubsFileEnable( wxCommandEvent& event )
1194 {
1195     subsfile_button->Enable( event.GetInt() != 0 );
1196 }
1197
1198 void OpenDialog::OnSubsFileSettings( wxCommandEvent& WXUNUSED(event) )
1199 {
1200     /* Show/hide the open dialog */
1201     if( subsfile_dialog == NULL )
1202         subsfile_dialog = new SubsFileDialog( p_intf, this );
1203
1204     if( subsfile_dialog && subsfile_dialog->ShowModal() == wxID_OK )
1205     {
1206         subsfile_mrl.Empty();
1207         subsfile_mrl.Add( wxString(wxT("sub-file=")) +
1208                           subsfile_dialog->file_combo->GetValue() );
1209         if( subsfile_dialog->encoding_combo )
1210             subsfile_mrl.Add( wxString(wxT("subsdec-encoding=")) +
1211                               subsfile_dialog->encoding_combo->GetValue() );
1212         subsfile_mrl.Add( wxString::Format( wxT("sub-delay=%i"),
1213                           subsfile_dialog->delay_spinctrl->GetValue() ) );
1214         subsfile_mrl.Add( wxString::Format( wxT("sub-fps=%i"),
1215                           subsfile_dialog->fps_spinctrl->GetValue() ) );
1216     }
1217 }
1218
1219 /*****************************************************************************
1220  * Stream output event methods.
1221  *****************************************************************************/
1222 void OpenDialog::OnSoutEnable( wxCommandEvent& event )
1223 {
1224     sout_button->Enable( event.GetInt() != 0 );
1225 }
1226
1227 void OpenDialog::OnSoutSettings( wxCommandEvent& WXUNUSED(event) )
1228 {
1229     /* Show/hide the open dialog */
1230     if( sout_dialog == NULL )
1231         sout_dialog = new SoutDialog( p_intf, this );
1232
1233     if( sout_dialog && sout_dialog->ShowModal() == wxID_OK )
1234     {
1235         sout_mrl = sout_dialog->GetOptions();
1236     }
1237 }
1238
1239 /*****************************************************************************
1240  * Utility functions.
1241  *****************************************************************************/
1242 wxArrayString SeparateEntries( wxString entries )
1243 {
1244     vlc_bool_t b_quotes_mode = VLC_FALSE;
1245
1246     wxArrayString entries_array;
1247     wxString entry;
1248
1249     wxStringTokenizer token( entries, wxT(" \t\r\n\""), wxTOKEN_RET_DELIMS );
1250
1251     while( token.HasMoreTokens() )
1252     {
1253         entry += token.GetNextToken();
1254
1255         if( entry.IsEmpty() ) continue;
1256
1257         if( !b_quotes_mode && entry.Last() == wxT('\"') )
1258         {
1259             /* Enters quotes mode */
1260             entry.RemoveLast();
1261             b_quotes_mode = VLC_TRUE;
1262         }
1263         else if( b_quotes_mode && entry.Last() == wxT('\"') )
1264         {
1265             /* Finished the quotes mode */
1266             entry.RemoveLast();
1267             if( !entry.IsEmpty() ) entries_array.Add( entry );
1268             entry.Empty();
1269             b_quotes_mode = VLC_FALSE;
1270         }
1271         else if( !b_quotes_mode && entry.Last() != wxT('\"') )
1272         {
1273             /* we found a non-quoted standalone string */
1274             if( token.HasMoreTokens() ||
1275                 entry.Last() == wxT(' ') || entry.Last() == wxT('\t') ||
1276                 entry.Last() == wxT('\r') || entry.Last() == wxT('\n') )
1277                 entry.RemoveLast();
1278             if( !entry.IsEmpty() ) entries_array.Add( entry );
1279             entry.Empty();
1280         }
1281         else
1282         {;}
1283     }
1284
1285     if( !entry.IsEmpty() ) entries_array.Add( entry );
1286
1287     return entries_array;
1288 }