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 <vlc_charset.h> /* FromWide for Win32 */
44 #include <QFileDialog>
45 #include <QDialogButtonBox>
47 #include <QStackedLayout>
51 #include <QScrollArea>
53 #include <QStringListModel>
56 #define I_DEVICE_TOOLTIP \
57 I_DIR_OR_FOLDER( N_("Select a device or a VIDEO_TS directory"), \
58 N_("Select a device or a VIDEO_TS folder") )
60 /* Populate a combobox with the devices matching a pattern.
61 Combobox will automatically do autocompletion on the edit zone */
62 #define POPULATE_WITH_DEVS(ppsz_devlist, targetCombo) \
63 QStringList targetCombo ## StringList = QStringList(); \
64 for ( size_t i = 0; i< sizeof(ppsz_devlist) / sizeof(*ppsz_devlist); i++ ) \
65 targetCombo ## StringList << QString( ppsz_devlist[ i ] ); \
66 targetCombo->addItems( QDir( "/dev/" )\
67 .entryList( targetCombo ## StringList, QDir::System )\
68 .replaceInStrings( QRegExp("^"), "/dev/" ) \
71 static const char psz_devModule[][8] = { "v4l2", "pvr", "dtv",
72 "dshow", "screen", "jack" };
74 /**************************************************************************
75 * Open Files and subtitles *
76 **************************************************************************/
77 FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
78 OpenPanel( _parent, _p_intf ), dialogBox( NULL )
80 /* Classic UI Setup */
83 setAcceptDrops( true );
85 /* Set Filters for file selection */
86 /* QString fileTypes = "";
87 ADD_FILTER_MEDIA( fileTypes );
88 ADD_FILTER_VIDEO( fileTypes );
89 ADD_FILTER_AUDIO( fileTypes );
90 ADD_FILTER_PLAYLIST( fileTypes );
91 ADD_FILTER_ALL( fileTypes );
92 fileTypes.replace( QString(";*"), QString(" *")); */
95 /* lineFileEdit = ui.fileEdit;
96 //TODO later: fill the fileCompleteList with previous items played.
97 QCompleter *fileCompleter = new QCompleter( fileCompleteList, this );
98 fileCompleter->setModel( new QDirModel( fileCompleter ) );
99 lineFileEdit->setCompleter( fileCompleter );*/
100 if( var_InheritBool( p_intf, "qt-embedded-open" ) )
102 ui.tempWidget->hide();
107 /* Deactivate the subtitles control by default. */
108 ui.subFrame->setEnabled( false );
111 BUTTONACT( ui.fileBrowseButton, browseFile() );
112 BUTTONACT( ui.removeFileButton, removeFile() );
114 BUTTONACT( ui.subBrowseButton, browseFileSub() );
115 CONNECT( ui.subCheckBox, toggled( bool ), this, toggleSubtitleFrame( bool ) );
117 CONNECT( ui.fileListWidg, itemChanged( QListWidgetItem * ), this, updateMRL() );
118 CONNECT( ui.subInput, textChanged( const QString& ), this, updateMRL() );
122 inline void FileOpenPanel::BuildOldPanel()
124 /** BEGIN QFileDialog tweaking **/
125 /* Use a QFileDialog and customize it because we don't want to
126 rewrite it all. Be careful to your eyes cause there are a few hacks.
127 Be very careful and test correctly when you modify this. */
129 /* Make this QFileDialog a child of tempWidget from the ui. */
130 dialogBox = new FileOpenBox( ui.tempWidget, NULL,
131 p_intf->p_sys->filepath, "" );
133 dialogBox->setFileMode( QFileDialog::ExistingFiles );
134 dialogBox->setAcceptMode( QFileDialog::AcceptOpen );
135 dialogBox->restoreState(
136 getSettings()->value( "file-dialog-state" ).toByteArray() );
138 /* We don't want to see a grip in the middle of the window, do we? */
139 dialogBox->setSizeGripEnabled( false );
142 dialogBox->setToolTip( qtr( "Select one or multiple files" ) );
143 dialogBox->setMinimumHeight( 250 );
145 // But hide the two OK/Cancel buttons. Enable them for debug.
146 QDialogButtonBox *fileDialogAcceptBox =
147 dialogBox->findChildren<QDialogButtonBox*>()[0];
148 fileDialogAcceptBox->hide();
150 /* Ugly hacks to get the good Widget */
151 //This lineEdit is the normal line in the fileDialog.
152 QLineEdit *lineFileEdit = dialogBox->findChildren<QLineEdit*>()[0];
153 /* Make a list of QLabel inside the QFileDialog to access the good ones */
154 QList<QLabel *> listLabel = dialogBox->findChildren<QLabel*>();
156 /* Hide the FileNames one. Enable it for debug */
157 listLabel[1]->setText( qtr( "File names:" ) );
158 /* Change the text that was uncool in the usual box */
159 listLabel[2]->setText( qtr( "Filter:" ) );
161 dialogBox->layout()->setMargin( 0 );
162 dialogBox->layout()->setSizeConstraint( QLayout::SetNoConstraint );
164 /** END of QFileDialog tweaking **/
166 // Add the DialogBox to the layout
167 ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
169 CONNECT( lineFileEdit, textChanged( const QString& ), this, updateMRL() );
170 dialogBox->installEventFilter( this );
173 FileOpenPanel::~FileOpenPanel()
176 getSettings()->setValue( "file-dialog-state", dialogBox->saveState() );
179 void FileOpenPanel::dragEnterEvent( QDragEnterEvent *event )
181 event->acceptProposedAction();
184 void FileOpenPanel::dragMoveEvent( QDragMoveEvent *event )
186 event->acceptProposedAction();
189 void FileOpenPanel::dragLeaveEvent( QDragLeaveEvent *event )
194 void FileOpenPanel::dropEvent( QDropEvent *event )
196 if( event->possibleActions() & Qt::CopyAction )
197 event->setDropAction( Qt::CopyAction );
201 const QMimeData *mimeData = event->mimeData();
202 foreach( const QUrl &url, mimeData->urls() )
206 QListWidgetItem *item = new QListWidgetItem(
207 toNativeSeparators( url.toLocalFile() ),
209 item->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled );
210 ui.fileListWidg->addItem( item );
218 void FileOpenPanel::browseFile()
220 QStringList files = QFileDialog::getOpenFileNames( this, qtr( "Select one or multiple files" ), p_intf->p_sys->filepath) ;
221 foreach( const QString &file, files )
223 QListWidgetItem *item =
224 new QListWidgetItem( toNativeSeparators( file ), ui.fileListWidg );
225 item->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled );
226 ui.fileListWidg->addItem( item );
227 savedirpathFromFile( file );
233 void FileOpenPanel::removeFile()
235 int i = ui.fileListWidg->currentRow();
238 QListWidgetItem *temp = ui.fileListWidg->takeItem( i );
246 /* Show a fileBrowser to select a subtitle */
247 void FileOpenPanel::browseFileSub()
249 // TODO Handle selection of more than one subtitles file
250 QStringList files = THEDP->showSimpleOpen( qtr("Open subtitles file"),
251 EXT_FILTER_SUBTITLE, p_intf->p_sys->filepath );
253 if( files.isEmpty() ) return;
254 ui.subInput->setText( toNativeSeparators( files.join(" ") ) );
258 void FileOpenPanel::toggleSubtitleFrame( bool b )
260 ui.subFrame->setEnabled( b );
267 /* Update the current MRL */
268 void FileOpenPanel::updateMRL()
270 QStringList fileList;
274 if( dialogBox == NULL )
275 for( int i = 0; i < ui.fileListWidg->count(); i++ )
277 if( !ui.fileListWidg->item( i )->text().isEmpty() )
278 fileList << toURI(ui.fileListWidg->item( i )->text());
282 fileList = dialogBox->selectedFiles();
283 for( int i = 0; i < fileList.count(); i++ )
284 fileList[i] = toURI( fileList[i] );
288 if( ui.subCheckBox->isChecked() && !ui.subInput->text().isEmpty() ) {
289 mrl.append( " :sub-file=" + colon_escape( ui.subInput->text() ) );
292 emit methodChanged( "file-caching" );
293 emit mrlUpdated( fileList, mrl );
296 /* Function called by Open Dialog when clicke on Play/Enqueue */
297 void FileOpenPanel::accept()
300 p_intf->p_sys->filepath = dialogBox->directory().absolutePath();
301 ui.fileListWidg->clear();
304 /* Function called by Open Dialog when clicked on cancel */
305 void FileOpenPanel::clear()
307 ui.fileListWidg->clear();
308 ui.subInput->clear();
311 /* Update buttons depending on current selection */
312 void FileOpenPanel::updateButtons()
314 bool b_has_files = ( ui.fileListWidg->count() > 0 );
315 ui.removeFileButton->setEnabled( b_has_files );
316 ui.subCheckBox->setEnabled( b_has_files );
319 /**************************************************************************
320 * Open Discs ( DVD, CD, VCD and similar devices ) *
321 **************************************************************************/
322 DiscOpenPanel::DiscOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
323 OpenPanel( _parent, _p_intf )
327 /* Get the default configuration path for the devices */
328 psz_dvddiscpath = var_InheritString( p_intf, "dvd" );
329 psz_vcddiscpath = var_InheritString( p_intf, "vcd" );
330 psz_cddadiscpath = var_InheritString( p_intf, "cd-audio" );
332 /* State to avoid overwritting the users changes with the configuration */
335 ui.browseDiscButton->setToolTip( qtr( I_DEVICE_TOOLTIP ));
336 ui.deviceCombo->setToolTip( qtr(I_DEVICE_TOOLTIP) );
337 ui.deviceCombo->setInsertPolicy( QComboBox::InsertAtTop );
340 BUTTONACT( ui.dvdRadioButton, updateButtons() );
341 BUTTONACT( ui.bdRadioButton, updateButtons() );
342 BUTTONACT( ui.vcdRadioButton, updateButtons() );
343 BUTTONACT( ui.audioCDRadioButton, updateButtons() );
344 BUTTONACT( ui.dvdsimple, updateButtons() );
345 BUTTONACT( ui.browseDiscButton, browseDevice() );
346 BUTTON_SET_ACT_I( ui.ejectButton, "", toolbar/eject, qtr( "Eject the disc" ),
349 CONNECT( ui.deviceCombo, editTextChanged( QString ), this, updateMRL());
350 CONNECT( ui.deviceCombo, currentIndexChanged( QString ), this, updateMRL());
351 CONNECT( ui.titleSpin, valueChanged( int ), this, updateMRL());
352 CONNECT( ui.chapterSpin, valueChanged( int ), this, updateMRL());
353 CONNECT( ui.audioSpin, valueChanged( int ), this, updateMRL());
354 CONNECT( ui.subtitlesSpin, valueChanged( int ), this, updateMRL());
356 /* Run once the updateButtons function in order to fill correctly the comboBoxes */
360 void DiscOpenPanel::onFocus()
362 #ifdef WIN32 /* Disc drives probing for Windows */
363 wchar_t szDrives[512];
365 if( GetLogicalDriveStringsW( sizeof( szDrives ) - 1, szDrives ) )
367 wchar_t *drive = szDrives;
368 UINT oldMode = SetErrorMode( SEM_FAILCRITICALERRORS );
371 if( GetDriveTypeW(drive) == DRIVE_CDROM )
373 wchar_t psz_name[512] = L"";
374 GetVolumeInformationW( drive, psz_name, 511, NULL, NULL, NULL, NULL, 0 );
376 QString displayName = FromWide( drive );
378 displayName = displayName + " - " + FromWide( psz_name );
381 ui.deviceCombo->addItem( displayName, FromWide( drive ) );
384 /* go to next drive */
387 SetErrorMode(oldMode);
390 char const * const ppsz_discdevices[] = {
397 QComboBox *discCombo = ui.deviceCombo; /* avoid namespacing in macro */
398 POPULATE_WITH_DEVS( ppsz_discdevices, discCombo );
404 DiscOpenPanel::~DiscOpenPanel()
406 free( psz_dvddiscpath );
407 free( psz_vcddiscpath );
408 free( psz_cddadiscpath );
411 void DiscOpenPanel::clear()
413 ui.titleSpin->setValue( 0 );
414 ui.chapterSpin->setValue( 0 );
415 ui.subtitlesSpin->setValue( -1 );
416 ui.audioSpin->setValue( -1 );
421 #define setDrive( psz_name ) {\
422 int index = ui.deviceCombo->findText( qfu( psz_name ) ); \
423 if( index != -1 ) ui.deviceCombo->setCurrentIndex( index );}
425 #define setDrive( psz_name ) {\
426 ui.deviceCombo->setEditText( qfu( psz_name ) ); }
429 /* update the buttons according the type of device */
430 void DiscOpenPanel::updateButtons()
432 if ( ui.dvdRadioButton->isChecked() )
434 if( m_discType != Dvd )
436 setDrive( psz_dvddiscpath );
439 ui.titleLabel->setText( qtr("Title") );
440 ui.chapterLabel->show();
441 ui.chapterSpin->show();
442 ui.diskOptionBox_2->show();
443 ui.dvdsimple->setEnabled( true );
445 else if ( ui.bdRadioButton->isChecked() )
447 if( m_discType != BRD )
449 setDrive( psz_dvddiscpath );
452 ui.titleLabel->setText( qtr("Title") );
453 ui.chapterLabel->hide();
454 ui.chapterSpin->hide();
455 ui.diskOptionBox_2->hide();
456 ui.dvdsimple->setEnabled( true );
458 else if ( ui.vcdRadioButton->isChecked() )
460 if( m_discType != Vcd )
462 setDrive( psz_vcddiscpath );
465 ui.titleLabel->setText( qtr("Entry") );
466 ui.chapterLabel->hide();
467 ui.chapterSpin->hide();
468 ui.diskOptionBox_2->show();
469 ui.dvdsimple->setEnabled( false );
473 if( m_discType != Cdda )
475 setDrive( psz_cddadiscpath );
478 ui.titleLabel->setText( qtr("Track") );
479 ui.chapterLabel->hide();
480 ui.chapterSpin->hide();
481 ui.diskOptionBox_2->hide();
482 ui.dvdsimple->setEnabled( false );
491 # define LOCALHOST ""
493 # define LOCALHOST "/"
496 /* Update the current MRL */
497 void DiscOpenPanel::updateMRL()
501 QStringList fileList;
503 if( ui.deviceCombo->itemData( ui.deviceCombo->currentIndex() ) != QVariant::Invalid )
504 discPath = ui.deviceCombo->itemData( ui.deviceCombo->currentIndex() ).toString();
506 discPath = ui.deviceCombo->currentText();
510 if( ui.dvdRadioButton->isChecked() ) {
511 if( !ui.dvdsimple->isChecked() )
512 mrl = "dvd://" LOCALHOST;
514 mrl = "dvdsimple://" LOCALHOST + discPath;
515 } else if ( ui.bdRadioButton->isChecked() )
516 mrl = "bluray://" LOCALHOST;
518 else if ( ui.vcdRadioButton->isChecked() )
519 mrl = "vcd://" LOCALHOST;
522 mrl = "cdda://" LOCALHOST;
526 /* Title/chapter encoded in MRL */
527 if( ui.titleSpin->value() > 0 ) {
528 if( ui.dvdRadioButton->isChecked() || ui.bdRadioButton->isChecked() ) {
529 mrl += QString("#%1").arg( ui.titleSpin->value() );
530 if ( ui.chapterSpin->value() > 0 )
531 mrl+= QString(":%1").arg( ui.chapterSpin->value() );
533 else if ( ui.vcdRadioButton->isChecked() )
534 mrl += QString("@%1").arg( ui.titleSpin->value() );
537 emit methodChanged( "disc-caching" );
539 fileList << mrl; mrl = "";
541 /* Input item options */
542 if ( ui.dvdRadioButton->isChecked() || ui.vcdRadioButton->isChecked() )
544 if ( ui.audioSpin->value() >= 0 ) {
545 mrl += " :audio-track=" +
546 QString("%1").arg( ui.audioSpin->value() );
548 if ( ui.subtitlesSpin->value() >= 0 ) {
549 mrl += " :sub-track=" +
550 QString("%1").arg( ui.subtitlesSpin->value() );
553 if( ui.audioCDRadioButton->isChecked() )
555 if( ui.titleSpin->value() > 0 )
556 mrl += QString(" :cdda-track=%1").arg( ui.titleSpin->value() );
558 emit mrlUpdated( fileList, mrl );
561 void DiscOpenPanel::browseDevice()
563 QString dir = QFileDialog::getExistingDirectory( this,
564 qtr( I_DEVICE_TOOLTIP ) );
567 ui.deviceCombo->addItem( toNativeSepNoSlash( dir ) );
568 ui.deviceCombo->setCurrentIndex( ui.deviceCombo->findText( toNativeSepNoSlash( dir ) ) );
575 void DiscOpenPanel::eject()
577 intf_Eject( p_intf, qtu( ui.deviceCombo->currentText() ) );
580 void DiscOpenPanel::accept()
583 /**************************************************************************
584 * Open Network streams and URL pages *
585 **************************************************************************/
586 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
587 OpenPanel( _parent, _p_intf )
590 CONNECT( ui.urlComboBox, editTextChanged( const QString& ), this, updateMRL());
593 if( var_InheritBool( p_intf, "qt-recentplay" ) )
596 ui.urlComboBox->addItems( getSettings()->value( "OpenDialog/netMRL" ).toStringList() );
597 ui.urlComboBox->setMaxCount( 10 );
600 b_recentList = false;
602 /* Use a simple validator for URLs */
603 ui.urlComboBox->setValidator( new UrlValidator( this ) );
604 ui.urlComboBox->setFocus();
607 NetOpenPanel::~NetOpenPanel()
609 if( !b_recentList ) return;
611 /* Create the list with the current items */
613 for( int i = 0; i < ui.urlComboBox->count(); i++ )
614 mrlList << ui.urlComboBox->itemText( i );
616 /* Clean the list... */
617 mrlList.removeDuplicates();
618 /* ...and save the 8 last entries */
619 getSettings()->setValue( "OpenDialog/netMRL", mrlList );
622 void NetOpenPanel::clear()
624 ui.urlComboBox->clear();
627 void NetOpenPanel::onAccept()
629 if( ui.urlComboBox->findText( ui.urlComboBox->currentText() ) == -1 )
630 ui.urlComboBox->insertItem( 0, ui.urlComboBox->currentText());
633 void NetOpenPanel::onFocus()
635 ui.urlComboBox->setFocus();
636 ui.urlComboBox->lineEdit()->selectAll();
639 void NetOpenPanel::updateMRL()
641 QString url = ui.urlComboBox->lineEdit()->text();
646 emit methodChanged( qfu( "network-caching" ) );
650 emit mrlUpdated( qsl, "" );
653 QValidator::State UrlValidator::validate( QString& str, int& ) const
655 if( str.contains( ' ' ) )
656 return QValidator::Invalid;
657 if( !str.contains( "://" ) )
658 return QValidator::Intermediate;
659 return QValidator::Acceptable;
662 void UrlValidator::fixup( QString& str ) const
667 /**************************************************************************
668 * Open Capture device ( DVB, PVR, V4L, and similar ) *
669 **************************************************************************/
670 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
671 OpenPanel( _parent, _p_intf )
673 isInitialized = false;
676 void CaptureOpenPanel::initialize()
678 if( isInitialized ) return;
680 isInitialized = true;
684 BUTTONACT( ui.advancedButton, advancedDialog() );
686 /* Create two stacked layouts in the main comboBoxes */
687 QStackedLayout *stackedDevLayout = new QStackedLayout;
688 ui.cardBox->setLayout( stackedDevLayout );
690 QStackedLayout *stackedPropLayout = new QStackedLayout;
691 ui.optionsBox->setLayout( stackedPropLayout );
693 /* Creation and connections of the WIdgets in the stacked layout */
694 #define addModuleAndLayouts( number, name, label, layout ) \
695 QWidget * name ## DevPage = new QWidget( this ); \
696 QWidget * name ## PropPage = new QWidget( this ); \
697 stackedDevLayout->addWidget( name ## DevPage ); \
698 stackedPropLayout->addWidget( name ## PropPage ); \
699 layout * name ## DevLayout = new layout; \
700 layout * name ## PropLayout = new layout; \
701 name ## DevPage->setLayout( name ## DevLayout ); \
702 name ## PropPage->setLayout( name ## PropLayout ); \
703 ui.deviceCombo->addItem( qtr( label ), QVariant( number ) );
705 #define CuMRL( widget, slot ) CONNECT( widget , slot , this, updateMRL() );
708 /*********************
709 * DirectShow Stuffs *
710 *********************/
711 if( module_exists( "dshow" ) ){
712 addModuleAndLayouts( DSHOW_DEVICE, dshow, "DirectShow", QGridLayout );
716 module_config_t *p_config =
717 config_FindConfig( VLC_OBJECT(p_intf), "dshow-vdev" );
718 vdevDshowW = new StringListConfigControl(
719 VLC_OBJECT(p_intf), p_config, this, dshowDevLayout, line );
722 p_config = config_FindConfig( VLC_OBJECT(p_intf), "dshow-adev" );
723 adevDshowW = new StringListConfigControl(
724 VLC_OBJECT(p_intf), p_config, this, dshowDevLayout, line );
727 /* dshow Properties */
728 QLabel *dshowVSizeLabel = new QLabel( qtr( "Video size" ) );
729 dshowPropLayout->addWidget( dshowVSizeLabel, 0, 0 );
731 dshowVSizeLine = new QLineEdit;
732 dshowPropLayout->addWidget( dshowVSizeLine, 0, 1);
733 dshowPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
737 CuMRL( vdevDshowW->combo, currentIndexChanged ( int ) );
738 CuMRL( adevDshowW->combo, currentIndexChanged ( int ) );
739 CuMRL( dshowVSizeLine, textChanged( const QString& ) );
740 configList << "dshow-vdev" << "dshow-adev" << "dshow-size";
746 if( module_exists( "v4l2" ) ){
747 addModuleAndLayouts( V4L2_DEVICE, v4l2, "Video for Linux 2", QGridLayout );
749 char const * const ppsz_v4lvdevices[] = {
753 /* V4L2 main panel */
754 QLabel *v4l2VideoDeviceLabel = new QLabel( qtr( "Video device name" ) );
755 v4l2DevLayout->addWidget( v4l2VideoDeviceLabel, 0, 0 );
757 v4l2VideoDevice = new QComboBox( this );
758 v4l2VideoDevice->setEditable( true );
759 POPULATE_WITH_DEVS( ppsz_v4lvdevices, v4l2VideoDevice );
760 v4l2VideoDevice->clearEditText();
761 v4l2DevLayout->addWidget( v4l2VideoDevice, 0, 1 );
763 QLabel *v4l2AudioDeviceLabel = new QLabel( qtr( "Audio device name" ) );
764 v4l2DevLayout->addWidget( v4l2AudioDeviceLabel, 1, 0 );
766 v4l2AudioDevice = new QComboBox( this );
767 v4l2AudioDevice->setEditable( true );
769 QStringList patterns = QStringList();
770 patterns << QString( "pcmC*D*c" );
772 QStringList nodes = QDir( "/dev/snd" ).entryList( patterns,
774 QStringList names = nodes.replaceInStrings( QRegExp("^pcmC"), "hw:" )
775 .replaceInStrings( QRegExp("c$"), "" )
776 .replaceInStrings( QRegExp("D"), "," );
777 v4l2AudioDevice->addItems( names );
779 v4l2AudioDevice->clearEditText();
780 v4l2DevLayout->addWidget( v4l2AudioDevice, 1, 1 );
782 /* v4l2 Props panel */
783 QLabel *v4l2StdLabel = new QLabel( qtr( "Video standard" ) );
784 v4l2PropLayout->addWidget( v4l2StdLabel, 0 , 0 );
786 v4l2StdBox = new QComboBox;
787 setfillVLCConfigCombo( "v4l2-standard", p_intf, v4l2StdBox );
788 v4l2PropLayout->addWidget( v4l2StdBox, 0 , 1 );
789 v4l2PropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
793 CuMRL( v4l2VideoDevice->lineEdit(), textChanged( const QString& ) );
794 CuMRL( v4l2VideoDevice, currentIndexChanged ( int ) );
795 CuMRL( v4l2AudioDevice->lineEdit(), textChanged( const QString& ) );
796 CuMRL( v4l2AudioDevice, currentIndexChanged ( int ) );
797 CuMRL( v4l2StdBox, currentIndexChanged ( int ) );
798 configList << "v4l2-standard" << "v4l2-dev";
804 if( module_exists( "jack" ) ){
805 addModuleAndLayouts( JACK_DEVICE, jack, "JACK Audio Connection Kit",
808 /* Jack Main panel */
810 QLabel *jackChannelsLabel = new QLabel( qtr( "Channels:" ) );
811 jackDevLayout->addWidget( jackChannelsLabel, 1, 0 );
813 jackChannels = new QSpinBox;
814 setSpinBoxFreq( jackChannels );
815 jackChannels->setMaximum(255);
816 jackChannels->setValue(2);
817 jackChannels->setAlignment( Qt::AlignRight );
818 jackDevLayout->addWidget( jackChannels, 1, 1 );
821 QLabel *jackPortsLabel = new QLabel( qtr( "Selected ports:" ) );
822 jackDevLayout->addWidget( jackPortsLabel, 0 , 0 );
824 jackPortsSelected = new QLineEdit( qtr( ".*") );
825 jackPortsSelected->setAlignment( Qt::AlignRight );
826 jackDevLayout->addWidget( jackPortsSelected, 0, 1 );
828 /* Jack Props panel */
831 jackPace = new QCheckBox(qtr( "Use VLC pace" ));
832 jackPropLayout->addWidget( jackPace, 1, 1 );
835 jackConnect = new QCheckBox( qtr( "Auto connection" ));
836 jackPropLayout->addWidget( jackConnect, 1, 2 );
839 CuMRL( jackChannels, valueChanged( int ) );
840 CuMRL( jackPace, stateChanged( int ) );
841 CuMRL( jackConnect, stateChanged( int ) );
842 CuMRL( jackPortsSelected, textChanged( const QString& ) );
843 configList << "jack-input-use-vlc-pace" << "jack-input-auto-connect";
849 if( module_exists( "pvr" ) ){
850 addModuleAndLayouts( PVR_DEVICE, pvr, "PVR", QGridLayout );
853 QLabel *pvrDeviceLabel = new QLabel( qtr( "Device name" ) );
854 pvrDevLayout->addWidget( pvrDeviceLabel, 0, 0 );
856 pvrDevice = new QLineEdit;
857 pvrDevLayout->addWidget( pvrDevice, 0, 1 );
859 QLabel *pvrRadioDeviceLabel = new QLabel( qtr( "Radio device name" ) );
860 pvrDevLayout->addWidget( pvrRadioDeviceLabel, 1, 0 );
862 pvrRadioDevice = new QLineEdit;
863 pvrDevLayout->addWidget( pvrRadioDevice, 1, 1 );
865 /* PVR props panel */
866 QLabel *pvrNormLabel = new QLabel( qtr( "Norm" ) );
867 pvrPropLayout->addWidget( pvrNormLabel, 0, 0 );
869 pvrNormBox = new QComboBox;
870 setfillVLCConfigCombo( "pvr-norm", p_intf, pvrNormBox );
871 pvrPropLayout->addWidget( pvrNormBox, 0, 1 );
873 QLabel *pvrFreqLabel = new QLabel( qtr( "Frequency" ) );
874 pvrPropLayout->addWidget( pvrFreqLabel, 1, 0 );
876 pvrFreq = new QSpinBox;
877 pvrFreq->setAlignment( Qt::AlignRight );
878 pvrFreq->setSuffix(" kHz");
879 setSpinBoxFreq( pvrFreq );
880 pvrPropLayout->addWidget( pvrFreq, 1, 1 );
882 QLabel *pvrBitrLabel = new QLabel( qtr( "Bitrate" ) );
883 pvrPropLayout->addWidget( pvrBitrLabel, 2, 0 );
885 pvrBitr = new QSpinBox;
886 pvrBitr->setAlignment( Qt::AlignRight );
887 pvrBitr->setSuffix(" kHz");
888 setSpinBoxFreq( pvrBitr );
889 pvrPropLayout->addWidget( pvrBitr, 2, 1 );
890 pvrPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
894 CuMRL( pvrDevice, textChanged( const QString& ) );
895 CuMRL( pvrRadioDevice, textChanged( const QString& ) );
897 CuMRL( pvrFreq, valueChanged ( int ) );
898 CuMRL( pvrBitr, valueChanged ( int ) );
899 CuMRL( pvrNormBox, currentIndexChanged ( int ) );
900 configList << "pvr-device" << "pvr-radio-device" << "pvr-norm"
901 << "pvr-frequency" << "pvr-bitrate";
907 if( module_exists( "dtv" ) ){
908 addModuleAndLayouts( DTV_DEVICE, dvb, N_("TV (digital)"), QGridLayout );
911 QLabel *dvbDeviceLabel = new QLabel( qtr( "Tuner card" ) );
912 QLabel *dvbTypeLabel = new QLabel( qtr( "Delivery system" ) );
914 dvbCard = new QSpinBox;
915 dvbCard->setAlignment( Qt::AlignRight );
917 dvbCard->setPrefix( "/dev/dvb/adapter" );
919 dvbDevLayout->addWidget( dvbDeviceLabel, 0, 0 );
920 dvbDevLayout->addWidget( dvbCard, 0, 1, 1, 2 );
922 dvbc = new QRadioButton( "DVB-C" );
923 dvbs = new QRadioButton( "DVB-S" );
924 dvbs2 = new QRadioButton( "DVB-S2" );
925 dvbt = new QRadioButton( "DVB-T" );
926 dvbt2 = new QRadioButton( "DVB-T2" );
927 atsc = new QRadioButton( "ATSC" );
928 cqam = new QRadioButton( "Clear QAM" );
929 dvbt->setChecked( true );
931 dvbDevLayout->addWidget( dvbTypeLabel, 1, 0, 2, 1 );
932 dvbDevLayout->addWidget( dvbc, 1, 1 );
933 dvbDevLayout->addWidget( dvbs, 1, 2 );
934 dvbDevLayout->addWidget( dvbs2, 2, 2 );
935 dvbDevLayout->addWidget( dvbt, 1, 3 );
936 dvbDevLayout->addWidget( dvbt2, 2, 3 );
937 dvbDevLayout->addWidget( atsc, 1, 4 );
938 dvbDevLayout->addWidget( cqam, 2, 4 );
940 /* DVB Props panel */
941 QLabel *dvbFreqLabel =
942 new QLabel( qtr( "Transponder/multiplex frequency" ) );
943 dvbPropLayout->addWidget( dvbFreqLabel, 0, 0 );
945 dvbFreq = new QSpinBox;
946 dvbFreq->setAlignment( Qt::AlignRight );
947 dvbFreq->setSuffix(" kHz");
948 dvbFreq->setSingleStep( 1000 );
949 setSpinBoxFreq( dvbFreq );
950 dvbPropLayout->addWidget( dvbFreq, 0, 1 );
952 dvbSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
953 dvbPropLayout->addWidget( dvbSrateLabel, 1, 0 );
955 dvbSrate = new QSpinBox;
956 dvbSrate->setAlignment( Qt::AlignRight );
957 dvbSrate->setSuffix(" bauds");
958 setSpinBoxFreq( dvbSrate );
959 dvbPropLayout->addWidget( dvbSrate, 1, 1 );
961 dvbModLabel = new QLabel( qtr( "Modulation / Constellation" ) );
962 dvbPropLayout->addWidget( dvbModLabel, 2, 0 );
964 dvbQamBox = new QComboBox;
965 dvbQamBox->addItem( qtr( "Automatic" ), qfu("QAM") );
966 dvbQamBox->addItem( "256-QAM", qfu("256QAM") );
967 dvbQamBox->addItem( "128-QAM", qfu("128QAM") );
968 dvbQamBox->addItem( "64-QAM", qfu("64QAM") );
969 dvbQamBox->addItem( "32-QAM", qfu("32QAM") );
970 dvbQamBox->addItem( "16-QAM", qfu("16QAM") );
971 dvbPropLayout->addWidget( dvbQamBox, 2, 1 );
973 dvbPskBox = new QComboBox;
974 dvbPskBox->addItem( "QPSK", qfu("QPSK") );
975 dvbPskBox->addItem( "DQPSK", qfu("DQPSK") );
976 dvbPskBox->addItem( "8-PSK", qfu("8PSK") );
977 dvbPskBox->addItem( "16-APSK", qfu("16APSK") );
978 dvbPskBox->addItem( "32-APSK", qfu("32APSK") );
979 dvbPropLayout->addWidget( dvbPskBox, 2, 1 );
985 dvbBandLabel = new QLabel( qtr( "Bandwidth" ) );
986 dvbPropLayout->addWidget( dvbBandLabel, 2, 0 );
988 dvbBandBox = new QComboBox;
989 setfillVLCConfigCombo( "dvb-bandwidth", p_intf, dvbBandBox );
990 dvbPropLayout->addWidget( dvbBandBox, 2, 1 );
992 dvbBandLabel->hide();
995 dvbPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
999 CuMRL( dvbCard, valueChanged ( int ) );
1000 CuMRL( dvbFreq, valueChanged ( int ) );
1001 CuMRL( dvbSrate, valueChanged ( int ) );
1002 CuMRL( dvbQamBox, currentIndexChanged ( int ) );
1003 CuMRL( dvbPskBox, currentIndexChanged ( int ) );
1004 CuMRL( dvbBandBox, currentIndexChanged ( int ) );
1006 BUTTONACT( dvbc, updateButtons() );
1007 BUTTONACT( dvbs, updateButtons() );
1008 BUTTONACT( dvbs2, updateButtons() );
1009 BUTTONACT( dvbt, updateButtons() );
1010 BUTTONACT( dvbt2, updateButtons() );
1011 BUTTONACT( atsc, updateButtons() );
1012 BUTTONACT( cqam, updateButtons() );
1013 BUTTONACT( dvbc, updateMRL() );
1014 BUTTONACT( dvbt, updateMRL() );
1015 BUTTONACT( dvbt2, updateMRL() );
1016 BUTTONACT( dvbs, updateMRL() );
1017 BUTTONACT( dvbs2, updateMRL() );
1018 BUTTONACT( atsc, updateMRL() );
1019 BUTTONACT( cqam, updateMRL() );
1020 configList << "dvb-adapter" << "dvb-frequency" << "dvb-modulation"
1027 addModuleAndLayouts( SCREEN_DEVICE, screen, "Desktop", QGridLayout );
1028 QLabel *screenLabel = new QLabel( qtr( "Your display will be "
1029 "opened and played in order to stream or save it." ) );
1030 screenLabel->setWordWrap( true );
1031 screenDevLayout->addWidget( screenLabel, 0, 0 );
1033 QLabel *screenFPSLabel = new QLabel(
1034 qtr( "Desired frame rate for the capture." ) );
1035 screenPropLayout->addWidget( screenFPSLabel, 0, 0 );
1037 screenFPS = new QDoubleSpinBox;
1038 screenFPS->setValue( 1. );
1039 screenFPS->setRange( .01, 100. );
1040 screenFPS->setAlignment( Qt::AlignRight );
1041 /* xgettext: frames per second */
1042 screenFPS->setSuffix( qtr( " f/s" ) );
1043 screenPropLayout->addWidget( screenFPS, 0, 1 );
1045 /* Screen connect */
1046 CuMRL( screenFPS, valueChanged( double ) );
1048 /* General connects */
1049 CONNECT( ui.deviceCombo, activated( int ) ,
1050 stackedDevLayout, setCurrentIndex( int ) );
1051 CONNECT( ui.deviceCombo, activated( int ),
1052 stackedPropLayout, setCurrentIndex( int ) );
1053 CONNECT( ui.deviceCombo, activated( int ), this, updateMRL() );
1054 CONNECT( ui.deviceCombo, activated( int ), this, updateButtons() );
1057 #undef addModuleAndLayouts
1060 CaptureOpenPanel::~CaptureOpenPanel()
1064 void CaptureOpenPanel::clear()
1069 void CaptureOpenPanel::updateMRL()
1072 QStringList fileList;
1073 int i_devicetype = ui.deviceCombo->itemData(
1074 ui.deviceCombo->currentIndex() ).toInt();
1075 switch( i_devicetype )
1079 fileList << "dshow://";
1080 mrl+= " :dshow-vdev=" +
1081 colon_escape( QString("%1").arg( vdevDshowW->getValue() ) );
1082 mrl+= " :dshow-adev=" +
1083 colon_escape( QString("%1").arg( adevDshowW->getValue() ) )+" ";
1084 if( dshowVSizeLine->isModified() )
1085 mrl += ":dshow-size=" + dshowVSizeLine->text();
1089 fileList << "v4l2://" + v4l2VideoDevice->currentText();
1090 mrl += ":v4l2-standard="
1091 + v4l2StdBox->itemData( v4l2StdBox->currentIndex() ).toString();
1092 mrl += " :input-slave=alsa://" + v4l2AudioDevice->currentText();
1096 mrl += "channels=" + QString::number( jackChannels->value() );
1097 mrl += ":ports=" + jackPortsSelected->text();
1098 fileList << mrl; mrl = "";
1100 if ( jackPace->isChecked() )
1102 mrl += " :jack-input-use-vlc-pace";
1104 if ( jackConnect->isChecked() )
1106 mrl += " :jack-input-auto-connect";
1110 fileList << "pvr://";
1111 mrl += " :pvr-device=" + pvrDevice->text();
1112 mrl += " :pvr-radio-device=" + pvrRadioDevice->text();
1113 mrl += " :pvr-norm=" + QString::number( pvrNormBox->currentIndex() );
1114 if( pvrFreq->value() )
1115 mrl += " :pvr-frequency=" + QString::number( pvrFreq->value() );
1116 if( pvrBitr->value() )
1117 mrl += " :pvr-bitrate=" + QString::number( pvrBitr->value() );
1121 if( dvbc->isChecked() ) mrl = "dvb-c://";
1123 if( dvbs->isChecked() ) mrl = "dvb-s://";
1125 if( dvbs2->isChecked() ) mrl = "dvb-s2://";
1127 if( dvbt->isChecked() ) mrl = "dvb-t://";
1129 if( dvbt2->isChecked() ) mrl = "dvb-t2://";
1131 if( atsc->isChecked() ) mrl = "atsc://";
1133 if( cqam->isChecked() ) mrl = "cqam://";
1135 mrl += "frequency=" + QString::number( dvbFreq->value() ) + "000";
1137 if( dvbc->isChecked() || cqam->isChecked() )
1138 mrl += ":modulation="
1139 + dvbQamBox->itemData( dvbQamBox->currentIndex() ).toString();
1140 if( dvbs2->isChecked() )
1141 mrl += ":modulation="
1142 + dvbPskBox->itemData( dvbPskBox->currentIndex() ).toString();
1143 if( dvbc->isChecked() || dvbs->isChecked() || dvbs2->isChecked() )
1144 mrl += ":srate=" + QString::number( dvbSrate->value() );
1145 if( dvbt->isChecked() || dvbt2->isChecked() )
1146 mrl += ":bandwidth=" +
1147 QString::number( dvbBandBox->itemData(
1148 dvbBandBox->currentIndex() ).toInt() );
1150 fileList << mrl; mrl= "";
1151 mrl += " :dvb-adapter=" + QString::number( dvbCard->value() );
1154 fileList << "screen://";
1155 mrl = " :screen-fps=" + QString::number( screenFPS->value(), 'f' );
1159 emit methodChanged( "live-caching" );
1161 if( !advMRL.isEmpty() ) mrl += advMRL;
1163 emit mrlUpdated( fileList, mrl );
1167 * Update the Buttons (show/hide) for the GUI as all device type don't
1168 * use the same ui. elements.
1170 void CaptureOpenPanel::updateButtons()
1172 /* Be sure to display the ui Elements in case they were hidden by
1173 * some Device Type (like Screen://) */
1174 ui.optionsBox->show();
1175 ui.advancedButton->show();
1176 /* Get the current Device Number */
1177 int i_devicetype = ui.deviceCombo->itemData(
1178 ui.deviceCombo->currentIndex() ).toInt();
1179 switch( i_devicetype )
1183 dvbSrateLabel->hide();
1186 dvbModLabel->hide();
1188 dvbBandLabel->hide();
1190 if( dvbc->isChecked() )
1193 dvbSrateLabel->show();
1195 dvbModLabel->show();
1197 else if( dvbs->isChecked() )
1200 dvbSrateLabel->show();
1202 else if( dvbs2->isChecked() )
1205 dvbSrateLabel->show();
1207 dvbModLabel->show();
1209 else if( dvbt->isChecked() || dvbt2->isChecked() )
1212 dvbBandLabel->show();
1216 //ui.optionsBox->hide();
1217 ui.advancedButton->hide();
1224 void CaptureOpenPanel::advancedDialog()
1226 /* Get selected device type */
1227 int i_devicetype = ui.deviceCombo->itemData(
1228 ui.deviceCombo->currentIndex() ).toInt();
1230 /* Get the corresponding module */
1231 module_t *p_module =
1232 module_find( psz_devModule[i_devicetype] );
1233 if( NULL == p_module ) return;
1236 QList<ConfigControl *> controls;
1238 /* Get the confsize */
1239 unsigned int i_confsize;
1240 module_config_t *p_config;
1241 p_config = module_config_get( p_module, &i_confsize );
1243 /* New Adv Prop dialog */
1244 adv = new QDialog( this );
1245 adv->setWindowTitle( qtr( "Advanced Options" ) );
1246 adv->setWindowRole( "vlc-advanced-options" );
1248 /* A main Layout with a Frame */
1249 QVBoxLayout *mainLayout = new QVBoxLayout( adv );
1250 QScrollArea *scroll = new QScrollArea;
1251 mainLayout->addWidget( scroll );
1253 QFrame *advFrame = new QFrame;
1254 /* GridLayout inside the Frame */
1255 QGridLayout *gLayout = new QGridLayout( advFrame );
1257 scroll->setWidgetResizable( true );
1258 scroll->setWidget( advFrame );
1260 /* Create the options inside the FrameLayout */
1261 for( int n = 0; n < (int)i_confsize; n++ )
1263 module_config_t *p_item = p_config + n;
1264 QString name = p_item->psz_name;
1266 if( name.isEmpty() || configList.contains( name ) )
1269 msg_Err( p_intf, "%s", p_item->psz_name);
1270 ConfigControl *config = ConfigControl::createControl(
1271 VLC_OBJECT( p_intf ), p_item, advFrame, gLayout, n );
1273 controls.append( config );
1277 QDialogButtonBox *advButtonBox = new QDialogButtonBox( adv );
1278 QPushButton *closeButton = new QPushButton( qtr( "OK" ) );
1279 QPushButton *cancelButton = new QPushButton( qtr( "Cancel" ) );
1281 CONNECT( closeButton, clicked(), adv, accept() );
1282 CONNECT( cancelButton, clicked(), adv, reject() );
1284 advButtonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
1285 advButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
1287 mainLayout->addWidget( advButtonBox );
1289 /* Creation of the MRL */
1292 QString tempMRL = "";
1293 for( int i = 0; i < controls.count(); i++ )
1295 ConfigControl *control = controls[i];
1297 tempMRL += (i ? " :" : ":");
1299 if( control->getType() == CONFIG_ITEM_BOOL )
1300 if( !(qobject_cast<VIntConfigControl *>(control)->getValue() ) )
1303 tempMRL += control->getName();
1305 switch( control->getType() )
1307 case CONFIG_ITEM_STRING:
1308 case CONFIG_ITEM_LOADFILE:
1309 case CONFIG_ITEM_SAVEFILE:
1310 case CONFIG_ITEM_DIRECTORY:
1311 case CONFIG_ITEM_MODULE:
1312 tempMRL += colon_escape( QString("=%1").arg( qobject_cast<VStringConfigControl *>(control)->getValue() ) );
1314 case CONFIG_ITEM_INTEGER:
1315 tempMRL += QString("=%1").arg( qobject_cast<VIntConfigControl *>(control)->getValue() );
1317 case CONFIG_ITEM_FLOAT:
1318 tempMRL += QString("=%1").arg( qobject_cast<VFloatConfigControl *>(control)->getValue() );
1325 qDeleteAll( controls );
1327 module_config_free( p_config );