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