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