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,
67 NetRadio1_Event, NetRadio2_Event, NetRadio3_Event, NetRadio4_Event,
68 NetPort1_Event, NetPort2_Event, NetPort3_Event,
69 NetAddr1_Event, NetAddr2_Event, NetAddr3_Event, NetAddr4_Event,
73 SubsFileSettings_Event,
84 BEGIN_EVENT_TABLE(OpenDialog, wxDialog)
86 EVT_BUTTON(wxID_OK, OpenDialog::OnOk)
87 EVT_BUTTON(wxID_CANCEL, OpenDialog::OnCancel)
89 EVT_NOTEBOOK_PAGE_CHANGED(Notebook_Event, OpenDialog::OnPageChange)
91 EVT_TEXT(MRL_Event, OpenDialog::OnMRLChange)
93 /* Events generated by the file panel */
94 EVT_TEXT(FileName_Event, OpenDialog::OnFilePanelChange)
95 EVT_BUTTON(FileBrowse_Event, OpenDialog::OnFileBrowse)
97 /* Events generated by the disc panel */
98 EVT_RADIOBOX(DiscType_Event, OpenDialog::OnDiscTypeChange)
99 EVT_TEXT(DiscDevice_Event, OpenDialog::OnDiscDeviceChange)
100 EVT_TEXT(DiscDevice_Event, OpenDialog::OnDiscPanelChange)
101 EVT_TEXT(DiscTitle_Event, OpenDialog::OnDiscPanelChange)
102 EVT_SPINCTRL(DiscTitle_Event, OpenDialog::OnDiscPanelChange)
103 EVT_TEXT(DiscChapter_Event, OpenDialog::OnDiscPanelChange)
104 EVT_SPINCTRL(DiscChapter_Event, OpenDialog::OnDiscPanelChange)
105 EVT_TEXT(DiscSub_Event, OpenDialog::OnDiscPanelChange)
106 EVT_SPINCTRL(DiscSub_Event, OpenDialog::OnDiscPanelChange)
108 /* Events generated by the net panel */
109 EVT_RADIOBUTTON(NetRadio1_Event, OpenDialog::OnNetTypeChange)
110 EVT_RADIOBUTTON(NetRadio2_Event, OpenDialog::OnNetTypeChange)
111 EVT_RADIOBUTTON(NetRadio3_Event, OpenDialog::OnNetTypeChange)
112 EVT_RADIOBUTTON(NetRadio4_Event, OpenDialog::OnNetTypeChange)
113 EVT_TEXT(NetPort1_Event, OpenDialog::OnNetPanelChange)
114 EVT_SPINCTRL(NetPort1_Event, OpenDialog::OnNetPanelChange)
115 EVT_TEXT(NetPort2_Event, OpenDialog::OnNetPanelChange)
116 EVT_SPINCTRL(NetPort2_Event, OpenDialog::OnNetPanelChange)
117 EVT_TEXT(NetPort3_Event, OpenDialog::OnNetPanelChange)
118 EVT_SPINCTRL(NetPort3_Event, OpenDialog::OnNetPanelChange)
119 EVT_TEXT(NetAddr2_Event, OpenDialog::OnNetPanelChange)
120 EVT_TEXT(NetAddr3_Event, OpenDialog::OnNetPanelChange)
121 EVT_TEXT(NetAddr4_Event, OpenDialog::OnNetPanelChange)
122 EVT_CHECKBOX(NetForceIPv6_Event, OpenDialog::OnNetPanelChange)
124 /* Events generated by the subtitle file buttons */
125 EVT_CHECKBOX(SubsFileEnable_Event, OpenDialog::OnSubsFileEnable)
126 EVT_BUTTON(SubsFileSettings_Event, OpenDialog::OnSubsFileSettings)
128 /* Events generated by the stream output buttons */
129 EVT_CHECKBOX(SoutEnable_Event, OpenDialog::OnSoutEnable)
130 EVT_BUTTON(SoutSettings_Event, OpenDialog::OnSoutSettings)
132 /* Events generated by the caching button */
133 EVT_CHECKBOX(CachingEnable_Event, OpenDialog::OnCachingEnable)
134 EVT_TEXT(CachingChange_Event, OpenDialog::OnCachingChange)
135 EVT_SPINCTRL(CachingChange_Event, OpenDialog::OnCachingChange)
137 /* Hide the window when the user closes the window */
138 EVT_CLOSE(OpenDialog::OnCancel)
142 /*****************************************************************************
144 *****************************************************************************/
145 WX_DEFINE_ARRAY(ConfigControl *, ArrayOfConfigControls);
147 class AutoBuiltPanel : public wxPanel
152 AutoBuiltPanel( wxWindow *, OpenDialog *, intf_thread_t *,
155 virtual ~AutoBuiltPanel() {}
157 void UpdateAdvancedMRL();
160 ArrayOfConfigControls config_array;
161 ArrayOfConfigControls advanced_config_array;
162 wxComboBox *p_advanced_mrl_combo;
165 intf_thread_t *p_intf;
166 OpenDialog *p_open_dialog;
168 void OnAdvanced( wxCommandEvent& event );
169 wxDialog *p_advanced_dialog;
171 DECLARE_EVENT_TABLE();
174 BEGIN_EVENT_TABLE(AutoBuiltPanel, wxPanel)
175 EVT_BUTTON(AdvancedOptions_Event, AutoBuiltPanel::OnAdvanced)
178 static void AutoBuildCallback( void *p_data )
180 ((OpenDialog *)p_data)->UpdateMRL();
183 static void AutoBuildAdvancedCallback( void *p_data )
185 ((AutoBuiltPanel *)p_data)->UpdateAdvancedMRL();
188 AutoBuiltPanel::AutoBuiltPanel( wxWindow *parent, OpenDialog *dialog,
189 intf_thread_t *_p_intf,
190 const module_t *p_module )
191 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize ),
192 name( wxU(p_module->psz_object_name) ),
193 p_advanced_mrl_combo( NULL ),
194 p_intf( _p_intf ), p_open_dialog( dialog ), p_advanced_dialog( NULL )
196 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
197 module_config_t *p_item = p_module->p_config;
198 bool b_advanced = false;
202 if( !(p_item->i_type & CONFIG_HINT) && p_item->b_advanced )
205 if( p_item->i_type & CONFIG_HINT || p_item->b_advanced )
208 ConfigControl *control =
209 CreateConfigControl( VLC_OBJECT(p_intf), p_item, this );
211 config_array.Add( control );
213 /* Don't add items that were not recognized */
214 if( control == NULL ) continue;
216 control->SetUpdateCallback( AutoBuildCallback, (void *)dialog );
218 sizer->Add( control, 0, wxEXPAND | wxALL, 2 );
220 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
224 wxPanel *dummy_panel = new wxPanel( this, -1 );
225 sizer->Add( dummy_panel, 1 );
228 new wxButton( this, AdvancedOptions_Event,
229 wxU(_("Advanced options...")) );
230 sizer->Add( button, 0, wxALL, 5 );
232 /* Build the advanced dialog */
234 new wxDialog( this, -1, ((wxString)wxU(_("Advanced options"))) +
235 wxT(" (") + wxU( p_module->psz_longname ) + wxT(")"),
236 wxDefaultPosition, wxDefaultSize,
237 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER );
239 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
241 /* Create MRL combobox */
242 wxBoxSizer *mrl_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
243 wxStaticBox *mrl_box =
244 new wxStaticBox( p_advanced_dialog, -1,
245 wxU(_("Advanced options")) );
246 wxStaticBoxSizer *mrl_sizer =
247 new wxStaticBoxSizer( mrl_box, wxHORIZONTAL );
248 wxStaticText *mrl_label =
249 new wxStaticText( p_advanced_dialog, -1, wxU(_("Options:")) );
250 p_advanced_mrl_combo =
251 new wxComboBox( p_advanced_dialog, MRL_Event, wxT(""),
252 wxDefaultPosition, wxDefaultSize );
253 mrl_sizer->Add( mrl_label, 0, wxALL | wxALIGN_CENTER, 5 );
254 mrl_sizer->Add( p_advanced_mrl_combo, 1, wxALL | wxALIGN_CENTER, 5 );
255 mrl_sizer_sizer->Add( mrl_sizer, 1, wxEXPAND | wxALL, 5 );
256 sizer->Add( mrl_sizer_sizer, 0, wxEXPAND | wxALL, 2 );
258 /* Add advanced options to panel */
259 module_config_t *p_item = p_module->p_config;
262 if( p_item->i_type & CONFIG_HINT || !p_item->b_advanced )
265 ConfigControl *control =
266 CreateConfigControl( VLC_OBJECT(p_intf), p_item,
269 advanced_config_array.Add( control );
271 /* Don't add items that were not recognized */
272 if( control == NULL ) continue;
274 control->SetUpdateCallback( AutoBuildAdvancedCallback,
277 sizer->Add( control, 0, wxEXPAND | wxALL, 2 );
279 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
282 dummy_panel = new wxPanel( p_advanced_dialog, -1 );
283 sizer->Add( dummy_panel, 1 );
284 wxStaticLine *static_line =
285 new wxStaticLine( p_advanced_dialog, wxID_OK );
286 sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
289 wxButton *ok_button =
290 new wxButton( p_advanced_dialog, wxID_OK, wxU(_("OK")) );
291 ok_button->SetDefault();
292 wxButton *cancel_button =
293 new wxButton( p_advanced_dialog, wxID_CANCEL, wxU(_("Cancel")) );
294 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
295 button_sizer->Add( ok_button, 0, wxALL, 5 );
296 button_sizer->Add( cancel_button, 0, wxALL, 5 );
297 button_sizer->Layout();
298 sizer->Add( button_sizer, 0, wxALL, 0 );
300 sizer->SetMinSize( 400, -1 );
301 p_advanced_dialog->SetSizerAndFit( sizer );
304 this->SetSizerAndFit( sizer );
307 void AutoBuiltPanel::OnAdvanced( wxCommandEvent& event )
309 if( p_advanced_dialog->ShowModal() == wxID_OK )
312 p_open_dialog->UpdateMRL();
316 void AutoBuiltPanel::UpdateAdvancedMRL()
320 for( int i = 0; i < (int)advanced_config_array.GetCount(); i++ )
322 ConfigControl *control = advanced_config_array.Item(i);
324 mrltemp += (i ? wxT(" :") : wxT(":"));
326 if( control->GetType() == CONFIG_ITEM_BOOL &&
327 !control->GetIntValue() ) mrltemp += wxT("no-");
329 mrltemp += control->GetName();
331 switch( control->GetType() )
333 case CONFIG_ITEM_STRING:
334 case CONFIG_ITEM_FILE:
335 case CONFIG_ITEM_DIRECTORY:
336 case CONFIG_ITEM_MODULE:
337 mrltemp += wxT("=\"") + control->GetPszValue() + wxT("\"");
339 case CONFIG_ITEM_INTEGER:
341 wxString::Format( wxT("=%i"), control->GetIntValue() );
343 case CONFIG_ITEM_FLOAT:
345 wxString::Format(wxT("=%f"), control->GetFloatValue());
350 p_advanced_mrl_combo->SetValue( mrltemp );
353 /*****************************************************************************
355 *****************************************************************************/
356 OpenDialog::OpenDialog( intf_thread_t *_p_intf, wxWindow *_p_parent,
357 int i_access_method, int i_arg ):
358 wxDialog( _p_parent, -1, wxU(_("Open...")), wxDefaultPosition,
359 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
361 OpenDialog( _p_intf, _p_parent, i_access_method, i_arg, OPEN_NORMAL );
364 OpenDialog::OpenDialog( intf_thread_t *_p_intf, wxWindow *_p_parent,
365 int i_access_method, int i_arg, int _i_method ):
366 wxDialog( _p_parent, -1, wxU(_("Open...")), wxDefaultPosition,
367 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
369 /* Initializations */
370 i_method = _i_method;
372 p_parent = _p_parent;
373 SetIcon( *p_intf->p_sys->p_icon );
375 i_disc_type_selection = 0;
379 subsfile_dialog = NULL;
380 b_disc_device_changed = false;
382 /* Create a panel to put everything in */
383 wxPanel *panel = new wxPanel( this, -1 );
384 panel->SetAutoLayout( TRUE );
386 /* Create MRL combobox */
387 wxBoxSizer *mrl_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
388 wxStaticBox *mrl_box = new wxStaticBox( panel, -1,
389 wxU(_("Media Resource Locator (MRL)")) );
390 wxStaticBoxSizer *mrl_sizer = new wxStaticBoxSizer( mrl_box,
392 wxStaticText *mrl_label = new wxStaticText( panel, -1,
394 mrl_combo = new wxComboBox( panel, MRL_Event, wxT(""),
395 wxPoint(20,25), wxSize(120, -1),
397 mrl_combo->SetToolTip( wxU(_("You can use this field directly by typing "
398 "the full MRL you want to open.\n""Alternatively, the field will be "
399 "filled automatically when you use the controls below.")) );
401 mrl_sizer->Add( mrl_label, 0, wxALL | wxALIGN_CENTER, 5 );
402 mrl_sizer->Add( mrl_combo, 1, wxALL | wxALIGN_CENTER, 5 );
403 mrl_sizer_sizer->Add( mrl_sizer, 1, wxEXPAND | wxALL, 5 );
406 /* Create Static Text */
407 wxStaticText *label = new wxStaticText( panel, -1,
408 wxU(_("Alternatively, you can build an MRL using one of the "
409 "following predefined targets:")) );
411 wxFlexGridSizer *common_opt_sizer = new wxFlexGridSizer( 5, 1, 20 );
413 if( i_method == OPEN_NORMAL )
415 /* Create Stream Output checkox */
416 sout_checkbox = new wxCheckBox( panel, SoutEnable_Event,
417 wxU(_("Stream output")) );
418 sout_checkbox->SetToolTip( wxU(_("Use VLC as a server of streams")) );
419 common_opt_sizer->Add( sout_checkbox, 0,
420 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
422 sout_button = new wxButton( panel, SoutSettings_Event,
423 wxU(_("Settings...")) );
424 sout_button->Disable();
426 char *psz_sout = config_GetPsz( p_intf, "sout" );
427 if( psz_sout && *psz_sout )
429 sout_checkbox->SetValue(TRUE);
430 sout_button->Enable();
431 subsfile_mrl.Add( wxString(wxT("sout=")) + wxL2U(psz_sout) );
433 if( psz_sout ) free( psz_sout );
435 common_opt_sizer->Add( sout_button, 1, wxALIGN_LEFT |
436 wxALIGN_CENTER_VERTICAL );
438 common_opt_sizer->Add( new wxPanel( this, -1 ), 1,
439 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
442 /* Create caching options */
443 caching_checkbox = new wxCheckBox( panel, CachingEnable_Event,
445 caching_checkbox->SetToolTip( wxU(_("Change the default caching value "
446 "(in milliseconds)")) );
447 common_opt_sizer->Add( caching_checkbox, 0,
448 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
449 caching_value = new wxSpinCtrl( panel, CachingChange_Event );
450 caching_value->SetRange( 0, 1000000 );
451 caching_value->Disable();
452 common_opt_sizer->Add( caching_value, 0,
453 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
456 wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
458 /* Create the buttons */
459 wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
460 ok_button->SetDefault();
461 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
464 /* Create notebook */
465 notebook = new wxNotebook( panel, Notebook_Event );
466 wxNotebookSizer *notebook_sizer = new wxNotebookSizer( notebook );
468 notebook->AddPage( FilePanel( notebook ), wxU(_("File")),
469 i_access_method == FILE_ACCESS );
470 notebook->AddPage( DiscPanel( notebook ), wxU(_("Disc")),
471 i_access_method == DISC_ACCESS );
472 notebook->AddPage( NetPanel( notebook ), wxU(_("Network")),
473 i_access_method == NET_ACCESS );
475 module_t *p_module = config_FindModule( VLC_OBJECT(p_intf), "v4l" );
478 AutoBuiltPanel *autopanel =
479 new AutoBuiltPanel( notebook, this, p_intf, p_module );
480 input_tab_array.Add( autopanel );
481 notebook->AddPage( autopanel, wxU( p_module->psz_shortname ),
482 i_access_method == CAPTURE_ACCESS );
485 p_module = config_FindModule( VLC_OBJECT(p_intf), "pvr" );
488 AutoBuiltPanel *autopanel =
489 new AutoBuiltPanel( notebook, this, p_intf, p_module );
490 input_tab_array.Add( autopanel );
491 notebook->AddPage( autopanel, wxU( p_module->psz_shortname ),
492 i_access_method == CAPTURE_ACCESS );
495 p_module = config_FindModule( VLC_OBJECT(p_intf), "dvb" );
498 AutoBuiltPanel *autopanel =
499 new AutoBuiltPanel( notebook, this, p_intf, p_module );
500 input_tab_array.Add( autopanel );
501 notebook->AddPage( autopanel, wxU( p_module->psz_shortname ),
502 i_access_method == CAPTURE_ACCESS );
505 p_module = config_FindModule( VLC_OBJECT(p_intf), "dshow" );
508 AutoBuiltPanel *autopanel =
509 new AutoBuiltPanel( notebook, this, p_intf, p_module );
510 input_tab_array.Add( autopanel );
511 notebook->AddPage( autopanel, wxU( p_module->psz_shortname ),
512 i_access_method == CAPTURE_ACCESS );
515 /* Update Disc panel */
516 wxCommandEvent dummy_event;
517 OnDiscTypeChange( dummy_event );
519 /* Update Net panel */
520 dummy_event.SetId( NetRadio1_Event );
521 OnNetTypeChange( dummy_event );
524 wxNotebookEvent event( wxEVT_NULL, 0, i_access_method );
525 OnPageChange( event );
527 /* Place everything in sizers */
528 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
529 button_sizer->Add( ok_button, 0, wxALL, 5 );
530 button_sizer->Add( cancel_button, 0, wxALL, 5 );
531 button_sizer->Layout();
532 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
533 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
534 panel_sizer->Add( mrl_sizer_sizer, 0, wxEXPAND, 5 );
535 panel_sizer->Add( label, 0, wxEXPAND | wxALL, 5 );
536 panel_sizer->Add( notebook_sizer, 1, wxEXPAND | wxALL, 5 );
537 panel_sizer->Add( common_opt_sizer, 0, wxALIGN_LEFT | wxALL, 5 );
538 panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
539 panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALL, 5 );
540 panel_sizer->Layout();
541 panel->SetSizerAndFit( panel_sizer );
542 main_sizer->Add( panel, 1, wxGROW, 0 );
543 main_sizer->Layout();
544 SetSizerAndFit( main_sizer );
547 OpenDialog::~OpenDialog()
550 if( file_dialog ) delete file_dialog;
551 if( sout_dialog ) delete sout_dialog;
552 if( subsfile_dialog ) delete subsfile_dialog;
555 int OpenDialog::Show( int i_access_method, int i_arg )
557 notebook->SetSelection( i_access_method );
558 int i_ret = wxDialog::Show();
565 int OpenDialog::Show()
567 int i_ret = wxDialog::Show();
573 /*****************************************************************************
575 *****************************************************************************/
576 wxPanel *OpenDialog::FilePanel( wxWindow* parent )
578 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
581 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
583 /* Create browse file line */
584 wxBoxSizer *file_sizer = new wxBoxSizer( wxHORIZONTAL );
586 file_combo = new wxComboBox( panel, FileName_Event, wxT(""),
587 wxPoint(20,25), wxSize(200, -1), 0, NULL );
588 wxButton *browse_button = new wxButton( panel, FileBrowse_Event,
589 wxU(_("Browse...")) );
590 file_sizer->Add( file_combo, 1, wxALL, 5 );
591 file_sizer->Add( browse_button, 0, wxALL, 5 );
593 /* Create Subtitles File checkox */
594 wxFlexGridSizer *subsfile_sizer = new wxFlexGridSizer( 2, 1, 20 );
595 subsfile_checkbox = new wxCheckBox( panel, SubsFileEnable_Event,
596 wxU(_("Subtitle options")) );
597 subsfile_checkbox->SetToolTip( wxU(_("Force options for separate subtitle files.")) );
598 subsfile_sizer->Add( subsfile_checkbox, 0,
599 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
600 subsfile_button = new wxButton( panel, SubsFileSettings_Event,
601 wxU(_("Settings...")) );
602 subsfile_button->Disable();
604 char *psz_subsfile = config_GetPsz( p_intf, "sub-file" );
605 if( psz_subsfile && *psz_subsfile )
607 subsfile_checkbox->SetValue(TRUE);
608 subsfile_button->Enable();
609 subsfile_mrl.Add( wxString(wxT("sub-file=")) + wxL2U(psz_subsfile) );
611 if( psz_subsfile ) free( psz_subsfile );
613 subsfile_sizer->Add( subsfile_button, 1,
614 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
616 sizer->Add( file_sizer, 0, wxEXPAND | wxALL, 5 );
617 sizer->Add( subsfile_sizer, 0, wxEXPAND | wxALL, 5 );
618 panel->SetSizerAndFit( sizer );
622 wxPanel *OpenDialog::DiscPanel( wxWindow* parent )
624 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
627 wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
628 wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 3, 20 );
630 static const wxString disc_type_array[] =
632 wxU(_("DVD (menus)")),
638 disc_type = new wxRadioBox( panel, DiscType_Event, wxU(_("Disc type")),
639 wxDefaultPosition, wxDefaultSize,
640 WXSIZEOF(disc_type_array), disc_type_array,
641 WXSIZEOF(disc_type_array), wxRA_SPECIFY_COLS );
643 sizer_row->Add( disc_type, i_disc_type_selection, wxEXPAND | wxALL, 5 );
645 wxStaticText *label = new wxStaticText( panel, -1, wxU(_("Device name")) );
646 disc_device = new wxTextCtrl( panel, DiscDevice_Event, wxT(""),
647 wxDefaultPosition, wxDefaultSize,
650 sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
651 sizer->Add( disc_device, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
653 disc_title_label = new wxStaticText( panel, -1, wxU(_("Title")) );
654 disc_title = new wxSpinCtrl( panel, DiscTitle_Event );
655 sizer->Add( disc_title_label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
656 sizer->Add( disc_title, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
658 disc_chapter_label = new wxStaticText( panel, -1, wxU(_("Chapter")) );
659 disc_chapter = new wxSpinCtrl( panel, DiscChapter_Event );
660 sizer->Add( disc_chapter_label, 0,
661 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
662 sizer->Add( disc_chapter, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
664 disc_sub_label = new wxStaticText( panel, -1, wxU(_("Subtitles track")) );
665 disc_sub = new wxSpinCtrl( panel, DiscSub_Event );
666 sizer->Add( disc_sub_label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
667 sizer->Add( disc_sub, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
668 disc_sub->SetRange( -1, 255 );
669 i_disc_sub = config_GetInt( p_intf, "spu-channel" );
670 disc_sub->SetValue( i_disc_sub );
672 sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
674 panel->SetSizerAndFit( sizer_row );
678 wxPanel *OpenDialog::NetPanel( wxWindow* parent )
681 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
684 wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
685 wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 4, 20 );
687 static const wxString net_type_array[] =
690 wxU(_("UDP/RTP Multicast")),
691 wxU(_("HTTP/FTP/MMS")),
697 net_radios[i] = new wxRadioButton( panel, NetRadio1_Event + i,
699 wxDefaultPosition, wxDefaultSize,
702 net_subpanels[i] = new wxPanel( panel, -1,
703 wxDefaultPosition, wxDefaultSize );
707 wxFlexGridSizer *subpanel_sizer;
709 i_net_ports[0] = config_GetInt( p_intf, "server-port" );
710 subpanel_sizer = new wxFlexGridSizer( 3, 1, 20 );
711 label = new wxStaticText( net_subpanels[0], -1, wxU(_("Port")) );
712 net_ports[0] = new wxSpinCtrl( net_subpanels[0], NetPort1_Event,
713 wxString::Format(wxT("%d"), i_net_ports[0]),
714 wxDefaultPosition, wxDefaultSize,
716 0, 16000, i_net_ports[0] );
718 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
719 subpanel_sizer->Add( net_ports[0], 1,
720 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
721 net_ipv6 = new wxCheckBox( net_subpanels[0], NetForceIPv6_Event,
722 wxU(_("Force IPv6")));
723 subpanel_sizer->Add( net_ipv6, 0,
724 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
725 net_subpanels[0]->SetSizerAndFit( subpanel_sizer );
726 net_radios[0]->SetValue( TRUE );
728 /* UDP/RTP Multicast row */
729 subpanel_sizer = new wxFlexGridSizer( 4, 1, 20 );
730 label = new wxStaticText( net_subpanels[1], -1, wxU(_("Address")) );
731 net_addrs[1] = new wxTextCtrl( net_subpanels[1], NetAddr2_Event, wxT(""),
732 wxDefaultPosition, wxDefaultSize,
734 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
735 subpanel_sizer->Add( net_addrs[1], 1,
736 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
738 label = new wxStaticText( net_subpanels[1], -1, wxU(_("Port")) );
739 i_net_ports[1] = i_net_ports[0];
740 net_ports[1] = new wxSpinCtrl( net_subpanels[1], NetPort2_Event,
741 wxString::Format(wxT("%d"), i_net_ports[1]),
742 wxDefaultPosition, wxDefaultSize,
744 0, 16000, i_net_ports[1] );
746 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
747 subpanel_sizer->Add( net_ports[1], 1,
748 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
749 net_subpanels[1]->SetSizerAndFit( subpanel_sizer );
751 /* HTTP and RTSP rows */
754 subpanel_sizer = new wxFlexGridSizer( 2, 1, 20 );
755 label = new wxStaticText( net_subpanels[i], -1, wxU(_("URL")) );
756 net_addrs[i] = new wxTextCtrl( net_subpanels[i], NetAddr1_Event + i,
757 (i == 2) ? wxT("") : wxT("rtsp://"),
758 wxDefaultPosition, wxSize( 200, -1 ),
760 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
761 subpanel_sizer->Add( net_addrs[i], 1,
762 wxEXPAND | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
763 net_subpanels[i]->SetSizerAndFit( subpanel_sizer );
766 /* Stuff everything into the main panel */
769 sizer->Add( net_radios[i], 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
771 sizer->Add( net_subpanels[i], 1, wxEXPAND | wxALIGN_LEFT |
772 wxALIGN_CENTER_VERTICAL | wxALL, 5 );
775 sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
777 panel->SetSizerAndFit( sizer_row );
781 void OpenDialog::UpdateMRL()
783 UpdateMRL( i_current_access_method );
786 void OpenDialog::UpdateMRL( int i_access_method )
788 wxString demux, mrltemp, caching_name;
790 i_current_access_method = i_access_method;
792 switch( i_access_method )
795 mrltemp = file_combo->GetValue();
796 caching_name = wxT("file-caching");
800 i_disc_type_selection = disc_type->GetSelection();
802 switch ( i_disc_type_selection )
804 case 0: /* DVD with menus */
805 case 1: /* DVD without menus */
806 if( i_disc_type_selection == 0 )
808 mrltemp = wxT("dvd://") + disc_device->GetValue();
809 caching_name = wxT("dvdnav-caching");
813 mrltemp = wxT("dvdsimple://") + disc_device->GetValue();
814 caching_name = wxT("dvdread-caching");
817 if( i_disc_title > 0 )
819 mrltemp += wxString::Format( wxT("@%d"), i_disc_title );
821 if( i_disc_chapter > 0 )
822 mrltemp += wxString::Format( wxT(":%d"), i_disc_chapter );
825 if( i_disc_sub >= 0 )
826 mrltemp += wxString::Format( wxT(" :spu-channel=%d"),
830 case 2: /* VCD of some sort */
832 mrltemp = wxT("vcdx://") + disc_device->GetValue();
833 if( i_disc_title > 0 )
834 mrltemp += wxString::Format( wxT("@%c%d"),
835 config_GetInt( p_intf, "vcdx-PBC" )
836 ? 'P' : 'E', i_disc_title );
838 mrltemp = wxT("vcd://") + disc_device->GetValue();
839 if( i_disc_title > 0 )
840 mrltemp += wxString::Format( wxT("@%d"), i_disc_title );
843 if( i_disc_sub >= 0 )
844 mrltemp += wxString::Format( wxT(" :spu-channel=%d"),
847 caching_name = wxT("vcd-caching");
851 mrltemp = wxT("cdda://") + disc_device->GetValue();
852 if( i_disc_title > 0 )
853 mrltemp += wxString::Format( wxT("@%d"), i_disc_title );
855 caching_name = wxT("cdda-caching");
859 msg_Err( p_intf, "invalid selection (%d)",
860 disc_type->GetSelection() );
869 mrltemp = wxT("udp") + demux + wxT("://");
870 if ( net_ipv6->GetValue() )
872 mrltemp += wxT("@[::]");
874 if( i_net_ports[0] !=
875 config_GetInt( p_intf, "server-port" ) )
877 mrltemp += wxString::Format( wxT("@:%d"), i_net_ports[0] );
880 caching_name = wxT("udp-caching");
884 mrltemp = wxT("udp") + demux + wxT("://@");
885 if ((net_addrs[1]->GetLineText(0).Find (':') != -1)
886 && (net_addrs[1]->GetLineText(0)[0u] != '['))
888 /* automatically adds '[' and ']' to IPv6 addresses */
889 mrltemp += wxT("[") + net_addrs[1]->GetLineText(0)
894 mrltemp += net_addrs[1]->GetLineText(0);
896 if( i_net_ports[1] != config_GetInt( p_intf, "server-port" ) )
898 mrltemp += wxString::Format( wxT(":%d"), i_net_ports[1] );
901 caching_name = wxT("udp-caching");
906 if( net_addrs[2]->GetLineText(0).Find(wxT("http://")) )
908 mrltemp = wxT("http") + demux + wxT("://");
910 mrltemp += net_addrs[2]->GetLineText(0);
912 caching_name = wxT("http-caching");
917 if( net_addrs[3]->GetLineText(0).Find(wxT("rtsp://")) != 0 )
919 mrltemp = wxT("rtsp") + demux + wxT("://");
921 mrltemp += net_addrs[3]->GetLineText(0);
923 caching_name = wxT("rtsp-caching");
930 int i_item = i_access_method - MAX_ACCESS;
932 if( i_item < 0 || i_item >= (int)input_tab_array.GetCount() )
935 AutoBuiltPanel *input_panel = input_tab_array.Item( i_item );
937 mrltemp = input_panel->name + wxT("://");
939 for( int i=0; i < (int)input_panel->config_array.GetCount(); i++ )
941 ConfigControl *control = input_panel->config_array.Item(i);
943 mrltemp += wxT(" :");
945 if( control->GetType() == CONFIG_ITEM_BOOL &&
946 !control->GetIntValue() ) mrltemp += wxT("no-");
948 mrltemp += control->GetName();
950 switch( control->GetType() )
952 case CONFIG_ITEM_STRING:
953 case CONFIG_ITEM_FILE:
954 case CONFIG_ITEM_DIRECTORY:
955 case CONFIG_ITEM_MODULE:
956 mrltemp += wxT("=\"") + control->GetPszValue() + wxT("\"");
958 case CONFIG_ITEM_INTEGER:
960 wxString::Format( wxT("=%i"), control->GetIntValue() );
962 case CONFIG_ITEM_FLOAT:
964 wxString::Format(wxT("=%f"), control->GetFloatValue());
969 if( input_panel->p_advanced_mrl_combo &&
970 input_panel->p_advanced_mrl_combo->GetValue() )
972 mrltemp += wxT(" ") +
973 input_panel->p_advanced_mrl_combo->GetValue();
979 if( caching_name.size() )
981 if( caching_value->IsEnabled() )
983 mrltemp += wxT(" :") + caching_name +
984 wxString::Format( wxT("=%d"), i_caching );
988 int i_value = config_GetInt( p_intf, caching_name.mb_str() );
989 caching_value->SetValue( i_value );
993 mrl_combo->SetValue( mrltemp );
996 /*****************************************************************************
998 *****************************************************************************/
999 void OpenDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
1001 mrl = SeparateEntries( mrl_combo->GetValue() );
1002 mrl_combo->Append( mrl_combo->GetValue() );
1003 if( mrl_combo->GetCount() > 10 ) mrl_combo->Delete( 0 );
1004 mrl_combo->SetSelection( mrl_combo->GetCount() - 1 );
1006 if( i_method == OPEN_STREAM )
1008 if( IsModal() ) EndModal( wxID_OK );
1013 /* Update the playlist */
1014 playlist_t *p_playlist =
1015 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1017 if( p_playlist == NULL ) return;
1019 for( int i = 0; i < (int)mrl.GetCount(); i++ )
1021 vlc_bool_t b_start = !i && i_open_arg;
1022 playlist_item_t *p_item =
1023 playlist_ItemNew( p_intf, (const char*)mrl[i].mb_str(),
1024 (const char *)mrl[i].mb_str() );
1026 /* Insert options */
1027 while( i + 1 < (int)mrl.GetCount() &&
1028 ((const char *)mrl[i + 1].mb_str())[0] == ':' )
1030 playlist_ItemAddOption( p_item, mrl[i + 1].mb_str() );
1034 /* Get the options from the subtitles dialog */
1035 if( subsfile_checkbox->IsChecked() && subsfile_mrl.GetCount() )
1037 for( int j = 0; j < (int)subsfile_mrl.GetCount(); j++ )
1039 playlist_ItemAddOption( p_item, subsfile_mrl[j].mb_str() );
1043 /* Get the options from the stream output dialog */
1044 if( sout_checkbox->IsChecked() && sout_mrl.GetCount() )
1046 for( int j = 0; j < (int)sout_mrl.GetCount(); j++ )
1048 playlist_ItemAddOption( p_item, sout_mrl[j].mb_str() );
1052 int i_id = playlist_AddItem( p_playlist, p_item,
1053 PLAYLIST_APPEND, PLAYLIST_END );
1057 int i_pos = playlist_GetPositionById( p_playlist , i_id );
1058 playlist_Command( p_playlist, PLAYLIST_GOTO, i_pos );
1062 vlc_object_release( p_playlist );
1066 if( IsModal() ) EndModal( wxID_OK );
1069 void OpenDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
1073 if( IsModal() ) EndModal( wxID_CANCEL );
1076 void OpenDialog::OnPageChange( wxNotebookEvent& event )
1078 UpdateMRL( event.GetSelection() );
1081 void OpenDialog::OnMRLChange( wxCommandEvent& event )
1083 //mrl = SeparateEntries( event.GetString() );
1086 /*****************************************************************************
1087 * File panel event methods.
1088 *****************************************************************************/
1089 void OpenDialog::OnFilePanelChange( wxCommandEvent& WXUNUSED(event) )
1091 UpdateMRL( FILE_ACCESS );
1094 void OpenDialog::OnFileBrowse( wxCommandEvent& WXUNUSED(event) )
1096 if( file_dialog == NULL )
1097 file_dialog = new wxFileDialog( this, wxU(_("Open File")),
1098 wxT(""), wxT(""), wxT("*"), wxOPEN | wxMULTIPLE );
1100 if( file_dialog && file_dialog->ShowModal() == wxID_OK )
1102 wxArrayString paths;
1105 file_dialog->GetPaths( paths );
1107 for( size_t i = 0; i < paths.GetCount(); i++ )
1109 if( paths[i].Find( wxT(' ') ) >= 0 )
1110 path += wxT("\"") + paths[i] + wxT("\" ");
1112 path += paths[i] + wxT(" ");
1115 file_combo->SetValue( path );
1116 file_combo->Append( path );
1117 if( file_combo->GetCount() > 10 ) file_combo->Delete( 0 );
1118 UpdateMRL( FILE_ACCESS );
1122 /*****************************************************************************
1123 * Disc panel event methods.
1124 *****************************************************************************/
1125 void OpenDialog::OnDiscPanelChange( wxCommandEvent& event )
1127 if( event.GetId() == DiscTitle_Event ) i_disc_title = event.GetInt();
1128 if( event.GetId() == DiscChapter_Event ) i_disc_chapter = event.GetInt();
1129 if( event.GetId() == DiscSub_Event ) i_disc_sub = event.GetInt();
1131 UpdateMRL( DISC_ACCESS );
1134 void OpenDialog::OnDiscDeviceChange( wxCommandEvent& event )
1138 switch( disc_type->GetSelection() )
1141 psz_device = config_GetPsz( p_intf, "cd-audio" );
1145 psz_device = config_GetPsz( p_intf, "vcd" );
1149 psz_device = config_GetPsz( p_intf, "dvd" );
1153 if ( !psz_device ) psz_device = "";
1155 if( disc_device->GetValue().Cmp( wxL2U( psz_device ) ) )
1157 b_disc_device_changed = true;
1160 UpdateMRL( DISC_ACCESS );
1163 void OpenDialog::OnDiscTypeChange( wxCommandEvent& WXUNUSED(event) )
1165 char *psz_device = NULL;
1167 switch( disc_type->GetSelection() )
1170 case 0: /* DVD with menus */
1171 case 1: /* DVD without menus */
1172 disc_sub->Enable(); disc_sub_label->Enable();
1173 disc_chapter->Enable(); disc_chapter_label->Enable();
1174 disc_title_label->SetLabel ( wxU(_("Title")) );
1175 psz_device = config_GetPsz( p_intf, "dvd" );
1176 if( !b_disc_device_changed )
1178 if( psz_device ) disc_device->SetValue( wxL2U(psz_device) );
1179 else disc_device->SetValue( wxT("") );
1181 disc_title->SetRange( 0, 255 );
1182 disc_chapter->SetRange( 0, 255 );
1185 case 2: /* VCD of some sort */
1186 disc_sub->Enable(); disc_sub_label->Enable();
1187 disc_chapter->Disable(); disc_chapter_label->Disable();
1188 psz_device = config_GetPsz( p_intf, "vcd" );
1189 if( !b_disc_device_changed )
1191 if( psz_device ) disc_device->SetValue( wxL2U(psz_device) );
1192 else disc_device->SetValue( wxT("") );
1196 disc_title_label->SetLabel ( config_GetInt( p_intf, "vcdx-PBC" )
1197 ? wxT("Playback LID") : wxT("Entry") );
1199 disc_title_label->SetLabel ( wxU(_("Track")) );
1201 disc_title->SetRange( 0, 999 );
1205 disc_sub->Disable(); disc_sub_label->Disable();
1206 disc_chapter->Disable(); disc_chapter_label->Disable();
1207 disc_title_label->SetLabel ( wxU(_("Track")) );
1208 psz_device = config_GetPsz( p_intf, "cd-audio" );
1209 if( !b_disc_device_changed )
1211 if( psz_device ) disc_device->SetValue( wxL2U(psz_device) );
1212 else disc_device->SetValue( wxT("") );
1215 /* There are at most 99 tracks in a CD-DA */
1216 disc_title->SetRange( 0, 99 );
1220 msg_Err( p_intf, "invalid Disc type selection (%d)",
1221 disc_type->GetSelection() );
1225 disc_title->SetValue( 0 ); i_disc_title = 0;
1226 disc_chapter->SetValue( 0 ); i_disc_chapter = 0;
1228 if( psz_device ) free( psz_device );
1230 UpdateMRL( DISC_ACCESS );
1233 /*****************************************************************************
1234 * Net panel event methods.
1235 *****************************************************************************/
1236 void OpenDialog::OnNetPanelChange( wxCommandEvent& event )
1238 if( event.GetId() >= NetPort1_Event && event.GetId() <= NetPort3_Event )
1240 i_net_ports[event.GetId() - NetPort1_Event] = event.GetInt();
1243 UpdateMRL( NET_ACCESS );
1246 void OpenDialog::OnNetTypeChange( wxCommandEvent& event )
1250 i_net_type = event.GetId() - NetRadio1_Event;
1254 net_radios[i]->SetValue( event.GetId() == (NetRadio1_Event+i) );
1255 net_subpanels[i]->Enable( event.GetId() == (NetRadio1_Event+i) );
1258 UpdateMRL( NET_ACCESS );
1261 /*****************************************************************************
1262 * Subtitles file event methods.
1263 *****************************************************************************/
1264 void OpenDialog::OnSubsFileEnable( wxCommandEvent& event )
1266 subsfile_button->Enable( event.GetInt() != 0 );
1269 void OpenDialog::OnSubsFileSettings( wxCommandEvent& WXUNUSED(event) )
1271 /* Show/hide the open dialog */
1272 if( subsfile_dialog == NULL )
1273 subsfile_dialog = new SubsFileDialog( p_intf, this );
1275 if( subsfile_dialog && subsfile_dialog->ShowModal() == wxID_OK )
1277 subsfile_mrl.Empty();
1278 subsfile_mrl.Add( wxString(wxT("sub-file=")) +
1279 subsfile_dialog->file_combo->GetValue() );
1280 if( subsfile_dialog->encoding_combo )
1281 subsfile_mrl.Add( wxString(wxT("subsdec-encoding=")) +
1282 subsfile_dialog->encoding_combo->GetValue() );
1283 subsfile_mrl.Add( wxString::Format( wxT("sub-delay=%i"),
1284 subsfile_dialog->delay_spinctrl->GetValue() ) );
1285 subsfile_mrl.Add( wxString::Format( wxT("sub-fps=%i"),
1286 subsfile_dialog->fps_spinctrl->GetValue() ) );
1290 /*****************************************************************************
1291 * Stream output event methods.
1292 *****************************************************************************/
1293 void OpenDialog::OnSoutEnable( wxCommandEvent& event )
1295 sout_button->Enable( event.GetInt() != 0 );
1298 void OpenDialog::OnSoutSettings( wxCommandEvent& WXUNUSED(event) )
1300 /* Show/hide the open dialog */
1301 if( sout_dialog == NULL )
1302 sout_dialog = new SoutDialog( p_intf, this );
1304 if( sout_dialog && sout_dialog->ShowModal() == wxID_OK )
1306 sout_mrl = sout_dialog->GetOptions();
1310 /*****************************************************************************
1311 * Caching event methods.
1312 *****************************************************************************/
1313 void OpenDialog::OnCachingEnable( wxCommandEvent& event )
1315 caching_value->Enable( event.GetInt() != 0 );
1316 i_caching = caching_value->GetValue();
1320 void OpenDialog::OnCachingChange( wxCommandEvent& event )
1322 i_caching = event.GetInt();
1326 /*****************************************************************************
1327 * Utility functions.
1328 *****************************************************************************/
1329 wxArrayString SeparateEntries( wxString entries )
1331 vlc_bool_t b_quotes_mode = VLC_FALSE;
1333 wxArrayString entries_array;
1336 wxStringTokenizer token( entries, wxT(" \t\r\n\""), wxTOKEN_RET_DELIMS );
1338 while( token.HasMoreTokens() )
1340 entry += token.GetNextToken();
1342 if( entry.IsEmpty() ) continue;
1344 if( !b_quotes_mode && entry.Last() == wxT('\"') )
1346 /* Enters quotes mode */
1348 b_quotes_mode = VLC_TRUE;
1350 else if( b_quotes_mode && entry.Last() == wxT('\"') )
1352 /* Finished the quotes mode */
1354 b_quotes_mode = VLC_FALSE;
1356 else if( !b_quotes_mode && entry.Last() != wxT('\"') )
1358 /* we found a non-quoted standalone string */
1359 if( token.HasMoreTokens() ||
1360 entry.Last() == wxT(' ') || entry.Last() == wxT('\t') ||
1361 entry.Last() == wxT('\r') || entry.Last() == wxT('\n') )
1363 if( !entry.IsEmpty() ) entries_array.Add( entry );
1370 if( !entry.IsEmpty() ) entries_array.Add( entry );
1372 return entries_array;