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 );
339 #ifdef WIN32 /* Disc drives probing for Windows */
340 wchar_t szDrives[512];
342 if( GetLogicalDriveStringsW( sizeof( szDrives ) - 1, szDrives ) )
344 wchar_t *drive = szDrives;
345 UINT oldMode = SetErrorMode( SEM_FAILCRITICALERRORS );
348 if( GetDriveTypeW(drive) == DRIVE_CDROM )
350 wchar_t psz_name[512] = L"";
351 GetVolumeInformationW( drive, psz_name, 511, NULL, NULL, NULL, NULL, 0 );
353 QString displayName = FromWide( drive );
355 displayName = displayName + " - " + FromWide( psz_name );
358 ui.deviceCombo->addItem( displayName, FromWide( drive ) );
361 /* go to next drive */
364 SetErrorMode(oldMode);
367 char const * const ppsz_discdevices[] = {
374 QComboBox *discCombo = ui.deviceCombo; /* avoid namespacing in macro */
375 POPULATE_WITH_DEVS( ppsz_discdevices, discCombo );
379 BUTTONACT( ui.dvdRadioButton, updateButtons() );
380 BUTTONACT( ui.vcdRadioButton, updateButtons() );
381 BUTTONACT( ui.audioCDRadioButton, updateButtons() );
382 BUTTONACT( ui.dvdsimple, updateButtons() );
383 BUTTONACT( ui.browseDiscButton, browseDevice() );
384 BUTTON_SET_ACT_I( ui.ejectButton, "", toolbar/eject, qtr( "Eject the disc" ),
387 CONNECT( ui.deviceCombo, editTextChanged( QString ), this, updateMRL());
388 CONNECT( ui.deviceCombo, currentIndexChanged( QString ), this, updateMRL());
389 CONNECT( ui.titleSpin, valueChanged( int ), this, updateMRL());
390 CONNECT( ui.chapterSpin, valueChanged( int ), this, updateMRL());
391 CONNECT( ui.audioSpin, valueChanged( int ), this, updateMRL());
392 CONNECT( ui.subtitlesSpin, valueChanged( int ), this, updateMRL());
394 /* Run once the updateButtons function in order to fill correctly the comboBoxes */
398 DiscOpenPanel::~DiscOpenPanel()
400 free( psz_dvddiscpath );
401 free( psz_vcddiscpath );
402 free( psz_cddadiscpath );
405 void DiscOpenPanel::clear()
407 ui.titleSpin->setValue( 0 );
408 ui.chapterSpin->setValue( 0 );
409 ui.subtitlesSpin->setValue( -1 );
410 ui.audioSpin->setValue( -1 );
415 #define setDrive( psz_name ) {\
416 int index = ui.deviceCombo->findText( qfu( psz_name ) ); \
417 if( index != -1 ) ui.deviceCombo->setCurrentIndex( index );}
419 #define setDrive( psz_name ) {\
420 ui.deviceCombo->setEditText( qfu( psz_name ) ); }
423 /* update the buttons according the type of device */
424 void DiscOpenPanel::updateButtons()
426 if ( ui.dvdRadioButton->isChecked() )
428 if( m_discType != Dvd )
430 setDrive( psz_dvddiscpath );
433 ui.titleLabel->setText( qtr("Title") );
434 ui.chapterLabel->show();
435 ui.chapterSpin->show();
436 ui.diskOptionBox_2->show();
437 ui.dvdsimple->setEnabled( true );
439 else if ( ui.vcdRadioButton->isChecked() )
441 if( m_discType != Vcd )
443 setDrive( psz_vcddiscpath );
446 ui.titleLabel->setText( qtr("Entry") );
447 ui.chapterLabel->hide();
448 ui.chapterSpin->hide();
449 ui.diskOptionBox_2->show();
450 ui.dvdsimple->setEnabled( false );
454 if( m_discType != Cdda )
456 setDrive( psz_cddadiscpath );
459 ui.titleLabel->setText( qtr("Track") );
460 ui.chapterLabel->hide();
461 ui.chapterSpin->hide();
462 ui.diskOptionBox_2->hide();
463 ui.dvdsimple->setEnabled( false );
472 # define LOCALHOST ""
474 # define LOCALHOST "/"
477 /* Update the current MRL */
478 void DiscOpenPanel::updateMRL()
482 QStringList fileList;
484 if( ui.deviceCombo->itemData( ui.deviceCombo->currentIndex() ) != QVariant::Invalid )
485 discPath = ui.deviceCombo->itemData( ui.deviceCombo->currentIndex() ).toString();
487 discPath = ui.deviceCombo->currentText();
489 /* CDDAX and VCDX not implemented. TODO ? No. */
491 if( ui.dvdRadioButton->isChecked() ) {
492 if( !ui.dvdsimple->isChecked() )
493 mrl = "dvd://" LOCALHOST + discPath;
495 mrl = "dvdsimple://" LOCALHOST + discPath;
497 if ( ui.titleSpin->value() > 0 ) {
498 mrl += QString("@%1").arg( ui.titleSpin->value() );
499 if ( ui.chapterSpin->value() > 0 ) {
500 mrl+= QString(":%1").arg( ui.chapterSpin->value() );
505 } else if ( ui.vcdRadioButton->isChecked() ) {
506 mrl = "vcd://" LOCALHOST + discPath;
508 if( ui.titleSpin->value() > 0 ) {
509 mrl += QString("@E%1").arg( ui.titleSpin->value() );
514 mrl = "cdda://" LOCALHOST + discPath;
516 emit methodChanged( "disc-caching" );
518 fileList << mrl; mrl = "";
520 if ( ui.dvdRadioButton->isChecked() || ui.vcdRadioButton->isChecked() )
522 if ( ui.audioSpin->value() >= 0 ) {
523 mrl += " :audio-track=" +
524 QString("%1").arg( ui.audioSpin->value() );
526 if ( ui.subtitlesSpin->value() >= 0 ) {
527 mrl += " :sub-track=" +
528 QString("%1").arg( ui.subtitlesSpin->value() );
533 if( ui.titleSpin->value() > 0 )
534 mrl += QString(" :cdda-track=%1").arg( ui.titleSpin->value() );
536 emit mrlUpdated( fileList, mrl );
539 void DiscOpenPanel::browseDevice()
541 QString dir = QFileDialog::getExistingDirectory( this,
542 qtr( I_DEVICE_TOOLTIP ) );
545 ui.deviceCombo->addItem( toNativeSepNoSlash( dir ) );
546 ui.deviceCombo->setCurrentIndex( ui.deviceCombo->findText( toNativeSepNoSlash( dir ) ) );
553 void DiscOpenPanel::eject()
555 intf_Eject( p_intf, qtu( ui.deviceCombo->currentText() ) );
558 void DiscOpenPanel::accept()
561 /**************************************************************************
562 * Open Network streams and URL pages *
563 **************************************************************************/
564 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
565 OpenPanel( _parent, _p_intf )
568 CONNECT( ui.urlComboBox, editTextChanged( const QString& ), this, updateMRL());
571 if( var_InheritBool( p_intf, "qt-recentplay" ) )
574 ui.urlComboBox->addItems( getSettings()->value( "Open/netMRL" ).toStringList() );
575 ui.urlComboBox->setMaxCount( 10 );
578 b_recentList = false;
580 /* Use a simple validator for URLs */
581 ui.urlComboBox->setValidator( new UrlValidator( this ) );
582 ui.urlComboBox->setFocus();
585 NetOpenPanel::~NetOpenPanel()
587 if( !b_recentList ) return;
589 /* Create the list with the current items */
591 for( int i = 0; i < ui.urlComboBox->count(); i++ )
592 mrlList << ui.urlComboBox->itemText( i );
594 /* Clean the list... */
596 mrlList.removeDuplicates();
598 /* ...and save the 8 last entries */
599 getSettings()->setValue( "Open/netMRL", mrlList );
602 void NetOpenPanel::clear()
604 ui.urlComboBox->clear();
607 void NetOpenPanel::onAccept()
609 if( ui.urlComboBox->findText( ui.urlComboBox->currentText() ) == -1 )
610 ui.urlComboBox->insertItem( 0, ui.urlComboBox->currentText());
613 void NetOpenPanel::onFocus()
615 ui.urlComboBox->setFocus();
616 ui.urlComboBox->lineEdit()->selectAll();
619 void NetOpenPanel::updateMRL()
621 QString url = ui.urlComboBox->lineEdit()->text();
626 emit methodChanged( qfu( "network-caching" ) );
630 emit mrlUpdated( qsl, "" );
633 QValidator::State UrlValidator::validate( QString& str, int& ) const
635 if( str.contains( ' ' ) )
636 return QValidator::Invalid;
637 if( !str.contains( "://" ) )
638 return QValidator::Intermediate;
639 return QValidator::Acceptable;
642 void UrlValidator::fixup( QString& str ) const
647 /**************************************************************************
648 * Open Capture device ( DVB, PVR, V4L, and similar ) *
649 **************************************************************************/
650 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
651 OpenPanel( _parent, _p_intf )
653 isInitialized = false;
656 void CaptureOpenPanel::initialize()
658 if( isInitialized ) return;
660 msg_Dbg( p_intf, "Initialization of Capture device panel" );
661 isInitialized = true;
665 BUTTONACT( ui.advancedButton, advancedDialog() );
667 /* Create two stacked layouts in the main comboBoxes */
668 QStackedLayout *stackedDevLayout = new QStackedLayout;
669 ui.cardBox->setLayout( stackedDevLayout );
671 QStackedLayout *stackedPropLayout = new QStackedLayout;
672 ui.optionsBox->setLayout( stackedPropLayout );
674 /* Creation and connections of the WIdgets in the stacked layout */
675 #define addModuleAndLayouts( number, name, label, layout ) \
676 QWidget * name ## DevPage = new QWidget( this ); \
677 QWidget * name ## PropPage = new QWidget( this ); \
678 stackedDevLayout->addWidget( name ## DevPage ); \
679 stackedPropLayout->addWidget( name ## PropPage ); \
680 layout * name ## DevLayout = new layout; \
681 layout * name ## PropLayout = new layout; \
682 name ## DevPage->setLayout( name ## DevLayout ); \
683 name ## PropPage->setLayout( name ## PropLayout ); \
684 ui.deviceCombo->addItem( qtr( label ), QVariant( number ) );
686 #define CuMRL( widget, slot ) CONNECT( widget , slot , this, updateMRL() );
689 /*********************
690 * DirectShow Stuffs *
691 *********************/
692 if( module_exists( "dshow" ) ){
693 addModuleAndLayouts( DSHOW_DEVICE, dshow, "DirectShow", QGridLayout );
697 module_config_t *p_config =
698 config_FindConfig( VLC_OBJECT(p_intf), "dshow-vdev" );
699 vdevDshowW = new StringListConfigControl(
700 VLC_OBJECT(p_intf), p_config, this, dshowDevLayout, line );
703 p_config = config_FindConfig( VLC_OBJECT(p_intf), "dshow-adev" );
704 adevDshowW = new StringListConfigControl(
705 VLC_OBJECT(p_intf), p_config, this, dshowDevLayout, line );
708 /* dshow Properties */
709 QLabel *dshowVSizeLabel = new QLabel( qtr( "Video size" ) );
710 dshowPropLayout->addWidget( dshowVSizeLabel, 0, 0 );
712 dshowVSizeLine = new QLineEdit;
713 dshowPropLayout->addWidget( dshowVSizeLine, 0, 1);
714 dshowPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
718 CuMRL( vdevDshowW->combo, currentIndexChanged ( int ) );
719 CuMRL( adevDshowW->combo, currentIndexChanged ( int ) );
720 CuMRL( dshowVSizeLine, textChanged( const QString& ) );
726 if( module_exists( "v4l2" ) ){
727 addModuleAndLayouts( V4L2_DEVICE, v4l2, "Video for Linux 2", QGridLayout );
729 char const * const ppsz_v4lvdevices[] = {
733 char const * const ppsz_v4ladevices[] = {
739 QLabel *v4l2VideoDeviceLabel = new QLabel( qtr( "Video device name" ) );
740 v4l2DevLayout->addWidget( v4l2VideoDeviceLabel, 0, 0 );
742 v4l2VideoDevice = new QComboBox( this );
743 v4l2VideoDevice->setEditable( true );
744 POPULATE_WITH_DEVS( ppsz_v4lvdevices, v4l2VideoDevice );
745 v4l2VideoDevice->clearEditText();
746 v4l2DevLayout->addWidget( v4l2VideoDevice, 0, 1 );
748 QLabel *v4l2AudioDeviceLabel = new QLabel( qtr( "Audio device name" ) );
749 v4l2DevLayout->addWidget( v4l2AudioDeviceLabel, 1, 0 );
751 v4l2AudioDevice = new QComboBox( this );
752 v4l2AudioDevice->setEditable( true );
753 POPULATE_WITH_DEVS( ppsz_v4ladevices, v4l2AudioDevice );
754 v4l2AudioDevice->clearEditText();
755 v4l2DevLayout->addWidget( v4l2AudioDevice, 1, 1 );
757 /* v4l2 Props panel */
758 QLabel *v4l2StdLabel = new QLabel( qtr( "Video standard" ) );
759 v4l2PropLayout->addWidget( v4l2StdLabel, 0 , 0 );
761 v4l2StdBox = new QComboBox;
762 setfillVLCConfigCombo( "v4l2-standard", p_intf, v4l2StdBox );
763 v4l2PropLayout->addWidget( v4l2StdBox, 0 , 1 );
764 v4l2PropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
768 CuMRL( v4l2VideoDevice->lineEdit(), textChanged( const QString& ) );
769 CuMRL( v4l2VideoDevice, currentIndexChanged ( int ) );
770 CuMRL( v4l2AudioDevice->lineEdit(), textChanged( const QString& ) );
771 CuMRL( v4l2AudioDevice, currentIndexChanged ( int ) );
772 CuMRL( v4l2StdBox, currentIndexChanged ( int ) );
778 if( module_exists( "jack" ) ){
779 addModuleAndLayouts( JACK_DEVICE, jack, "JACK Audio Connection Kit",
782 /* Jack Main panel */
784 QLabel *jackChannelsLabel = new QLabel( qtr( "Channels:" ) );
785 jackDevLayout->addWidget( jackChannelsLabel, 1, 0 );
787 jackChannels = new QSpinBox;
788 setSpinBoxFreq( jackChannels );
789 jackChannels->setMaximum(255);
790 jackChannels->setValue(2);
791 jackChannels->setAlignment( Qt::AlignRight );
792 jackDevLayout->addWidget( jackChannels, 1, 1 );
795 QLabel *jackPortsLabel = new QLabel( qtr( "Selected ports:" ) );
796 jackDevLayout->addWidget( jackPortsLabel, 0 , 0 );
798 jackPortsSelected = new QLineEdit( qtr( ".*") );
799 jackPortsSelected->setAlignment( Qt::AlignRight );
800 jackDevLayout->addWidget( jackPortsSelected, 0, 1 );
802 /* Jack Props panel */
805 jackPace = new QCheckBox(qtr( "Use VLC pace" ));
806 jackPropLayout->addWidget( jackPace, 1, 1 );
809 jackConnect = new QCheckBox( qtr( "Auto connection" ));
810 jackPropLayout->addWidget( jackConnect, 1, 2 );
813 CuMRL( jackChannels, valueChanged( int ) );
814 CuMRL( jackPace, stateChanged( int ) );
815 CuMRL( jackConnect, stateChanged( int ) );
816 CuMRL( jackPortsSelected, textChanged( const QString& ) );
822 if( module_exists( "pvr" ) ){
823 addModuleAndLayouts( PVR_DEVICE, pvr, "PVR", QGridLayout );
826 QLabel *pvrDeviceLabel = new QLabel( qtr( "Device name" ) );
827 pvrDevLayout->addWidget( pvrDeviceLabel, 0, 0 );
829 pvrDevice = new QLineEdit;
830 pvrDevLayout->addWidget( pvrDevice, 0, 1 );
832 QLabel *pvrRadioDeviceLabel = new QLabel( qtr( "Radio device name" ) );
833 pvrDevLayout->addWidget( pvrRadioDeviceLabel, 1, 0 );
835 pvrRadioDevice = new QLineEdit;
836 pvrDevLayout->addWidget( pvrRadioDevice, 1, 1 );
838 /* PVR props panel */
839 QLabel *pvrNormLabel = new QLabel( qtr( "Norm" ) );
840 pvrPropLayout->addWidget( pvrNormLabel, 0, 0 );
842 pvrNormBox = new QComboBox;
843 setfillVLCConfigCombo( "pvr-norm", p_intf, pvrNormBox );
844 pvrPropLayout->addWidget( pvrNormBox, 0, 1 );
846 QLabel *pvrFreqLabel = new QLabel( qtr( "Frequency" ) );
847 pvrPropLayout->addWidget( pvrFreqLabel, 1, 0 );
849 pvrFreq = new QSpinBox;
850 pvrFreq->setAlignment( Qt::AlignRight );
851 pvrFreq->setSuffix(" kHz");
852 setSpinBoxFreq( pvrFreq );
853 pvrPropLayout->addWidget( pvrFreq, 1, 1 );
855 QLabel *pvrBitrLabel = new QLabel( qtr( "Bitrate" ) );
856 pvrPropLayout->addWidget( pvrBitrLabel, 2, 0 );
858 pvrBitr = new QSpinBox;
859 pvrBitr->setAlignment( Qt::AlignRight );
860 pvrBitr->setSuffix(" kHz");
861 setSpinBoxFreq( pvrBitr );
862 pvrPropLayout->addWidget( pvrBitr, 2, 1 );
863 pvrPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
867 CuMRL( pvrDevice, textChanged( const QString& ) );
868 CuMRL( pvrRadioDevice, textChanged( const QString& ) );
870 CuMRL( pvrFreq, valueChanged ( int ) );
871 CuMRL( pvrBitr, valueChanged ( int ) );
872 CuMRL( pvrNormBox, currentIndexChanged ( int ) );
878 if( module_exists( "dtv" ) ){
879 addModuleAndLayouts( DTV_DEVICE, dvb, N_("TV (digital)"), QGridLayout );
882 QLabel *dvbDeviceLabel = new QLabel( qtr( "Tuner card" ) );
883 QLabel *dvbTypeLabel = new QLabel( qtr( "Delivery system" ) );
885 dvbCard = new QSpinBox;
886 dvbCard->setAlignment( Qt::AlignRight );
888 dvbCard->setPrefix( "/dev/dvb/adapter" );
890 dvbDevLayout->addWidget( dvbDeviceLabel, 0, 0 );
891 dvbDevLayout->addWidget( dvbCard, 0, 1, 1, 2 );
893 dvbc = new QRadioButton( "DVB-C" );
894 dvbs = new QRadioButton( "DVB-S" );
895 dvbs2 = new QRadioButton( "DVB-S2" );
896 dvbt = new QRadioButton( "DVB-T" );
897 dvbt2 = new QRadioButton( "DVB-T2" );
898 atsc = new QRadioButton( "ATSC" );
899 cqam = new QRadioButton( "Clear QAM" );
900 dvbt->setChecked( true );
902 dvbDevLayout->addWidget( dvbTypeLabel, 1, 0, 2, 1 );
903 dvbDevLayout->addWidget( dvbc, 1, 1 );
904 dvbDevLayout->addWidget( dvbs, 1, 2 );
905 dvbDevLayout->addWidget( dvbs2, 2, 2 );
906 dvbDevLayout->addWidget( dvbt, 1, 3 );
907 dvbDevLayout->addWidget( dvbt2, 2, 3 );
908 dvbDevLayout->addWidget( atsc, 1, 4 );
909 dvbDevLayout->addWidget( cqam, 2, 4 );
911 /* DVB Props panel */
912 QLabel *dvbFreqLabel =
913 new QLabel( qtr( "Transponder/multiplex frequency" ) );
914 dvbPropLayout->addWidget( dvbFreqLabel, 0, 0 );
916 dvbFreq = new QSpinBox;
917 dvbFreq->setAlignment( Qt::AlignRight );
918 dvbFreq->setSuffix(" kHz");
919 dvbFreq->setSingleStep( 1000 );
920 setSpinBoxFreq( dvbFreq );
921 dvbPropLayout->addWidget( dvbFreq, 0, 1 );
923 dvbSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
924 dvbPropLayout->addWidget( dvbSrateLabel, 1, 0 );
926 dvbSrate = new QSpinBox;
927 dvbSrate->setAlignment( Qt::AlignRight );
928 dvbSrate->setSuffix(" bauds");
929 setSpinBoxFreq( dvbSrate );
930 dvbPropLayout->addWidget( dvbSrate, 1, 1 );
932 dvbModLabel = new QLabel( qtr( "Modulation / Constellation" ) );
933 dvbPropLayout->addWidget( dvbModLabel, 2, 0 );
935 dvbQamBox = new QComboBox;
936 dvbQamBox->addItem( qtr( "Automatic" ), qfu("QAM") );
937 dvbQamBox->addItem( "256-QAM", qfu("256QAM") );
938 dvbQamBox->addItem( "128-QAM", qfu("128QAM") );
939 dvbQamBox->addItem( "64-QAM", qfu("64QAM") );
940 dvbQamBox->addItem( "32-QAM", qfu("32QAM") );
941 dvbQamBox->addItem( "16-QAM", qfu("16QAM") );
942 dvbPropLayout->addWidget( dvbQamBox, 2, 1 );
944 dvbPskBox = new QComboBox;
945 dvbPskBox->addItem( "QPSK", qfu("QPSK") );
946 dvbPskBox->addItem( "DQPSK", qfu("DQPSK") );
947 dvbPskBox->addItem( "8-PSK", qfu("8PSK") );
948 dvbPskBox->addItem( "16-APSK", qfu("16APSK") );
949 dvbPskBox->addItem( "32-APSK", qfu("32APSK") );
950 dvbPropLayout->addWidget( dvbPskBox, 2, 1 );
956 dvbBandLabel = new QLabel( qtr( "Bandwidth" ) );
957 dvbPropLayout->addWidget( dvbBandLabel, 2, 0 );
959 dvbBandBox = new QComboBox;
960 setfillVLCConfigCombo( "dvb-bandwidth", p_intf, dvbBandBox );
961 dvbPropLayout->addWidget( dvbBandBox, 2, 1 );
963 dvbBandLabel->hide();
966 dvbPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
970 CuMRL( dvbCard, valueChanged ( int ) );
971 CuMRL( dvbFreq, valueChanged ( int ) );
972 CuMRL( dvbSrate, valueChanged ( int ) );
973 CuMRL( dvbQamBox, currentIndexChanged ( int ) );
974 CuMRL( dvbPskBox, currentIndexChanged ( int ) );
975 CuMRL( dvbBandBox, currentIndexChanged ( int ) );
977 BUTTONACT( dvbc, updateButtons() );
978 BUTTONACT( dvbs, updateButtons() );
979 BUTTONACT( dvbs2, updateButtons() );
980 BUTTONACT( dvbt, updateButtons() );
981 BUTTONACT( dvbt2, updateButtons() );
982 BUTTONACT( atsc, updateButtons() );
983 BUTTONACT( cqam, updateButtons() );
984 BUTTONACT( dvbc, updateMRL() );
985 BUTTONACT( dvbt, updateMRL() );
986 BUTTONACT( dvbt2, updateMRL() );
987 BUTTONACT( dvbs, updateMRL() );
988 BUTTONACT( dvbs2, updateMRL() );
989 BUTTONACT( atsc, updateMRL() );
990 BUTTONACT( cqam, updateMRL() );
996 addModuleAndLayouts( SCREEN_DEVICE, screen, "Desktop", QGridLayout );
997 QLabel *screenLabel = new QLabel( qtr( "Your display will be "
998 "opened and played in order to stream or save it." ) );
999 screenLabel->setWordWrap( true );
1000 screenDevLayout->addWidget( screenLabel, 0, 0 );
1002 QLabel *screenFPSLabel = new QLabel(
1003 qtr( "Desired frame rate for the capture." ) );
1004 screenPropLayout->addWidget( screenFPSLabel, 0, 0 );
1006 screenFPS = new QDoubleSpinBox;
1007 screenFPS->setValue( 1. );
1008 screenFPS->setRange( .01, 100. );
1009 screenFPS->setAlignment( Qt::AlignRight );
1010 /* xgettext: frames per second */
1011 screenFPS->setSuffix( qtr( " f/s" ) );
1012 screenPropLayout->addWidget( screenFPS, 0, 1 );
1014 /* Screen connect */
1015 CuMRL( screenFPS, valueChanged( double ) );
1017 /* General connects */
1018 CONNECT( ui.deviceCombo, activated( int ) ,
1019 stackedDevLayout, setCurrentIndex( int ) );
1020 CONNECT( ui.deviceCombo, activated( int ),
1021 stackedPropLayout, setCurrentIndex( int ) );
1022 CONNECT( ui.deviceCombo, activated( int ), this, updateMRL() );
1023 CONNECT( ui.deviceCombo, activated( int ), this, updateButtons() );
1026 #undef addModuleAndLayouts
1029 CaptureOpenPanel::~CaptureOpenPanel()
1033 void CaptureOpenPanel::clear()
1038 void CaptureOpenPanel::updateMRL()
1041 QStringList fileList;
1042 int i_devicetype = ui.deviceCombo->itemData(
1043 ui.deviceCombo->currentIndex() ).toInt();
1044 switch( i_devicetype )
1048 fileList << "dshow://";
1049 mrl+= " :dshow-vdev=" +
1050 colon_escape( QString("%1").arg( vdevDshowW->getValue() ) );
1051 mrl+= " :dshow-adev=" +
1052 colon_escape( QString("%1").arg( adevDshowW->getValue() ) )+" ";
1053 if( dshowVSizeLine->isModified() )
1054 mrl += ":dshow-size=" + dshowVSizeLine->text();
1058 fileList << "v4l2://" + v4l2VideoDevice->currentText();
1059 mrl += ":v4l2-standard="
1060 + v4l2StdBox->itemData( v4l2StdBox->currentIndex() ).toString();
1061 mrl += " :input-slave=alsa://" + v4l2AudioDevice->currentText();
1065 mrl += "channels=" + QString::number( jackChannels->value() );
1066 mrl += ":ports=" + jackPortsSelected->text();
1067 fileList << mrl; mrl = "";
1069 if ( jackPace->isChecked() )
1071 mrl += " :jack-input-use-vlc-pace";
1073 if ( jackConnect->isChecked() )
1075 mrl += " :jack-input-auto-connect";
1079 fileList << "pvr://";
1080 mrl += " :pvr-device=" + pvrDevice->text();
1081 mrl += " :pvr-radio-device=" + pvrRadioDevice->text();
1082 mrl += " :pvr-norm=" + QString::number( pvrNormBox->currentIndex() );
1083 if( pvrFreq->value() )
1084 mrl += " :pvr-frequency=" + QString::number( pvrFreq->value() );
1085 if( pvrBitr->value() )
1086 mrl += " :pvr-bitrate=" + QString::number( pvrBitr->value() );
1090 if( dvbc->isChecked() ) mrl = "dvb-c://";
1092 if( dvbs->isChecked() ) mrl = "dvb-s://";
1094 if( dvbs2->isChecked() ) mrl = "dvb-s2://";
1096 if( dvbt->isChecked() ) mrl = "dvb-t://";
1098 if( dvbt2->isChecked() ) mrl = "dvb-t2://";
1100 if( atsc->isChecked() ) mrl = "atsc://";
1102 if( cqam->isChecked() ) mrl = "cqam://";
1104 mrl += "frequency=" + QString::number( dvbFreq->value() ) + "000";
1106 if( dvbc->isChecked() || cqam->isChecked() )
1107 mrl += ":modulation="
1108 + dvbQamBox->itemData( dvbQamBox->currentIndex() ).toString();
1109 if( dvbs2->isChecked() )
1110 mrl += ":modulation="
1111 + dvbPskBox->itemData( dvbPskBox->currentIndex() ).toString();
1112 if( dvbc->isChecked() || dvbs->isChecked() || dvbs2->isChecked() )
1113 mrl += ":srate=" + QString::number( dvbSrate->value() );
1114 if( dvbt->isChecked() || dvbt2->isChecked() )
1115 mrl += ":bandwidth=" +
1116 QString::number( dvbBandBox->itemData(
1117 dvbBandBox->currentIndex() ).toInt() );
1119 fileList << mrl; mrl= "";
1120 mrl += " :dvb-adapter=" + QString::number( dvbCard->value() );
1123 fileList << "screen://";
1124 mrl = " :screen-fps=" + QString::number( screenFPS->value(), 'f' );
1128 emit methodChanged( "live-caching" );
1130 if( !advMRL.isEmpty() ) mrl += advMRL;
1132 emit mrlUpdated( fileList, mrl );
1136 * Update the Buttons (show/hide) for the GUI as all device type don't
1137 * use the same ui. elements.
1139 void CaptureOpenPanel::updateButtons()
1141 /* Be sure to display the ui Elements in case they were hidden by
1142 * some Device Type (like Screen://) */
1143 ui.optionsBox->show();
1144 ui.advancedButton->show();
1145 /* Get the current Device Number */
1146 int i_devicetype = ui.deviceCombo->itemData(
1147 ui.deviceCombo->currentIndex() ).toInt();
1148 switch( i_devicetype )
1152 dvbSrateLabel->hide();
1155 dvbModLabel->hide();
1157 dvbBandLabel->hide();
1159 if( dvbc->isChecked() )
1162 dvbSrateLabel->show();
1164 dvbModLabel->show();
1166 else if( dvbs->isChecked() )
1169 dvbSrateLabel->show();
1171 else if( dvbs2->isChecked() )
1174 dvbSrateLabel->show();
1176 dvbModLabel->show();
1178 else if( dvbt->isChecked() || dvbt2->isChecked() )
1181 dvbBandLabel->show();
1185 //ui.optionsBox->hide();
1186 ui.advancedButton->hide();
1193 void CaptureOpenPanel::advancedDialog()
1195 /* Get selected device type */
1196 int i_devicetype = ui.deviceCombo->itemData(
1197 ui.deviceCombo->currentIndex() ).toInt();
1199 /* Get the corresponding module */
1200 module_t *p_module =
1201 module_find( psz_devModule[i_devicetype] );
1202 if( NULL == p_module ) return;
1205 QList<ConfigControl *> controls;
1207 /* Get the confsize */
1208 unsigned int i_confsize;
1209 module_config_t *p_config;
1210 p_config = module_config_get( p_module, &i_confsize );
1212 /* New Adv Prop dialog */
1213 adv = new QDialog( this );
1214 adv->setWindowTitle( qtr( "Advanced Options" ) );
1215 adv->setWindowRole( "vlc-advanced-options" );
1217 /* A main Layout with a Frame */
1218 QVBoxLayout *mainLayout = new QVBoxLayout( adv );
1219 QScrollArea *scroll = new QScrollArea;
1220 mainLayout->addWidget( scroll );
1222 QFrame *advFrame = new QFrame;
1223 /* GridLayout inside the Frame */
1224 QGridLayout *gLayout = new QGridLayout( advFrame );
1226 scroll->setWidgetResizable( true );
1227 scroll->setWidget( advFrame );
1229 /* Create the options inside the FrameLayout */
1230 for( int n = 0; n < (int)i_confsize; n++ )
1232 module_config_t *p_item = p_config + n;
1233 ConfigControl *config = ConfigControl::createControl(
1234 VLC_OBJECT( p_intf ), p_item, advFrame, gLayout, n );
1236 controls.append( config );
1240 QDialogButtonBox *advButtonBox = new QDialogButtonBox( adv );
1241 QPushButton *closeButton = new QPushButton( qtr( "OK" ) );
1242 QPushButton *cancelButton = new QPushButton( qtr( "Cancel" ) );
1244 CONNECT( closeButton, clicked(), adv, accept() );
1245 CONNECT( cancelButton, clicked(), adv, reject() );
1247 advButtonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
1248 advButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
1250 mainLayout->addWidget( advButtonBox );
1252 /* Creation of the MRL */
1255 QString tempMRL = "";
1256 for( int i = 0; i < controls.count(); i++ )
1258 ConfigControl *control = controls[i];
1260 tempMRL += (i ? " :" : ":");
1262 if( control->getType() == CONFIG_ITEM_BOOL )
1263 if( !(qobject_cast<VIntConfigControl *>(control)->getValue() ) )
1266 tempMRL += control->getName();
1268 switch( control->getType() )
1270 case CONFIG_ITEM_STRING:
1271 case CONFIG_ITEM_LOADFILE:
1272 case CONFIG_ITEM_SAVEFILE:
1273 case CONFIG_ITEM_DIRECTORY:
1274 case CONFIG_ITEM_MODULE:
1275 tempMRL += colon_escape( QString("=%1").arg( qobject_cast<VStringConfigControl *>(control)->getValue() ) );
1277 case CONFIG_ITEM_INTEGER:
1278 tempMRL += QString("=%1").arg( qobject_cast<VIntConfigControl *>(control)->getValue() );
1280 case CONFIG_ITEM_FLOAT:
1281 tempMRL += QString("=%1").arg( qobject_cast<VFloatConfigControl *>(control)->getValue() );
1287 msg_Dbg( p_intf, "%s", qtu( advMRL ) );
1289 qDeleteAll( controls );
1291 module_config_free( p_config );