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 ), dialogBox( NULL )
61 /* Classic UI Setup */
64 /* Set Filters for file selection */
65 /* QString fileTypes = "";
66 ADD_FILTER_MEDIA( fileTypes );
67 ADD_FILTER_VIDEO( fileTypes );
68 ADD_FILTER_AUDIO( fileTypes );
69 ADD_FILTER_PLAYLIST( fileTypes );
70 ADD_FILTER_ALL( fileTypes );
71 fileTypes.replace( QString(";*"), QString(" *")); */
74 /* lineFileEdit = ui.fileEdit;
75 //TODO later: fill the fileCompleteList with previous items played.
76 QCompleter *fileCompleter = new QCompleter( fileCompleteList, this );
77 fileCompleter->setModel( new QDirModel( fileCompleter ) );
78 lineFileEdit->setCompleter( fileCompleter );*/
79 if( config_GetInt( p_intf, "qt-embedded-open" ) )
81 ui.tempWidget->hide();
86 /* Deactivate the subtitles control by default. */
87 ui.subFrame->setEnabled( false );
88 /* Build the subs size combo box */
89 setfillVLCConfigCombo( "freetype-rel-fontsize" , p_intf,
91 /* Build the subs align combo box */
92 setfillVLCConfigCombo( "subsdec-align", p_intf, ui.alignSubComboBox );
95 BUTTONACT( ui.fileBrowseButton, browseFile() );
96 BUTTONACT( ui.delFileButton, deleteFile() );
98 BUTTONACT( ui.subBrowseButton, browseFileSub() );
99 CONNECT( ui.subCheckBox, toggled( bool ), this, toggleSubtitleFrame( bool ) );
101 CONNECT( ui.fileListWidg, itemChanged( QListWidgetItem * ), this, updateMRL() );
102 CONNECT( ui.subInput, textChanged( const QString& ), this, updateMRL() );
103 CONNECT( ui.alignSubComboBox, currentIndexChanged( int ), this, updateMRL() );
104 CONNECT( ui.sizeSubComboBox, currentIndexChanged( int ), this, updateMRL() );
107 inline void FileOpenPanel::BuildOldPanel()
109 /** BEGIN QFileDialog tweaking **/
110 /* Use a QFileDialog and customize it because we don't want to
111 rewrite it all. Be careful to your eyes cause there are a few hacks.
112 Be very careful and test correctly when you modify this. */
114 /* Make this QFileDialog a child of tempWidget from the ui. */
115 dialogBox = new FileOpenBox( ui.tempWidget, NULL,
116 p_intf->p_sys->filepath, "" );
118 dialogBox->setFileMode( QFileDialog::ExistingFiles );
119 dialogBox->setAcceptMode( QFileDialog::AcceptOpen );
120 dialogBox->restoreState(
121 getSettings()->value( "file-dialog-state" ).toByteArray() );
123 /* We don't want to see a grip in the middle of the window, do we? */
124 dialogBox->setSizeGripEnabled( false );
127 dialogBox->setToolTip( qtr( "Select one or multiple files" ) );
128 dialogBox->setMinimumHeight( 250 );
130 // But hide the two OK/Cancel buttons. Enable them for debug.
131 QDialogButtonBox *fileDialogAcceptBox =
132 dialogBox->findChildren<QDialogButtonBox*>()[0];
133 fileDialogAcceptBox->hide();
135 /* Ugly hacks to get the good Widget */
136 //This lineEdit is the normal line in the fileDialog.
137 QLineEdit *lineFileEdit = dialogBox->findChildren<QLineEdit*>()[0];
138 /* Make a list of QLabel inside the QFileDialog to access the good ones */
139 QList<QLabel *> listLabel = dialogBox->findChildren<QLabel*>();
141 /* Hide the FileNames one. Enable it for debug */
142 listLabel[1]->setText( qtr( "File names:" ) );
143 /* Change the text that was uncool in the usual box */
144 listLabel[2]->setText( qtr( "Filter:" ) );
146 dialogBox->layout()->setMargin( 0 );
147 dialogBox->layout()->setSizeConstraint( QLayout::SetNoConstraint );
149 /** END of QFileDialog tweaking **/
151 // Add the DialogBox to the layout
152 ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
154 CONNECT( lineFileEdit, textChanged( const QString& ), this, updateMRL() );
155 dialogBox->installEventFilter( this );
158 FileOpenPanel::~FileOpenPanel()
161 getSettings()->setValue( "file-dialog-state", dialogBox->saveState() );
164 void FileOpenPanel::browseFile()
166 QStringList files = QFileDialog::getOpenFileNames( this );
167 foreach( const QString &file, files)
169 QListWidgetItem *item = new QListWidgetItem( file, ui.fileListWidg );
170 item->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled );
171 ui.fileListWidg->addItem( item );
176 void FileOpenPanel::deleteFile()
178 int i = ui.fileListWidg->currentRow();
181 QListWidgetItem *temp = ui.fileListWidg->takeItem( i );
188 /* Show a fileBrowser to select a subtitle */
189 void FileOpenPanel::browseFileSub()
191 // TODO Handle selection of more than one subtitles file
192 QStringList files = THEDP->showSimpleOpen( qtr("Open subtitles file"),
193 EXT_FILTER_SUBTITLE, p_intf->p_sys->filepath );
195 if( files.isEmpty() ) return;
196 ui.subInput->setText( files.join(" ") );
200 void FileOpenPanel::toggleSubtitleFrame( bool b )
202 ui.subFrame->setEnabled( b );
209 /* Update the current MRL */
210 void FileOpenPanel::updateMRL()
212 QStringList fileList;
216 if( dialogBox == NULL )
217 for( int i = 0; i < ui.fileListWidg->count(); i++ )
219 if( !ui.fileListWidg->item( i )->text().isEmpty() )
220 fileList << ui.fileListWidg->item( i )->text();
223 fileList = dialogBox->selectedFiles();
226 if( ui.subCheckBox->isChecked() && !ui.subInput->text().isEmpty() ) {
227 mrl.append( " :sub-file=" + colon_escape( ui.subInput->text() ) );
228 int align = ui.alignSubComboBox->itemData(
229 ui.alignSubComboBox->currentIndex() ).toInt();
230 mrl.append( " :subsdec-align=" + QString().setNum( align ) );
231 int size = ui.sizeSubComboBox->itemData(
232 ui.sizeSubComboBox->currentIndex() ).toInt();
233 mrl.append( " :freetype-rel-fontsize=" + QString().setNum( size ) );
236 emit mrlUpdated( fileList, mrl );
237 emit methodChanged( "file-caching" );
240 /* Function called by Open Dialog when clicke on Play/Enqueue */
241 void FileOpenPanel::accept()
243 p_intf->p_sys->filepath = dialogBox->directory().absolutePath();
244 ui.fileListWidg->clear();
247 /* Function called by Open Dialog when clicked on cancel */
248 void FileOpenPanel::clear()
250 ui.fileListWidg->clear();
251 ui.subInput->clear();
254 /**************************************************************************
255 * Open Discs ( DVD, CD, VCD and similar devices ) *
256 **************************************************************************/
257 DiscOpenPanel::DiscOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
258 OpenPanel( _parent, _p_intf )
262 /* Get the default configuration path for the devices */
263 psz_dvddiscpath = config_GetPsz( p_intf, "dvd" );
264 psz_vcddiscpath = config_GetPsz( p_intf, "vcd" );
265 psz_cddadiscpath = config_GetPsz( p_intf, "cd-audio" );
267 /* State to avoid overwritting the users changes with the configuration */
272 ui.browseDiscButton->setToolTip( qtr( I_DEVICE_TOOLTIP ));
273 ui.deviceCombo->setToolTip( qtr(I_DEVICE_TOOLTIP) );
275 #ifdef WIN32 /* Disc drives probing for Windows */
278 if( GetLogicalDriveStringsA( sizeof( szDrives ) - 1, szDrives ) )
280 char *drive = szDrives;
281 UINT oldMode = SetErrorMode( SEM_FAILCRITICALERRORS );
284 if( GetDriveTypeA(drive) == DRIVE_CDROM )
285 ui.deviceCombo->addItem( drive );
287 /* go to next drive */
290 SetErrorMode(oldMode);
292 #else /* Use a Completer under Linux */
293 QCompleter *discCompleter = new QCompleter( this );
294 discCompleter->setModel( new QDirModel( discCompleter ) );
295 ui.deviceCombo->setCompleter( discCompleter );
299 BUTTONACT( ui.dvdRadioButton, updateButtons() );
300 BUTTONACT( ui.vcdRadioButton, updateButtons() );
301 BUTTONACT( ui.audioCDRadioButton, updateButtons() );
302 BUTTONACT( ui.dvdsimple, updateButtons() );
303 BUTTONACT( ui.browseDiscButton, browseDevice() );
304 BUTTON_SET_ACT_I( ui.ejectButton, "", eject, qtr( "Eject the disc" ),
307 CONNECT( ui.deviceCombo, editTextChanged( QString ), this, updateMRL());
308 CONNECT( ui.titleSpin, valueChanged( int ), this, updateMRL());
309 CONNECT( ui.chapterSpin, valueChanged( int ), this, updateMRL());
310 CONNECT( ui.audioSpin, valueChanged( int ), this, updateMRL());
311 CONNECT( ui.subtitlesSpin, valueChanged( int ), this, updateMRL());
313 /* Run once the updateButtons function in order to fill correctly the comboBoxes */
317 DiscOpenPanel::~DiscOpenPanel()
319 free( psz_dvddiscpath );
320 free( psz_vcddiscpath );
321 free( psz_cddadiscpath );
324 void DiscOpenPanel::clear()
326 ui.titleSpin->setValue( 0 );
327 ui.chapterSpin->setValue( 0 );
328 ui.subtitlesSpin->setValue( -1 );
329 ui.audioSpin->setValue( -1 );
336 #define setDrive( psz_name ) {\
337 int index = ui.deviceCombo->findText( qfu( psz_name ) ); \
338 if( index != -1 ) ui.deviceCombo->setCurrentIndex( index );}
340 #define setDrive( psz_name ) {\
341 ui.deviceCombo->setEditText( qfu( psz_name ) ); }
344 /* update the buttons according the type of device */
345 void DiscOpenPanel::updateButtons()
347 if ( ui.dvdRadioButton->isChecked() )
351 setDrive( psz_dvddiscpath );
354 ui.titleLabel->setText( qtr("Title") );
355 ui.chapterLabel->show();
356 ui.chapterSpin->show();
357 ui.diskOptionBox_2->show();
358 ui.dvdsimple->setEnabled( true );
360 else if ( ui.vcdRadioButton->isChecked() )
364 setDrive( psz_vcddiscpath );
367 ui.titleLabel->setText( qtr("Entry") );
368 ui.chapterLabel->hide();
369 ui.chapterSpin->hide();
370 ui.diskOptionBox_2->show();
371 ui.dvdsimple->setEnabled( false );
377 setDrive( psz_cddadiscpath );
380 ui.titleLabel->setText( qtr("Track") );
381 ui.chapterLabel->hide();
382 ui.chapterSpin->hide();
383 ui.diskOptionBox_2->hide();
384 ui.dvdsimple->setEnabled( false );
392 /* Update the current MRL */
393 void DiscOpenPanel::updateMRL()
396 QStringList fileList;
398 /* CDDAX and VCDX not implemented. TODO ? No. */
400 if( ui.dvdRadioButton->isChecked() ) {
401 if( !ui.dvdsimple->isChecked() )
404 mrl = "dvdsimple://";
405 mrl += ui.deviceCombo->currentText();
406 emit methodChanged( "dvdnav-caching" );
408 if ( ui.titleSpin->value() > 0 ) {
409 mrl += QString("@%1").arg( ui.titleSpin->value() );
410 if ( ui.chapterSpin->value() > 0 ) {
411 mrl+= QString(":%1").arg( ui.chapterSpin->value() );
416 } else if ( ui.vcdRadioButton->isChecked() ) {
417 mrl = "vcd://" + ui.deviceCombo->currentText();
418 emit methodChanged( "vcd-caching" );
420 if( ui.titleSpin->value() > 0 ) {
421 mrl += QString("@E%1").arg( ui.titleSpin->value() );
426 mrl = "cdda://" + ui.deviceCombo->currentText();
429 fileList << mrl; mrl = "";
431 if ( ui.dvdRadioButton->isChecked() || ui.vcdRadioButton->isChecked() )
433 if ( ui.audioSpin->value() >= 0 ) {
434 mrl += " :audio-track=" +
435 QString("%1").arg( ui.audioSpin->value() );
437 if ( ui.subtitlesSpin->value() >= 0 ) {
438 mrl += " :sub-track=" +
439 QString("%1").arg( ui.subtitlesSpin->value() );
444 if( ui.titleSpin->value() > 0 )
445 mrl += QString(" :cdda-track=%1").arg( ui.titleSpin->value() );
447 emit mrlUpdated( fileList, mrl );
450 void DiscOpenPanel::browseDevice()
452 QString dir = QFileDialog::getExistingDirectory( this,
453 qtr( I_DEVICE_TOOLTIP ) );
455 ui.deviceCombo->setEditText( toNativeSepNoSlash( dir ) );
460 void DiscOpenPanel::eject()
462 intf_Eject( p_intf, qtu( ui.deviceCombo->currentText() ) );
465 void DiscOpenPanel::accept()
468 /**************************************************************************
469 * Open Network streams and URL pages *
470 **************************************************************************/
471 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
472 OpenPanel( _parent, _p_intf )
477 CONNECT( ui.protocolCombo, activated( int ),
478 this, updateProtocol( int ) );
479 CONNECT( ui.portSpin, valueChanged( int ), this, updateMRL() );
480 CONNECT( ui.addressText, textChanged( const QString& ), this, updateMRL());
482 ui.protocolCombo->addItem( "" );
483 ui.protocolCombo->addItem("HTTP", QVariant("http"));
484 ui.protocolCombo->addItem("HTTPS", QVariant("https"));
485 ui.protocolCombo->addItem("MMS", QVariant("mms"));
486 ui.protocolCombo->addItem("FTP", QVariant("ftp"));
487 ui.protocolCombo->addItem("RTSP", QVariant("rtsp"));
488 ui.protocolCombo->addItem("RTP", QVariant("rtp"));
489 ui.protocolCombo->addItem("UDP", QVariant("udp"));
490 ui.protocolCombo->addItem("RTMP", QVariant("rtmp"));
492 updateProtocol( ui.protocolCombo->currentIndex() );
494 if( config_GetInt( p_intf, "qt-recentplay" ) )
496 mrlList = new QStringListModel(
497 getSettings()->value( "Open/netMRL" ).toStringList() );
498 QCompleter *completer = new QCompleter( mrlList, this );
499 ui.addressText->setCompleter( completer );
501 CONNECT( ui.addressText, editingFinished(), this, updateCompleter() );
507 NetOpenPanel::~NetOpenPanel()
509 if( !mrlList ) return;
511 QStringList tempL = mrlList->stringList();
512 while( tempL.size() > 8 ) tempL.removeFirst();
514 getSettings()->setValue( "Open/netMRL", tempL );
519 void NetOpenPanel::clear()
522 /* update the widgets according the type of protocol */
523 void NetOpenPanel::updateProtocol( int idx_proto ) {
524 QString addr = ui.addressText->text();
525 QString proto = ui.protocolCombo->itemData( idx_proto ).toString();
527 ui.portSpin->setEnabled( idx_proto == UDP_PROTO ||
528 idx_proto == RTP_PROTO );
530 if( idx_proto == NO_PROTO ) return;
532 /* If we already have a protocol in the address, replace it */
533 if( addr.contains( "://"))
535 if( idx_proto != UDP_PROTO && idx_proto != RTP_PROTO )
536 addr.replace( QRegExp("^.*://@*"), proto + "://");
537 else if ( ( addr.contains(QRegExp("://((22[4-9])|(23\\d)|(\\[?[fF]{2}[0-9a-fA-F]{2}:))"))) ||
538 ( !addr.contains(QRegExp("^\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}")) &&
539 !addr.contains(QRegExp(":[a-fA-F0-9]{1,4}:")) ) )
540 addr.replace( QRegExp("^.*://"), proto + "://@");
542 addr.replace( QRegExp("^.*://"), proto + "://");
543 addr.replace( QRegExp("@+"), "@");
544 ui.addressText->setText( addr );
549 void NetOpenPanel::updateMRL() {
551 QString addr = ui.addressText->text();
552 addr = QUrl::toPercentEncoding( addr, ":/?#@!$&'()*+,;=" );
553 int idx_proto = ui.protocolCombo->currentIndex();
554 int addr_is_multicast = addr.contains(QRegExp("^(22[4-9])|(23\\d)|(\\[?[fF]{2}[0-9a-fA-F]{2}:)"))?1:0;
555 int addr_is_ipv4 = addr.contains(QRegExp("^\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}"))?1:0;
556 int addr_is_ipv6 = addr.contains(QRegExp(":[a-fA-F0-9]{1,4}:"))?1:0;
557 int addr_has_port = addr.contains(QRegExp("[^:]{5}:\\d{1,5}$"))?1:0;
558 if( addr.contains( "://"))
560 /* Match the correct item in the comboBox */
561 ui.protocolCombo->setCurrentIndex(
562 ui.protocolCombo->findData( addr.section( ':', 0, 0 ) ) );
567 switch( idx_proto ) {
569 mrl = "http://" + addr;
570 emit methodChanged("http-caching");
573 mrl = "https://" + addr;
574 emit methodChanged("http-caching");
577 mrl = "mms://" + addr;
578 emit methodChanged("mms-caching");
581 mrl = "ftp://" + addr;
582 emit methodChanged("ftp-caching");
585 mrl = "rtsp://" + addr;
586 emit methodChanged("rtsp-caching");
589 if(( addr_is_multicast ) || ( !addr_is_ipv4 && !addr_is_ipv6 ))
594 if ( addr_is_ipv6 && !addr.contains('[') )
596 mrl += "[" + addr + "]";
600 mrl += QString(":%1").arg( ui.portSpin->value() );
601 emit methodChanged("udp-caching");
604 if(( addr_is_multicast ) || ( !addr_is_ipv4 && !addr_is_ipv6 ))
608 if ( addr_is_ipv6 && !addr.contains('[') )
609 mrl += "[" + addr + "]"; /* Add [] to IPv6 */
613 mrl += QString(":%1").arg( ui.portSpin->value() );
614 emit methodChanged("rtp-caching");
617 mrl = "rtmp://" + addr;
618 emit methodChanged("rtmp-caching");
623 QStringList qsl; qsl<< mrl;
624 emit mrlUpdated( qsl, "" );
627 void NetOpenPanel::updateCompleter()
630 QStringList tempL = mrlList->stringList();
631 if( !tempL.contains( ui.addressText->text() ) )
632 tempL.append( ui.addressText->text() );
633 mrlList->setStringList( tempL );
636 /**************************************************************************
637 * Open Capture device ( DVB, PVR, V4L, and similar ) *
638 **************************************************************************/
639 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
640 OpenPanel( _parent, _p_intf )
642 isInitialized = false;
645 void CaptureOpenPanel::initialize()
647 if( isInitialized ) return;
649 msg_Dbg( p_intf, "Initialization of Capture device panel" );
650 isInitialized = true;
654 BUTTONACT( ui.advancedButton, advancedDialog() );
656 /* Create two stacked layouts in the main comboBoxes */
657 QStackedLayout *stackedDevLayout = new QStackedLayout;
658 ui.cardBox->setLayout( stackedDevLayout );
660 QStackedLayout *stackedPropLayout = new QStackedLayout;
661 ui.optionsBox->setLayout( stackedPropLayout );
663 /* Creation and connections of the WIdgets in the stacked layout */
664 #define addModuleAndLayouts( number, name, label ) \
665 QWidget * name ## DevPage = new QWidget( this ); \
666 QWidget * name ## PropPage = new QWidget( this ); \
667 stackedDevLayout->addWidget( name ## DevPage ); \
668 stackedPropLayout->addWidget( name ## PropPage ); \
669 QGridLayout * name ## DevLayout = new QGridLayout; \
670 QGridLayout * name ## PropLayout = new QGridLayout; \
671 name ## DevPage->setLayout( name ## DevLayout ); \
672 name ## PropPage->setLayout( name ## PropLayout ); \
673 ui.deviceCombo->addItem( qtr( label ), QVariant( number ) );
675 #define CuMRL( widget, slot ) CONNECT( widget , slot , this, updateMRL() );
678 /*********************
679 * DirectShow Stuffs *
680 *********************/
681 if( module_exists( "dshow" ) ){
682 addModuleAndLayouts( DSHOW_DEVICE, dshow, "DirectShow" );
686 module_config_t *p_config =
687 config_FindConfig( VLC_OBJECT(p_intf), "dshow-vdev" );
688 vdevDshowW = new StringListConfigControl(
689 VLC_OBJECT(p_intf), p_config, this, false, dshowDevLayout, line );
692 p_config = config_FindConfig( VLC_OBJECT(p_intf), "dshow-adev" );
693 adevDshowW = new StringListConfigControl(
694 VLC_OBJECT(p_intf), p_config, this, false, dshowDevLayout, line );
697 /* dshow Properties */
698 QLabel *dshowVSizeLabel = new QLabel( qtr( "Video size" ) );
699 dshowPropLayout->addWidget( dshowVSizeLabel, 0, 0 );
701 dshowVSizeLine = new QLineEdit;
702 dshowPropLayout->addWidget( dshowVSizeLine, 0, 1);
703 dshowPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
707 CuMRL( vdevDshowW->combo, currentIndexChanged ( int ) );
708 CuMRL( adevDshowW->combo, currentIndexChanged ( int ) );
709 CuMRL( dshowVSizeLine, textChanged( const QString& ) );
715 if( module_exists( "bda" ) ){
716 addModuleAndLayouts( BDA_DEVICE, bda, "DVB DirectShow" );
719 QLabel *bdaTypeLabel = new QLabel( qtr( "DVB Type:" ) );
721 bdas = new QRadioButton( "DVB-S" );
722 bdas->setChecked( true );
723 bdac = new QRadioButton( "DVB-C" );
724 bdat = new QRadioButton( "DVB-T" );
725 bdaa = new QRadioButton( "ATSC" );
727 bdaDevLayout->addWidget( bdaTypeLabel, 0, 0 );
728 bdaDevLayout->addWidget( bdas, 0, 1 );
729 bdaDevLayout->addWidget( bdac, 0, 2 );
730 bdaDevLayout->addWidget( bdat, 0, 3 );
731 bdaDevLayout->addWidget( bdaa, 0, 4 );
734 QLabel *bdaFreqLabel =
735 new QLabel( qtr( "Transponder/multiplex frequency" ) );
736 bdaPropLayout->addWidget( bdaFreqLabel, 0, 0 );
738 bdaFreq = new QSpinBox;
739 bdaFreq->setAlignment( Qt::AlignRight );
740 bdaFreq->setSuffix(" kHz");
741 bdaFreq->setSingleStep( 1000 );
742 setSpinBoxFreq( bdaFreq )
743 bdaPropLayout->addWidget( bdaFreq, 0, 1 );
745 bdaSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
746 bdaPropLayout->addWidget( bdaSrateLabel, 1, 0 );
748 bdaSrate = new QSpinBox;
749 bdaSrate->setAlignment( Qt::AlignRight );
750 bdaSrate->setSuffix(" kHz");
751 setSpinBoxFreq( bdaSrate );
752 bdaPropLayout->addWidget( bdaSrate, 1, 1 );
754 bdaBandLabel = new QLabel( qtr( "Bandwidth" ) );
755 bdaPropLayout->addWidget( bdaBandLabel, 2, 0 );
757 bdaBandBox = new QComboBox;
758 setfillVLCConfigCombo( "dvb-bandwidth", p_intf, bdaBandBox );
759 bdaPropLayout->addWidget( bdaBandBox, 2, 1 );
761 bdaBandLabel->hide();
763 bdaPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
767 CuMRL( bdaFreq, valueChanged ( int ) );
768 CuMRL( bdaSrate, valueChanged ( int ) );
769 CuMRL( bdaBandBox, currentIndexChanged ( int ) );
770 BUTTONACT( bdas, updateButtons() );
771 BUTTONACT( bdat, updateButtons() );
772 BUTTONACT( bdac, updateButtons() );
773 BUTTONACT( bdaa, updateButtons() );
774 BUTTONACT( bdas, updateMRL() );
775 BUTTONACT( bdat, updateMRL() );
776 BUTTONACT( bdac, updateMRL() );
777 BUTTONACT( bdaa, updateMRL() );
784 if( module_exists( "v4l2" ) ){
785 addModuleAndLayouts( V4L2_DEVICE, v4l2, "Video for Linux 2" );
788 QLabel *v4l2VideoDeviceLabel = new QLabel( qtr( "Video device name" ) );
789 v4l2DevLayout->addWidget( v4l2VideoDeviceLabel, 0, 0 );
791 v4l2VideoDevice = new QLineEdit;
792 v4l2DevLayout->addWidget( v4l2VideoDevice, 0, 1 );
794 QLabel *v4l2AudioDeviceLabel = new QLabel( qtr( "Audio device name" ) );
795 v4l2DevLayout->addWidget( v4l2AudioDeviceLabel, 1, 0 );
797 v4l2AudioDevice = new QLineEdit;
798 v4l2DevLayout->addWidget( v4l2AudioDevice, 1, 1 );
800 /* v4l2 Props panel */
801 QLabel *v4l2StdLabel = new QLabel( qtr( "Standard" ) );
802 v4l2PropLayout->addWidget( v4l2StdLabel, 0 , 0 );
804 v4l2StdBox = new QComboBox;
805 setfillVLCConfigCombo( "v4l2-standard", p_intf, v4l2StdBox );
806 v4l2PropLayout->addWidget( v4l2StdBox, 0 , 1 );
807 v4l2PropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
811 CuMRL( v4l2VideoDevice, textChanged( const QString& ) );
812 CuMRL( v4l2AudioDevice, textChanged( const QString& ) );
813 CuMRL( v4l2StdBox, currentIndexChanged ( int ) );
819 if( module_exists( "v4l" ) ){
820 addModuleAndLayouts( V4L_DEVICE, v4l, "Video for Linux" );
823 QLabel *v4lVideoDeviceLabel = new QLabel( qtr( "Video device name" ) );
824 v4lDevLayout->addWidget( v4lVideoDeviceLabel, 0, 0 );
826 v4lVideoDevice = new QLineEdit;
827 v4lDevLayout->addWidget( v4lVideoDevice, 0, 1 );
829 QLabel *v4lAudioDeviceLabel = new QLabel( qtr( "Audio device name" ) );
830 v4lDevLayout->addWidget( v4lAudioDeviceLabel, 1, 0 );
832 v4lAudioDevice = new QLineEdit;
833 v4lDevLayout->addWidget( v4lAudioDevice, 1, 1 );
835 /* V4l Props panel */
836 QLabel *v4lNormLabel = new QLabel( qtr( "Norm" ) );
837 v4lPropLayout->addWidget( v4lNormLabel, 0 , 0 );
839 v4lNormBox = new QComboBox;
840 setfillVLCConfigCombo( "v4l-norm", p_intf, v4lNormBox );
841 v4lPropLayout->addWidget( v4lNormBox, 0 , 1 );
843 QLabel *v4lFreqLabel = new QLabel( qtr( "Frequency" ) );
844 v4lPropLayout->addWidget( v4lFreqLabel, 1 , 0 );
846 v4lFreq = new QSpinBox;
847 v4lFreq->setAlignment( Qt::AlignRight );
848 v4lFreq->setSuffix(" kHz");
849 setSpinBoxFreq( v4lFreq );
850 v4lPropLayout->addWidget( v4lFreq, 1 , 1 );
851 v4lPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
855 CuMRL( v4lVideoDevice, textChanged( const QString& ) );
856 CuMRL( v4lAudioDevice, textChanged( const QString& ) );
857 CuMRL( v4lFreq, valueChanged ( int ) );
858 CuMRL( v4lNormBox, currentIndexChanged ( int ) );
864 if( module_exists( "jack" ) ){
865 addModuleAndLayouts( JACK_DEVICE, jack, "JACK Audio Connection Kit" );
867 /* Jack Main panel */
869 QLabel *jackChannelsLabel = new QLabel( qtr( "Channels:" ) );
870 jackDevLayout->addWidget( jackChannelsLabel, 1, 0 );
872 jackChannels = new QSpinBox;
873 setSpinBoxFreq( jackChannels );
874 jackChannels->setMaximum(255);
875 jackChannels->setValue(2);
876 jackChannels->setAlignment( Qt::AlignRight );
877 jackDevLayout->addWidget( jackChannels, 1, 1 );
880 QLabel *jackPortsLabel = new QLabel( qtr( "Selected ports:" ) );
881 jackDevLayout->addWidget( jackPortsLabel, 0 , 0 );
883 jackPortsSelected = new QLineEdit( qtr( ".*") );
884 jackPortsSelected->setAlignment( Qt::AlignRight );
885 jackDevLayout->addWidget( jackPortsSelected, 0, 1 );
887 /* Jack Props panel */
890 QLabel *jackCachingLabel = new QLabel( qtr( "Input caching:" ) );
891 jackPropLayout->addWidget( jackCachingLabel, 1 , 0 );
892 jackCaching = new QSpinBox;
893 setSpinBoxFreq( jackCaching );
894 jackCaching->setSuffix( " ms" );
895 jackCaching->setValue(1000);
896 jackCaching->setAlignment( Qt::AlignRight );
897 jackPropLayout->addWidget( jackCaching, 1 , 2 );
900 jackPace = new QCheckBox(qtr( "Use VLC pace" ));
901 jackPropLayout->addWidget( jackPace, 2, 1 );
904 jackConnect = new QCheckBox( qtr( "Auto connnection" ));
905 jackPropLayout->addWidget( jackConnect, 2, 2 );
908 CuMRL( jackChannels, valueChanged( int ) );
909 CuMRL( jackCaching, valueChanged( int ) );
910 CuMRL( jackPace, stateChanged( int ) );
911 CuMRL( jackConnect, stateChanged( int ) );
912 CuMRL( jackPortsSelected, textChanged( const QString& ) );
918 if( module_exists( "pvr" ) ){
919 addModuleAndLayouts( PVR_DEVICE, pvr, "PVR" );
922 QLabel *pvrDeviceLabel = new QLabel( qtr( "Device name" ) );
923 pvrDevLayout->addWidget( pvrDeviceLabel, 0, 0 );
925 pvrDevice = new QLineEdit;
926 pvrDevLayout->addWidget( pvrDevice, 0, 1 );
928 QLabel *pvrRadioDeviceLabel = new QLabel( qtr( "Radio device name" ) );
929 pvrDevLayout->addWidget( pvrRadioDeviceLabel, 1, 0 );
931 pvrRadioDevice = new QLineEdit;
932 pvrDevLayout->addWidget( pvrRadioDevice, 1, 1 );
934 /* PVR props panel */
935 QLabel *pvrNormLabel = new QLabel( qtr( "Norm" ) );
936 pvrPropLayout->addWidget( pvrNormLabel, 0, 0 );
938 pvrNormBox = new QComboBox;
939 setfillVLCConfigCombo( "pvr-norm", p_intf, pvrNormBox );
940 pvrPropLayout->addWidget( pvrNormBox, 0, 1 );
942 QLabel *pvrFreqLabel = new QLabel( qtr( "Frequency" ) );
943 pvrPropLayout->addWidget( pvrFreqLabel, 1, 0 );
945 pvrFreq = new QSpinBox;
946 pvrFreq->setAlignment( Qt::AlignRight );
947 pvrFreq->setSuffix(" kHz");
948 setSpinBoxFreq( pvrFreq );
949 pvrPropLayout->addWidget( pvrFreq, 1, 1 );
951 QLabel *pvrBitrLabel = new QLabel( qtr( "Bitrate" ) );
952 pvrPropLayout->addWidget( pvrBitrLabel, 2, 0 );
954 pvrBitr = new QSpinBox;
955 pvrBitr->setAlignment( Qt::AlignRight );
956 pvrBitr->setSuffix(" kHz");
957 setSpinBoxFreq( pvrBitr );
958 pvrPropLayout->addWidget( pvrBitr, 2, 1 );
959 pvrPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
963 CuMRL( pvrDevice, textChanged( const QString& ) );
964 CuMRL( pvrRadioDevice, textChanged( const QString& ) );
966 CuMRL( pvrFreq, valueChanged ( int ) );
967 CuMRL( pvrBitr, valueChanged ( int ) );
968 CuMRL( pvrNormBox, currentIndexChanged ( int ) );
974 if( module_exists( "dvb" ) ){
975 addModuleAndLayouts( DVB_DEVICE, dvb, "DVB" );
978 QLabel *dvbDeviceLabel = new QLabel( qtr( "Adapter card to tune" ) );
979 QLabel *dvbTypeLabel = new QLabel( qtr( "DVB Type:" ) );
981 dvbCard = new QSpinBox;
982 dvbCard->setAlignment( Qt::AlignRight );
983 dvbCard->setPrefix( "/dev/dvb/adapter" );
985 dvbDevLayout->addWidget( dvbDeviceLabel, 0, 0 );
986 dvbDevLayout->addWidget( dvbCard, 0, 2, 1, 2 );
988 dvbs = new QRadioButton( "DVB-S" );
989 dvbs->setChecked( true );
990 dvbc = new QRadioButton( "DVB-C" );
991 dvbt = new QRadioButton( "DVB-T" );
993 dvbDevLayout->addWidget( dvbTypeLabel, 1, 0 );
994 dvbDevLayout->addWidget( dvbs, 1, 1 );
995 dvbDevLayout->addWidget( dvbc, 1, 2 );
996 dvbDevLayout->addWidget( dvbt, 1, 3 );
998 /* DVB Props panel */
999 QLabel *dvbFreqLabel =
1000 new QLabel( qtr( "Transponder/multiplex frequency" ) );
1001 dvbPropLayout->addWidget( dvbFreqLabel, 0, 0 );
1003 dvbFreq = new QSpinBox;
1004 dvbFreq->setAlignment( Qt::AlignRight );
1005 dvbFreq->setSuffix(" kHz");
1006 dvbFreq->setSingleStep( 1000 );
1007 setSpinBoxFreq( dvbFreq );
1008 dvbPropLayout->addWidget( dvbFreq, 0, 1 );
1010 dvbSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
1011 dvbPropLayout->addWidget( dvbSrateLabel, 1, 0 );
1013 dvbSrate = new QSpinBox;
1014 dvbSrate->setAlignment( Qt::AlignRight );
1015 dvbSrate->setSuffix(" kHz");
1016 setSpinBoxFreq( dvbSrate );
1017 dvbPropLayout->addWidget( dvbSrate, 1, 1 );
1019 dvbBandLabel = new QLabel( qtr( "Bandwidth" ) );
1020 dvbPropLayout->addWidget( dvbBandLabel, 2, 0 );
1022 dvbBandBox = new QComboBox;
1023 /* This doesn't work since dvb-bandwidth doesn't seem to be a
1025 setfillVLCConfigCombo( "dvb-bandwidth", p_intf, bdaBandBox );
1027 dvbBandBox->addItem( qtr( "Auto" ), 0 );
1028 dvbBandBox->addItem( qtr( "6 MHz" ), 6 );
1029 dvbBandBox->addItem( qtr( "7 MHz" ), 7 );
1030 dvbBandBox->addItem( qtr( "8 MHz" ), 8 );
1031 dvbPropLayout->addWidget( dvbBandBox, 2, 1 );
1033 dvbBandLabel->hide();
1036 dvbPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
1040 CuMRL( dvbCard, valueChanged ( int ) );
1041 CuMRL( dvbFreq, valueChanged ( int ) );
1042 CuMRL( dvbSrate, valueChanged ( int ) );
1043 CuMRL( dvbBandBox, activated ( int ) );
1045 BUTTONACT( dvbs, updateButtons() );
1046 BUTTONACT( dvbt, updateButtons() );
1047 BUTTONACT( dvbc, updateButtons() );
1048 BUTTONACT( dvbs, updateMRL() );
1049 BUTTONACT( dvbt, updateMRL() );
1050 BUTTONACT( dvbc, updateMRL() );
1059 addModuleAndLayouts( SCREEN_DEVICE, screen, "Desktop" );
1060 QLabel *screenLabel = new QLabel( qtr( "Your display will be "
1061 "opened and played in order to stream or save it." ) );
1062 screenLabel->setWordWrap( true );
1063 screenDevLayout->addWidget( screenLabel, 0, 0 );
1065 QLabel *screenFPSLabel = new QLabel(
1066 qtr( "Desired frame rate for the capture." ) );
1067 screenPropLayout->addWidget( screenFPSLabel, 0, 0 );
1069 screenFPS = new QSpinBox;
1070 screenFPS->setValue( 1 );
1071 screenFPS->setAlignment( Qt::AlignRight );
1072 screenPropLayout->addWidget( screenFPS, 0, 1 );
1074 /* General connects */
1075 CONNECT( ui.deviceCombo, activated( int ) ,
1076 stackedDevLayout, setCurrentIndex( int ) );
1077 CONNECT( ui.deviceCombo, activated( int ),
1078 stackedPropLayout, setCurrentIndex( int ) );
1079 CONNECT( ui.deviceCombo, activated( int ), this, updateMRL() );
1080 CONNECT( ui.deviceCombo, activated( int ), this, updateButtons() );
1083 #undef addModuleAndLayouts
1086 CaptureOpenPanel::~CaptureOpenPanel()
1090 void CaptureOpenPanel::clear()
1095 void CaptureOpenPanel::updateMRL()
1098 QStringList fileList;
1099 int i_devicetype = ui.deviceCombo->itemData(
1100 ui.deviceCombo->currentIndex() ).toInt();
1101 switch( i_devicetype )
1105 if( bdas->isChecked() ) mrl = "dvb-s://";
1106 else if( bdat->isChecked() ) mrl = "dvb-t://";
1107 else if( bdac->isChecked() ) mrl = "dvb-c://";
1108 else if( bdaa->isChecked() ) mrl = "atsc://";
1110 mrl += "frequency=" + QString::number( bdaFreq->value() );
1111 if( bdac->isChecked() || bdat->isChecked() || bdaa->isChecked() )
1113 fileList << mrl; mrl = "";
1115 if( bdas->isChecked() || bdac->isChecked() )
1116 mrl += " :dvb-srate=" + QString::number( bdaSrate->value() );
1117 else if( bdat->isChecked() || bdaa->isChecked() )
1118 mrl += " :dvb-bandwidth=" +
1119 QString::number( bdaBandBox->itemData(
1120 bdaBandBox->currentIndex() ).toInt() );
1123 fileList << "dshow://";
1124 mrl+= " :dshow-vdev=" +
1125 colon_escape( QString("%1").arg( vdevDshowW->getValue() ) );
1126 mrl+= " :dshow-adev=" +
1127 colon_escape( QString("%1").arg( adevDshowW->getValue() ) );
1128 if( dshowVSizeLine->isModified() )
1129 mrl += " :dshow-size=" + dshowVSizeLine->text();
1133 fileList << "v4l://";
1134 mrl += " :v4l-vdev=" + v4lVideoDevice->text();
1135 mrl += " :v4l-adev=" + v4lAudioDevice->text();
1136 mrl += " :v4l-norm=" + QString::number( v4lNormBox->currentIndex() );
1137 mrl += " :v4l-frequency=" + QString::number( v4lFreq->value() );
1140 fileList << "v4l2://";
1141 mrl += " :v4l2-dev=" + v4l2VideoDevice->text();
1142 mrl += " :v4l2-adev=" + v4l2AudioDevice->text();
1143 mrl += " :v4l2-standard=" + QString::number( v4l2StdBox->currentIndex() );
1147 mrl += "channels=" + QString::number( jackChannels->value() );
1148 mrl += ":ports=" + jackPortsSelected->text();
1149 fileList << mrl; mrl = "";
1151 mrl += " :jack-input-caching=" + QString::number( jackCaching->value() );
1152 if ( jackPace->isChecked() )
1154 mrl += " :jack-input-use-vlc-pace";
1156 if ( jackConnect->isChecked() )
1158 mrl += " :jack-input-auto-connect";
1162 fileList << "pvr://";
1163 mrl += " :pvr-device=" + pvrDevice->text();
1164 mrl += " :pvr-radio-device=" + pvrRadioDevice->text();
1165 mrl += " :pvr-norm=" + QString::number( pvrNormBox->currentIndex() );
1166 if( pvrFreq->value() )
1167 mrl += " :pvr-frequency=" + QString::number( pvrFreq->value() );
1168 if( pvrBitr->value() )
1169 mrl += " :pvr-bitrate=" + QString::number( pvrBitr->value() );
1173 mrl += "frequency=" + QString::number( dvbFreq->value() );
1174 if( dvbc->isChecked() || dvbt->isChecked() )
1176 fileList << mrl; mrl= "";
1178 mrl += " :dvb-adapter=" + QString::number( dvbCard->value() );
1179 if( dvbs->isChecked() || dvbc->isChecked() )
1180 mrl += " :dvb-srate=" + QString::number( dvbSrate->value() );
1181 else if( dvbt->isChecked() )
1182 mrl += " :dvb-bandwidth=" +
1183 QString::number( dvbBandBox->itemData(
1184 dvbBandBox->currentIndex() ).toInt() );
1189 fileList << "screen://";
1190 mrl = " :screen-fps=" + QString::number( screenFPS->value() );
1195 if( !advMRL.isEmpty() ) mrl += advMRL;
1197 emit mrlUpdated( fileList, mrl );
1201 * Update the Buttons (show/hide) for the GUI as all device type don't
1202 * use the same ui. elements.
1204 void CaptureOpenPanel::updateButtons()
1206 /* Be sure to display the ui Elements in case they were hidden by
1207 * some Device Type (like Screen://) */
1208 ui.optionsBox->show();
1209 ui.advancedButton->show();
1210 /* Get the current Device Number */
1211 int i_devicetype = ui.deviceCombo->itemData(
1212 ui.deviceCombo->currentIndex() ).toInt();
1213 switch( i_devicetype )
1217 if( bdas->isChecked() || bdac->isChecked() )
1220 bdaSrateLabel->show();
1222 bdaBandLabel->hide();
1224 else if( bdat->isChecked() || bdaa->isChecked() )
1227 bdaSrateLabel->hide();
1229 bdaBandLabel->show();
1234 if( dvbs->isChecked() || dvbc->isChecked() )
1237 dvbSrateLabel->show();
1239 dvbBandLabel->hide();
1241 else if( dvbt->isChecked() )
1244 dvbSrateLabel->hide();
1246 dvbBandLabel->show();
1251 //ui.optionsBox->hide();
1252 ui.advancedButton->hide();
1259 void CaptureOpenPanel::advancedDialog()
1261 /* Get selected device type */
1262 int i_devicetype = ui.deviceCombo->itemData(
1263 ui.deviceCombo->currentIndex() ).toInt();
1265 /* Get the corresponding module */
1266 module_t *p_module =
1267 module_find( psz_devModule[i_devicetype] );
1268 if( NULL == p_module ) return;
1271 QList<ConfigControl *> controls;
1273 /* Get the confsize */
1274 unsigned int i_confsize;
1275 module_config_t *p_config;
1276 p_config = module_config_get( p_module, &i_confsize );
1278 /* New Adv Prop dialog */
1279 adv = new QDialog( this );
1280 adv->setWindowTitle( qtr( "Advanced Options" ) );
1282 /* A main Layout with a Frame */
1283 QVBoxLayout *mainLayout = new QVBoxLayout( adv );
1284 QScrollArea *scroll = new QScrollArea;
1285 mainLayout->addWidget( scroll );
1287 QFrame *advFrame = new QFrame;
1288 /* GridLayout inside the Frame */
1289 QGridLayout *gLayout = new QGridLayout( advFrame );
1291 scroll->setWidgetResizable( true );
1292 scroll->setWidget( advFrame );
1294 /* Create the options inside the FrameLayout */
1295 for( int n = 0; n < (int)i_confsize; n++ )
1297 module_config_t *p_item = p_config + n;
1298 ConfigControl *config = ConfigControl::createControl(
1299 VLC_OBJECT( p_intf ), p_item, advFrame, gLayout, n );
1301 controls.append( config );
1305 QDialogButtonBox *advButtonBox = new QDialogButtonBox( adv );
1306 QPushButton *closeButton = new QPushButton( qtr( "OK" ) );
1307 QPushButton *cancelButton = new QPushButton( qtr( "Cancel" ) );
1309 CONNECT( closeButton, clicked(), adv, accept() );
1310 CONNECT( cancelButton, clicked(), adv, reject() );
1312 advButtonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
1313 advButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
1315 mainLayout->addWidget( advButtonBox );
1317 /* Creation of the MRL */
1320 QString tempMRL = "";
1321 for( int i = 0; i < controls.size(); i++ )
1323 ConfigControl *control = controls[i];
1325 tempMRL += (i ? " :" : ":");
1327 if( control->getType() == CONFIG_ITEM_BOOL )
1328 if( !(qobject_cast<VIntConfigControl *>(control)->getValue() ) )
1331 tempMRL += control->getName();
1333 switch( control->getType() )
1335 case CONFIG_ITEM_STRING:
1336 case CONFIG_ITEM_FILE:
1337 case CONFIG_ITEM_DIRECTORY:
1338 case CONFIG_ITEM_MODULE:
1339 tempMRL += colon_escape( QString("=%1").arg( qobject_cast<VStringConfigControl *>(control)->getValue() ) );
1341 case CONFIG_ITEM_INTEGER:
1342 tempMRL += QString("=%1").arg( qobject_cast<VIntConfigControl *>(control)->getValue() );
1344 case CONFIG_ITEM_FLOAT:
1345 tempMRL += QString("=%1").arg( qobject_cast<VFloatConfigControl *>(control)->getValue() );
1351 msg_Dbg( p_intf, "%s", qtu( advMRL ) );
1353 for( int i = 0; i < controls.size(); i++ )
1355 ConfigControl *control = controls[i];
1359 module_config_free( p_config );
1360 module_release (p_module);