1 /*****************************************************************************
2 * open.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000, 2001, 2003 VideoLAN
5 * $Id: open.cpp,v 1.58 2003/12/16 13:35:12 gbazin 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, NetRadio4_Event,
81 NetPort1_Event, NetPort2_Event, NetPort3_Event,
82 NetAddr1_Event, NetAddr2_Event, NetAddr3_Event, NetAddr4_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_RADIOBUTTON(NetRadio4_Event, OpenDialog::OnNetTypeChange)
126 EVT_TEXT(NetPort1_Event, OpenDialog::OnNetPanelChange)
127 EVT_SPINCTRL(NetPort1_Event, OpenDialog::OnNetPanelChange)
128 EVT_TEXT(NetPort2_Event, OpenDialog::OnNetPanelChange)
129 EVT_SPINCTRL(NetPort2_Event, OpenDialog::OnNetPanelChange)
130 EVT_TEXT(NetPort3_Event, OpenDialog::OnNetPanelChange)
131 EVT_SPINCTRL(NetPort3_Event, OpenDialog::OnNetPanelChange)
132 EVT_TEXT(NetAddr2_Event, OpenDialog::OnNetPanelChange)
133 EVT_TEXT(NetAddr3_Event, OpenDialog::OnNetPanelChange)
134 EVT_TEXT(NetAddr4_Event, OpenDialog::OnNetPanelChange)
135 EVT_CHECKBOX(NetForceIPv6_Event, OpenDialog::OnNetPanelChange)
138 /* Events generated by the v4l panel */
139 EVT_RADIOBOX(VideoType_Event, OpenDialog::OnV4LTypeChange)
140 EVT_TEXT(VideoDevice_Event, OpenDialog::OnV4LPanelChange)
141 EVT_SPINCTRL(VideoChannel_Event, OpenDialog::OnV4LPanelChange)
142 EVT_BUTTON(V4LSettings_Event, OpenDialog::OnV4LSettingsChange)
145 /* Events generated by the subtitle file buttons */
146 EVT_CHECKBOX(SubsFileEnable_Event, OpenDialog::OnSubsFileEnable)
147 EVT_BUTTON(SubsFileSettings_Event, OpenDialog::OnSubsFileSettings)
149 /* Events generated by the stream output buttons */
150 EVT_CHECKBOX(SoutEnable_Event, OpenDialog::OnSoutEnable)
151 EVT_BUTTON(SoutSettings_Event, OpenDialog::OnSoutSettings)
153 /* Hide the window when the user closes the window */
154 EVT_CLOSE(OpenDialog::OnCancel)
158 /*****************************************************************************
160 *****************************************************************************/
161 WX_DEFINE_ARRAY(ConfigControl *, ArrayOfConfigControls);
163 class AutoBuiltPanel : public wxPanel
168 AutoBuiltPanel( wxWindow *, OpenDialog *, intf_thread_t *,
171 virtual ~AutoBuiltPanel() {}
174 ArrayOfConfigControls config_array;
177 intf_thread_t *p_intf;
180 void AutoBuildCallback( void *p_data )
182 ((OpenDialog *)p_data)->UpdateMRL();
185 AutoBuiltPanel::AutoBuiltPanel( wxWindow *parent, OpenDialog *dialog,
186 intf_thread_t *_p_intf,
187 const module_t *p_module )
188 : wxPanel( parent, -1, wxDefaultPosition, wxSize(200, 200) ),
189 name( wxU(p_module->psz_object_name) ), p_intf( _p_intf )
191 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
193 module_config_t *p_item = p_module->p_config;
197 if( p_item->i_type & CONFIG_HINT || p_item->b_advanced )
200 ConfigControl *control =
201 CreateConfigControl( VLC_OBJECT(p_intf), p_item, this );
203 config_array.Add( control );
205 /* Don't add items that were not recognized */
206 if( control == NULL ) continue;
208 control->SetUpdateCallback( AutoBuildCallback, (void *)dialog );
210 sizer->Add( control, 0, wxEXPAND | wxALL, 2 );
212 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
214 this->SetSizerAndFit( sizer );
217 /*****************************************************************************
219 *****************************************************************************/
220 OpenDialog::OpenDialog( intf_thread_t *_p_intf, wxWindow *_p_parent,
221 int i_access_method, int i_arg ):
222 wxFrame( _p_parent, -1, wxU(_("Open Target")), wxDefaultPosition,
223 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
225 OpenDialog( _p_intf, _p_parent, i_access_method, i_arg, OPEN_NORMAL );
228 OpenDialog::OpenDialog( intf_thread_t *_p_intf, wxWindow *_p_parent,
229 int i_access_method, int i_arg, int _i_method ):
230 wxFrame( _p_parent, -1, wxU(_("Open Target")), wxDefaultPosition,
231 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
233 /* Initializations */
234 i_method = _i_method;
236 p_parent = _p_parent;
237 SetIcon( *p_intf->p_sys->p_icon );
239 i_disc_type_selection = 0;
245 subsfile_dialog = NULL;
246 b_disc_device_changed = false;
248 /* Create a panel to put everything in */
249 wxPanel *panel = new wxPanel( this, -1 );
250 panel->SetAutoLayout( TRUE );
252 /* Create MRL combobox */
253 wxBoxSizer *mrl_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
254 wxStaticBox *mrl_box = new wxStaticBox( panel, -1,
255 wxU(_("Media Resource Locator (MRL)")) );
256 wxStaticBoxSizer *mrl_sizer = new wxStaticBoxSizer( mrl_box,
258 wxStaticText *mrl_label = new wxStaticText( panel, -1,
259 wxU(_("Open Target:")) );
260 mrl_combo = new wxComboBox( panel, MRL_Event, wxT(""),
261 wxPoint(20,25), wxSize(120, -1),
263 mrl_combo->SetToolTip( wxU(_("You can use this field directly by typing "
264 "the full MRL you want to open.\n""Alternatively, the field will be "
265 "filled automatically when you use the controls below.")) );
267 mrl_sizer->Add( mrl_label, 0, wxALL | wxALIGN_CENTER, 5 );
268 mrl_sizer->Add( mrl_combo, 1, wxALL | wxALIGN_CENTER, 5 );
269 mrl_sizer_sizer->Add( mrl_sizer, 1, wxEXPAND | wxALL, 5 );
272 /* Create Static Text */
273 wxStaticText *label = new wxStaticText( panel, -1,
274 wxU(_("Alternatively, you can build an MRL using one of the "
275 "following predefined targets:")) );
277 wxFlexGridSizer *sout_sizer = NULL;
278 wxStaticLine *static_line = NULL;
280 if( i_method == OPEN_NORMAL )
282 /* Create Stream Output checkox */
283 sout_sizer = new wxFlexGridSizer( 2, 1, 20 );
286 sout_checkbox = new wxCheckBox( panel, SoutEnable_Event,
287 wxU(_("Stream output")) );
288 sout_checkbox->SetToolTip( wxU(_("Use VLC as a stream server")) );
289 sout_sizer->Add( sout_checkbox, 0,
290 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
291 sout_button = new wxButton( panel, SoutSettings_Event,
292 wxU(_("Settings...")) );
293 sout_button->Disable();
295 char *psz_sout = config_GetPsz( p_intf, "sout" );
296 if( psz_sout && *psz_sout )
298 sout_checkbox->SetValue(TRUE);
299 sout_button->Enable();
300 subsfile_mrl.Add( wxString(wxT("sout=")) + wxU(psz_sout) );
302 if( psz_sout ) free( psz_sout );
304 sout_sizer->Add( sout_button, 1, wxALIGN_LEFT |
305 wxALIGN_CENTER_VERTICAL );
308 static_line = new wxStaticLine( panel, wxID_OK );
311 /* Create the buttons */
312 wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
313 ok_button->SetDefault();
314 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
317 /* Create notebook */
318 notebook = new wxNotebook( panel, Notebook_Event );
319 wxNotebookSizer *notebook_sizer = new wxNotebookSizer( notebook );
321 notebook->AddPage( FilePanel( notebook ), wxU(_("File")),
322 i_access_method == FILE_ACCESS );
323 notebook->AddPage( DiscPanel( notebook ), wxU(_("Disc")),
324 i_access_method == DISC_ACCESS );
325 notebook->AddPage( NetPanel( notebook ), wxU(_("Network")),
326 i_access_method == NET_ACCESS );
328 notebook->AddPage( V4LPanel( notebook ), wxU(_("Video For Linux")),
329 i_access_method == V4L_ACCESS );
332 module_t *p_module = config_FindModule( VLC_OBJECT(p_intf), "dshow" );
335 AutoBuiltPanel *autopanel =
336 new AutoBuiltPanel( notebook, this, p_intf, p_module );
337 input_tab_array.Add( autopanel );
338 notebook->AddPage( autopanel, wxU( p_module->psz_longname ) );
341 /* Update Disc panel */
342 wxCommandEvent dummy_event;
343 OnDiscTypeChange( dummy_event );
345 /* Update Net panel */
346 dummy_event.SetId( NetRadio1_Event );
347 OnNetTypeChange( dummy_event );
350 /* Update v4l panel */
351 dummy_event.SetId( VideoType_Event );
352 OnV4LTypeChange( dummy_event );
356 wxNotebookEvent event( wxEVT_NULL, 0, i_access_method );
357 OnPageChange( event );
359 /* Place everything in sizers */
360 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
361 button_sizer->Add( ok_button, 0, wxALL, 5 );
362 button_sizer->Add( cancel_button, 0, wxALL, 5 );
363 button_sizer->Layout();
364 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
365 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
366 panel_sizer->Add( mrl_sizer_sizer, 0, wxEXPAND, 5 );
367 panel_sizer->Add( label, 0, wxEXPAND | wxALL, 5 );
368 panel_sizer->Add( notebook_sizer, 1, wxEXPAND | wxALL, 5 );
369 if( i_method == OPEN_NORMAL)
371 panel_sizer->Add( sout_sizer, 0, wxALIGN_LEFT | wxALL, 5 );
372 panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
374 panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALL, 5 );
375 panel_sizer->Layout();
376 panel->SetSizerAndFit( panel_sizer );
377 main_sizer->Add( panel, 1, wxGROW, 0 );
378 main_sizer->Layout();
379 SetSizerAndFit( main_sizer );
382 OpenDialog::~OpenDialog()
385 if( file_dialog ) delete file_dialog;
387 if( v4l_dialog ) delete v4l_dialog;
389 if( sout_dialog ) delete sout_dialog;
390 if( subsfile_dialog ) delete subsfile_dialog;
393 int OpenDialog::Show( int i_access_method, int i_arg )
396 notebook->SetSelection( i_access_method );
397 i_ret = wxFrame::Show();
403 int OpenDialog::Show()
406 i_ret = wxFrame::Show();
412 /*****************************************************************************
414 *****************************************************************************/
415 wxPanel *OpenDialog::FilePanel( wxWindow* parent )
417 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
420 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
422 /* Create browse file line */
423 wxBoxSizer *file_sizer = new wxBoxSizer( wxHORIZONTAL );
425 file_combo = new wxComboBox( panel, FileName_Event, wxT(""),
426 wxPoint(20,25), wxSize(200, -1), 0, NULL );
427 wxButton *browse_button = new wxButton( panel, FileBrowse_Event,
428 wxU(_("Browse...")) );
429 file_sizer->Add( file_combo, 1, wxALL, 5 );
430 file_sizer->Add( browse_button, 0, wxALL, 5 );
432 /* Create Subtitles File checkox */
433 wxFlexGridSizer *subsfile_sizer = new wxFlexGridSizer( 2, 1, 20 );
434 subsfile_checkbox = new wxCheckBox( panel, SubsFileEnable_Event,
435 wxU(_("Subtitles file")) );
436 subsfile_checkbox->SetToolTip( wxU(_("Load an additional subtitles file. "
437 "Currently only works with AVI files.")) );
438 subsfile_sizer->Add( subsfile_checkbox, 0,
439 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
440 subsfile_button = new wxButton( panel, SubsFileSettings_Event,
441 wxU(_("Settings...")) );
442 subsfile_button->Disable();
444 char *psz_subsfile = config_GetPsz( p_intf, "sub-file" );
445 if( psz_subsfile && *psz_subsfile )
447 subsfile_checkbox->SetValue(TRUE);
448 subsfile_button->Enable();
449 subsfile_mrl.Add( wxString(wxT("sub-file=")) + wxU(psz_subsfile) );
451 if( psz_subsfile ) free( psz_subsfile );
453 subsfile_sizer->Add( subsfile_button, 1,
454 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
456 sizer->Add( file_sizer, 0, wxEXPAND | wxALL, 5 );
457 sizer->Add( subsfile_sizer, 0, wxEXPAND | wxALL, 5 );
458 panel->SetSizerAndFit( sizer );
462 wxPanel *OpenDialog::DiscPanel( wxWindow* parent )
464 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
467 wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
468 wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 3, 20 );
470 static const wxString disc_type_array[] =
472 wxU(_("DVD (menus support)")),
479 disc_type = new wxRadioBox( panel, DiscType_Event, wxU(_("Disc type")),
480 wxDefaultPosition, wxDefaultSize,
481 WXSIZEOF(disc_type_array), disc_type_array,
482 WXSIZEOF(disc_type_array), wxRA_SPECIFY_COLS );
484 sizer_row->Add( disc_type, i_disc_type_selection, wxEXPAND | wxALL, 5 );
486 wxStaticText *label = new wxStaticText( panel, -1, wxU(_("Device name")) );
487 disc_device = new wxTextCtrl( panel, DiscDevice_Event, wxT(""),
488 wxDefaultPosition, wxDefaultSize,
491 sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
492 sizer->Add( disc_device, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
494 disc_title_label = new wxStaticText( panel, -1, wxU(_("Title")) );
495 disc_title = new wxSpinCtrl( panel, DiscTitle_Event );
497 sizer->Add( disc_title_label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
498 sizer->Add( disc_title, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
500 disc_chapter_label = new wxStaticText( panel, -1, wxU(_("Chapter")) );
501 disc_chapter = new wxSpinCtrl( panel, DiscChapter_Event );
502 sizer->Add( disc_chapter_label, 0,
503 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
504 sizer->Add( disc_chapter, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
505 sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
507 panel->SetSizerAndFit( sizer_row );
511 wxPanel *OpenDialog::NetPanel( wxWindow* parent )
514 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
517 wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
518 wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 4, 20 );
520 static const wxString net_type_array[] =
523 wxU(_("UDP/RTP Multicast")),
524 wxU(_("HTTP/FTP/MMS")),
530 net_radios[i] = new wxRadioButton( panel, NetRadio1_Event + i,
532 wxDefaultPosition, wxDefaultSize,
535 net_subpanels[i] = new wxPanel( panel, -1,
536 wxDefaultPosition, wxDefaultSize );
540 wxFlexGridSizer *subpanel_sizer;
542 i_net_ports[0] = config_GetInt( p_intf, "server-port" );
543 subpanel_sizer = new wxFlexGridSizer( 3, 1, 20 );
544 label = new wxStaticText( net_subpanels[0], -1, wxU(_("Port")) );
545 net_ports[0] = new wxSpinCtrl( net_subpanels[0], NetPort1_Event,
546 wxString::Format(wxT("%d"), i_net_ports[0]),
547 wxDefaultPosition, wxDefaultSize,
549 0, 16000, i_net_ports[0] );
551 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
552 subpanel_sizer->Add( net_ports[0], 1,
553 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
554 net_ipv6 = new wxCheckBox( net_subpanels[0], NetForceIPv6_Event,
555 wxU(_("Force IPv6")));
556 subpanel_sizer->Add( net_ipv6, 0,
557 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
558 net_subpanels[0]->SetSizerAndFit( subpanel_sizer );
559 net_radios[0]->SetValue( TRUE );
561 /* UDP/RTP Multicast row */
562 subpanel_sizer = new wxFlexGridSizer( 4, 1, 20 );
563 label = new wxStaticText( net_subpanels[1], -1, wxU(_("Address")) );
564 net_addrs[1] = new wxTextCtrl( net_subpanels[1], NetAddr2_Event, wxT(""),
565 wxDefaultPosition, wxDefaultSize,
567 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
568 subpanel_sizer->Add( net_addrs[1], 1,
569 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
571 label = new wxStaticText( net_subpanels[1], -1, wxU(_("Port")) );
572 i_net_ports[1] = i_net_ports[0];
573 net_ports[1] = new wxSpinCtrl( net_subpanels[1], NetPort2_Event,
574 wxString::Format(wxT("%d"), i_net_ports[1]),
575 wxDefaultPosition, wxDefaultSize,
577 0, 16000, i_net_ports[1] );
579 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
580 subpanel_sizer->Add( net_ports[1], 1,
581 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
582 net_subpanels[1]->SetSizerAndFit( subpanel_sizer );
584 /* HTTP and RTSP rows */
587 subpanel_sizer = new wxFlexGridSizer( 2, 1, 20 );
588 label = new wxStaticText( net_subpanels[i], -1, wxU(_("URL")) );
589 net_addrs[i] = new wxTextCtrl( net_subpanels[i], NetAddr1_Event + i,
590 wxT((i == 2) ? "" : "rtsp://"),
591 wxDefaultPosition, wxSize( 200, -1 ),
593 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
594 subpanel_sizer->Add( net_addrs[i], 1,
595 wxEXPAND | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
596 net_subpanels[i]->SetSizerAndFit( subpanel_sizer );
599 /* Stuff everything into the main panel */
602 sizer->Add( net_radios[i], 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
604 sizer->Add( net_subpanels[i], 1, wxEXPAND | wxALIGN_LEFT |
605 wxALIGN_CENTER_VERTICAL | wxALL, 5 );
608 sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
610 panel->SetSizerAndFit( sizer_row );
615 wxPanel *OpenDialog::V4LPanel( wxWindow* parent )
617 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
620 wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
621 wxFlexGridSizer *sizer = new wxFlexGridSizer( 1, 4, 20 );
623 static const wxString video_type_array[] =
631 video_type = new wxRadioBox( panel, VideoType_Event,
632 wxU(_("Video Device Type")),
633 wxDefaultPosition, wxDefaultSize,
634 WXSIZEOF(video_type_array), video_type_array,
635 WXSIZEOF(video_type_array), wxRA_SPECIFY_COLS );
637 sizer_row->Add( video_type, 0, wxEXPAND | wxALL, 5 );
641 wxFlexGridSizer *video_sizer = new wxFlexGridSizer( 4, 2, 20 );
642 wxStaticText *label = new wxStaticText( panel, -1, wxU(_("Video Device")) );
643 video_device = new wxTextCtrl( panel, VideoDevice_Event, wxT(""),
644 wxDefaultPosition, wxDefaultSize,
646 video_device->SetToolTip( wxU(_("Device corresponding to your acquisition "
647 "card or your webcam")) );
648 video_sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
649 video_sizer->Add( video_device, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
651 label = new wxStaticText( panel, -1, wxU(_("Channel")) );
652 video_channel = new wxSpinCtrl( panel, VideoChannel_Event, wxT("0") );
653 video_channel->SetToolTip( wxU(_("Usually 0 is for tuner, 1 for composite "
654 "and 2 for svideo")) );
655 video_sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_HORIZONTAL );
656 video_sizer->Add( video_channel, 1, wxALIGN_LEFT | wxALIGN_CENTER_HORIZONTAL );
657 sizer->Add( video_sizer, 0, wxEXPAND | wxALL, 5 );
659 wxBoxSizer *v4lbutton_sizer = new wxBoxSizer( wxHORIZONTAL );
660 v4l_button = new wxButton( panel, V4LSettings_Event,
661 wxU(_("Advanced Settings...")) );
663 v4lbutton_sizer->Add( v4l_button, 0, wxALIGN_RIGHT, 5 );
665 sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
666 sizer_row->Add( v4lbutton_sizer, 0, wxEXPAND | wxALL, 5 );
668 panel->SetSizerAndFit( sizer_row );
673 void OpenDialog::UpdateMRL()
675 UpdateMRL( i_current_access_method );
678 void OpenDialog::UpdateMRL( int i_access_method )
680 wxString demux, mrltemp;
682 i_current_access_method = i_access_method;
684 switch( i_access_method )
687 //mrltemp = wxT("file") + demux + wxT(":") + file_combo->GetValue();
688 mrltemp = file_combo->GetValue();
691 i_disc_type_selection = disc_type->GetSelection();
693 switch ( i_disc_type_selection )
696 disc_chapter->Enable();
697 disc_chapter_label->Enable();
698 mrltemp = wxT("dvd://")
699 + disc_device->GetValue()
700 + wxString::Format( wxT("@%d:%d"),
701 disc_title->GetValue(),
702 disc_chapter->GetValue() );
705 disc_chapter->Enable();
706 disc_chapter_label->Enable();
707 mrltemp = wxT("dvdsimple://")
708 + disc_device->GetValue()
709 + wxString::Format( wxT("@%d:%d"),
710 disc_title->GetValue(),
711 disc_chapter->GetValue() );
714 disc_chapter->Disable();
715 disc_chapter_label->Disable();
717 if ( disc_title->GetValue() )
718 mrltemp = wxT("vcdx://")
719 + disc_device->GetValue()
720 + wxString::Format( wxT("@%c%d"),
721 config_GetInt( p_intf, "vcdx-PBC" )
723 disc_title->GetValue()
726 mrltemp = wxT("vcdx://")
727 + disc_device->GetValue();
729 mrltemp = wxT("vcd://")
730 + disc_device->GetValue()
731 + wxString::Format( wxT("@%d"),
732 disc_title->GetValue() );
736 disc_chapter->Disable();
737 disc_chapter_label->Disable();
739 if ( disc_title->GetValue() )
740 mrltemp = wxT("cddax://")
741 + disc_device->GetValue()
742 + wxString::Format( wxT("@T%d"),
743 disc_title->GetValue() );
745 mrltemp = wxT("cddax://")
746 + disc_device->GetValue();
749 mrltemp = wxT("cdda://")
750 + disc_device->GetValue()
751 + wxString::Format( wxT("@%d"),
752 disc_title->GetValue() );
756 msg_Err( p_intf, "invalid selection (%d)",
757 disc_type->GetSelection() );
765 mrltemp = wxT("udp") + demux + wxT("://");
766 if ( net_ipv6->GetValue() )
768 mrltemp += wxT("@[::]");
770 if( i_net_ports[0] !=
771 config_GetInt( p_intf, "server-port" ) )
773 mrltemp += wxString::Format( wxT("@:%d"), i_net_ports[0] );
778 mrltemp = wxT("udp") + demux + wxT("://@");
779 if ((net_addrs[1]->GetLineText(0).Find (':') != -1)
780 && (net_addrs[1]->GetLineText(0)[0u] != '['))
782 /* automatically adds '[' and ']' to IPv6 addresses */
783 mrltemp += wxT("[") + net_addrs[1]->GetLineText(0)
788 mrltemp += net_addrs[1]->GetLineText(0);
790 if( i_net_ports[1] != config_GetInt( p_intf, "server-port" ) )
792 mrltemp += wxString::Format( wxT(":%d"), i_net_ports[1] );
798 if( net_addrs[2]->GetLineText(0).Find(wxT("http://")) )
800 mrltemp = wxT("http") + demux + wxT("://");
802 mrltemp += net_addrs[2]->GetLineText(0);
807 if( net_addrs[3]->GetLineText(0).Find(wxT("rtsp://")) != 0 )
809 mrltemp = wxT("rtsp") + demux + wxT("://");
811 mrltemp += net_addrs[3]->GetLineText(0);
818 mrltemp = ( video_type->GetSelection() == 0 ? wxT("v4l") :
819 video_type->GetSelection() == 1 ? wxT("v4l") :
820 video_type->GetSelection() == 2 ? wxT("pvr") :
823 + video_device->GetLineText( 0 );
825 if( video_type->GetSelection() == 1 )
827 mrltemp += wxString::Format( wxT(":channel=%d"),
828 video_channel->GetValue() );
831 if ( /* v4l_dialog != NULL && */ !v4l_mrl.IsEmpty() )
833 mrltemp += v4l_mrl[0];
841 int i_item = i_access_method - MAX_ACCESS;
843 if( i_item < 0 || i_item >= (int)input_tab_array.GetCount() )
846 AutoBuiltPanel *input_panel = input_tab_array.Item( i_item );
848 mrltemp = input_panel->name + wxT("://");
850 for( int i=0; i < (int)input_panel->config_array.GetCount(); i++ )
852 ConfigControl *control = input_panel->config_array.Item(i);
853 mrltemp += wxT(" :") + control->GetName() + wxT("=");
855 switch( control->GetType() )
857 case CONFIG_ITEM_STRING:
858 case CONFIG_ITEM_FILE:
859 case CONFIG_ITEM_DIRECTORY:
860 case CONFIG_ITEM_MODULE:
861 mrltemp += wxT("\"") + control->GetPszValue() + wxT("\"");
863 case CONFIG_ITEM_INTEGER:
864 case CONFIG_ITEM_BOOL:
866 wxString::Format( wxT("%i"), control->GetIntValue() );
868 case CONFIG_ITEM_FLOAT:
870 wxString::Format( wxT("%f"), control->GetFloatValue());
878 mrl_combo->SetValue( mrltemp );
881 /*****************************************************************************
883 *****************************************************************************/
884 void OpenDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
886 mrl = SeparateEntries( mrl_combo->GetValue() );
887 mrl_combo->Append( mrl_combo->GetValue() );
888 if( mrl_combo->GetCount() > 10 ) mrl_combo->Delete( 0 );
889 mrl_combo->SetSelection( mrl_combo->GetCount() - 1 );
891 if( i_method == OPEN_STREAM )
897 /* Update the playlist */
898 playlist_t *p_playlist =
899 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
901 if( p_playlist == NULL ) return;
903 for( int i = 0; i < (int)mrl.GetCount(); i++ )
905 int i_options = 0, i_total_options;
906 char **ppsz_options = NULL;
908 /* Count the input options */
909 while( i + i_options + 1 < (int)mrl.GetCount() &&
910 ((const char *)mrl[i + i_options + 1].mb_str())[0] == ':' )
915 /* Allocate ppsz_options */
916 for( int j = 0; j < i_options; j++ )
919 ppsz_options = (char **)malloc( sizeof(char *) * i_options );
921 ppsz_options[j] = strdup( mrl[i + j + 1].mb_str() );
924 i_total_options = i_options;
926 /* Get the options from the subtitles dialog */
927 if( subsfile_checkbox->IsChecked() && subsfile_mrl.GetCount() )
929 ppsz_options = (char **)realloc( ppsz_options, sizeof(char *) *
930 (i_total_options + subsfile_mrl.GetCount()) );
932 for( int j = 0; j < (int)subsfile_mrl.GetCount(); j++ )
934 ppsz_options[i_total_options + j] =
935 strdup( subsfile_mrl[j].mb_str() );
938 i_total_options += subsfile_mrl.GetCount();
941 /* Get the options from the stream output dialog */
942 if( sout_checkbox->IsChecked() && sout_mrl.GetCount() )
944 ppsz_options = (char **)realloc( ppsz_options, sizeof(char *) *
945 (i_total_options + sout_mrl.GetCount()) );
947 for( int j = 0; j < (int)sout_mrl.GetCount(); j++ )
949 ppsz_options[i_total_options + j] =
950 strdup( sout_mrl[j].mb_str() );
953 i_total_options += sout_mrl.GetCount();
957 playlist_Add( p_playlist, (const char *)mrl[i].mb_str(),
958 (const char **)ppsz_options, i_total_options,
959 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );
962 for( int j = 0; j < i_total_options; j++ )
963 free( ppsz_options[j] );
964 if( ppsz_options ) free( ppsz_options );
969 //TogglePlayButton( PLAYING_S );
971 vlc_object_release( p_playlist );
976 void OpenDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
981 void OpenDialog::OnPageChange( wxNotebookEvent& event )
983 UpdateMRL( event.GetSelection() );
986 void OpenDialog::OnMRLChange( wxCommandEvent& event )
988 //mrl = SeparateEntries( event.GetString() );
991 /*****************************************************************************
992 * File panel event methods.
993 *****************************************************************************/
994 void OpenDialog::OnFilePanelChange( wxCommandEvent& WXUNUSED(event) )
996 UpdateMRL( FILE_ACCESS );
999 void OpenDialog::OnFileBrowse( wxCommandEvent& WXUNUSED(event) )
1001 if( file_dialog == NULL )
1002 file_dialog = new wxFileDialog( this, wxU(_("Open file")),
1003 wxT(""), wxT(""), wxT("*"), wxOPEN | wxMULTIPLE );
1005 if( file_dialog && file_dialog->ShowModal() == wxID_OK )
1007 wxArrayString paths;
1010 file_dialog->GetPaths( paths );
1012 for( size_t i = 0; i < paths.GetCount(); i++ )
1014 if( paths[i].Find( wxT(' ') ) >= 0 )
1015 path += wxT("\"") + paths[i] + wxT("\" ");
1017 path += paths[i] + wxT(" ");
1020 file_combo->SetValue( path );
1021 file_combo->Append( path );
1022 if( file_combo->GetCount() > 10 ) file_combo->Delete( 0 );
1023 UpdateMRL( FILE_ACCESS );
1027 /*****************************************************************************
1028 * Disc panel event methods.
1029 *****************************************************************************/
1030 void OpenDialog::OnDiscPanelChange( wxCommandEvent& event )
1032 UpdateMRL( DISC_ACCESS );
1035 void OpenDialog::OnDiscDeviceChange( wxCommandEvent& event )
1039 switch( disc_type->GetSelection() )
1042 psz_device = config_GetPsz( p_intf, "cd-audio" );
1046 psz_device = config_GetPsz( p_intf, "vcd" );
1050 psz_device = config_GetPsz( p_intf, "dvd" );
1054 if ( !psz_device ) psz_device = "";
1056 if( disc_device->GetValue().Cmp( wxU( psz_device ) ) )
1058 b_disc_device_changed = true;
1061 UpdateMRL( DISC_ACCESS );
1064 void OpenDialog::OnDiscTypeChange( wxCommandEvent& WXUNUSED(event) )
1066 char *psz_device = NULL;
1067 int i_selection = 1; /* Default Title/Track selection number*/
1069 switch( disc_type->GetSelection() )
1072 case 0: /* DVD with menues */
1074 /* Fall through... */
1076 case 1: /* DVD of some sort */
1078 psz_device = config_GetPsz( p_intf, "dvd" );
1079 if( !b_disc_device_changed )
1081 disc_device->SetValue( psz_device ? wxU(psz_device) : wxT("") );
1082 disc_title_label->SetLabel ( wxT("Title") );
1084 disc_title->SetRange( i_selection, 255 );
1085 disc_title->SetValue( i_selection );
1089 case 2: /* VCD of some sort */
1090 psz_device = config_GetPsz( p_intf, "vcd" );
1091 if( !b_disc_device_changed )
1093 disc_device->SetValue( psz_device ? wxU(psz_device) : wxT("") );
1096 /* There are at most 98, tracks in a VCD, 999 Segments, 500 entries
1097 I don't know what the limit is for LIDs, 999 is probably safe
1100 FIXME: it would be better however to get the information for
1101 this particular Media possibly from the General Info area.
1104 disc_title_label->SetLabel ( config_GetInt( p_intf, "vcdx-PBC" )
1105 ? wxT("PBC LID") : wxT("Entry") );
1106 disc_title->SetRange( 0, 999 );
1109 disc_title_label->SetLabel ( wxT("Track") );
1110 disc_title->SetRange( 1, 98 );
1112 disc_title->SetValue( i_selection );
1116 psz_device = config_GetPsz( p_intf, "cd-audio" );
1117 if( !b_disc_device_changed )
1119 disc_device->SetValue( psz_device ? wxU(psz_device) : wxT("") );
1121 disc_title_label->SetLabel ( wxT("Track") );
1125 /* There are at most 99 tracks in a CD-DA */
1126 disc_title->SetRange( i_selection, 99 );
1127 disc_title->SetValue( i_selection );
1130 msg_Err( p_intf, "invalid Disc type selection (%d)",
1131 disc_type->GetSelection() );
1135 if( psz_device ) free( psz_device );
1137 disc_chapter->SetRange( 1, 255 );
1138 disc_chapter->SetValue( 1 );
1140 UpdateMRL( DISC_ACCESS );
1143 /*****************************************************************************
1144 * Net panel event methods.
1145 *****************************************************************************/
1146 void OpenDialog::OnNetPanelChange( wxCommandEvent& event )
1148 if( event.GetId() >= NetPort1_Event && event.GetId() <= NetPort3_Event )
1150 i_net_ports[event.GetId() - NetPort1_Event] = event.GetInt();
1153 UpdateMRL( NET_ACCESS );
1156 void OpenDialog::OnNetTypeChange( wxCommandEvent& event )
1160 i_net_type = event.GetId() - NetRadio1_Event;
1164 net_radios[i]->SetValue( event.GetId() == (NetRadio1_Event+i) );
1165 net_subpanels[i]->Enable( event.GetId() == (NetRadio1_Event+i) );
1168 UpdateMRL( NET_ACCESS );
1172 /*****************************************************************************
1173 * v4l panel event methods.
1174 *****************************************************************************/
1175 void OpenDialog::OnV4LPanelChange( wxCommandEvent& WXUNUSED(event) )
1177 UpdateMRL( V4L_ACCESS );
1180 void OpenDialog::OnV4LTypeChange( wxCommandEvent& WXUNUSED(event) )
1182 video_device->SetValue( wxU( "/dev/video" ) );
1184 v4l_button->Enable();
1185 video_channel->Disable();
1187 switch( video_type->GetSelection() )
1190 video_channel->Enable();
1191 video_channel->SetRange( 0, 255 );
1194 v4l_button->Disable();
1200 UpdateMRL( V4L_ACCESS );
1203 void OpenDialog::OnV4LSettingsChange( wxCommandEvent& WXUNUSED(event) )
1205 /* Show/hide the open dialog */
1206 if( v4l_dialog == NULL )
1207 v4l_dialog = new V4LDialog( p_intf, this );
1209 if( v4l_dialog && v4l_dialog->ShowModal() == wxID_OK )
1211 v4l_mrl = v4l_dialog->GetOptions();
1214 UpdateMRL( V4L_ACCESS );
1218 /*****************************************************************************
1219 * Subtitles file event methods.
1220 *****************************************************************************/
1221 void OpenDialog::OnSubsFileEnable( wxCommandEvent& event )
1223 subsfile_button->Enable( event.GetInt() != 0 );
1226 void OpenDialog::OnSubsFileSettings( wxCommandEvent& WXUNUSED(event) )
1228 /* Show/hide the open dialog */
1229 if( subsfile_dialog == NULL )
1230 subsfile_dialog = new SubsFileDialog( p_intf, this );
1232 if( subsfile_dialog && subsfile_dialog->ShowModal() == wxID_OK )
1234 subsfile_mrl.Empty();
1235 subsfile_mrl.Add( wxString(wxT("sub-file=")) +
1236 subsfile_dialog->file_combo->GetValue() );
1237 if( subsfile_dialog->encoding_combo )
1238 subsfile_mrl.Add( wxString(wxT("subsdec-encoding=")) +
1239 subsfile_dialog->encoding_combo->GetValue() );
1240 subsfile_mrl.Add( wxString::Format( wxT("sub-delay=%i"),
1241 subsfile_dialog->delay_spinctrl->GetValue() ) );
1242 subsfile_mrl.Add( wxString::Format( wxT("sub-fps=%i"),
1243 subsfile_dialog->fps_spinctrl->GetValue() ) );
1247 /*****************************************************************************
1248 * Stream output event methods.
1249 *****************************************************************************/
1250 void OpenDialog::OnSoutEnable( wxCommandEvent& event )
1252 sout_button->Enable( event.GetInt() != 0 );
1255 void OpenDialog::OnSoutSettings( wxCommandEvent& WXUNUSED(event) )
1257 /* Show/hide the open dialog */
1258 if( sout_dialog == NULL )
1259 sout_dialog = new SoutDialog( p_intf, this );
1261 if( sout_dialog && sout_dialog->ShowModal() == wxID_OK )
1263 sout_mrl = sout_dialog->GetOptions();
1267 /*****************************************************************************
1268 * Utility functions.
1269 *****************************************************************************/
1270 wxArrayString SeparateEntries( wxString entries )
1272 vlc_bool_t b_quotes_mode = VLC_FALSE;
1274 wxArrayString entries_array;
1277 wxStringTokenizer token( entries, wxT(" \t\r\n\""), wxTOKEN_RET_DELIMS );
1279 while( token.HasMoreTokens() )
1281 entry += token.GetNextToken();
1283 if( entry.IsEmpty() ) continue;
1285 if( !b_quotes_mode && entry.Last() == wxT('\"') )
1287 /* Enters quotes mode */
1289 b_quotes_mode = VLC_TRUE;
1291 else if( b_quotes_mode && entry.Last() == wxT('\"') )
1293 /* Finished the quotes mode */
1295 if( !entry.IsEmpty() ) entries_array.Add( entry );
1297 b_quotes_mode = VLC_FALSE;
1299 else if( !b_quotes_mode && entry.Last() != wxT('\"') )
1301 /* we found a non-quoted standalone string */
1302 if( token.HasMoreTokens() ||
1303 entry.Last() == wxT(' ') || entry.Last() == wxT('\t') ||
1304 entry.Last() == wxT('\r') || entry.Last() == wxT('\n') )
1306 if( !entry.IsEmpty() ) entries_array.Add( entry );
1313 if( !entry.IsEmpty() ) entries_array.Add( entry );
1315 return entries_array;