1 /*****************************************************************************
2 * open.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2004 VideoLAN
7 * Authors: Gildas Bazin <gbazin@videolan.org>
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.
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.
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 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
28 #include <errno.h> /* ENOMEM */
29 #include <string.h> /* strerror() */
34 #include <wx/combobox.h>
35 #include <wx/statline.h>
36 #include <wx/tokenzr.h>
40 #include "wxwindows.h"
41 #include "preferences_widgets.h"
44 # define wxRB_SINGLE 0
47 /*****************************************************************************
49 *****************************************************************************/
51 /* IDs for the controls and the menu commands */
54 Notebook_Event = wxID_HIGHEST,
66 NetRadio1_Event, NetRadio2_Event, NetRadio3_Event, NetRadio4_Event,
67 NetPort1_Event, NetPort2_Event, NetPort3_Event,
68 NetAddr1_Event, NetAddr2_Event, NetAddr3_Event, NetAddr4_Event,
72 SubsFileSettings_Event,
80 BEGIN_EVENT_TABLE(OpenDialog, wxDialog)
82 EVT_BUTTON(wxID_OK, OpenDialog::OnOk)
83 EVT_BUTTON(wxID_CANCEL, OpenDialog::OnCancel)
85 EVT_NOTEBOOK_PAGE_CHANGED(Notebook_Event, OpenDialog::OnPageChange)
87 EVT_TEXT(MRL_Event, OpenDialog::OnMRLChange)
89 /* Events generated by the file panel */
90 EVT_TEXT(FileName_Event, OpenDialog::OnFilePanelChange)
91 EVT_BUTTON(FileBrowse_Event, OpenDialog::OnFileBrowse)
93 /* Events generated by the disc panel */
94 EVT_RADIOBOX(DiscType_Event, OpenDialog::OnDiscTypeChange)
95 EVT_TEXT(DiscDevice_Event, OpenDialog::OnDiscDeviceChange)
96 EVT_TEXT(DiscDevice_Event, OpenDialog::OnDiscPanelChange)
97 EVT_TEXT(DiscTitle_Event, OpenDialog::OnDiscPanelChange)
98 EVT_SPINCTRL(DiscTitle_Event, OpenDialog::OnDiscPanelChange)
99 EVT_TEXT(DiscChapter_Event, OpenDialog::OnDiscPanelChange)
100 EVT_SPINCTRL(DiscChapter_Event, OpenDialog::OnDiscPanelChange)
102 /* Events generated by the net panel */
103 EVT_RADIOBUTTON(NetRadio1_Event, OpenDialog::OnNetTypeChange)
104 EVT_RADIOBUTTON(NetRadio2_Event, OpenDialog::OnNetTypeChange)
105 EVT_RADIOBUTTON(NetRadio3_Event, OpenDialog::OnNetTypeChange)
106 EVT_RADIOBUTTON(NetRadio4_Event, OpenDialog::OnNetTypeChange)
107 EVT_TEXT(NetPort1_Event, OpenDialog::OnNetPanelChange)
108 EVT_SPINCTRL(NetPort1_Event, OpenDialog::OnNetPanelChange)
109 EVT_TEXT(NetPort2_Event, OpenDialog::OnNetPanelChange)
110 EVT_SPINCTRL(NetPort2_Event, OpenDialog::OnNetPanelChange)
111 EVT_TEXT(NetPort3_Event, OpenDialog::OnNetPanelChange)
112 EVT_SPINCTRL(NetPort3_Event, OpenDialog::OnNetPanelChange)
113 EVT_TEXT(NetAddr2_Event, OpenDialog::OnNetPanelChange)
114 EVT_TEXT(NetAddr3_Event, OpenDialog::OnNetPanelChange)
115 EVT_TEXT(NetAddr4_Event, OpenDialog::OnNetPanelChange)
116 EVT_CHECKBOX(NetForceIPv6_Event, OpenDialog::OnNetPanelChange)
118 /* Events generated by the subtitle file buttons */
119 EVT_CHECKBOX(SubsFileEnable_Event, OpenDialog::OnSubsFileEnable)
120 EVT_BUTTON(SubsFileSettings_Event, OpenDialog::OnSubsFileSettings)
122 /* Events generated by the stream output buttons */
123 EVT_CHECKBOX(SoutEnable_Event, OpenDialog::OnSoutEnable)
124 EVT_BUTTON(SoutSettings_Event, OpenDialog::OnSoutSettings)
126 /* Hide the window when the user closes the window */
127 EVT_CLOSE(OpenDialog::OnCancel)
131 /*****************************************************************************
133 *****************************************************************************/
134 WX_DEFINE_ARRAY(ConfigControl *, ArrayOfConfigControls);
136 class AutoBuiltPanel : public wxPanel
141 AutoBuiltPanel( wxWindow *, OpenDialog *, intf_thread_t *,
144 virtual ~AutoBuiltPanel() {}
146 void UpdateAdvancedMRL();
149 ArrayOfConfigControls config_array;
150 ArrayOfConfigControls advanced_config_array;
151 wxComboBox *p_advanced_mrl_combo;
154 intf_thread_t *p_intf;
155 OpenDialog *p_open_dialog;
157 void OnAdvanced( wxCommandEvent& event );
158 wxDialog *p_advanced_dialog;
160 DECLARE_EVENT_TABLE();
163 BEGIN_EVENT_TABLE(AutoBuiltPanel, wxPanel)
164 EVT_BUTTON(AdvancedOptions_Event, AutoBuiltPanel::OnAdvanced)
167 static void AutoBuildCallback( void *p_data )
169 ((OpenDialog *)p_data)->UpdateMRL();
172 static void AutoBuildAdvancedCallback( void *p_data )
174 ((AutoBuiltPanel *)p_data)->UpdateAdvancedMRL();
177 AutoBuiltPanel::AutoBuiltPanel( wxWindow *parent, OpenDialog *dialog,
178 intf_thread_t *_p_intf,
179 const module_t *p_module )
180 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize ),
181 name( wxU(p_module->psz_object_name) ),
182 p_advanced_mrl_combo( NULL ),
183 p_intf( _p_intf ), p_open_dialog( dialog ), p_advanced_dialog( NULL )
185 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
186 module_config_t *p_item = p_module->p_config;
187 bool b_advanced = false;
191 if( !(p_item->i_type & CONFIG_HINT) && p_item->b_advanced )
194 if( p_item->i_type & CONFIG_HINT || p_item->b_advanced )
197 ConfigControl *control =
198 CreateConfigControl( VLC_OBJECT(p_intf), p_item, this );
200 config_array.Add( control );
202 /* Don't add items that were not recognized */
203 if( control == NULL ) continue;
205 control->SetUpdateCallback( AutoBuildCallback, (void *)dialog );
207 sizer->Add( control, 0, wxEXPAND | wxALL, 2 );
209 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
213 wxPanel *dummy_panel = new wxPanel( this, -1 );
214 sizer->Add( dummy_panel, 1 );
217 new wxButton( this, AdvancedOptions_Event,
218 wxU(_("Advanced options...")) );
219 sizer->Add( button, 0, wxALL, 5 );
221 /* Build the advanced dialog */
223 new wxDialog( this, -1, ((wxString)wxU(_("Advanced options"))) +
224 wxT(" (") + wxU( p_module->psz_longname ) + wxT(")"),
225 wxDefaultPosition, wxDefaultSize,
226 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER );
228 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
230 /* Create MRL combobox */
231 wxBoxSizer *mrl_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
232 wxStaticBox *mrl_box =
233 new wxStaticBox( p_advanced_dialog, -1,
234 wxU(_("Advanced options")) );
235 wxStaticBoxSizer *mrl_sizer =
236 new wxStaticBoxSizer( mrl_box, wxHORIZONTAL );
237 wxStaticText *mrl_label =
238 new wxStaticText( p_advanced_dialog, -1, wxU(_("Options:")) );
239 p_advanced_mrl_combo =
240 new wxComboBox( p_advanced_dialog, MRL_Event, wxT(""),
241 wxDefaultPosition, wxDefaultSize );
242 mrl_sizer->Add( mrl_label, 0, wxALL | wxALIGN_CENTER, 5 );
243 mrl_sizer->Add( p_advanced_mrl_combo, 1, wxALL | wxALIGN_CENTER, 5 );
244 mrl_sizer_sizer->Add( mrl_sizer, 1, wxEXPAND | wxALL, 5 );
245 sizer->Add( mrl_sizer_sizer, 0, wxEXPAND | wxALL, 2 );
247 /* Add advanced options to panel */
248 module_config_t *p_item = p_module->p_config;
251 if( p_item->i_type & CONFIG_HINT || !p_item->b_advanced )
254 ConfigControl *control =
255 CreateConfigControl( VLC_OBJECT(p_intf), p_item,
258 advanced_config_array.Add( control );
260 /* Don't add items that were not recognized */
261 if( control == NULL ) continue;
263 control->SetUpdateCallback( AutoBuildAdvancedCallback,
266 sizer->Add( control, 0, wxEXPAND | wxALL, 2 );
268 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
271 dummy_panel = new wxPanel( p_advanced_dialog, -1 );
272 sizer->Add( dummy_panel, 1 );
273 wxStaticLine *static_line =
274 new wxStaticLine( p_advanced_dialog, wxID_OK );
275 sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
278 wxButton *ok_button =
279 new wxButton( p_advanced_dialog, wxID_OK, wxU(_("OK")) );
280 ok_button->SetDefault();
281 wxButton *cancel_button =
282 new wxButton( p_advanced_dialog, wxID_CANCEL, wxU(_("Cancel")) );
283 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
284 button_sizer->Add( ok_button, 0, wxALL, 5 );
285 button_sizer->Add( cancel_button, 0, wxALL, 5 );
286 button_sizer->Layout();
287 sizer->Add( button_sizer, 0, wxALL, 0 );
289 sizer->SetMinSize( 400, -1 );
290 p_advanced_dialog->SetSizerAndFit( sizer );
293 this->SetSizerAndFit( sizer );
296 void AutoBuiltPanel::OnAdvanced( wxCommandEvent& event )
298 if( p_advanced_dialog->ShowModal() == wxID_OK )
301 p_open_dialog->UpdateMRL();
305 void AutoBuiltPanel::UpdateAdvancedMRL()
309 for( int i = 0; i < (int)advanced_config_array.GetCount(); i++ )
311 ConfigControl *control = advanced_config_array.Item(i);
313 mrltemp += (i ? wxT(" :") : wxT(":"));
315 if( control->GetType() == CONFIG_ITEM_BOOL &&
316 !control->GetIntValue() ) mrltemp += wxT("no-");
318 mrltemp += control->GetName();
320 switch( control->GetType() )
322 case CONFIG_ITEM_STRING:
323 case CONFIG_ITEM_FILE:
324 case CONFIG_ITEM_DIRECTORY:
325 case CONFIG_ITEM_MODULE:
326 mrltemp += wxT("=\"") + control->GetPszValue() + wxT("\"");
328 case CONFIG_ITEM_INTEGER:
330 wxString::Format( wxT("=%i"), control->GetIntValue() );
332 case CONFIG_ITEM_FLOAT:
334 wxString::Format(wxT("=%f"), control->GetFloatValue());
339 p_advanced_mrl_combo->SetValue( mrltemp );
342 /*****************************************************************************
344 *****************************************************************************/
345 OpenDialog::OpenDialog( intf_thread_t *_p_intf, wxWindow *_p_parent,
346 int i_access_method, int i_arg ):
347 wxDialog( _p_parent, -1, wxU(_("Open...")), wxDefaultPosition,
348 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
350 OpenDialog( _p_intf, _p_parent, i_access_method, i_arg, OPEN_NORMAL );
353 OpenDialog::OpenDialog( intf_thread_t *_p_intf, wxWindow *_p_parent,
354 int i_access_method, int i_arg, int _i_method ):
355 wxDialog( _p_parent, -1, wxU(_("Open...")), wxDefaultPosition,
356 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
358 /* Initializations */
359 i_method = _i_method;
361 p_parent = _p_parent;
362 SetIcon( *p_intf->p_sys->p_icon );
364 i_disc_type_selection = 0;
368 subsfile_dialog = NULL;
369 b_disc_device_changed = false;
371 /* Create a panel to put everything in */
372 wxPanel *panel = new wxPanel( this, -1 );
373 panel->SetAutoLayout( TRUE );
375 /* Create MRL combobox */
376 wxBoxSizer *mrl_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
377 wxStaticBox *mrl_box = new wxStaticBox( panel, -1,
378 wxU(_("Media Resource Locator (MRL)")) );
379 wxStaticBoxSizer *mrl_sizer = new wxStaticBoxSizer( mrl_box,
381 wxStaticText *mrl_label = new wxStaticText( panel, -1,
383 mrl_combo = new wxComboBox( panel, MRL_Event, wxT(""),
384 wxPoint(20,25), wxSize(120, -1),
386 mrl_combo->SetToolTip( wxU(_("You can use this field directly by typing "
387 "the full MRL you want to open.\n""Alternatively, the field will be "
388 "filled automatically when you use the controls below.")) );
390 mrl_sizer->Add( mrl_label, 0, wxALL | wxALIGN_CENTER, 5 );
391 mrl_sizer->Add( mrl_combo, 1, wxALL | wxALIGN_CENTER, 5 );
392 mrl_sizer_sizer->Add( mrl_sizer, 1, wxEXPAND | wxALL, 5 );
395 /* Create Static Text */
396 wxStaticText *label = new wxStaticText( panel, -1,
397 wxU(_("Alternatively, you can build an MRL using one of the "
398 "following predefined targets:")) );
400 wxFlexGridSizer *sout_sizer = NULL;
401 wxStaticLine *static_line = NULL;
403 if( i_method == OPEN_NORMAL )
405 /* Create Stream Output checkox */
406 sout_sizer = new wxFlexGridSizer( 2, 1, 20 );
409 sout_checkbox = new wxCheckBox( panel, SoutEnable_Event,
410 wxU(_("Stream output")) );
411 sout_checkbox->SetToolTip( wxU(_("Use VLC as a server of streams")) );
412 sout_sizer->Add( sout_checkbox, 0,
413 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
414 sout_button = new wxButton( panel, SoutSettings_Event,
415 wxU(_("Settings...")) );
416 sout_button->Disable();
418 char *psz_sout = config_GetPsz( p_intf, "sout" );
419 if( psz_sout && *psz_sout )
421 sout_checkbox->SetValue(TRUE);
422 sout_button->Enable();
423 subsfile_mrl.Add( wxString(wxT("sout=")) + wxL2U(psz_sout) );
425 if( psz_sout ) free( psz_sout );
427 sout_sizer->Add( sout_button, 1, wxALIGN_LEFT |
428 wxALIGN_CENTER_VERTICAL );
431 static_line = new wxStaticLine( panel, wxID_OK );
434 /* Create the buttons */
435 wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
436 ok_button->SetDefault();
437 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
440 /* Create notebook */
441 notebook = new wxNotebook( panel, Notebook_Event );
442 wxNotebookSizer *notebook_sizer = new wxNotebookSizer( notebook );
444 notebook->AddPage( FilePanel( notebook ), wxU(_("File")),
445 i_access_method == FILE_ACCESS );
446 notebook->AddPage( DiscPanel( notebook ), wxU(_("Disc")),
447 i_access_method == DISC_ACCESS );
448 notebook->AddPage( NetPanel( notebook ), wxU(_("Network")),
449 i_access_method == NET_ACCESS );
451 module_t *p_module = config_FindModule( VLC_OBJECT(p_intf), "v4l" );
454 AutoBuiltPanel *autopanel =
455 new AutoBuiltPanel( notebook, this, p_intf, p_module );
456 input_tab_array.Add( autopanel );
457 notebook->AddPage( autopanel, wxU( p_module->psz_longname ),
458 i_access_method == CAPTURE_ACCESS );
461 p_module = config_FindModule( VLC_OBJECT(p_intf), "pvr" );
464 AutoBuiltPanel *autopanel =
465 new AutoBuiltPanel( notebook, this, p_intf, p_module );
466 input_tab_array.Add( autopanel );
467 notebook->AddPage( autopanel, wxU( p_module->psz_longname ),
468 i_access_method == CAPTURE_ACCESS );
471 p_module = config_FindModule( VLC_OBJECT(p_intf), "dshow" );
474 AutoBuiltPanel *autopanel =
475 new AutoBuiltPanel( notebook, this, p_intf, p_module );
476 input_tab_array.Add( autopanel );
477 notebook->AddPage( autopanel, wxU( p_module->psz_longname ),
478 i_access_method == CAPTURE_ACCESS );
481 /* Update Disc panel */
482 wxCommandEvent dummy_event;
483 OnDiscTypeChange( dummy_event );
485 /* Update Net panel */
486 dummy_event.SetId( NetRadio1_Event );
487 OnNetTypeChange( dummy_event );
490 wxNotebookEvent event( wxEVT_NULL, 0, i_access_method );
491 OnPageChange( event );
493 /* Place everything in sizers */
494 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
495 button_sizer->Add( ok_button, 0, wxALL, 5 );
496 button_sizer->Add( cancel_button, 0, wxALL, 5 );
497 button_sizer->Layout();
498 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
499 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
500 panel_sizer->Add( mrl_sizer_sizer, 0, wxEXPAND, 5 );
501 panel_sizer->Add( label, 0, wxEXPAND | wxALL, 5 );
502 panel_sizer->Add( notebook_sizer, 1, wxEXPAND | wxALL, 5 );
503 if( i_method == OPEN_NORMAL)
505 panel_sizer->Add( sout_sizer, 0, wxALIGN_LEFT | wxALL, 5 );
506 panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
508 panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALL, 5 );
509 panel_sizer->Layout();
510 panel->SetSizerAndFit( panel_sizer );
511 main_sizer->Add( panel, 1, wxGROW, 0 );
512 main_sizer->Layout();
513 SetSizerAndFit( main_sizer );
516 OpenDialog::~OpenDialog()
519 if( file_dialog ) delete file_dialog;
520 if( sout_dialog ) delete sout_dialog;
521 if( subsfile_dialog ) delete subsfile_dialog;
524 int OpenDialog::Show( int i_access_method, int i_arg )
526 notebook->SetSelection( i_access_method );
527 int i_ret = wxDialog::Show();
534 int OpenDialog::Show()
536 int i_ret = wxDialog::Show();
542 /*****************************************************************************
544 *****************************************************************************/
545 wxPanel *OpenDialog::FilePanel( wxWindow* parent )
547 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
550 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
552 /* Create browse file line */
553 wxBoxSizer *file_sizer = new wxBoxSizer( wxHORIZONTAL );
555 file_combo = new wxComboBox( panel, FileName_Event, wxT(""),
556 wxPoint(20,25), wxSize(200, -1), 0, NULL );
557 wxButton *browse_button = new wxButton( panel, FileBrowse_Event,
558 wxU(_("Browse...")) );
559 file_sizer->Add( file_combo, 1, wxALL, 5 );
560 file_sizer->Add( browse_button, 0, wxALL, 5 );
562 /* Create Subtitles File checkox */
563 wxFlexGridSizer *subsfile_sizer = new wxFlexGridSizer( 2, 1, 20 );
564 subsfile_checkbox = new wxCheckBox( panel, SubsFileEnable_Event,
565 wxU(_("Subtitle options")) );
566 subsfile_checkbox->SetToolTip( wxU(_("Force options for separate subtitle files.")) );
567 subsfile_sizer->Add( subsfile_checkbox, 0,
568 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
569 subsfile_button = new wxButton( panel, SubsFileSettings_Event,
570 wxU(_("Settings...")) );
571 subsfile_button->Disable();
573 char *psz_subsfile = config_GetPsz( p_intf, "sub-file" );
574 if( psz_subsfile && *psz_subsfile )
576 subsfile_checkbox->SetValue(TRUE);
577 subsfile_button->Enable();
578 subsfile_mrl.Add( wxString(wxT("sub-file=")) + wxL2U(psz_subsfile) );
580 if( psz_subsfile ) free( psz_subsfile );
582 subsfile_sizer->Add( subsfile_button, 1,
583 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
585 sizer->Add( file_sizer, 0, wxEXPAND | wxALL, 5 );
586 sizer->Add( subsfile_sizer, 0, wxEXPAND | wxALL, 5 );
587 panel->SetSizerAndFit( sizer );
591 wxPanel *OpenDialog::DiscPanel( wxWindow* parent )
593 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
596 wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
597 wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 3, 20 );
599 static const wxString disc_type_array[] =
601 wxU(_("DVD (menus support)")),
605 wxU(_("DVD (experimental)"))
608 disc_type = new wxRadioBox( panel, DiscType_Event, wxU(_("Disc type")),
609 wxDefaultPosition, wxDefaultSize,
610 WXSIZEOF(disc_type_array), disc_type_array,
611 WXSIZEOF(disc_type_array), wxRA_SPECIFY_COLS );
613 sizer_row->Add( disc_type, i_disc_type_selection, wxEXPAND | wxALL, 5 );
615 wxStaticText *label = new wxStaticText( panel, -1, wxU(_("Device name")) );
616 disc_device = new wxTextCtrl( panel, DiscDevice_Event, wxT(""),
617 wxDefaultPosition, wxDefaultSize,
620 sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
621 sizer->Add( disc_device, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
623 disc_title_label = new wxStaticText( panel, -1, wxU(_("Title")) );
624 disc_title = new wxSpinCtrl( panel, DiscTitle_Event );
626 sizer->Add( disc_title_label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
627 sizer->Add( disc_title, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
629 disc_chapter_label = new wxStaticText( panel, -1, wxU(_("Chapter")) );
630 disc_chapter = new wxSpinCtrl( panel, DiscChapter_Event );
631 sizer->Add( disc_chapter_label, 0,
632 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
633 sizer->Add( disc_chapter, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
634 sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
636 panel->SetSizerAndFit( sizer_row );
640 wxPanel *OpenDialog::NetPanel( wxWindow* parent )
643 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
646 wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
647 wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 4, 20 );
649 static const wxString net_type_array[] =
652 wxU(_("UDP/RTP Multicast")),
653 wxU(_("HTTP/FTP/MMS")),
659 net_radios[i] = new wxRadioButton( panel, NetRadio1_Event + i,
661 wxDefaultPosition, wxDefaultSize,
664 net_subpanels[i] = new wxPanel( panel, -1,
665 wxDefaultPosition, wxDefaultSize );
669 wxFlexGridSizer *subpanel_sizer;
671 i_net_ports[0] = config_GetInt( p_intf, "server-port" );
672 subpanel_sizer = new wxFlexGridSizer( 3, 1, 20 );
673 label = new wxStaticText( net_subpanels[0], -1, wxU(_("Port")) );
674 net_ports[0] = new wxSpinCtrl( net_subpanels[0], NetPort1_Event,
675 wxString::Format(wxT("%d"), i_net_ports[0]),
676 wxDefaultPosition, wxDefaultSize,
678 0, 16000, i_net_ports[0] );
680 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
681 subpanel_sizer->Add( net_ports[0], 1,
682 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
683 net_ipv6 = new wxCheckBox( net_subpanels[0], NetForceIPv6_Event,
684 wxU(_("Force IPv6")));
685 subpanel_sizer->Add( net_ipv6, 0,
686 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
687 net_subpanels[0]->SetSizerAndFit( subpanel_sizer );
688 net_radios[0]->SetValue( TRUE );
690 /* UDP/RTP Multicast row */
691 subpanel_sizer = new wxFlexGridSizer( 4, 1, 20 );
692 label = new wxStaticText( net_subpanels[1], -1, wxU(_("Address")) );
693 net_addrs[1] = new wxTextCtrl( net_subpanels[1], NetAddr2_Event, wxT(""),
694 wxDefaultPosition, wxDefaultSize,
696 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
697 subpanel_sizer->Add( net_addrs[1], 1,
698 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
700 label = new wxStaticText( net_subpanels[1], -1, wxU(_("Port")) );
701 i_net_ports[1] = i_net_ports[0];
702 net_ports[1] = new wxSpinCtrl( net_subpanels[1], NetPort2_Event,
703 wxString::Format(wxT("%d"), i_net_ports[1]),
704 wxDefaultPosition, wxDefaultSize,
706 0, 16000, i_net_ports[1] );
708 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
709 subpanel_sizer->Add( net_ports[1], 1,
710 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
711 net_subpanels[1]->SetSizerAndFit( subpanel_sizer );
713 /* HTTP and RTSP rows */
716 subpanel_sizer = new wxFlexGridSizer( 2, 1, 20 );
717 label = new wxStaticText( net_subpanels[i], -1, wxU(_("URL")) );
718 net_addrs[i] = new wxTextCtrl( net_subpanels[i], NetAddr1_Event + i,
719 (i == 2) ? wxT("") : wxT("rtsp://"),
720 wxDefaultPosition, wxSize( 200, -1 ),
722 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
723 subpanel_sizer->Add( net_addrs[i], 1,
724 wxEXPAND | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
725 net_subpanels[i]->SetSizerAndFit( subpanel_sizer );
728 /* Stuff everything into the main panel */
731 sizer->Add( net_radios[i], 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
733 sizer->Add( net_subpanels[i], 1, wxEXPAND | wxALIGN_LEFT |
734 wxALIGN_CENTER_VERTICAL | wxALL, 5 );
737 sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
739 panel->SetSizerAndFit( sizer_row );
743 void OpenDialog::UpdateMRL()
745 UpdateMRL( i_current_access_method );
748 void OpenDialog::UpdateMRL( int i_access_method )
750 wxString demux, mrltemp;
752 i_current_access_method = i_access_method;
754 switch( i_access_method )
757 //mrltemp = wxT("file") + demux + wxT(":") + file_combo->GetValue();
758 mrltemp = file_combo->GetValue();
761 i_disc_type_selection = disc_type->GetSelection();
763 switch ( i_disc_type_selection )
765 case 0: /* DVD with menues */
766 disc_chapter->Enable();
767 disc_chapter_label->Enable();
768 mrltemp = wxT("dvd://")
769 + disc_device->GetValue()
770 + wxString::Format( wxT("@%d:%d"),
771 disc_title->GetValue(),
772 disc_chapter->GetValue() );
775 case 1: /* DVD of some sort */
776 disc_chapter->Enable();
777 disc_chapter_label->Enable();
778 mrltemp = wxT("dvdsimple://")
779 + disc_device->GetValue()
780 + wxString::Format( wxT("@%d:%d"),
781 disc_title->GetValue(),
782 disc_chapter->GetValue() );
785 case 2: /* VCD of some sort */
787 /* The chapter object is used for subtitles */
789 int i_subtitle = disc_chapter->GetValue();
790 config_PutInt( p_intf, "spu-channel", i_subtitle );
792 disc_chapter->Enable();
793 disc_chapter_label->Enable();
795 if ( disc_title->GetValue() )
796 mrltemp = wxT("vcdx://")
797 + disc_device->GetValue()
798 + wxString::Format( wxT("@%c%d"),
799 config_GetInt( p_intf, "vcdx-PBC" )
801 disc_title->GetValue()
804 mrltemp = wxT("vcdx://")
805 + disc_device->GetValue();
807 mrltemp = wxT("vcd://")
808 + disc_device->GetValue()
809 + wxString::Format( wxT("@%d"),
810 disc_title->GetValue() );
817 disc_chapter->Disable();
818 disc_chapter_label->Disable();
820 if ( disc_title->GetValue() )
821 mrltemp = wxT("cddax://")
822 + disc_device->GetValue()
823 + wxString::Format( wxT("@T%d"),
824 disc_title->GetValue() );
826 mrltemp = wxT("cddax://")
827 + disc_device->GetValue();
830 mrltemp = wxT("cdda://")
831 + disc_device->GetValue()
832 + wxString::Format( wxT("@%d"),
833 disc_title->GetValue() );
837 case 4: /* DVD of some sort */
838 disc_chapter->Enable();
839 disc_chapter_label->Enable();
840 mrltemp = wxT("dvdnav://")
841 + disc_device->GetValue()
842 + wxString::Format( wxT("@%d:%d"),
843 disc_title->GetValue(),
844 disc_chapter->GetValue() );
848 msg_Err( p_intf, "invalid selection (%d)",
849 disc_type->GetSelection() );
857 mrltemp = wxT("udp") + demux + wxT("://");
858 if ( net_ipv6->GetValue() )
860 mrltemp += wxT("@[::]");
862 if( i_net_ports[0] !=
863 config_GetInt( p_intf, "server-port" ) )
865 mrltemp += wxString::Format( wxT("@:%d"), i_net_ports[0] );
870 mrltemp = wxT("udp") + demux + wxT("://@");
871 if ((net_addrs[1]->GetLineText(0).Find (':') != -1)
872 && (net_addrs[1]->GetLineText(0)[0u] != '['))
874 /* automatically adds '[' and ']' to IPv6 addresses */
875 mrltemp += wxT("[") + net_addrs[1]->GetLineText(0)
880 mrltemp += net_addrs[1]->GetLineText(0);
882 if( i_net_ports[1] != config_GetInt( p_intf, "server-port" ) )
884 mrltemp += wxString::Format( wxT(":%d"), i_net_ports[1] );
890 if( net_addrs[2]->GetLineText(0).Find(wxT("http://")) )
892 mrltemp = wxT("http") + demux + wxT("://");
894 mrltemp += net_addrs[2]->GetLineText(0);
899 if( net_addrs[3]->GetLineText(0).Find(wxT("rtsp://")) != 0 )
901 mrltemp = wxT("rtsp") + demux + wxT("://");
903 mrltemp += net_addrs[3]->GetLineText(0);
910 int i_item = i_access_method - MAX_ACCESS;
912 if( i_item < 0 || i_item >= (int)input_tab_array.GetCount() )
915 AutoBuiltPanel *input_panel = input_tab_array.Item( i_item );
917 mrltemp = input_panel->name + wxT("://");
919 for( int i=0; i < (int)input_panel->config_array.GetCount(); i++ )
921 ConfigControl *control = input_panel->config_array.Item(i);
923 mrltemp += wxT(" :");
925 if( control->GetType() == CONFIG_ITEM_BOOL &&
926 !control->GetIntValue() ) mrltemp += wxT("no-");
928 mrltemp += control->GetName();
930 switch( control->GetType() )
932 case CONFIG_ITEM_STRING:
933 case CONFIG_ITEM_FILE:
934 case CONFIG_ITEM_DIRECTORY:
935 case CONFIG_ITEM_MODULE:
936 mrltemp += wxT("=\"") + control->GetPszValue() + wxT("\"");
938 case CONFIG_ITEM_INTEGER:
940 wxString::Format( wxT("=%i"), control->GetIntValue() );
942 case CONFIG_ITEM_FLOAT:
944 wxString::Format(wxT("=%f"), control->GetFloatValue());
949 if( input_panel->p_advanced_mrl_combo &&
950 input_panel->p_advanced_mrl_combo->GetValue() )
952 mrltemp += wxT(" ") +
953 input_panel->p_advanced_mrl_combo->GetValue();
959 mrl_combo->SetValue( mrltemp );
962 /*****************************************************************************
964 *****************************************************************************/
965 void OpenDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
967 mrl = SeparateEntries( mrl_combo->GetValue() );
968 mrl_combo->Append( mrl_combo->GetValue() );
969 if( mrl_combo->GetCount() > 10 ) mrl_combo->Delete( 0 );
970 mrl_combo->SetSelection( mrl_combo->GetCount() - 1 );
972 if( i_method == OPEN_STREAM )
975 if( IsModal() ) EndModal( wxID_OK );
979 /* Update the playlist */
980 playlist_t *p_playlist =
981 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
983 if( p_playlist == NULL ) return;
985 for( int i = 0; i < (int)mrl.GetCount(); i++ )
987 vlc_bool_t b_start = !i && i_open_arg;
988 playlist_item_t *p_item =
989 playlist_ItemNew( p_intf, (const char*)mrl[i].mb_str(),
990 (const char *)mrl[i].mb_str() );
993 while( i + 1 < (int)mrl.GetCount() &&
994 ((const char *)mrl[i + 1].mb_str())[0] == ':' )
996 playlist_ItemAddOption( p_item, mrl[i + 1].mb_str() );
1000 /* Get the options from the subtitles dialog */
1001 if( subsfile_checkbox->IsChecked() && subsfile_mrl.GetCount() )
1003 for( int j = 0; j < (int)subsfile_mrl.GetCount(); j++ )
1005 playlist_ItemAddOption( p_item, subsfile_mrl[j].mb_str() );
1009 /* Get the options from the stream output dialog */
1010 if( sout_checkbox->IsChecked() && sout_mrl.GetCount() )
1012 for( int j = 0; j < (int)sout_mrl.GetCount(); j++ )
1014 playlist_ItemAddOption( p_item, sout_mrl[j].mb_str() );
1018 int i_id = playlist_AddItem( p_playlist, p_item,
1019 PLAYLIST_APPEND, PLAYLIST_END );
1023 int i_pos = playlist_GetPositionById( p_playlist , i_id );
1024 playlist_Command( p_playlist, PLAYLIST_GOTO, i_pos );
1028 vlc_object_release( p_playlist );
1032 if( IsModal() ) EndModal( wxID_OK );
1035 void OpenDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
1039 if( IsModal() ) EndModal( wxID_CANCEL );
1042 void OpenDialog::OnPageChange( wxNotebookEvent& event )
1044 UpdateMRL( event.GetSelection() );
1047 void OpenDialog::OnMRLChange( wxCommandEvent& event )
1049 //mrl = SeparateEntries( event.GetString() );
1052 /*****************************************************************************
1053 * File panel event methods.
1054 *****************************************************************************/
1055 void OpenDialog::OnFilePanelChange( wxCommandEvent& WXUNUSED(event) )
1057 UpdateMRL( FILE_ACCESS );
1060 void OpenDialog::OnFileBrowse( wxCommandEvent& WXUNUSED(event) )
1062 if( file_dialog == NULL )
1063 file_dialog = new wxFileDialog( this, wxU(_("Open File")),
1064 wxT(""), wxT(""), wxT("*"), wxOPEN | wxMULTIPLE );
1066 if( file_dialog && file_dialog->ShowModal() == wxID_OK )
1068 wxArrayString paths;
1071 file_dialog->GetPaths( paths );
1073 for( size_t i = 0; i < paths.GetCount(); i++ )
1075 if( paths[i].Find( wxT(' ') ) >= 0 )
1076 path += wxT("\"") + paths[i] + wxT("\" ");
1078 path += paths[i] + wxT(" ");
1081 file_combo->SetValue( path );
1082 file_combo->Append( path );
1083 if( file_combo->GetCount() > 10 ) file_combo->Delete( 0 );
1084 UpdateMRL( FILE_ACCESS );
1088 /*****************************************************************************
1089 * Disc panel event methods.
1090 *****************************************************************************/
1091 void OpenDialog::OnDiscPanelChange( wxCommandEvent& event )
1093 UpdateMRL( DISC_ACCESS );
1096 void OpenDialog::OnDiscDeviceChange( wxCommandEvent& event )
1100 switch( disc_type->GetSelection() )
1103 psz_device = config_GetPsz( p_intf, "cd-audio" );
1107 psz_device = config_GetPsz( p_intf, "vcd" );
1111 psz_device = config_GetPsz( p_intf, "dvd" );
1115 if ( !psz_device ) psz_device = "";
1117 if( disc_device->GetValue().Cmp( wxL2U( psz_device ) ) )
1119 b_disc_device_changed = true;
1122 UpdateMRL( DISC_ACCESS );
1125 void OpenDialog::OnDiscTypeChange( wxCommandEvent& WXUNUSED(event) )
1127 char *psz_device = NULL;
1128 int i_selection = 1; /* Default Title/Track selection number*/
1130 switch( disc_type->GetSelection() )
1133 case 0: /* DVD with menus */
1134 case 4: /* DVD with menus (dvdnav) */
1136 /* Fall through... */
1138 case 1: /* DVD of some sort */
1139 psz_device = config_GetPsz( p_intf, "dvd" );
1140 if( !b_disc_device_changed )
1143 disc_device->SetValue( wxL2U(psz_device) );
1145 disc_device->SetValue( wxT("") );
1147 disc_title_label->SetLabel ( wxU(_("Title")) );
1149 disc_title->SetRange( i_selection, 255 );
1150 disc_title->SetValue( i_selection );
1152 disc_chapter->SetRange( 1, 255 );
1153 disc_chapter->SetValue( 1 );
1154 disc_chapter_label->SetLabel ( wxU(_("Chapter")) );
1158 case 2: /* VCD of some sort */
1159 psz_device = config_GetPsz( p_intf, "vcd" );
1160 if( !b_disc_device_changed )
1163 disc_device->SetValue( wxL2U(psz_device) );
1165 disc_device->SetValue( wxT("") );
1168 /* There are at most 98, tracks in a VCD, 999 Segments, 500 entries
1169 I don't know what the limit is for LIDs, 999 is probably safe
1172 FIXME: it would be better however to get the information for
1173 this particular Media possibly from the General Info area.
1176 disc_title_label->SetLabel ( config_GetInt( p_intf, "vcdx-PBC" )
1177 ? wxT("Playback LID") : wxT("Entry") );
1178 disc_title->SetRange( 0, 999 );
1181 disc_title_label->SetLabel ( wxU(_("Track")) );
1182 disc_title->SetRange( 1, 98 );
1184 disc_title->SetValue( i_selection );
1186 /* We use the chapter to set subtitle number */
1187 disc_chapter_label->SetLabel ( wxU(_("Subtitle")) );
1188 disc_chapter->SetRange( -1, 4 );
1189 disc_chapter->SetValue( config_GetInt( p_intf, "spu-channel" ) );
1193 psz_device = config_GetPsz( p_intf, "cd-audio" );
1194 if( !b_disc_device_changed )
1197 disc_device->SetValue( wxL2U(psz_device) );
1199 disc_device->SetValue( wxT("") );
1201 disc_title_label->SetLabel ( wxU(_("Track")) );
1205 /* There are at most 99 tracks in a CD-DA */
1206 disc_title->SetRange( i_selection, 99 );
1207 disc_title->SetValue( i_selection );
1210 msg_Err( p_intf, "invalid Disc type selection (%d)",
1211 disc_type->GetSelection() );
1215 if( psz_device ) free( psz_device );
1217 UpdateMRL( DISC_ACCESS );
1220 /*****************************************************************************
1221 * Net panel event methods.
1222 *****************************************************************************/
1223 void OpenDialog::OnNetPanelChange( wxCommandEvent& event )
1225 if( event.GetId() >= NetPort1_Event && event.GetId() <= NetPort3_Event )
1227 i_net_ports[event.GetId() - NetPort1_Event] = event.GetInt();
1230 UpdateMRL( NET_ACCESS );
1233 void OpenDialog::OnNetTypeChange( wxCommandEvent& event )
1237 i_net_type = event.GetId() - NetRadio1_Event;
1241 net_radios[i]->SetValue( event.GetId() == (NetRadio1_Event+i) );
1242 net_subpanels[i]->Enable( event.GetId() == (NetRadio1_Event+i) );
1245 UpdateMRL( NET_ACCESS );
1248 /*****************************************************************************
1249 * Subtitles file event methods.
1250 *****************************************************************************/
1251 void OpenDialog::OnSubsFileEnable( wxCommandEvent& event )
1253 subsfile_button->Enable( event.GetInt() != 0 );
1256 void OpenDialog::OnSubsFileSettings( wxCommandEvent& WXUNUSED(event) )
1258 /* Show/hide the open dialog */
1259 if( subsfile_dialog == NULL )
1260 subsfile_dialog = new SubsFileDialog( p_intf, this );
1262 if( subsfile_dialog && subsfile_dialog->ShowModal() == wxID_OK )
1264 subsfile_mrl.Empty();
1265 subsfile_mrl.Add( wxString(wxT("sub-file=")) +
1266 subsfile_dialog->file_combo->GetValue() );
1267 if( subsfile_dialog->encoding_combo )
1268 subsfile_mrl.Add( wxString(wxT("subsdec-encoding=")) +
1269 subsfile_dialog->encoding_combo->GetValue() );
1270 subsfile_mrl.Add( wxString::Format( wxT("sub-delay=%i"),
1271 subsfile_dialog->delay_spinctrl->GetValue() ) );
1272 subsfile_mrl.Add( wxString::Format( wxT("sub-fps=%i"),
1273 subsfile_dialog->fps_spinctrl->GetValue() ) );
1277 /*****************************************************************************
1278 * Stream output event methods.
1279 *****************************************************************************/
1280 void OpenDialog::OnSoutEnable( wxCommandEvent& event )
1282 sout_button->Enable( event.GetInt() != 0 );
1285 void OpenDialog::OnSoutSettings( wxCommandEvent& WXUNUSED(event) )
1287 /* Show/hide the open dialog */
1288 if( sout_dialog == NULL )
1289 sout_dialog = new SoutDialog( p_intf, this );
1291 if( sout_dialog && sout_dialog->ShowModal() == wxID_OK )
1293 sout_mrl = sout_dialog->GetOptions();
1297 /*****************************************************************************
1298 * Utility functions.
1299 *****************************************************************************/
1300 wxArrayString SeparateEntries( wxString entries )
1302 vlc_bool_t b_quotes_mode = VLC_FALSE;
1304 wxArrayString entries_array;
1307 wxStringTokenizer token( entries, wxT(" \t\r\n\""), wxTOKEN_RET_DELIMS );
1309 while( token.HasMoreTokens() )
1311 entry += token.GetNextToken();
1313 if( entry.IsEmpty() ) continue;
1315 if( !b_quotes_mode && entry.Last() == wxT('\"') )
1317 /* Enters quotes mode */
1319 b_quotes_mode = VLC_TRUE;
1321 else if( b_quotes_mode && entry.Last() == wxT('\"') )
1323 /* Finished the quotes mode */
1325 b_quotes_mode = VLC_FALSE;
1327 else if( !b_quotes_mode && entry.Last() != wxT('\"') )
1329 /* we found a non-quoted standalone string */
1330 if( token.HasMoreTokens() ||
1331 entry.Last() == wxT(' ') || entry.Last() == wxT('\t') ||
1332 entry.Last() == wxT('\r') || entry.Last() == wxT('\n') )
1334 if( !entry.IsEmpty() ) entries_array.Add( entry );
1341 if( !entry.IsEmpty() ) entries_array.Add( entry );
1343 return entries_array;