1 /*****************************************************************************
2 * open.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: open.cpp,v 1.49 2003/12/10 21:54:16 courmisch Exp $
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
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 #ifdef WIN32 /* mingw32 hack */
39 /* Let vlc take care of the i18n stuff */
40 #define WXINTL_NO_GETTEXT_MACRO
42 #include <wx/wxprec.h>
44 #include <wx/notebook.h>
45 #include <wx/textctrl.h>
46 #include <wx/combobox.h>
47 #include <wx/spinctrl.h>
48 #include <wx/statline.h>
49 #include <wx/tokenzr.h>
53 #include "wxwindows.h"
55 #include "preferences_widgets.h"
58 # define wxRB_SINGLE 0
61 /*****************************************************************************
63 *****************************************************************************/
65 /* IDs for the controls and the menu commands */
68 Notebook_Event = wxID_HIGHEST,
80 NetRadio1_Event, NetRadio2_Event, NetRadio3_Event,
81 NetPort1_Event, NetPort2_Event, NetPort3_Event,
82 NetAddr1_Event, NetAddr2_Event, NetAddr3_Event,
93 SubsFileSettings_Event,
99 BEGIN_EVENT_TABLE(OpenDialog, wxFrame)
101 EVT_BUTTON(wxID_OK, OpenDialog::OnOk)
102 EVT_BUTTON(wxID_CANCEL, OpenDialog::OnCancel)
104 EVT_NOTEBOOK_PAGE_CHANGED(Notebook_Event, OpenDialog::OnPageChange)
106 EVT_TEXT(MRL_Event, OpenDialog::OnMRLChange)
108 /* Events generated by the file panel */
109 EVT_TEXT(FileName_Event, OpenDialog::OnFilePanelChange)
110 EVT_BUTTON(FileBrowse_Event, OpenDialog::OnFileBrowse)
112 /* Events generated by the disc panel */
113 EVT_RADIOBOX(DiscType_Event, OpenDialog::OnDiscTypeChange)
114 EVT_TEXT(DiscDevice_Event, OpenDialog::OnDiscDeviceChange)
115 EVT_TEXT(DiscDevice_Event, OpenDialog::OnDiscPanelChange)
116 EVT_TEXT(DiscTitle_Event, OpenDialog::OnDiscPanelChange)
117 EVT_SPINCTRL(DiscTitle_Event, OpenDialog::OnDiscPanelChange)
118 EVT_TEXT(DiscChapter_Event, OpenDialog::OnDiscPanelChange)
119 EVT_SPINCTRL(DiscChapter_Event, OpenDialog::OnDiscPanelChange)
121 /* Events generated by the net panel */
122 EVT_RADIOBUTTON(NetRadio1_Event, OpenDialog::OnNetTypeChange)
123 EVT_RADIOBUTTON(NetRadio2_Event, OpenDialog::OnNetTypeChange)
124 EVT_RADIOBUTTON(NetRadio3_Event, OpenDialog::OnNetTypeChange)
125 EVT_TEXT(NetPort1_Event, OpenDialog::OnNetPanelChange)
126 EVT_SPINCTRL(NetPort1_Event, OpenDialog::OnNetPanelChange)
127 EVT_TEXT(NetPort2_Event, OpenDialog::OnNetPanelChange)
128 EVT_SPINCTRL(NetPort2_Event, OpenDialog::OnNetPanelChange)
129 EVT_TEXT(NetPort3_Event, OpenDialog::OnNetPanelChange)
130 EVT_SPINCTRL(NetPort3_Event, OpenDialog::OnNetPanelChange)
131 EVT_TEXT(NetAddr2_Event, OpenDialog::OnNetPanelChange)
132 EVT_TEXT(NetAddr3_Event, OpenDialog::OnNetPanelChange)
133 EVT_CHECKBOX(NetForceIPv6_Event, OpenDialog::OnNetPanelChange)
136 /* Events generated by the v4l panel */
137 EVT_RADIOBOX(VideoType_Event, OpenDialog::OnV4LTypeChange)
138 EVT_TEXT(VideoDevice_Event, OpenDialog::OnV4LPanelChange)
139 EVT_SPINCTRL(VideoChannel_Event, OpenDialog::OnV4LPanelChange)
140 EVT_BUTTON(V4LSettings_Event, OpenDialog::OnV4LSettingsChange)
143 /* Events generated by the subtitle file buttons */
144 EVT_CHECKBOX(SubsFileEnable_Event, OpenDialog::OnSubsFileEnable)
145 EVT_BUTTON(SubsFileSettings_Event, OpenDialog::OnSubsFileSettings)
147 /* Events generated by the stream output buttons */
148 EVT_CHECKBOX(SoutEnable_Event, OpenDialog::OnSoutEnable)
149 EVT_BUTTON(SoutSettings_Event, OpenDialog::OnSoutSettings)
151 /* Hide the window when the user closes the window */
152 EVT_CLOSE(OpenDialog::OnCancel)
156 /*****************************************************************************
158 *****************************************************************************/
159 WX_DEFINE_ARRAY(ConfigControl *, ArrayOfConfigControls);
161 class AutoBuiltPanel : public wxPanel
166 AutoBuiltPanel( wxWindow *, OpenDialog *, intf_thread_t *,
169 virtual ~AutoBuiltPanel() {}
172 ArrayOfConfigControls config_array;
175 intf_thread_t *p_intf;
178 void AutoBuildCallback( void *p_data )
180 ((OpenDialog *)p_data)->UpdateMRL();
183 AutoBuiltPanel::AutoBuiltPanel( wxWindow *parent, OpenDialog *dialog,
184 intf_thread_t *_p_intf,
185 const module_t *p_module )
186 : wxPanel( parent, -1, wxDefaultPosition, wxSize(200, 200) ),
187 name( wxU(p_module->psz_object_name) ), p_intf( _p_intf )
189 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
191 module_config_t *p_item = p_module->p_config;
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++ );
212 this->SetSizerAndFit( sizer );
215 /*****************************************************************************
217 *****************************************************************************/
218 OpenDialog::OpenDialog( intf_thread_t *_p_intf, wxWindow *_p_parent,
219 int i_access_method, int i_arg ):
220 wxFrame( _p_parent, -1, wxU(_("Open Target")), wxDefaultPosition,
221 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
223 OpenDialog( _p_intf, _p_parent, i_access_method, i_arg, OPEN_NORMAL );
226 OpenDialog::OpenDialog( intf_thread_t *_p_intf, wxWindow *_p_parent,
227 int i_access_method, int i_arg, int _i_method ):
228 wxFrame( _p_parent, -1, wxU(_("Open Target")), wxDefaultPosition,
229 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
231 /* Initializations */
232 i_method = _i_method;
234 p_parent = _p_parent;
235 SetIcon( *p_intf->p_sys->p_icon );
241 subsfile_dialog = NULL;
242 b_disc_device_changed = false;
244 /* Create a panel to put everything in */
245 wxPanel *panel = new wxPanel( this, -1 );
246 panel->SetAutoLayout( TRUE );
248 /* Create MRL combobox */
249 wxBoxSizer *mrl_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
250 wxStaticBox *mrl_box = new wxStaticBox( panel, -1,
251 wxU(_("Media Resource Locator (MRL)")) );
252 wxStaticBoxSizer *mrl_sizer = new wxStaticBoxSizer( mrl_box,
254 wxStaticText *mrl_label = new wxStaticText( panel, -1,
255 wxU(_("Open Target:")) );
256 mrl_combo = new wxComboBox( panel, MRL_Event, wxT(""),
257 wxPoint(20,25), wxSize(120, -1),
259 mrl_combo->SetToolTip( wxU(_("You can use this field directly by typing "
260 "the full MRL you want to open.\n""Alternatively, the field will be "
261 "filled automatically when you use the controls below.")) );
263 mrl_sizer->Add( mrl_label, 0, wxALL | wxALIGN_CENTER, 5 );
264 mrl_sizer->Add( mrl_combo, 1, wxALL | wxALIGN_CENTER, 5 );
265 mrl_sizer_sizer->Add( mrl_sizer, 1, wxEXPAND | wxALL, 5 );
268 /* Create Static Text */
269 wxStaticText *label = new wxStaticText( panel, -1,
270 wxU(_("Alternatively, you can build an MRL using one of the "
271 "following predefined targets:")) );
273 wxFlexGridSizer *sout_sizer = NULL;
274 wxStaticLine *static_line = NULL;
276 if( i_method == OPEN_NORMAL )
278 /* Create Stream Output checkox */
279 sout_sizer = new wxFlexGridSizer( 2, 1, 20 );
282 sout_checkbox = new wxCheckBox( panel, SoutEnable_Event,
283 wxU(_("Stream output")) );
284 sout_checkbox->SetToolTip( wxU(_("Use VLC as a stream server")) );
285 sout_sizer->Add( sout_checkbox, 0,
286 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
287 sout_button = new wxButton( panel, SoutSettings_Event,
288 wxU(_("Settings...")) );
289 sout_button->Disable();
291 char *psz_sout = config_GetPsz( p_intf, "sout" );
292 if( psz_sout && *psz_sout )
294 sout_checkbox->SetValue(TRUE);
295 sout_button->Enable();
296 subsfile_mrl.Add( wxString(wxT("sout=")) + wxU(psz_sout) );
298 if( psz_sout ) free( psz_sout );
300 sout_sizer->Add( sout_button, 1, wxALIGN_LEFT |
301 wxALIGN_CENTER_VERTICAL );
304 static_line = new wxStaticLine( panel, wxID_OK );
307 /* Create the buttons */
308 wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
309 ok_button->SetDefault();
310 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
313 /* Create notebook */
314 notebook = new wxNotebook( panel, Notebook_Event );
315 wxNotebookSizer *notebook_sizer = new wxNotebookSizer( notebook );
317 notebook->AddPage( FilePanel( notebook ), wxU(_("File")),
318 i_access_method == FILE_ACCESS );
319 notebook->AddPage( DiscPanel( notebook ), wxU(_("Disc")),
320 i_access_method == DISC_ACCESS );
321 notebook->AddPage( NetPanel( notebook ), wxU(_("Network")),
322 i_access_method == NET_ACCESS );
324 notebook->AddPage( V4LPanel( notebook ), wxU(_("Video For Linux")),
325 i_access_method == V4L_ACCESS );
328 module_t *p_module = config_FindModule( VLC_OBJECT(p_intf), "dshow" );
331 AutoBuiltPanel *autopanel =
332 new AutoBuiltPanel( notebook, this, p_intf, p_module );
333 input_tab_array.Add( autopanel );
334 notebook->AddPage( autopanel, wxU( p_module->psz_longname ) );
337 /* Update Disc panel */
338 wxCommandEvent dummy_event;
339 OnDiscTypeChange( dummy_event );
341 /* Update Net panel */
342 dummy_event.SetId( NetRadio1_Event );
343 OnNetTypeChange( dummy_event );
346 /* Update v4l panel */
347 dummy_event.SetId( VideoType_Event );
348 OnV4LTypeChange( dummy_event );
352 wxNotebookEvent event( wxEVT_NULL, 0, i_access_method );
353 OnPageChange( event );
355 /* Place everything in sizers */
356 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
357 button_sizer->Add( ok_button, 0, wxALL, 5 );
358 button_sizer->Add( cancel_button, 0, wxALL, 5 );
359 button_sizer->Layout();
360 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
361 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
362 panel_sizer->Add( mrl_sizer_sizer, 0, wxEXPAND, 5 );
363 panel_sizer->Add( label, 0, wxEXPAND | wxALL, 5 );
364 panel_sizer->Add( notebook_sizer, 1, wxEXPAND | wxALL, 5 );
365 if( i_method == OPEN_NORMAL)
367 panel_sizer->Add( sout_sizer, 0, wxALIGN_LEFT | wxALL, 5 );
368 panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
370 panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALL, 5 );
371 panel_sizer->Layout();
372 panel->SetSizerAndFit( panel_sizer );
373 main_sizer->Add( panel, 1, wxGROW, 0 );
374 main_sizer->Layout();
375 SetSizerAndFit( main_sizer );
378 OpenDialog::~OpenDialog()
381 if( file_dialog ) delete file_dialog;
383 if( v4l_dialog ) delete v4l_dialog;
385 if( sout_dialog ) delete sout_dialog;
386 if( subsfile_dialog ) delete subsfile_dialog;
389 int OpenDialog::Show( int i_access_method, int i_arg )
392 notebook->SetSelection( i_access_method );
393 i_ret = wxFrame::Show();
399 int OpenDialog::Show()
402 i_ret = wxFrame::Show();
408 /*****************************************************************************
410 *****************************************************************************/
411 wxPanel *OpenDialog::FilePanel( wxWindow* parent )
413 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
416 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
418 /* Create browse file line */
419 wxBoxSizer *file_sizer = new wxBoxSizer( wxHORIZONTAL );
421 file_combo = new wxComboBox( panel, FileName_Event, wxT(""),
422 wxPoint(20,25), wxSize(200, -1), 0, NULL );
423 wxButton *browse_button = new wxButton( panel, FileBrowse_Event,
424 wxU(_("Browse...")) );
425 file_sizer->Add( file_combo, 1, wxALL, 5 );
426 file_sizer->Add( browse_button, 0, wxALL, 5 );
428 /* Create Subtitles File checkox */
429 wxFlexGridSizer *subsfile_sizer = new wxFlexGridSizer( 2, 1, 20 );
430 subsfile_checkbox = new wxCheckBox( panel, SubsFileEnable_Event,
431 wxU(_("Subtitles file")) );
432 subsfile_checkbox->SetToolTip( wxU(_("Load an additional subtitles file. "
433 "Currently only works with AVI files.")) );
434 subsfile_sizer->Add( subsfile_checkbox, 0,
435 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
436 subsfile_button = new wxButton( panel, SubsFileSettings_Event,
437 wxU(_("Settings...")) );
438 subsfile_button->Disable();
440 char *psz_subsfile = config_GetPsz( p_intf, "sub-file" );
441 if( psz_subsfile && *psz_subsfile )
443 subsfile_checkbox->SetValue(TRUE);
444 subsfile_button->Enable();
445 subsfile_mrl.Add( wxString(wxT("sub-file=")) + wxU(psz_subsfile) );
447 if( psz_subsfile ) free( psz_subsfile );
449 subsfile_sizer->Add( subsfile_button, 1,
450 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
452 sizer->Add( file_sizer, 0, wxEXPAND | wxALL, 5 );
453 sizer->Add( subsfile_sizer, 0, wxEXPAND | wxALL, 5 );
454 panel->SetSizerAndFit( sizer );
458 wxPanel *OpenDialog::DiscPanel( wxWindow* parent )
460 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
463 wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
464 wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 3, 20 );
466 static const wxString disc_type_array[] =
468 wxU(_("DVD (menus support)")),
475 disc_type = new wxRadioBox( panel, DiscType_Event, wxU(_("Disc type")),
476 wxDefaultPosition, wxDefaultSize,
477 WXSIZEOF(disc_type_array), disc_type_array,
478 WXSIZEOF(disc_type_array), wxRA_SPECIFY_COLS );
479 sizer_row->Add( disc_type, 0, wxEXPAND | wxALL, 5 );
481 wxStaticText *label = new wxStaticText( panel, -1, wxU(_("Device name")) );
482 disc_device = new wxTextCtrl( panel, DiscDevice_Event, wxT(""),
483 wxDefaultPosition, wxDefaultSize,
486 sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
487 sizer->Add( disc_device, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
489 label = new wxStaticText( panel, -1, wxU(_("Title")) );
490 disc_title = new wxSpinCtrl( panel, DiscTitle_Event );
492 sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
493 sizer->Add( disc_title, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
495 label = new wxStaticText( panel, -1, wxU(_("Chapter")) );
496 disc_chapter = new wxSpinCtrl( panel, DiscChapter_Event );
497 sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
498 sizer->Add( disc_chapter, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
499 sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
501 panel->SetSizerAndFit( sizer_row );
505 wxPanel *OpenDialog::NetPanel( wxWindow* parent )
508 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
511 wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
512 wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 3, 20 );
514 static const wxString net_type_array[] =
517 wxU(_("UDP/RTP Multicast")),
518 wxU(_("HTTP/FTP/MMS"))
523 net_radios[i] = new wxRadioButton( panel, NetRadio1_Event + i,
525 wxDefaultPosition, wxDefaultSize,
528 net_subpanels[i] = new wxPanel( panel, -1,
529 wxDefaultPosition, wxDefaultSize );
533 wxFlexGridSizer *subpanel_sizer;
535 i_net_ports[0] = config_GetInt( p_intf, "server-port" );
536 subpanel_sizer = new wxFlexGridSizer( 3, 1, 20 );
537 label = new wxStaticText( net_subpanels[0], -1, wxU(_("Port")) );
538 net_ports[0] = new wxSpinCtrl( net_subpanels[0], NetPort1_Event,
539 wxString::Format(wxT("%d"), i_net_ports[0]),
540 wxDefaultPosition, wxDefaultSize,
542 0, 16000, i_net_ports[0] );
544 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
545 subpanel_sizer->Add( net_ports[0], 1,
546 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
547 net_ipv6 = new wxCheckBox( net_subpanels[0], NetForceIPv6_Event,
548 wxU(_("Force IPv6")));
549 subpanel_sizer->Add( net_ipv6, 0,
550 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
551 net_subpanels[0]->SetSizerAndFit( subpanel_sizer );
552 net_radios[0]->SetValue( TRUE );
554 /* UDP/RTP Multicast row */
555 subpanel_sizer = new wxFlexGridSizer( 4, 1, 20 );
556 label = new wxStaticText( net_subpanels[1], -1, wxU(_("Address")) );
557 net_addrs[1] = new wxTextCtrl( net_subpanels[1], NetAddr2_Event, wxT(""),
558 wxDefaultPosition, wxDefaultSize,
560 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
561 subpanel_sizer->Add( net_addrs[1], 1,
562 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
564 label = new wxStaticText( net_subpanels[1], -1, wxU(_("Port")) );
565 i_net_ports[1] = i_net_ports[0];
566 net_ports[1] = new wxSpinCtrl( net_subpanels[1], NetPort2_Event,
567 wxString::Format(wxT("%d"), i_net_ports[1]),
568 wxDefaultPosition, wxDefaultSize,
570 0, 16000, i_net_ports[1] );
572 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
573 subpanel_sizer->Add( net_ports[1], 1,
574 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
575 net_subpanels[1]->SetSizerAndFit( subpanel_sizer );
578 subpanel_sizer = new wxFlexGridSizer( 2, 1, 20 );
579 label = new wxStaticText( net_subpanels[2], -1, wxU(_("URL")) );
580 net_addrs[2] = new wxTextCtrl( net_subpanels[2], NetAddr3_Event, wxT(""),
581 wxDefaultPosition, wxSize( 200, -1 ),
583 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
584 subpanel_sizer->Add( net_addrs[2], 1,
585 wxEXPAND | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
586 net_subpanels[2]->SetSizerAndFit( subpanel_sizer );
588 /* Stuff everything into the main panel */
591 sizer->Add( net_radios[i], 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
593 sizer->Add( net_subpanels[i], 1, wxEXPAND | wxALIGN_LEFT |
594 wxALIGN_CENTER_VERTICAL | wxALL, 5 );
597 sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
599 panel->SetSizerAndFit( sizer_row );
604 wxPanel *OpenDialog::V4LPanel( wxWindow* parent )
606 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
609 wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
610 wxFlexGridSizer *sizer = new wxFlexGridSizer( 1, 4, 20 );
612 static const wxString video_type_array[] =
620 video_type = new wxRadioBox( panel, VideoType_Event,
621 wxU(_("Video Device Type")),
622 wxDefaultPosition, wxDefaultSize,
623 WXSIZEOF(video_type_array), video_type_array,
624 WXSIZEOF(video_type_array), wxRA_SPECIFY_COLS );
626 sizer_row->Add( video_type, 0, wxEXPAND | wxALL, 5 );
630 wxFlexGridSizer *video_sizer = new wxFlexGridSizer( 4, 2, 20 );
631 wxStaticText *label = new wxStaticText( panel, -1, wxU(_("Video Device")) );
632 video_device = new wxTextCtrl( panel, VideoDevice_Event, wxT(""),
633 wxDefaultPosition, wxDefaultSize,
635 video_device->SetToolTip( wxU(_("Device corresponding to your acquisition "
636 "card or your webcam")) );
637 video_sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
638 video_sizer->Add( video_device, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
640 label = new wxStaticText( panel, -1, wxU(_("Channel")) );
641 video_channel = new wxSpinCtrl( panel, VideoChannel_Event, wxT("0") );
642 video_channel->SetToolTip( wxU(_("Usually 0 is for tuner, 1 for composite "
643 "and 2 for svideo")) );
644 video_sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_HORIZONTAL );
645 video_sizer->Add( video_channel, 1, wxALIGN_LEFT | wxALIGN_CENTER_HORIZONTAL );
646 sizer->Add( video_sizer, 0, wxEXPAND | wxALL, 5 );
648 wxBoxSizer *v4lbutton_sizer = new wxBoxSizer( wxHORIZONTAL );
649 v4l_button = new wxButton( panel, V4LSettings_Event,
650 wxU(_("Advanced Settings...")) );
652 v4lbutton_sizer->Add( v4l_button, 0, wxALIGN_RIGHT, 5 );
654 sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
655 sizer_row->Add( v4lbutton_sizer, 0, wxEXPAND | wxALL, 5 );
657 panel->SetSizerAndFit( sizer_row );
662 void OpenDialog::UpdateMRL()
664 UpdateMRL( i_current_access_method );
667 void OpenDialog::UpdateMRL( int i_access_method )
669 wxString demux, mrltemp;
671 i_current_access_method = i_access_method;
673 switch( i_access_method )
676 //mrltemp = wxT("file") + demux + wxT(":") + file_combo->GetValue();
677 mrltemp = file_combo->GetValue();
680 mrltemp = ( disc_type->GetSelection() == 0 ? wxT("dvd") :
681 disc_type->GetSelection() == 1 ? wxT("dvdsimple") :
682 disc_type->GetSelection() == 2 ? wxT("vcd") : wxT("cdda") )
684 // + disc_device->GetLineText(0)
685 + disc_device->GetValue()
686 + wxString::Format( wxT("@%d:%d"),
687 disc_title->GetValue(),
688 disc_chapter->GetValue() );
694 mrltemp = wxT("udp") + demux + wxT("://");
695 if ( net_ipv6->GetValue() )
697 mrltemp += wxT("@[::]");
699 if( i_net_ports[0] !=
700 config_GetInt( p_intf, "server-port" ) )
702 mrltemp += wxString::Format( wxT("@:%d"), i_net_ports[0] );
707 mrltemp = wxT("udp") + demux + wxT("://@");
708 if ((net_addrs[1]->GetLineText(0).Find (':') != -1)
709 && (net_addrs[1]->GetLineText(0)[0u] != '['))
711 /* automatically adds '[' and ']' to IPv6 addresses */
712 mrltemp += wxT("[") + net_addrs[1]->GetLineText(0)
717 mrltemp += net_addrs[1]->GetLineText(0);
719 if( i_net_ports[1] != config_GetInt( p_intf, "server-port" ) )
721 mrltemp += wxString::Format( wxT(":%d"), i_net_ports[1] );
727 mrltemp = wxT("http") + demux + wxT("://") +
728 net_addrs[2]->GetLineText(0);
735 mrltemp = ( video_type->GetSelection() == 0 ? wxT("v4l") :
736 video_type->GetSelection() == 1 ? wxT("v4l") :
737 video_type->GetSelection() == 2 ? wxT("pvr") :
740 + video_device->GetLineText( 0 );
742 if( video_type->GetSelection() == 1 )
744 mrltemp += wxString::Format( wxT(":channel=%d"),
745 video_channel->GetValue() );
748 if ( /* v4l_dialog != NULL && */ !v4l_mrl.IsEmpty() )
750 mrltemp += v4l_mrl[0];
758 int i_item = i_access_method - MAX_ACCESS;
760 if( i_item < 0 || i_item >= (int)input_tab_array.GetCount() )
763 AutoBuiltPanel *input_panel = input_tab_array.Item( i_item );
765 mrltemp = input_panel->name + wxT("://");
767 for( int i=0; i < (int)input_panel->config_array.GetCount(); i++ )
769 ConfigControl *control = input_panel->config_array.Item(i);
770 mrltemp += wxT(" :") + control->GetName() + wxT("=");
772 switch( control->GetType() )
774 case CONFIG_ITEM_STRING:
775 case CONFIG_ITEM_FILE:
776 case CONFIG_ITEM_DIRECTORY:
777 case CONFIG_ITEM_MODULE:
778 mrltemp += wxT("\"") + control->GetPszValue() + wxT("\"");
780 case CONFIG_ITEM_INTEGER:
781 case CONFIG_ITEM_BOOL:
783 wxString::Format( wxT("%i"), control->GetIntValue() );
785 case CONFIG_ITEM_FLOAT:
787 wxString::Format( wxT("%f"), control->GetFloatValue());
795 mrl_combo->SetValue( mrltemp );
798 /*****************************************************************************
800 *****************************************************************************/
801 void OpenDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
803 mrl = SeparateEntries( mrl_combo->GetValue() );
804 mrl_combo->Append( mrl_combo->GetValue() );
805 if( mrl_combo->GetCount() > 10 ) mrl_combo->Delete( 0 );
806 mrl_combo->SetSelection( mrl_combo->GetCount() - 1 );
808 if( i_method == OPEN_STREAM )
814 /* Update the playlist */
815 playlist_t *p_playlist =
816 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
818 if( p_playlist == NULL ) return;
820 for( int i = 0; i < (int)mrl.GetCount(); i++ )
822 int i_options = 0, i_total_options;
823 char **ppsz_options = NULL;
825 /* Count the input options */
826 while( i + i_options + 1 < (int)mrl.GetCount() &&
827 ((const char *)mrl[i + i_options + 1].mb_str())[0] == ':' )
832 /* Allocate ppsz_options */
833 for( int j = 0; j < i_options; j++ )
836 ppsz_options = (char **)malloc( sizeof(char *) * i_options );
838 ppsz_options[j] = strdup( mrl[i + j + 1].mb_str() );
841 i_total_options = i_options;
843 /* Get the options from the subtitles dialog */
844 if( subsfile_checkbox->IsChecked() && subsfile_mrl.GetCount() )
846 ppsz_options = (char **)realloc( ppsz_options, sizeof(char *) *
847 (i_total_options + subsfile_mrl.GetCount()) );
849 for( int j = 0; j < (int)subsfile_mrl.GetCount(); j++ )
851 ppsz_options[i_total_options + j] =
852 strdup( subsfile_mrl[j].mb_str() );
855 i_total_options += subsfile_mrl.GetCount();
858 /* Get the options from the stream output dialog */
859 if( sout_checkbox->IsChecked() && sout_mrl.GetCount() )
861 ppsz_options = (char **)realloc( ppsz_options, sizeof(char *) *
862 (i_total_options + sout_mrl.GetCount()) );
864 for( int j = 0; j < (int)sout_mrl.GetCount(); j++ )
866 ppsz_options[i_total_options + j] =
867 strdup( sout_mrl[j].mb_str() );
870 i_total_options += sout_mrl.GetCount();
874 playlist_Add( p_playlist, (const char *)mrl[i].mb_str(),
875 (const char **)ppsz_options, i_total_options,
876 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );
879 for( int j = 0; j < i_total_options; j++ )
880 free( ppsz_options[j] );
881 if( ppsz_options ) free( ppsz_options );
886 //TogglePlayButton( PLAYING_S );
888 vlc_object_release( p_playlist );
893 void OpenDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
898 void OpenDialog::OnPageChange( wxNotebookEvent& event )
900 UpdateMRL( event.GetSelection() );
903 void OpenDialog::OnMRLChange( wxCommandEvent& event )
905 //mrl = SeparateEntries( event.GetString() );
908 /*****************************************************************************
909 * File panel event methods.
910 *****************************************************************************/
911 void OpenDialog::OnFilePanelChange( wxCommandEvent& WXUNUSED(event) )
913 UpdateMRL( FILE_ACCESS );
916 void OpenDialog::OnFileBrowse( wxCommandEvent& WXUNUSED(event) )
918 if( file_dialog == NULL )
919 file_dialog = new wxFileDialog( this, wxU(_("Open file")),
920 wxT(""), wxT(""), wxT("*"), wxOPEN | wxMULTIPLE );
922 if( file_dialog && file_dialog->ShowModal() == wxID_OK )
927 file_dialog->GetPaths( paths );
929 for( size_t i = 0; i < paths.GetCount(); i++ )
931 if( paths[i].Find( wxT(' ') ) >= 0 )
932 path += wxT("\"") + paths[i] + wxT("\" ");
934 path += paths[i] + wxT(" ");
937 file_combo->SetValue( path );
938 file_combo->Append( path );
939 if( file_combo->GetCount() > 10 ) file_combo->Delete( 0 );
940 UpdateMRL( FILE_ACCESS );
944 /*****************************************************************************
945 * Disc panel event methods.
946 *****************************************************************************/
947 void OpenDialog::OnDiscPanelChange( wxCommandEvent& event )
949 UpdateMRL( DISC_ACCESS );
952 void OpenDialog::OnDiscDeviceChange( wxCommandEvent& event )
956 switch( disc_type->GetSelection() )
959 psz_device = config_GetPsz( p_intf, "cd-audio" );
963 psz_device = config_GetPsz( p_intf, "vcd" );
967 psz_device = config_GetPsz( p_intf, "dvd" );
971 if( disc_device->GetValue().Cmp( wxU( psz_device ) ) )
973 b_disc_device_changed = true;
976 UpdateMRL( DISC_ACCESS );
979 void OpenDialog::OnDiscTypeChange( wxCommandEvent& WXUNUSED(event) )
983 switch( disc_type->GetSelection() )
986 psz_device = config_GetPsz( p_intf, "cd-audio" );
987 if( !b_disc_device_changed )
989 disc_device->SetValue( psz_device ? wxU(psz_device) : wxT("") );
994 psz_device = config_GetPsz( p_intf, "vcd" );
995 if( !b_disc_device_changed )
997 disc_device->SetValue( psz_device ? wxU(psz_device) : wxT("") );
1002 psz_device = config_GetPsz( p_intf, "dvd" );
1003 if( !b_disc_device_changed )
1005 disc_device->SetValue( psz_device ? wxU(psz_device) : wxT("") );
1010 if( psz_device ) free( psz_device );
1012 switch( disc_type->GetSelection() )
1015 disc_title->SetRange( 0, 255 );
1016 disc_title->SetValue( 0 );
1020 disc_title->SetRange( 1, 255 );
1021 disc_title->SetValue( 1 );
1025 disc_chapter->SetRange( 1, 255 );
1026 disc_chapter->SetValue( 1 );
1028 UpdateMRL( DISC_ACCESS );
1031 /*****************************************************************************
1032 * Net panel event methods.
1033 *****************************************************************************/
1034 void OpenDialog::OnNetPanelChange( wxCommandEvent& event )
1036 if( event.GetId() >= NetPort1_Event && event.GetId() <= NetPort3_Event )
1038 i_net_ports[event.GetId() - NetPort1_Event] = event.GetInt();
1041 UpdateMRL( NET_ACCESS );
1044 void OpenDialog::OnNetTypeChange( wxCommandEvent& event )
1048 i_net_type = event.GetId() - NetRadio1_Event;
1052 net_radios[i]->SetValue( event.GetId() == (NetRadio1_Event+i) );
1053 net_subpanels[i]->Enable( event.GetId() == (NetRadio1_Event+i) );
1056 UpdateMRL( NET_ACCESS );
1060 /*****************************************************************************
1061 * v4l panel event methods.
1062 *****************************************************************************/
1063 void OpenDialog::OnV4LPanelChange( wxCommandEvent& WXUNUSED(event) )
1065 UpdateMRL( V4L_ACCESS );
1068 void OpenDialog::OnV4LTypeChange( wxCommandEvent& WXUNUSED(event) )
1070 video_device->SetValue( wxU( "/dev/video" ) );
1072 v4l_button->Enable();
1073 video_channel->Disable();
1075 switch( video_type->GetSelection() )
1078 video_channel->Enable();
1079 video_channel->SetRange( 0, 255 );
1082 v4l_button->Disable();
1088 UpdateMRL( V4L_ACCESS );
1091 void OpenDialog::OnV4LSettingsChange( wxCommandEvent& WXUNUSED(event) )
1093 /* Show/hide the open dialog */
1094 if( v4l_dialog == NULL )
1095 v4l_dialog = new V4LDialog( p_intf, this );
1097 if( v4l_dialog && v4l_dialog->ShowModal() == wxID_OK )
1099 v4l_mrl = v4l_dialog->GetOptions();
1102 UpdateMRL( V4L_ACCESS );
1106 /*****************************************************************************
1107 * Subtitles file event methods.
1108 *****************************************************************************/
1109 void OpenDialog::OnSubsFileEnable( wxCommandEvent& event )
1111 subsfile_button->Enable( event.GetInt() != 0 );
1114 void OpenDialog::OnSubsFileSettings( wxCommandEvent& WXUNUSED(event) )
1116 /* Show/hide the open dialog */
1117 if( subsfile_dialog == NULL )
1118 subsfile_dialog = new SubsFileDialog( p_intf, this );
1120 if( subsfile_dialog && subsfile_dialog->ShowModal() == wxID_OK )
1122 subsfile_mrl.Empty();
1123 subsfile_mrl.Add( wxString(wxT("sub-file=")) +
1124 subsfile_dialog->file_combo->GetValue() );
1125 if( subsfile_dialog->encoding_combo )
1126 subsfile_mrl.Add( wxString(wxT("subsdec-encoding=")) +
1127 subsfile_dialog->encoding_combo->GetValue() );
1128 subsfile_mrl.Add( wxString::Format( wxT("sub-delay=%i"),
1129 subsfile_dialog->delay_spinctrl->GetValue() ) );
1130 subsfile_mrl.Add( wxString::Format( wxT("sub-fps=%i"),
1131 subsfile_dialog->fps_spinctrl->GetValue() ) );
1135 /*****************************************************************************
1136 * Stream output event methods.
1137 *****************************************************************************/
1138 void OpenDialog::OnSoutEnable( wxCommandEvent& event )
1140 sout_button->Enable( event.GetInt() != 0 );
1143 void OpenDialog::OnSoutSettings( wxCommandEvent& WXUNUSED(event) )
1145 /* Show/hide the open dialog */
1146 if( sout_dialog == NULL )
1147 sout_dialog = new SoutDialog( p_intf, this );
1149 if( sout_dialog && sout_dialog->ShowModal() == wxID_OK )
1151 sout_mrl = sout_dialog->GetOptions();
1155 /*****************************************************************************
1156 * Utility functions.
1157 *****************************************************************************/
1158 wxArrayString SeparateEntries( wxString entries )
1160 vlc_bool_t b_quotes_mode = VLC_FALSE;
1162 wxArrayString entries_array;
1165 wxStringTokenizer token( entries, wxT(" \t\r\n\""), wxTOKEN_RET_DELIMS );
1167 while( token.HasMoreTokens() )
1169 entry += token.GetNextToken();
1171 if( entry.IsEmpty() ) continue;
1173 if( !b_quotes_mode && entry.Last() == wxT('\"') )
1175 /* Enters quotes mode */
1177 b_quotes_mode = VLC_TRUE;
1179 else if( b_quotes_mode && entry.Last() == wxT('\"') )
1181 /* Finished the quotes mode */
1183 if( !entry.IsEmpty() ) entries_array.Add( entry );
1185 b_quotes_mode = VLC_FALSE;
1187 else if( !b_quotes_mode && entry.Last() != wxT('\"') )
1189 /* we found a non-quoted standalone string */
1190 if( token.HasMoreTokens() ||
1191 entry.Last() == wxT(' ') || entry.Last() == wxT('\t') ||
1192 entry.Last() == wxT('\r') || entry.Last() == wxT('\n') )
1194 if( !entry.IsEmpty() ) entries_array.Add( entry );
1201 if( !entry.IsEmpty() ) entries_array.Add( entry );
1203 return entries_array;