1 /*****************************************************************************
2 * open.cpp : Panels for the open dialogs
3 ****************************************************************************
4 * Copyright (C) 2006-2009 the VideoLAN team
5 * Copyright (C) 2007 Société des arts technologiques
6 * Copyright (C) 2007 Savoir-faire Linux
10 * Authors: Clément Stenac <zorglub@videolan.org>
11 * Jean-Baptiste Kempf <jb@videolan.org>
12 * Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
27 *****************************************************************************/
34 #include "components/open_panels.hpp"
35 #include "dialogs/open.hpp"
36 #include "dialogs_provider.hpp" /* Open Subtitle file */
37 #include "util/qt_dirs.hpp"
39 #include <QFileDialog>
40 #include <QDialogButtonBox>
42 #include <QStackedLayout>
46 #include <QScrollArea>
48 #include <QStringListModel>
50 #define I_DEVICE_TOOLTIP N_("Select the device or the VIDEO_TS directory")
52 static const char *psz_devModule[] = { "v4l", "v4l2", "pvr", "dvb", "bda",
53 "dshow", "screen", "jack" };
55 /**************************************************************************
56 * Open Files and subtitles *
57 **************************************************************************/
58 FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
59 OpenPanel( _parent, _p_intf )
61 /* Classic UI Setup */
65 /** BEGIN QFileDialog tweaking **/
66 /* Use a QFileDialog and customize it because we don't want to
67 rewrite it all. Be careful to your eyes cause there are a few hacks.
68 Be very careful and test correctly when you modify this. */
70 /* Set Filters for file selection */
71 QString fileTypes = "";
72 ADD_FILTER_MEDIA( fileTypes );
73 ADD_FILTER_VIDEO( fileTypes );
74 ADD_FILTER_AUDIO( fileTypes );
75 ADD_FILTER_PLAYLIST( fileTypes );
76 ADD_FILTER_ALL( fileTypes );
77 fileTypes.replace( QString(";*"), QString(" *"));
79 // Make this QFileDialog a child of tempWidget from the ui.
80 dialogBox = new FileOpenBox( ui.tempWidget, NULL,
81 qfu( p_intf->p_sys->psz_filepath ), fileTypes );
83 dialogBox->setFileMode( QFileDialog::ExistingFiles );
84 dialogBox->setAcceptMode( QFileDialog::AcceptOpen );
85 dialogBox->restoreState(
86 getSettings()->value( "file-dialog-state" ).toByteArray() );
88 /* We don't want to see a grip in the middle of the window, do we? */
89 dialogBox->setSizeGripEnabled( false );
92 dialogBox->setToolTip( qtr( "Select one or multiple files" ) );
93 dialogBox->setMinimumHeight( 250 );
95 // But hide the two OK/Cancel buttons. Enable them for debug.
96 QDialogButtonBox *fileDialogAcceptBox =
97 dialogBox->findChildren<QDialogButtonBox*>()[0];
98 fileDialogAcceptBox->hide();
100 /* Ugly hacks to get the good Widget */
101 //This lineEdit is the normal line in the fileDialog.
102 lineFileEdit = dialogBox->findChildren<QLineEdit*>()[0];
103 /* Make a list of QLabel inside the QFileDialog to access the good ones */
104 QList<QLabel *> listLabel = dialogBox->findChildren<QLabel*>();
106 /* Hide the FileNames one. Enable it for debug */
107 listLabel[1]->setText( qtr( "File names:" ) );
108 /* Change the text that was uncool in the usual box */
109 listLabel[2]->setText( qtr( "Filter:" ) );
111 dialogBox->layout()->setMargin( 0 );
112 dialogBox->layout()->setSizeConstraint( QLayout::SetNoConstraint );
114 /** END of QFileDialog tweaking **/
116 // Add the DialogBox to the layout
117 ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
120 /* lineFileEdit = ui.fileEdit;
121 //TODO later: fill the fileCompleteList with previous items played.
122 QCompleter *fileCompleter = new QCompleter( fileCompleteList, this );
123 fileCompleter->setModel( new QDirModel( fileCompleter ) );
124 lineFileEdit->setCompleter( fileCompleter );*/
126 // Hide the subtitles control by default.
127 ui.subFrame->setEnabled( false );
129 /* Build the subs size combo box */
130 setfillVLCConfigCombo( "freetype-rel-fontsize" , p_intf,
131 ui.sizeSubComboBox );
133 /* Build the subs align combo box */
134 setfillVLCConfigCombo( "subsdec-align", p_intf, ui.alignSubComboBox );
137 BUTTONACT( ui.fileBrowseButton, browseFile() );
138 BUTTONACT( ui.subBrowseButton, browseFileSub() );
139 CONNECT( ui.subCheckBox, toggled( bool ), this, toggleSubtitleFrame( bool ) );
141 CONNECT( ui.fileListWidg, itemChanged( QListWidgetItem * ), this, updateMRL() );
142 CONNECT( ui.subInput, textChanged( QString ), this, updateMRL() );
143 CONNECT( ui.alignSubComboBox, currentIndexChanged( int ), this, updateMRL() );
144 CONNECT( ui.sizeSubComboBox, currentIndexChanged( int ), this, updateMRL() );
147 FileOpenPanel::~FileOpenPanel()
149 // getSettings()->setValue( "file-dialog-state", dialogBox->saveState() );
152 void FileOpenPanel::browseFile()
154 QStringList files = QFileDialog::getOpenFileNames( this );
155 foreach( const QString &file, files)
157 QListWidgetItem *item = new QListWidgetItem( file, ui.fileListWidg );
158 item->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled );
159 ui.fileListWidg->addItem( item );
164 /* Show a fileBrowser to select a subtitle */
165 void FileOpenPanel::browseFileSub()
167 // TODO Handle selection of more than one subtitles file
168 QStringList files = THEDP->showSimpleOpen( qtr("Open subtitles file"),
169 EXT_FILTER_SUBTITLE, p_intf->p_sys->psz_filepath );
171 if( files.isEmpty() ) return;
172 ui.subInput->setText( files.join(" ") );
176 void FileOpenPanel::toggleSubtitleFrame( bool b )
178 ui.subFrame->setEnabled( b );
185 /* Update the current MRL */
186 void FileOpenPanel::updateMRL()
188 QStringList fileList;
191 for( int i = 0; i < ui.fileListWidg->count(); i++ )
192 fileList << ui.fileListWidg->item( i )->text();
194 if( ui.subCheckBox->isChecked() && !ui.subInput->text().isEmpty() ) {
195 mrl.append( " :sub-file=\"" + ui.subInput->text() + "\"" );
196 int align = ui.alignSubComboBox->itemData(
197 ui.alignSubComboBox->currentIndex() ).toInt();
198 mrl.append( " :subsdec-align=" + QString().setNum( align ) );
199 int size = ui.sizeSubComboBox->itemData(
200 ui.sizeSubComboBox->currentIndex() ).toInt();
201 mrl.append( " :freetype-rel-fontsize=" + QString().setNum( size ) );
204 emit mrlUpdated( fileList, mrl );
205 emit methodChanged( "file-caching" );
208 /* Function called by Open Dialog when clicke on Play/Enqueue */
209 void FileOpenPanel::accept()
212 // p_intf->p_sys->psz_filepath = qtu( dialogBox->directory().absolutePath() );
215 /* Function called by Open Dialog when clicked on cancel */
216 void FileOpenPanel::clear()
218 ui.fileListWidg->clear();
219 ui.subInput->clear();
222 /**************************************************************************
223 * Open Discs ( DVD, CD, VCD and similar devices ) *
224 **************************************************************************/
225 DiscOpenPanel::DiscOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
226 OpenPanel( _parent, _p_intf )
230 /* Get the default configuration path for the devices */
231 psz_dvddiscpath = config_GetPsz( p_intf, "dvd" );
232 psz_vcddiscpath = config_GetPsz( p_intf, "vcd" );
233 psz_cddadiscpath = config_GetPsz( p_intf, "cd-audio" );
235 /* State to avoid overwritting the users changes with the configuration */
240 ui.browseDiscButton->setToolTip( qtr( I_DEVICE_TOOLTIP ));
241 ui.deviceCombo->setToolTip( I_DEVICE_TOOLTIP );
243 #ifdef WIN32 /* Disc drives probing for Windows */
246 if( GetLogicalDriveStringsA( sizeof( szDrives ) - 1, szDrives ) )
248 char *drive = szDrives;
249 UINT oldMode = SetErrorMode( SEM_FAILCRITICALERRORS );
252 if( GetDriveTypeA(drive) == DRIVE_CDROM )
253 ui.deviceCombo->addItem( drive );
255 /* go to next drive */
258 SetErrorMode(oldMode);
260 #else /* Use a Completer under Linux */
261 QCompleter *discCompleter = new QCompleter( this );
262 discCompleter->setModel( new QDirModel( discCompleter ) );
263 ui.deviceCombo->setCompleter( discCompleter );
267 BUTTONACT( ui.dvdRadioButton, updateButtons() );
268 BUTTONACT( ui.vcdRadioButton, updateButtons() );
269 BUTTONACT( ui.audioCDRadioButton, updateButtons() );
270 BUTTONACT( ui.dvdsimple, updateButtons() );
271 BUTTONACT( ui.browseDiscButton, browseDevice() );
272 BUTTON_SET_ACT_I( ui.ejectButton, "", eject, qtr( "Eject the disc" ),
275 CONNECT( ui.deviceCombo, editTextChanged( QString ), this, updateMRL());
276 CONNECT( ui.titleSpin, valueChanged( int ), this, updateMRL());
277 CONNECT( ui.chapterSpin, valueChanged( int ), this, updateMRL());
278 CONNECT( ui.audioSpin, valueChanged( int ), this, updateMRL());
279 CONNECT( ui.subtitlesSpin, valueChanged( int ), this, updateMRL());
281 /* Run once the updateButtons function in order to fill correctly the comboBoxes */
285 DiscOpenPanel::~DiscOpenPanel()
287 free( psz_dvddiscpath );
288 free( psz_vcddiscpath );
289 free( psz_cddadiscpath );
292 void DiscOpenPanel::clear()
294 ui.titleSpin->setValue( 0 );
295 ui.chapterSpin->setValue( 0 );
296 ui.subtitlesSpin->setValue( -1 );
297 ui.audioSpin->setValue( -1 );
304 #define setDrive( psz_name ) {\
305 int index = ui.deviceCombo->findText( qfu( psz_name ) ); \
306 if( index != -1 ) ui.deviceCombo->setCurrentIndex( index );}
308 #define setDrive( psz_name ) {\
309 ui.deviceCombo->setEditText( qfu( psz_name ) ); }
312 /* update the buttons according the type of device */
313 void DiscOpenPanel::updateButtons()
315 if ( ui.dvdRadioButton->isChecked() )
319 setDrive( psz_dvddiscpath );
322 ui.titleLabel->setText( qtr("Title") );
323 ui.chapterLabel->show();
324 ui.chapterSpin->show();
325 ui.diskOptionBox_2->show();
326 ui.dvdsimple->setEnabled( true );
328 else if ( ui.vcdRadioButton->isChecked() )
332 setDrive( psz_vcddiscpath );
335 ui.titleLabel->setText( qtr("Entry") );
336 ui.chapterLabel->hide();
337 ui.chapterSpin->hide();
338 ui.diskOptionBox_2->show();
339 ui.dvdsimple->setEnabled( false );
345 setDrive( psz_cddadiscpath );
348 ui.titleLabel->setText( qtr("Track") );
349 ui.chapterLabel->hide();
350 ui.chapterSpin->hide();
351 ui.diskOptionBox_2->hide();
352 ui.dvdsimple->setEnabled( false );
358 /* Update the current MRL */
359 void DiscOpenPanel::updateMRL()
362 QStringList fileList;
364 /* CDDAX and VCDX not implemented. TODO ? No. */
366 if( ui.dvdRadioButton->isChecked() ) {
367 if( !ui.dvdsimple->isChecked() )
370 mrl = "dvdsimple://";
371 mrl += ui.deviceCombo->currentText();
372 emit methodChanged( "dvdnav-caching" );
374 if ( ui.titleSpin->value() > 0 ) {
375 mrl += QString("@%1").arg( ui.titleSpin->value() );
376 if ( ui.chapterSpin->value() > 0 ) {
377 mrl+= QString(":%1").arg( ui.chapterSpin->value() );
382 } else if ( ui.vcdRadioButton->isChecked() ) {
383 mrl = "vcd://" + ui.deviceCombo->currentText();
384 emit methodChanged( "vcd-caching" );
386 if( ui.titleSpin->value() > 0 ) {
387 mrl += QString("@E%1").arg( ui.titleSpin->value() );
392 mrl = "cdda://" + ui.deviceCombo->currentText();
393 if( ui.titleSpin->value() > 0 ) {
394 mrl += QString("@%1").arg( ui.titleSpin->value() );
398 fileList << mrl; mrl = "";
400 if ( ui.dvdRadioButton->isChecked() || ui.vcdRadioButton->isChecked() )
402 if ( ui.audioSpin->value() >= 0 ) {
403 mrl += " :audio-track=" +
404 QString("%1").arg( ui.audioSpin->value() );
406 if ( ui.subtitlesSpin->value() >= 0 ) {
407 mrl += " :sub-track=" +
408 QString("%1").arg( ui.subtitlesSpin->value() );
411 emit mrlUpdated( fileList, mrl );
414 void DiscOpenPanel::browseDevice()
416 QString dir = QFileDialog::getExistingDirectory( this,
417 qtr( I_DEVICE_TOOLTIP ) );
419 ui.deviceCombo->setEditText( toNativeSepNoSlash( dir ) );
424 void DiscOpenPanel::eject()
426 intf_Eject( p_intf, qtu( ui.deviceCombo->currentText() ) );
429 void DiscOpenPanel::accept()
432 /**************************************************************************
433 * Open Network streams and URL pages *
434 **************************************************************************/
435 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
436 OpenPanel( _parent, _p_intf )
441 CONNECT( ui.protocolCombo, activated( int ),
442 this, updateProtocol( int ) );
443 CONNECT( ui.portSpin, valueChanged( int ), this, updateMRL() );
444 CONNECT( ui.addressText, textChanged( QString ), this, updateMRL());
446 ui.protocolCombo->addItem( "" );
447 ui.protocolCombo->addItem("HTTP", QVariant("http"));
448 ui.protocolCombo->addItem("HTTPS", QVariant("https"));
449 ui.protocolCombo->addItem("MMS", QVariant("mms"));
450 ui.protocolCombo->addItem("FTP", QVariant("ftp"));
451 ui.protocolCombo->addItem("RTSP", QVariant("rtsp"));
452 ui.protocolCombo->addItem("RTP", QVariant("rtp"));
453 ui.protocolCombo->addItem("UDP", QVariant("udp"));
454 ui.protocolCombo->addItem("RTMP", QVariant("rtmp"));
456 updateProtocol( ui.protocolCombo->currentIndex() );
458 if( config_GetInt( p_intf, "qt-recentplay" ) )
460 mrlList = new QStringListModel(
461 getSettings()->value( "Open/netMRL" ).toStringList() );
462 QCompleter *completer = new QCompleter( mrlList, this );
463 ui.addressText->setCompleter( completer );
465 CONNECT( ui.addressText, editingFinished(), this, updateCompleter() );
471 NetOpenPanel::~NetOpenPanel()
473 if( !mrlList ) return;
475 QStringList tempL = mrlList->stringList();
476 while( tempL.size() > 8 ) tempL.removeFirst();
478 getSettings()->setValue( "Open/netMRL", tempL );
481 void NetOpenPanel::clear()
484 /* update the widgets according the type of protocol */
485 void NetOpenPanel::updateProtocol( int idx_proto ) {
486 QString addr = ui.addressText->text();
487 QString proto = ui.protocolCombo->itemData( idx_proto ).toString();
489 ui.portSpin->setEnabled( idx_proto == UDP_PROTO ||
490 idx_proto == RTP_PROTO );
492 if( idx_proto == NO_PROTO ) return;
494 /* If we already have a protocol in the address, replace it */
495 if( addr.contains( "://"))
497 if( idx_proto != UDP_PROTO && idx_proto != RTP_PROTO )
498 addr.replace( QRegExp("^.*://@*"), proto + "://");
499 else if ( ( addr.contains(QRegExp("://((22[4-9])|(23\\d)|(\\[?[fF]{2}[0-9a-fA-F]{2}:))"))) ||
500 ( !addr.contains(QRegExp("^\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}")) &&
501 !addr.contains(QRegExp(":[a-fA-F0-9]{1,4}:")) ) )
502 addr.replace( QRegExp("^.*://"), proto + "://@");
504 addr.replace( QRegExp("^.*://"), proto + "://");
505 addr.replace( QRegExp("@+"), "@");
506 ui.addressText->setText( addr );
511 void NetOpenPanel::updateMRL() {
513 QString addr = ui.addressText->text();
514 addr = QUrl::toPercentEncoding( addr, ":/?#@!$&'()*+,;=" );
515 int idx_proto = ui.protocolCombo->currentIndex();
516 int addr_is_multicast = addr.contains(QRegExp("^(22[4-9])|(23\\d)|(\\[?[fF]{2}[0-9a-fA-F]{2}:)"))?1:0;
517 int addr_is_ipv4 = addr.contains(QRegExp("^\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}"))?1:0;
518 int addr_is_ipv6 = addr.contains(QRegExp(":[a-fA-F0-9]{1,4}:"))?1:0;
519 int addr_has_port = addr.contains(QRegExp("[^:]{5}:\\d{1,5}$"))?1:0;
520 if( addr.contains( "://"))
522 /* Match the correct item in the comboBox */
523 ui.protocolCombo->setCurrentIndex(
524 ui.protocolCombo->findData( addr.section( ':', 0, 0 ) ) );
529 switch( idx_proto ) {
531 mrl = "http://" + addr;
532 emit methodChanged("http-caching");
535 mrl = "https://" + addr;
536 emit methodChanged("http-caching");
539 mrl = "mms://" + addr;
540 emit methodChanged("mms-caching");
543 mrl = "ftp://" + addr;
544 emit methodChanged("ftp-caching");
547 mrl = "rtsp://" + addr;
548 emit methodChanged("rtsp-caching");
551 if(( addr_is_multicast ) || ( !addr_is_ipv4 && !addr_is_ipv6 ))
556 if ( addr_is_ipv6 && !addr.contains('[') )
558 mrl += "[" + addr + "]";
562 mrl += QString(":%1").arg( ui.portSpin->value() );
563 emit methodChanged("udp-caching");
566 if(( addr_is_multicast ) || ( !addr_is_ipv4 && !addr_is_ipv6 ))
570 if ( addr_is_ipv6 && !addr.contains('[') )
571 mrl += "[" + addr + "]"; /* Add [] to IPv6 */
575 mrl += QString(":%1").arg( ui.portSpin->value() );
576 emit methodChanged("rtp-caching");
579 mrl = "rtmp://" + addr;
580 emit methodChanged("rtmp-caching");
585 QStringList qsl; qsl<< mrl;
586 emit mrlUpdated( qsl, "" );
589 void NetOpenPanel::updateCompleter()
592 QStringList tempL = mrlList->stringList();
593 tempL.append( ui.addressText->text() );
594 mrlList->setStringList( tempL );
597 /**************************************************************************
598 * Open Capture device ( DVB, PVR, V4L, and similar ) *
599 **************************************************************************/
600 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
601 OpenPanel( _parent, _p_intf )
603 isInitialized = false;
606 void CaptureOpenPanel::initialize()
608 if( isInitialized ) return;
610 msg_Dbg( p_intf, "Initialization of Capture device panel" );
611 isInitialized = true;
615 BUTTONACT( ui.advancedButton, advancedDialog() );
617 /* Create two stacked layouts in the main comboBoxes */
618 QStackedLayout *stackedDevLayout = new QStackedLayout;
619 ui.cardBox->setLayout( stackedDevLayout );
621 QStackedLayout *stackedPropLayout = new QStackedLayout;
622 ui.optionsBox->setLayout( stackedPropLayout );
624 /* Creation and connections of the WIdgets in the stacked layout */
625 #define addModuleAndLayouts( number, name, label ) \
626 QWidget * name ## DevPage = new QWidget( this ); \
627 QWidget * name ## PropPage = new QWidget( this ); \
628 stackedDevLayout->addWidget( name ## DevPage ); \
629 stackedPropLayout->addWidget( name ## PropPage ); \
630 QGridLayout * name ## DevLayout = new QGridLayout; \
631 QGridLayout * name ## PropLayout = new QGridLayout; \
632 name ## DevPage->setLayout( name ## DevLayout ); \
633 name ## PropPage->setLayout( name ## PropLayout ); \
634 ui.deviceCombo->addItem( qtr( label ), QVariant( number ) );
636 #define CuMRL( widget, slot ) CONNECT( widget , slot , this, updateMRL() );
639 /*********************
640 * DirectShow Stuffs *
641 *********************/
642 if( module_exists( "dshow" ) ){
643 addModuleAndLayouts( DSHOW_DEVICE, dshow, "DirectShow" );
647 module_config_t *p_config =
648 config_FindConfig( VLC_OBJECT(p_intf), "dshow-vdev" );
649 vdevDshowW = new StringListConfigControl(
650 VLC_OBJECT(p_intf), p_config, this, false, dshowDevLayout, line );
653 p_config = config_FindConfig( VLC_OBJECT(p_intf), "dshow-adev" );
654 adevDshowW = new StringListConfigControl(
655 VLC_OBJECT(p_intf), p_config, this, false, dshowDevLayout, line );
658 /* dshow Properties */
659 QLabel *dshowVSizeLabel = new QLabel( qtr( "Video size" ) );
660 dshowPropLayout->addWidget( dshowVSizeLabel, 0, 0 );
662 dshowVSizeLine = new QLineEdit;
663 dshowPropLayout->addWidget( dshowVSizeLine, 0, 1);
664 dshowPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
668 CuMRL( vdevDshowW->combo, currentIndexChanged ( int ) );
669 CuMRL( adevDshowW->combo, currentIndexChanged ( int ) );
670 CuMRL( dshowVSizeLine, textChanged( QString ) );
676 if( module_exists( "bda" ) ){
677 addModuleAndLayouts( BDA_DEVICE, bda, "DVB DirectShow" );
680 QLabel *bdaTypeLabel = new QLabel( qtr( "DVB Type:" ) );
682 bdas = new QRadioButton( "DVB-S" );
683 bdas->setChecked( true );
684 bdac = new QRadioButton( "DVB-C" );
685 bdat = new QRadioButton( "DVB-T" );
686 bdaa = new QRadioButton( "ATSC" );
688 bdaDevLayout->addWidget( bdaTypeLabel, 0, 0 );
689 bdaDevLayout->addWidget( bdas, 0, 1 );
690 bdaDevLayout->addWidget( bdac, 0, 2 );
691 bdaDevLayout->addWidget( bdat, 0, 3 );
692 bdaDevLayout->addWidget( bdaa, 0, 4 );
695 QLabel *bdaFreqLabel =
696 new QLabel( qtr( "Transponder/multiplex frequency" ) );
697 bdaPropLayout->addWidget( bdaFreqLabel, 0, 0 );
699 bdaFreq = new QSpinBox;
700 bdaFreq->setAlignment( Qt::AlignRight );
701 bdaFreq->setSuffix(" kHz");
702 bdaFreq->setSingleStep( 1000 );
703 setSpinBoxFreq( bdaFreq )
704 bdaPropLayout->addWidget( bdaFreq, 0, 1 );
706 bdaSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
707 bdaPropLayout->addWidget( bdaSrateLabel, 1, 0 );
709 bdaSrate = new QSpinBox;
710 bdaSrate->setAlignment( Qt::AlignRight );
711 bdaSrate->setSuffix(" kHz");
712 setSpinBoxFreq( bdaSrate );
713 bdaPropLayout->addWidget( bdaSrate, 1, 1 );
715 bdaBandLabel = new QLabel( qtr( "Bandwidth" ) );
716 bdaPropLayout->addWidget( bdaBandLabel, 2, 0 );
718 bdaBandBox = new QComboBox;
719 setfillVLCConfigCombo( "dvb-bandwidth", p_intf, bdaBandBox );
720 bdaPropLayout->addWidget( bdaBandBox, 2, 1 );
722 bdaBandLabel->hide();
724 bdaPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
728 CuMRL( bdaFreq, valueChanged ( int ) );
729 CuMRL( bdaSrate, valueChanged ( int ) );
730 CuMRL( bdaBandBox, currentIndexChanged ( int ) );
731 BUTTONACT( bdas, updateButtons() );
732 BUTTONACT( bdat, updateButtons() );
733 BUTTONACT( bdac, updateButtons() );
734 BUTTONACT( bdaa, updateButtons() );
735 BUTTONACT( bdas, updateMRL() );
736 BUTTONACT( bdat, updateMRL() );
737 BUTTONACT( bdac, updateMRL() );
738 BUTTONACT( bdaa, updateMRL() );
745 if( module_exists( "v4l2" ) ){
746 addModuleAndLayouts( V4L2_DEVICE, v4l2, "Video for Linux 2" );
749 QLabel *v4l2VideoDeviceLabel = new QLabel( qtr( "Video device name" ) );
750 v4l2DevLayout->addWidget( v4l2VideoDeviceLabel, 0, 0 );
752 v4l2VideoDevice = new QLineEdit;
753 v4l2DevLayout->addWidget( v4l2VideoDevice, 0, 1 );
755 QLabel *v4l2AudioDeviceLabel = new QLabel( qtr( "Audio device name" ) );
756 v4l2DevLayout->addWidget( v4l2AudioDeviceLabel, 1, 0 );
758 v4l2AudioDevice = new QLineEdit;
759 v4l2DevLayout->addWidget( v4l2AudioDevice, 1, 1 );
761 /* v4l2 Props panel */
762 QLabel *v4l2StdLabel = new QLabel( qtr( "Standard" ) );
763 v4l2PropLayout->addWidget( v4l2StdLabel, 0 , 0 );
765 v4l2StdBox = new QComboBox;
766 setfillVLCConfigCombo( "v4l2-standard", p_intf, v4l2StdBox );
767 v4l2PropLayout->addWidget( v4l2StdBox, 0 , 1 );
768 v4l2PropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
772 CuMRL( v4l2VideoDevice, textChanged( QString ) );
773 CuMRL( v4l2AudioDevice, textChanged( QString ) );
774 CuMRL( v4l2StdBox, currentIndexChanged ( int ) );
780 if( module_exists( "v4l" ) ){
781 addModuleAndLayouts( V4L_DEVICE, v4l, "Video for Linux" );
784 QLabel *v4lVideoDeviceLabel = new QLabel( qtr( "Video device name" ) );
785 v4lDevLayout->addWidget( v4lVideoDeviceLabel, 0, 0 );
787 v4lVideoDevice = new QLineEdit;
788 v4lDevLayout->addWidget( v4lVideoDevice, 0, 1 );
790 QLabel *v4lAudioDeviceLabel = new QLabel( qtr( "Audio device name" ) );
791 v4lDevLayout->addWidget( v4lAudioDeviceLabel, 1, 0 );
793 v4lAudioDevice = new QLineEdit;
794 v4lDevLayout->addWidget( v4lAudioDevice, 1, 1 );
796 /* V4l Props panel */
797 QLabel *v4lNormLabel = new QLabel( qtr( "Norm" ) );
798 v4lPropLayout->addWidget( v4lNormLabel, 0 , 0 );
800 v4lNormBox = new QComboBox;
801 setfillVLCConfigCombo( "v4l-norm", p_intf, v4lNormBox );
802 v4lPropLayout->addWidget( v4lNormBox, 0 , 1 );
804 QLabel *v4lFreqLabel = new QLabel( qtr( "Frequency" ) );
805 v4lPropLayout->addWidget( v4lFreqLabel, 1 , 0 );
807 v4lFreq = new QSpinBox;
808 v4lFreq->setAlignment( Qt::AlignRight );
809 v4lFreq->setSuffix(" kHz");
810 setSpinBoxFreq( v4lFreq );
811 v4lPropLayout->addWidget( v4lFreq, 1 , 1 );
812 v4lPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
816 CuMRL( v4lVideoDevice, textChanged( QString ) );
817 CuMRL( v4lAudioDevice, textChanged( QString ) );
818 CuMRL( v4lFreq, valueChanged ( int ) );
819 CuMRL( v4lNormBox, currentIndexChanged ( int ) );
825 if( module_exists( "jack" ) ){
826 addModuleAndLayouts( JACK_DEVICE, jack, "JACK Audio Connection Kit" );
828 /* Jack Main panel */
830 QLabel *jackChannelsLabel = new QLabel( qtr( "Channels:" ) );
831 jackDevLayout->addWidget( jackChannelsLabel, 1, 0 );
833 jackChannels = new QSpinBox;
834 setSpinBoxFreq( jackChannels );
835 jackChannels->setMaximum(255);
836 jackChannels->setValue(2);
837 jackChannels->setAlignment( Qt::AlignRight );
838 jackDevLayout->addWidget( jackChannels, 1, 1 );
841 QLabel *jackPortsLabel = new QLabel( qtr( "Selected ports:" ) );
842 jackDevLayout->addWidget( jackPortsLabel, 0 , 0 );
844 jackPortsSelected = new QLineEdit( qtr( ".*") );
845 jackPortsSelected->setAlignment( Qt::AlignRight );
846 jackDevLayout->addWidget( jackPortsSelected, 0, 1 );
848 /* Jack Props panel */
851 QLabel *jackCachingLabel = new QLabel( qtr( "Input caching:" ) );
852 jackPropLayout->addWidget( jackCachingLabel, 1 , 0 );
853 jackCaching = new QSpinBox;
854 setSpinBoxFreq( jackCaching );
855 jackCaching->setSuffix( " ms" );
856 jackCaching->setValue(1000);
857 jackCaching->setAlignment( Qt::AlignRight );
858 jackPropLayout->addWidget( jackCaching, 1 , 2 );
861 jackPace = new QCheckBox(qtr( "Use VLC pace" ));
862 jackPropLayout->addWidget( jackPace, 2, 1 );
865 jackConnect = new QCheckBox( qtr( "Auto connnection" ));
866 jackPropLayout->addWidget( jackConnect, 2, 2 );
869 CuMRL( jackChannels, valueChanged( int ) );
870 CuMRL( jackCaching, valueChanged( int ) );
871 CuMRL( jackPace, stateChanged( int ) );
872 CuMRL( jackConnect, stateChanged( int ) );
873 CuMRL( jackPortsSelected, textChanged( QString ) );
879 if( module_exists( "pvr" ) ){
880 addModuleAndLayouts( PVR_DEVICE, pvr, "PVR" );
883 QLabel *pvrDeviceLabel = new QLabel( qtr( "Device name" ) );
884 pvrDevLayout->addWidget( pvrDeviceLabel, 0, 0 );
886 pvrDevice = new QLineEdit;
887 pvrDevLayout->addWidget( pvrDevice, 0, 1 );
889 QLabel *pvrRadioDeviceLabel = new QLabel( qtr( "Radio device name" ) );
890 pvrDevLayout->addWidget( pvrRadioDeviceLabel, 1, 0 );
892 pvrRadioDevice = new QLineEdit;
893 pvrDevLayout->addWidget( pvrRadioDevice, 1, 1 );
895 /* PVR props panel */
896 QLabel *pvrNormLabel = new QLabel( qtr( "Norm" ) );
897 pvrPropLayout->addWidget( pvrNormLabel, 0, 0 );
899 pvrNormBox = new QComboBox;
900 setfillVLCConfigCombo( "pvr-norm", p_intf, pvrNormBox );
901 pvrPropLayout->addWidget( pvrNormBox, 0, 1 );
903 QLabel *pvrFreqLabel = new QLabel( qtr( "Frequency" ) );
904 pvrPropLayout->addWidget( pvrFreqLabel, 1, 0 );
906 pvrFreq = new QSpinBox;
907 pvrFreq->setAlignment( Qt::AlignRight );
908 pvrFreq->setSuffix(" kHz");
909 setSpinBoxFreq( pvrFreq );
910 pvrPropLayout->addWidget( pvrFreq, 1, 1 );
912 QLabel *pvrBitrLabel = new QLabel( qtr( "Bitrate" ) );
913 pvrPropLayout->addWidget( pvrBitrLabel, 2, 0 );
915 pvrBitr = new QSpinBox;
916 pvrBitr->setAlignment( Qt::AlignRight );
917 pvrBitr->setSuffix(" kHz");
918 setSpinBoxFreq( pvrBitr );
919 pvrPropLayout->addWidget( pvrBitr, 2, 1 );
920 pvrPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
924 CuMRL( pvrDevice, textChanged( QString ) );
925 CuMRL( pvrRadioDevice, textChanged( QString ) );
927 CuMRL( pvrFreq, valueChanged ( int ) );
928 CuMRL( pvrBitr, valueChanged ( int ) );
929 CuMRL( pvrNormBox, currentIndexChanged ( int ) );
935 if( module_exists( "dvb" ) ){
936 addModuleAndLayouts( DVB_DEVICE, dvb, "DVB" );
939 QLabel *dvbDeviceLabel = new QLabel( qtr( "Adapter card to tune" ) );
940 QLabel *dvbTypeLabel = new QLabel( qtr( "DVB Type:" ) );
942 dvbCard = new QSpinBox;
943 dvbCard->setAlignment( Qt::AlignRight );
944 dvbCard->setPrefix( "/dev/dvb/adapter" );
946 dvbDevLayout->addWidget( dvbDeviceLabel, 0, 0 );
947 dvbDevLayout->addWidget( dvbCard, 0, 2, 1, 2 );
949 dvbs = new QRadioButton( "DVB-S" );
950 dvbs->setChecked( true );
951 dvbc = new QRadioButton( "DVB-C" );
952 dvbt = new QRadioButton( "DVB-T" );
954 dvbDevLayout->addWidget( dvbTypeLabel, 1, 0 );
955 dvbDevLayout->addWidget( dvbs, 1, 1 );
956 dvbDevLayout->addWidget( dvbc, 1, 2 );
957 dvbDevLayout->addWidget( dvbt, 1, 3 );
959 /* DVB Props panel */
960 QLabel *dvbFreqLabel =
961 new QLabel( qtr( "Transponder/multiplex frequency" ) );
962 dvbPropLayout->addWidget( dvbFreqLabel, 0, 0 );
964 dvbFreq = new QSpinBox;
965 dvbFreq->setAlignment( Qt::AlignRight );
966 dvbFreq->setSuffix(" kHz");
967 setSpinBoxFreq( dvbFreq );
968 dvbPropLayout->addWidget( dvbFreq, 0, 1 );
970 QLabel *dvbSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
971 dvbPropLayout->addWidget( dvbSrateLabel, 1, 0 );
973 dvbSrate = new QSpinBox;
974 dvbSrate->setAlignment( Qt::AlignRight );
975 dvbSrate->setSuffix(" kHz");
976 setSpinBoxFreq( dvbSrate );
977 dvbPropLayout->addWidget( dvbSrate, 1, 1 );
978 dvbPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
982 CuMRL( dvbCard, valueChanged ( int ) );
983 CuMRL( dvbFreq, valueChanged ( int ) );
984 CuMRL( dvbSrate, valueChanged ( int ) );
986 BUTTONACT( dvbs, updateButtons() );
987 BUTTONACT( dvbt, updateButtons() );
988 BUTTONACT( dvbc, updateButtons() );
997 addModuleAndLayouts( SCREEN_DEVICE, screen, "Desktop" );
998 QLabel *screenLabel = new QLabel( "This option will open your own "
999 "desktop in order to save or stream it.");
1000 screenLabel->setWordWrap( true );
1001 screenDevLayout->addWidget( screenLabel, 0, 0 );
1003 QLabel *screenFPSLabel = new QLabel(
1004 qtr( "Desired frame rate for the capture." ) );
1005 screenPropLayout->addWidget( screenFPSLabel, 0, 0 );
1007 screenFPS = new QSpinBox;
1008 screenFPS->setValue( 1 );
1009 screenFPS->setAlignment( Qt::AlignRight );
1010 screenPropLayout->addWidget( screenFPS, 0, 1 );
1012 /* General connects */
1013 CONNECT( ui.deviceCombo, activated( int ) ,
1014 stackedDevLayout, setCurrentIndex( int ) );
1015 CONNECT( ui.deviceCombo, activated( int ),
1016 stackedPropLayout, setCurrentIndex( int ) );
1017 CONNECT( ui.deviceCombo, activated( int ), this, updateMRL() );
1018 CONNECT( ui.deviceCombo, activated( int ), this, updateButtons() );
1023 CaptureOpenPanel::~CaptureOpenPanel()
1027 void CaptureOpenPanel::clear()
1032 void CaptureOpenPanel::updateMRL()
1035 QStringList fileList;
1036 int i_devicetype = ui.deviceCombo->itemData(
1037 ui.deviceCombo->currentIndex() ).toInt();
1038 switch( i_devicetype )
1042 if( bdas->isChecked() ) mrl = "dvb-s://";
1043 else if( bdat->isChecked() ) mrl = "dvb-t://";
1044 else if( bdac->isChecked() ) mrl = "dvb-c://";
1045 else if( bdaa->isChecked() ) mrl = "atsc://";
1047 fileList << mrl; mrl = "";
1049 mrl += " :dvb-frequency=" + QString("%1").arg( bdaFreq->value() );
1050 if( bdas->isChecked() || bdac->isChecked() )
1051 mrl += " :dvb-srate=" + QString("%1").arg( bdaSrate->value() );
1052 else if( bdat->isChecked() )
1053 mrl += " :dvb-bandwidth=" +
1054 QString("%1").arg( bdaBandBox->itemData(
1055 bdaBandBox->currentIndex() ).toInt() );
1058 fileList << "dshow://";
1059 mrl+= " :dshow-vdev=" + QString("\"%1\"").arg( vdevDshowW->getValue() );
1060 mrl+= " :dshow-adev=" + QString("\"%1\"").arg( adevDshowW->getValue() );
1061 if( dshowVSizeLine->isModified() )
1062 mrl += " :dshow-size=" + dshowVSizeLine->text();
1066 fileList << "v4l://";
1067 mrl += " :v4l-vdev=" + v4lVideoDevice->text();
1068 mrl += " :v4l-adev=" + v4lAudioDevice->text();
1069 mrl += " :v4l-norm=" + QString("%1").arg( v4lNormBox->currentIndex() );
1070 mrl += " :v4l-frequency=" + QString("%1").arg( v4lFreq->value() );
1073 fileList << "v4l2://";
1074 mrl += " :v4l2-dev=" + v4l2VideoDevice->text();
1075 mrl += " :v4l2-adev=" + v4l2AudioDevice->text();
1076 mrl += " :v4l2-standard=" + QString("%1").arg( v4l2StdBox->currentIndex() );
1080 mrl += "channels=" + QString("%1").arg( jackChannels->value() );
1081 mrl += ":ports=" + jackPortsSelected->text();
1082 fileList << mrl; mrl = "";
1084 mrl += " :jack-input-caching=" + QString("%1").arg( jackCaching->value() );
1085 if ( jackPace->isChecked() )
1087 mrl += " :jack-input-use-vlc-pace";
1089 if ( jackConnect->isChecked() )
1091 mrl += " :jack-input-auto-connect";
1095 fileList << "pvr://";
1096 mrl += " :pvr-device=" + pvrDevice->text();
1097 mrl += " :pvr-radio-device=" + pvrRadioDevice->text();
1098 mrl += " :pvr-norm=" + QString("%1").arg( pvrNormBox->currentIndex() );
1099 if( pvrFreq->value() )
1100 mrl += " :pvr-frequency=" + QString("%1").arg( pvrFreq->value() );
1101 if( pvrBitr->value() )
1102 mrl += " :pvr-bitrate=" + QString("%1").arg( pvrBitr->value() );
1105 fileList << "dvb://";
1106 mrl += " :dvb-adapter=" + QString("%1").arg( dvbCard->value() );
1107 mrl += " :dvb-frequency=" + QString("%1").arg( dvbFreq->value() );
1108 mrl += " :dvb-srate=" + QString("%1").arg( dvbSrate->value() );
1112 fileList << "screen://";
1113 mrl = " :screen-fps=" + QString("%1").arg( screenFPS->value() );
1118 if( !advMRL.isEmpty() ) mrl += advMRL;
1120 emit mrlUpdated( fileList, mrl );
1124 * Update the Buttons (show/hide) for the GUI as all device type don't
1125 * use the same ui. elements.
1127 void CaptureOpenPanel::updateButtons()
1129 /* Be sure to display the ui Elements in case they were hidden by
1130 * some Device Type (like Screen://) */
1131 ui.optionsBox->show();
1132 ui.advancedButton->show();
1133 /* Get the current Device Number */
1134 int i_devicetype = ui.deviceCombo->itemData(
1135 ui.deviceCombo->currentIndex() ).toInt();
1136 switch( i_devicetype )
1140 if( bdas->isChecked() || bdac->isChecked() )
1143 bdaSrateLabel->show();
1145 bdaBandLabel->hide();
1147 else if( bdat->isChecked() )
1150 bdaSrateLabel->hide();
1152 bdaBandLabel->show();
1157 if( dvbs->isChecked() ) dvbFreq->setSuffix(" kHz");
1158 if( dvbc->isChecked() || dvbt->isChecked() ) dvbFreq->setSuffix(" Hz");
1162 //ui.optionsBox->hide();
1163 ui.advancedButton->hide();
1170 void CaptureOpenPanel::advancedDialog()
1172 /* Get selected device type */
1173 int i_devicetype = ui.deviceCombo->itemData(
1174 ui.deviceCombo->currentIndex() ).toInt();
1176 /* Get the corresponding module */
1177 module_t *p_module =
1178 module_find( psz_devModule[i_devicetype] );
1179 if( NULL == p_module ) return;
1182 QList<ConfigControl *> controls;
1184 /* Get the confsize */
1185 unsigned int i_confsize;
1186 module_config_t *p_config;
1187 p_config = module_config_get( p_module, &i_confsize );
1189 /* New Adv Prop dialog */
1190 adv = new QDialog( this );
1191 adv->setWindowTitle( qtr( "Advanced Options" ) );
1193 /* A main Layout with a Frame */
1194 QVBoxLayout *mainLayout = new QVBoxLayout( adv );
1195 QScrollArea *scroll = new QScrollArea;
1196 mainLayout->addWidget( scroll );
1198 QFrame *advFrame = new QFrame;
1199 /* GridLayout inside the Frame */
1200 QGridLayout *gLayout = new QGridLayout( advFrame );
1202 scroll->setWidgetResizable( true );
1203 scroll->setWidget( advFrame );
1205 /* Create the options inside the FrameLayout */
1206 for( int n = 0; n < (int)i_confsize; n++ )
1208 module_config_t *p_item = p_config + n;
1209 ConfigControl *config = ConfigControl::createControl(
1210 VLC_OBJECT( p_intf ), p_item, advFrame, gLayout, n );
1211 controls.append( config );
1215 QDialogButtonBox *advButtonBox = new QDialogButtonBox( adv );
1216 QPushButton *closeButton = new QPushButton( qtr( "OK" ) );
1217 QPushButton *cancelButton = new QPushButton( qtr( "Cancel" ) );
1219 CONNECT( closeButton, clicked(), adv, accept() );
1220 CONNECT( cancelButton, clicked(), adv, reject() );
1222 advButtonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
1223 advButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
1225 mainLayout->addWidget( advButtonBox );
1227 /* Creation of the MRL */
1230 QString tempMRL = "";
1231 for( int i = 0; i < controls.size(); i++ )
1233 ConfigControl *control = controls[i];
1236 msg_Dbg( p_intf, "This shouldn't happen, please report" );
1240 tempMRL += (i ? " :" : ":");
1242 if( control->getType() == CONFIG_ITEM_BOOL )
1243 if( !(qobject_cast<VIntConfigControl *>(control)->getValue() ) )
1246 tempMRL += control->getName();
1248 switch( control->getType() )
1250 case CONFIG_ITEM_STRING:
1251 case CONFIG_ITEM_FILE:
1252 case CONFIG_ITEM_DIRECTORY:
1253 case CONFIG_ITEM_MODULE:
1254 tempMRL += QString("=\"%1\"").arg( qobject_cast<VStringConfigControl *>(control)->getValue() );
1256 case CONFIG_ITEM_INTEGER:
1257 tempMRL += QString("=%1").arg( qobject_cast<VIntConfigControl *>(control)->getValue() );
1259 case CONFIG_ITEM_FLOAT:
1260 tempMRL += QString("=%1").arg( qobject_cast<VFloatConfigControl *>(control)->getValue() );
1266 msg_Dbg( p_intf, "%s", qtu( advMRL ) );
1269 module_config_free( p_config );
1270 module_release (p_module);