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