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