1 /*****************************************************************************
2 * open.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: open.cpp,v 1.45 2003/11/27 06:37:10 adn 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::OnDiscPanelChange)
114 EVT_TEXT(DiscTitle_Event, OpenDialog::OnDiscPanelChange)
115 EVT_SPINCTRL(DiscTitle_Event, OpenDialog::OnDiscPanelChange)
116 EVT_TEXT(DiscChapter_Event, OpenDialog::OnDiscPanelChange)
117 EVT_SPINCTRL(DiscChapter_Event, OpenDialog::OnDiscPanelChange)
119 /* Events generated by the net panel */
120 EVT_RADIOBUTTON(NetRadio1_Event, OpenDialog::OnNetTypeChange)
121 EVT_RADIOBUTTON(NetRadio2_Event, OpenDialog::OnNetTypeChange)
122 EVT_RADIOBUTTON(NetRadio3_Event, OpenDialog::OnNetTypeChange)
123 EVT_TEXT(NetPort1_Event, OpenDialog::OnNetPanelChange)
124 EVT_SPINCTRL(NetPort1_Event, OpenDialog::OnNetPanelChange)
125 EVT_TEXT(NetPort2_Event, OpenDialog::OnNetPanelChange)
126 EVT_SPINCTRL(NetPort2_Event, OpenDialog::OnNetPanelChange)
127 EVT_TEXT(NetPort3_Event, OpenDialog::OnNetPanelChange)
128 EVT_SPINCTRL(NetPort3_Event, OpenDialog::OnNetPanelChange)
129 EVT_TEXT(NetAddr2_Event, OpenDialog::OnNetPanelChange)
130 EVT_TEXT(NetAddr3_Event, OpenDialog::OnNetPanelChange)
133 /* Events generated by the v4l panel */
134 EVT_RADIOBOX(VideoType_Event, OpenDialog::OnV4LTypeChange)
135 EVT_TEXT(VideoDevice_Event, OpenDialog::OnV4LPanelChange)
136 EVT_SPINCTRL(VideoChannel_Event, OpenDialog::OnV4LPanelChange)
137 EVT_BUTTON(V4LSettings_Event, OpenDialog::OnV4LSettingsChange)
140 /* Events generated by the subtitle file buttons */
141 EVT_CHECKBOX(SubsFileEnable_Event, OpenDialog::OnSubsFileEnable)
142 EVT_BUTTON(SubsFileSettings_Event, OpenDialog::OnSubsFileSettings)
144 /* Events generated by the stream output buttons */
145 EVT_CHECKBOX(SoutEnable_Event, OpenDialog::OnSoutEnable)
146 EVT_BUTTON(SoutSettings_Event, OpenDialog::OnSoutSettings)
148 /* Hide the window when the user closes the window */
149 EVT_CLOSE(OpenDialog::OnCancel)
153 /*****************************************************************************
155 *****************************************************************************/
156 WX_DEFINE_ARRAY(ConfigControl *, ArrayOfConfigControls);
158 class AutoBuiltPanel : public wxPanel
163 AutoBuiltPanel( wxWindow *, OpenDialog *, intf_thread_t *,
166 virtual ~AutoBuiltPanel() {}
169 ArrayOfConfigControls config_array;
172 intf_thread_t *p_intf;
175 void AutoBuildCallback( void *p_data )
177 ((OpenDialog *)p_data)->UpdateMRL();
180 AutoBuiltPanel::AutoBuiltPanel( wxWindow *parent, OpenDialog *dialog,
181 intf_thread_t *_p_intf,
182 const module_t *p_module )
183 : wxPanel( parent, -1, wxDefaultPosition, wxSize(200, 200) ),
184 name( wxU(p_module->psz_object_name) ), p_intf( _p_intf )
186 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
188 module_config_t *p_item = p_module->p_config;
192 if( p_item->i_type & CONFIG_HINT || p_item->b_advanced )
195 ConfigControl *control =
196 CreateConfigControl( VLC_OBJECT(p_intf), p_item, this );
198 config_array.Add( control );
200 /* Don't add items that were not recognized */
201 if( control == NULL ) continue;
203 control->SetUpdateCallback( AutoBuildCallback, (void *)dialog );
205 sizer->Add( control, 0, wxEXPAND | wxALL, 2 );
207 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
209 this->SetSizerAndFit( sizer );
212 /*****************************************************************************
214 *****************************************************************************/
215 OpenDialog::OpenDialog( intf_thread_t *_p_intf, wxWindow *_p_parent,
216 int i_access_method, int i_arg ):
217 wxFrame( _p_parent, -1, wxU(_("Open Target")), wxDefaultPosition,
218 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
220 OpenDialog( _p_intf, _p_parent, i_access_method, i_arg, OPEN_NORMAL );
223 OpenDialog::OpenDialog( intf_thread_t *_p_intf, wxWindow *_p_parent,
224 int i_access_method, int i_arg, int _i_method ):
225 wxFrame( _p_parent, -1, wxU(_("Open Target")), wxDefaultPosition,
226 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
228 /* Initializations */
229 i_method = _i_method;
231 p_parent = _p_parent;
232 SetIcon( *p_intf->p_sys->p_icon );
238 subsfile_dialog = NULL;
240 /* Create a panel to put everything in */
241 wxPanel *panel = new wxPanel( this, -1 );
242 panel->SetAutoLayout( TRUE );
244 /* Create MRL combobox */
245 wxBoxSizer *mrl_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
246 wxStaticBox *mrl_box = new wxStaticBox( panel, -1,
247 wxU(_("Media Resource Locator (MRL)")) );
248 wxStaticBoxSizer *mrl_sizer = new wxStaticBoxSizer( mrl_box,
250 wxStaticText *mrl_label = new wxStaticText( panel, -1,
251 wxU(_("Open Target:")) );
252 mrl_combo = new wxComboBox( panel, MRL_Event, wxT(""),
253 wxPoint(20,25), wxSize(120, -1),
255 mrl_combo->SetToolTip( wxU(_("You can use this field directly by typing "
256 "the full MRL you want to open.\n""Alternatively, the field will be "
257 "filled automatically when you use the controls below.")) );
259 mrl_sizer->Add( mrl_label, 0, wxALL | wxALIGN_CENTER, 5 );
260 mrl_sizer->Add( mrl_combo, 1, wxALL | wxALIGN_CENTER, 5 );
261 mrl_sizer_sizer->Add( mrl_sizer, 1, wxEXPAND | wxALL, 5 );
264 /* Create Static Text */
265 wxStaticText *label = new wxStaticText( panel, -1,
266 wxU(_("Alternatively, you can build an MRL using one of the "
267 "following predefined targets:")) );
269 wxFlexGridSizer *sout_sizer = NULL;
270 wxStaticLine *static_line = NULL;
272 if( i_method == OPEN_NORMAL )
274 /* Create Stream Output checkox */
275 sout_sizer = new wxFlexGridSizer( 2, 1, 20 );
278 sout_checkbox = new wxCheckBox( panel, SoutEnable_Event,
279 wxU(_("Stream output")) );
280 sout_checkbox->SetToolTip( wxU(_("Use VLC as a stream server")) );
281 sout_sizer->Add( sout_checkbox, 0,
282 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
283 sout_button = new wxButton( panel, SoutSettings_Event,
284 wxU(_("Settings...")) );
285 sout_button->Disable();
287 char *psz_sout = config_GetPsz( p_intf, "sout" );
288 if( psz_sout && *psz_sout )
290 sout_checkbox->SetValue(TRUE);
291 sout_button->Enable();
292 subsfile_mrl.Add( wxString(wxT("sout=")) + wxU(psz_sout) );
294 if( psz_sout ) free( psz_sout );
296 sout_sizer->Add( sout_button, 1, wxALIGN_LEFT |
297 wxALIGN_CENTER_VERTICAL );
300 static_line = new wxStaticLine( panel, wxID_OK );
303 /* Create the buttons */
304 wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
305 ok_button->SetDefault();
306 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
309 /* Create notebook */
310 notebook = new wxNotebook( panel, Notebook_Event );
311 wxNotebookSizer *notebook_sizer = new wxNotebookSizer( notebook );
313 notebook->AddPage( FilePanel( notebook ), wxU(_("File")),
314 i_access_method == FILE_ACCESS );
315 notebook->AddPage( DiscPanel( notebook ), wxU(_("Disc")),
316 i_access_method == DISC_ACCESS );
317 notebook->AddPage( NetPanel( notebook ), wxU(_("Network")),
318 i_access_method == NET_ACCESS );
320 notebook->AddPage( V4LPanel( notebook ), wxU(_("Video For Linux")),
321 i_access_method == V4L_ACCESS );
324 module_t *p_module = config_FindModule( VLC_OBJECT(p_intf), "dshow" );
327 AutoBuiltPanel *autopanel =
328 new AutoBuiltPanel( notebook, this, p_intf, p_module );
329 input_tab_array.Add( autopanel );
330 notebook->AddPage( autopanel, wxU( p_module->psz_longname ) );
333 /* Update Disc panel */
334 wxCommandEvent dummy_event;
335 OnDiscTypeChange( dummy_event );
337 /* Update Net panel */
338 dummy_event.SetId( NetRadio1_Event );
339 OnNetTypeChange( dummy_event );
342 /* Update v4l panel */
343 dummy_event.SetId( VideoType_Event );
344 OnV4LTypeChange( dummy_event );
348 wxNotebookEvent event( wxEVT_NULL, 0, i_access_method );
349 OnPageChange( event );
351 /* Place everything in sizers */
352 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
353 button_sizer->Add( ok_button, 0, wxALL, 5 );
354 button_sizer->Add( cancel_button, 0, wxALL, 5 );
355 button_sizer->Layout();
356 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
357 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
358 panel_sizer->Add( mrl_sizer_sizer, 0, wxEXPAND, 5 );
359 panel_sizer->Add( label, 0, wxEXPAND | wxALL, 5 );
360 panel_sizer->Add( notebook_sizer, 1, wxEXPAND | wxALL, 5 );
361 if( i_method == OPEN_NORMAL)
363 panel_sizer->Add( sout_sizer, 0, wxALIGN_LEFT | wxALL, 5 );
364 panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
366 panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALL, 5 );
367 panel_sizer->Layout();
368 panel->SetSizerAndFit( panel_sizer );
369 main_sizer->Add( panel, 1, wxGROW, 0 );
370 main_sizer->Layout();
371 SetSizerAndFit( main_sizer );
374 OpenDialog::~OpenDialog()
377 if( file_dialog ) delete file_dialog;
379 if( v4l_dialog ) delete v4l_dialog;
381 if( sout_dialog ) delete sout_dialog;
382 if( subsfile_dialog ) delete subsfile_dialog;
385 int OpenDialog::Show( int i_access_method, int i_arg )
388 notebook->SetSelection( i_access_method );
389 i_ret = wxFrame::Show();
395 int OpenDialog::Show()
398 i_ret = wxFrame::Show();
404 /*****************************************************************************
406 *****************************************************************************/
407 wxPanel *OpenDialog::FilePanel( wxWindow* parent )
409 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
412 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
414 /* Create browse file line */
415 wxBoxSizer *file_sizer = new wxBoxSizer( wxHORIZONTAL );
417 file_combo = new wxComboBox( panel, FileName_Event, wxT(""),
418 wxPoint(20,25), wxSize(200, -1), 0, NULL );
419 wxButton *browse_button = new wxButton( panel, FileBrowse_Event,
420 wxU(_("Browse...")) );
421 file_sizer->Add( file_combo, 1, wxALL, 5 );
422 file_sizer->Add( browse_button, 0, wxALL, 5 );
424 /* Create Subtitles File checkox */
425 wxFlexGridSizer *subsfile_sizer = new wxFlexGridSizer( 2, 1, 20 );
426 subsfile_checkbox = new wxCheckBox( panel, SubsFileEnable_Event,
427 wxU(_("Subtitles file")) );
428 subsfile_checkbox->SetToolTip( wxU(_("Load an additional subtitles file. "
429 "Currently only works with AVI files.")) );
430 subsfile_sizer->Add( subsfile_checkbox, 0,
431 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
432 subsfile_button = new wxButton( panel, SubsFileSettings_Event,
433 wxU(_("Settings...")) );
434 subsfile_button->Disable();
436 char *psz_subsfile = config_GetPsz( p_intf, "sub-file" );
437 if( psz_subsfile && *psz_subsfile )
439 subsfile_checkbox->SetValue(TRUE);
440 subsfile_button->Enable();
441 subsfile_mrl.Add( wxString(wxT("sub-file=")) + wxU(psz_subsfile) );
443 if( psz_subsfile ) free( psz_subsfile );
445 subsfile_sizer->Add( subsfile_button, 1,
446 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
448 sizer->Add( file_sizer, 0, wxEXPAND | wxALL, 5 );
449 sizer->Add( subsfile_sizer, 0, wxEXPAND | wxALL, 5 );
450 panel->SetSizerAndFit( sizer );
454 wxPanel *OpenDialog::DiscPanel( wxWindow* parent )
456 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
459 wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
460 wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 3, 20 );
462 static const wxString disc_type_array[] =
464 wxU(_("DVD (menus support)")),
471 disc_type = new wxRadioBox( panel, DiscType_Event, wxU(_("Disc type")),
472 wxDefaultPosition, wxDefaultSize,
473 WXSIZEOF(disc_type_array), disc_type_array,
474 WXSIZEOF(disc_type_array), wxRA_SPECIFY_COLS );
475 sizer_row->Add( disc_type, 0, wxEXPAND | wxALL, 5 );
477 wxStaticText *label = new wxStaticText( panel, -1, wxU(_("Device name")) );
478 disc_device = new wxTextCtrl( panel, DiscDevice_Event, wxT(""),
479 wxDefaultPosition, wxDefaultSize,
482 sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
483 sizer->Add( disc_device, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
485 label = new wxStaticText( panel, -1, wxU(_("Title")) );
486 disc_title = new wxSpinCtrl( panel, DiscTitle_Event );
488 sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
489 sizer->Add( disc_title, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
491 label = new wxStaticText( panel, -1, wxU(_("Chapter")) );
492 disc_chapter = new wxSpinCtrl( panel, DiscChapter_Event );
493 sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
494 sizer->Add( disc_chapter, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
495 sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
497 panel->SetSizerAndFit( sizer_row );
501 wxPanel *OpenDialog::NetPanel( wxWindow* parent )
504 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
507 wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
508 wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 3, 20 );
510 static const wxString net_type_array[] =
513 wxU(_("UDP/RTP Multicast")),
514 wxU(_("HTTP/FTP/MMS"))
519 net_radios[i] = new wxRadioButton( panel, NetRadio1_Event + i,
521 wxDefaultPosition, wxDefaultSize,
524 net_subpanels[i] = new wxPanel( panel, -1,
525 wxDefaultPosition, wxDefaultSize );
529 wxFlexGridSizer *subpanel_sizer;
531 i_net_ports[0] = config_GetInt( p_intf, "server-port" );
532 subpanel_sizer = new wxFlexGridSizer( 2, 1, 20 );
533 label = new wxStaticText( net_subpanels[0], -1, wxU(_("Port")) );
534 net_ports[0] = new wxSpinCtrl( net_subpanels[0], NetPort1_Event,
535 wxString::Format(wxT("%d"), i_net_ports[0]),
536 wxDefaultPosition, wxDefaultSize,
538 0, 16000, i_net_ports[0] );
540 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
541 subpanel_sizer->Add( net_ports[0], 1,
542 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
543 net_subpanels[0]->SetSizerAndFit( subpanel_sizer );
544 net_radios[0]->SetValue( TRUE );
546 /* UDP/RTP Multicast row */
547 subpanel_sizer = new wxFlexGridSizer( 4, 1, 20 );
548 label = new wxStaticText( net_subpanels[1], -1, wxU(_("Address")) );
549 net_addrs[1] = new wxTextCtrl( net_subpanels[1], NetAddr2_Event, wxT(""),
550 wxDefaultPosition, wxDefaultSize,
552 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
553 subpanel_sizer->Add( net_addrs[1], 1,
554 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
556 label = new wxStaticText( net_subpanels[1], -1, wxU(_("Port")) );
557 i_net_ports[1] = i_net_ports[0];
558 net_ports[1] = new wxSpinCtrl( net_subpanels[1], NetPort2_Event,
559 wxString::Format(wxT("%d"), i_net_ports[1]),
560 wxDefaultPosition, wxDefaultSize,
562 0, 16000, i_net_ports[1] );
564 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
565 subpanel_sizer->Add( net_ports[1], 1,
566 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
567 net_subpanels[1]->SetSizerAndFit( subpanel_sizer );
570 subpanel_sizer = new wxFlexGridSizer( 2, 1, 20 );
571 label = new wxStaticText( net_subpanels[2], -1, wxU(_("URL")) );
572 net_addrs[2] = new wxTextCtrl( net_subpanels[2], NetAddr3_Event, wxT(""),
573 wxDefaultPosition, wxSize( 200, -1 ),
575 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
576 subpanel_sizer->Add( net_addrs[2], 1,
577 wxEXPAND | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
578 net_subpanels[2]->SetSizerAndFit( subpanel_sizer );
580 /* Stuff everything into the main panel */
583 sizer->Add( net_radios[i], 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
585 sizer->Add( net_subpanels[i], 1, wxEXPAND | wxALIGN_LEFT |
586 wxALIGN_CENTER_VERTICAL | wxALL, 5 );
589 sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
591 panel->SetSizerAndFit( sizer_row );
596 wxPanel *OpenDialog::V4LPanel( wxWindow* parent )
598 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
601 wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
602 wxFlexGridSizer *sizer = new wxFlexGridSizer( 1, 4, 20 );
604 static const wxString video_type_array[] =
612 video_type = new wxRadioBox( panel, VideoType_Event,
613 wxU(_("Video Device Type")),
614 wxDefaultPosition, wxDefaultSize,
615 WXSIZEOF(video_type_array), video_type_array,
616 WXSIZEOF(video_type_array), wxRA_SPECIFY_COLS );
618 sizer_row->Add( video_type, 0, wxEXPAND | wxALL, 5 );
622 wxFlexGridSizer *video_sizer = new wxFlexGridSizer( 4, 2, 20 );
623 wxStaticText *label = new wxStaticText( panel, -1, wxU(_("Video Device")) );
624 video_device = new wxTextCtrl( panel, VideoDevice_Event, wxT(""),
625 wxDefaultPosition, wxDefaultSize,
627 video_device->SetToolTip( wxU(_("Device corresponding to your acquisition "
628 "card or your webcam")) );
629 video_sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
630 video_sizer->Add( video_device, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
632 label = new wxStaticText( panel, -1, wxU(_("Channel")) );
633 video_channel = new wxSpinCtrl( panel, VideoChannel_Event, wxT("0") );
634 video_channel->SetToolTip( wxU(_("Usually 0 is for tuner, 1 for composite "
635 "and 2 for svideo")) );
636 video_sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_HORIZONTAL );
637 video_sizer->Add( video_channel, 1, wxALIGN_LEFT | wxALIGN_CENTER_HORIZONTAL );
638 sizer->Add( video_sizer, 0, wxEXPAND | wxALL, 5 );
640 wxBoxSizer *v4lbutton_sizer = new wxBoxSizer( wxHORIZONTAL );
641 v4l_button = new wxButton( panel, V4LSettings_Event,
642 wxU(_("Advanced Settings...")) );
644 v4lbutton_sizer->Add( v4l_button, 0, wxALIGN_RIGHT, 5 );
646 sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
647 sizer_row->Add( v4lbutton_sizer, 0, wxEXPAND | wxALL, 5 );
649 panel->SetSizerAndFit( sizer_row );
654 void OpenDialog::UpdateMRL()
656 UpdateMRL( i_current_access_method );
659 void OpenDialog::UpdateMRL( int i_access_method )
661 wxString demux, mrltemp;
663 i_current_access_method = i_access_method;
665 switch( i_access_method )
668 //mrltemp = wxT("file") + demux + wxT(":") + file_combo->GetValue();
669 mrltemp = file_combo->GetValue();
672 mrltemp = ( disc_type->GetSelection() == 0 ? wxT("dvd") :
673 disc_type->GetSelection() == 1 ? wxT("dvdsimple") :
674 disc_type->GetSelection() == 2 ? wxT("vcd") : wxT("cdda") )
676 + disc_device->GetLineText(0)
677 + wxString::Format( wxT("@%d:%d"),
678 disc_title->GetValue(),
679 disc_chapter->GetValue() );
685 if( i_net_ports[0] !=
686 config_GetInt( p_intf, "server-port" ) )
688 mrltemp = wxT("udp") + demux +
689 wxString::Format( wxT("://@:%d"),
694 mrltemp = wxT("udp") + demux + wxT("://");
699 mrltemp = wxT("udp") + demux + wxT("://@") +
700 net_addrs[1]->GetLineText(0);
701 if( i_net_ports[1] !=
702 config_GetInt( p_intf, "server-port" ) )
704 mrltemp = mrltemp + wxString::Format( wxT(":%d"),
711 mrltemp = wxT("http") + demux + wxT("://") +
712 net_addrs[2]->GetLineText(0);
719 mrltemp = ( video_type->GetSelection() == 0 ? wxT("v4l") :
720 video_type->GetSelection() == 1 ? wxT("v4l") :
721 video_type->GetSelection() == 2 ? wxT("pvr") :
724 + video_device->GetLineText( 0 );
726 if( video_type->GetSelection() == 1 )
728 mrltemp += wxString::Format( wxT(":channel=%d"),
729 video_channel->GetValue() );
732 if ( /* v4l_dialog != NULL && */ !v4l_mrl.IsEmpty() )
734 mrltemp += v4l_mrl[0];
742 int i_item = i_access_method - MAX_ACCESS;
744 if( i_item < 0 || i_item >= (int)input_tab_array.GetCount() )
747 AutoBuiltPanel *input_panel = input_tab_array.Item( i_item );
749 mrltemp = input_panel->name + wxT("://");
751 for( int i=0; i < (int)input_panel->config_array.GetCount(); i++ )
753 ConfigControl *control = input_panel->config_array.Item(i);
754 mrltemp += wxT(" :") + control->GetName() + wxT("=");
756 switch( control->GetType() )
758 case CONFIG_ITEM_STRING:
759 case CONFIG_ITEM_FILE:
760 case CONFIG_ITEM_DIRECTORY:
761 case CONFIG_ITEM_MODULE:
762 mrltemp += wxT("\"") + control->GetPszValue() + wxT("\"");
764 case CONFIG_ITEM_INTEGER:
765 case CONFIG_ITEM_BOOL:
767 wxString::Format( wxT("%i"), control->GetIntValue() );
769 case CONFIG_ITEM_FLOAT:
771 wxString::Format( wxT("%f"), control->GetFloatValue());
779 mrl_combo->SetValue( mrltemp );
782 /*****************************************************************************
784 *****************************************************************************/
785 void OpenDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
787 mrl = SeparateEntries( mrl_combo->GetValue() );
788 mrl_combo->Append( mrl_combo->GetValue() );
789 if( mrl_combo->GetCount() > 10 ) mrl_combo->Delete( 0 );
790 mrl_combo->SetSelection( mrl_combo->GetCount() - 1 );
792 if( i_method == OPEN_STREAM )
798 /* Update the playlist */
799 playlist_t *p_playlist =
800 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
802 if( p_playlist == NULL ) return;
804 for( int i = 0; i < (int)mrl.GetCount(); i++ )
806 int i_options = 0, i_total_options;
807 char **ppsz_options = NULL;
809 /* Count the input options */
810 while( i + i_options + 1 < (int)mrl.GetCount() &&
811 ((const char *)mrl[i + i_options + 1].mb_str())[0] == ':' )
816 /* Allocate ppsz_options */
817 for( int j = 0; j < i_options; j++ )
820 ppsz_options = (char **)malloc( sizeof(char *) * i_options );
822 ppsz_options[j] = strdup( mrl[i + j + 1].mb_str() );
825 i_total_options = i_options;
827 /* Get the options from the subtitles dialog */
828 if( subsfile_checkbox->IsChecked() && subsfile_mrl.GetCount() )
830 ppsz_options = (char **)realloc( ppsz_options, sizeof(char *) *
831 (i_total_options + subsfile_mrl.GetCount()) );
833 for( int j = 0; j < (int)subsfile_mrl.GetCount(); j++ )
835 ppsz_options[i_total_options + j] =
836 strdup( subsfile_mrl[j].mb_str() );
839 i_total_options += subsfile_mrl.GetCount();
842 /* Get the options from the stream output dialog */
843 if( sout_checkbox->IsChecked() && sout_mrl.GetCount() )
845 ppsz_options = (char **)realloc( ppsz_options, sizeof(char *) *
846 (i_total_options + sout_mrl.GetCount()) );
848 for( int j = 0; j < (int)sout_mrl.GetCount(); j++ )
850 ppsz_options[i_total_options + j] =
851 strdup( sout_mrl[j].mb_str() );
854 i_total_options += sout_mrl.GetCount();
858 playlist_Add( p_playlist, (const char *)mrl[i].mb_str(),
859 (const char **)ppsz_options, i_total_options,
860 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );
863 for( int j = 0; j < i_total_options; j++ )
864 free( ppsz_options[j] );
865 if( ppsz_options ) free( ppsz_options );
870 //TogglePlayButton( PLAYING_S );
872 vlc_object_release( p_playlist );
877 void OpenDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
882 void OpenDialog::OnPageChange( wxNotebookEvent& event )
884 UpdateMRL( event.GetSelection() );
887 void OpenDialog::OnMRLChange( wxCommandEvent& event )
889 //mrl = SeparateEntries( event.GetString() );
892 /*****************************************************************************
893 * File panel event methods.
894 *****************************************************************************/
895 void OpenDialog::OnFilePanelChange( wxCommandEvent& WXUNUSED(event) )
897 UpdateMRL( FILE_ACCESS );
900 void OpenDialog::OnFileBrowse( wxCommandEvent& WXUNUSED(event) )
902 if( file_dialog == NULL )
903 file_dialog = new wxFileDialog( this, wxU(_("Open file")),
904 wxT(""), wxT(""), wxT("*"), wxOPEN | wxMULTIPLE );
906 if( file_dialog && file_dialog->ShowModal() == wxID_OK )
911 file_dialog->GetPaths( paths );
913 for( size_t i = 0; i < paths.GetCount(); i++ )
915 if( paths[i].Find( wxT(' ') ) >= 0 )
916 path += wxT("\"") + paths[i] + wxT("\" ");
918 path += paths[i] + wxT(" ");
921 file_combo->SetValue( path );
922 file_combo->Append( path );
923 if( file_combo->GetCount() > 10 ) file_combo->Delete( 0 );
924 UpdateMRL( FILE_ACCESS );
928 /*****************************************************************************
929 * Disc panel event methods.
930 *****************************************************************************/
931 void OpenDialog::OnDiscPanelChange( wxCommandEvent& event )
933 UpdateMRL( DISC_ACCESS );
936 void OpenDialog::OnDiscTypeChange( wxCommandEvent& WXUNUSED(event) )
940 switch( disc_type->GetSelection() )
943 psz_device = config_GetPsz( p_intf, "vcd" );
944 disc_device->SetValue( psz_device ? wxU(psz_device) : wxT("") );
948 psz_device = config_GetPsz( p_intf, "dvd" );
949 disc_device->SetValue( psz_device ? wxU(psz_device) : wxT("") );
953 if( psz_device ) free( psz_device );
955 switch( disc_type->GetSelection() )
958 disc_title->SetRange( 0, 255 );
959 disc_title->SetValue( 0 );
963 disc_title->SetRange( 1, 255 );
964 disc_title->SetValue( 1 );
968 disc_chapter->SetRange( 1, 255 );
969 disc_chapter->SetValue( 1 );
971 UpdateMRL( DISC_ACCESS );
974 /*****************************************************************************
975 * Net panel event methods.
976 *****************************************************************************/
977 void OpenDialog::OnNetPanelChange( wxCommandEvent& event )
979 if( event.GetId() >= NetPort1_Event && event.GetId() <= NetPort3_Event )
981 i_net_ports[event.GetId() - NetPort1_Event] = event.GetInt();
984 UpdateMRL( NET_ACCESS );
987 void OpenDialog::OnNetTypeChange( wxCommandEvent& event )
991 i_net_type = event.GetId() - NetRadio1_Event;
995 net_radios[i]->SetValue( event.GetId() == (NetRadio1_Event+i) );
996 net_subpanels[i]->Enable( event.GetId() == (NetRadio1_Event+i) );
999 UpdateMRL( NET_ACCESS );
1003 /*****************************************************************************
1004 * v4l panel event methods.
1005 *****************************************************************************/
1006 void OpenDialog::OnV4LPanelChange( wxCommandEvent& WXUNUSED(event) )
1008 UpdateMRL( V4L_ACCESS );
1011 void OpenDialog::OnV4LTypeChange( wxCommandEvent& WXUNUSED(event) )
1013 video_device->SetValue( wxU( "/dev/video" ) );
1015 v4l_button->Enable();
1016 video_channel->Disable();
1018 switch( video_type->GetSelection() )
1021 video_channel->Enable();
1022 video_channel->SetRange( 0, 255 );
1025 v4l_button->Disable();
1031 UpdateMRL( V4L_ACCESS );
1034 void OpenDialog::OnV4LSettingsChange( wxCommandEvent& WXUNUSED(event) )
1036 /* Show/hide the open dialog */
1037 if( v4l_dialog == NULL )
1038 v4l_dialog = new V4LDialog( p_intf, this );
1040 if( v4l_dialog && v4l_dialog->ShowModal() == wxID_OK )
1042 v4l_mrl = v4l_dialog->GetOptions();
1045 UpdateMRL( V4L_ACCESS );
1049 /*****************************************************************************
1050 * Subtitles file event methods.
1051 *****************************************************************************/
1052 void OpenDialog::OnSubsFileEnable( wxCommandEvent& event )
1054 subsfile_button->Enable( event.GetInt() != 0 );
1057 void OpenDialog::OnSubsFileSettings( wxCommandEvent& WXUNUSED(event) )
1059 /* Show/hide the open dialog */
1060 if( subsfile_dialog == NULL )
1061 subsfile_dialog = new SubsFileDialog( p_intf, this );
1063 if( subsfile_dialog && subsfile_dialog->ShowModal() == wxID_OK )
1065 subsfile_mrl.Empty();
1066 subsfile_mrl.Add( wxString(wxT("sub-file=")) +
1067 subsfile_dialog->file_combo->GetValue() );
1068 if( subsfile_dialog->encoding_combo )
1069 subsfile_mrl.Add( wxString(wxT("subsdec-encoding=")) +
1070 subsfile_dialog->encoding_combo->GetValue() );
1071 subsfile_mrl.Add( wxString::Format( wxT("sub-delay=%i"),
1072 subsfile_dialog->delay_spinctrl->GetValue() ) );
1073 subsfile_mrl.Add( wxString::Format( wxT("sub-fps=%i"),
1074 subsfile_dialog->fps_spinctrl->GetValue() ) );
1078 /*****************************************************************************
1079 * Stream output event methods.
1080 *****************************************************************************/
1081 void OpenDialog::OnSoutEnable( wxCommandEvent& event )
1083 sout_button->Enable( event.GetInt() != 0 );
1086 void OpenDialog::OnSoutSettings( wxCommandEvent& WXUNUSED(event) )
1088 /* Show/hide the open dialog */
1089 if( sout_dialog == NULL )
1090 sout_dialog = new SoutDialog( p_intf, this );
1092 if( sout_dialog && sout_dialog->ShowModal() == wxID_OK )
1094 sout_mrl = sout_dialog->GetOptions();
1098 /*****************************************************************************
1099 * Utility functions.
1100 *****************************************************************************/
1101 wxArrayString SeparateEntries( wxString entries )
1103 vlc_bool_t b_quotes_mode = VLC_FALSE;
1105 wxArrayString entries_array;
1108 wxStringTokenizer token( entries, wxT(" \t\r\n\""), wxTOKEN_RET_DELIMS );
1110 while( token.HasMoreTokens() )
1112 entry += token.GetNextToken();
1114 if( entry.IsEmpty() ) continue;
1116 if( !b_quotes_mode && entry.Last() == wxT('\"') )
1118 /* Enters quotes mode */
1120 b_quotes_mode = VLC_TRUE;
1122 else if( b_quotes_mode && entry.Last() == wxT('\"') )
1124 /* Finished the quotes mode */
1126 if( !entry.IsEmpty() ) entries_array.Add( entry );
1128 b_quotes_mode = VLC_FALSE;
1130 else if( !b_quotes_mode && entry.Last() != wxT('\"') )
1132 /* we found a non-quoted standalone string */
1133 if( token.HasMoreTokens() ||
1134 entry.Last() == wxT(' ') || entry.Last() == wxT('\t') ||
1135 entry.Last() == wxT('\r') || entry.Last() == wxT('\n') )
1137 if( !entry.IsEmpty() ) entries_array.Add( entry );
1144 if( !entry.IsEmpty() ) entries_array.Add( entry );
1146 return entries_array;