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