1 /*****************************************************************************
2 * open_panels.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>
40 #include <vlc_plugin.h>
42 #include <vlc_charset.h> /* FromWide for Win32 */
45 #include <QFileDialog>
46 #include <QDialogButtonBox>
48 #include <QStackedLayout>
51 #include <QScrollArea>
55 #define I_DEVICE_TOOLTIP \
56 I_DIR_OR_FOLDER( N_("Select a device or a VIDEO_TS directory"), \
57 N_("Select a device or a VIDEO_TS folder") )
59 #include "../../eject.c"
61 /* Populate a combobox with the devices matching a pattern.
62 Combobox will automatically do autocompletion on the edit zone */
63 #define POPULATE_WITH_DEVS(ppsz_devlist, targetCombo) \
64 QStringList targetCombo ## StringList = QStringList(); \
65 for ( size_t i = 0; i< sizeof(ppsz_devlist) / sizeof(*ppsz_devlist); i++ ) \
66 targetCombo ## StringList << QString( ppsz_devlist[ i ] ); \
67 targetCombo->addItems( QDir( "/dev/" )\
68 .entryList( targetCombo ## StringList, QDir::System )\
69 .replaceInStrings( QRegExp("^"), "/dev/" ) \
72 static const char psz_devModule[][8] = { "v4l2", "pvr", "dtv",
73 "dshow", "screen", "jack" };
75 /**************************************************************************
76 * Open Files and subtitles *
77 **************************************************************************/
78 FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
79 OpenPanel( _parent, _p_intf ), dialogBox( NULL )
81 /* Classic UI Setup */
84 setAcceptDrops( true );
86 /* Set Filters for file selection */
87 /* QString fileTypes = "";
88 ADD_FILTER_MEDIA( fileTypes );
89 ADD_FILTER_VIDEO( fileTypes );
90 ADD_FILTER_AUDIO( fileTypes );
91 ADD_FILTER_PLAYLIST( fileTypes );
92 ADD_FILTER_ALL( fileTypes );
93 fileTypes.replace( QString(";*"), QString(" *")); */
96 /* lineFileEdit = ui.fileEdit;
97 //TODO later: fill the fileCompleteList with previous items played.
98 QCompleter *fileCompleter = new QCompleter( fileCompleteList, this );
99 fileCompleter->setModel( new QDirModel( fileCompleter ) );
100 lineFileEdit->setCompleter( fileCompleter );*/
101 if( var_InheritBool( p_intf, "qt-embedded-open" ) )
103 ui.tempWidget->hide();
108 /* Deactivate the subtitles control by default. */
109 ui.subFrame->setEnabled( false );
112 BUTTONACT( ui.fileBrowseButton, browseFile() );
113 BUTTONACT( ui.removeFileButton, removeFile() );
115 BUTTONACT( ui.subBrowseButton, browseFileSub() );
116 CONNECT( ui.subCheckBox, toggled( bool ), this, toggleSubtitleFrame( bool ) );
118 CONNECT( ui.fileListWidg, itemChanged( QListWidgetItem * ), this, updateMRL() );
119 CONNECT( ui.subInput, textChanged( const QString& ), this, updateMRL() );
123 inline void FileOpenPanel::BuildOldPanel()
125 /** BEGIN QFileDialog tweaking **/
126 /* Use a QFileDialog and customize it because we don't want to
127 rewrite it all. Be careful to your eyes cause there are a few hacks.
128 Be very careful and test correctly when you modify this. */
130 /* Make this QFileDialog a child of tempWidget from the ui. */
131 dialogBox = new FileOpenBox( ui.tempWidget, NULL,
132 p_intf->p_sys->filepath, "" );
134 dialogBox->setFileMode( QFileDialog::ExistingFiles );
135 dialogBox->setAcceptMode( QFileDialog::AcceptOpen );
136 dialogBox->restoreState(
137 getSettings()->value( "file-dialog-state" ).toByteArray() );
139 /* We don't want to see a grip in the middle of the window, do we? */
140 dialogBox->setSizeGripEnabled( false );
143 dialogBox->setToolTip( qtr( "Select one or multiple files" ) );
144 dialogBox->setMinimumHeight( 250 );
146 // But hide the two OK/Cancel buttons. Enable them for debug.
147 QDialogButtonBox *fileDialogAcceptBox =
148 dialogBox->findChildren<QDialogButtonBox*>()[0];
149 fileDialogAcceptBox->hide();
151 /* Ugly hacks to get the good Widget */
152 //This lineEdit is the normal line in the fileDialog.
153 QLineEdit *lineFileEdit = dialogBox->findChildren<QLineEdit*>()[0];
154 /* Make a list of QLabel inside the QFileDialog to access the good ones */
155 QList<QLabel *> listLabel = dialogBox->findChildren<QLabel*>();
157 /* Hide the FileNames one. Enable it for debug */
158 listLabel[1]->setText( qtr( "File names:" ) );
159 /* Change the text that was uncool in the usual box */
160 listLabel[2]->setText( qtr( "Filter:" ) );
162 dialogBox->layout()->setMargin( 0 );
163 dialogBox->layout()->setSizeConstraint( QLayout::SetNoConstraint );
165 /** END of QFileDialog tweaking **/
167 // Add the DialogBox to the layout
168 ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
170 CONNECT( lineFileEdit, textChanged( const QString& ), this, updateMRL() );
171 dialogBox->installEventFilter( this );
174 FileOpenPanel::~FileOpenPanel()
177 getSettings()->setValue( "file-dialog-state", dialogBox->saveState() );
180 void FileOpenPanel::dragEnterEvent( QDragEnterEvent *event )
182 event->acceptProposedAction();
185 void FileOpenPanel::dragMoveEvent( QDragMoveEvent *event )
187 event->acceptProposedAction();
190 void FileOpenPanel::dragLeaveEvent( QDragLeaveEvent *event )
195 void FileOpenPanel::dropEvent( QDropEvent *event )
197 if( event->possibleActions() & Qt::CopyAction )
198 event->setDropAction( Qt::CopyAction );
202 const QMimeData *mimeData = event->mimeData();
203 foreach( const QUrl &url, mimeData->urls() )
207 QListWidgetItem *item = new QListWidgetItem(
208 toNativeSeparators( url.toLocalFile() ),
210 item->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled );
211 ui.fileListWidg->addItem( item );
219 void FileOpenPanel::browseFile()
221 QStringList files = QFileDialog::getOpenFileNames( this, qtr( "Select one or multiple files" ), p_intf->p_sys->filepath) ;
222 foreach( const QString &file, files )
224 QListWidgetItem *item =
225 new QListWidgetItem( toNativeSeparators( file ), ui.fileListWidg );
226 item->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled );
227 ui.fileListWidg->addItem( item );
228 savedirpathFromFile( file );
234 void FileOpenPanel::removeFile()
236 int i = ui.fileListWidg->currentRow();
239 QListWidgetItem *temp = ui.fileListWidg->takeItem( i );
247 /* Show a fileBrowser to select a subtitle */
248 void FileOpenPanel::browseFileSub()
250 // TODO Handle selection of more than one subtitles file
251 QStringList files = THEDP->showSimpleOpen( qtr("Open subtitles file"),
252 EXT_FILTER_SUBTITLE, p_intf->p_sys->filepath );
254 if( files.isEmpty() ) return;
255 ui.subInput->setText( toNativeSeparators( files.join(" ") ) );
259 void FileOpenPanel::toggleSubtitleFrame( bool b )
261 ui.subFrame->setEnabled( b );
268 /* Update the current MRL */
269 void FileOpenPanel::updateMRL()
271 QStringList fileList;
275 if( dialogBox == NULL )
276 for( int i = 0; i < ui.fileListWidg->count(); i++ )
278 if( !ui.fileListWidg->item( i )->text().isEmpty() )
279 fileList << toURI(ui.fileListWidg->item( i )->text());
283 fileList = dialogBox->selectedFiles();
284 for( int i = 0; i < fileList.count(); i++ )
285 fileList[i] = toURI( fileList[i] );
289 if( ui.subCheckBox->isChecked() && !ui.subInput->text().isEmpty() ) {
290 mrl.append( " :sub-file=" + colon_escape( ui.subInput->text() ) );
293 emit methodChanged( "file-caching" );
294 emit mrlUpdated( fileList, mrl );
297 /* Function called by Open Dialog when clicke on Play/Enqueue */
298 void FileOpenPanel::accept()
301 p_intf->p_sys->filepath = dialogBox->directory().absolutePath();
302 ui.fileListWidg->clear();
305 /* Function called by Open Dialog when clicked on cancel */
306 void FileOpenPanel::clear()
308 ui.fileListWidg->clear();
309 ui.subInput->clear();
312 /* Update buttons depending on current selection */
313 void FileOpenPanel::updateButtons()
315 bool b_has_files = ( ui.fileListWidg->count() > 0 );
316 ui.removeFileButton->setEnabled( b_has_files );
317 ui.subCheckBox->setEnabled( b_has_files );
320 /**************************************************************************
321 * Open Discs ( DVD, CD, VCD and similar devices ) *
322 **************************************************************************/
323 DiscOpenPanel::DiscOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
324 OpenPanel( _parent, _p_intf )
328 /* Get the default configuration path for the devices */
329 psz_dvddiscpath = var_InheritString( p_intf, "dvd" );
330 psz_vcddiscpath = var_InheritString( p_intf, "vcd" );
331 psz_cddadiscpath = var_InheritString( p_intf, "cd-audio" );
333 /* State to avoid overwritting the users changes with the configuration */
336 ui.browseDiscButton->setToolTip( qtr( I_DEVICE_TOOLTIP ));
337 ui.deviceCombo->setToolTip( qtr(I_DEVICE_TOOLTIP) );
338 ui.deviceCombo->setInsertPolicy( QComboBox::InsertAtTop );
341 char const * const ppsz_discdevices[] = {
348 QComboBox *discCombo = ui.deviceCombo; /* avoid namespacing in macro */
349 POPULATE_WITH_DEVS( ppsz_discdevices, discCombo );
353 BUTTONACT( ui.dvdRadioButton, updateButtons() );
354 BUTTONACT( ui.bdRadioButton, updateButtons() );
355 BUTTONACT( ui.vcdRadioButton, updateButtons() );
356 BUTTONACT( ui.audioCDRadioButton, updateButtons() );
357 BUTTONACT( ui.dvdsimple, updateButtons() );
358 BUTTONACT( ui.browseDiscButton, browseDevice() );
359 BUTTON_SET_ACT_I( ui.ejectButton, "", toolbar/eject, qtr( "Eject the disc" ),
362 CONNECT( ui.deviceCombo, editTextChanged( QString ), this, updateMRL());
363 CONNECT( ui.deviceCombo, currentIndexChanged( QString ), this, updateMRL());
364 CONNECT( ui.titleSpin, valueChanged( int ), this, updateMRL());
365 CONNECT( ui.chapterSpin, valueChanged( int ), this, updateMRL());
366 CONNECT( ui.audioSpin, valueChanged( int ), this, updateMRL());
367 CONNECT( ui.subtitlesSpin, valueChanged( int ), this, updateMRL());
369 /* Run once the updateButtons function in order to fill correctly the comboBoxes */
373 #ifdef WIN32 /* Disc drives probing for Windows */
374 void DiscOpenPanel::onFocus()
376 ui.deviceCombo->clear();
377 wchar_t szDrives[512];
379 if( GetLogicalDriveStringsW( sizeof( szDrives ) - 1, szDrives ) )
381 wchar_t *drive = szDrives;
382 UINT oldMode = SetErrorMode( SEM_FAILCRITICALERRORS );
385 if( GetDriveTypeW(drive) == DRIVE_CDROM )
387 wchar_t psz_name[512] = L"";
388 GetVolumeInformationW( drive, psz_name, 511, NULL, NULL, NULL, NULL, 0 );
390 QString displayName = FromWide( drive );
391 char *psz_title = FromWide( psz_name );
392 if( !EMPTY_STR(psz_title)) {
393 displayName = displayName + " - " + psz_title;
396 ui.deviceCombo->addItem( displayName, FromWide( drive ) );
400 /* go to next drive */
403 SetErrorMode(oldMode);
408 DiscOpenPanel::~DiscOpenPanel()
410 free( psz_dvddiscpath );
411 free( psz_vcddiscpath );
412 free( psz_cddadiscpath );
415 void DiscOpenPanel::clear()
417 ui.titleSpin->setValue( 0 );
418 ui.chapterSpin->setValue( 0 );
419 ui.subtitlesSpin->setValue( -1 );
420 ui.audioSpin->setValue( -1 );
425 #define setDrive( psz_name ) {\
426 int index = ui.deviceCombo->findText( qfu( psz_name ) ); \
427 if( index != -1 ) ui.deviceCombo->setCurrentIndex( index );}
429 #define setDrive( psz_name ) {\
430 ui.deviceCombo->setEditText( qfu( psz_name ) ); }
433 /* update the buttons according the type of device */
434 void DiscOpenPanel::updateButtons()
436 if ( ui.dvdRadioButton->isChecked() )
438 if( m_discType != Dvd )
440 setDrive( psz_dvddiscpath );
443 ui.titleLabel->setText( qtr("Title") );
444 ui.chapterLabel->show();
445 ui.chapterSpin->show();
446 ui.diskOptionBox_2->show();
447 ui.dvdsimple->setEnabled( true );
449 else if ( ui.bdRadioButton->isChecked() )
451 if( m_discType != BRD )
453 setDrive( psz_dvddiscpath );
455 ui.dvdsimple->setChecked( !var_InheritBool( p_intf, "bluray-menu" ) );
457 ui.titleLabel->setText( qtr("Title") );
458 ui.chapterLabel->hide();
459 ui.chapterSpin->hide();
460 ui.diskOptionBox_2->hide();
461 ui.dvdsimple->setEnabled( true );
463 else if ( ui.vcdRadioButton->isChecked() )
465 if( m_discType != Vcd )
467 setDrive( psz_vcddiscpath );
470 ui.titleLabel->setText( qtr("Entry") );
471 ui.chapterLabel->hide();
472 ui.chapterSpin->hide();
473 ui.diskOptionBox_2->show();
474 ui.dvdsimple->setEnabled( false );
478 if( m_discType != Cdda )
480 setDrive( psz_cddadiscpath );
483 ui.titleLabel->setText( qtr("Track") );
484 ui.chapterLabel->hide();
485 ui.chapterSpin->hide();
486 ui.diskOptionBox_2->hide();
487 ui.dvdsimple->setEnabled( false );
495 /* Update the current MRL */
496 void DiscOpenPanel::updateMRL()
499 QStringList fileList;
501 discPath = ui.deviceCombo->currentText();
503 int tmp = ui.deviceCombo->findText( discPath );
504 if( tmp != -1 && ui.deviceCombo->itemData( tmp ) != QVariant::Invalid )
505 discPath = ui.deviceCombo->itemData( tmp ).toString();
510 if( ui.dvdRadioButton->isChecked() ) {
511 if( !ui.dvdsimple->isChecked() )
514 scheme = "dvdsimple";
515 } else if ( ui.bdRadioButton->isChecked() )
518 else if ( ui.vcdRadioButton->isChecked() )
524 char *mrl = make_URI( qtu(discPath), scheme );
525 if( unlikely(mrl == NULL) )
528 /* Title/chapter encoded in MRL */
530 if( ui.titleSpin->value() > 0 ) {
531 if( ui.dvdRadioButton->isChecked() || ui.bdRadioButton->isChecked() ) {
532 anchor = QString("#%1").arg( ui.titleSpin->value() );
533 if ( ui.chapterSpin->value() > 0 )
534 anchor += QString(":%1").arg( ui.chapterSpin->value() );
536 else if ( ui.vcdRadioButton->isChecked() )
537 anchor = QString("#%1").arg( ui.titleSpin->value() );
540 emit methodChanged( "disc-caching" );
542 fileList << (qfu(mrl) + anchor);
547 /* Input item options */
548 if ( ui.dvdRadioButton->isChecked() || ui.vcdRadioButton->isChecked() )
550 if ( ui.audioSpin->value() >= 0 )
551 opts += " :audio-track=" +
552 QString("%1").arg( ui.audioSpin->value() );
553 if ( ui.subtitlesSpin->value() >= 0 )
554 opts += " :sub-track=" +
555 QString("%1").arg( ui.subtitlesSpin->value() );
557 else if( ui.audioCDRadioButton->isChecked() )
559 if( ui.titleSpin->value() > 0 )
560 opts += QString(" :cdda-track=%1").arg( ui.titleSpin->value() );
562 else if ( ui.bdRadioButton->isChecked() )
564 if ( ui.dvdsimple->isChecked() == false )
565 opts += " :bluray-menu";
567 emit mrlUpdated( fileList, opts );
570 void DiscOpenPanel::browseDevice()
572 QString dir = QFileDialog::getExistingDirectory( this,
573 qtr( I_DEVICE_TOOLTIP ), p_intf->p_sys->filepath );
576 ui.deviceCombo->addItem( toNativeSepNoSlash( dir ) );
577 ui.deviceCombo->setCurrentIndex( ui.deviceCombo->findText( toNativeSepNoSlash( dir ) ) );
583 void DiscOpenPanel::eject()
585 intf_Eject( p_intf, qtu( ui.deviceCombo->currentText() ) );
588 void DiscOpenPanel::accept()
591 /**************************************************************************
592 * Open Network streams and URL pages *
593 **************************************************************************/
594 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
595 OpenPanel( _parent, _p_intf )
598 CONNECT( ui.urlComboBox, editTextChanged( const QString& ), this, updateMRL());
601 if( var_InheritBool( p_intf, "qt-recentplay" ) )
604 ui.urlComboBox->addItems( getSettings()->value( "OpenDialog/netMRL" ).toStringList() );
605 ui.urlComboBox->setMaxCount( 10 );
608 b_recentList = false;
610 /* Use a simple validator for URLs */
611 ui.urlComboBox->setValidator( new UrlValidator( this ) );
612 ui.urlComboBox->setFocus();
615 NetOpenPanel::~NetOpenPanel()
617 if( !b_recentList ) return;
619 /* Create the list with the current items */
621 for( int i = 0; i < ui.urlComboBox->count(); i++ )
622 mrlList << ui.urlComboBox->itemText( i );
624 if( mrlList.count() > 0 )
626 /* Clean the list... */
627 mrlList.removeDuplicates();
628 /* ...and save the 8 last entries */
629 getSettings()->setValue( "OpenDialog/netMRL", mrlList );
633 void NetOpenPanel::clear()
635 ui.urlComboBox->clear();
638 void NetOpenPanel::onAccept()
640 if( ui.urlComboBox->findText( ui.urlComboBox->currentText() ) == -1 )
641 ui.urlComboBox->insertItem( 0, ui.urlComboBox->currentText());
644 void NetOpenPanel::onFocus()
646 ui.urlComboBox->setFocus();
647 ui.urlComboBox->lineEdit()->selectAll();
650 void NetOpenPanel::updateMRL()
652 QString url = ui.urlComboBox->lineEdit()->text();
657 emit methodChanged( qfu( "network-caching" ) );
661 emit mrlUpdated( qsl, "" );
664 QValidator::State UrlValidator::validate( QString& str, int& ) const
666 if( str.contains( ' ' ) )
667 return QValidator::Invalid;
668 if( !str.contains( "://" ) )
669 return QValidator::Intermediate;
670 return QValidator::Acceptable;
673 void UrlValidator::fixup( QString& str ) const
678 /**************************************************************************
679 * Open Capture device ( DVB, PVR, V4L, and similar ) *
680 **************************************************************************/
681 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
682 OpenPanel( _parent, _p_intf )
684 isInitialized = false;
687 void CaptureOpenPanel::initialize()
689 if( isInitialized ) return;
691 isInitialized = true;
695 BUTTONACT( ui.advancedButton, advancedDialog() );
697 /* Create two stacked layouts in the main comboBoxes */
698 QStackedLayout *stackedDevLayout = new QStackedLayout;
699 ui.cardBox->setLayout( stackedDevLayout );
701 QStackedLayout *stackedPropLayout = new QStackedLayout;
702 ui.optionsBox->setLayout( stackedPropLayout );
704 /* Creation and connections of the WIdgets in the stacked layout */
705 #define addModuleAndLayouts( number, name, label, layout ) \
706 QWidget * name ## DevPage = new QWidget( this ); \
707 QWidget * name ## PropPage = new QWidget( this ); \
708 stackedDevLayout->addWidget( name ## DevPage ); \
709 stackedPropLayout->addWidget( name ## PropPage ); \
710 layout * name ## DevLayout = new layout; \
711 layout * name ## PropLayout = new layout; \
712 name ## DevPage->setLayout( name ## DevLayout ); \
713 name ## PropPage->setLayout( name ## PropLayout ); \
714 ui.deviceCombo->addItem( qtr( label ), QVariant( number ) );
716 #define CuMRL( widget, slot ) CONNECT( widget , slot , this, updateMRL() );
719 /*********************
720 * DirectShow Stuffs *
721 *********************/
722 if( module_exists( "dshow" ) ){
723 addModuleAndLayouts( DSHOW_DEVICE, dshow, "DirectShow", QGridLayout );
727 module_config_t *p_config =
728 config_FindConfig( VLC_OBJECT(p_intf), "dshow-vdev" );
729 vdevDshowW = new StringListConfigControl(
730 VLC_OBJECT(p_intf), p_config, this );
731 vdevDshowW->insertIntoExistingGrid( dshowDevLayout, line );
734 p_config = config_FindConfig( VLC_OBJECT(p_intf), "dshow-adev" );
735 adevDshowW = new StringListConfigControl(
736 VLC_OBJECT(p_intf), p_config, this );
737 adevDshowW->insertIntoExistingGrid( dshowDevLayout, line );
740 /* dshow Properties */
741 QLabel *dshowVSizeLabel = new QLabel( qtr( "Video size" ) );
742 dshowPropLayout->addWidget( dshowVSizeLabel, 0, 0 );
744 dshowVSizeLine = new QLineEdit;
745 dshowPropLayout->addWidget( dshowVSizeLine, 0, 1);
746 dshowPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
750 CuMRL( vdevDshowW, changed() );
751 CuMRL( adevDshowW, changed() );
752 CuMRL( dshowVSizeLine, textChanged( const QString& ) );
753 configList << "dshow-vdev" << "dshow-adev" << "dshow-size";
759 if( module_exists( "v4l2" ) ){
760 addModuleAndLayouts( V4L2_DEVICE, v4l2, "Video for Linux 2", QGridLayout );
762 char const * const ppsz_v4lvdevices[] = {
766 /* V4L2 main panel */
767 QLabel *v4l2VideoDeviceLabel = new QLabel( qtr( "Video device name" ) );
768 v4l2DevLayout->addWidget( v4l2VideoDeviceLabel, 0, 0 );
770 v4l2VideoDevice = new QComboBox( this );
771 v4l2VideoDevice->setEditable( true );
772 POPULATE_WITH_DEVS( ppsz_v4lvdevices, v4l2VideoDevice );
773 v4l2VideoDevice->clearEditText();
774 v4l2DevLayout->addWidget( v4l2VideoDevice, 0, 1 );
776 QLabel *v4l2AudioDeviceLabel = new QLabel( qtr( "Audio device name" ) );
777 v4l2DevLayout->addWidget( v4l2AudioDeviceLabel, 1, 0 );
779 v4l2AudioDevice = new QComboBox( this );
780 v4l2AudioDevice->setEditable( true );
782 QStringList patterns = QStringList();
783 patterns << QString( "pcmC*D*c" );
785 QStringList nodes = QDir( "/dev/snd" ).entryList( patterns,
787 QStringList names = nodes.replaceInStrings( QRegExp("^pcmC"), "hw:" )
788 .replaceInStrings( QRegExp("c$"), "" )
789 .replaceInStrings( QRegExp("D"), "," );
790 v4l2AudioDevice->addItems( names );
792 v4l2AudioDevice->clearEditText();
793 v4l2DevLayout->addWidget( v4l2AudioDevice, 1, 1 );
795 /* v4l2 Props panel */
796 QLabel *v4l2StdLabel = new QLabel( qtr( "Video standard" ) );
797 v4l2PropLayout->addWidget( v4l2StdLabel, 0 , 0 );
799 v4l2StdBox = new QComboBox;
800 setfillVLCConfigCombo( "v4l2-standard", p_intf, v4l2StdBox );
801 v4l2PropLayout->addWidget( v4l2StdBox, 0 , 1 );
802 v4l2PropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
806 CuMRL( v4l2VideoDevice->lineEdit(), textChanged( const QString& ) );
807 CuMRL( v4l2VideoDevice, currentIndexChanged ( int ) );
808 CuMRL( v4l2AudioDevice->lineEdit(), textChanged( const QString& ) );
809 CuMRL( v4l2AudioDevice, currentIndexChanged ( int ) );
810 CuMRL( v4l2StdBox, currentIndexChanged ( int ) );
811 configList << "v4l2-standard" << "v4l2-dev";
817 if( module_exists( "jack" ) ){
818 addModuleAndLayouts( JACK_DEVICE, jack, "JACK Audio Connection Kit",
821 /* Jack Main panel */
823 QLabel *jackChannelsLabel = new QLabel( qtr( "Channels:" ) );
824 jackDevLayout->addWidget( jackChannelsLabel, 1, 0 );
826 jackChannels = new QSpinBox;
827 setSpinBoxFreq( jackChannels );
828 jackChannels->setMaximum(255);
829 jackChannels->setValue(2);
830 jackChannels->setAlignment( Qt::AlignRight );
831 jackDevLayout->addWidget( jackChannels, 1, 1 );
834 QLabel *jackPortsLabel = new QLabel( qtr( "Selected ports:" ) );
835 jackDevLayout->addWidget( jackPortsLabel, 0 , 0 );
837 jackPortsSelected = new QLineEdit( qtr( ".*") );
838 jackPortsSelected->setAlignment( Qt::AlignRight );
839 jackDevLayout->addWidget( jackPortsSelected, 0, 1 );
841 /* Jack Props panel */
844 jackPace = new QCheckBox(qtr( "Use VLC pace" ));
845 jackPropLayout->addWidget( jackPace, 1, 1 );
848 jackConnect = new QCheckBox( qtr( "Auto connection" ));
849 jackPropLayout->addWidget( jackConnect, 1, 2 );
852 CuMRL( jackChannels, valueChanged( int ) );
853 CuMRL( jackPace, stateChanged( int ) );
854 CuMRL( jackConnect, stateChanged( int ) );
855 CuMRL( jackPortsSelected, textChanged( const QString& ) );
856 configList << "jack-input-use-vlc-pace" << "jack-input-auto-connect";
862 if( module_exists( "pvr" ) ){
863 addModuleAndLayouts( PVR_DEVICE, pvr, "PVR", QGridLayout );
866 QLabel *pvrDeviceLabel = new QLabel( qtr( "Device name" ) );
867 pvrDevLayout->addWidget( pvrDeviceLabel, 0, 0 );
869 pvrDevice = new QLineEdit;
870 pvrDevLayout->addWidget( pvrDevice, 0, 1 );
872 QLabel *pvrRadioDeviceLabel = new QLabel( qtr( "Radio device name" ) );
873 pvrDevLayout->addWidget( pvrRadioDeviceLabel, 1, 0 );
875 pvrRadioDevice = new QLineEdit;
876 pvrDevLayout->addWidget( pvrRadioDevice, 1, 1 );
878 /* PVR props panel */
879 QLabel *pvrNormLabel = new QLabel( qtr( "Norm" ) );
880 pvrPropLayout->addWidget( pvrNormLabel, 0, 0 );
882 pvrNormBox = new QComboBox;
883 setfillVLCConfigCombo( "pvr-norm", p_intf, pvrNormBox );
884 pvrPropLayout->addWidget( pvrNormBox, 0, 1 );
886 QLabel *pvrFreqLabel = new QLabel( qtr( "Frequency" ) );
887 pvrPropLayout->addWidget( pvrFreqLabel, 1, 0 );
889 pvrFreq = new QSpinBox;
890 pvrFreq->setAlignment( Qt::AlignRight );
891 pvrFreq->setSuffix(" kHz");
892 setSpinBoxFreq( pvrFreq );
893 pvrPropLayout->addWidget( pvrFreq, 1, 1 );
895 QLabel *pvrBitrLabel = new QLabel( qtr( "Bitrate" ) );
896 pvrPropLayout->addWidget( pvrBitrLabel, 2, 0 );
898 pvrBitr = new QSpinBox;
899 pvrBitr->setAlignment( Qt::AlignRight );
900 pvrBitr->setSuffix(" kHz");
901 setSpinBoxFreq( pvrBitr );
902 pvrPropLayout->addWidget( pvrBitr, 2, 1 );
903 pvrPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
907 CuMRL( pvrDevice, textChanged( const QString& ) );
908 CuMRL( pvrRadioDevice, textChanged( const QString& ) );
910 CuMRL( pvrFreq, valueChanged ( int ) );
911 CuMRL( pvrBitr, valueChanged ( int ) );
912 CuMRL( pvrNormBox, currentIndexChanged ( int ) );
913 configList << "pvr-device" << "pvr-radio-device" << "pvr-norm"
914 << "pvr-frequency" << "pvr-bitrate";
920 if( module_exists( "dtv" ) ){
921 addModuleAndLayouts( DTV_DEVICE, dvb, N_("TV (digital)"), QGridLayout );
924 QLabel *dvbDeviceLabel = new QLabel( qtr( "Tuner card" ) );
925 QLabel *dvbTypeLabel = new QLabel( qtr( "Delivery system" ) );
927 dvbCard = new QSpinBox;
928 dvbCard->setAlignment( Qt::AlignRight );
930 dvbCard->setPrefix( "/dev/dvb/adapter" );
932 dvbDevLayout->addWidget( dvbDeviceLabel, 0, 0 );
933 dvbDevLayout->addWidget( dvbCard, 0, 1, 1, 2 );
935 dvbc = new QRadioButton( "DVB-C" );
936 dvbs = new QRadioButton( "DVB-S" );
937 dvbs2 = new QRadioButton( "DVB-S2" );
938 dvbt = new QRadioButton( "DVB-T" );
939 dvbt2 = new QRadioButton( "DVB-T2" );
940 atsc = new QRadioButton( "ATSC" );
941 cqam = new QRadioButton( "Clear QAM" );
942 dvbt->setChecked( true );
944 dvbDevLayout->addWidget( dvbTypeLabel, 1, 0, 2, 1 );
945 dvbDevLayout->addWidget( dvbc, 1, 1 );
946 dvbDevLayout->addWidget( dvbs, 1, 2 );
947 dvbDevLayout->addWidget( dvbs2, 2, 2 );
948 dvbDevLayout->addWidget( dvbt, 1, 3 );
949 dvbDevLayout->addWidget( dvbt2, 2, 3 );
950 dvbDevLayout->addWidget( atsc, 1, 4 );
951 dvbDevLayout->addWidget( cqam, 2, 4 );
953 /* DVB Props panel */
954 QLabel *dvbFreqLabel =
955 new QLabel( qtr( "Transponder/multiplex frequency" ) );
956 dvbPropLayout->addWidget( dvbFreqLabel, 0, 0 );
958 dvbFreq = new QSpinBox;
959 dvbFreq->setAlignment( Qt::AlignRight );
960 dvbFreq->setSuffix(" kHz");
961 dvbFreq->setSingleStep( 1000 );
962 setSpinBoxFreq( dvbFreq );
963 dvbPropLayout->addWidget( dvbFreq, 0, 1 );
965 dvbSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
966 dvbPropLayout->addWidget( dvbSrateLabel, 1, 0 );
968 dvbSrate = new QSpinBox;
969 dvbSrate->setAlignment( Qt::AlignRight );
970 dvbSrate->setSuffix(" bauds");
971 setSpinBoxFreq( dvbSrate );
972 dvbPropLayout->addWidget( dvbSrate, 1, 1 );
974 dvbModLabel = new QLabel( qtr( "Modulation / Constellation" ) );
975 dvbPropLayout->addWidget( dvbModLabel, 2, 0 );
977 dvbQamBox = new QComboBox;
978 dvbQamBox->addItem( qtr( "Automatic" ), qfu("QAM") );
979 dvbQamBox->addItem( "256-QAM", qfu("256QAM") );
980 dvbQamBox->addItem( "128-QAM", qfu("128QAM") );
981 dvbQamBox->addItem( "64-QAM", qfu("64QAM") );
982 dvbQamBox->addItem( "32-QAM", qfu("32QAM") );
983 dvbQamBox->addItem( "16-QAM", qfu("16QAM") );
984 dvbPropLayout->addWidget( dvbQamBox, 2, 1 );
986 dvbPskBox = new QComboBox;
987 dvbPskBox->addItem( "QPSK", qfu("QPSK") );
988 dvbPskBox->addItem( "DQPSK", qfu("DQPSK") );
989 dvbPskBox->addItem( "8-PSK", qfu("8PSK") );
990 dvbPskBox->addItem( "16-APSK", qfu("16APSK") );
991 dvbPskBox->addItem( "32-APSK", qfu("32APSK") );
992 dvbPropLayout->addWidget( dvbPskBox, 2, 1 );
998 dvbBandLabel = new QLabel( qtr( "Bandwidth" ) );
999 dvbPropLayout->addWidget( dvbBandLabel, 2, 0 );
1001 dvbBandBox = new QComboBox;
1002 setfillVLCConfigCombo( "dvb-bandwidth", p_intf, dvbBandBox );
1003 dvbPropLayout->addWidget( dvbBandBox, 2, 1 );
1005 dvbBandLabel->hide();
1008 dvbPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
1012 CuMRL( dvbCard, valueChanged ( int ) );
1013 CuMRL( dvbFreq, valueChanged ( int ) );
1014 CuMRL( dvbSrate, valueChanged ( int ) );
1015 CuMRL( dvbQamBox, currentIndexChanged ( int ) );
1016 CuMRL( dvbPskBox, currentIndexChanged ( int ) );
1017 CuMRL( dvbBandBox, currentIndexChanged ( int ) );
1019 BUTTONACT( dvbc, updateButtons() );
1020 BUTTONACT( dvbs, updateButtons() );
1021 BUTTONACT( dvbs2, updateButtons() );
1022 BUTTONACT( dvbt, updateButtons() );
1023 BUTTONACT( dvbt2, updateButtons() );
1024 BUTTONACT( atsc, updateButtons() );
1025 BUTTONACT( cqam, updateButtons() );
1026 BUTTONACT( dvbc, updateMRL() );
1027 BUTTONACT( dvbt, updateMRL() );
1028 BUTTONACT( dvbt2, updateMRL() );
1029 BUTTONACT( dvbs, updateMRL() );
1030 BUTTONACT( dvbs2, updateMRL() );
1031 BUTTONACT( atsc, updateMRL() );
1032 BUTTONACT( cqam, updateMRL() );
1033 configList << "dvb-adapter" << "dvb-frequency" << "dvb-modulation"
1040 addModuleAndLayouts( SCREEN_DEVICE, screen, "Desktop", QGridLayout );
1041 QLabel *screenLabel = new QLabel( qtr( "Your display will be "
1042 "opened and played in order to stream or save it." ) );
1043 screenLabel->setWordWrap( true );
1044 screenDevLayout->addWidget( screenLabel, 0, 0 );
1046 QLabel *screenFPSLabel = new QLabel(
1047 qtr( "Desired frame rate for the capture." ) );
1048 screenPropLayout->addWidget( screenFPSLabel, 0, 0 );
1050 screenFPS = new QDoubleSpinBox;
1051 screenFPS->setValue( 1. );
1052 screenFPS->setRange( .01, 100. );
1053 screenFPS->setAlignment( Qt::AlignRight );
1054 /* xgettext: frames per second */
1055 screenFPS->setSuffix( qtr( " f/s" ) );
1056 screenPropLayout->addWidget( screenFPS, 0, 1 );
1058 /* Screen connect */
1059 CuMRL( screenFPS, valueChanged( double ) );
1061 /* General connects */
1062 CONNECT( ui.deviceCombo, activated( int ) ,
1063 stackedDevLayout, setCurrentIndex( int ) );
1064 CONNECT( ui.deviceCombo, activated( int ),
1065 stackedPropLayout, setCurrentIndex( int ) );
1066 CONNECT( ui.deviceCombo, activated( int ), this, updateMRL() );
1067 CONNECT( ui.deviceCombo, activated( int ), this, updateButtons() );
1070 #undef addModuleAndLayouts
1073 CaptureOpenPanel::~CaptureOpenPanel()
1077 void CaptureOpenPanel::clear()
1082 void CaptureOpenPanel::updateMRL()
1085 QStringList fileList;
1086 int i_devicetype = ui.deviceCombo->itemData(
1087 ui.deviceCombo->currentIndex() ).toInt();
1088 switch( i_devicetype )
1092 fileList << "dshow://";
1093 mrl+= " :dshow-vdev=" +
1094 colon_escape( QString("%1").arg( vdevDshowW->getValue() ) );
1095 mrl+= " :dshow-adev=" +
1096 colon_escape( QString("%1").arg( adevDshowW->getValue() ) )+" ";
1097 if( dshowVSizeLine->isModified() )
1098 mrl += ":dshow-size=" + dshowVSizeLine->text();
1102 fileList << "v4l2://" + v4l2VideoDevice->currentText();
1103 mrl += ":v4l2-standard="
1104 + v4l2StdBox->itemData( v4l2StdBox->currentIndex() ).toString();
1105 mrl += " :input-slave=alsa://" + v4l2AudioDevice->currentText();
1109 mrl += "channels=" + QString::number( jackChannels->value() );
1110 mrl += ":ports=" + jackPortsSelected->text();
1111 fileList << mrl; mrl = "";
1113 if ( jackPace->isChecked() )
1115 mrl += " :jack-input-use-vlc-pace";
1117 if ( jackConnect->isChecked() )
1119 mrl += " :jack-input-auto-connect";
1123 fileList << "pvr://";
1124 mrl += " :pvr-device=" + pvrDevice->text();
1125 mrl += " :pvr-radio-device=" + pvrRadioDevice->text();
1126 mrl += " :pvr-norm=" + QString::number( pvrNormBox->currentIndex() );
1127 if( pvrFreq->value() )
1128 mrl += " :pvr-frequency=" + QString::number( pvrFreq->value() );
1129 if( pvrBitr->value() )
1130 mrl += " :pvr-bitrate=" + QString::number( pvrBitr->value() );
1134 if( dvbc->isChecked() ) mrl = "dvb-c://";
1136 if( dvbs->isChecked() ) mrl = "dvb-s://";
1138 if( dvbs2->isChecked() ) mrl = "dvb-s2://";
1140 if( dvbt->isChecked() ) mrl = "dvb-t://";
1142 if( dvbt2->isChecked() ) mrl = "dvb-t2://";
1144 if( atsc->isChecked() ) mrl = "atsc://";
1146 if( cqam->isChecked() ) mrl = "cqam://";
1148 mrl += "frequency=" + QString::number( dvbFreq->value() ) + "000";
1150 if( dvbc->isChecked() || cqam->isChecked() )
1151 mrl += ":modulation="
1152 + dvbQamBox->itemData( dvbQamBox->currentIndex() ).toString();
1153 if( dvbs2->isChecked() )
1154 mrl += ":modulation="
1155 + dvbPskBox->itemData( dvbPskBox->currentIndex() ).toString();
1156 if( dvbc->isChecked() || dvbs->isChecked() || dvbs2->isChecked() )
1157 mrl += ":srate=" + QString::number( dvbSrate->value() );
1158 if( dvbt->isChecked() || dvbt2->isChecked() )
1159 mrl += ":bandwidth=" +
1160 QString::number( dvbBandBox->itemData(
1161 dvbBandBox->currentIndex() ).toInt() );
1163 fileList << mrl; mrl= "";
1164 mrl += " :dvb-adapter=" + QString::number( dvbCard->value() );
1167 fileList << "screen://";
1168 mrl = " :screen-fps=" + QString::number( screenFPS->value(), 'f' );
1172 emit methodChanged( "live-caching" );
1174 if( !advMRL.isEmpty() ) mrl += " " + advMRL;
1176 emit mrlUpdated( fileList, mrl );
1180 * Update the Buttons (show/hide) for the GUI as all device type don't
1181 * use the same ui. elements.
1183 void CaptureOpenPanel::updateButtons()
1185 /* Be sure to display the ui Elements in case they were hidden by
1186 * some Device Type (like Screen://) */
1187 ui.optionsBox->show();
1188 ui.advancedButton->show();
1189 /* Get the current Device Number */
1190 int i_devicetype = ui.deviceCombo->itemData(
1191 ui.deviceCombo->currentIndex() ).toInt();
1192 switch( i_devicetype )
1196 dvbSrateLabel->hide();
1199 dvbModLabel->hide();
1201 dvbBandLabel->hide();
1203 if( dvbc->isChecked() )
1206 dvbSrateLabel->show();
1208 dvbModLabel->show();
1210 else if( dvbs->isChecked() )
1213 dvbSrateLabel->show();
1215 else if( dvbs2->isChecked() )
1218 dvbSrateLabel->show();
1220 dvbModLabel->show();
1222 else if( dvbt->isChecked() || dvbt2->isChecked() )
1225 dvbBandLabel->show();
1229 //ui.optionsBox->hide();
1230 ui.advancedButton->hide();
1237 void CaptureOpenPanel::advancedDialog()
1239 /* Get selected device type */
1240 int i_devicetype = ui.deviceCombo->itemData(
1241 ui.deviceCombo->currentIndex() ).toInt();
1243 /* Get the corresponding module */
1244 module_t *p_module =
1245 module_find( psz_devModule[i_devicetype] );
1246 if( NULL == p_module ) return;
1249 QList<ConfigControl *> controls;
1251 /* Get the confsize */
1252 unsigned int i_confsize;
1253 module_config_t *p_config;
1254 p_config = module_config_get( p_module, &i_confsize );
1256 /* New Adv Prop dialog */
1257 adv = new QDialog( this );
1258 adv->setWindowTitle( qtr( "Advanced Options" ) );
1259 adv->setWindowRole( "vlc-advanced-options" );
1261 /* A main Layout with a Frame */
1262 QVBoxLayout *mainLayout = new QVBoxLayout( adv );
1263 QScrollArea *scroll = new QScrollArea;
1264 mainLayout->addWidget( scroll );
1266 QFrame *advFrame = new QFrame;
1267 /* GridLayout inside the Frame */
1268 QGridLayout *gLayout = new QGridLayout( advFrame );
1270 scroll->setWidgetResizable( true );
1271 scroll->setWidget( advFrame );
1273 /* Create the options inside the FrameLayout */
1274 for( int n = 0; n < (int)i_confsize; n++ )
1276 module_config_t *p_item = p_config + n;
1277 QString name = p_item->psz_name;
1279 if( name.isEmpty() || configList.contains( name ) )
1282 msg_Dbg( p_intf, "item %s", p_item->psz_name);
1283 ConfigControl *config = ConfigControl::createControl(
1284 VLC_OBJECT( p_intf ), p_item, advFrame, gLayout, n );
1286 controls.append( config );
1290 QDialogButtonBox *advButtonBox = new QDialogButtonBox( adv );
1291 QPushButton *closeButton = new QPushButton( qtr( "OK" ) );
1292 QPushButton *cancelButton = new QPushButton( qtr( "Cancel" ) );
1294 CONNECT( closeButton, clicked(), adv, accept() );
1295 CONNECT( cancelButton, clicked(), adv, reject() );
1297 advButtonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
1298 advButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
1300 mainLayout->addWidget( advButtonBox );
1302 /* Creation of the MRL */
1305 QString tempMRL = "";
1306 for( int i = 0; i < controls.count(); i++ )
1308 ConfigControl *control = controls[i];
1310 tempMRL += (i ? " :" : ":");
1312 if( control->getType() == CONFIG_ITEM_BOOL )
1313 if( !(qobject_cast<VIntConfigControl *>(control)->getValue() ) )
1316 tempMRL += control->getName();
1318 switch( control->getType() )
1320 case CONFIG_ITEM_STRING:
1321 case CONFIG_ITEM_LOADFILE:
1322 case CONFIG_ITEM_SAVEFILE:
1323 case CONFIG_ITEM_DIRECTORY:
1324 case CONFIG_ITEM_MODULE:
1325 tempMRL += colon_escape( QString("=%1").arg( qobject_cast<VStringConfigControl *>(control)->getValue() ) );
1327 case CONFIG_ITEM_INTEGER:
1328 tempMRL += QString("=%1").arg( qobject_cast<VIntConfigControl *>(control)->getValue() );
1330 case CONFIG_ITEM_FLOAT:
1331 tempMRL += QString("=%1").arg( qobject_cast<VFloatConfigControl *>(control)->getValue() );
1338 qDeleteAll( controls );
1340 module_config_free( p_config );