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