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"
38 #include <vlc_intf_strings.h>
39 #include <vlc_modules.h>
41 #include <QFileDialog>
42 #include <QDialogButtonBox>
44 #include <QStackedLayout>
48 #include <QScrollArea>
50 #include <QStringListModel>
53 #define I_DEVICE_TOOLTIP \
54 I_DIR_OR_FOLDER( N_("Select a device or a VIDEO_TS directory"), \
55 N_("Select a device or a VIDEO_TS folder") )
57 /* Populate a combobox with the devices matching a pattern.
58 Combobox will automatically do autocompletion on the edit zone */
59 #define POPULATE_WITH_DEVS(ppsz_devlist, targetCombo) \
60 QStringList targetCombo ## StringList = QStringList(); \
61 for ( int i = 0; i< sizeof(ppsz_devlist) / sizeof(*ppsz_devlist); i++ ) \
62 targetCombo ## StringList << QString( ppsz_devlist[ i ] ); \
63 targetCombo->addItems( QDir( "/dev/" )\
64 .entryList( targetCombo ## StringList, QDir::System )\
65 .replaceInStrings( QRegExp("^"), "/dev/" ) \
68 static const char *psz_devModule[] = { "v4l2", "pvr", "dvb", "bda",
69 "dshow", "screen", "jack" };
71 /**************************************************************************
72 * Open Files and subtitles *
73 **************************************************************************/
74 FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
75 OpenPanel( _parent, _p_intf ), dialogBox( NULL )
77 /* Classic UI Setup */
80 setAcceptDrops( true );
82 /* Set Filters for file selection */
83 /* QString fileTypes = "";
84 ADD_FILTER_MEDIA( fileTypes );
85 ADD_FILTER_VIDEO( fileTypes );
86 ADD_FILTER_AUDIO( fileTypes );
87 ADD_FILTER_PLAYLIST( fileTypes );
88 ADD_FILTER_ALL( fileTypes );
89 fileTypes.replace( QString(";*"), QString(" *")); */
92 /* lineFileEdit = ui.fileEdit;
93 //TODO later: fill the fileCompleteList with previous items played.
94 QCompleter *fileCompleter = new QCompleter( fileCompleteList, this );
95 fileCompleter->setModel( new QDirModel( fileCompleter ) );
96 lineFileEdit->setCompleter( fileCompleter );*/
97 if( var_InheritBool( p_intf, "qt-embedded-open" ) )
99 ui.tempWidget->hide();
104 /* Deactivate the subtitles control by default. */
105 ui.subFrame->setEnabled( false );
106 /* Build the subs size combo box */
107 setfillVLCConfigCombo( "freetype-rel-fontsize" , p_intf,
108 ui.sizeSubComboBox );
109 /* Build the subs align combo box */
110 setfillVLCConfigCombo( "subsdec-align", p_intf, ui.alignSubComboBox );
113 BUTTONACT( ui.fileBrowseButton, browseFile() );
114 BUTTONACT( ui.removeFileButton, removeFile() );
116 BUTTONACT( ui.subBrowseButton, browseFileSub() );
117 CONNECT( ui.subCheckBox, toggled( bool ), this, toggleSubtitleFrame( bool ) );
119 CONNECT( ui.fileListWidg, itemChanged( QListWidgetItem * ), this, updateMRL() );
120 CONNECT( ui.subInput, textChanged( const QString& ), this, updateMRL() );
121 CONNECT( ui.alignSubComboBox, currentIndexChanged( int ), this, updateMRL() );
122 CONNECT( ui.sizeSubComboBox, currentIndexChanged( int ), this, updateMRL() );
126 inline void FileOpenPanel::BuildOldPanel()
128 /** BEGIN QFileDialog tweaking **/
129 /* Use a QFileDialog and customize it because we don't want to
130 rewrite it all. Be careful to your eyes cause there are a few hacks.
131 Be very careful and test correctly when you modify this. */
133 /* Make this QFileDialog a child of tempWidget from the ui. */
134 dialogBox = new FileOpenBox( ui.tempWidget, NULL,
135 p_intf->p_sys->filepath, "" );
137 dialogBox->setFileMode( QFileDialog::ExistingFiles );
138 dialogBox->setAcceptMode( QFileDialog::AcceptOpen );
139 dialogBox->restoreState(
140 getSettings()->value( "file-dialog-state" ).toByteArray() );
142 /* We don't want to see a grip in the middle of the window, do we? */
143 dialogBox->setSizeGripEnabled( false );
146 dialogBox->setToolTip( qtr( "Select one or multiple files" ) );
147 dialogBox->setMinimumHeight( 250 );
149 // But hide the two OK/Cancel buttons. Enable them for debug.
150 QDialogButtonBox *fileDialogAcceptBox =
151 dialogBox->findChildren<QDialogButtonBox*>()[0];
152 fileDialogAcceptBox->hide();
154 /* Ugly hacks to get the good Widget */
155 //This lineEdit is the normal line in the fileDialog.
156 QLineEdit *lineFileEdit = dialogBox->findChildren<QLineEdit*>()[0];
157 /* Make a list of QLabel inside the QFileDialog to access the good ones */
158 QList<QLabel *> listLabel = dialogBox->findChildren<QLabel*>();
160 /* Hide the FileNames one. Enable it for debug */
161 listLabel[1]->setText( qtr( "File names:" ) );
162 /* Change the text that was uncool in the usual box */
163 listLabel[2]->setText( qtr( "Filter:" ) );
165 dialogBox->layout()->setMargin( 0 );
166 dialogBox->layout()->setSizeConstraint( QLayout::SetNoConstraint );
168 /** END of QFileDialog tweaking **/
170 // Add the DialogBox to the layout
171 ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
173 CONNECT( lineFileEdit, textChanged( const QString& ), this, updateMRL() );
174 dialogBox->installEventFilter( this );
177 FileOpenPanel::~FileOpenPanel()
180 getSettings()->setValue( "file-dialog-state", dialogBox->saveState() );
183 void FileOpenPanel::dragEnterEvent( QDragEnterEvent *event )
185 event->acceptProposedAction();
188 void FileOpenPanel::dragMoveEvent( QDragMoveEvent *event )
190 event->acceptProposedAction();
193 void FileOpenPanel::dragLeaveEvent( QDragLeaveEvent *event )
198 void FileOpenPanel::dropEvent( QDropEvent *event )
200 if( event->possibleActions() & Qt::CopyAction )
201 event->setDropAction( Qt::CopyAction );
205 const QMimeData *mimeData = event->mimeData();
206 foreach( const QUrl &url, mimeData->urls() )
210 QListWidgetItem *item = new QListWidgetItem(
211 toNativeSeparators( url.toLocalFile() ),
213 item->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled );
214 ui.fileListWidg->addItem( item );
222 void FileOpenPanel::browseFile()
224 QStringList files = QFileDialog::getOpenFileNames( this, qtr( "Select one or multiple files" ), p_intf->p_sys->filepath) ;
225 foreach( const QString &file, files )
227 QListWidgetItem *item =
228 new QListWidgetItem( toNativeSeparators( file ), ui.fileListWidg );
229 item->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled );
230 ui.fileListWidg->addItem( item );
231 savedirpathFromFile( file );
237 void FileOpenPanel::removeFile()
239 int i = ui.fileListWidg->currentRow();
242 QListWidgetItem *temp = ui.fileListWidg->takeItem( i );
250 /* Show a fileBrowser to select a subtitle */
251 void FileOpenPanel::browseFileSub()
253 // TODO Handle selection of more than one subtitles file
254 QStringList files = THEDP->showSimpleOpen( qtr("Open subtitles file"),
255 EXT_FILTER_SUBTITLE, p_intf->p_sys->filepath );
257 if( files.isEmpty() ) return;
258 ui.subInput->setText( toNativeSeparators( files.join(" ") ) );
262 void FileOpenPanel::toggleSubtitleFrame( bool b )
264 ui.subFrame->setEnabled( b );
271 /* Update the current MRL */
272 void FileOpenPanel::updateMRL()
274 QStringList fileList;
278 if( dialogBox == NULL )
279 for( int i = 0; i < ui.fileListWidg->count(); i++ )
281 if( !ui.fileListWidg->item( i )->text().isEmpty() )
282 fileList << toURI(ui.fileListWidg->item( i )->text());
286 fileList = dialogBox->selectedFiles();
287 for( int i = 0; i < fileList.count(); i++ )
288 fileList[i] = toURI( fileList[i] );
292 if( ui.subCheckBox->isChecked() && !ui.subInput->text().isEmpty() ) {
293 mrl.append( " :sub-file=" + colon_escape( ui.subInput->text() ) );
294 int align = ui.alignSubComboBox->itemData(
295 ui.alignSubComboBox->currentIndex() ).toInt();
296 mrl.append( " :subsdec-align=" + QString().setNum( align ) );
297 int size = ui.sizeSubComboBox->itemData(
298 ui.sizeSubComboBox->currentIndex() ).toInt();
299 mrl.append( " :freetype-rel-fontsize=" + QString().setNum( size ) );
302 emit mrlUpdated( fileList, mrl );
303 emit methodChanged( "file-caching" );
306 /* Function called by Open Dialog when clicke on Play/Enqueue */
307 void FileOpenPanel::accept()
310 p_intf->p_sys->filepath = dialogBox->directory().absolutePath();
311 ui.fileListWidg->clear();
314 /* Function called by Open Dialog when clicked on cancel */
315 void FileOpenPanel::clear()
317 ui.fileListWidg->clear();
318 ui.subInput->clear();
321 /* Update buttons depending on current selection */
322 void FileOpenPanel::updateButtons()
324 bool b_has_files = ( ui.fileListWidg->count() > 0 );
325 ui.removeFileButton->setEnabled( b_has_files );
326 ui.subCheckBox->setEnabled( b_has_files );
329 /**************************************************************************
330 * Open Discs ( DVD, CD, VCD and similar devices ) *
331 **************************************************************************/
332 DiscOpenPanel::DiscOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
333 OpenPanel( _parent, _p_intf )
337 /* Get the default configuration path for the devices */
338 psz_dvddiscpath = var_InheritString( p_intf, "dvd" );
339 psz_vcddiscpath = var_InheritString( p_intf, "vcd" );
340 psz_cddadiscpath = var_InheritString( p_intf, "cd-audio" );
342 /* State to avoid overwritting the users changes with the configuration */
345 ui.browseDiscButton->setToolTip( qtr( I_DEVICE_TOOLTIP ));
346 ui.deviceCombo->setToolTip( qtr(I_DEVICE_TOOLTIP) );
348 #ifdef WIN32 /* Disc drives probing for Windows */
351 if( GetLogicalDriveStringsA( sizeof( szDrives ) - 1, szDrives ) )
353 char *drive = szDrives;
354 UINT oldMode = SetErrorMode( SEM_FAILCRITICALERRORS );
357 if( GetDriveTypeA(drive) == DRIVE_CDROM )
359 ui.deviceCombo->addItem( drive );
362 /* go to next drive */
365 SetErrorMode(oldMode);
368 char const * const ppsz_discdevices[] = {
375 QComboBox *discCombo = ui.deviceCombo; /* avoid namespacing in macro */
376 POPULATE_WITH_DEVS( ppsz_discdevices, discCombo );
380 BUTTONACT( ui.dvdRadioButton, updateButtons() );
381 BUTTONACT( ui.vcdRadioButton, updateButtons() );
382 BUTTONACT( ui.audioCDRadioButton, updateButtons() );
383 BUTTONACT( ui.dvdsimple, updateButtons() );
384 BUTTONACT( ui.browseDiscButton, browseDevice() );
385 BUTTON_SET_ACT_I( ui.ejectButton, "", toolbar/eject, qtr( "Eject the disc" ),
388 CONNECT( ui.deviceCombo, editTextChanged( QString ), this, updateMRL());
389 CONNECT( ui.titleSpin, valueChanged( int ), this, updateMRL());
390 CONNECT( ui.chapterSpin, valueChanged( int ), this, updateMRL());
391 CONNECT( ui.audioSpin, valueChanged( int ), this, updateMRL());
392 CONNECT( ui.subtitlesSpin, valueChanged( int ), this, updateMRL());
394 /* Run once the updateButtons function in order to fill correctly the comboBoxes */
398 DiscOpenPanel::~DiscOpenPanel()
400 free( psz_dvddiscpath );
401 free( psz_vcddiscpath );
402 free( psz_cddadiscpath );
405 void DiscOpenPanel::clear()
407 ui.titleSpin->setValue( 0 );
408 ui.chapterSpin->setValue( 0 );
409 ui.subtitlesSpin->setValue( -1 );
410 ui.audioSpin->setValue( -1 );
415 #define setDrive( psz_name ) {\
416 int index = ui.deviceCombo->findText( qfu( psz_name ) ); \
417 if( index != -1 ) ui.deviceCombo->setCurrentIndex( index );}
419 #define setDrive( psz_name ) {\
420 ui.deviceCombo->setEditText( qfu( psz_name ) ); }
423 /* update the buttons according the type of device */
424 void DiscOpenPanel::updateButtons()
426 if ( ui.dvdRadioButton->isChecked() )
428 if( m_discType != Dvd )
430 setDrive( psz_dvddiscpath );
433 ui.titleLabel->setText( qtr("Title") );
434 ui.chapterLabel->show();
435 ui.chapterSpin->show();
436 ui.diskOptionBox_2->show();
437 ui.dvdsimple->setEnabled( true );
439 else if ( ui.vcdRadioButton->isChecked() )
441 if( m_discType != Vcd )
443 setDrive( psz_vcddiscpath );
446 ui.titleLabel->setText( qtr("Entry") );
447 ui.chapterLabel->hide();
448 ui.chapterSpin->hide();
449 ui.diskOptionBox_2->show();
450 ui.dvdsimple->setEnabled( false );
454 if( m_discType != Cdda )
456 setDrive( psz_cddadiscpath );
459 ui.titleLabel->setText( qtr("Track") );
460 ui.chapterLabel->hide();
461 ui.chapterSpin->hide();
462 ui.diskOptionBox_2->hide();
463 ui.dvdsimple->setEnabled( false );
472 # define LOCALHOST ""
474 # define LOCALHOST "/"
477 /* Update the current MRL */
478 void DiscOpenPanel::updateMRL()
482 QStringList fileList;
484 if( ui.deviceCombo->itemData( ui.deviceCombo->currentIndex() ) != QVariant::Invalid )
485 discPath = ui.deviceCombo->itemData( ui.deviceCombo->currentIndex() ).toString();
487 discPath = ui.deviceCombo->currentText();
489 /* CDDAX and VCDX not implemented. TODO ? No. */
491 if( ui.dvdRadioButton->isChecked() ) {
492 if( !ui.dvdsimple->isChecked() )
493 mrl = "dvd://" LOCALHOST + discPath;
495 mrl = "dvdsimple://" LOCALHOST + discPath;
497 if( !ui.dvdsimple->isChecked() )
498 emit methodChanged( "dvdnav-caching" );
500 emit methodChanged( "dvdread-caching" );
502 if ( ui.titleSpin->value() > 0 ) {
503 mrl += QString("@%1").arg( ui.titleSpin->value() );
504 if ( ui.chapterSpin->value() > 0 ) {
505 mrl+= QString(":%1").arg( ui.chapterSpin->value() );
510 } else if ( ui.vcdRadioButton->isChecked() ) {
511 mrl = "vcd://" LOCALHOST + discPath;
512 emit methodChanged( "vcd-caching" );
514 if( ui.titleSpin->value() > 0 ) {
515 mrl += QString("@E%1").arg( ui.titleSpin->value() );
520 mrl = "cdda://" LOCALHOST + discPath;
521 emit methodChanged( "cdda-caching" );
524 fileList << mrl; mrl = "";
526 if ( ui.dvdRadioButton->isChecked() || ui.vcdRadioButton->isChecked() )
528 if ( ui.audioSpin->value() >= 0 ) {
529 mrl += " :audio-track=" +
530 QString("%1").arg( ui.audioSpin->value() );
532 if ( ui.subtitlesSpin->value() >= 0 ) {
533 mrl += " :sub-track=" +
534 QString("%1").arg( ui.subtitlesSpin->value() );
539 if( ui.titleSpin->value() > 0 )
540 mrl += QString(" :cdda-track=%1").arg( ui.titleSpin->value() );
542 emit mrlUpdated( fileList, mrl );
545 void DiscOpenPanel::browseDevice()
547 QString dir = QFileDialog::getExistingDirectory( this,
548 qtr( I_DEVICE_TOOLTIP ) );
550 ui.deviceCombo->setEditText( toNativeSepNoSlash( dir ) );
555 void DiscOpenPanel::eject()
557 intf_Eject( p_intf, qtu( ui.deviceCombo->currentText() ) );
560 void DiscOpenPanel::accept()
563 /**************************************************************************
564 * Open Network streams and URL pages *
565 **************************************************************************/
566 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
567 OpenPanel( _parent, _p_intf )
572 CONNECT( ui.urlComboBox->lineEdit(), textChanged( const QString& ), this, updateMRL());
573 CONNECT( ui.urlComboBox, currentIndexChanged( const QString& ), this, updateMRL());
575 if( var_InheritBool( p_intf, "qt-recentplay" ) )
577 mrlList = new QStringListModel(
578 getSettings()->value( "Open/netMRL" ).toStringList() );
579 ui.urlComboBox->setModel( mrlList );
580 ui.urlComboBox->clearEditText();
581 CONNECT( ui.urlComboBox->lineEdit(), editingFinished(), this, updateModel() );
586 ui.urlComboBox->setValidator( new UrlValidator( this ) );
587 ui.urlComboBox->setFocus();
590 NetOpenPanel::~NetOpenPanel()
592 if( !mrlList ) return;
594 QStringList tempL = mrlList->stringList();
595 while( tempL.size() > 8 ) tempL.removeFirst();
597 getSettings()->setValue( "Open/netMRL", tempL );
602 void NetOpenPanel::clear()
605 void NetOpenPanel::onFocus()
607 ui.urlComboBox->setFocus();
608 ui.urlComboBox->lineEdit()->selectAll();
611 static int strcmp_void( const void *k, const void *e )
613 return strcmp( (const char *)k, (const char *)e );
616 void NetOpenPanel::updateMRL()
618 static const struct caching_map
623 { /* KEEP alphabetical order on first column!! */
641 QString url = ui.urlComboBox->lineEdit()->text();
642 if( !url.contains( "://") )
643 return; /* nothing to do this far */
645 /* Match the correct item in the comboBox */
646 QString proto = url.section( ':', 0, 0 );
647 const struct caching_map *r = (const struct caching_map *)
648 bsearch( qtu(proto), schemes, sizeof(schemes) / sizeof(schemes[0]),
649 sizeof(schemes[0]), strcmp_void );
651 emit methodChanged( qfu( r->caching ) + qfu( "-caching" ) );
655 emit mrlUpdated( qsl, "" );
658 void NetOpenPanel::updateModel()
661 QStringList tempL = mrlList->stringList();
662 if( !tempL.contains( ui.urlComboBox->lineEdit()->text() ) )
663 tempL.append( ui.urlComboBox->lineEdit()->text() );
664 mrlList->setStringList( tempL );
667 void UrlValidator::fixup( QString& str ) const
672 QValidator::State UrlValidator::validate( QString& str, int& pos ) const
674 if( str.contains( ' ' ) )
675 return QValidator::Invalid;
676 if( !str.contains( "://" ) )
677 return QValidator::Intermediate;
678 return QValidator::Acceptable;
681 /**************************************************************************
682 * Open Capture device ( DVB, PVR, V4L, and similar ) *
683 **************************************************************************/
684 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
685 OpenPanel( _parent, _p_intf )
687 isInitialized = false;
690 void CaptureOpenPanel::initialize()
692 if( isInitialized ) return;
694 msg_Dbg( p_intf, "Initialization of Capture device panel" );
695 isInitialized = true;
699 BUTTONACT( ui.advancedButton, advancedDialog() );
701 /* Create two stacked layouts in the main comboBoxes */
702 QStackedLayout *stackedDevLayout = new QStackedLayout;
703 ui.cardBox->setLayout( stackedDevLayout );
705 QStackedLayout *stackedPropLayout = new QStackedLayout;
706 ui.optionsBox->setLayout( stackedPropLayout );
708 /* Creation and connections of the WIdgets in the stacked layout */
709 #define addModuleAndLayouts( number, name, label, layout ) \
710 QWidget * name ## DevPage = new QWidget( this ); \
711 QWidget * name ## PropPage = new QWidget( this ); \
712 stackedDevLayout->addWidget( name ## DevPage ); \
713 stackedPropLayout->addWidget( name ## PropPage ); \
714 layout * name ## DevLayout = new layout; \
715 layout * name ## PropLayout = new layout; \
716 name ## DevPage->setLayout( name ## DevLayout ); \
717 name ## PropPage->setLayout( name ## PropLayout ); \
718 ui.deviceCombo->addItem( qtr( label ), QVariant( number ) );
720 #define CuMRL( widget, slot ) CONNECT( widget , slot , this, updateMRL() );
723 /*********************
724 * DirectShow Stuffs *
725 *********************/
726 if( module_exists( "dshow" ) ){
727 addModuleAndLayouts( DSHOW_DEVICE, dshow, "DirectShow", QGridLayout );
731 module_config_t *p_config =
732 config_FindConfig( VLC_OBJECT(p_intf), "dshow-vdev" );
733 vdevDshowW = new StringListConfigControl(
734 VLC_OBJECT(p_intf), p_config, this, false, dshowDevLayout, line );
737 p_config = config_FindConfig( VLC_OBJECT(p_intf), "dshow-adev" );
738 adevDshowW = new StringListConfigControl(
739 VLC_OBJECT(p_intf), p_config, this, false, dshowDevLayout, line );
742 /* dshow Properties */
743 QLabel *dshowVSizeLabel = new QLabel( qtr( "Video size" ) );
744 dshowPropLayout->addWidget( dshowVSizeLabel, 0, 0 );
746 dshowVSizeLine = new QLineEdit;
747 dshowPropLayout->addWidget( dshowVSizeLine, 0, 1);
748 dshowPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
752 CuMRL( vdevDshowW->combo, currentIndexChanged ( int ) );
753 CuMRL( adevDshowW->combo, currentIndexChanged ( int ) );
754 CuMRL( dshowVSizeLine, textChanged( const QString& ) );
760 if( module_exists( "bda" ) ){
761 addModuleAndLayouts( BDA_DEVICE, bda, "DVB DirectShow", QGridLayout );
764 QLabel *bdaTypeLabel = new QLabel( qtr( "DVB Type:" ) );
766 bdas = new QRadioButton( "DVB-S" );
767 bdas->setChecked( true );
768 bdac = new QRadioButton( "DVB-C" );
769 bdat = new QRadioButton( "DVB-T" );
770 bdaa = new QRadioButton( "ATSC" );
771 bdaq = new QRadioButton( "Clear QAM" );
773 bdaDevLayout->addWidget( bdaTypeLabel, 0, 0 );
774 bdaDevLayout->addWidget( bdas, 0, 1 );
775 bdaDevLayout->addWidget( bdac, 0, 2 );
776 bdaDevLayout->addWidget( bdat, 0, 3 );
777 bdaDevLayout->addWidget( bdaa, 0, 4 );
778 bdaDevLayout->addWidget( bdaq, 0, 5 );
781 QLabel *bdaFreqLabel =
782 new QLabel( qtr( "Transponder/multiplex frequency" ) );
783 bdaPropLayout->addWidget( bdaFreqLabel, 0, 0 );
785 bdaFreq = new QSpinBox;
786 bdaFreq->setAlignment( Qt::AlignRight );
787 bdaFreq->setSuffix(" kHz");
788 bdaFreq->setSingleStep( 1000 );
789 setSpinBoxFreq( bdaFreq )
790 bdaPropLayout->addWidget( bdaFreq, 0, 1 );
792 bdaSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
793 bdaPropLayout->addWidget( bdaSrateLabel, 1, 0 );
795 bdaSrate = new QSpinBox;
796 bdaSrate->setAlignment( Qt::AlignRight );
797 bdaSrate->setSuffix(" kHz");
798 setSpinBoxFreq( bdaSrate );
799 bdaPropLayout->addWidget( bdaSrate, 1, 1 );
801 bdaBandLabel = new QLabel( qtr( "Bandwidth" ) );
802 bdaPropLayout->addWidget( bdaBandLabel, 2, 0 );
804 bdaBandBox = new QComboBox;
805 setfillVLCConfigCombo( "dvb-bandwidth", p_intf, bdaBandBox );
806 bdaPropLayout->addWidget( bdaBandBox, 2, 1 );
808 bdaBandLabel->hide();
810 bdaPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
814 CuMRL( bdaFreq, valueChanged ( int ) );
815 CuMRL( bdaSrate, valueChanged ( int ) );
816 CuMRL( bdaBandBox, currentIndexChanged ( int ) );
817 BUTTONACT( bdas, updateButtons() );
818 BUTTONACT( bdat, updateButtons() );
819 BUTTONACT( bdac, updateButtons() );
820 BUTTONACT( bdaa, updateButtons() );
821 BUTTONACT( bdaq, updateButtons() );
822 BUTTONACT( bdas, updateMRL() );
823 BUTTONACT( bdat, updateMRL() );
824 BUTTONACT( bdac, updateMRL() );
825 BUTTONACT( bdaa, updateMRL() );
826 BUTTONACT( bdaq, updateMRL() );
833 if( module_exists( "v4l2" ) ){
834 addModuleAndLayouts( V4L2_DEVICE, v4l2, "Video for Linux 2", QGridLayout );
836 char const * const ppsz_v4lvdevices[] = {
840 char const * const ppsz_v4ladevices[] = {
846 QLabel *v4l2VideoDeviceLabel = new QLabel( qtr( "Video device name" ) );
847 v4l2DevLayout->addWidget( v4l2VideoDeviceLabel, 0, 0 );
849 v4l2VideoDevice = new QComboBox( this );
850 v4l2VideoDevice->setEditable( true );
851 POPULATE_WITH_DEVS( ppsz_v4lvdevices, v4l2VideoDevice );
852 v4l2VideoDevice->clearEditText();
853 v4l2DevLayout->addWidget( v4l2VideoDevice, 0, 1 );
855 QLabel *v4l2AudioDeviceLabel = new QLabel( qtr( "Audio device name" ) );
856 v4l2DevLayout->addWidget( v4l2AudioDeviceLabel, 1, 0 );
858 v4l2AudioDevice = new QComboBox( this );
859 v4l2AudioDevice->setEditable( true );
860 POPULATE_WITH_DEVS( ppsz_v4ladevices, v4l2AudioDevice );
861 v4l2AudioDevice->clearEditText();
862 v4l2DevLayout->addWidget( v4l2AudioDevice, 1, 1 );
864 /* v4l2 Props panel */
865 QLabel *v4l2StdLabel = new QLabel( qtr( "Video standard" ) );
866 v4l2PropLayout->addWidget( v4l2StdLabel, 0 , 0 );
868 v4l2StdBox = new QComboBox;
869 setfillVLCConfigCombo( "v4l2-standard", p_intf, v4l2StdBox );
870 v4l2PropLayout->addWidget( v4l2StdBox, 0 , 1 );
871 v4l2PropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
875 CuMRL( v4l2VideoDevice->lineEdit(), textChanged( const QString& ) );
876 CuMRL( v4l2VideoDevice, currentIndexChanged ( int ) );
877 CuMRL( v4l2AudioDevice->lineEdit(), textChanged( const QString& ) );
878 CuMRL( v4l2AudioDevice, currentIndexChanged ( int ) );
879 CuMRL( v4l2StdBox, currentIndexChanged ( int ) );
885 if( module_exists( "jack" ) ){
886 addModuleAndLayouts( JACK_DEVICE, jack, "JACK Audio Connection Kit",
889 /* Jack Main panel */
891 QLabel *jackChannelsLabel = new QLabel( qtr( "Channels:" ) );
892 jackDevLayout->addWidget( jackChannelsLabel, 1, 0 );
894 jackChannels = new QSpinBox;
895 setSpinBoxFreq( jackChannels );
896 jackChannels->setMaximum(255);
897 jackChannels->setValue(2);
898 jackChannels->setAlignment( Qt::AlignRight );
899 jackDevLayout->addWidget( jackChannels, 1, 1 );
902 QLabel *jackPortsLabel = new QLabel( qtr( "Selected ports:" ) );
903 jackDevLayout->addWidget( jackPortsLabel, 0 , 0 );
905 jackPortsSelected = new QLineEdit( qtr( ".*") );
906 jackPortsSelected->setAlignment( Qt::AlignRight );
907 jackDevLayout->addWidget( jackPortsSelected, 0, 1 );
909 /* Jack Props panel */
912 QLabel *jackCachingLabel = new QLabel( qtr( "Input caching:" ) );
913 jackPropLayout->addWidget( jackCachingLabel, 1 , 0 );
914 jackCaching = new QSpinBox;
915 setSpinBoxFreq( jackCaching );
916 jackCaching->setSuffix( " ms" );
917 jackCaching->setValue(1000);
918 jackCaching->setAlignment( Qt::AlignRight );
919 jackPropLayout->addWidget( jackCaching, 1 , 2 );
922 jackPace = new QCheckBox(qtr( "Use VLC pace" ));
923 jackPropLayout->addWidget( jackPace, 2, 1 );
926 jackConnect = new QCheckBox( qtr( "Auto connection" ));
927 jackPropLayout->addWidget( jackConnect, 2, 2 );
930 CuMRL( jackChannels, valueChanged( int ) );
931 CuMRL( jackCaching, valueChanged( int ) );
932 CuMRL( jackPace, stateChanged( int ) );
933 CuMRL( jackConnect, stateChanged( int ) );
934 CuMRL( jackPortsSelected, textChanged( const QString& ) );
940 if( module_exists( "pvr" ) ){
941 addModuleAndLayouts( PVR_DEVICE, pvr, "PVR", QGridLayout );
944 QLabel *pvrDeviceLabel = new QLabel( qtr( "Device name" ) );
945 pvrDevLayout->addWidget( pvrDeviceLabel, 0, 0 );
947 pvrDevice = new QLineEdit;
948 pvrDevLayout->addWidget( pvrDevice, 0, 1 );
950 QLabel *pvrRadioDeviceLabel = new QLabel( qtr( "Radio device name" ) );
951 pvrDevLayout->addWidget( pvrRadioDeviceLabel, 1, 0 );
953 pvrRadioDevice = new QLineEdit;
954 pvrDevLayout->addWidget( pvrRadioDevice, 1, 1 );
956 /* PVR props panel */
957 QLabel *pvrNormLabel = new QLabel( qtr( "Norm" ) );
958 pvrPropLayout->addWidget( pvrNormLabel, 0, 0 );
960 pvrNormBox = new QComboBox;
961 setfillVLCConfigCombo( "pvr-norm", p_intf, pvrNormBox );
962 pvrPropLayout->addWidget( pvrNormBox, 0, 1 );
964 QLabel *pvrFreqLabel = new QLabel( qtr( "Frequency" ) );
965 pvrPropLayout->addWidget( pvrFreqLabel, 1, 0 );
967 pvrFreq = new QSpinBox;
968 pvrFreq->setAlignment( Qt::AlignRight );
969 pvrFreq->setSuffix(" kHz");
970 setSpinBoxFreq( pvrFreq );
971 pvrPropLayout->addWidget( pvrFreq, 1, 1 );
973 QLabel *pvrBitrLabel = new QLabel( qtr( "Bitrate" ) );
974 pvrPropLayout->addWidget( pvrBitrLabel, 2, 0 );
976 pvrBitr = new QSpinBox;
977 pvrBitr->setAlignment( Qt::AlignRight );
978 pvrBitr->setSuffix(" kHz");
979 setSpinBoxFreq( pvrBitr );
980 pvrPropLayout->addWidget( pvrBitr, 2, 1 );
981 pvrPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
985 CuMRL( pvrDevice, textChanged( const QString& ) );
986 CuMRL( pvrRadioDevice, textChanged( const QString& ) );
988 CuMRL( pvrFreq, valueChanged ( int ) );
989 CuMRL( pvrBitr, valueChanged ( int ) );
990 CuMRL( pvrNormBox, currentIndexChanged ( int ) );
996 if( module_exists( "dvb" ) ){
997 addModuleAndLayouts( DVB_DEVICE, dvb, "DVB", QGridLayout );
1000 QLabel *dvbDeviceLabel = new QLabel( qtr( "Adapter card to tune" ) );
1001 QLabel *dvbTypeLabel = new QLabel( qtr( "DVB Type:" ) );
1003 dvbCard = new QSpinBox;
1004 dvbCard->setAlignment( Qt::AlignRight );
1005 dvbCard->setPrefix( "/dev/dvb/adapter" );
1007 dvbDevLayout->addWidget( dvbDeviceLabel, 0, 0 );
1008 dvbDevLayout->addWidget( dvbCard, 0, 2, 1, 2 );
1010 dvbs = new QRadioButton( "DVB-S" );
1011 dvbs->setChecked( true );
1012 dvbc = new QRadioButton( "DVB-C" );
1013 dvbt = new QRadioButton( "DVB-T" );
1015 dvbDevLayout->addWidget( dvbTypeLabel, 1, 0 );
1016 dvbDevLayout->addWidget( dvbs, 1, 1 );
1017 dvbDevLayout->addWidget( dvbc, 1, 2 );
1018 dvbDevLayout->addWidget( dvbt, 1, 3 );
1020 /* DVB Props panel */
1021 QLabel *dvbFreqLabel =
1022 new QLabel( qtr( "Transponder/multiplex frequency" ) );
1023 dvbPropLayout->addWidget( dvbFreqLabel, 0, 0 );
1025 dvbFreq = new QSpinBox;
1026 dvbFreq->setAlignment( Qt::AlignRight );
1027 dvbFreq->setSuffix(" kHz");
1028 dvbFreq->setSingleStep( 1000 );
1029 setSpinBoxFreq( dvbFreq );
1030 dvbPropLayout->addWidget( dvbFreq, 0, 1 );
1032 dvbSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
1033 dvbPropLayout->addWidget( dvbSrateLabel, 1, 0 );
1035 dvbSrate = new QSpinBox;
1036 dvbSrate->setAlignment( Qt::AlignRight );
1037 dvbSrate->setSuffix(" kHz");
1038 setSpinBoxFreq( dvbSrate );
1039 dvbPropLayout->addWidget( dvbSrate, 1, 1 );
1041 dvbBandLabel = new QLabel( qtr( "Bandwidth" ) );
1042 dvbPropLayout->addWidget( dvbBandLabel, 2, 0 );
1044 dvbBandBox = new QComboBox;
1045 /* This doesn't work since dvb-bandwidth doesn't seem to be a
1047 setfillVLCConfigCombo( "dvb-bandwidth", p_intf, bdaBandBox );
1049 dvbBandBox->addItem( qtr( "Auto" ), 0 );
1050 dvbBandBox->addItem( qtr( "6 MHz" ), 6 );
1051 dvbBandBox->addItem( qtr( "7 MHz" ), 7 );
1052 dvbBandBox->addItem( qtr( "8 MHz" ), 8 );
1053 dvbPropLayout->addWidget( dvbBandBox, 2, 1 );
1055 dvbBandLabel->hide();
1058 dvbPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
1062 CuMRL( dvbCard, valueChanged ( int ) );
1063 CuMRL( dvbFreq, valueChanged ( int ) );
1064 CuMRL( dvbSrate, valueChanged ( int ) );
1065 CuMRL( dvbBandBox, currentIndexChanged ( int ) );
1067 BUTTONACT( dvbs, updateButtons() );
1068 BUTTONACT( dvbt, updateButtons() );
1069 BUTTONACT( dvbc, updateButtons() );
1070 BUTTONACT( dvbs, updateMRL() );
1071 BUTTONACT( dvbt, updateMRL() );
1072 BUTTONACT( dvbc, updateMRL() );
1081 addModuleAndLayouts( SCREEN_DEVICE, screen, "Desktop", QGridLayout );
1082 QLabel *screenLabel = new QLabel( qtr( "Your display will be "
1083 "opened and played in order to stream or save it." ) );
1084 screenLabel->setWordWrap( true );
1085 screenDevLayout->addWidget( screenLabel, 0, 0 );
1087 QLabel *screenFPSLabel = new QLabel(
1088 qtr( "Desired frame rate for the capture." ) );
1089 screenPropLayout->addWidget( screenFPSLabel, 0, 0 );
1091 screenFPS = new QDoubleSpinBox;
1092 screenFPS->setValue( 1. );
1093 screenFPS->setRange( .01, 100. );
1094 screenFPS->setAlignment( Qt::AlignRight );
1095 /* xgettext: frames per second */
1096 screenFPS->setSuffix( qtr( " f/s" ) );
1097 screenPropLayout->addWidget( screenFPS, 0, 1 );
1099 /* Screen connect */
1100 CuMRL( screenFPS, valueChanged( double ) );
1102 /* General connects */
1103 CONNECT( ui.deviceCombo, activated( int ) ,
1104 stackedDevLayout, setCurrentIndex( int ) );
1105 CONNECT( ui.deviceCombo, activated( int ),
1106 stackedPropLayout, setCurrentIndex( int ) );
1107 CONNECT( ui.deviceCombo, activated( int ), this, updateMRL() );
1108 CONNECT( ui.deviceCombo, activated( int ), this, updateButtons() );
1111 #undef addModuleAndLayouts
1114 CaptureOpenPanel::~CaptureOpenPanel()
1118 void CaptureOpenPanel::clear()
1123 void CaptureOpenPanel::updateMRL()
1126 QStringList fileList;
1127 int i_devicetype = ui.deviceCombo->itemData(
1128 ui.deviceCombo->currentIndex() ).toInt();
1129 switch( i_devicetype )
1133 if( bdas->isChecked() ) mrl = "dvb-s://";
1134 else if( bdat->isChecked() ) mrl = "dvb-t://";
1135 else if( bdac->isChecked() ) mrl = "dvb-c://";
1136 else if( bdaa->isChecked() ) mrl = "atsc://";
1137 else if( bdaq->isChecked() ) mrl = "cqam://";
1139 mrl += "frequency=" + QString::number( bdaFreq->value() );
1140 if( bdac->isChecked() || bdat->isChecked() || bdaa->isChecked() )
1142 fileList << mrl; mrl = "";
1144 if( bdas->isChecked() || bdac->isChecked() )
1145 mrl += " :dvb-srate=" + QString::number( bdaSrate->value() );
1146 else if( bdat->isChecked() || bdaa->isChecked() )
1147 mrl += " :dvb-bandwidth=" +
1148 QString::number( bdaBandBox->itemData(
1149 bdaBandBox->currentIndex() ).toInt() );
1150 emit methodChanged( "dvb-caching" );
1153 fileList << "dshow://";
1154 mrl+= " :dshow-vdev=" +
1155 colon_escape( QString("%1").arg( vdevDshowW->getValue() ) );
1156 mrl+= " :dshow-adev=" +
1157 colon_escape( QString("%1").arg( adevDshowW->getValue() ) )+" ";
1158 if( dshowVSizeLine->isModified() )
1159 mrl += ":dshow-size=" + dshowVSizeLine->text();
1160 emit methodChanged( "dshow-caching" );
1164 fileList << "v4l2://" + v4l2VideoDevice->currentText();
1165 mrl += " :input-slave=alsa://" + v4l2AudioDevice->currentText();
1166 mrl += " :v4l2-standard=" + QString::number( v4l2StdBox->currentIndex() );
1170 mrl += "channels=" + QString::number( jackChannels->value() );
1171 mrl += ":ports=" + jackPortsSelected->text();
1172 fileList << mrl; mrl = "";
1174 mrl += " :jack-input-caching=" + QString::number( jackCaching->value() );
1175 if ( jackPace->isChecked() )
1177 mrl += " :jack-input-use-vlc-pace";
1179 if ( jackConnect->isChecked() )
1181 mrl += " :jack-input-auto-connect";
1185 fileList << "pvr://";
1186 mrl += " :pvr-device=" + pvrDevice->text();
1187 mrl += " :pvr-radio-device=" + pvrRadioDevice->text();
1188 mrl += " :pvr-norm=" + QString::number( pvrNormBox->currentIndex() );
1189 if( pvrFreq->value() )
1190 mrl += " :pvr-frequency=" + QString::number( pvrFreq->value() );
1191 if( pvrBitr->value() )
1192 mrl += " :pvr-bitrate=" + QString::number( pvrBitr->value() );
1196 mrl += "frequency=" + QString::number( dvbFreq->value() );
1197 if( dvbc->isChecked() || dvbt->isChecked() )
1199 fileList << mrl; mrl= "";
1201 mrl += " :dvb-adapter=" + QString::number( dvbCard->value() );
1202 if( dvbs->isChecked() || dvbc->isChecked() )
1203 mrl += " :dvb-srate=" + QString::number( dvbSrate->value() );
1204 else if( dvbt->isChecked() )
1205 mrl += " :dvb-bandwidth=" +
1206 QString::number( dvbBandBox->itemData(
1207 dvbBandBox->currentIndex() ).toInt() );
1212 fileList << "screen://";
1213 mrl = " :screen-fps=" + QString::number( screenFPS->value(), 'f' );
1214 emit methodChanged( "screen-caching" );
1219 if( !advMRL.isEmpty() ) mrl += advMRL;
1221 emit mrlUpdated( fileList, mrl );
1225 * Update the Buttons (show/hide) for the GUI as all device type don't
1226 * use the same ui. elements.
1228 void CaptureOpenPanel::updateButtons()
1230 /* Be sure to display the ui Elements in case they were hidden by
1231 * some Device Type (like Screen://) */
1232 ui.optionsBox->show();
1233 ui.advancedButton->show();
1234 /* Get the current Device Number */
1235 int i_devicetype = ui.deviceCombo->itemData(
1236 ui.deviceCombo->currentIndex() ).toInt();
1237 switch( i_devicetype )
1241 if( bdas->isChecked() || bdac->isChecked() )
1244 bdaSrateLabel->show();
1246 bdaBandLabel->hide();
1248 else if( bdat->isChecked() || bdaa->isChecked() )
1251 bdaSrateLabel->hide();
1253 bdaBandLabel->show();
1255 else if( bdaq->isChecked() )
1258 bdaSrateLabel->hide();
1260 bdaBandLabel->hide();
1265 if( dvbs->isChecked() || dvbc->isChecked() )
1268 dvbSrateLabel->show();
1270 dvbBandLabel->hide();
1272 else if( dvbt->isChecked() )
1275 dvbSrateLabel->hide();
1277 dvbBandLabel->show();
1282 //ui.optionsBox->hide();
1283 ui.advancedButton->hide();
1290 void CaptureOpenPanel::advancedDialog()
1292 /* Get selected device type */
1293 int i_devicetype = ui.deviceCombo->itemData(
1294 ui.deviceCombo->currentIndex() ).toInt();
1296 /* Get the corresponding module */
1297 module_t *p_module =
1298 module_find( psz_devModule[i_devicetype] );
1299 if( NULL == p_module ) return;
1302 QList<ConfigControl *> controls;
1304 /* Get the confsize */
1305 unsigned int i_confsize;
1306 module_config_t *p_config;
1307 p_config = module_config_get( p_module, &i_confsize );
1309 /* New Adv Prop dialog */
1310 adv = new QDialog( this );
1311 adv->setWindowTitle( qtr( "Advanced Options" ) );
1312 adv->setWindowRole( "vlc-advanced-options" );
1314 /* A main Layout with a Frame */
1315 QVBoxLayout *mainLayout = new QVBoxLayout( adv );
1316 QScrollArea *scroll = new QScrollArea;
1317 mainLayout->addWidget( scroll );
1319 QFrame *advFrame = new QFrame;
1320 /* GridLayout inside the Frame */
1321 QGridLayout *gLayout = new QGridLayout( advFrame );
1323 scroll->setWidgetResizable( true );
1324 scroll->setWidget( advFrame );
1326 /* Create the options inside the FrameLayout */
1327 for( int n = 0; n < (int)i_confsize; n++ )
1329 module_config_t *p_item = p_config + n;
1330 ConfigControl *config = ConfigControl::createControl(
1331 VLC_OBJECT( p_intf ), p_item, advFrame, gLayout, n );
1333 controls.append( config );
1337 QDialogButtonBox *advButtonBox = new QDialogButtonBox( adv );
1338 QPushButton *closeButton = new QPushButton( qtr( "OK" ) );
1339 QPushButton *cancelButton = new QPushButton( qtr( "Cancel" ) );
1341 CONNECT( closeButton, clicked(), adv, accept() );
1342 CONNECT( cancelButton, clicked(), adv, reject() );
1344 advButtonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
1345 advButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
1347 mainLayout->addWidget( advButtonBox );
1349 /* Creation of the MRL */
1352 QString tempMRL = "";
1353 for( int i = 0; i < controls.size(); i++ )
1355 ConfigControl *control = controls[i];
1357 tempMRL += (i ? " :" : ":");
1359 if( control->getType() == CONFIG_ITEM_BOOL )
1360 if( !(qobject_cast<VIntConfigControl *>(control)->getValue() ) )
1363 tempMRL += control->getName();
1365 switch( control->getType() )
1367 case CONFIG_ITEM_STRING:
1368 case CONFIG_ITEM_LOADFILE:
1369 case CONFIG_ITEM_SAVEFILE:
1370 case CONFIG_ITEM_DIRECTORY:
1371 case CONFIG_ITEM_MODULE:
1372 tempMRL += colon_escape( QString("=%1").arg( qobject_cast<VStringConfigControl *>(control)->getValue() ) );
1374 case CONFIG_ITEM_INTEGER:
1375 tempMRL += QString("=%1").arg( qobject_cast<VIntConfigControl *>(control)->getValue() );
1377 case CONFIG_ITEM_FLOAT:
1378 tempMRL += QString("=%1").arg( qobject_cast<VFloatConfigControl *>(control)->getValue() );
1384 msg_Dbg( p_intf, "%s", qtu( advMRL ) );
1386 for( int i = 0; i < controls.size(); i++ )
1388 ConfigControl *control = controls[i];
1392 module_config_free( p_config );
1393 module_release (p_module);