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 ( int 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 );
109 /* Build the subs size combo box */
110 setfillVLCConfigCombo( "freetype-rel-fontsize" , p_intf,
111 ui.sizeSubComboBox );
112 /* Build the subs align combo box */
113 setfillVLCConfigCombo( "subsdec-align", p_intf, ui.alignSubComboBox );
116 BUTTONACT( ui.fileBrowseButton, browseFile() );
117 BUTTONACT( ui.removeFileButton, removeFile() );
119 BUTTONACT( ui.subBrowseButton, browseFileSub() );
120 CONNECT( ui.subCheckBox, toggled( bool ), this, toggleSubtitleFrame( bool ) );
122 CONNECT( ui.fileListWidg, itemChanged( QListWidgetItem * ), this, updateMRL() );
123 CONNECT( ui.subInput, textChanged( const QString& ), this, updateMRL() );
124 CONNECT( ui.alignSubComboBox, currentIndexChanged( int ), this, updateMRL() );
125 CONNECT( ui.sizeSubComboBox, currentIndexChanged( int ), this, updateMRL() );
129 inline void FileOpenPanel::BuildOldPanel()
131 /** BEGIN QFileDialog tweaking **/
132 /* Use a QFileDialog and customize it because we don't want to
133 rewrite it all. Be careful to your eyes cause there are a few hacks.
134 Be very careful and test correctly when you modify this. */
136 /* Make this QFileDialog a child of tempWidget from the ui. */
137 dialogBox = new FileOpenBox( ui.tempWidget, NULL,
138 p_intf->p_sys->filepath, "" );
140 dialogBox->setFileMode( QFileDialog::ExistingFiles );
141 dialogBox->setAcceptMode( QFileDialog::AcceptOpen );
142 dialogBox->restoreState(
143 getSettings()->value( "file-dialog-state" ).toByteArray() );
145 /* We don't want to see a grip in the middle of the window, do we? */
146 dialogBox->setSizeGripEnabled( false );
149 dialogBox->setToolTip( qtr( "Select one or multiple files" ) );
150 dialogBox->setMinimumHeight( 250 );
152 // But hide the two OK/Cancel buttons. Enable them for debug.
153 QDialogButtonBox *fileDialogAcceptBox =
154 dialogBox->findChildren<QDialogButtonBox*>()[0];
155 fileDialogAcceptBox->hide();
157 /* Ugly hacks to get the good Widget */
158 //This lineEdit is the normal line in the fileDialog.
159 QLineEdit *lineFileEdit = dialogBox->findChildren<QLineEdit*>()[0];
160 /* Make a list of QLabel inside the QFileDialog to access the good ones */
161 QList<QLabel *> listLabel = dialogBox->findChildren<QLabel*>();
163 /* Hide the FileNames one. Enable it for debug */
164 listLabel[1]->setText( qtr( "File names:" ) );
165 /* Change the text that was uncool in the usual box */
166 listLabel[2]->setText( qtr( "Filter:" ) );
168 dialogBox->layout()->setMargin( 0 );
169 dialogBox->layout()->setSizeConstraint( QLayout::SetNoConstraint );
171 /** END of QFileDialog tweaking **/
173 // Add the DialogBox to the layout
174 ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
176 CONNECT( lineFileEdit, textChanged( const QString& ), this, updateMRL() );
177 dialogBox->installEventFilter( this );
180 FileOpenPanel::~FileOpenPanel()
183 getSettings()->setValue( "file-dialog-state", dialogBox->saveState() );
186 void FileOpenPanel::dragEnterEvent( QDragEnterEvent *event )
188 event->acceptProposedAction();
191 void FileOpenPanel::dragMoveEvent( QDragMoveEvent *event )
193 event->acceptProposedAction();
196 void FileOpenPanel::dragLeaveEvent( QDragLeaveEvent *event )
201 void FileOpenPanel::dropEvent( QDropEvent *event )
203 if( event->possibleActions() & Qt::CopyAction )
204 event->setDropAction( Qt::CopyAction );
208 const QMimeData *mimeData = event->mimeData();
209 foreach( const QUrl &url, mimeData->urls() )
213 QListWidgetItem *item = new QListWidgetItem(
214 toNativeSeparators( url.toLocalFile() ),
216 item->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled );
217 ui.fileListWidg->addItem( item );
225 void FileOpenPanel::browseFile()
227 QStringList files = QFileDialog::getOpenFileNames( this, qtr( "Select one or multiple files" ), p_intf->p_sys->filepath) ;
228 foreach( const QString &file, files )
230 QListWidgetItem *item =
231 new QListWidgetItem( toNativeSeparators( file ), ui.fileListWidg );
232 item->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled );
233 ui.fileListWidg->addItem( item );
234 savedirpathFromFile( file );
240 void FileOpenPanel::removeFile()
242 int i = ui.fileListWidg->currentRow();
245 QListWidgetItem *temp = ui.fileListWidg->takeItem( i );
253 /* Show a fileBrowser to select a subtitle */
254 void FileOpenPanel::browseFileSub()
256 // TODO Handle selection of more than one subtitles file
257 QStringList files = THEDP->showSimpleOpen( qtr("Open subtitles file"),
258 EXT_FILTER_SUBTITLE, p_intf->p_sys->filepath );
260 if( files.isEmpty() ) return;
261 ui.subInput->setText( toNativeSeparators( files.join(" ") ) );
265 void FileOpenPanel::toggleSubtitleFrame( bool b )
267 ui.subFrame->setEnabled( b );
274 /* Update the current MRL */
275 void FileOpenPanel::updateMRL()
277 QStringList fileList;
281 if( dialogBox == NULL )
282 for( int i = 0; i < ui.fileListWidg->count(); i++ )
284 if( !ui.fileListWidg->item( i )->text().isEmpty() )
285 fileList << toURI(ui.fileListWidg->item( i )->text());
289 fileList = dialogBox->selectedFiles();
290 for( int i = 0; i < fileList.count(); i++ )
291 fileList[i] = toURI( fileList[i] );
295 if( ui.subCheckBox->isChecked() && !ui.subInput->text().isEmpty() ) {
296 mrl.append( " :sub-file=" + colon_escape( ui.subInput->text() ) );
297 int align = ui.alignSubComboBox->itemData(
298 ui.alignSubComboBox->currentIndex() ).toInt();
299 mrl.append( " :subsdec-align=" + QString().setNum( align ) );
300 int size = ui.sizeSubComboBox->itemData(
301 ui.sizeSubComboBox->currentIndex() ).toInt();
302 mrl.append( " :freetype-rel-fontsize=" + QString().setNum( size ) );
305 emit mrlUpdated( fileList, mrl );
306 emit methodChanged( "file-caching" );
309 /* Function called by Open Dialog when clicke on Play/Enqueue */
310 void FileOpenPanel::accept()
313 p_intf->p_sys->filepath = dialogBox->directory().absolutePath();
314 ui.fileListWidg->clear();
317 /* Function called by Open Dialog when clicked on cancel */
318 void FileOpenPanel::clear()
320 ui.fileListWidg->clear();
321 ui.subInput->clear();
324 /* Update buttons depending on current selection */
325 void FileOpenPanel::updateButtons()
327 bool b_has_files = ( ui.fileListWidg->count() > 0 );
328 ui.removeFileButton->setEnabled( b_has_files );
329 ui.subCheckBox->setEnabled( b_has_files );
332 /**************************************************************************
333 * Open Discs ( DVD, CD, VCD and similar devices ) *
334 **************************************************************************/
335 DiscOpenPanel::DiscOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
336 OpenPanel( _parent, _p_intf )
340 /* Get the default configuration path for the devices */
341 psz_dvddiscpath = var_InheritString( p_intf, "dvd" );
342 psz_vcddiscpath = var_InheritString( p_intf, "vcd" );
343 psz_cddadiscpath = var_InheritString( p_intf, "cd-audio" );
345 /* State to avoid overwritting the users changes with the configuration */
348 ui.browseDiscButton->setToolTip( qtr( I_DEVICE_TOOLTIP ));
349 ui.deviceCombo->setToolTip( qtr(I_DEVICE_TOOLTIP) );
351 #ifdef WIN32 /* Disc drives probing for Windows */
352 wchar_t szDrives[512];
354 if( GetLogicalDriveStringsW( sizeof( szDrives ) - 1, szDrives ) )
356 wchar_t *drive = szDrives;
357 UINT oldMode = SetErrorMode( SEM_FAILCRITICALERRORS );
360 if( GetDriveTypeW(drive) == DRIVE_CDROM )
362 wchar_t psz_name[512] = L"";
363 GetVolumeInformationW( drive, psz_name, 511, NULL, NULL, NULL, NULL, 0 );
365 QString displayName = FromWide( drive );
366 if( !EMPTY_STR(psz_name) ) {
367 displayName = displayName + " - " + FromWide( psz_name );
370 ui.deviceCombo->addItem( displayName, FromWide( drive ) );
373 /* go to next drive */
376 SetErrorMode(oldMode);
379 char const * const ppsz_discdevices[] = {
386 QComboBox *discCombo = ui.deviceCombo; /* avoid namespacing in macro */
387 POPULATE_WITH_DEVS( ppsz_discdevices, discCombo );
391 BUTTONACT( ui.dvdRadioButton, updateButtons() );
392 BUTTONACT( ui.vcdRadioButton, updateButtons() );
393 BUTTONACT( ui.audioCDRadioButton, updateButtons() );
394 BUTTONACT( ui.dvdsimple, updateButtons() );
395 BUTTONACT( ui.browseDiscButton, browseDevice() );
396 BUTTON_SET_ACT_I( ui.ejectButton, "", toolbar/eject, qtr( "Eject the disc" ),
399 CONNECT( ui.deviceCombo, editTextChanged( QString ), this, updateMRL());
400 CONNECT( ui.titleSpin, valueChanged( int ), this, updateMRL());
401 CONNECT( ui.chapterSpin, valueChanged( int ), this, updateMRL());
402 CONNECT( ui.audioSpin, valueChanged( int ), this, updateMRL());
403 CONNECT( ui.subtitlesSpin, valueChanged( int ), this, updateMRL());
405 /* Run once the updateButtons function in order to fill correctly the comboBoxes */
409 DiscOpenPanel::~DiscOpenPanel()
411 free( psz_dvddiscpath );
412 free( psz_vcddiscpath );
413 free( psz_cddadiscpath );
416 void DiscOpenPanel::clear()
418 ui.titleSpin->setValue( 0 );
419 ui.chapterSpin->setValue( 0 );
420 ui.subtitlesSpin->setValue( -1 );
421 ui.audioSpin->setValue( -1 );
426 #define setDrive( psz_name ) {\
427 int index = ui.deviceCombo->findText( qfu( psz_name ) ); \
428 if( index != -1 ) ui.deviceCombo->setCurrentIndex( index );}
430 #define setDrive( psz_name ) {\
431 ui.deviceCombo->setEditText( qfu( psz_name ) ); }
434 /* update the buttons according the type of device */
435 void DiscOpenPanel::updateButtons()
437 if ( ui.dvdRadioButton->isChecked() )
439 if( m_discType != Dvd )
441 setDrive( psz_dvddiscpath );
444 ui.titleLabel->setText( qtr("Title") );
445 ui.chapterLabel->show();
446 ui.chapterSpin->show();
447 ui.diskOptionBox_2->show();
448 ui.dvdsimple->setEnabled( true );
450 else if ( ui.vcdRadioButton->isChecked() )
452 if( m_discType != Vcd )
454 setDrive( psz_vcddiscpath );
457 ui.titleLabel->setText( qtr("Entry") );
458 ui.chapterLabel->hide();
459 ui.chapterSpin->hide();
460 ui.diskOptionBox_2->show();
461 ui.dvdsimple->setEnabled( false );
465 if( m_discType != Cdda )
467 setDrive( psz_cddadiscpath );
470 ui.titleLabel->setText( qtr("Track") );
471 ui.chapterLabel->hide();
472 ui.chapterSpin->hide();
473 ui.diskOptionBox_2->hide();
474 ui.dvdsimple->setEnabled( false );
483 # define LOCALHOST ""
485 # define LOCALHOST "/"
488 /* Update the current MRL */
489 void DiscOpenPanel::updateMRL()
493 QStringList fileList;
495 if( ui.deviceCombo->itemData( ui.deviceCombo->currentIndex() ) != QVariant::Invalid )
496 discPath = ui.deviceCombo->itemData( ui.deviceCombo->currentIndex() ).toString();
498 discPath = ui.deviceCombo->currentText();
500 /* CDDAX and VCDX not implemented. TODO ? No. */
502 if( ui.dvdRadioButton->isChecked() ) {
503 if( !ui.dvdsimple->isChecked() )
504 mrl = "dvd://" LOCALHOST + discPath;
506 mrl = "dvdsimple://" LOCALHOST + discPath;
508 if( !ui.dvdsimple->isChecked() )
509 emit methodChanged( "dvdnav-caching" );
511 emit methodChanged( "dvdread-caching" );
513 if ( ui.titleSpin->value() > 0 ) {
514 mrl += QString("@%1").arg( ui.titleSpin->value() );
515 if ( ui.chapterSpin->value() > 0 ) {
516 mrl+= QString(":%1").arg( ui.chapterSpin->value() );
521 } else if ( ui.vcdRadioButton->isChecked() ) {
522 mrl = "vcd://" LOCALHOST + discPath;
523 emit methodChanged( "vcd-caching" );
525 if( ui.titleSpin->value() > 0 ) {
526 mrl += QString("@E%1").arg( ui.titleSpin->value() );
531 mrl = "cdda://" LOCALHOST + discPath;
532 emit methodChanged( "cdda-caching" );
535 fileList << mrl; mrl = "";
537 if ( ui.dvdRadioButton->isChecked() || ui.vcdRadioButton->isChecked() )
539 if ( ui.audioSpin->value() >= 0 ) {
540 mrl += " :audio-track=" +
541 QString("%1").arg( ui.audioSpin->value() );
543 if ( ui.subtitlesSpin->value() >= 0 ) {
544 mrl += " :sub-track=" +
545 QString("%1").arg( ui.subtitlesSpin->value() );
550 if( ui.titleSpin->value() > 0 )
551 mrl += QString(" :cdda-track=%1").arg( ui.titleSpin->value() );
553 emit mrlUpdated( fileList, mrl );
556 void DiscOpenPanel::browseDevice()
558 QString dir = QFileDialog::getExistingDirectory( this,
559 qtr( I_DEVICE_TOOLTIP ) );
561 ui.deviceCombo->setEditText( toNativeSepNoSlash( dir ) );
566 void DiscOpenPanel::eject()
568 intf_Eject( p_intf, qtu( ui.deviceCombo->currentText() ) );
571 void DiscOpenPanel::accept()
574 /**************************************************************************
575 * Open Network streams and URL pages *
576 **************************************************************************/
577 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
578 OpenPanel( _parent, _p_intf )
583 CONNECT( ui.urlComboBox->lineEdit(), textChanged( const QString& ), this, updateMRL());
584 CONNECT( ui.urlComboBox, currentIndexChanged( const QString& ), this, updateMRL());
586 if( var_InheritBool( p_intf, "qt-recentplay" ) )
588 mrlList = new QStringListModel(
589 getSettings()->value( "Open/netMRL" ).toStringList() );
590 ui.urlComboBox->setModel( mrlList );
591 ui.urlComboBox->clearEditText();
592 CONNECT( ui.urlComboBox->lineEdit(), editingFinished(), this, updateModel() );
597 ui.urlComboBox->setValidator( new UrlValidator( this ) );
598 ui.urlComboBox->setFocus();
601 NetOpenPanel::~NetOpenPanel()
603 if( !mrlList ) return;
605 QStringList tempL = mrlList->stringList();
606 while( tempL.size() > 8 ) tempL.removeFirst();
608 getSettings()->setValue( "Open/netMRL", tempL );
613 void NetOpenPanel::clear()
616 void NetOpenPanel::onFocus()
618 ui.urlComboBox->setFocus();
619 ui.urlComboBox->lineEdit()->selectAll();
622 static int strcmp_void( const void *k, const void *e )
624 return strcmp( (const char *)k, (const char *)e );
627 void NetOpenPanel::updateMRL()
629 static const struct caching_map
634 { /* KEEP alphabetical order on first column!! */
652 QString url = ui.urlComboBox->lineEdit()->text();
653 if( !url.contains( "://") )
654 return; /* nothing to do this far */
656 /* Match the correct item in the comboBox */
657 QString proto = url.section( ':', 0, 0 );
658 const struct caching_map *r = (const struct caching_map *)
659 bsearch( qtu(proto), schemes, sizeof(schemes) / sizeof(schemes[0]),
660 sizeof(schemes[0]), strcmp_void );
662 emit methodChanged( qfu( r->caching ) + qfu( "-caching" ) );
666 emit mrlUpdated( qsl, "" );
669 void NetOpenPanel::updateModel()
672 QStringList tempL = mrlList->stringList();
673 if( !tempL.contains( ui.urlComboBox->lineEdit()->text() ) )
674 tempL.append( ui.urlComboBox->lineEdit()->text() );
675 mrlList->setStringList( tempL );
678 void UrlValidator::fixup( QString& str ) const
683 QValidator::State UrlValidator::validate( QString& str, int& pos ) const
685 if( str.contains( ' ' ) )
686 return QValidator::Invalid;
687 if( !str.contains( "://" ) )
688 return QValidator::Intermediate;
689 return QValidator::Acceptable;
692 /**************************************************************************
693 * Open Capture device ( DVB, PVR, V4L, and similar ) *
694 **************************************************************************/
695 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
696 OpenPanel( _parent, _p_intf )
698 isInitialized = false;
701 void CaptureOpenPanel::initialize()
703 if( isInitialized ) return;
705 msg_Dbg( p_intf, "Initialization of Capture device panel" );
706 isInitialized = true;
710 BUTTONACT( ui.advancedButton, advancedDialog() );
712 /* Create two stacked layouts in the main comboBoxes */
713 QStackedLayout *stackedDevLayout = new QStackedLayout;
714 ui.cardBox->setLayout( stackedDevLayout );
716 QStackedLayout *stackedPropLayout = new QStackedLayout;
717 ui.optionsBox->setLayout( stackedPropLayout );
719 /* Creation and connections of the WIdgets in the stacked layout */
720 #define addModuleAndLayouts( number, name, label, layout ) \
721 QWidget * name ## DevPage = new QWidget( this ); \
722 QWidget * name ## PropPage = new QWidget( this ); \
723 stackedDevLayout->addWidget( name ## DevPage ); \
724 stackedPropLayout->addWidget( name ## PropPage ); \
725 layout * name ## DevLayout = new layout; \
726 layout * name ## PropLayout = new layout; \
727 name ## DevPage->setLayout( name ## DevLayout ); \
728 name ## PropPage->setLayout( name ## PropLayout ); \
729 ui.deviceCombo->addItem( qtr( label ), QVariant( number ) );
731 #define CuMRL( widget, slot ) CONNECT( widget , slot , this, updateMRL() );
734 /*********************
735 * DirectShow Stuffs *
736 *********************/
737 if( module_exists( "dshow" ) ){
738 addModuleAndLayouts( DSHOW_DEVICE, dshow, "DirectShow", QGridLayout );
742 module_config_t *p_config =
743 config_FindConfig( VLC_OBJECT(p_intf), "dshow-vdev" );
744 vdevDshowW = new StringListConfigControl(
745 VLC_OBJECT(p_intf), p_config, this, false, dshowDevLayout, line );
748 p_config = config_FindConfig( VLC_OBJECT(p_intf), "dshow-adev" );
749 adevDshowW = new StringListConfigControl(
750 VLC_OBJECT(p_intf), p_config, this, false, dshowDevLayout, line );
753 /* dshow Properties */
754 QLabel *dshowVSizeLabel = new QLabel( qtr( "Video size" ) );
755 dshowPropLayout->addWidget( dshowVSizeLabel, 0, 0 );
757 dshowVSizeLine = new QLineEdit;
758 dshowPropLayout->addWidget( dshowVSizeLine, 0, 1);
759 dshowPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
763 CuMRL( vdevDshowW->combo, currentIndexChanged ( int ) );
764 CuMRL( adevDshowW->combo, currentIndexChanged ( int ) );
765 CuMRL( dshowVSizeLine, textChanged( const QString& ) );
771 if( module_exists( "v4l2" ) ){
772 addModuleAndLayouts( V4L2_DEVICE, v4l2, "Video for Linux 2", QGridLayout );
774 char const * const ppsz_v4lvdevices[] = {
778 char const * const ppsz_v4ladevices[] = {
784 QLabel *v4l2VideoDeviceLabel = new QLabel( qtr( "Video device name" ) );
785 v4l2DevLayout->addWidget( v4l2VideoDeviceLabel, 0, 0 );
787 v4l2VideoDevice = new QComboBox( this );
788 v4l2VideoDevice->setEditable( true );
789 POPULATE_WITH_DEVS( ppsz_v4lvdevices, v4l2VideoDevice );
790 v4l2VideoDevice->clearEditText();
791 v4l2DevLayout->addWidget( v4l2VideoDevice, 0, 1 );
793 QLabel *v4l2AudioDeviceLabel = new QLabel( qtr( "Audio device name" ) );
794 v4l2DevLayout->addWidget( v4l2AudioDeviceLabel, 1, 0 );
796 v4l2AudioDevice = new QComboBox( this );
797 v4l2AudioDevice->setEditable( true );
798 POPULATE_WITH_DEVS( ppsz_v4ladevices, v4l2AudioDevice );
799 v4l2AudioDevice->clearEditText();
800 v4l2DevLayout->addWidget( v4l2AudioDevice, 1, 1 );
802 /* v4l2 Props panel */
803 QLabel *v4l2StdLabel = new QLabel( qtr( "Video standard" ) );
804 v4l2PropLayout->addWidget( v4l2StdLabel, 0 , 0 );
806 v4l2StdBox = new QComboBox;
807 setfillVLCConfigCombo( "v4l2-standard", p_intf, v4l2StdBox );
808 v4l2PropLayout->addWidget( v4l2StdBox, 0 , 1 );
809 v4l2PropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
813 CuMRL( v4l2VideoDevice->lineEdit(), textChanged( const QString& ) );
814 CuMRL( v4l2VideoDevice, currentIndexChanged ( int ) );
815 CuMRL( v4l2AudioDevice->lineEdit(), textChanged( const QString& ) );
816 CuMRL( v4l2AudioDevice, currentIndexChanged ( int ) );
817 CuMRL( v4l2StdBox, currentIndexChanged ( int ) );
823 if( module_exists( "jack" ) ){
824 addModuleAndLayouts( JACK_DEVICE, jack, "JACK Audio Connection Kit",
827 /* Jack Main panel */
829 QLabel *jackChannelsLabel = new QLabel( qtr( "Channels:" ) );
830 jackDevLayout->addWidget( jackChannelsLabel, 1, 0 );
832 jackChannels = new QSpinBox;
833 setSpinBoxFreq( jackChannels );
834 jackChannels->setMaximum(255);
835 jackChannels->setValue(2);
836 jackChannels->setAlignment( Qt::AlignRight );
837 jackDevLayout->addWidget( jackChannels, 1, 1 );
840 QLabel *jackPortsLabel = new QLabel( qtr( "Selected ports:" ) );
841 jackDevLayout->addWidget( jackPortsLabel, 0 , 0 );
843 jackPortsSelected = new QLineEdit( qtr( ".*") );
844 jackPortsSelected->setAlignment( Qt::AlignRight );
845 jackDevLayout->addWidget( jackPortsSelected, 0, 1 );
847 /* Jack Props panel */
850 QLabel *jackCachingLabel = new QLabel( qtr( "Input caching:" ) );
851 jackPropLayout->addWidget( jackCachingLabel, 1 , 0 );
852 jackCaching = new QSpinBox;
853 setSpinBoxFreq( jackCaching );
854 jackCaching->setSuffix( " ms" );
855 jackCaching->setValue(1000);
856 jackCaching->setAlignment( Qt::AlignRight );
857 jackPropLayout->addWidget( jackCaching, 1 , 2 );
860 jackPace = new QCheckBox(qtr( "Use VLC pace" ));
861 jackPropLayout->addWidget( jackPace, 2, 1 );
864 jackConnect = new QCheckBox( qtr( "Auto connection" ));
865 jackPropLayout->addWidget( jackConnect, 2, 2 );
868 CuMRL( jackChannels, valueChanged( int ) );
869 CuMRL( jackCaching, valueChanged( int ) );
870 CuMRL( jackPace, stateChanged( int ) );
871 CuMRL( jackConnect, stateChanged( int ) );
872 CuMRL( jackPortsSelected, textChanged( const QString& ) );
878 if( module_exists( "pvr" ) ){
879 addModuleAndLayouts( PVR_DEVICE, pvr, "PVR", QGridLayout );
882 QLabel *pvrDeviceLabel = new QLabel( qtr( "Device name" ) );
883 pvrDevLayout->addWidget( pvrDeviceLabel, 0, 0 );
885 pvrDevice = new QLineEdit;
886 pvrDevLayout->addWidget( pvrDevice, 0, 1 );
888 QLabel *pvrRadioDeviceLabel = new QLabel( qtr( "Radio device name" ) );
889 pvrDevLayout->addWidget( pvrRadioDeviceLabel, 1, 0 );
891 pvrRadioDevice = new QLineEdit;
892 pvrDevLayout->addWidget( pvrRadioDevice, 1, 1 );
894 /* PVR props panel */
895 QLabel *pvrNormLabel = new QLabel( qtr( "Norm" ) );
896 pvrPropLayout->addWidget( pvrNormLabel, 0, 0 );
898 pvrNormBox = new QComboBox;
899 setfillVLCConfigCombo( "pvr-norm", p_intf, pvrNormBox );
900 pvrPropLayout->addWidget( pvrNormBox, 0, 1 );
902 QLabel *pvrFreqLabel = new QLabel( qtr( "Frequency" ) );
903 pvrPropLayout->addWidget( pvrFreqLabel, 1, 0 );
905 pvrFreq = new QSpinBox;
906 pvrFreq->setAlignment( Qt::AlignRight );
907 pvrFreq->setSuffix(" kHz");
908 setSpinBoxFreq( pvrFreq );
909 pvrPropLayout->addWidget( pvrFreq, 1, 1 );
911 QLabel *pvrBitrLabel = new QLabel( qtr( "Bitrate" ) );
912 pvrPropLayout->addWidget( pvrBitrLabel, 2, 0 );
914 pvrBitr = new QSpinBox;
915 pvrBitr->setAlignment( Qt::AlignRight );
916 pvrBitr->setSuffix(" kHz");
917 setSpinBoxFreq( pvrBitr );
918 pvrPropLayout->addWidget( pvrBitr, 2, 1 );
919 pvrPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
923 CuMRL( pvrDevice, textChanged( const QString& ) );
924 CuMRL( pvrRadioDevice, textChanged( const QString& ) );
926 CuMRL( pvrFreq, valueChanged ( int ) );
927 CuMRL( pvrBitr, valueChanged ( int ) );
928 CuMRL( pvrNormBox, currentIndexChanged ( int ) );
934 if( module_exists( "dtv" ) ){
935 addModuleAndLayouts( DTV_DEVICE, dvb, N_("TV (digital)"), QGridLayout );
938 QLabel *dvbDeviceLabel = new QLabel( qtr( "Tuner card" ) );
939 QLabel *dvbTypeLabel = new QLabel( qtr( "Delivery system" ) );
941 dvbCard = new QSpinBox;
942 dvbCard->setAlignment( Qt::AlignRight );
944 dvbCard->setPrefix( "/dev/dvb/adapter" );
945 dvbFE = new QSpinBox;
946 dvbFE->setPrefix( "/frontend" );
948 dvbDevLayout->addWidget( dvbDeviceLabel, 0, 0 );
949 dvbDevLayout->addWidget( dvbCard, 0, 1, 1, 2 );
951 dvbDevLayout->addWidget( dvbFE, 0, 3 );
954 dvbc = new QRadioButton( "DVB-C" );
955 dvbs = new QRadioButton( "DVB-S" );
956 dvbs2 = new QRadioButton( "DVB-S2" );
957 dvbt = new QRadioButton( "DVB-T" );
958 atsc = new QRadioButton( "ATSC" );
959 cqam = new QRadioButton( "Clear QAM" );
960 dvbt->setChecked( true );
962 dvbDevLayout->addWidget( dvbTypeLabel, 1, 0, 2, 1 );
963 dvbDevLayout->addWidget( dvbc, 1, 1 );
964 dvbDevLayout->addWidget( dvbs, 1, 2 );
965 dvbDevLayout->addWidget( dvbs2, 2, 2 );
966 dvbDevLayout->addWidget( dvbt, 1, 3 );
967 dvbDevLayout->addWidget( atsc, 1, 4 );
968 dvbDevLayout->addWidget( cqam, 2, 4 );
970 /* DVB Props panel */
971 QLabel *dvbFreqLabel =
972 new QLabel( qtr( "Transponder/multiplex frequency" ) );
973 dvbPropLayout->addWidget( dvbFreqLabel, 0, 0 );
975 dvbFreq = new QSpinBox;
976 dvbFreq->setAlignment( Qt::AlignRight );
977 dvbFreq->setSuffix(" kHz");
978 dvbFreq->setSingleStep( 1000 );
979 setSpinBoxFreq( dvbFreq );
980 dvbPropLayout->addWidget( dvbFreq, 0, 1 );
982 dvbSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
983 dvbPropLayout->addWidget( dvbSrateLabel, 1, 0 );
985 dvbSrate = new QSpinBox;
986 dvbSrate->setAlignment( Qt::AlignRight );
987 dvbSrate->setSuffix(" bauds");
988 setSpinBoxFreq( dvbSrate );
989 dvbPropLayout->addWidget( dvbSrate, 1, 1 );
991 dvbModLabel = new QLabel( qtr( "Modulation / Constellation" ) );
992 dvbPropLayout->addWidget( dvbModLabel, 2, 0 );
994 dvbQamBox = new QComboBox;
995 dvbQamBox->addItem( qtr( "Automatic" ), qfu("QAM") );
996 dvbQamBox->addItem( "256-QAM", qfu("256QAM") );
997 dvbQamBox->addItem( "128-QAM", qfu("128QAM") );
998 dvbQamBox->addItem( "64-QAM", qfu("64QAM") );
999 dvbQamBox->addItem( "32-QAM", qfu("32QAM") );
1000 dvbQamBox->addItem( "16-QAM", qfu("16QAM") );
1001 dvbPropLayout->addWidget( dvbQamBox, 2, 1 );
1003 dvbPskBox = new QComboBox;
1004 dvbPskBox->addItem( "QPSK", qfu("QPSK") );
1005 dvbPskBox->addItem( "DQPSK", qfu("DQPSK") );
1006 dvbPskBox->addItem( "8-PSK", qfu("8PSK") );
1007 dvbPskBox->addItem( "16-APSK", qfu("16APSK") );
1008 dvbPskBox->addItem( "32-APSK", qfu("32APSK") );
1009 dvbPropLayout->addWidget( dvbPskBox, 2, 1 );
1011 dvbModLabel->hide();
1015 dvbBandLabel = new QLabel( qtr( "Bandwidth" ) );
1016 dvbPropLayout->addWidget( dvbBandLabel, 2, 0 );
1018 dvbBandBox = new QComboBox;
1019 setfillVLCConfigCombo( "dvb-bandwidth", p_intf, dvbBandBox );
1020 dvbPropLayout->addWidget( dvbBandBox, 2, 1 );
1022 dvbBandLabel->hide();
1025 dvbPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
1029 CuMRL( dvbCard, valueChanged ( int ) );
1031 CuMRL( dvbFE, valueChanged ( int ) );
1033 CuMRL( dvbFreq, valueChanged ( int ) );
1034 CuMRL( dvbSrate, valueChanged ( int ) );
1035 CuMRL( dvbQamBox, currentIndexChanged ( int ) );
1036 CuMRL( dvbPskBox, currentIndexChanged ( int ) );
1037 CuMRL( dvbBandBox, currentIndexChanged ( int ) );
1039 BUTTONACT( dvbc, updateButtons() );
1040 BUTTONACT( dvbs, updateButtons() );
1041 BUTTONACT( dvbs2, updateButtons() );
1042 BUTTONACT( dvbt, updateButtons() );
1043 BUTTONACT( atsc, updateButtons() );
1044 BUTTONACT( cqam, updateButtons() );
1045 BUTTONACT( dvbc, updateMRL() );
1046 BUTTONACT( dvbt, updateMRL() );
1047 BUTTONACT( dvbs, updateMRL() );
1048 BUTTONACT( dvbs2, updateMRL() );
1049 BUTTONACT( atsc, updateMRL() );
1050 BUTTONACT( cqam, updateMRL() );
1056 addModuleAndLayouts( SCREEN_DEVICE, screen, "Desktop", QGridLayout );
1057 QLabel *screenLabel = new QLabel( qtr( "Your display will be "
1058 "opened and played in order to stream or save it." ) );
1059 screenLabel->setWordWrap( true );
1060 screenDevLayout->addWidget( screenLabel, 0, 0 );
1062 QLabel *screenFPSLabel = new QLabel(
1063 qtr( "Desired frame rate for the capture." ) );
1064 screenPropLayout->addWidget( screenFPSLabel, 0, 0 );
1066 screenFPS = new QDoubleSpinBox;
1067 screenFPS->setValue( 1. );
1068 screenFPS->setRange( .01, 100. );
1069 screenFPS->setAlignment( Qt::AlignRight );
1070 /* xgettext: frames per second */
1071 screenFPS->setSuffix( qtr( " f/s" ) );
1072 screenPropLayout->addWidget( screenFPS, 0, 1 );
1074 /* Screen connect */
1075 CuMRL( screenFPS, valueChanged( double ) );
1077 /* General connects */
1078 CONNECT( ui.deviceCombo, activated( int ) ,
1079 stackedDevLayout, setCurrentIndex( int ) );
1080 CONNECT( ui.deviceCombo, activated( int ),
1081 stackedPropLayout, setCurrentIndex( int ) );
1082 CONNECT( ui.deviceCombo, activated( int ), this, updateMRL() );
1083 CONNECT( ui.deviceCombo, activated( int ), this, updateButtons() );
1086 #undef addModuleAndLayouts
1089 CaptureOpenPanel::~CaptureOpenPanel()
1093 void CaptureOpenPanel::clear()
1098 void CaptureOpenPanel::updateMRL()
1101 QStringList fileList;
1102 int i_devicetype = ui.deviceCombo->itemData(
1103 ui.deviceCombo->currentIndex() ).toInt();
1104 switch( i_devicetype )
1108 fileList << "dshow://";
1109 mrl+= " :dshow-vdev=" +
1110 colon_escape( QString("%1").arg( vdevDshowW->getValue() ) );
1111 mrl+= " :dshow-adev=" +
1112 colon_escape( QString("%1").arg( adevDshowW->getValue() ) )+" ";
1113 if( dshowVSizeLine->isModified() )
1114 mrl += ":dshow-size=" + dshowVSizeLine->text();
1115 emit methodChanged( "dshow-caching" );
1119 fileList << "v4l2://" + v4l2VideoDevice->currentText();
1120 mrl += " :input-slave=alsa://" + v4l2AudioDevice->currentText();
1121 mrl += " :v4l2-standard=" + QString::number( v4l2StdBox->currentIndex() );
1125 mrl += "channels=" + QString::number( jackChannels->value() );
1126 mrl += ":ports=" + jackPortsSelected->text();
1127 fileList << mrl; mrl = "";
1129 mrl += " :jack-input-caching=" + QString::number( jackCaching->value() );
1130 if ( jackPace->isChecked() )
1132 mrl += " :jack-input-use-vlc-pace";
1134 if ( jackConnect->isChecked() )
1136 mrl += " :jack-input-auto-connect";
1140 fileList << "pvr://";
1141 mrl += " :pvr-device=" + pvrDevice->text();
1142 mrl += " :pvr-radio-device=" + pvrRadioDevice->text();
1143 mrl += " :pvr-norm=" + QString::number( pvrNormBox->currentIndex() );
1144 if( pvrFreq->value() )
1145 mrl += " :pvr-frequency=" + QString::number( pvrFreq->value() );
1146 if( pvrBitr->value() )
1147 mrl += " :pvr-bitrate=" + QString::number( pvrBitr->value() );
1151 if( dvbc->isChecked() ) mrl = "dvb-c://";
1153 if( dvbs->isChecked() ) mrl = "dvb-s://";
1155 if( dvbs2->isChecked() ) mrl = "dvb-s2://";
1157 if( dvbt->isChecked() ) mrl = "dvb-t://";
1159 if( atsc->isChecked() ) mrl = "atsc://";
1161 if( cqam->isChecked() ) mrl = "cqam://";
1163 mrl += "frequency=" + QString::number( dvbFreq->value() );
1165 if( dvbc->isChecked() || cqam->isChecked() )
1166 mrl += ":modulation="
1167 + dvbQamBox->itemData( dvbQamBox->currentIndex() ).toString();
1168 if( dvbs2->isChecked() )
1169 mrl += ":modulation="
1170 + dvbPskBox->itemData( dvbPskBox->currentIndex() ).toString();
1171 if( dvbc->isChecked() || dvbs->isChecked() || dvbs2->isChecked() )
1172 mrl += ":srate=" + QString::number( dvbSrate->value() );
1173 if( dvbt->isChecked() )
1174 mrl += ":bandwidth=" +
1175 QString::number( dvbBandBox->itemData(
1176 dvbBandBox->currentIndex() ).toInt() );
1178 fileList << mrl; mrl= "";
1179 mrl += " :dvb-adapter=" + QString::number( dvbCard->value() );
1181 mrl += " :dvb-device=" + QString::number( dvbFE->value() );
1185 fileList << "screen://";
1186 mrl = " :screen-fps=" + QString::number( screenFPS->value(), 'f' );
1187 emit methodChanged( "screen-caching" );
1192 if( !advMRL.isEmpty() ) mrl += advMRL;
1194 emit mrlUpdated( fileList, mrl );
1198 * Update the Buttons (show/hide) for the GUI as all device type don't
1199 * use the same ui. elements.
1201 void CaptureOpenPanel::updateButtons()
1203 /* Be sure to display the ui Elements in case they were hidden by
1204 * some Device Type (like Screen://) */
1205 ui.optionsBox->show();
1206 ui.advancedButton->show();
1207 /* Get the current Device Number */
1208 int i_devicetype = ui.deviceCombo->itemData(
1209 ui.deviceCombo->currentIndex() ).toInt();
1210 switch( i_devicetype )
1214 dvbSrateLabel->hide();
1217 dvbModLabel->hide();
1219 dvbBandLabel->hide();
1221 if( dvbc->isChecked() )
1224 dvbSrateLabel->show();
1226 dvbModLabel->show();
1228 else if( dvbs->isChecked() )
1231 dvbSrateLabel->show();
1233 else if( dvbs2->isChecked() )
1236 dvbSrateLabel->show();
1238 dvbModLabel->show();
1240 else if( dvbt->isChecked() )
1243 dvbBandLabel->show();
1247 //ui.optionsBox->hide();
1248 ui.advancedButton->hide();
1255 void CaptureOpenPanel::advancedDialog()
1257 /* Get selected device type */
1258 int i_devicetype = ui.deviceCombo->itemData(
1259 ui.deviceCombo->currentIndex() ).toInt();
1261 /* Get the corresponding module */
1262 module_t *p_module =
1263 module_find( psz_devModule[i_devicetype] );
1264 if( NULL == p_module ) return;
1267 QList<ConfigControl *> controls;
1269 /* Get the confsize */
1270 unsigned int i_confsize;
1271 module_config_t *p_config;
1272 p_config = module_config_get( p_module, &i_confsize );
1274 /* New Adv Prop dialog */
1275 adv = new QDialog( this );
1276 adv->setWindowTitle( qtr( "Advanced Options" ) );
1277 adv->setWindowRole( "vlc-advanced-options" );
1279 /* A main Layout with a Frame */
1280 QVBoxLayout *mainLayout = new QVBoxLayout( adv );
1281 QScrollArea *scroll = new QScrollArea;
1282 mainLayout->addWidget( scroll );
1284 QFrame *advFrame = new QFrame;
1285 /* GridLayout inside the Frame */
1286 QGridLayout *gLayout = new QGridLayout( advFrame );
1288 scroll->setWidgetResizable( true );
1289 scroll->setWidget( advFrame );
1291 /* Create the options inside the FrameLayout */
1292 for( int n = 0; n < (int)i_confsize; n++ )
1294 module_config_t *p_item = p_config + n;
1295 ConfigControl *config = ConfigControl::createControl(
1296 VLC_OBJECT( p_intf ), p_item, advFrame, gLayout, n );
1298 controls.append( config );
1302 QDialogButtonBox *advButtonBox = new QDialogButtonBox( adv );
1303 QPushButton *closeButton = new QPushButton( qtr( "OK" ) );
1304 QPushButton *cancelButton = new QPushButton( qtr( "Cancel" ) );
1306 CONNECT( closeButton, clicked(), adv, accept() );
1307 CONNECT( cancelButton, clicked(), adv, reject() );
1309 advButtonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
1310 advButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
1312 mainLayout->addWidget( advButtonBox );
1314 /* Creation of the MRL */
1317 QString tempMRL = "";
1318 for( int i = 0; i < controls.size(); i++ )
1320 ConfigControl *control = controls[i];
1322 tempMRL += (i ? " :" : ":");
1324 if( control->getType() == CONFIG_ITEM_BOOL )
1325 if( !(qobject_cast<VIntConfigControl *>(control)->getValue() ) )
1328 tempMRL += control->getName();
1330 switch( control->getType() )
1332 case CONFIG_ITEM_STRING:
1333 case CONFIG_ITEM_LOADFILE:
1334 case CONFIG_ITEM_SAVEFILE:
1335 case CONFIG_ITEM_DIRECTORY:
1336 case CONFIG_ITEM_MODULE:
1337 tempMRL += colon_escape( QString("=%1").arg( qobject_cast<VStringConfigControl *>(control)->getValue() ) );
1339 case CONFIG_ITEM_INTEGER:
1340 tempMRL += QString("=%1").arg( qobject_cast<VIntConfigControl *>(control)->getValue() );
1342 case CONFIG_ITEM_FLOAT:
1343 tempMRL += QString("=%1").arg( qobject_cast<VFloatConfigControl *>(control)->getValue() );
1349 msg_Dbg( p_intf, "%s", qtu( advMRL ) );
1351 for( int i = 0; i < controls.size(); i++ )
1353 ConfigControl *control = controls[i];
1357 module_config_free( p_config );
1358 module_release (p_module);