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, wxFrame)
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(wxID_OK, AutoBuiltPanel::OnAdvanced)
165 EVT_BUTTON(AdvancedOptions_Event, AutoBuiltPanel::OnAdvanced)
168 static void AutoBuildCallback( void *p_data )
170 ((OpenDialog *)p_data)->UpdateMRL();
173 static void AutoBuildAdvancedCallback( void *p_data )
175 ((AutoBuiltPanel *)p_data)->UpdateAdvancedMRL();
178 AutoBuiltPanel::AutoBuiltPanel( wxWindow *parent, OpenDialog *dialog,
179 intf_thread_t *_p_intf,
180 const module_t *p_module )
181 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize ),
182 name( wxU(p_module->psz_object_name) ),
183 p_advanced_mrl_combo( NULL ),
184 p_intf( _p_intf ), p_open_dialog( dialog ), p_advanced_dialog( NULL )
186 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
187 module_config_t *p_item = p_module->p_config;
188 bool b_advanced = false;
192 if( !(p_item->i_type & CONFIG_HINT) && p_item->b_advanced )
195 if( p_item->i_type & CONFIG_HINT || p_item->b_advanced )
198 ConfigControl *control =
199 CreateConfigControl( VLC_OBJECT(p_intf), p_item, this );
201 config_array.Add( control );
203 /* Don't add items that were not recognized */
204 if( control == NULL ) continue;
206 control->SetUpdateCallback( AutoBuildCallback, (void *)dialog );
208 sizer->Add( control, 0, wxEXPAND | wxALL, 2 );
210 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
214 wxPanel *dummy_panel = new wxPanel( this, -1 );
215 sizer->Add( dummy_panel, 1 );
218 new wxButton( this, AdvancedOptions_Event,
219 wxU(_("Advanced options...")) );
220 sizer->Add( button, 0, wxALL, 5 );
222 /* Build the advanced dialog */
224 new wxDialog( this, -1, ((wxString)wxU(_("Advanced options"))) +
225 wxT(" (") + wxU( p_module->psz_longname ) + wxT(")"),
226 wxDefaultPosition, wxDefaultSize,
227 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER );
229 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
231 /* Create MRL combobox */
232 wxBoxSizer *mrl_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
233 wxStaticBox *mrl_box =
234 new wxStaticBox( p_advanced_dialog, -1,
235 wxU(_("Advanced options")) );
236 wxStaticBoxSizer *mrl_sizer =
237 new wxStaticBoxSizer( mrl_box, wxHORIZONTAL );
238 wxStaticText *mrl_label =
239 new wxStaticText( p_advanced_dialog, -1, wxU(_("Options:")) );
240 p_advanced_mrl_combo =
241 new wxComboBox( p_advanced_dialog, MRL_Event, wxT(""),
242 wxDefaultPosition, wxDefaultSize );
243 mrl_sizer->Add( mrl_label, 0, wxALL | wxALIGN_CENTER, 5 );
244 mrl_sizer->Add( p_advanced_mrl_combo, 1, wxALL | wxALIGN_CENTER, 5 );
245 mrl_sizer_sizer->Add( mrl_sizer, 1, wxEXPAND | wxALL, 5 );
246 sizer->Add( mrl_sizer_sizer, 0, wxEXPAND | wxALL, 2 );
248 /* Add advanced options to panel */
249 module_config_t *p_item = p_module->p_config;
252 if( p_item->i_type & CONFIG_HINT || !p_item->b_advanced )
255 ConfigControl *control =
256 CreateConfigControl( VLC_OBJECT(p_intf), p_item,
259 advanced_config_array.Add( control );
261 /* Don't add items that were not recognized */
262 if( control == NULL ) continue;
264 control->SetUpdateCallback( AutoBuildAdvancedCallback,
267 sizer->Add( control, 0, wxEXPAND | wxALL, 2 );
269 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
272 dummy_panel = new wxPanel( p_advanced_dialog, -1 );
273 sizer->Add( dummy_panel, 1 );
274 wxStaticLine *static_line =
275 new wxStaticLine( p_advanced_dialog, wxID_OK );
276 sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
278 /* Create OK button */
279 wxButton *ok_button =
280 new wxButton( p_advanced_dialog, wxID_OK, wxU(_("OK")) );
281 ok_button->SetDefault();
282 sizer->Add( ok_button, 0, wxALL, 5 );
284 sizer->SetMinSize( 400, -1 );
285 p_advanced_dialog->SetSizerAndFit( sizer );
288 this->SetSizerAndFit( sizer );
291 void AutoBuiltPanel::OnAdvanced( wxCommandEvent& event )
293 p_advanced_dialog->Show( !p_advanced_dialog->IsShown() );
295 p_open_dialog->UpdateMRL();
298 void AutoBuiltPanel::UpdateAdvancedMRL()
302 for( int i = 0; i < (int)advanced_config_array.GetCount(); i++ )
304 ConfigControl *control = advanced_config_array.Item(i);
308 if( control->GetType() == CONFIG_ITEM_BOOL &&
309 !control->GetIntValue() ) mrltemp += wxT("no-");
311 mrltemp += control->GetName();
313 switch( control->GetType() )
315 case CONFIG_ITEM_STRING:
316 case CONFIG_ITEM_FILE:
317 case CONFIG_ITEM_DIRECTORY:
318 case CONFIG_ITEM_MODULE:
319 mrltemp += wxT("=\"") + control->GetPszValue() + wxT("\"");
321 case CONFIG_ITEM_INTEGER:
323 wxString::Format( wxT("=%i"), control->GetIntValue() );
325 case CONFIG_ITEM_FLOAT:
327 wxString::Format(wxT("=%f"), control->GetFloatValue());
332 p_advanced_mrl_combo->SetValue( mrltemp );
335 /*****************************************************************************
337 *****************************************************************************/
338 OpenDialog::OpenDialog( intf_thread_t *_p_intf, wxWindow *_p_parent,
339 int i_access_method, int i_arg ):
340 wxFrame( _p_parent, -1, wxU(_("Open...")), wxDefaultPosition,
341 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
343 OpenDialog( _p_intf, _p_parent, i_access_method, i_arg, OPEN_NORMAL );
346 OpenDialog::OpenDialog( intf_thread_t *_p_intf, wxWindow *_p_parent,
347 int i_access_method, int i_arg, int _i_method ):
348 wxFrame( _p_parent, -1, wxU(_("Open...")), wxDefaultPosition,
349 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
351 /* Initializations */
352 i_method = _i_method;
354 p_parent = _p_parent;
355 SetIcon( *p_intf->p_sys->p_icon );
357 i_disc_type_selection = 0;
361 subsfile_dialog = NULL;
362 b_disc_device_changed = false;
364 /* Create a panel to put everything in */
365 wxPanel *panel = new wxPanel( this, -1 );
366 panel->SetAutoLayout( TRUE );
368 /* Create MRL combobox */
369 wxBoxSizer *mrl_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
370 wxStaticBox *mrl_box = new wxStaticBox( panel, -1,
371 wxU(_("Media Resource Locator (MRL)")) );
372 wxStaticBoxSizer *mrl_sizer = new wxStaticBoxSizer( mrl_box,
374 wxStaticText *mrl_label = new wxStaticText( panel, -1,
376 mrl_combo = new wxComboBox( panel, MRL_Event, wxT(""),
377 wxPoint(20,25), wxSize(120, -1),
379 mrl_combo->SetToolTip( wxU(_("You can use this field directly by typing "
380 "the full MRL you want to open.\n""Alternatively, the field will be "
381 "filled automatically when you use the controls below.")) );
383 mrl_sizer->Add( mrl_label, 0, wxALL | wxALIGN_CENTER, 5 );
384 mrl_sizer->Add( mrl_combo, 1, wxALL | wxALIGN_CENTER, 5 );
385 mrl_sizer_sizer->Add( mrl_sizer, 1, wxEXPAND | wxALL, 5 );
388 /* Create Static Text */
389 wxStaticText *label = new wxStaticText( panel, -1,
390 wxU(_("Alternatively, you can build an MRL using one of the "
391 "following predefined targets:")) );
393 wxFlexGridSizer *sout_sizer = NULL;
394 wxStaticLine *static_line = NULL;
396 if( i_method == OPEN_NORMAL )
398 /* Create Stream Output checkox */
399 sout_sizer = new wxFlexGridSizer( 2, 1, 20 );
402 sout_checkbox = new wxCheckBox( panel, SoutEnable_Event,
403 wxU(_("Stream output")) );
404 sout_checkbox->SetToolTip( wxU(_("Use VLC as a server of streams")) );
405 sout_sizer->Add( sout_checkbox, 0,
406 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
407 sout_button = new wxButton( panel, SoutSettings_Event,
408 wxU(_("Settings...")) );
409 sout_button->Disable();
411 char *psz_sout = config_GetPsz( p_intf, "sout" );
412 if( psz_sout && *psz_sout )
414 sout_checkbox->SetValue(TRUE);
415 sout_button->Enable();
416 subsfile_mrl.Add( wxString(wxT("sout=")) + wxL2U(psz_sout) );
418 if( psz_sout ) free( psz_sout );
420 sout_sizer->Add( sout_button, 1, wxALIGN_LEFT |
421 wxALIGN_CENTER_VERTICAL );
424 static_line = new wxStaticLine( panel, wxID_OK );
427 /* Create the buttons */
428 wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
429 ok_button->SetDefault();
430 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
433 /* Create notebook */
434 notebook = new wxNotebook( panel, Notebook_Event );
435 wxNotebookSizer *notebook_sizer = new wxNotebookSizer( notebook );
437 notebook->AddPage( FilePanel( notebook ), wxU(_("File")),
438 i_access_method == FILE_ACCESS );
439 notebook->AddPage( DiscPanel( notebook ), wxU(_("Disc")),
440 i_access_method == DISC_ACCESS );
441 notebook->AddPage( NetPanel( notebook ), wxU(_("Network")),
442 i_access_method == NET_ACCESS );
444 module_t *p_module = config_FindModule( VLC_OBJECT(p_intf), "v4l" );
447 AutoBuiltPanel *autopanel =
448 new AutoBuiltPanel( notebook, this, p_intf, p_module );
449 input_tab_array.Add( autopanel );
450 notebook->AddPage( autopanel, wxU( p_module->psz_longname ),
451 i_access_method == CAPTURE_ACCESS );
454 p_module = config_FindModule( VLC_OBJECT(p_intf), "pvr" );
457 AutoBuiltPanel *autopanel =
458 new AutoBuiltPanel( notebook, this, p_intf, p_module );
459 input_tab_array.Add( autopanel );
460 notebook->AddPage( autopanel, wxU( p_module->psz_longname ),
461 i_access_method == CAPTURE_ACCESS );
464 p_module = config_FindModule( VLC_OBJECT(p_intf), "dshow" );
467 AutoBuiltPanel *autopanel =
468 new AutoBuiltPanel( notebook, this, p_intf, p_module );
469 input_tab_array.Add( autopanel );
470 notebook->AddPage( autopanel, wxU( p_module->psz_longname ),
471 i_access_method == CAPTURE_ACCESS );
474 /* Update Disc panel */
475 wxCommandEvent dummy_event;
476 OnDiscTypeChange( dummy_event );
478 /* Update Net panel */
479 dummy_event.SetId( NetRadio1_Event );
480 OnNetTypeChange( dummy_event );
483 wxNotebookEvent event( wxEVT_NULL, 0, i_access_method );
484 OnPageChange( event );
486 /* Place everything in sizers */
487 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
488 button_sizer->Add( ok_button, 0, wxALL, 5 );
489 button_sizer->Add( cancel_button, 0, wxALL, 5 );
490 button_sizer->Layout();
491 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
492 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
493 panel_sizer->Add( mrl_sizer_sizer, 0, wxEXPAND, 5 );
494 panel_sizer->Add( label, 0, wxEXPAND | wxALL, 5 );
495 panel_sizer->Add( notebook_sizer, 1, wxEXPAND | wxALL, 5 );
496 if( i_method == OPEN_NORMAL)
498 panel_sizer->Add( sout_sizer, 0, wxALIGN_LEFT | wxALL, 5 );
499 panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
501 panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALL, 5 );
502 panel_sizer->Layout();
503 panel->SetSizerAndFit( panel_sizer );
504 main_sizer->Add( panel, 1, wxGROW, 0 );
505 main_sizer->Layout();
506 SetSizerAndFit( main_sizer );
509 OpenDialog::~OpenDialog()
512 if( file_dialog ) delete file_dialog;
513 if( sout_dialog ) delete sout_dialog;
514 if( subsfile_dialog ) delete subsfile_dialog;
517 int OpenDialog::Show( int i_access_method, int i_arg )
520 notebook->SetSelection( i_access_method );
521 i_ret = wxFrame::Show();
528 int OpenDialog::Show()
531 i_ret = wxFrame::Show();
537 /*****************************************************************************
539 *****************************************************************************/
540 wxPanel *OpenDialog::FilePanel( wxWindow* parent )
542 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
545 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
547 /* Create browse file line */
548 wxBoxSizer *file_sizer = new wxBoxSizer( wxHORIZONTAL );
550 file_combo = new wxComboBox( panel, FileName_Event, wxT(""),
551 wxPoint(20,25), wxSize(200, -1), 0, NULL );
552 wxButton *browse_button = new wxButton( panel, FileBrowse_Event,
553 wxU(_("Browse...")) );
554 file_sizer->Add( file_combo, 1, wxALL, 5 );
555 file_sizer->Add( browse_button, 0, wxALL, 5 );
557 /* Create Subtitles File checkox */
558 wxFlexGridSizer *subsfile_sizer = new wxFlexGridSizer( 2, 1, 20 );
559 subsfile_checkbox = new wxCheckBox( panel, SubsFileEnable_Event,
560 wxU(_("Subtitle options")) );
561 subsfile_checkbox->SetToolTip( wxU(_("Force options for separate subtitle files.")) );
562 subsfile_sizer->Add( subsfile_checkbox, 0,
563 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
564 subsfile_button = new wxButton( panel, SubsFileSettings_Event,
565 wxU(_("Settings...")) );
566 subsfile_button->Disable();
568 char *psz_subsfile = config_GetPsz( p_intf, "sub-file" );
569 if( psz_subsfile && *psz_subsfile )
571 subsfile_checkbox->SetValue(TRUE);
572 subsfile_button->Enable();
573 subsfile_mrl.Add( wxString(wxT("sub-file=")) + wxL2U(psz_subsfile) );
575 if( psz_subsfile ) free( psz_subsfile );
577 subsfile_sizer->Add( subsfile_button, 1,
578 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
580 sizer->Add( file_sizer, 0, wxEXPAND | wxALL, 5 );
581 sizer->Add( subsfile_sizer, 0, wxEXPAND | wxALL, 5 );
582 panel->SetSizerAndFit( sizer );
586 wxPanel *OpenDialog::DiscPanel( wxWindow* parent )
588 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
591 wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
592 wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 3, 20 );
594 static const wxString disc_type_array[] =
596 wxU(_("DVD (menus support)")),
603 disc_type = new wxRadioBox( panel, DiscType_Event, wxU(_("Disc type")),
604 wxDefaultPosition, wxDefaultSize,
605 WXSIZEOF(disc_type_array), disc_type_array,
606 WXSIZEOF(disc_type_array), wxRA_SPECIFY_COLS );
608 sizer_row->Add( disc_type, i_disc_type_selection, wxEXPAND | wxALL, 5 );
610 wxStaticText *label = new wxStaticText( panel, -1, wxU(_("Device name")) );
611 disc_device = new wxTextCtrl( panel, DiscDevice_Event, wxT(""),
612 wxDefaultPosition, wxDefaultSize,
615 sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
616 sizer->Add( disc_device, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
618 disc_title_label = new wxStaticText( panel, -1, wxU(_("Title")) );
619 disc_title = new wxSpinCtrl( panel, DiscTitle_Event );
621 sizer->Add( disc_title_label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
622 sizer->Add( disc_title, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
624 disc_chapter_label = new wxStaticText( panel, -1, wxU(_("Chapter")) );
625 disc_chapter = new wxSpinCtrl( panel, DiscChapter_Event );
626 sizer->Add( disc_chapter_label, 0,
627 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
628 sizer->Add( disc_chapter, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
629 sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
631 panel->SetSizerAndFit( sizer_row );
635 wxPanel *OpenDialog::NetPanel( wxWindow* parent )
638 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
641 wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
642 wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 4, 20 );
644 static const wxString net_type_array[] =
647 wxU(_("UDP/RTP Multicast")),
648 wxU(_("HTTP/FTP/MMS")),
654 net_radios[i] = new wxRadioButton( panel, NetRadio1_Event + i,
656 wxDefaultPosition, wxDefaultSize,
659 net_subpanels[i] = new wxPanel( panel, -1,
660 wxDefaultPosition, wxDefaultSize );
664 wxFlexGridSizer *subpanel_sizer;
666 i_net_ports[0] = config_GetInt( p_intf, "server-port" );
667 subpanel_sizer = new wxFlexGridSizer( 3, 1, 20 );
668 label = new wxStaticText( net_subpanels[0], -1, wxU(_("Port")) );
669 net_ports[0] = new wxSpinCtrl( net_subpanels[0], NetPort1_Event,
670 wxString::Format(wxT("%d"), i_net_ports[0]),
671 wxDefaultPosition, wxDefaultSize,
673 0, 16000, i_net_ports[0] );
675 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
676 subpanel_sizer->Add( net_ports[0], 1,
677 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
678 net_ipv6 = new wxCheckBox( net_subpanels[0], NetForceIPv6_Event,
679 wxU(_("Force IPv6")));
680 subpanel_sizer->Add( net_ipv6, 0,
681 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
682 net_subpanels[0]->SetSizerAndFit( subpanel_sizer );
683 net_radios[0]->SetValue( TRUE );
685 /* UDP/RTP Multicast row */
686 subpanel_sizer = new wxFlexGridSizer( 4, 1, 20 );
687 label = new wxStaticText( net_subpanels[1], -1, wxU(_("Address")) );
688 net_addrs[1] = new wxTextCtrl( net_subpanels[1], NetAddr2_Event, wxT(""),
689 wxDefaultPosition, wxDefaultSize,
691 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
692 subpanel_sizer->Add( net_addrs[1], 1,
693 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
695 label = new wxStaticText( net_subpanels[1], -1, wxU(_("Port")) );
696 i_net_ports[1] = i_net_ports[0];
697 net_ports[1] = new wxSpinCtrl( net_subpanels[1], NetPort2_Event,
698 wxString::Format(wxT("%d"), i_net_ports[1]),
699 wxDefaultPosition, wxDefaultSize,
701 0, 16000, i_net_ports[1] );
703 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
704 subpanel_sizer->Add( net_ports[1], 1,
705 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
706 net_subpanels[1]->SetSizerAndFit( subpanel_sizer );
708 /* HTTP and RTSP rows */
711 subpanel_sizer = new wxFlexGridSizer( 2, 1, 20 );
712 label = new wxStaticText( net_subpanels[i], -1, wxU(_("URL")) );
713 net_addrs[i] = new wxTextCtrl( net_subpanels[i], NetAddr1_Event + i,
714 (i == 2) ? wxT("") : wxT("rtsp://"),
715 wxDefaultPosition, wxSize( 200, -1 ),
717 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
718 subpanel_sizer->Add( net_addrs[i], 1,
719 wxEXPAND | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
720 net_subpanels[i]->SetSizerAndFit( subpanel_sizer );
723 /* Stuff everything into the main panel */
726 sizer->Add( net_radios[i], 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
728 sizer->Add( net_subpanels[i], 1, wxEXPAND | wxALIGN_LEFT |
729 wxALIGN_CENTER_VERTICAL | wxALL, 5 );
732 sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
734 panel->SetSizerAndFit( sizer_row );
738 void OpenDialog::UpdateMRL()
740 UpdateMRL( i_current_access_method );
743 void OpenDialog::UpdateMRL( int i_access_method )
745 wxString demux, mrltemp;
747 i_current_access_method = i_access_method;
749 switch( i_access_method )
752 //mrltemp = wxT("file") + demux + wxT(":") + file_combo->GetValue();
753 mrltemp = file_combo->GetValue();
756 i_disc_type_selection = disc_type->GetSelection();
758 switch ( i_disc_type_selection )
760 case 0: /* DVD with menues */
761 disc_chapter->Enable();
762 disc_chapter_label->Enable();
763 mrltemp = wxT("dvd://")
764 + disc_device->GetValue()
765 + wxString::Format( wxT("@%d:%d"),
766 disc_title->GetValue(),
767 disc_chapter->GetValue() );
770 case 1: /* DVD of some sort */
771 disc_chapter->Enable();
772 disc_chapter_label->Enable();
773 mrltemp = wxT("dvdsimple://")
774 + disc_device->GetValue()
775 + wxString::Format( wxT("@%d:%d"),
776 disc_title->GetValue(),
777 disc_chapter->GetValue() );
780 case 2: /* VCD of some sort */
782 /* The chapter object is used for subtitles */
784 int i_subtitle = disc_chapter->GetValue();
785 config_PutInt( p_intf, "spu-channel", i_subtitle );
787 disc_chapter->Enable();
788 disc_chapter_label->Enable();
790 if ( disc_title->GetValue() )
791 mrltemp = wxT("vcdx://")
792 + disc_device->GetValue()
793 + wxString::Format( wxT("@%c%d"),
794 config_GetInt( p_intf, "vcdx-PBC" )
796 disc_title->GetValue()
799 mrltemp = wxT("vcdx://")
800 + disc_device->GetValue();
802 mrltemp = wxT("vcd://")
803 + disc_device->GetValue()
804 + wxString::Format( wxT("@%d"),
805 disc_title->GetValue() );
812 disc_chapter->Disable();
813 disc_chapter_label->Disable();
815 if ( disc_title->GetValue() )
816 mrltemp = wxT("cddax://")
817 + disc_device->GetValue()
818 + wxString::Format( wxT("@T%d"),
819 disc_title->GetValue() );
821 mrltemp = wxT("cddax://")
822 + disc_device->GetValue();
825 mrltemp = wxT("cdda://")
826 + disc_device->GetValue()
827 + wxString::Format( wxT("@%d"),
828 disc_title->GetValue() );
832 msg_Err( p_intf, "invalid selection (%d)",
833 disc_type->GetSelection() );
841 mrltemp = wxT("udp") + demux + wxT("://");
842 if ( net_ipv6->GetValue() )
844 mrltemp += wxT("@[::]");
846 if( i_net_ports[0] !=
847 config_GetInt( p_intf, "server-port" ) )
849 mrltemp += wxString::Format( wxT("@:%d"), i_net_ports[0] );
854 mrltemp = wxT("udp") + demux + wxT("://@");
855 if ((net_addrs[1]->GetLineText(0).Find (':') != -1)
856 && (net_addrs[1]->GetLineText(0)[0u] != '['))
858 /* automatically adds '[' and ']' to IPv6 addresses */
859 mrltemp += wxT("[") + net_addrs[1]->GetLineText(0)
864 mrltemp += net_addrs[1]->GetLineText(0);
866 if( i_net_ports[1] != config_GetInt( p_intf, "server-port" ) )
868 mrltemp += wxString::Format( wxT(":%d"), i_net_ports[1] );
874 if( net_addrs[2]->GetLineText(0).Find(wxT("http://")) )
876 mrltemp = wxT("http") + demux + wxT("://");
878 mrltemp += net_addrs[2]->GetLineText(0);
883 if( net_addrs[3]->GetLineText(0).Find(wxT("rtsp://")) != 0 )
885 mrltemp = wxT("rtsp") + demux + wxT("://");
887 mrltemp += net_addrs[3]->GetLineText(0);
894 int i_item = i_access_method - MAX_ACCESS;
896 if( i_item < 0 || i_item >= (int)input_tab_array.GetCount() )
899 AutoBuiltPanel *input_panel = input_tab_array.Item( i_item );
901 mrltemp = input_panel->name + wxT("://");
903 for( int i=0; i < (int)input_panel->config_array.GetCount(); i++ )
905 ConfigControl *control = input_panel->config_array.Item(i);
907 mrltemp += wxT(" :");
909 if( control->GetType() == CONFIG_ITEM_BOOL &&
910 !control->GetIntValue() ) mrltemp += wxT("no-");
912 mrltemp += control->GetName();
914 switch( control->GetType() )
916 case CONFIG_ITEM_STRING:
917 case CONFIG_ITEM_FILE:
918 case CONFIG_ITEM_DIRECTORY:
919 case CONFIG_ITEM_MODULE:
920 mrltemp += wxT("=\"") + control->GetPszValue() + wxT("\"");
922 case CONFIG_ITEM_INTEGER:
924 wxString::Format( wxT("=%i"), control->GetIntValue() );
926 case CONFIG_ITEM_FLOAT:
928 wxString::Format(wxT("=%f"), control->GetFloatValue());
933 if( input_panel->p_advanced_mrl_combo &&
934 input_panel->p_advanced_mrl_combo->GetValue() )
936 mrltemp += wxT(" ") +
937 input_panel->p_advanced_mrl_combo->GetValue();
943 mrl_combo->SetValue( mrltemp );
946 /*****************************************************************************
948 *****************************************************************************/
949 void OpenDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
951 mrl = SeparateEntries( mrl_combo->GetValue() );
952 mrl_combo->Append( mrl_combo->GetValue() );
953 if( mrl_combo->GetCount() > 10 ) mrl_combo->Delete( 0 );
954 mrl_combo->SetSelection( mrl_combo->GetCount() - 1 );
956 if( i_method == OPEN_STREAM )
962 /* Update the playlist */
963 playlist_t *p_playlist =
964 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
966 if( p_playlist == NULL ) return;
968 for( int i = 0; i < (int)mrl.GetCount(); i++ )
970 vlc_bool_t b_start = !i && i_open_arg;
971 playlist_item_t *p_item =
972 playlist_ItemNew( p_intf, (const char*)mrl[i].mb_str(),
973 (const char *)mrl[i].mb_str() );
976 while( i + 1 < (int)mrl.GetCount() &&
977 ((const char *)mrl[i + 1].mb_str())[0] == ':' )
979 playlist_ItemAddOption( p_item, mrl[i + 1].mb_str() );
983 /* Get the options from the subtitles dialog */
984 if( subsfile_checkbox->IsChecked() && subsfile_mrl.GetCount() )
986 for( int j = 0; j < (int)subsfile_mrl.GetCount(); j++ )
988 playlist_ItemAddOption( p_item, subsfile_mrl[j].mb_str() );
992 /* Get the options from the stream output dialog */
993 if( sout_checkbox->IsChecked() && sout_mrl.GetCount() )
995 for( int j = 0; j < (int)sout_mrl.GetCount(); j++ )
997 playlist_ItemAddOption( p_item, sout_mrl[j].mb_str() );
1001 int i_id = playlist_AddItem( p_playlist, p_item,
1002 PLAYLIST_APPEND, PLAYLIST_END );
1006 int i_pos = playlist_GetPositionById( p_playlist , i_id );
1007 playlist_Command( p_playlist, PLAYLIST_GOTO, i_pos );
1011 vlc_object_release( p_playlist );
1016 void OpenDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
1021 void OpenDialog::OnPageChange( wxNotebookEvent& event )
1023 UpdateMRL( event.GetSelection() );
1026 void OpenDialog::OnMRLChange( wxCommandEvent& event )
1028 //mrl = SeparateEntries( event.GetString() );
1031 /*****************************************************************************
1032 * File panel event methods.
1033 *****************************************************************************/
1034 void OpenDialog::OnFilePanelChange( wxCommandEvent& WXUNUSED(event) )
1036 UpdateMRL( FILE_ACCESS );
1039 void OpenDialog::OnFileBrowse( wxCommandEvent& WXUNUSED(event) )
1041 if( file_dialog == NULL )
1042 file_dialog = new wxFileDialog( this, wxU(_("Open File")),
1043 wxT(""), wxT(""), wxT("*"), wxOPEN | wxMULTIPLE );
1045 if( file_dialog && file_dialog->ShowModal() == wxID_OK )
1047 wxArrayString paths;
1050 file_dialog->GetPaths( paths );
1052 for( size_t i = 0; i < paths.GetCount(); i++ )
1054 if( paths[i].Find( wxT(' ') ) >= 0 )
1055 path += wxT("\"") + paths[i] + wxT("\" ");
1057 path += paths[i] + wxT(" ");
1060 file_combo->SetValue( path );
1061 file_combo->Append( path );
1062 if( file_combo->GetCount() > 10 ) file_combo->Delete( 0 );
1063 UpdateMRL( FILE_ACCESS );
1067 /*****************************************************************************
1068 * Disc panel event methods.
1069 *****************************************************************************/
1070 void OpenDialog::OnDiscPanelChange( wxCommandEvent& event )
1072 UpdateMRL( DISC_ACCESS );
1075 void OpenDialog::OnDiscDeviceChange( wxCommandEvent& event )
1079 switch( disc_type->GetSelection() )
1082 psz_device = config_GetPsz( p_intf, "cd-audio" );
1086 psz_device = config_GetPsz( p_intf, "vcd" );
1090 psz_device = config_GetPsz( p_intf, "dvd" );
1094 if ( !psz_device ) psz_device = "";
1096 if( disc_device->GetValue().Cmp( wxL2U( psz_device ) ) )
1098 b_disc_device_changed = true;
1101 UpdateMRL( DISC_ACCESS );
1104 void OpenDialog::OnDiscTypeChange( wxCommandEvent& WXUNUSED(event) )
1106 char *psz_device = NULL;
1107 int i_selection = 1; /* Default Title/Track selection number*/
1109 switch( disc_type->GetSelection() )
1112 case 0: /* DVD with menues */
1114 /* Fall through... */
1116 case 1: /* DVD of some sort */
1117 psz_device = config_GetPsz( p_intf, "dvd" );
1118 if( !b_disc_device_changed )
1121 disc_device->SetValue( wxL2U(psz_device) );
1123 disc_device->SetValue( wxT("") );
1125 disc_title_label->SetLabel ( wxU(_("Title")) );
1127 disc_title->SetRange( i_selection, 255 );
1128 disc_title->SetValue( i_selection );
1130 disc_chapter->SetRange( 1, 255 );
1131 disc_chapter->SetValue( 1 );
1132 disc_chapter_label->SetLabel ( wxU(_("Chapter")) );
1136 case 2: /* VCD of some sort */
1137 psz_device = config_GetPsz( p_intf, "vcd" );
1138 if( !b_disc_device_changed )
1141 disc_device->SetValue( wxL2U(psz_device) );
1143 disc_device->SetValue( wxT("") );
1146 /* There are at most 98, tracks in a VCD, 999 Segments, 500 entries
1147 I don't know what the limit is for LIDs, 999 is probably safe
1150 FIXME: it would be better however to get the information for
1151 this particular Media possibly from the General Info area.
1154 disc_title_label->SetLabel ( config_GetInt( p_intf, "vcdx-PBC" )
1155 ? wxT("Playback LID") : wxT("Entry") );
1156 disc_title->SetRange( 0, 999 );
1159 disc_title_label->SetLabel ( wxU(_("Track")) );
1160 disc_title->SetRange( 1, 98 );
1162 disc_title->SetValue( i_selection );
1164 /* We use the chapter to set subtitle number */
1165 disc_chapter_label->SetLabel ( wxU(_("Subtitle")) );
1166 disc_chapter->SetRange( -1, 4 );
1167 disc_chapter->SetValue( config_GetInt( p_intf, "spu-channel" ) );
1171 psz_device = config_GetPsz( p_intf, "cd-audio" );
1172 if( !b_disc_device_changed )
1175 disc_device->SetValue( wxL2U(psz_device) );
1177 disc_device->SetValue( wxT("") );
1179 disc_title_label->SetLabel ( wxU(_("Track")) );
1183 /* There are at most 99 tracks in a CD-DA */
1184 disc_title->SetRange( i_selection, 99 );
1185 disc_title->SetValue( i_selection );
1188 msg_Err( p_intf, "invalid Disc type selection (%d)",
1189 disc_type->GetSelection() );
1193 if( psz_device ) free( psz_device );
1195 UpdateMRL( DISC_ACCESS );
1198 /*****************************************************************************
1199 * Net panel event methods.
1200 *****************************************************************************/
1201 void OpenDialog::OnNetPanelChange( wxCommandEvent& event )
1203 if( event.GetId() >= NetPort1_Event && event.GetId() <= NetPort3_Event )
1205 i_net_ports[event.GetId() - NetPort1_Event] = event.GetInt();
1208 UpdateMRL( NET_ACCESS );
1211 void OpenDialog::OnNetTypeChange( wxCommandEvent& event )
1215 i_net_type = event.GetId() - NetRadio1_Event;
1219 net_radios[i]->SetValue( event.GetId() == (NetRadio1_Event+i) );
1220 net_subpanels[i]->Enable( event.GetId() == (NetRadio1_Event+i) );
1223 UpdateMRL( NET_ACCESS );
1226 /*****************************************************************************
1227 * Subtitles file event methods.
1228 *****************************************************************************/
1229 void OpenDialog::OnSubsFileEnable( wxCommandEvent& event )
1231 subsfile_button->Enable( event.GetInt() != 0 );
1234 void OpenDialog::OnSubsFileSettings( wxCommandEvent& WXUNUSED(event) )
1236 /* Show/hide the open dialog */
1237 if( subsfile_dialog == NULL )
1238 subsfile_dialog = new SubsFileDialog( p_intf, this );
1240 if( subsfile_dialog && subsfile_dialog->ShowModal() == wxID_OK )
1242 subsfile_mrl.Empty();
1243 subsfile_mrl.Add( wxString(wxT("sub-file=")) +
1244 subsfile_dialog->file_combo->GetValue() );
1245 if( subsfile_dialog->encoding_combo )
1246 subsfile_mrl.Add( wxString(wxT("subsdec-encoding=")) +
1247 subsfile_dialog->encoding_combo->GetValue() );
1248 subsfile_mrl.Add( wxString::Format( wxT("sub-delay=%i"),
1249 subsfile_dialog->delay_spinctrl->GetValue() ) );
1250 subsfile_mrl.Add( wxString::Format( wxT("sub-fps=%i"),
1251 subsfile_dialog->fps_spinctrl->GetValue() ) );
1255 /*****************************************************************************
1256 * Stream output event methods.
1257 *****************************************************************************/
1258 void OpenDialog::OnSoutEnable( wxCommandEvent& event )
1260 sout_button->Enable( event.GetInt() != 0 );
1263 void OpenDialog::OnSoutSettings( wxCommandEvent& WXUNUSED(event) )
1265 /* Show/hide the open dialog */
1266 if( sout_dialog == NULL )
1267 sout_dialog = new SoutDialog( p_intf, this );
1269 if( sout_dialog && sout_dialog->ShowModal() == wxID_OK )
1271 sout_mrl = sout_dialog->GetOptions();
1275 /*****************************************************************************
1276 * Utility functions.
1277 *****************************************************************************/
1278 wxArrayString SeparateEntries( wxString entries )
1280 vlc_bool_t b_quotes_mode = VLC_FALSE;
1282 wxArrayString entries_array;
1285 wxStringTokenizer token( entries, wxT(" \t\r\n\""), wxTOKEN_RET_DELIMS );
1287 while( token.HasMoreTokens() )
1289 entry += token.GetNextToken();
1291 if( entry.IsEmpty() ) continue;
1293 if( !b_quotes_mode && entry.Last() == wxT('\"') )
1295 /* Enters quotes mode */
1297 b_quotes_mode = VLC_TRUE;
1299 else if( b_quotes_mode && entry.Last() == wxT('\"') )
1301 /* Finished the quotes mode */
1303 if( !entry.IsEmpty() ) entries_array.Add( entry );
1305 b_quotes_mode = VLC_FALSE;
1307 else if( !b_quotes_mode && entry.Last() != wxT('\"') )
1309 /* we found a non-quoted standalone string */
1310 if( token.HasMoreTokens() ||
1311 entry.Last() == wxT(' ') || entry.Last() == wxT('\t') ||
1312 entry.Last() == wxT('\r') || entry.Last() == wxT('\n') )
1314 if( !entry.IsEmpty() ) entries_array.Add( entry );
1321 if( !entry.IsEmpty() ) entries_array.Add( entry );
1323 return entries_array;