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