1 /*****************************************************************************
2 * open.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2004 VideoLAN
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 #include <wx/combobox.h>
35 #include <wx/statline.h>
36 #include <wx/tokenzr.h>
40 #include "wxwindows.h"
41 #include "preferences_widgets.h"
44 # define wxRB_SINGLE 0
47 /*****************************************************************************
49 *****************************************************************************/
51 /* IDs for the controls and the menu commands */
54 Notebook_Event = wxID_HIGHEST,
66 NetRadio1_Event, NetRadio2_Event, NetRadio3_Event, NetRadio4_Event,
67 NetPort1_Event, NetPort2_Event, NetPort3_Event,
68 NetAddr1_Event, NetAddr2_Event, NetAddr3_Event, NetAddr4_Event,
79 SubsFileSettings_Event,
85 BEGIN_EVENT_TABLE(OpenDialog, wxFrame)
87 EVT_BUTTON(wxID_OK, OpenDialog::OnOk)
88 EVT_BUTTON(wxID_CANCEL, OpenDialog::OnCancel)
90 EVT_NOTEBOOK_PAGE_CHANGED(Notebook_Event, OpenDialog::OnPageChange)
92 EVT_TEXT(MRL_Event, OpenDialog::OnMRLChange)
94 /* Events generated by the file panel */
95 EVT_TEXT(FileName_Event, OpenDialog::OnFilePanelChange)
96 EVT_BUTTON(FileBrowse_Event, OpenDialog::OnFileBrowse)
98 /* Events generated by the disc panel */
99 EVT_RADIOBOX(DiscType_Event, OpenDialog::OnDiscTypeChange)
100 EVT_TEXT(DiscDevice_Event, OpenDialog::OnDiscDeviceChange)
101 EVT_TEXT(DiscDevice_Event, OpenDialog::OnDiscPanelChange)
102 EVT_TEXT(DiscTitle_Event, OpenDialog::OnDiscPanelChange)
103 EVT_SPINCTRL(DiscTitle_Event, OpenDialog::OnDiscPanelChange)
104 EVT_TEXT(DiscChapter_Event, OpenDialog::OnDiscPanelChange)
105 EVT_SPINCTRL(DiscChapter_Event, OpenDialog::OnDiscPanelChange)
107 /* Events generated by the net panel */
108 EVT_RADIOBUTTON(NetRadio1_Event, OpenDialog::OnNetTypeChange)
109 EVT_RADIOBUTTON(NetRadio2_Event, OpenDialog::OnNetTypeChange)
110 EVT_RADIOBUTTON(NetRadio3_Event, OpenDialog::OnNetTypeChange)
111 EVT_RADIOBUTTON(NetRadio4_Event, OpenDialog::OnNetTypeChange)
112 EVT_TEXT(NetPort1_Event, OpenDialog::OnNetPanelChange)
113 EVT_SPINCTRL(NetPort1_Event, OpenDialog::OnNetPanelChange)
114 EVT_TEXT(NetPort2_Event, OpenDialog::OnNetPanelChange)
115 EVT_SPINCTRL(NetPort2_Event, OpenDialog::OnNetPanelChange)
116 EVT_TEXT(NetPort3_Event, OpenDialog::OnNetPanelChange)
117 EVT_SPINCTRL(NetPort3_Event, OpenDialog::OnNetPanelChange)
118 EVT_TEXT(NetAddr2_Event, OpenDialog::OnNetPanelChange)
119 EVT_TEXT(NetAddr3_Event, OpenDialog::OnNetPanelChange)
120 EVT_TEXT(NetAddr4_Event, OpenDialog::OnNetPanelChange)
121 EVT_CHECKBOX(NetForceIPv6_Event, OpenDialog::OnNetPanelChange)
124 /* Events generated by the v4l panel */
125 EVT_RADIOBOX(VideoType_Event, OpenDialog::OnV4LTypeChange)
126 EVT_TEXT(VideoDevice_Event, OpenDialog::OnV4LPanelChange)
127 EVT_SPINCTRL(VideoChannel_Event, OpenDialog::OnV4LPanelChange)
128 EVT_BUTTON(V4LSettings_Event, OpenDialog::OnV4LSettingsChange)
131 /* Events generated by the subtitle file buttons */
132 EVT_CHECKBOX(SubsFileEnable_Event, OpenDialog::OnSubsFileEnable)
133 EVT_BUTTON(SubsFileSettings_Event, OpenDialog::OnSubsFileSettings)
135 /* Events generated by the stream output buttons */
136 EVT_CHECKBOX(SoutEnable_Event, OpenDialog::OnSoutEnable)
137 EVT_BUTTON(SoutSettings_Event, OpenDialog::OnSoutSettings)
139 /* Hide the window when the user closes the window */
140 EVT_CLOSE(OpenDialog::OnCancel)
144 /*****************************************************************************
146 *****************************************************************************/
147 WX_DEFINE_ARRAY(ConfigControl *, ArrayOfConfigControls);
149 class AutoBuiltPanel : public wxPanel
154 AutoBuiltPanel( wxWindow *, OpenDialog *, intf_thread_t *,
157 virtual ~AutoBuiltPanel() {}
160 ArrayOfConfigControls config_array;
163 intf_thread_t *p_intf;
166 void AutoBuildCallback( void *p_data )
168 ((OpenDialog *)p_data)->UpdateMRL();
171 AutoBuiltPanel::AutoBuiltPanel( wxWindow *parent, OpenDialog *dialog,
172 intf_thread_t *_p_intf,
173 const module_t *p_module )
174 : wxPanel( parent, -1, wxDefaultPosition, wxSize(200, 200) ),
175 name( wxU(p_module->psz_object_name) ), p_intf( _p_intf )
177 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
179 module_config_t *p_item = p_module->p_config;
183 if( p_item->i_type & CONFIG_HINT || p_item->b_advanced )
186 ConfigControl *control =
187 CreateConfigControl( VLC_OBJECT(p_intf), p_item, this );
189 config_array.Add( control );
191 /* Don't add items that were not recognized */
192 if( control == NULL ) continue;
194 control->SetUpdateCallback( AutoBuildCallback, (void *)dialog );
196 sizer->Add( control, 0, wxEXPAND | wxALL, 2 );
198 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
200 this->SetSizerAndFit( sizer );
203 /*****************************************************************************
205 *****************************************************************************/
206 OpenDialog::OpenDialog( intf_thread_t *_p_intf, wxWindow *_p_parent,
207 int i_access_method, int i_arg ):
208 wxFrame( _p_parent, -1, wxU(_("Open...")), wxDefaultPosition,
209 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
211 OpenDialog( _p_intf, _p_parent, i_access_method, i_arg, OPEN_NORMAL );
214 OpenDialog::OpenDialog( intf_thread_t *_p_intf, wxWindow *_p_parent,
215 int i_access_method, int i_arg, int _i_method ):
216 wxFrame( _p_parent, -1, wxU(_("Open...")), wxDefaultPosition,
217 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
219 /* Initializations */
220 i_method = _i_method;
222 p_parent = _p_parent;
223 SetIcon( *p_intf->p_sys->p_icon );
225 i_disc_type_selection = 0;
232 subsfile_dialog = NULL;
233 b_disc_device_changed = false;
235 /* Create a panel to put everything in */
236 wxPanel *panel = new wxPanel( this, -1 );
237 panel->SetAutoLayout( TRUE );
239 /* Create MRL combobox */
240 wxBoxSizer *mrl_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
241 wxStaticBox *mrl_box = new wxStaticBox( panel, -1,
242 wxU(_("Media Resource Locator (MRL)")) );
243 wxStaticBoxSizer *mrl_sizer = new wxStaticBoxSizer( mrl_box,
245 wxStaticText *mrl_label = new wxStaticText( panel, -1,
247 mrl_combo = new wxComboBox( panel, MRL_Event, wxT(""),
248 wxPoint(20,25), wxSize(120, -1),
250 mrl_combo->SetToolTip( wxU(_("You can use this field directly by typing "
251 "the full MRL you want to open.\n""Alternatively, the field will be "
252 "filled automatically when you use the controls below.")) );
254 mrl_sizer->Add( mrl_label, 0, wxALL | wxALIGN_CENTER, 5 );
255 mrl_sizer->Add( mrl_combo, 1, wxALL | wxALIGN_CENTER, 5 );
256 mrl_sizer_sizer->Add( mrl_sizer, 1, wxEXPAND | wxALL, 5 );
259 /* Create Static Text */
260 wxStaticText *label = new wxStaticText( panel, -1,
261 wxU(_("Alternatively, you can build an MRL using one of the "
262 "following predefined targets:")) );
264 wxFlexGridSizer *sout_sizer = NULL;
265 wxStaticLine *static_line = NULL;
267 if( i_method == OPEN_NORMAL )
269 /* Create Stream Output checkox */
270 sout_sizer = new wxFlexGridSizer( 2, 1, 20 );
273 sout_checkbox = new wxCheckBox( panel, SoutEnable_Event,
274 wxU(_("Stream output")) );
275 sout_checkbox->SetToolTip( wxU(_("Use VLC as a server of streams")) );
276 sout_sizer->Add( sout_checkbox, 0,
277 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
278 sout_button = new wxButton( panel, SoutSettings_Event,
279 wxU(_("Settings...")) );
280 sout_button->Disable();
282 char *psz_sout = config_GetPsz( p_intf, "sout" );
283 if( psz_sout && *psz_sout )
285 sout_checkbox->SetValue(TRUE);
286 sout_button->Enable();
287 subsfile_mrl.Add( wxString(wxT("sout=")) + wxL2U(psz_sout) );
289 if( psz_sout ) free( psz_sout );
291 sout_sizer->Add( sout_button, 1, wxALIGN_LEFT |
292 wxALIGN_CENTER_VERTICAL );
295 static_line = new wxStaticLine( panel, wxID_OK );
298 /* Create the buttons */
299 wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
300 ok_button->SetDefault();
301 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
304 /* Create notebook */
305 notebook = new wxNotebook( panel, Notebook_Event );
306 wxNotebookSizer *notebook_sizer = new wxNotebookSizer( notebook );
308 notebook->AddPage( FilePanel( notebook ), wxU(_("File")),
309 i_access_method == FILE_ACCESS );
310 notebook->AddPage( DiscPanel( notebook ), wxU(_("Disc")),
311 i_access_method == DISC_ACCESS );
312 notebook->AddPage( NetPanel( notebook ), wxU(_("Network")),
313 i_access_method == NET_ACCESS );
315 notebook->AddPage( V4LPanel( notebook ), wxU(_("Video for Linux")),
316 i_access_method == V4L_ACCESS );
319 module_t *p_module = config_FindModule( VLC_OBJECT(p_intf), "dshow" );
322 AutoBuiltPanel *autopanel =
323 new AutoBuiltPanel( notebook, this, p_intf, p_module );
324 input_tab_array.Add( autopanel );
325 notebook->AddPage( autopanel, wxU( p_module->psz_longname ) );
328 /* Update Disc panel */
329 wxCommandEvent dummy_event;
330 OnDiscTypeChange( dummy_event );
332 /* Update Net panel */
333 dummy_event.SetId( NetRadio1_Event );
334 OnNetTypeChange( dummy_event );
337 /* Update v4l panel */
338 dummy_event.SetId( VideoType_Event );
339 OnV4LTypeChange( dummy_event );
343 wxNotebookEvent event( wxEVT_NULL, 0, i_access_method );
344 OnPageChange( event );
346 /* Place everything in sizers */
347 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
348 button_sizer->Add( ok_button, 0, wxALL, 5 );
349 button_sizer->Add( cancel_button, 0, wxALL, 5 );
350 button_sizer->Layout();
351 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
352 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
353 panel_sizer->Add( mrl_sizer_sizer, 0, wxEXPAND, 5 );
354 panel_sizer->Add( label, 0, wxEXPAND | wxALL, 5 );
355 panel_sizer->Add( notebook_sizer, 1, wxEXPAND | wxALL, 5 );
356 if( i_method == OPEN_NORMAL)
358 panel_sizer->Add( sout_sizer, 0, wxALIGN_LEFT | wxALL, 5 );
359 panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
361 panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALL, 5 );
362 panel_sizer->Layout();
363 panel->SetSizerAndFit( panel_sizer );
364 main_sizer->Add( panel, 1, wxGROW, 0 );
365 main_sizer->Layout();
366 SetSizerAndFit( main_sizer );
369 OpenDialog::~OpenDialog()
372 if( file_dialog ) delete file_dialog;
374 if( v4l_dialog ) delete v4l_dialog;
376 if( sout_dialog ) delete sout_dialog;
377 if( subsfile_dialog ) delete subsfile_dialog;
380 int OpenDialog::Show( int i_access_method, int i_arg )
383 notebook->SetSelection( i_access_method );
384 i_ret = wxFrame::Show();
391 int OpenDialog::Show()
394 i_ret = wxFrame::Show();
400 /*****************************************************************************
402 *****************************************************************************/
403 wxPanel *OpenDialog::FilePanel( wxWindow* parent )
405 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
408 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
410 /* Create browse file line */
411 wxBoxSizer *file_sizer = new wxBoxSizer( wxHORIZONTAL );
413 file_combo = new wxComboBox( panel, FileName_Event, wxT(""),
414 wxPoint(20,25), wxSize(200, -1), 0, NULL );
415 wxButton *browse_button = new wxButton( panel, FileBrowse_Event,
416 wxU(_("Browse...")) );
417 file_sizer->Add( file_combo, 1, wxALL, 5 );
418 file_sizer->Add( browse_button, 0, wxALL, 5 );
420 /* Create Subtitles File checkox */
421 wxFlexGridSizer *subsfile_sizer = new wxFlexGridSizer( 2, 1, 20 );
422 subsfile_checkbox = new wxCheckBox( panel, SubsFileEnable_Event,
423 wxU(_("Subtitle options")) );
424 subsfile_checkbox->SetToolTip( wxU(_("Force options for separate subtitle files.")) );
425 subsfile_sizer->Add( subsfile_checkbox, 0,
426 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
427 subsfile_button = new wxButton( panel, SubsFileSettings_Event,
428 wxU(_("Settings...")) );
429 subsfile_button->Disable();
431 char *psz_subsfile = config_GetPsz( p_intf, "sub-file" );
432 if( psz_subsfile && *psz_subsfile )
434 subsfile_checkbox->SetValue(TRUE);
435 subsfile_button->Enable();
436 subsfile_mrl.Add( wxString(wxT("sub-file=")) + wxL2U(psz_subsfile) );
438 if( psz_subsfile ) free( psz_subsfile );
440 subsfile_sizer->Add( subsfile_button, 1,
441 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
443 sizer->Add( file_sizer, 0, wxEXPAND | wxALL, 5 );
444 sizer->Add( subsfile_sizer, 0, wxEXPAND | wxALL, 5 );
445 panel->SetSizerAndFit( sizer );
449 wxPanel *OpenDialog::DiscPanel( wxWindow* parent )
451 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
454 wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
455 wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 3, 20 );
457 static const wxString disc_type_array[] =
459 wxU(_("DVD (menus support)")),
466 disc_type = new wxRadioBox( panel, DiscType_Event, wxU(_("Disc type")),
467 wxDefaultPosition, wxDefaultSize,
468 WXSIZEOF(disc_type_array), disc_type_array,
469 WXSIZEOF(disc_type_array), wxRA_SPECIFY_COLS );
471 sizer_row->Add( disc_type, i_disc_type_selection, wxEXPAND | wxALL, 5 );
473 wxStaticText *label = new wxStaticText( panel, -1, wxU(_("Device name")) );
474 disc_device = new wxTextCtrl( panel, DiscDevice_Event, wxT(""),
475 wxDefaultPosition, wxDefaultSize,
478 sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
479 sizer->Add( disc_device, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
481 disc_title_label = new wxStaticText( panel, -1, wxU(_("Title")) );
482 disc_title = new wxSpinCtrl( panel, DiscTitle_Event );
484 sizer->Add( disc_title_label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
485 sizer->Add( disc_title, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
487 disc_chapter_label = new wxStaticText( panel, -1, wxU(_("Chapter")) );
488 disc_chapter = new wxSpinCtrl( panel, DiscChapter_Event );
489 sizer->Add( disc_chapter_label, 0,
490 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
491 sizer->Add( disc_chapter, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
492 sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
494 panel->SetSizerAndFit( sizer_row );
498 wxPanel *OpenDialog::NetPanel( wxWindow* parent )
501 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
504 wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
505 wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 4, 20 );
507 static const wxString net_type_array[] =
510 wxU(_("UDP/RTP Multicast")),
511 wxU(_("HTTP/FTP/MMS")),
517 net_radios[i] = new wxRadioButton( panel, NetRadio1_Event + i,
519 wxDefaultPosition, wxDefaultSize,
522 net_subpanels[i] = new wxPanel( panel, -1,
523 wxDefaultPosition, wxDefaultSize );
527 wxFlexGridSizer *subpanel_sizer;
529 i_net_ports[0] = config_GetInt( p_intf, "server-port" );
530 subpanel_sizer = new wxFlexGridSizer( 3, 1, 20 );
531 label = new wxStaticText( net_subpanels[0], -1, wxU(_("Port")) );
532 net_ports[0] = new wxSpinCtrl( net_subpanels[0], NetPort1_Event,
533 wxString::Format(wxT("%d"), i_net_ports[0]),
534 wxDefaultPosition, wxDefaultSize,
536 0, 16000, i_net_ports[0] );
538 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
539 subpanel_sizer->Add( net_ports[0], 1,
540 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
541 net_ipv6 = new wxCheckBox( net_subpanels[0], NetForceIPv6_Event,
542 wxU(_("Force IPv6")));
543 subpanel_sizer->Add( net_ipv6, 0,
544 wxALIGN_RIGHT | 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 );
571 /* HTTP and RTSP rows */
574 subpanel_sizer = new wxFlexGridSizer( 2, 1, 20 );
575 label = new wxStaticText( net_subpanels[i], -1, wxU(_("URL")) );
576 net_addrs[i] = new wxTextCtrl( net_subpanels[i], NetAddr1_Event + i,
577 (i == 2) ? wxT("") : wxT("rtsp://"),
578 wxDefaultPosition, wxSize( 200, -1 ),
580 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
581 subpanel_sizer->Add( net_addrs[i], 1,
582 wxEXPAND | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
583 net_subpanels[i]->SetSizerAndFit( subpanel_sizer );
586 /* Stuff everything into the main panel */
589 sizer->Add( net_radios[i], 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
591 sizer->Add( net_subpanels[i], 1, wxEXPAND | wxALIGN_LEFT |
592 wxALIGN_CENTER_VERTICAL | wxALL, 5 );
595 sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
597 panel->SetSizerAndFit( sizer_row );
602 wxPanel *OpenDialog::V4LPanel( wxWindow* parent )
604 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
607 wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
608 wxFlexGridSizer *sizer = new wxFlexGridSizer( 1, 4, 20 );
610 static const wxString video_type_array[] =
618 video_type = new wxRadioBox( panel, VideoType_Event,
619 wxU(_("Video device type")),
620 wxDefaultPosition, wxDefaultSize,
621 WXSIZEOF(video_type_array), video_type_array,
622 WXSIZEOF(video_type_array), wxRA_SPECIFY_COLS );
624 sizer_row->Add( video_type, 0, wxEXPAND | wxALL, 5 );
628 wxFlexGridSizer *video_sizer = new wxFlexGridSizer( 4, 2, 20 );
629 wxStaticText *label = new wxStaticText( panel, -1, wxU(_("Video device")) );
630 video_device = new wxTextCtrl( panel, VideoDevice_Event, wxT(""),
631 wxDefaultPosition, wxDefaultSize,
633 video_device->SetToolTip( wxU(_("Device corresponding to your acquisition "
634 "card or your webcam")) );
635 video_sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
636 video_sizer->Add( video_device, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
638 label = new wxStaticText( panel, -1, wxU(_("Channel")) );
639 video_channel = new wxSpinCtrl( panel, VideoChannel_Event, wxT("0") );
640 video_channel->SetToolTip( wxU(_("Usually 0 is for tuner, 1 for composite "
641 "and 2 for svideo")) );
642 video_sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_HORIZONTAL );
643 video_sizer->Add( video_channel, 1, wxALIGN_LEFT | wxALIGN_CENTER_HORIZONTAL );
644 sizer->Add( video_sizer, 0, wxEXPAND | wxALL, 5 );
646 wxBoxSizer *v4lbutton_sizer = new wxBoxSizer( wxHORIZONTAL );
647 v4l_button = new wxButton( panel, V4LSettings_Event,
648 wxU(_("Advanced settings...")) );
650 v4lbutton_sizer->Add( v4l_button, 0, wxALIGN_RIGHT, 5 );
652 sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
653 sizer_row->Add( v4lbutton_sizer, 0, wxEXPAND | wxALL, 5 );
655 panel->SetSizerAndFit( sizer_row );
660 void OpenDialog::UpdateMRL()
662 UpdateMRL( i_current_access_method );
665 void OpenDialog::UpdateMRL( int i_access_method )
667 wxString demux, mrltemp;
669 i_current_access_method = i_access_method;
671 switch( i_access_method )
674 //mrltemp = wxT("file") + demux + wxT(":") + file_combo->GetValue();
675 mrltemp = file_combo->GetValue();
678 i_disc_type_selection = disc_type->GetSelection();
680 switch ( i_disc_type_selection )
682 case 0: /* DVD with menues */
683 disc_chapter->Enable();
684 disc_chapter_label->Enable();
685 mrltemp = wxT("dvd://")
686 + disc_device->GetValue()
687 + wxString::Format( wxT("@%d:%d"),
688 disc_title->GetValue(),
689 disc_chapter->GetValue() );
692 case 1: /* DVD of some sort */
693 disc_chapter->Enable();
694 disc_chapter_label->Enable();
695 mrltemp = wxT("dvdsimple://")
696 + disc_device->GetValue()
697 + wxString::Format( wxT("@%d:%d"),
698 disc_title->GetValue(),
699 disc_chapter->GetValue() );
702 case 2: /* VCD of some sort */
704 /* The chapter object is used for subtitles */
706 int i_subtitle = disc_chapter->GetValue();
707 config_PutInt( p_intf, "spu-channel", i_subtitle );
709 disc_chapter->Enable();
710 disc_chapter_label->Enable();
712 if ( disc_title->GetValue() )
713 mrltemp = wxT("vcdx://")
714 + disc_device->GetValue()
715 + wxString::Format( wxT("@%c%d"),
716 config_GetInt( p_intf, "vcdx-PBC" )
718 disc_title->GetValue()
721 mrltemp = wxT("vcdx://")
722 + disc_device->GetValue();
724 mrltemp = wxT("vcd://")
725 + disc_device->GetValue()
726 + wxString::Format( wxT("@%d"),
727 disc_title->GetValue() );
734 disc_chapter->Disable();
735 disc_chapter_label->Disable();
737 if ( disc_title->GetValue() )
738 mrltemp = wxT("cddax://")
739 + disc_device->GetValue()
740 + wxString::Format( wxT("@T%d"),
741 disc_title->GetValue() );
743 mrltemp = wxT("cddax://")
744 + disc_device->GetValue();
747 mrltemp = wxT("cdda://")
748 + disc_device->GetValue()
749 + wxString::Format( wxT("@%d"),
750 disc_title->GetValue() );
754 msg_Err( p_intf, "invalid selection (%d)",
755 disc_type->GetSelection() );
763 mrltemp = wxT("udp") + demux + wxT("://");
764 if ( net_ipv6->GetValue() )
766 mrltemp += wxT("@[::]");
768 if( i_net_ports[0] !=
769 config_GetInt( p_intf, "server-port" ) )
771 mrltemp += wxString::Format( wxT("@:%d"), i_net_ports[0] );
776 mrltemp = wxT("udp") + demux + wxT("://@");
777 if ((net_addrs[1]->GetLineText(0).Find (':') != -1)
778 && (net_addrs[1]->GetLineText(0)[0u] != '['))
780 /* automatically adds '[' and ']' to IPv6 addresses */
781 mrltemp += wxT("[") + net_addrs[1]->GetLineText(0)
786 mrltemp += net_addrs[1]->GetLineText(0);
788 if( i_net_ports[1] != config_GetInt( p_intf, "server-port" ) )
790 mrltemp += wxString::Format( wxT(":%d"), i_net_ports[1] );
796 if( net_addrs[2]->GetLineText(0).Find(wxT("http://")) )
798 mrltemp = wxT("http") + demux + wxT("://");
800 mrltemp += net_addrs[2]->GetLineText(0);
805 if( net_addrs[3]->GetLineText(0).Find(wxT("rtsp://")) != 0 )
807 mrltemp = wxT("rtsp") + demux + wxT("://");
809 mrltemp += net_addrs[3]->GetLineText(0);
816 mrltemp = ( video_type->GetSelection() == 0 ? wxT("v4l") :
817 video_type->GetSelection() == 1 ? wxT("v4l") :
818 video_type->GetSelection() == 2 ? wxT("pvr") :
821 + video_device->GetLineText( 0 );
823 if( video_type->GetSelection() == 1 )
825 mrltemp += wxString::Format( wxT(":channel=%d"),
826 video_channel->GetValue() );
829 if ( /* v4l_dialog != NULL && */ !v4l_mrl.IsEmpty() )
831 mrltemp += v4l_mrl[0];
839 int i_item = i_access_method - MAX_ACCESS;
841 if( i_item < 0 || i_item >= (int)input_tab_array.GetCount() )
844 AutoBuiltPanel *input_panel = input_tab_array.Item( i_item );
846 mrltemp = input_panel->name + wxT("://");
848 for( int i=0; i < (int)input_panel->config_array.GetCount(); i++ )
850 ConfigControl *control = input_panel->config_array.Item(i);
851 mrltemp += wxT(" :") + control->GetName() + wxT("=");
853 switch( control->GetType() )
855 case CONFIG_ITEM_STRING:
856 case CONFIG_ITEM_FILE:
857 case CONFIG_ITEM_DIRECTORY:
858 case CONFIG_ITEM_MODULE:
859 mrltemp += wxT("\"") + control->GetPszValue() + wxT("\"");
861 case CONFIG_ITEM_INTEGER:
862 case CONFIG_ITEM_BOOL:
864 wxString::Format( wxT("%i"), control->GetIntValue() );
866 case CONFIG_ITEM_FLOAT:
868 wxString::Format( wxT("%f"), control->GetFloatValue());
876 mrl_combo->SetValue( mrltemp );
879 /*****************************************************************************
881 *****************************************************************************/
882 void OpenDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
884 mrl = SeparateEntries( mrl_combo->GetValue() );
885 mrl_combo->Append( mrl_combo->GetValue() );
886 if( mrl_combo->GetCount() > 10 ) mrl_combo->Delete( 0 );
887 mrl_combo->SetSelection( mrl_combo->GetCount() - 1 );
889 if( i_method == OPEN_STREAM )
895 /* Update the playlist */
896 playlist_t *p_playlist =
897 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
899 if( p_playlist == NULL ) return;
901 for( int i = 0; i < (int)mrl.GetCount(); i++ )
903 vlc_bool_t b_start = !i && i_open_arg;
904 playlist_item_t *p_item =
905 playlist_ItemNew( p_intf, (const char*)mrl[i].mb_str(),
906 (const char *)mrl[i].mb_str() );
909 while( i + 1 < (int)mrl.GetCount() &&
910 ((const char *)mrl[i + 1].mb_str())[0] == ':' )
912 playlist_ItemAddOption( p_item, mrl[i + 1].mb_str() );
916 /* Get the options from the subtitles dialog */
917 if( subsfile_checkbox->IsChecked() && subsfile_mrl.GetCount() )
919 for( int j = 0; j < (int)subsfile_mrl.GetCount(); j++ )
921 playlist_ItemAddOption( p_item, subsfile_mrl[j].mb_str() );
925 /* Get the options from the stream output dialog */
926 if( sout_checkbox->IsChecked() && sout_mrl.GetCount() )
928 for( int j = 0; j < (int)sout_mrl.GetCount(); j++ )
930 playlist_ItemAddOption( p_item, sout_mrl[j].mb_str() );
934 int i_id = playlist_AddItem( p_playlist, p_item,
935 PLAYLIST_APPEND, PLAYLIST_END );
939 int i_pos = playlist_GetPositionById( p_playlist , i_id );
940 playlist_Command( p_playlist, PLAYLIST_GOTO, i_pos );
944 //TogglePlayButton( PLAYING_S );
946 vlc_object_release( p_playlist );
951 void OpenDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
956 void OpenDialog::OnPageChange( wxNotebookEvent& event )
958 UpdateMRL( event.GetSelection() );
961 void OpenDialog::OnMRLChange( wxCommandEvent& event )
963 //mrl = SeparateEntries( event.GetString() );
966 /*****************************************************************************
967 * File panel event methods.
968 *****************************************************************************/
969 void OpenDialog::OnFilePanelChange( wxCommandEvent& WXUNUSED(event) )
971 UpdateMRL( FILE_ACCESS );
974 void OpenDialog::OnFileBrowse( wxCommandEvent& WXUNUSED(event) )
976 if( file_dialog == NULL )
977 file_dialog = new wxFileDialog( this, wxU(_("Open File")),
978 wxT(""), wxT(""), wxT("*"), wxOPEN | wxMULTIPLE );
980 if( file_dialog && file_dialog->ShowModal() == wxID_OK )
985 file_dialog->GetPaths( paths );
987 for( size_t i = 0; i < paths.GetCount(); i++ )
989 if( paths[i].Find( wxT(' ') ) >= 0 )
990 path += wxT("\"") + paths[i] + wxT("\" ");
992 path += paths[i] + wxT(" ");
995 file_combo->SetValue( path );
996 file_combo->Append( path );
997 if( file_combo->GetCount() > 10 ) file_combo->Delete( 0 );
998 UpdateMRL( FILE_ACCESS );
1002 /*****************************************************************************
1003 * Disc panel event methods.
1004 *****************************************************************************/
1005 void OpenDialog::OnDiscPanelChange( wxCommandEvent& event )
1007 UpdateMRL( DISC_ACCESS );
1010 void OpenDialog::OnDiscDeviceChange( wxCommandEvent& event )
1014 switch( disc_type->GetSelection() )
1017 psz_device = config_GetPsz( p_intf, "cd-audio" );
1021 psz_device = config_GetPsz( p_intf, "vcd" );
1025 psz_device = config_GetPsz( p_intf, "dvd" );
1029 if ( !psz_device ) psz_device = "";
1031 if( disc_device->GetValue().Cmp( wxL2U( psz_device ) ) )
1033 b_disc_device_changed = true;
1036 UpdateMRL( DISC_ACCESS );
1039 void OpenDialog::OnDiscTypeChange( wxCommandEvent& WXUNUSED(event) )
1041 char *psz_device = NULL;
1042 int i_selection = 1; /* Default Title/Track selection number*/
1044 switch( disc_type->GetSelection() )
1047 case 0: /* DVD with menues */
1049 /* Fall through... */
1051 case 1: /* DVD of some sort */
1052 psz_device = config_GetPsz( p_intf, "dvd" );
1053 if( !b_disc_device_changed )
1056 disc_device->SetValue( wxL2U(psz_device) );
1058 disc_device->SetValue( wxT("") );
1060 disc_title_label->SetLabel ( wxU(_("Title")) );
1062 disc_title->SetRange( i_selection, 255 );
1063 disc_title->SetValue( i_selection );
1065 disc_chapter->SetRange( 1, 255 );
1066 disc_chapter->SetValue( 1 );
1067 disc_chapter_label->SetLabel ( wxU(_("Chapter")) );
1071 case 2: /* VCD of some sort */
1072 psz_device = config_GetPsz( p_intf, "vcd" );
1073 if( !b_disc_device_changed )
1076 disc_device->SetValue( wxL2U(psz_device) );
1078 disc_device->SetValue( wxT("") );
1081 /* There are at most 98, tracks in a VCD, 999 Segments, 500 entries
1082 I don't know what the limit is for LIDs, 999 is probably safe
1085 FIXME: it would be better however to get the information for
1086 this particular Media possibly from the General Info area.
1089 disc_title_label->SetLabel ( config_GetInt( p_intf, "vcdx-PBC" )
1090 ? wxT("Playback LID") : wxT("Entry") );
1091 disc_title->SetRange( 0, 999 );
1094 disc_title_label->SetLabel ( wxU(_("Track")) );
1095 disc_title->SetRange( 1, 98 );
1097 disc_title->SetValue( i_selection );
1099 /* We use the chapter to set subtitle number */
1100 disc_chapter_label->SetLabel ( wxU(_("Subtitle")) );
1101 disc_chapter->SetRange( -1, 4 );
1102 disc_chapter->SetValue( config_GetInt( p_intf, "spu-channel" ) );
1106 psz_device = config_GetPsz( p_intf, "cd-audio" );
1107 if( !b_disc_device_changed )
1110 disc_device->SetValue( wxL2U(psz_device) );
1112 disc_device->SetValue( wxT("") );
1114 disc_title_label->SetLabel ( wxU(_("Track")) );
1118 /* There are at most 99 tracks in a CD-DA */
1119 disc_title->SetRange( i_selection, 99 );
1120 disc_title->SetValue( i_selection );
1123 msg_Err( p_intf, "invalid Disc type selection (%d)",
1124 disc_type->GetSelection() );
1128 if( psz_device ) free( psz_device );
1130 UpdateMRL( DISC_ACCESS );
1133 /*****************************************************************************
1134 * Net panel event methods.
1135 *****************************************************************************/
1136 void OpenDialog::OnNetPanelChange( wxCommandEvent& event )
1138 if( event.GetId() >= NetPort1_Event && event.GetId() <= NetPort3_Event )
1140 i_net_ports[event.GetId() - NetPort1_Event] = event.GetInt();
1143 UpdateMRL( NET_ACCESS );
1146 void OpenDialog::OnNetTypeChange( wxCommandEvent& event )
1150 i_net_type = event.GetId() - NetRadio1_Event;
1154 net_radios[i]->SetValue( event.GetId() == (NetRadio1_Event+i) );
1155 net_subpanels[i]->Enable( event.GetId() == (NetRadio1_Event+i) );
1158 UpdateMRL( NET_ACCESS );
1162 /*****************************************************************************
1163 * v4l panel event methods.
1164 *****************************************************************************/
1165 void OpenDialog::OnV4LPanelChange( wxCommandEvent& WXUNUSED(event) )
1167 UpdateMRL( V4L_ACCESS );
1170 void OpenDialog::OnV4LTypeChange( wxCommandEvent& WXUNUSED(event) )
1172 video_device->SetValue( wxT( "/dev/video" ) );
1174 v4l_button->Enable();
1175 video_channel->Disable();
1177 switch( video_type->GetSelection() )
1180 video_channel->Enable();
1181 video_channel->SetRange( 0, 255 );
1184 v4l_button->Disable();
1190 UpdateMRL( V4L_ACCESS );
1193 void OpenDialog::OnV4LSettingsChange( wxCommandEvent& WXUNUSED(event) )
1195 /* Show/hide the open dialog */
1196 if( v4l_dialog == NULL )
1197 v4l_dialog = new V4LDialog( p_intf, this );
1199 if( v4l_dialog && v4l_dialog->ShowModal() == wxID_OK )
1201 v4l_mrl = v4l_dialog->GetOptions();
1204 UpdateMRL( V4L_ACCESS );
1208 /*****************************************************************************
1209 * Subtitles file event methods.
1210 *****************************************************************************/
1211 void OpenDialog::OnSubsFileEnable( wxCommandEvent& event )
1213 subsfile_button->Enable( event.GetInt() != 0 );
1216 void OpenDialog::OnSubsFileSettings( wxCommandEvent& WXUNUSED(event) )
1218 /* Show/hide the open dialog */
1219 if( subsfile_dialog == NULL )
1220 subsfile_dialog = new SubsFileDialog( p_intf, this );
1222 if( subsfile_dialog && subsfile_dialog->ShowModal() == wxID_OK )
1224 subsfile_mrl.Empty();
1225 subsfile_mrl.Add( wxString(wxT("sub-file=")) +
1226 subsfile_dialog->file_combo->GetValue() );
1227 if( subsfile_dialog->encoding_combo )
1228 subsfile_mrl.Add( wxString(wxT("subsdec-encoding=")) +
1229 subsfile_dialog->encoding_combo->GetValue() );
1230 subsfile_mrl.Add( wxString::Format( wxT("sub-delay=%i"),
1231 subsfile_dialog->delay_spinctrl->GetValue() ) );
1232 subsfile_mrl.Add( wxString::Format( wxT("sub-fps=%i"),
1233 subsfile_dialog->fps_spinctrl->GetValue() ) );
1237 /*****************************************************************************
1238 * Stream output event methods.
1239 *****************************************************************************/
1240 void OpenDialog::OnSoutEnable( wxCommandEvent& event )
1242 sout_button->Enable( event.GetInt() != 0 );
1245 void OpenDialog::OnSoutSettings( wxCommandEvent& WXUNUSED(event) )
1247 /* Show/hide the open dialog */
1248 if( sout_dialog == NULL )
1249 sout_dialog = new SoutDialog( p_intf, this );
1251 if( sout_dialog && sout_dialog->ShowModal() == wxID_OK )
1253 sout_mrl = sout_dialog->GetOptions();
1257 /*****************************************************************************
1258 * Utility functions.
1259 *****************************************************************************/
1260 wxArrayString SeparateEntries( wxString entries )
1262 vlc_bool_t b_quotes_mode = VLC_FALSE;
1264 wxArrayString entries_array;
1267 wxStringTokenizer token( entries, wxT(" \t\r\n\""), wxTOKEN_RET_DELIMS );
1269 while( token.HasMoreTokens() )
1271 entry += token.GetNextToken();
1273 if( entry.IsEmpty() ) continue;
1275 if( !b_quotes_mode && entry.Last() == wxT('\"') )
1277 /* Enters quotes mode */
1279 b_quotes_mode = VLC_TRUE;
1281 else if( b_quotes_mode && entry.Last() == wxT('\"') )
1283 /* Finished the quotes mode */
1285 if( !entry.IsEmpty() ) entries_array.Add( entry );
1287 b_quotes_mode = VLC_FALSE;
1289 else if( !b_quotes_mode && entry.Last() != wxT('\"') )
1291 /* we found a non-quoted standalone string */
1292 if( token.HasMoreTokens() ||
1293 entry.Last() == wxT(' ') || entry.Last() == wxT('\t') ||
1294 entry.Last() == wxT('\r') || entry.Last() == wxT('\n') )
1296 if( !entry.IsEmpty() ) entries_array.Add( entry );
1303 if( !entry.IsEmpty() ) entries_array.Add( entry );
1305 return entries_array;