]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/open.cpp
fixed a compilation error
[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.48 2003/12/10 11:04:25 courmisch 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             mrltemp = wxT("udp") + demux + wxT("://");
689             if( i_net_ports[0] !=
690                 config_GetInt( p_intf, "server-port" ) )
691             {
692                 mrltemp += wxString::Format( wxT("@:%d"), i_net_ports[0] );
693             }
694             break;
695
696         case 1:
697             mrltemp = wxT("udp") + demux + wxT("://@");
698             if ((net_addrs[1]->GetLineText(0).Find (':') != -1)
699                 && (net_addrs[1]->GetLineText(0)[0u] != '['))
700             {
701                 /* automatically adds '[' and ']' to IPv6 addresses */
702                 mrltemp += wxT("[") + net_addrs[1]->GetLineText(0)
703                          + wxT("]");
704             }
705             else
706             {
707                 mrltemp += net_addrs[1]->GetLineText(0);
708             }
709             if( i_net_ports[1] != config_GetInt( p_intf, "server-port" ) )
710             {
711                 mrltemp += wxString::Format( wxT(":%d"), i_net_ports[1] );
712             }
713             break;
714
715         case 2:
716             /* http access */
717             mrltemp = wxT("http") + demux + wxT("://") +
718                       net_addrs[2]->GetLineText(0);
719             break;
720         }
721         break;
722
723 #ifndef WIN32
724     case V4L_ACCESS:
725         mrltemp = ( video_type->GetSelection() == 0 ? wxT("v4l") :
726                     video_type->GetSelection() == 1 ? wxT("v4l") :
727                     video_type->GetSelection() == 2 ? wxT("pvr") :
728                                                       wxT("kfir") )
729             + demux + wxT(":")
730             + video_device->GetLineText( 0 );
731
732         if( video_type->GetSelection() == 1 )
733         {
734             mrltemp += wxString::Format( wxT(":channel=%d"),
735                                          video_channel->GetValue() );
736         }
737
738         if ( /* v4l_dialog != NULL && */ !v4l_mrl.IsEmpty() )
739         {
740             mrltemp += v4l_mrl[0];
741         }
742
743         break;
744 #endif
745
746     default:
747         {
748             int i_item = i_access_method - MAX_ACCESS;
749
750             if( i_item < 0 || i_item >= (int)input_tab_array.GetCount() )
751                 break;
752
753             AutoBuiltPanel *input_panel = input_tab_array.Item( i_item );
754
755             mrltemp = input_panel->name + wxT("://");
756
757             for( int i=0; i < (int)input_panel->config_array.GetCount(); i++ )
758             {
759                 ConfigControl *control = input_panel->config_array.Item(i);
760                 mrltemp += wxT(" :") + control->GetName() + wxT("=");
761
762                 switch( control->GetType() )
763                 {
764                 case CONFIG_ITEM_STRING:
765                 case CONFIG_ITEM_FILE:
766                 case CONFIG_ITEM_DIRECTORY:
767                 case CONFIG_ITEM_MODULE:
768                     mrltemp += wxT("\"") + control->GetPszValue() + wxT("\"");
769                     break;
770                 case CONFIG_ITEM_INTEGER:
771                 case CONFIG_ITEM_BOOL:
772                     mrltemp +=
773                         wxString::Format( wxT("%i"), control->GetIntValue() );
774                     break;
775                 case CONFIG_ITEM_FLOAT:
776                     mrltemp +=
777                         wxString::Format( wxT("%f"), control->GetFloatValue());
778                     break;
779                 }
780             }
781         }
782         break;
783     }
784
785     mrl_combo->SetValue( mrltemp );
786 }
787
788 /*****************************************************************************
789  * Events methods.
790  *****************************************************************************/
791 void OpenDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
792 {
793     mrl = SeparateEntries( mrl_combo->GetValue() );
794     mrl_combo->Append( mrl_combo->GetValue() );
795     if( mrl_combo->GetCount() > 10 ) mrl_combo->Delete( 0 );
796     mrl_combo->SetSelection( mrl_combo->GetCount() - 1 );
797
798     if( i_method == OPEN_STREAM )
799     {
800         Hide();
801         return;
802     }
803
804     /* Update the playlist */
805     playlist_t *p_playlist =
806         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
807                                        FIND_ANYWHERE );
808     if( p_playlist == NULL ) return;
809
810     for( int i = 0; i < (int)mrl.GetCount(); i++ )
811     {
812         int i_options = 0, i_total_options;
813         char **ppsz_options = NULL;
814
815         /* Count the input options */
816         while( i + i_options + 1 < (int)mrl.GetCount() &&
817                ((const char *)mrl[i + i_options + 1].mb_str())[0] == ':' )
818         {
819             i_options++;
820         }
821
822         /* Allocate ppsz_options */
823         for( int j = 0; j < i_options; j++ )
824         {
825             if( !ppsz_options )
826                 ppsz_options = (char **)malloc( sizeof(char *) * i_options );
827
828             ppsz_options[j] = strdup( mrl[i + j  + 1].mb_str() );
829         }
830
831         i_total_options = i_options;
832
833         /* Get the options from the subtitles dialog */
834         if( subsfile_checkbox->IsChecked() && subsfile_mrl.GetCount() )
835         {
836             ppsz_options = (char **)realloc( ppsz_options, sizeof(char *) *
837                                (i_total_options + subsfile_mrl.GetCount()) );
838
839             for( int j = 0; j < (int)subsfile_mrl.GetCount(); j++ )
840             {
841                 ppsz_options[i_total_options + j] =
842                     strdup( subsfile_mrl[j].mb_str() );
843             }
844
845             i_total_options += subsfile_mrl.GetCount();
846         }
847
848         /* Get the options from the stream output dialog */
849         if( sout_checkbox->IsChecked() && sout_mrl.GetCount() )
850         {
851             ppsz_options = (char **)realloc( ppsz_options, sizeof(char *) *
852                                (i_total_options + sout_mrl.GetCount()) );
853
854             for( int j = 0; j < (int)sout_mrl.GetCount(); j++ )
855             {
856                 ppsz_options[i_total_options + j] =
857                     strdup( sout_mrl[j].mb_str() );
858             }
859
860             i_total_options += sout_mrl.GetCount();
861
862         }
863
864         playlist_Add( p_playlist, (const char *)mrl[i].mb_str(),
865                       (const char **)ppsz_options, i_total_options,
866                       PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );
867
868         /* clean up */
869         for( int j = 0; j < i_total_options; j++ )
870             free( ppsz_options[j] );
871         if( ppsz_options ) free( ppsz_options );
872
873         i += i_options;
874     }
875
876     //TogglePlayButton( PLAYING_S );
877
878     vlc_object_release( p_playlist );
879
880     Hide();
881 }
882
883 void OpenDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
884 {
885     Hide();
886 }
887
888 void OpenDialog::OnPageChange( wxNotebookEvent& event )
889 {
890     UpdateMRL( event.GetSelection() );
891 }
892
893 void OpenDialog::OnMRLChange( wxCommandEvent& event )
894 {
895     //mrl = SeparateEntries( event.GetString() );
896 }
897
898 /*****************************************************************************
899  * File panel event methods.
900  *****************************************************************************/
901 void OpenDialog::OnFilePanelChange( wxCommandEvent& WXUNUSED(event) )
902 {
903     UpdateMRL( FILE_ACCESS );
904 }
905
906 void OpenDialog::OnFileBrowse( wxCommandEvent& WXUNUSED(event) )
907 {
908     if( file_dialog == NULL )
909         file_dialog = new wxFileDialog( this, wxU(_("Open file")),
910             wxT(""), wxT(""), wxT("*"), wxOPEN | wxMULTIPLE );
911
912     if( file_dialog && file_dialog->ShowModal() == wxID_OK )
913     {
914         wxArrayString paths;
915         wxString path;
916
917         file_dialog->GetPaths( paths );
918
919         for( size_t i = 0; i < paths.GetCount(); i++ )
920         {
921             if( paths[i].Find( wxT(' ') ) >= 0 )
922                 path += wxT("\"") + paths[i] + wxT("\" ");
923             else
924                 path += paths[i] + wxT(" ");
925         }
926
927         file_combo->SetValue( path );
928         file_combo->Append( path );
929         if( file_combo->GetCount() > 10 ) file_combo->Delete( 0 );
930         UpdateMRL( FILE_ACCESS );
931     }
932 }
933
934 /*****************************************************************************
935  * Disc panel event methods.
936  *****************************************************************************/
937 void OpenDialog::OnDiscPanelChange( wxCommandEvent& event )
938 {
939     UpdateMRL( DISC_ACCESS );
940 }
941
942 void OpenDialog::OnDiscDeviceChange( wxCommandEvent& event )
943 {
944     char *psz_device;
945
946     switch( disc_type->GetSelection() )
947     {
948         case 3:
949             psz_device = config_GetPsz( p_intf, "cd-audio" );
950             break;
951                                                                                                                            
952         case 2:
953             psz_device = config_GetPsz( p_intf, "vcd" );
954             break;
955                                                                                                                             
956         default:
957             psz_device = config_GetPsz( p_intf, "dvd" );
958             break;
959     }
960
961     if( disc_device->GetValue().Cmp( wxU( psz_device ) ) )
962     {
963         b_disc_device_changed = true;
964     }
965
966     UpdateMRL( DISC_ACCESS );
967 }
968
969 void OpenDialog::OnDiscTypeChange( wxCommandEvent& WXUNUSED(event) )
970 {
971     char *psz_device;
972
973     switch( disc_type->GetSelection() )
974     {
975     case 3:
976         psz_device = config_GetPsz( p_intf, "cd-audio" );
977         if( !b_disc_device_changed )
978         {
979             disc_device->SetValue( psz_device ? wxU(psz_device) : wxT("") );
980         }
981         break;
982
983     case 2:
984         psz_device = config_GetPsz( p_intf, "vcd" );
985         if( !b_disc_device_changed )
986         {
987             disc_device->SetValue( psz_device ? wxU(psz_device) : wxT("") );
988         }
989         break;
990
991     default:
992         psz_device = config_GetPsz( p_intf, "dvd" );
993         if( !b_disc_device_changed )
994         {
995             disc_device->SetValue( psz_device ? wxU(psz_device) : wxT("") );
996         }
997         break;
998     }
999
1000     if( psz_device ) free( psz_device );
1001
1002     switch( disc_type->GetSelection() )
1003     {
1004     case 0:
1005         disc_title->SetRange( 0, 255 );
1006         disc_title->SetValue( 0 );
1007         break;
1008
1009     default:
1010         disc_title->SetRange( 1, 255 );
1011         disc_title->SetValue( 1 );
1012         break;
1013     }
1014
1015     disc_chapter->SetRange( 1, 255 );
1016     disc_chapter->SetValue( 1 );
1017
1018     UpdateMRL( DISC_ACCESS );
1019 }
1020
1021 /*****************************************************************************
1022  * Net panel event methods.
1023  *****************************************************************************/
1024 void OpenDialog::OnNetPanelChange( wxCommandEvent& event )
1025 {
1026     if( event.GetId() >= NetPort1_Event && event.GetId() <= NetPort3_Event )
1027     {
1028         i_net_ports[event.GetId() - NetPort1_Event] = event.GetInt();
1029     }
1030
1031     UpdateMRL( NET_ACCESS );
1032 }
1033
1034 void OpenDialog::OnNetTypeChange( wxCommandEvent& event )
1035 {
1036     int i;
1037
1038     i_net_type = event.GetId() - NetRadio1_Event;
1039
1040     for(i=0; i<3; i++)
1041     {
1042         net_radios[i]->SetValue( event.GetId() == (NetRadio1_Event+i) );
1043         net_subpanels[i]->Enable( event.GetId() == (NetRadio1_Event+i) );
1044     }
1045
1046     UpdateMRL( NET_ACCESS );
1047 }
1048
1049 #ifndef WIN32
1050 /*****************************************************************************
1051  * v4l panel event methods.
1052  *****************************************************************************/
1053 void OpenDialog::OnV4LPanelChange( wxCommandEvent& WXUNUSED(event) )
1054 {
1055     UpdateMRL( V4L_ACCESS );
1056 }
1057
1058 void OpenDialog::OnV4LTypeChange( wxCommandEvent& WXUNUSED(event) )
1059 {
1060     video_device->SetValue( wxU( "/dev/video" ) );
1061
1062     v4l_button->Enable();
1063     video_channel->Disable();
1064
1065     switch( video_type->GetSelection() )
1066     {
1067         case 1:
1068             video_channel->Enable();
1069             video_channel->SetRange( 0, 255 );
1070            break;
1071         case 3:
1072             v4l_button->Disable();
1073             break;
1074         default:
1075             break;
1076     }
1077
1078     UpdateMRL( V4L_ACCESS );
1079 }
1080
1081 void OpenDialog::OnV4LSettingsChange( wxCommandEvent& WXUNUSED(event) )
1082 {
1083     /* Show/hide the open dialog */
1084     if( v4l_dialog == NULL )
1085         v4l_dialog = new V4LDialog( p_intf, this );
1086
1087     if( v4l_dialog && v4l_dialog->ShowModal() == wxID_OK )
1088     {
1089         v4l_mrl = v4l_dialog->GetOptions();
1090     }
1091
1092     UpdateMRL( V4L_ACCESS );
1093 }
1094 #endif
1095
1096 /*****************************************************************************
1097  * Subtitles file event methods.
1098  *****************************************************************************/
1099 void OpenDialog::OnSubsFileEnable( wxCommandEvent& event )
1100 {
1101     subsfile_button->Enable( event.GetInt() != 0 );
1102 }
1103
1104 void OpenDialog::OnSubsFileSettings( wxCommandEvent& WXUNUSED(event) )
1105 {
1106     /* Show/hide the open dialog */
1107     if( subsfile_dialog == NULL )
1108         subsfile_dialog = new SubsFileDialog( p_intf, this );
1109
1110     if( subsfile_dialog && subsfile_dialog->ShowModal() == wxID_OK )
1111     {
1112         subsfile_mrl.Empty();
1113         subsfile_mrl.Add( wxString(wxT("sub-file=")) +
1114                           subsfile_dialog->file_combo->GetValue() );
1115         if( subsfile_dialog->encoding_combo )
1116             subsfile_mrl.Add( wxString(wxT("subsdec-encoding=")) +
1117                               subsfile_dialog->encoding_combo->GetValue() );
1118         subsfile_mrl.Add( wxString::Format( wxT("sub-delay=%i"),
1119                           subsfile_dialog->delay_spinctrl->GetValue() ) );
1120         subsfile_mrl.Add( wxString::Format( wxT("sub-fps=%i"),
1121                           subsfile_dialog->fps_spinctrl->GetValue() ) );
1122     }
1123 }
1124
1125 /*****************************************************************************
1126  * Stream output event methods.
1127  *****************************************************************************/
1128 void OpenDialog::OnSoutEnable( wxCommandEvent& event )
1129 {
1130     sout_button->Enable( event.GetInt() != 0 );
1131 }
1132
1133 void OpenDialog::OnSoutSettings( wxCommandEvent& WXUNUSED(event) )
1134 {
1135     /* Show/hide the open dialog */
1136     if( sout_dialog == NULL )
1137         sout_dialog = new SoutDialog( p_intf, this );
1138
1139     if( sout_dialog && sout_dialog->ShowModal() == wxID_OK )
1140     {
1141         sout_mrl = sout_dialog->GetOptions();
1142     }
1143 }
1144
1145 /*****************************************************************************
1146  * Utility functions.
1147  *****************************************************************************/
1148 wxArrayString SeparateEntries( wxString entries )
1149 {
1150     vlc_bool_t b_quotes_mode = VLC_FALSE;
1151
1152     wxArrayString entries_array;
1153     wxString entry;
1154
1155     wxStringTokenizer token( entries, wxT(" \t\r\n\""), wxTOKEN_RET_DELIMS );
1156
1157     while( token.HasMoreTokens() )
1158     {
1159         entry += token.GetNextToken();
1160
1161         if( entry.IsEmpty() ) continue;
1162
1163         if( !b_quotes_mode && entry.Last() == wxT('\"') )
1164         {
1165             /* Enters quotes mode */
1166             entry.RemoveLast();
1167             b_quotes_mode = VLC_TRUE;
1168         }
1169         else if( b_quotes_mode && entry.Last() == wxT('\"') )
1170         {
1171             /* Finished the quotes mode */
1172             entry.RemoveLast();
1173             if( !entry.IsEmpty() ) entries_array.Add( entry );
1174             entry.Empty();
1175             b_quotes_mode = VLC_FALSE;
1176         }
1177         else if( !b_quotes_mode && entry.Last() != wxT('\"') )
1178         {
1179             /* we found a non-quoted standalone string */
1180             if( token.HasMoreTokens() ||
1181                 entry.Last() == wxT(' ') || entry.Last() == wxT('\t') ||
1182                 entry.Last() == wxT('\r') || entry.Last() == wxT('\n') )
1183                 entry.RemoveLast();
1184             if( !entry.IsEmpty() ) entries_array.Add( entry );
1185             entry.Empty();
1186         }
1187         else
1188         {;}
1189     }
1190
1191     if( !entry.IsEmpty() ) entries_array.Add( entry );
1192
1193     return entries_array;
1194 }