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