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