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 )
358 ui.deviceCombo->addItem( drive );
360 /* go to next drive */
363 SetErrorMode(oldMode);
366 char const * const ppsz_discdevices[] = {
373 QComboBox *discCombo = ui.deviceCombo; /* avoid namespacing in macro */
374 POPULATE_WITH_DEVS( ppsz_discdevices, discCombo );
378 BUTTONACT( ui.dvdRadioButton, updateButtons() );
379 BUTTONACT( ui.vcdRadioButton, updateButtons() );
380 BUTTONACT( ui.audioCDRadioButton, updateButtons() );
381 BUTTONACT( ui.dvdsimple, updateButtons() );
382 BUTTONACT( ui.browseDiscButton, browseDevice() );
383 BUTTON_SET_ACT_I( ui.ejectButton, "", toolbar/eject, qtr( "Eject the disc" ),
386 CONNECT( ui.deviceCombo, editTextChanged( QString ), this, updateMRL());
387 CONNECT( ui.titleSpin, valueChanged( int ), this, updateMRL());
388 CONNECT( ui.chapterSpin, valueChanged( int ), this, updateMRL());
389 CONNECT( ui.audioSpin, valueChanged( int ), this, updateMRL());
390 CONNECT( ui.subtitlesSpin, valueChanged( int ), this, updateMRL());
392 /* Run once the updateButtons function in order to fill correctly the comboBoxes */
396 DiscOpenPanel::~DiscOpenPanel()
398 free( psz_dvddiscpath );
399 free( psz_vcddiscpath );
400 free( psz_cddadiscpath );
403 void DiscOpenPanel::clear()
405 ui.titleSpin->setValue( 0 );
406 ui.chapterSpin->setValue( 0 );
407 ui.subtitlesSpin->setValue( -1 );
408 ui.audioSpin->setValue( -1 );
413 #define setDrive( psz_name ) {\
414 int index = ui.deviceCombo->findText( qfu( psz_name ) ); \
415 if( index != -1 ) ui.deviceCombo->setCurrentIndex( index );}
417 #define setDrive( psz_name ) {\
418 ui.deviceCombo->setEditText( qfu( psz_name ) ); }
421 /* update the buttons according the type of device */
422 void DiscOpenPanel::updateButtons()
424 if ( ui.dvdRadioButton->isChecked() )
426 if( m_discType != Dvd )
428 setDrive( psz_dvddiscpath );
431 ui.titleLabel->setText( qtr("Title") );
432 ui.chapterLabel->show();
433 ui.chapterSpin->show();
434 ui.diskOptionBox_2->show();
435 ui.dvdsimple->setEnabled( true );
437 else if ( ui.vcdRadioButton->isChecked() )
439 if( m_discType != Vcd )
441 setDrive( psz_vcddiscpath );
444 ui.titleLabel->setText( qtr("Entry") );
445 ui.chapterLabel->hide();
446 ui.chapterSpin->hide();
447 ui.diskOptionBox_2->show();
448 ui.dvdsimple->setEnabled( false );
452 if( m_discType != Cdda )
454 setDrive( psz_cddadiscpath );
457 ui.titleLabel->setText( qtr("Track") );
458 ui.chapterLabel->hide();
459 ui.chapterSpin->hide();
460 ui.diskOptionBox_2->hide();
461 ui.dvdsimple->setEnabled( false );
470 # define LOCALHOST ""
472 # define LOCALHOST "/"
475 /* Update the current MRL */
476 void DiscOpenPanel::updateMRL()
479 QStringList fileList;
481 /* CDDAX and VCDX not implemented. TODO ? No. */
483 if( ui.dvdRadioButton->isChecked() ) {
484 if( !ui.dvdsimple->isChecked() )
485 mrl = "dvd://" LOCALHOST;
487 mrl = "dvdsimple://" LOCALHOST;
488 mrl += ui.deviceCombo->currentText();
489 if( !ui.dvdsimple->isChecked() )
490 emit methodChanged( "dvdnav-caching" );
492 emit methodChanged( "dvdread-caching" );
494 if ( ui.titleSpin->value() > 0 ) {
495 mrl += QString("@%1").arg( ui.titleSpin->value() );
496 if ( ui.chapterSpin->value() > 0 ) {
497 mrl+= QString(":%1").arg( ui.chapterSpin->value() );
502 } else if ( ui.vcdRadioButton->isChecked() ) {
503 mrl = "vcd://" LOCALHOST + ui.deviceCombo->currentText();
504 emit methodChanged( "vcd-caching" );
506 if( ui.titleSpin->value() > 0 ) {
507 mrl += QString("@E%1").arg( ui.titleSpin->value() );
512 mrl = "cdda://" LOCALHOST + ui.deviceCombo->currentText();
513 emit methodChanged( "cdda-caching" );
516 fileList << mrl; mrl = "";
518 if ( ui.dvdRadioButton->isChecked() || ui.vcdRadioButton->isChecked() )
520 if ( ui.audioSpin->value() >= 0 ) {
521 mrl += " :audio-track=" +
522 QString("%1").arg( ui.audioSpin->value() );
524 if ( ui.subtitlesSpin->value() >= 0 ) {
525 mrl += " :sub-track=" +
526 QString("%1").arg( ui.subtitlesSpin->value() );
531 if( ui.titleSpin->value() > 0 )
532 mrl += QString(" :cdda-track=%1").arg( ui.titleSpin->value() );
534 emit mrlUpdated( fileList, mrl );
537 void DiscOpenPanel::browseDevice()
539 QString dir = QFileDialog::getExistingDirectory( this,
540 qtr( I_DEVICE_TOOLTIP ) );
542 ui.deviceCombo->setEditText( toNativeSepNoSlash( dir ) );
547 void DiscOpenPanel::eject()
549 intf_Eject( p_intf, qtu( ui.deviceCombo->currentText() ) );
552 void DiscOpenPanel::accept()
555 /**************************************************************************
556 * Open Network streams and URL pages *
557 **************************************************************************/
558 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
559 OpenPanel( _parent, _p_intf )
564 CONNECT( ui.urlComboBox->lineEdit(), textChanged( const QString& ), this, updateMRL());
565 CONNECT( ui.urlComboBox, currentIndexChanged( const QString& ), this, updateMRL());
567 if( var_InheritBool( p_intf, "qt-recentplay" ) )
569 mrlList = new QStringListModel(
570 getSettings()->value( "Open/netMRL" ).toStringList() );
571 ui.urlComboBox->setModel( mrlList );
572 ui.urlComboBox->clearEditText();
573 CONNECT( ui.urlComboBox->lineEdit(), editingFinished(), this, updateModel() );
578 ui.urlComboBox->setValidator( new UrlValidator( this ) );
579 ui.urlComboBox->setFocus();
582 NetOpenPanel::~NetOpenPanel()
584 if( !mrlList ) return;
586 QStringList tempL = mrlList->stringList();
587 while( tempL.size() > 8 ) tempL.removeFirst();
589 getSettings()->setValue( "Open/netMRL", tempL );
594 void NetOpenPanel::clear()
597 void NetOpenPanel::onFocus()
599 ui.urlComboBox->setFocus();
600 ui.urlComboBox->lineEdit()->selectAll();
603 static int strcmp_void( const void *k, const void *e )
605 return strcmp( (const char *)k, (const char *)e );
608 void NetOpenPanel::updateMRL()
610 static const struct caching_map
615 { /* KEEP alphabetical order on first column!! */
633 QString url = ui.urlComboBox->lineEdit()->text();
634 if( !url.contains( "://") )
635 return; /* nothing to do this far */
637 /* Match the correct item in the comboBox */
638 QString proto = url.section( ':', 0, 0 );
639 const struct caching_map *r = (const struct caching_map *)
640 bsearch( qtu(proto), schemes, sizeof(schemes) / sizeof(schemes[0]),
641 sizeof(schemes[0]), strcmp_void );
643 emit methodChanged( qfu( r->caching ) + qfu( "-caching" ) );
647 emit mrlUpdated( qsl, "" );
650 void NetOpenPanel::updateModel()
653 QStringList tempL = mrlList->stringList();
654 if( !tempL.contains( ui.urlComboBox->lineEdit()->text() ) )
655 tempL.append( ui.urlComboBox->lineEdit()->text() );
656 mrlList->setStringList( tempL );
659 void UrlValidator::fixup( QString& str ) const
664 QValidator::State UrlValidator::validate( QString& str, int& pos ) const
666 if( str.contains( ' ' ) )
667 return QValidator::Invalid;
668 if( !str.contains( "://" ) )
669 return QValidator::Intermediate;
670 return QValidator::Acceptable;
673 /**************************************************************************
674 * Open Capture device ( DVB, PVR, V4L, and similar ) *
675 **************************************************************************/
676 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
677 OpenPanel( _parent, _p_intf )
679 isInitialized = false;
682 void CaptureOpenPanel::initialize()
684 if( isInitialized ) return;
686 msg_Dbg( p_intf, "Initialization of Capture device panel" );
687 isInitialized = true;
691 BUTTONACT( ui.advancedButton, advancedDialog() );
693 /* Create two stacked layouts in the main comboBoxes */
694 QStackedLayout *stackedDevLayout = new QStackedLayout;
695 ui.cardBox->setLayout( stackedDevLayout );
697 QStackedLayout *stackedPropLayout = new QStackedLayout;
698 ui.optionsBox->setLayout( stackedPropLayout );
700 /* Creation and connections of the WIdgets in the stacked layout */
701 #define addModuleAndLayouts( number, name, label, layout ) \
702 QWidget * name ## DevPage = new QWidget( this ); \
703 QWidget * name ## PropPage = new QWidget( this ); \
704 stackedDevLayout->addWidget( name ## DevPage ); \
705 stackedPropLayout->addWidget( name ## PropPage ); \
706 layout * name ## DevLayout = new layout; \
707 layout * name ## PropLayout = new layout; \
708 name ## DevPage->setLayout( name ## DevLayout ); \
709 name ## PropPage->setLayout( name ## PropLayout ); \
710 ui.deviceCombo->addItem( qtr( label ), QVariant( number ) );
712 #define CuMRL( widget, slot ) CONNECT( widget , slot , this, updateMRL() );
715 /*********************
716 * DirectShow Stuffs *
717 *********************/
718 if( module_exists( "dshow" ) ){
719 addModuleAndLayouts( DSHOW_DEVICE, dshow, "DirectShow", QGridLayout );
723 module_config_t *p_config =
724 config_FindConfig( VLC_OBJECT(p_intf), "dshow-vdev" );
725 vdevDshowW = new StringListConfigControl(
726 VLC_OBJECT(p_intf), p_config, this, false, dshowDevLayout, line );
729 p_config = config_FindConfig( VLC_OBJECT(p_intf), "dshow-adev" );
730 adevDshowW = new StringListConfigControl(
731 VLC_OBJECT(p_intf), p_config, this, false, dshowDevLayout, line );
734 /* dshow Properties */
735 QLabel *dshowVSizeLabel = new QLabel( qtr( "Video size" ) );
736 dshowPropLayout->addWidget( dshowVSizeLabel, 0, 0 );
738 dshowVSizeLine = new QLineEdit;
739 dshowPropLayout->addWidget( dshowVSizeLine, 0, 1);
740 dshowPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
744 CuMRL( vdevDshowW->combo, currentIndexChanged ( int ) );
745 CuMRL( adevDshowW->combo, currentIndexChanged ( int ) );
746 CuMRL( dshowVSizeLine, textChanged( const QString& ) );
752 if( module_exists( "bda" ) ){
753 addModuleAndLayouts( BDA_DEVICE, bda, "DVB DirectShow", QGridLayout );
756 QLabel *bdaTypeLabel = new QLabel( qtr( "DVB Type:" ) );
758 bdas = new QRadioButton( "DVB-S" );
759 bdas->setChecked( true );
760 bdac = new QRadioButton( "DVB-C" );
761 bdat = new QRadioButton( "DVB-T" );
762 bdaa = new QRadioButton( "ATSC" );
763 bdaq = new QRadioButton( "Clear QAM" );
765 bdaDevLayout->addWidget( bdaTypeLabel, 0, 0 );
766 bdaDevLayout->addWidget( bdas, 0, 1 );
767 bdaDevLayout->addWidget( bdac, 0, 2 );
768 bdaDevLayout->addWidget( bdat, 0, 3 );
769 bdaDevLayout->addWidget( bdaa, 0, 4 );
770 bdaDevLayout->addWidget( bdaq, 0, 5 );
773 QLabel *bdaFreqLabel =
774 new QLabel( qtr( "Transponder/multiplex frequency" ) );
775 bdaPropLayout->addWidget( bdaFreqLabel, 0, 0 );
777 bdaFreq = new QSpinBox;
778 bdaFreq->setAlignment( Qt::AlignRight );
779 bdaFreq->setSuffix(" kHz");
780 bdaFreq->setSingleStep( 1000 );
781 setSpinBoxFreq( bdaFreq )
782 bdaPropLayout->addWidget( bdaFreq, 0, 1 );
784 bdaSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
785 bdaPropLayout->addWidget( bdaSrateLabel, 1, 0 );
787 bdaSrate = new QSpinBox;
788 bdaSrate->setAlignment( Qt::AlignRight );
789 bdaSrate->setSuffix(" kHz");
790 setSpinBoxFreq( bdaSrate );
791 bdaPropLayout->addWidget( bdaSrate, 1, 1 );
793 bdaBandLabel = new QLabel( qtr( "Bandwidth" ) );
794 bdaPropLayout->addWidget( bdaBandLabel, 2, 0 );
796 bdaBandBox = new QComboBox;
797 setfillVLCConfigCombo( "dvb-bandwidth", p_intf, bdaBandBox );
798 bdaPropLayout->addWidget( bdaBandBox, 2, 1 );
800 bdaBandLabel->hide();
802 bdaPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
806 CuMRL( bdaFreq, valueChanged ( int ) );
807 CuMRL( bdaSrate, valueChanged ( int ) );
808 CuMRL( bdaBandBox, currentIndexChanged ( int ) );
809 BUTTONACT( bdas, updateButtons() );
810 BUTTONACT( bdat, updateButtons() );
811 BUTTONACT( bdac, updateButtons() );
812 BUTTONACT( bdaa, updateButtons() );
813 BUTTONACT( bdaq, updateButtons() );
814 BUTTONACT( bdas, updateMRL() );
815 BUTTONACT( bdat, updateMRL() );
816 BUTTONACT( bdac, updateMRL() );
817 BUTTONACT( bdaa, updateMRL() );
818 BUTTONACT( bdaq, updateMRL() );
825 if( module_exists( "v4l2" ) ){
826 addModuleAndLayouts( V4L2_DEVICE, v4l2, "Video for Linux 2", QGridLayout );
828 char const * const ppsz_v4lvdevices[] = {
832 char const * const ppsz_v4ladevices[] = {
838 QLabel *v4l2VideoDeviceLabel = new QLabel( qtr( "Video device name" ) );
839 v4l2DevLayout->addWidget( v4l2VideoDeviceLabel, 0, 0 );
841 v4l2VideoDevice = new QComboBox( this );
842 v4l2VideoDevice->setEditable( true );
843 POPULATE_WITH_DEVS( ppsz_v4lvdevices, v4l2VideoDevice );
844 v4l2VideoDevice->clearEditText();
845 v4l2DevLayout->addWidget( v4l2VideoDevice, 0, 1 );
847 QLabel *v4l2AudioDeviceLabel = new QLabel( qtr( "Audio device name" ) );
848 v4l2DevLayout->addWidget( v4l2AudioDeviceLabel, 1, 0 );
850 v4l2AudioDevice = new QComboBox( this );
851 v4l2AudioDevice->setEditable( true );
852 POPULATE_WITH_DEVS( ppsz_v4ladevices, v4l2AudioDevice );
853 v4l2AudioDevice->clearEditText();
854 v4l2DevLayout->addWidget( v4l2AudioDevice, 1, 1 );
856 /* v4l2 Props panel */
857 QLabel *v4l2StdLabel = new QLabel( qtr( "Video standard" ) );
858 v4l2PropLayout->addWidget( v4l2StdLabel, 0 , 0 );
860 v4l2StdBox = new QComboBox;
861 setfillVLCConfigCombo( "v4l2-standard", p_intf, v4l2StdBox );
862 v4l2PropLayout->addWidget( v4l2StdBox, 0 , 1 );
863 v4l2PropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
867 CuMRL( v4l2VideoDevice->lineEdit(), textChanged( const QString& ) );
868 CuMRL( v4l2VideoDevice, currentIndexChanged ( int ) );
869 CuMRL( v4l2AudioDevice->lineEdit(), textChanged( const QString& ) );
870 CuMRL( v4l2AudioDevice, currentIndexChanged ( int ) );
871 CuMRL( v4l2StdBox, currentIndexChanged ( int ) );
877 if( module_exists( "jack" ) ){
878 addModuleAndLayouts( JACK_DEVICE, jack, "JACK Audio Connection Kit",
881 /* Jack Main panel */
883 QLabel *jackChannelsLabel = new QLabel( qtr( "Channels:" ) );
884 jackDevLayout->addWidget( jackChannelsLabel, 1, 0 );
886 jackChannels = new QSpinBox;
887 setSpinBoxFreq( jackChannels );
888 jackChannels->setMaximum(255);
889 jackChannels->setValue(2);
890 jackChannels->setAlignment( Qt::AlignRight );
891 jackDevLayout->addWidget( jackChannels, 1, 1 );
894 QLabel *jackPortsLabel = new QLabel( qtr( "Selected ports:" ) );
895 jackDevLayout->addWidget( jackPortsLabel, 0 , 0 );
897 jackPortsSelected = new QLineEdit( qtr( ".*") );
898 jackPortsSelected->setAlignment( Qt::AlignRight );
899 jackDevLayout->addWidget( jackPortsSelected, 0, 1 );
901 /* Jack Props panel */
904 QLabel *jackCachingLabel = new QLabel( qtr( "Input caching:" ) );
905 jackPropLayout->addWidget( jackCachingLabel, 1 , 0 );
906 jackCaching = new QSpinBox;
907 setSpinBoxFreq( jackCaching );
908 jackCaching->setSuffix( " ms" );
909 jackCaching->setValue(1000);
910 jackCaching->setAlignment( Qt::AlignRight );
911 jackPropLayout->addWidget( jackCaching, 1 , 2 );
914 jackPace = new QCheckBox(qtr( "Use VLC pace" ));
915 jackPropLayout->addWidget( jackPace, 2, 1 );
918 jackConnect = new QCheckBox( qtr( "Auto connection" ));
919 jackPropLayout->addWidget( jackConnect, 2, 2 );
922 CuMRL( jackChannels, valueChanged( int ) );
923 CuMRL( jackCaching, valueChanged( int ) );
924 CuMRL( jackPace, stateChanged( int ) );
925 CuMRL( jackConnect, stateChanged( int ) );
926 CuMRL( jackPortsSelected, textChanged( const QString& ) );
932 if( module_exists( "pvr" ) ){
933 addModuleAndLayouts( PVR_DEVICE, pvr, "PVR", QGridLayout );
936 QLabel *pvrDeviceLabel = new QLabel( qtr( "Device name" ) );
937 pvrDevLayout->addWidget( pvrDeviceLabel, 0, 0 );
939 pvrDevice = new QLineEdit;
940 pvrDevLayout->addWidget( pvrDevice, 0, 1 );
942 QLabel *pvrRadioDeviceLabel = new QLabel( qtr( "Radio device name" ) );
943 pvrDevLayout->addWidget( pvrRadioDeviceLabel, 1, 0 );
945 pvrRadioDevice = new QLineEdit;
946 pvrDevLayout->addWidget( pvrRadioDevice, 1, 1 );
948 /* PVR props panel */
949 QLabel *pvrNormLabel = new QLabel( qtr( "Norm" ) );
950 pvrPropLayout->addWidget( pvrNormLabel, 0, 0 );
952 pvrNormBox = new QComboBox;
953 setfillVLCConfigCombo( "pvr-norm", p_intf, pvrNormBox );
954 pvrPropLayout->addWidget( pvrNormBox, 0, 1 );
956 QLabel *pvrFreqLabel = new QLabel( qtr( "Frequency" ) );
957 pvrPropLayout->addWidget( pvrFreqLabel, 1, 0 );
959 pvrFreq = new QSpinBox;
960 pvrFreq->setAlignment( Qt::AlignRight );
961 pvrFreq->setSuffix(" kHz");
962 setSpinBoxFreq( pvrFreq );
963 pvrPropLayout->addWidget( pvrFreq, 1, 1 );
965 QLabel *pvrBitrLabel = new QLabel( qtr( "Bitrate" ) );
966 pvrPropLayout->addWidget( pvrBitrLabel, 2, 0 );
968 pvrBitr = new QSpinBox;
969 pvrBitr->setAlignment( Qt::AlignRight );
970 pvrBitr->setSuffix(" kHz");
971 setSpinBoxFreq( pvrBitr );
972 pvrPropLayout->addWidget( pvrBitr, 2, 1 );
973 pvrPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
977 CuMRL( pvrDevice, textChanged( const QString& ) );
978 CuMRL( pvrRadioDevice, textChanged( const QString& ) );
980 CuMRL( pvrFreq, valueChanged ( int ) );
981 CuMRL( pvrBitr, valueChanged ( int ) );
982 CuMRL( pvrNormBox, currentIndexChanged ( int ) );
988 if( module_exists( "dvb" ) ){
989 addModuleAndLayouts( DVB_DEVICE, dvb, "DVB", QGridLayout );
992 QLabel *dvbDeviceLabel = new QLabel( qtr( "Adapter card to tune" ) );
993 QLabel *dvbTypeLabel = new QLabel( qtr( "DVB Type:" ) );
995 dvbCard = new QSpinBox;
996 dvbCard->setAlignment( Qt::AlignRight );
997 dvbCard->setPrefix( "/dev/dvb/adapter" );
999 dvbDevLayout->addWidget( dvbDeviceLabel, 0, 0 );
1000 dvbDevLayout->addWidget( dvbCard, 0, 2, 1, 2 );
1002 dvbs = new QRadioButton( "DVB-S" );
1003 dvbs->setChecked( true );
1004 dvbc = new QRadioButton( "DVB-C" );
1005 dvbt = new QRadioButton( "DVB-T" );
1007 dvbDevLayout->addWidget( dvbTypeLabel, 1, 0 );
1008 dvbDevLayout->addWidget( dvbs, 1, 1 );
1009 dvbDevLayout->addWidget( dvbc, 1, 2 );
1010 dvbDevLayout->addWidget( dvbt, 1, 3 );
1012 /* DVB Props panel */
1013 QLabel *dvbFreqLabel =
1014 new QLabel( qtr( "Transponder/multiplex frequency" ) );
1015 dvbPropLayout->addWidget( dvbFreqLabel, 0, 0 );
1017 dvbFreq = new QSpinBox;
1018 dvbFreq->setAlignment( Qt::AlignRight );
1019 dvbFreq->setSuffix(" kHz");
1020 dvbFreq->setSingleStep( 1000 );
1021 setSpinBoxFreq( dvbFreq );
1022 dvbPropLayout->addWidget( dvbFreq, 0, 1 );
1024 dvbSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
1025 dvbPropLayout->addWidget( dvbSrateLabel, 1, 0 );
1027 dvbSrate = new QSpinBox;
1028 dvbSrate->setAlignment( Qt::AlignRight );
1029 dvbSrate->setSuffix(" kHz");
1030 setSpinBoxFreq( dvbSrate );
1031 dvbPropLayout->addWidget( dvbSrate, 1, 1 );
1033 dvbBandLabel = new QLabel( qtr( "Bandwidth" ) );
1034 dvbPropLayout->addWidget( dvbBandLabel, 2, 0 );
1036 dvbBandBox = new QComboBox;
1037 /* This doesn't work since dvb-bandwidth doesn't seem to be a
1039 setfillVLCConfigCombo( "dvb-bandwidth", p_intf, bdaBandBox );
1041 dvbBandBox->addItem( qtr( "Auto" ), 0 );
1042 dvbBandBox->addItem( qtr( "6 MHz" ), 6 );
1043 dvbBandBox->addItem( qtr( "7 MHz" ), 7 );
1044 dvbBandBox->addItem( qtr( "8 MHz" ), 8 );
1045 dvbPropLayout->addWidget( dvbBandBox, 2, 1 );
1047 dvbBandLabel->hide();
1050 dvbPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
1054 CuMRL( dvbCard, valueChanged ( int ) );
1055 CuMRL( dvbFreq, valueChanged ( int ) );
1056 CuMRL( dvbSrate, valueChanged ( int ) );
1057 CuMRL( dvbBandBox, currentIndexChanged ( int ) );
1059 BUTTONACT( dvbs, updateButtons() );
1060 BUTTONACT( dvbt, updateButtons() );
1061 BUTTONACT( dvbc, updateButtons() );
1062 BUTTONACT( dvbs, updateMRL() );
1063 BUTTONACT( dvbt, updateMRL() );
1064 BUTTONACT( dvbc, updateMRL() );
1073 addModuleAndLayouts( SCREEN_DEVICE, screen, "Desktop", QGridLayout );
1074 QLabel *screenLabel = new QLabel( qtr( "Your display will be "
1075 "opened and played in order to stream or save it." ) );
1076 screenLabel->setWordWrap( true );
1077 screenDevLayout->addWidget( screenLabel, 0, 0 );
1079 QLabel *screenFPSLabel = new QLabel(
1080 qtr( "Desired frame rate for the capture." ) );
1081 screenPropLayout->addWidget( screenFPSLabel, 0, 0 );
1083 screenFPS = new QDoubleSpinBox;
1084 screenFPS->setValue( 1. );
1085 screenFPS->setRange( .01, 100. );
1086 screenFPS->setAlignment( Qt::AlignRight );
1087 /* xgettext: frames per second */
1088 screenFPS->setSuffix( qtr( " f/s" ) );
1089 screenPropLayout->addWidget( screenFPS, 0, 1 );
1091 /* Screen connect */
1092 CuMRL( screenFPS, valueChanged( double ) );
1094 /* General connects */
1095 CONNECT( ui.deviceCombo, activated( int ) ,
1096 stackedDevLayout, setCurrentIndex( int ) );
1097 CONNECT( ui.deviceCombo, activated( int ),
1098 stackedPropLayout, setCurrentIndex( int ) );
1099 CONNECT( ui.deviceCombo, activated( int ), this, updateMRL() );
1100 CONNECT( ui.deviceCombo, activated( int ), this, updateButtons() );
1103 #undef addModuleAndLayouts
1106 CaptureOpenPanel::~CaptureOpenPanel()
1110 void CaptureOpenPanel::clear()
1115 void CaptureOpenPanel::updateMRL()
1118 QStringList fileList;
1119 int i_devicetype = ui.deviceCombo->itemData(
1120 ui.deviceCombo->currentIndex() ).toInt();
1121 switch( i_devicetype )
1125 if( bdas->isChecked() ) mrl = "dvb-s://";
1126 else if( bdat->isChecked() ) mrl = "dvb-t://";
1127 else if( bdac->isChecked() ) mrl = "dvb-c://";
1128 else if( bdaa->isChecked() ) mrl = "atsc://";
1129 else if( bdaq->isChecked() ) mrl = "cqam://";
1131 mrl += "frequency=" + QString::number( bdaFreq->value() );
1132 if( bdac->isChecked() || bdat->isChecked() || bdaa->isChecked() )
1134 fileList << mrl; mrl = "";
1136 if( bdas->isChecked() || bdac->isChecked() )
1137 mrl += " :dvb-srate=" + QString::number( bdaSrate->value() );
1138 else if( bdat->isChecked() || bdaa->isChecked() )
1139 mrl += " :dvb-bandwidth=" +
1140 QString::number( bdaBandBox->itemData(
1141 bdaBandBox->currentIndex() ).toInt() );
1142 emit methodChanged( "dvb-caching" );
1145 fileList << "dshow://";
1146 mrl+= " :dshow-vdev=" +
1147 colon_escape( QString("%1").arg( vdevDshowW->getValue() ) );
1148 mrl+= " :dshow-adev=" +
1149 colon_escape( QString("%1").arg( adevDshowW->getValue() ) )+" ";
1150 if( dshowVSizeLine->isModified() )
1151 mrl += ":dshow-size=" + dshowVSizeLine->text();
1152 emit methodChanged( "dshow-caching" );
1156 fileList << "v4l2://" + v4l2VideoDevice->currentText();
1157 mrl += " :input-slave=alsa://" + v4l2AudioDevice->currentText();
1158 mrl += " :v4l2-standard=" + QString::number( v4l2StdBox->currentIndex() );
1162 mrl += "channels=" + QString::number( jackChannels->value() );
1163 mrl += ":ports=" + jackPortsSelected->text();
1164 fileList << mrl; mrl = "";
1166 mrl += " :jack-input-caching=" + QString::number( jackCaching->value() );
1167 if ( jackPace->isChecked() )
1169 mrl += " :jack-input-use-vlc-pace";
1171 if ( jackConnect->isChecked() )
1173 mrl += " :jack-input-auto-connect";
1177 fileList << "pvr://";
1178 mrl += " :pvr-device=" + pvrDevice->text();
1179 mrl += " :pvr-radio-device=" + pvrRadioDevice->text();
1180 mrl += " :pvr-norm=" + QString::number( pvrNormBox->currentIndex() );
1181 if( pvrFreq->value() )
1182 mrl += " :pvr-frequency=" + QString::number( pvrFreq->value() );
1183 if( pvrBitr->value() )
1184 mrl += " :pvr-bitrate=" + QString::number( pvrBitr->value() );
1188 mrl += "frequency=" + QString::number( dvbFreq->value() );
1189 if( dvbc->isChecked() || dvbt->isChecked() )
1191 fileList << mrl; mrl= "";
1193 mrl += " :dvb-adapter=" + QString::number( dvbCard->value() );
1194 if( dvbs->isChecked() || dvbc->isChecked() )
1195 mrl += " :dvb-srate=" + QString::number( dvbSrate->value() );
1196 else if( dvbt->isChecked() )
1197 mrl += " :dvb-bandwidth=" +
1198 QString::number( dvbBandBox->itemData(
1199 dvbBandBox->currentIndex() ).toInt() );
1204 fileList << "screen://";
1205 mrl = " :screen-fps=" + QString::number( screenFPS->value(), 'f' );
1206 emit methodChanged( "screen-caching" );
1211 if( !advMRL.isEmpty() ) mrl += advMRL;
1213 emit mrlUpdated( fileList, mrl );
1217 * Update the Buttons (show/hide) for the GUI as all device type don't
1218 * use the same ui. elements.
1220 void CaptureOpenPanel::updateButtons()
1222 /* Be sure to display the ui Elements in case they were hidden by
1223 * some Device Type (like Screen://) */
1224 ui.optionsBox->show();
1225 ui.advancedButton->show();
1226 /* Get the current Device Number */
1227 int i_devicetype = ui.deviceCombo->itemData(
1228 ui.deviceCombo->currentIndex() ).toInt();
1229 switch( i_devicetype )
1233 if( bdas->isChecked() || bdac->isChecked() )
1236 bdaSrateLabel->show();
1238 bdaBandLabel->hide();
1240 else if( bdat->isChecked() || bdaa->isChecked() )
1243 bdaSrateLabel->hide();
1245 bdaBandLabel->show();
1247 else if( bdaq->isChecked() )
1250 bdaSrateLabel->hide();
1252 bdaBandLabel->hide();
1257 if( dvbs->isChecked() || dvbc->isChecked() )
1260 dvbSrateLabel->show();
1262 dvbBandLabel->hide();
1264 else if( dvbt->isChecked() )
1267 dvbSrateLabel->hide();
1269 dvbBandLabel->show();
1274 //ui.optionsBox->hide();
1275 ui.advancedButton->hide();
1282 void CaptureOpenPanel::advancedDialog()
1284 /* Get selected device type */
1285 int i_devicetype = ui.deviceCombo->itemData(
1286 ui.deviceCombo->currentIndex() ).toInt();
1288 /* Get the corresponding module */
1289 module_t *p_module =
1290 module_find( psz_devModule[i_devicetype] );
1291 if( NULL == p_module ) return;
1294 QList<ConfigControl *> controls;
1296 /* Get the confsize */
1297 unsigned int i_confsize;
1298 module_config_t *p_config;
1299 p_config = module_config_get( p_module, &i_confsize );
1301 /* New Adv Prop dialog */
1302 adv = new QDialog( this );
1303 adv->setWindowTitle( qtr( "Advanced Options" ) );
1304 adv->setWindowRole( "vlc-advanced-options" );
1306 /* A main Layout with a Frame */
1307 QVBoxLayout *mainLayout = new QVBoxLayout( adv );
1308 QScrollArea *scroll = new QScrollArea;
1309 mainLayout->addWidget( scroll );
1311 QFrame *advFrame = new QFrame;
1312 /* GridLayout inside the Frame */
1313 QGridLayout *gLayout = new QGridLayout( advFrame );
1315 scroll->setWidgetResizable( true );
1316 scroll->setWidget( advFrame );
1318 /* Create the options inside the FrameLayout */
1319 for( int n = 0; n < (int)i_confsize; n++ )
1321 module_config_t *p_item = p_config + n;
1322 ConfigControl *config = ConfigControl::createControl(
1323 VLC_OBJECT( p_intf ), p_item, advFrame, gLayout, n );
1325 controls.append( config );
1329 QDialogButtonBox *advButtonBox = new QDialogButtonBox( adv );
1330 QPushButton *closeButton = new QPushButton( qtr( "OK" ) );
1331 QPushButton *cancelButton = new QPushButton( qtr( "Cancel" ) );
1333 CONNECT( closeButton, clicked(), adv, accept() );
1334 CONNECT( cancelButton, clicked(), adv, reject() );
1336 advButtonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
1337 advButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
1339 mainLayout->addWidget( advButtonBox );
1341 /* Creation of the MRL */
1344 QString tempMRL = "";
1345 for( int i = 0; i < controls.size(); i++ )
1347 ConfigControl *control = controls[i];
1349 tempMRL += (i ? " :" : ":");
1351 if( control->getType() == CONFIG_ITEM_BOOL )
1352 if( !(qobject_cast<VIntConfigControl *>(control)->getValue() ) )
1355 tempMRL += control->getName();
1357 switch( control->getType() )
1359 case CONFIG_ITEM_STRING:
1360 case CONFIG_ITEM_LOADFILE:
1361 case CONFIG_ITEM_SAVEFILE:
1362 case CONFIG_ITEM_DIRECTORY:
1363 case CONFIG_ITEM_MODULE:
1364 tempMRL += colon_escape( QString("=%1").arg( qobject_cast<VStringConfigControl *>(control)->getValue() ) );
1366 case CONFIG_ITEM_INTEGER:
1367 tempMRL += QString("=%1").arg( qobject_cast<VIntConfigControl *>(control)->getValue() );
1369 case CONFIG_ITEM_FLOAT:
1370 tempMRL += QString("=%1").arg( qobject_cast<VFloatConfigControl *>(control)->getValue() );
1376 msg_Dbg( p_intf, "%s", qtu( advMRL ) );
1378 for( int i = 0; i < controls.size(); i++ )
1380 ConfigControl *control = controls[i];
1384 module_config_free( p_config );
1385 module_release (p_module);