1 /*****************************************************************************
2 * open.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: open.cpp,v 1.46 2003/12/09 00:46:03 yoann 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,
92 SubsFileSettings_Event,
98 BEGIN_EVENT_TABLE(OpenDialog, wxFrame)
100 EVT_BUTTON(wxID_OK, OpenDialog::OnOk)
101 EVT_BUTTON(wxID_CANCEL, OpenDialog::OnCancel)
103 EVT_NOTEBOOK_PAGE_CHANGED(Notebook_Event, OpenDialog::OnPageChange)
105 EVT_TEXT(MRL_Event, OpenDialog::OnMRLChange)
107 /* Events generated by the file panel */
108 EVT_TEXT(FileName_Event, OpenDialog::OnFilePanelChange)
109 EVT_BUTTON(FileBrowse_Event, OpenDialog::OnFileBrowse)
111 /* Events generated by the disc panel */
112 EVT_RADIOBOX(DiscType_Event, OpenDialog::OnDiscTypeChange)
113 EVT_TEXT(DiscDevice_Event, OpenDialog::OnDiscDeviceChange)
114 EVT_TEXT(DiscDevice_Event, OpenDialog::OnDiscPanelChange)
115 EVT_TEXT(DiscTitle_Event, OpenDialog::OnDiscPanelChange)
116 EVT_SPINCTRL(DiscTitle_Event, OpenDialog::OnDiscPanelChange)
117 EVT_TEXT(DiscChapter_Event, OpenDialog::OnDiscPanelChange)
118 EVT_SPINCTRL(DiscChapter_Event, OpenDialog::OnDiscPanelChange)
120 /* Events generated by the net panel */
121 EVT_RADIOBUTTON(NetRadio1_Event, OpenDialog::OnNetTypeChange)
122 EVT_RADIOBUTTON(NetRadio2_Event, OpenDialog::OnNetTypeChange)
123 EVT_RADIOBUTTON(NetRadio3_Event, OpenDialog::OnNetTypeChange)
124 EVT_TEXT(NetPort1_Event, OpenDialog::OnNetPanelChange)
125 EVT_SPINCTRL(NetPort1_Event, OpenDialog::OnNetPanelChange)
126 EVT_TEXT(NetPort2_Event, OpenDialog::OnNetPanelChange)
127 EVT_SPINCTRL(NetPort2_Event, OpenDialog::OnNetPanelChange)
128 EVT_TEXT(NetPort3_Event, OpenDialog::OnNetPanelChange)
129 EVT_SPINCTRL(NetPort3_Event, OpenDialog::OnNetPanelChange)
130 EVT_TEXT(NetAddr2_Event, OpenDialog::OnNetPanelChange)
131 EVT_TEXT(NetAddr3_Event, OpenDialog::OnNetPanelChange)
134 /* Events generated by the v4l panel */
135 EVT_RADIOBOX(VideoType_Event, OpenDialog::OnV4LTypeChange)
136 EVT_TEXT(VideoDevice_Event, OpenDialog::OnV4LPanelChange)
137 EVT_SPINCTRL(VideoChannel_Event, OpenDialog::OnV4LPanelChange)
138 EVT_BUTTON(V4LSettings_Event, OpenDialog::OnV4LSettingsChange)
141 /* Events generated by the subtitle file buttons */
142 EVT_CHECKBOX(SubsFileEnable_Event, OpenDialog::OnSubsFileEnable)
143 EVT_BUTTON(SubsFileSettings_Event, OpenDialog::OnSubsFileSettings)
145 /* Events generated by the stream output buttons */
146 EVT_CHECKBOX(SoutEnable_Event, OpenDialog::OnSoutEnable)
147 EVT_BUTTON(SoutSettings_Event, OpenDialog::OnSoutSettings)
149 /* Hide the window when the user closes the window */
150 EVT_CLOSE(OpenDialog::OnCancel)
154 /*****************************************************************************
156 *****************************************************************************/
157 WX_DEFINE_ARRAY(ConfigControl *, ArrayOfConfigControls);
159 class AutoBuiltPanel : public wxPanel
164 AutoBuiltPanel( wxWindow *, OpenDialog *, intf_thread_t *,
167 virtual ~AutoBuiltPanel() {}
170 ArrayOfConfigControls config_array;
173 intf_thread_t *p_intf;
176 void AutoBuildCallback( void *p_data )
178 ((OpenDialog *)p_data)->UpdateMRL();
181 AutoBuiltPanel::AutoBuiltPanel( wxWindow *parent, OpenDialog *dialog,
182 intf_thread_t *_p_intf,
183 const module_t *p_module )
184 : wxPanel( parent, -1, wxDefaultPosition, wxSize(200, 200) ),
185 name( wxU(p_module->psz_object_name) ), p_intf( _p_intf )
187 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
189 module_config_t *p_item = p_module->p_config;
193 if( p_item->i_type & CONFIG_HINT || p_item->b_advanced )
196 ConfigControl *control =
197 CreateConfigControl( VLC_OBJECT(p_intf), p_item, this );
199 config_array.Add( control );
201 /* Don't add items that were not recognized */
202 if( control == NULL ) continue;
204 control->SetUpdateCallback( AutoBuildCallback, (void *)dialog );
206 sizer->Add( control, 0, wxEXPAND | wxALL, 2 );
208 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
210 this->SetSizerAndFit( sizer );
213 /*****************************************************************************
215 *****************************************************************************/
216 OpenDialog::OpenDialog( intf_thread_t *_p_intf, wxWindow *_p_parent,
217 int i_access_method, int i_arg ):
218 wxFrame( _p_parent, -1, wxU(_("Open Target")), wxDefaultPosition,
219 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
221 OpenDialog( _p_intf, _p_parent, i_access_method, i_arg, OPEN_NORMAL );
224 OpenDialog::OpenDialog( intf_thread_t *_p_intf, wxWindow *_p_parent,
225 int i_access_method, int i_arg, int _i_method ):
226 wxFrame( _p_parent, -1, wxU(_("Open Target")), wxDefaultPosition,
227 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
229 /* Initializations */
230 i_method = _i_method;
232 p_parent = _p_parent;
233 SetIcon( *p_intf->p_sys->p_icon );
239 subsfile_dialog = NULL;
240 b_disc_device_changed = false;
242 /* Create a panel to put everything in */
243 wxPanel *panel = new wxPanel( this, -1 );
244 panel->SetAutoLayout( TRUE );
246 /* Create MRL combobox */
247 wxBoxSizer *mrl_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
248 wxStaticBox *mrl_box = new wxStaticBox( panel, -1,
249 wxU(_("Media Resource Locator (MRL)")) );
250 wxStaticBoxSizer *mrl_sizer = new wxStaticBoxSizer( mrl_box,
252 wxStaticText *mrl_label = new wxStaticText( panel, -1,
253 wxU(_("Open Target:")) );
254 mrl_combo = new wxComboBox( panel, MRL_Event, wxT(""),
255 wxPoint(20,25), wxSize(120, -1),
257 mrl_combo->SetToolTip( wxU(_("You can use this field directly by typing "
258 "the full MRL you want to open.\n""Alternatively, the field will be "
259 "filled automatically when you use the controls below.")) );
261 mrl_sizer->Add( mrl_label, 0, wxALL | wxALIGN_CENTER, 5 );
262 mrl_sizer->Add( mrl_combo, 1, wxALL | wxALIGN_CENTER, 5 );
263 mrl_sizer_sizer->Add( mrl_sizer, 1, wxEXPAND | wxALL, 5 );
266 /* Create Static Text */
267 wxStaticText *label = new wxStaticText( panel, -1,
268 wxU(_("Alternatively, you can build an MRL using one of the "
269 "following predefined targets:")) );
271 wxFlexGridSizer *sout_sizer = NULL;
272 wxStaticLine *static_line = NULL;
274 if( i_method == OPEN_NORMAL )
276 /* Create Stream Output checkox */
277 sout_sizer = new wxFlexGridSizer( 2, 1, 20 );
280 sout_checkbox = new wxCheckBox( panel, SoutEnable_Event,
281 wxU(_("Stream output")) );
282 sout_checkbox->SetToolTip( wxU(_("Use VLC as a stream server")) );
283 sout_sizer->Add( sout_checkbox, 0,
284 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
285 sout_button = new wxButton( panel, SoutSettings_Event,
286 wxU(_("Settings...")) );
287 sout_button->Disable();
289 char *psz_sout = config_GetPsz( p_intf, "sout" );
290 if( psz_sout && *psz_sout )
292 sout_checkbox->SetValue(TRUE);
293 sout_button->Enable();
294 subsfile_mrl.Add( wxString(wxT("sout=")) + wxU(psz_sout) );
296 if( psz_sout ) free( psz_sout );
298 sout_sizer->Add( sout_button, 1, wxALIGN_LEFT |
299 wxALIGN_CENTER_VERTICAL );
302 static_line = new wxStaticLine( panel, wxID_OK );
305 /* Create the buttons */
306 wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
307 ok_button->SetDefault();
308 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
311 /* Create notebook */
312 notebook = new wxNotebook( panel, Notebook_Event );
313 wxNotebookSizer *notebook_sizer = new wxNotebookSizer( notebook );
315 notebook->AddPage( FilePanel( notebook ), wxU(_("File")),
316 i_access_method == FILE_ACCESS );
317 notebook->AddPage( DiscPanel( notebook ), wxU(_("Disc")),
318 i_access_method == DISC_ACCESS );
319 notebook->AddPage( NetPanel( notebook ), wxU(_("Network")),
320 i_access_method == NET_ACCESS );
322 notebook->AddPage( V4LPanel( notebook ), wxU(_("Video For Linux")),
323 i_access_method == V4L_ACCESS );
326 module_t *p_module = config_FindModule( VLC_OBJECT(p_intf), "dshow" );
329 AutoBuiltPanel *autopanel =
330 new AutoBuiltPanel( notebook, this, p_intf, p_module );
331 input_tab_array.Add( autopanel );
332 notebook->AddPage( autopanel, wxU( p_module->psz_longname ) );
335 /* Update Disc panel */
336 wxCommandEvent dummy_event;
337 OnDiscTypeChange( dummy_event );
339 /* Update Net panel */
340 dummy_event.SetId( NetRadio1_Event );
341 OnNetTypeChange( dummy_event );
344 /* Update v4l panel */
345 dummy_event.SetId( VideoType_Event );
346 OnV4LTypeChange( dummy_event );
350 wxNotebookEvent event( wxEVT_NULL, 0, i_access_method );
351 OnPageChange( event );
353 /* Place everything in sizers */
354 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
355 button_sizer->Add( ok_button, 0, wxALL, 5 );
356 button_sizer->Add( cancel_button, 0, wxALL, 5 );
357 button_sizer->Layout();
358 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
359 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
360 panel_sizer->Add( mrl_sizer_sizer, 0, wxEXPAND, 5 );
361 panel_sizer->Add( label, 0, wxEXPAND | wxALL, 5 );
362 panel_sizer->Add( notebook_sizer, 1, wxEXPAND | wxALL, 5 );
363 if( i_method == OPEN_NORMAL)
365 panel_sizer->Add( sout_sizer, 0, wxALIGN_LEFT | wxALL, 5 );
366 panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
368 panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALL, 5 );
369 panel_sizer->Layout();
370 panel->SetSizerAndFit( panel_sizer );
371 main_sizer->Add( panel, 1, wxGROW, 0 );
372 main_sizer->Layout();
373 SetSizerAndFit( main_sizer );
376 OpenDialog::~OpenDialog()
379 if( file_dialog ) delete file_dialog;
381 if( v4l_dialog ) delete v4l_dialog;
383 if( sout_dialog ) delete sout_dialog;
384 if( subsfile_dialog ) delete subsfile_dialog;
387 int OpenDialog::Show( int i_access_method, int i_arg )
390 notebook->SetSelection( i_access_method );
391 i_ret = wxFrame::Show();
397 int OpenDialog::Show()
400 i_ret = wxFrame::Show();
406 /*****************************************************************************
408 *****************************************************************************/
409 wxPanel *OpenDialog::FilePanel( wxWindow* parent )
411 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
414 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
416 /* Create browse file line */
417 wxBoxSizer *file_sizer = new wxBoxSizer( wxHORIZONTAL );
419 file_combo = new wxComboBox( panel, FileName_Event, wxT(""),
420 wxPoint(20,25), wxSize(200, -1), 0, NULL );
421 wxButton *browse_button = new wxButton( panel, FileBrowse_Event,
422 wxU(_("Browse...")) );
423 file_sizer->Add( file_combo, 1, wxALL, 5 );
424 file_sizer->Add( browse_button, 0, wxALL, 5 );
426 /* Create Subtitles File checkox */
427 wxFlexGridSizer *subsfile_sizer = new wxFlexGridSizer( 2, 1, 20 );
428 subsfile_checkbox = new wxCheckBox( panel, SubsFileEnable_Event,
429 wxU(_("Subtitles file")) );
430 subsfile_checkbox->SetToolTip( wxU(_("Load an additional subtitles file. "
431 "Currently only works with AVI files.")) );
432 subsfile_sizer->Add( subsfile_checkbox, 0,
433 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
434 subsfile_button = new wxButton( panel, SubsFileSettings_Event,
435 wxU(_("Settings...")) );
436 subsfile_button->Disable();
438 char *psz_subsfile = config_GetPsz( p_intf, "sub-file" );
439 if( psz_subsfile && *psz_subsfile )
441 subsfile_checkbox->SetValue(TRUE);
442 subsfile_button->Enable();
443 subsfile_mrl.Add( wxString(wxT("sub-file=")) + wxU(psz_subsfile) );
445 if( psz_subsfile ) free( psz_subsfile );
447 subsfile_sizer->Add( subsfile_button, 1,
448 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
450 sizer->Add( file_sizer, 0, wxEXPAND | wxALL, 5 );
451 sizer->Add( subsfile_sizer, 0, wxEXPAND | wxALL, 5 );
452 panel->SetSizerAndFit( sizer );
456 wxPanel *OpenDialog::DiscPanel( wxWindow* parent )
458 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
461 wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
462 wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 3, 20 );
464 static const wxString disc_type_array[] =
466 wxU(_("DVD (menus support)")),
473 disc_type = new wxRadioBox( panel, DiscType_Event, wxU(_("Disc type")),
474 wxDefaultPosition, wxDefaultSize,
475 WXSIZEOF(disc_type_array), disc_type_array,
476 WXSIZEOF(disc_type_array), wxRA_SPECIFY_COLS );
477 sizer_row->Add( disc_type, 0, wxEXPAND | wxALL, 5 );
479 wxStaticText *label = new wxStaticText( panel, -1, wxU(_("Device name")) );
480 disc_device = new wxTextCtrl( panel, DiscDevice_Event, wxT(""),
481 wxDefaultPosition, wxDefaultSize,
484 sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
485 sizer->Add( disc_device, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
487 label = new wxStaticText( panel, -1, wxU(_("Title")) );
488 disc_title = new wxSpinCtrl( panel, DiscTitle_Event );
490 sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
491 sizer->Add( disc_title, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
493 label = new wxStaticText( panel, -1, wxU(_("Chapter")) );
494 disc_chapter = new wxSpinCtrl( panel, DiscChapter_Event );
495 sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
496 sizer->Add( disc_chapter, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
497 sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
499 panel->SetSizerAndFit( sizer_row );
503 wxPanel *OpenDialog::NetPanel( wxWindow* parent )
506 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
509 wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
510 wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 3, 20 );
512 static const wxString net_type_array[] =
515 wxU(_("UDP/RTP Multicast")),
516 wxU(_("HTTP/FTP/MMS"))
521 net_radios[i] = new wxRadioButton( panel, NetRadio1_Event + i,
523 wxDefaultPosition, wxDefaultSize,
526 net_subpanels[i] = new wxPanel( panel, -1,
527 wxDefaultPosition, wxDefaultSize );
531 wxFlexGridSizer *subpanel_sizer;
533 i_net_ports[0] = config_GetInt( p_intf, "server-port" );
534 subpanel_sizer = new wxFlexGridSizer( 2, 1, 20 );
535 label = new wxStaticText( net_subpanels[0], -1, wxU(_("Port")) );
536 net_ports[0] = new wxSpinCtrl( net_subpanels[0], NetPort1_Event,
537 wxString::Format(wxT("%d"), i_net_ports[0]),
538 wxDefaultPosition, wxDefaultSize,
540 0, 16000, i_net_ports[0] );
542 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
543 subpanel_sizer->Add( net_ports[0], 1,
544 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
545 net_subpanels[0]->SetSizerAndFit( subpanel_sizer );
546 net_radios[0]->SetValue( TRUE );
548 /* UDP/RTP Multicast row */
549 subpanel_sizer = new wxFlexGridSizer( 4, 1, 20 );
550 label = new wxStaticText( net_subpanels[1], -1, wxU(_("Address")) );
551 net_addrs[1] = new wxTextCtrl( net_subpanels[1], NetAddr2_Event, wxT(""),
552 wxDefaultPosition, wxDefaultSize,
554 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
555 subpanel_sizer->Add( net_addrs[1], 1,
556 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
558 label = new wxStaticText( net_subpanels[1], -1, wxU(_("Port")) );
559 i_net_ports[1] = i_net_ports[0];
560 net_ports[1] = new wxSpinCtrl( net_subpanels[1], NetPort2_Event,
561 wxString::Format(wxT("%d"), i_net_ports[1]),
562 wxDefaultPosition, wxDefaultSize,
564 0, 16000, i_net_ports[1] );
566 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
567 subpanel_sizer->Add( net_ports[1], 1,
568 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
569 net_subpanels[1]->SetSizerAndFit( subpanel_sizer );
572 subpanel_sizer = new wxFlexGridSizer( 2, 1, 20 );
573 label = new wxStaticText( net_subpanels[2], -1, wxU(_("URL")) );
574 net_addrs[2] = new wxTextCtrl( net_subpanels[2], NetAddr3_Event, wxT(""),
575 wxDefaultPosition, wxSize( 200, -1 ),
577 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
578 subpanel_sizer->Add( net_addrs[2], 1,
579 wxEXPAND | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
580 net_subpanels[2]->SetSizerAndFit( subpanel_sizer );
582 /* Stuff everything into the main panel */
585 sizer->Add( net_radios[i], 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
587 sizer->Add( net_subpanels[i], 1, wxEXPAND | wxALIGN_LEFT |
588 wxALIGN_CENTER_VERTICAL | wxALL, 5 );
591 sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
593 panel->SetSizerAndFit( sizer_row );
598 wxPanel *OpenDialog::V4LPanel( wxWindow* parent )
600 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
603 wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
604 wxFlexGridSizer *sizer = new wxFlexGridSizer( 1, 4, 20 );
606 static const wxString video_type_array[] =
614 video_type = new wxRadioBox( panel, VideoType_Event,
615 wxU(_("Video Device Type")),
616 wxDefaultPosition, wxDefaultSize,
617 WXSIZEOF(video_type_array), video_type_array,
618 WXSIZEOF(video_type_array), wxRA_SPECIFY_COLS );
620 sizer_row->Add( video_type, 0, wxEXPAND | wxALL, 5 );
624 wxFlexGridSizer *video_sizer = new wxFlexGridSizer( 4, 2, 20 );
625 wxStaticText *label = new wxStaticText( panel, -1, wxU(_("Video Device")) );
626 video_device = new wxTextCtrl( panel, VideoDevice_Event, wxT(""),
627 wxDefaultPosition, wxDefaultSize,
629 video_device->SetToolTip( wxU(_("Device corresponding to your acquisition "
630 "card or your webcam")) );
631 video_sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
632 video_sizer->Add( video_device, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
634 label = new wxStaticText( panel, -1, wxU(_("Channel")) );
635 video_channel = new wxSpinCtrl( panel, VideoChannel_Event, wxT("0") );
636 video_channel->SetToolTip( wxU(_("Usually 0 is for tuner, 1 for composite "
637 "and 2 for svideo")) );
638 video_sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_HORIZONTAL );
639 video_sizer->Add( video_channel, 1, wxALIGN_LEFT | wxALIGN_CENTER_HORIZONTAL );
640 sizer->Add( video_sizer, 0, wxEXPAND | wxALL, 5 );
642 wxBoxSizer *v4lbutton_sizer = new wxBoxSizer( wxHORIZONTAL );
643 v4l_button = new wxButton( panel, V4LSettings_Event,
644 wxU(_("Advanced Settings...")) );
646 v4lbutton_sizer->Add( v4l_button, 0, wxALIGN_RIGHT, 5 );
648 sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
649 sizer_row->Add( v4lbutton_sizer, 0, wxEXPAND | wxALL, 5 );
651 panel->SetSizerAndFit( sizer_row );
656 void OpenDialog::UpdateMRL()
658 UpdateMRL( i_current_access_method );
661 void OpenDialog::UpdateMRL( int i_access_method )
663 wxString demux, mrltemp;
665 i_current_access_method = i_access_method;
667 switch( i_access_method )
670 //mrltemp = wxT("file") + demux + wxT(":") + file_combo->GetValue();
671 mrltemp = file_combo->GetValue();
674 mrltemp = ( disc_type->GetSelection() == 0 ? wxT("dvd") :
675 disc_type->GetSelection() == 1 ? wxT("dvdsimple") :
676 disc_type->GetSelection() == 2 ? wxT("vcd") : wxT("cdda") )
678 // + disc_device->GetLineText(0)
679 + disc_device->GetValue()
680 + wxString::Format( wxT("@%d:%d"),
681 disc_title->GetValue(),
682 disc_chapter->GetValue() );
688 if( i_net_ports[0] !=
689 config_GetInt( p_intf, "server-port" ) )
691 mrltemp = wxT("udp") + demux +
692 wxString::Format( wxT("://@:%d"),
697 mrltemp = wxT("udp") + demux + wxT("://");
702 mrltemp = wxT("udp") + demux + wxT("://@") +
703 net_addrs[1]->GetLineText(0);
704 if( i_net_ports[1] !=
705 config_GetInt( p_intf, "server-port" ) )
707 mrltemp = mrltemp + wxString::Format( wxT(":%d"),
714 mrltemp = wxT("http") + demux + wxT("://") +
715 net_addrs[2]->GetLineText(0);
722 mrltemp = ( video_type->GetSelection() == 0 ? wxT("v4l") :
723 video_type->GetSelection() == 1 ? wxT("v4l") :
724 video_type->GetSelection() == 2 ? wxT("pvr") :
727 + video_device->GetLineText( 0 );
729 if( video_type->GetSelection() == 1 )
731 mrltemp += wxString::Format( wxT(":channel=%d"),
732 video_channel->GetValue() );
735 if ( /* v4l_dialog != NULL && */ !v4l_mrl.IsEmpty() )
737 mrltemp += v4l_mrl[0];
745 int i_item = i_access_method - MAX_ACCESS;
747 if( i_item < 0 || i_item >= (int)input_tab_array.GetCount() )
750 AutoBuiltPanel *input_panel = input_tab_array.Item( i_item );
752 mrltemp = input_panel->name + wxT("://");
754 for( int i=0; i < (int)input_panel->config_array.GetCount(); i++ )
756 ConfigControl *control = input_panel->config_array.Item(i);
757 mrltemp += wxT(" :") + control->GetName() + wxT("=");
759 switch( control->GetType() )
761 case CONFIG_ITEM_STRING:
762 case CONFIG_ITEM_FILE:
763 case CONFIG_ITEM_DIRECTORY:
764 case CONFIG_ITEM_MODULE:
765 mrltemp += wxT("\"") + control->GetPszValue() + wxT("\"");
767 case CONFIG_ITEM_INTEGER:
768 case CONFIG_ITEM_BOOL:
770 wxString::Format( wxT("%i"), control->GetIntValue() );
772 case CONFIG_ITEM_FLOAT:
774 wxString::Format( wxT("%f"), control->GetFloatValue());
782 mrl_combo->SetValue( mrltemp );
785 /*****************************************************************************
787 *****************************************************************************/
788 void OpenDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
790 mrl = SeparateEntries( mrl_combo->GetValue() );
791 mrl_combo->Append( mrl_combo->GetValue() );
792 if( mrl_combo->GetCount() > 10 ) mrl_combo->Delete( 0 );
793 mrl_combo->SetSelection( mrl_combo->GetCount() - 1 );
795 if( i_method == OPEN_STREAM )
801 /* Update the playlist */
802 playlist_t *p_playlist =
803 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
805 if( p_playlist == NULL ) return;
807 for( int i = 0; i < (int)mrl.GetCount(); i++ )
809 int i_options = 0, i_total_options;
810 char **ppsz_options = NULL;
812 /* Count the input options */
813 while( i + i_options + 1 < (int)mrl.GetCount() &&
814 ((const char *)mrl[i + i_options + 1].mb_str())[0] == ':' )
819 /* Allocate ppsz_options */
820 for( int j = 0; j < i_options; j++ )
823 ppsz_options = (char **)malloc( sizeof(char *) * i_options );
825 ppsz_options[j] = strdup( mrl[i + j + 1].mb_str() );
828 i_total_options = i_options;
830 /* Get the options from the subtitles dialog */
831 if( subsfile_checkbox->IsChecked() && subsfile_mrl.GetCount() )
833 ppsz_options = (char **)realloc( ppsz_options, sizeof(char *) *
834 (i_total_options + subsfile_mrl.GetCount()) );
836 for( int j = 0; j < (int)subsfile_mrl.GetCount(); j++ )
838 ppsz_options[i_total_options + j] =
839 strdup( subsfile_mrl[j].mb_str() );
842 i_total_options += subsfile_mrl.GetCount();
845 /* Get the options from the stream output dialog */
846 if( sout_checkbox->IsChecked() && sout_mrl.GetCount() )
848 ppsz_options = (char **)realloc( ppsz_options, sizeof(char *) *
849 (i_total_options + sout_mrl.GetCount()) );
851 for( int j = 0; j < (int)sout_mrl.GetCount(); j++ )
853 ppsz_options[i_total_options + j] =
854 strdup( sout_mrl[j].mb_str() );
857 i_total_options += sout_mrl.GetCount();
861 playlist_Add( p_playlist, (const char *)mrl[i].mb_str(),
862 (const char **)ppsz_options, i_total_options,
863 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );
866 for( int j = 0; j < i_total_options; j++ )
867 free( ppsz_options[j] );
868 if( ppsz_options ) free( ppsz_options );
873 //TogglePlayButton( PLAYING_S );
875 vlc_object_release( p_playlist );
880 void OpenDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
885 void OpenDialog::OnPageChange( wxNotebookEvent& event )
887 UpdateMRL( event.GetSelection() );
890 void OpenDialog::OnMRLChange( wxCommandEvent& event )
892 //mrl = SeparateEntries( event.GetString() );
895 /*****************************************************************************
896 * File panel event methods.
897 *****************************************************************************/
898 void OpenDialog::OnFilePanelChange( wxCommandEvent& WXUNUSED(event) )
900 UpdateMRL( FILE_ACCESS );
903 void OpenDialog::OnFileBrowse( wxCommandEvent& WXUNUSED(event) )
905 if( file_dialog == NULL )
906 file_dialog = new wxFileDialog( this, wxU(_("Open file")),
907 wxT(""), wxT(""), wxT("*"), wxOPEN | wxMULTIPLE );
909 if( file_dialog && file_dialog->ShowModal() == wxID_OK )
914 file_dialog->GetPaths( paths );
916 for( size_t i = 0; i < paths.GetCount(); i++ )
918 if( paths[i].Find( wxT(' ') ) >= 0 )
919 path += wxT("\"") + paths[i] + wxT("\" ");
921 path += paths[i] + wxT(" ");
924 file_combo->SetValue( path );
925 file_combo->Append( path );
926 if( file_combo->GetCount() > 10 ) file_combo->Delete( 0 );
927 UpdateMRL( FILE_ACCESS );
931 /*****************************************************************************
932 * Disc panel event methods.
933 *****************************************************************************/
934 void OpenDialog::OnDiscPanelChange( wxCommandEvent& event )
936 UpdateMRL( DISC_ACCESS );
939 void OpenDialog::OnDiscDeviceChange( wxCommandEvent& event )
943 switch( disc_type->GetSelection() )
946 psz_device = config_GetPsz( p_intf, "cd-audio" );
950 psz_device = config_GetPsz( p_intf, "vcd" );
954 psz_device = config_GetPsz( p_intf, "dvd" );
958 if( strcmp( psz_device, disc_device->GetValue().c_str() ) )
960 b_disc_device_changed = true;
963 UpdateMRL( DISC_ACCESS );
966 void OpenDialog::OnDiscTypeChange( wxCommandEvent& WXUNUSED(event) )
970 switch( disc_type->GetSelection() )
973 psz_device = config_GetPsz( p_intf, "cd-audio" );
974 if( !b_disc_device_changed )
976 disc_device->SetValue( psz_device ? wxU(psz_device) : wxT("") );
981 psz_device = config_GetPsz( p_intf, "vcd" );
982 if( !b_disc_device_changed )
984 disc_device->SetValue( psz_device ? wxU(psz_device) : wxT("") );
989 psz_device = config_GetPsz( p_intf, "dvd" );
990 if( !b_disc_device_changed )
992 disc_device->SetValue( psz_device ? wxU(psz_device) : wxT("") );
997 if( psz_device ) free( psz_device );
999 switch( disc_type->GetSelection() )
1002 disc_title->SetRange( 0, 255 );
1003 disc_title->SetValue( 0 );
1007 disc_title->SetRange( 1, 255 );
1008 disc_title->SetValue( 1 );
1012 disc_chapter->SetRange( 1, 255 );
1013 disc_chapter->SetValue( 1 );
1015 UpdateMRL( DISC_ACCESS );
1018 /*****************************************************************************
1019 * Net panel event methods.
1020 *****************************************************************************/
1021 void OpenDialog::OnNetPanelChange( wxCommandEvent& event )
1023 if( event.GetId() >= NetPort1_Event && event.GetId() <= NetPort3_Event )
1025 i_net_ports[event.GetId() - NetPort1_Event] = event.GetInt();
1028 UpdateMRL( NET_ACCESS );
1031 void OpenDialog::OnNetTypeChange( wxCommandEvent& event )
1035 i_net_type = event.GetId() - NetRadio1_Event;
1039 net_radios[i]->SetValue( event.GetId() == (NetRadio1_Event+i) );
1040 net_subpanels[i]->Enable( event.GetId() == (NetRadio1_Event+i) );
1043 UpdateMRL( NET_ACCESS );
1047 /*****************************************************************************
1048 * v4l panel event methods.
1049 *****************************************************************************/
1050 void OpenDialog::OnV4LPanelChange( wxCommandEvent& WXUNUSED(event) )
1052 UpdateMRL( V4L_ACCESS );
1055 void OpenDialog::OnV4LTypeChange( wxCommandEvent& WXUNUSED(event) )
1057 video_device->SetValue( wxU( "/dev/video" ) );
1059 v4l_button->Enable();
1060 video_channel->Disable();
1062 switch( video_type->GetSelection() )
1065 video_channel->Enable();
1066 video_channel->SetRange( 0, 255 );
1069 v4l_button->Disable();
1075 UpdateMRL( V4L_ACCESS );
1078 void OpenDialog::OnV4LSettingsChange( wxCommandEvent& WXUNUSED(event) )
1080 /* Show/hide the open dialog */
1081 if( v4l_dialog == NULL )
1082 v4l_dialog = new V4LDialog( p_intf, this );
1084 if( v4l_dialog && v4l_dialog->ShowModal() == wxID_OK )
1086 v4l_mrl = v4l_dialog->GetOptions();
1089 UpdateMRL( V4L_ACCESS );
1093 /*****************************************************************************
1094 * Subtitles file event methods.
1095 *****************************************************************************/
1096 void OpenDialog::OnSubsFileEnable( wxCommandEvent& event )
1098 subsfile_button->Enable( event.GetInt() != 0 );
1101 void OpenDialog::OnSubsFileSettings( wxCommandEvent& WXUNUSED(event) )
1103 /* Show/hide the open dialog */
1104 if( subsfile_dialog == NULL )
1105 subsfile_dialog = new SubsFileDialog( p_intf, this );
1107 if( subsfile_dialog && subsfile_dialog->ShowModal() == wxID_OK )
1109 subsfile_mrl.Empty();
1110 subsfile_mrl.Add( wxString(wxT("sub-file=")) +
1111 subsfile_dialog->file_combo->GetValue() );
1112 if( subsfile_dialog->encoding_combo )
1113 subsfile_mrl.Add( wxString(wxT("subsdec-encoding=")) +
1114 subsfile_dialog->encoding_combo->GetValue() );
1115 subsfile_mrl.Add( wxString::Format( wxT("sub-delay=%i"),
1116 subsfile_dialog->delay_spinctrl->GetValue() ) );
1117 subsfile_mrl.Add( wxString::Format( wxT("sub-fps=%i"),
1118 subsfile_dialog->fps_spinctrl->GetValue() ) );
1122 /*****************************************************************************
1123 * Stream output event methods.
1124 *****************************************************************************/
1125 void OpenDialog::OnSoutEnable( wxCommandEvent& event )
1127 sout_button->Enable( event.GetInt() != 0 );
1130 void OpenDialog::OnSoutSettings( wxCommandEvent& WXUNUSED(event) )
1132 /* Show/hide the open dialog */
1133 if( sout_dialog == NULL )
1134 sout_dialog = new SoutDialog( p_intf, this );
1136 if( sout_dialog && sout_dialog->ShowModal() == wxID_OK )
1138 sout_mrl = sout_dialog->GetOptions();
1142 /*****************************************************************************
1143 * Utility functions.
1144 *****************************************************************************/
1145 wxArrayString SeparateEntries( wxString entries )
1147 vlc_bool_t b_quotes_mode = VLC_FALSE;
1149 wxArrayString entries_array;
1152 wxStringTokenizer token( entries, wxT(" \t\r\n\""), wxTOKEN_RET_DELIMS );
1154 while( token.HasMoreTokens() )
1156 entry += token.GetNextToken();
1158 if( entry.IsEmpty() ) continue;
1160 if( !b_quotes_mode && entry.Last() == wxT('\"') )
1162 /* Enters quotes mode */
1164 b_quotes_mode = VLC_TRUE;
1166 else if( b_quotes_mode && entry.Last() == wxT('\"') )
1168 /* Finished the quotes mode */
1170 if( !entry.IsEmpty() ) entries_array.Add( entry );
1172 b_quotes_mode = VLC_FALSE;
1174 else if( !b_quotes_mode && entry.Last() != wxT('\"') )
1176 /* we found a non-quoted standalone string */
1177 if( token.HasMoreTokens() ||
1178 entry.Last() == wxT(' ') || entry.Last() == wxT('\t') ||
1179 entry.Last() == wxT('\r') || entry.Last() == wxT('\n') )
1181 if( !entry.IsEmpty() ) entries_array.Add( entry );
1188 if( !entry.IsEmpty() ) entries_array.Add( entry );
1190 return entries_array;