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