1 /*****************************************************************************
2 * open.cpp : Panels for the open dialogs
3 ****************************************************************************
4 * Copyright (C) 2006-2009 the VideoLAN team
5 * Copyright (C) 2007 Société des arts technologiques
6 * Copyright (C) 2007 Savoir-faire Linux
10 * Authors: Clément Stenac <zorglub@videolan.org>
11 * Jean-Baptiste Kempf <jb@videolan.org>
12 * Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
27 *****************************************************************************/
34 #include "components/open_panels.hpp"
35 #include "dialogs/open.hpp"
36 #include "dialogs_provider.hpp" /* Open Subtitle file */
37 #include "util/qt_dirs.hpp"
38 #include <vlc_intf_strings.h>
39 #include <vlc_modules.h>
41 #include <QFileDialog>
42 #include <QDialogButtonBox>
44 #include <QStackedLayout>
48 #include <QScrollArea>
50 #include <QStringListModel>
54 #define I_DEVICE_TOOLTIP \
55 I_DIR_OR_FOLDER( N_("Select a device or a VIDEO_TS directory"), \
56 N_("Select a device or a VIDEO_TS folder") )
58 static const char *psz_devModule[] = { "v4l", "v4l2", "pvr", "dvb", "bda",
59 "dshow", "screen", "jack" };
61 /**************************************************************************
62 * Open Files and subtitles *
63 **************************************************************************/
64 FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
65 OpenPanel( _parent, _p_intf ), dialogBox( NULL )
67 /* Classic UI Setup */
70 setAcceptDrops( true );
72 /* Set Filters for file selection */
73 /* QString fileTypes = "";
74 ADD_FILTER_MEDIA( fileTypes );
75 ADD_FILTER_VIDEO( fileTypes );
76 ADD_FILTER_AUDIO( fileTypes );
77 ADD_FILTER_PLAYLIST( fileTypes );
78 ADD_FILTER_ALL( fileTypes );
79 fileTypes.replace( QString(";*"), QString(" *")); */
82 /* lineFileEdit = ui.fileEdit;
83 //TODO later: fill the fileCompleteList with previous items played.
84 QCompleter *fileCompleter = new QCompleter( fileCompleteList, this );
85 fileCompleter->setModel( new QDirModel( fileCompleter ) );
86 lineFileEdit->setCompleter( fileCompleter );*/
87 if( var_InheritBool( p_intf, "qt-embedded-open" ) )
89 ui.tempWidget->hide();
94 /* Deactivate the subtitles control by default. */
95 ui.subFrame->setEnabled( false );
96 /* Build the subs size combo box */
97 setfillVLCConfigCombo( "freetype-rel-fontsize" , p_intf,
99 /* Build the subs align combo box */
100 setfillVLCConfigCombo( "subsdec-align", p_intf, ui.alignSubComboBox );
103 BUTTONACT( ui.fileBrowseButton, browseFile() );
104 BUTTONACT( ui.removeFileButton, removeFile() );
106 BUTTONACT( ui.subBrowseButton, browseFileSub() );
107 CONNECT( ui.subCheckBox, toggled( bool ), this, toggleSubtitleFrame( bool ) );
109 CONNECT( ui.fileListWidg, itemChanged( QListWidgetItem * ), this, updateMRL() );
110 CONNECT( ui.subInput, textChanged( const QString& ), this, updateMRL() );
111 CONNECT( ui.alignSubComboBox, currentIndexChanged( int ), this, updateMRL() );
112 CONNECT( ui.sizeSubComboBox, currentIndexChanged( int ), this, updateMRL() );
116 inline void FileOpenPanel::BuildOldPanel()
118 /** BEGIN QFileDialog tweaking **/
119 /* Use a QFileDialog and customize it because we don't want to
120 rewrite it all. Be careful to your eyes cause there are a few hacks.
121 Be very careful and test correctly when you modify this. */
123 /* Make this QFileDialog a child of tempWidget from the ui. */
124 dialogBox = new FileOpenBox( ui.tempWidget, NULL,
125 p_intf->p_sys->filepath, "" );
127 dialogBox->setFileMode( QFileDialog::ExistingFiles );
128 dialogBox->setAcceptMode( QFileDialog::AcceptOpen );
129 dialogBox->restoreState(
130 getSettings()->value( "file-dialog-state" ).toByteArray() );
132 /* We don't want to see a grip in the middle of the window, do we? */
133 dialogBox->setSizeGripEnabled( false );
136 dialogBox->setToolTip( qtr( "Select one or multiple files" ) );
137 dialogBox->setMinimumHeight( 250 );
139 // But hide the two OK/Cancel buttons. Enable them for debug.
140 QDialogButtonBox *fileDialogAcceptBox =
141 dialogBox->findChildren<QDialogButtonBox*>()[0];
142 fileDialogAcceptBox->hide();
144 /* Ugly hacks to get the good Widget */
145 //This lineEdit is the normal line in the fileDialog.
146 QLineEdit *lineFileEdit = dialogBox->findChildren<QLineEdit*>()[0];
147 /* Make a list of QLabel inside the QFileDialog to access the good ones */
148 QList<QLabel *> listLabel = dialogBox->findChildren<QLabel*>();
150 /* Hide the FileNames one. Enable it for debug */
151 listLabel[1]->setText( qtr( "File names:" ) );
152 /* Change the text that was uncool in the usual box */
153 listLabel[2]->setText( qtr( "Filter:" ) );
155 dialogBox->layout()->setMargin( 0 );
156 dialogBox->layout()->setSizeConstraint( QLayout::SetNoConstraint );
158 /** END of QFileDialog tweaking **/
160 // Add the DialogBox to the layout
161 ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
163 CONNECT( lineFileEdit, textChanged( const QString& ), this, updateMRL() );
164 dialogBox->installEventFilter( this );
167 FileOpenPanel::~FileOpenPanel()
170 getSettings()->setValue( "file-dialog-state", dialogBox->saveState() );
173 void FileOpenPanel::dragEnterEvent( QDragEnterEvent *event )
175 event->acceptProposedAction();
178 void FileOpenPanel::dragMoveEvent( QDragMoveEvent *event )
180 event->acceptProposedAction();
183 void FileOpenPanel::dragLeaveEvent( QDragLeaveEvent *event )
188 void FileOpenPanel::dropEvent( QDropEvent *event )
190 if( event->possibleActions() & Qt::CopyAction )
191 event->setDropAction( Qt::CopyAction );
195 const QMimeData *mimeData = event->mimeData();
196 foreach( const QUrl &url, mimeData->urls() )
200 QListWidgetItem *item = new QListWidgetItem(
201 toNativeSeparators( url.toLocalFile() ),
203 item->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled );
204 ui.fileListWidg->addItem( item );
212 void FileOpenPanel::browseFile()
214 QStringList files = QFileDialog::getOpenFileNames( this, qtr( "Select one or multiple files" ), p_intf->p_sys->filepath) ;
215 foreach( const QString &file, files )
217 QListWidgetItem *item =
218 new QListWidgetItem( toNativeSeparators( file ), ui.fileListWidg );
219 item->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled );
220 ui.fileListWidg->addItem( item );
221 savedirpathFromFile( file );
227 void FileOpenPanel::removeFile()
229 int i = ui.fileListWidg->currentRow();
232 QListWidgetItem *temp = ui.fileListWidg->takeItem( i );
240 /* Show a fileBrowser to select a subtitle */
241 void FileOpenPanel::browseFileSub()
243 // TODO Handle selection of more than one subtitles file
244 QStringList files = THEDP->showSimpleOpen( qtr("Open subtitles file"),
245 EXT_FILTER_SUBTITLE, p_intf->p_sys->filepath );
247 if( files.isEmpty() ) return;
248 ui.subInput->setText( toNativeSeparators( files.join(" ") ) );
252 void FileOpenPanel::toggleSubtitleFrame( bool b )
254 ui.subFrame->setEnabled( b );
261 /* Update the current MRL */
262 void FileOpenPanel::updateMRL()
264 QStringList fileList;
268 if( dialogBox == NULL )
269 for( int i = 0; i < ui.fileListWidg->count(); i++ )
271 if( !ui.fileListWidg->item( i )->text().isEmpty() )
272 fileList << ui.fileListWidg->item( i )->text();
276 fileList = dialogBox->selectedFiles();
277 for( int i = 0; i < fileList.count(); i++ )
278 fileList[i] = toNativeSeparators( fileList[i] );
282 if( ui.subCheckBox->isChecked() && !ui.subInput->text().isEmpty() ) {
283 mrl.append( " :sub-file=" + colon_escape( ui.subInput->text() ) );
284 int align = ui.alignSubComboBox->itemData(
285 ui.alignSubComboBox->currentIndex() ).toInt();
286 mrl.append( " :subsdec-align=" + QString().setNum( align ) );
287 int size = ui.sizeSubComboBox->itemData(
288 ui.sizeSubComboBox->currentIndex() ).toInt();
289 mrl.append( " :freetype-rel-fontsize=" + QString().setNum( size ) );
292 emit mrlUpdated( fileList, mrl );
293 emit methodChanged( "file-caching" );
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) );
338 #ifdef WIN32 /* Disc drives probing for Windows */
341 if( GetLogicalDriveStringsA( sizeof( szDrives ) - 1, szDrives ) )
343 char *drive = szDrives;
344 UINT oldMode = SetErrorMode( SEM_FAILCRITICALERRORS );
347 if( GetDriveTypeA(drive) == DRIVE_CDROM )
348 ui.deviceCombo->addItem( drive );
350 /* go to next drive */
353 SetErrorMode(oldMode);
355 #else /* Use a Completer under Linux */
356 QCompleter *discCompleter = new QCompleter( this );
357 discCompleter->setModel( new QDirModel( discCompleter ) );
358 ui.deviceCombo->setCompleter( discCompleter );
362 BUTTONACT( ui.dvdRadioButton, updateButtons() );
363 BUTTONACT( ui.vcdRadioButton, updateButtons() );
364 BUTTONACT( ui.audioCDRadioButton, updateButtons() );
365 BUTTONACT( ui.dvdsimple, updateButtons() );
366 BUTTONACT( ui.browseDiscButton, browseDevice() );
367 BUTTON_SET_ACT_I( ui.ejectButton, "", toolbar/eject, qtr( "Eject the disc" ),
370 CONNECT( ui.deviceCombo, editTextChanged( QString ), this, updateMRL());
371 CONNECT( ui.titleSpin, valueChanged( int ), this, updateMRL());
372 CONNECT( ui.chapterSpin, valueChanged( int ), this, updateMRL());
373 CONNECT( ui.audioSpin, valueChanged( int ), this, updateMRL());
374 CONNECT( ui.subtitlesSpin, valueChanged( int ), this, updateMRL());
376 /* Run once the updateButtons function in order to fill correctly the comboBoxes */
380 DiscOpenPanel::~DiscOpenPanel()
382 free( psz_dvddiscpath );
383 free( psz_vcddiscpath );
384 free( psz_cddadiscpath );
387 void DiscOpenPanel::clear()
389 ui.titleSpin->setValue( 0 );
390 ui.chapterSpin->setValue( 0 );
391 ui.subtitlesSpin->setValue( -1 );
392 ui.audioSpin->setValue( -1 );
397 #define setDrive( psz_name ) {\
398 int index = ui.deviceCombo->findText( qfu( psz_name ) ); \
399 if( index != -1 ) ui.deviceCombo->setCurrentIndex( index );}
401 #define setDrive( psz_name ) {\
402 ui.deviceCombo->setEditText( qfu( psz_name ) ); }
405 /* update the buttons according the type of device */
406 void DiscOpenPanel::updateButtons()
408 if ( ui.dvdRadioButton->isChecked() )
410 if( m_discType != Dvd )
412 setDrive( psz_dvddiscpath );
415 ui.titleLabel->setText( qtr("Title") );
416 ui.chapterLabel->show();
417 ui.chapterSpin->show();
418 ui.diskOptionBox_2->show();
419 ui.dvdsimple->setEnabled( true );
421 else if ( ui.vcdRadioButton->isChecked() )
423 if( m_discType != Vcd )
425 setDrive( psz_vcddiscpath );
428 ui.titleLabel->setText( qtr("Entry") );
429 ui.chapterLabel->hide();
430 ui.chapterSpin->hide();
431 ui.diskOptionBox_2->show();
432 ui.dvdsimple->setEnabled( false );
436 if( m_discType != Cdda )
438 setDrive( psz_cddadiscpath );
441 ui.titleLabel->setText( qtr("Track") );
442 ui.chapterLabel->hide();
443 ui.chapterSpin->hide();
444 ui.diskOptionBox_2->hide();
445 ui.dvdsimple->setEnabled( false );
453 /* Update the current MRL */
454 void DiscOpenPanel::updateMRL()
457 QStringList fileList;
459 /* CDDAX and VCDX not implemented. TODO ? No. */
461 if( ui.dvdRadioButton->isChecked() ) {
462 if( !ui.dvdsimple->isChecked() )
465 mrl = "dvdsimple://";
466 mrl += ui.deviceCombo->currentText();
467 if( !ui.dvdsimple->isChecked() )
468 emit methodChanged( "dvdnav-caching" );
470 emit methodChanged( "dvdread-caching" );
472 if ( ui.titleSpin->value() > 0 ) {
473 mrl += QString("@%1").arg( ui.titleSpin->value() );
474 if ( ui.chapterSpin->value() > 0 ) {
475 mrl+= QString(":%1").arg( ui.chapterSpin->value() );
480 } else if ( ui.vcdRadioButton->isChecked() ) {
481 mrl = "vcd://" + ui.deviceCombo->currentText();
482 emit methodChanged( "vcd-caching" );
484 if( ui.titleSpin->value() > 0 ) {
485 mrl += QString("@E%1").arg( ui.titleSpin->value() );
490 mrl = "cdda://" + ui.deviceCombo->currentText();
491 emit methodChanged( "cdda-caching" );
494 fileList << mrl; mrl = "";
496 if ( ui.dvdRadioButton->isChecked() || ui.vcdRadioButton->isChecked() )
498 if ( ui.audioSpin->value() >= 0 ) {
499 mrl += " :audio-track=" +
500 QString("%1").arg( ui.audioSpin->value() );
502 if ( ui.subtitlesSpin->value() >= 0 ) {
503 mrl += " :sub-track=" +
504 QString("%1").arg( ui.subtitlesSpin->value() );
509 if( ui.titleSpin->value() > 0 )
510 mrl += QString(" :cdda-track=%1").arg( ui.titleSpin->value() );
512 emit mrlUpdated( fileList, mrl );
515 void DiscOpenPanel::browseDevice()
517 QString dir = QFileDialog::getExistingDirectory( this,
518 qtr( I_DEVICE_TOOLTIP ) );
520 ui.deviceCombo->setEditText( toNativeSepNoSlash( dir ) );
525 void DiscOpenPanel::eject()
527 intf_Eject( p_intf, qtu( ui.deviceCombo->currentText() ) );
530 void DiscOpenPanel::accept()
533 /**************************************************************************
534 * Open Network streams and URL pages *
535 **************************************************************************/
536 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
537 OpenPanel( _parent, _p_intf )
542 CONNECT( ui.urlText, textChanged( const QString& ), this, updateMRL());
544 if( var_InheritBool( p_intf, "qt-recentplay" ) )
546 mrlList = new QStringListModel(
547 getSettings()->value( "Open/netMRL" ).toStringList() );
548 QCompleter *completer = new QCompleter( mrlList, this );
549 ui.urlText->setCompleter( completer );
551 CONNECT( ui.urlText, editingFinished(), this, updateCompleter() );
556 ui.urlText->setValidator( new UrlValidator( this ) );
559 NetOpenPanel::~NetOpenPanel()
561 if( !mrlList ) return;
563 QStringList tempL = mrlList->stringList();
564 while( tempL.size() > 8 ) tempL.removeFirst();
566 getSettings()->setValue( "Open/netMRL", tempL );
571 void NetOpenPanel::clear()
574 static int strcmp_void( const void *k, const void *e )
576 return strcmp( (const char *)k, (const char *)e );
579 void NetOpenPanel::updateMRL()
581 static const struct caching_map
586 { /* KEEP alphabetical order on first column!! */
604 QString url = ui.urlText->text();
605 if( !url.contains( "://") )
606 return; /* nothing to do this far */
608 /* Match the correct item in the comboBox */
609 QString proto = url.section( ':', 0, 0 );
610 const struct caching_map *r = (const struct caching_map *)
611 bsearch( qtu(proto), schemes, sizeof(schemes) / sizeof(schemes[0]),
612 sizeof(schemes[0]), strcmp_void );
614 emit methodChanged( qfu( r->caching ) + qfu( "-caching" ) );
618 emit mrlUpdated( qsl, "" );
621 void NetOpenPanel::updateCompleter()
624 QStringList tempL = mrlList->stringList();
625 if( !tempL.contains( ui.urlText->text() ) )
626 tempL.append( ui.urlText->text() );
627 mrlList->setStringList( tempL );
630 void UrlValidator::fixup( QString& str ) const
635 QValidator::State UrlValidator::validate( QString& str, int& pos ) const
637 if( str.contains( ' ' ) )
638 return QValidator::Invalid;
639 if( !str.contains( "://" ) )
640 return QValidator::Intermediate;
641 return QValidator::Acceptable;
644 /**************************************************************************
645 * Open Capture device ( DVB, PVR, V4L, and similar ) *
646 **************************************************************************/
647 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
648 OpenPanel( _parent, _p_intf )
650 isInitialized = false;
653 void CaptureOpenPanel::initialize()
655 if( isInitialized ) return;
657 msg_Dbg( p_intf, "Initialization of Capture device panel" );
658 isInitialized = true;
662 BUTTONACT( ui.advancedButton, advancedDialog() );
664 /* Create two stacked layouts in the main comboBoxes */
665 QStackedLayout *stackedDevLayout = new QStackedLayout;
666 ui.cardBox->setLayout( stackedDevLayout );
668 QStackedLayout *stackedPropLayout = new QStackedLayout;
669 ui.optionsBox->setLayout( stackedPropLayout );
671 /* Creation and connections of the WIdgets in the stacked layout */
672 #define addModuleAndLayouts( number, name, label, layout ) \
673 QWidget * name ## DevPage = new QWidget( this ); \
674 QWidget * name ## PropPage = new QWidget( this ); \
675 stackedDevLayout->addWidget( name ## DevPage ); \
676 stackedPropLayout->addWidget( name ## PropPage ); \
677 layout * name ## DevLayout = new layout; \
678 layout * name ## PropLayout = new layout; \
679 name ## DevPage->setLayout( name ## DevLayout ); \
680 name ## PropPage->setLayout( name ## PropLayout ); \
681 ui.deviceCombo->addItem( qtr( label ), QVariant( number ) );
683 #define CuMRL( widget, slot ) CONNECT( widget , slot , this, updateMRL() );
686 /*********************
687 * DirectShow Stuffs *
688 *********************/
689 if( module_exists( "dshow" ) ){
690 addModuleAndLayouts( DSHOW_DEVICE, dshow, "DirectShow", QGridLayout );
694 module_config_t *p_config =
695 config_FindConfig( VLC_OBJECT(p_intf), "dshow-vdev" );
696 vdevDshowW = new StringListConfigControl(
697 VLC_OBJECT(p_intf), p_config, this, false, dshowDevLayout, line );
700 p_config = config_FindConfig( VLC_OBJECT(p_intf), "dshow-adev" );
701 adevDshowW = new StringListConfigControl(
702 VLC_OBJECT(p_intf), p_config, this, false, dshowDevLayout, line );
705 /* dshow Properties */
706 QLabel *dshowVSizeLabel = new QLabel( qtr( "Video size" ) );
707 dshowPropLayout->addWidget( dshowVSizeLabel, 0, 0 );
709 dshowVSizeLine = new QLineEdit;
710 dshowPropLayout->addWidget( dshowVSizeLine, 0, 1);
711 dshowPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
715 CuMRL( vdevDshowW->combo, currentIndexChanged ( int ) );
716 CuMRL( adevDshowW->combo, currentIndexChanged ( int ) );
717 CuMRL( dshowVSizeLine, textChanged( const QString& ) );
723 if( module_exists( "bda" ) ){
724 addModuleAndLayouts( BDA_DEVICE, bda, "DVB DirectShow", QGridLayout );
727 QLabel *bdaTypeLabel = new QLabel( qtr( "DVB Type:" ) );
729 bdas = new QRadioButton( "DVB-S" );
730 bdas->setChecked( true );
731 bdac = new QRadioButton( "DVB-C" );
732 bdat = new QRadioButton( "DVB-T" );
733 bdaa = new QRadioButton( "ATSC" );
734 bdaq = new QRadioButton( "Clear QAM" );
736 bdaDevLayout->addWidget( bdaTypeLabel, 0, 0 );
737 bdaDevLayout->addWidget( bdas, 0, 1 );
738 bdaDevLayout->addWidget( bdac, 0, 2 );
739 bdaDevLayout->addWidget( bdat, 0, 3 );
740 bdaDevLayout->addWidget( bdaa, 0, 4 );
741 bdaDevLayout->addWidget( bdaq, 0, 5 );
744 QLabel *bdaFreqLabel =
745 new QLabel( qtr( "Transponder/multiplex frequency" ) );
746 bdaPropLayout->addWidget( bdaFreqLabel, 0, 0 );
748 bdaFreq = new QSpinBox;
749 bdaFreq->setAlignment( Qt::AlignRight );
750 bdaFreq->setSuffix(" kHz");
751 bdaFreq->setSingleStep( 1000 );
752 setSpinBoxFreq( bdaFreq )
753 bdaPropLayout->addWidget( bdaFreq, 0, 1 );
755 bdaSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
756 bdaPropLayout->addWidget( bdaSrateLabel, 1, 0 );
758 bdaSrate = new QSpinBox;
759 bdaSrate->setAlignment( Qt::AlignRight );
760 bdaSrate->setSuffix(" kHz");
761 setSpinBoxFreq( bdaSrate );
762 bdaPropLayout->addWidget( bdaSrate, 1, 1 );
764 bdaBandLabel = new QLabel( qtr( "Bandwidth" ) );
765 bdaPropLayout->addWidget( bdaBandLabel, 2, 0 );
767 bdaBandBox = new QComboBox;
768 setfillVLCConfigCombo( "dvb-bandwidth", p_intf, bdaBandBox );
769 bdaPropLayout->addWidget( bdaBandBox, 2, 1 );
771 bdaBandLabel->hide();
773 bdaPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
777 CuMRL( bdaFreq, valueChanged ( int ) );
778 CuMRL( bdaSrate, valueChanged ( int ) );
779 CuMRL( bdaBandBox, currentIndexChanged ( int ) );
780 BUTTONACT( bdas, updateButtons() );
781 BUTTONACT( bdat, updateButtons() );
782 BUTTONACT( bdac, updateButtons() );
783 BUTTONACT( bdaa, updateButtons() );
784 BUTTONACT( bdaq, updateButtons() );
785 BUTTONACT( bdas, updateMRL() );
786 BUTTONACT( bdat, updateMRL() );
787 BUTTONACT( bdac, updateMRL() );
788 BUTTONACT( bdaa, updateMRL() );
789 BUTTONACT( bdaq, updateMRL() );
796 if( module_exists( "v4l2" ) ){
797 addModuleAndLayouts( V4L2_DEVICE, v4l2, "Video for Linux 2", QGridLayout );
800 QLabel *v4l2VideoDeviceLabel = new QLabel( qtr( "Video device name" ) );
801 v4l2DevLayout->addWidget( v4l2VideoDeviceLabel, 0, 0 );
803 v4l2VideoDevice = new QLineEdit;
804 v4l2DevLayout->addWidget( v4l2VideoDevice, 0, 1 );
806 QLabel *v4l2AudioDeviceLabel = new QLabel( qtr( "Audio device name" ) );
807 v4l2DevLayout->addWidget( v4l2AudioDeviceLabel, 1, 0 );
809 v4l2AudioDevice = new QLineEdit;
810 v4l2DevLayout->addWidget( v4l2AudioDevice, 1, 1 );
812 /* v4l2 Props panel */
813 QLabel *v4l2StdLabel = new QLabel( qtr( "Standard" ) );
814 v4l2PropLayout->addWidget( v4l2StdLabel, 0 , 0 );
816 v4l2StdBox = new QComboBox;
817 setfillVLCConfigCombo( "v4l2-standard", p_intf, v4l2StdBox );
818 v4l2PropLayout->addWidget( v4l2StdBox, 0 , 1 );
819 v4l2PropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
823 CuMRL( v4l2VideoDevice, textChanged( const QString& ) );
824 CuMRL( v4l2AudioDevice, textChanged( const QString& ) );
825 CuMRL( v4l2StdBox, currentIndexChanged ( int ) );
831 if( module_exists( "v4l" ) ){
832 addModuleAndLayouts( V4L_DEVICE, v4l, "Video for Linux", QGridLayout );
835 QLabel *v4lVideoDeviceLabel = new QLabel( qtr( "Video device name" ) );
836 v4lDevLayout->addWidget( v4lVideoDeviceLabel, 0, 0 );
838 v4lVideoDevice = new QLineEdit;
839 v4lDevLayout->addWidget( v4lVideoDevice, 0, 1 );
841 QLabel *v4lAudioDeviceLabel = new QLabel( qtr( "Audio device name" ) );
842 v4lDevLayout->addWidget( v4lAudioDeviceLabel, 1, 0 );
844 v4lAudioDevice = new QLineEdit;
845 v4lDevLayout->addWidget( v4lAudioDevice, 1, 1 );
847 /* V4l Props panel */
848 QLabel *v4lNormLabel = new QLabel( qtr( "Norm" ) );
849 v4lPropLayout->addWidget( v4lNormLabel, 0 , 0 );
851 v4lNormBox = new QComboBox;
852 setfillVLCConfigCombo( "v4l-norm", p_intf, v4lNormBox );
853 v4lPropLayout->addWidget( v4lNormBox, 0 , 1 );
855 QLabel *v4lFreqLabel = new QLabel( qtr( "Frequency" ) );
856 v4lPropLayout->addWidget( v4lFreqLabel, 1 , 0 );
858 v4lFreq = new QSpinBox;
859 v4lFreq->setAlignment( Qt::AlignRight );
860 v4lFreq->setSuffix(" kHz");
861 setSpinBoxFreq( v4lFreq );
862 v4lPropLayout->addWidget( v4lFreq, 1 , 1 );
863 v4lPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
867 CuMRL( v4lVideoDevice, textChanged( const QString& ) );
868 CuMRL( v4lAudioDevice, textChanged( const QString& ) );
869 CuMRL( v4lFreq, valueChanged ( int ) );
870 CuMRL( v4lNormBox, currentIndexChanged ( int ) );
876 if( module_exists( "jack" ) ){
877 addModuleAndLayouts( JACK_DEVICE, jack, "JACK Audio Connection Kit",
880 /* Jack Main panel */
882 QLabel *jackChannelsLabel = new QLabel( qtr( "Channels:" ) );
883 jackDevLayout->addWidget( jackChannelsLabel, 1, 0 );
885 jackChannels = new QSpinBox;
886 setSpinBoxFreq( jackChannels );
887 jackChannels->setMaximum(255);
888 jackChannels->setValue(2);
889 jackChannels->setAlignment( Qt::AlignRight );
890 jackDevLayout->addWidget( jackChannels, 1, 1 );
893 QLabel *jackPortsLabel = new QLabel( qtr( "Selected ports:" ) );
894 jackDevLayout->addWidget( jackPortsLabel, 0 , 0 );
896 jackPortsSelected = new QLineEdit( qtr( ".*") );
897 jackPortsSelected->setAlignment( Qt::AlignRight );
898 jackDevLayout->addWidget( jackPortsSelected, 0, 1 );
900 /* Jack Props panel */
903 QLabel *jackCachingLabel = new QLabel( qtr( "Input caching:" ) );
904 jackPropLayout->addWidget( jackCachingLabel, 1 , 0 );
905 jackCaching = new QSpinBox;
906 setSpinBoxFreq( jackCaching );
907 jackCaching->setSuffix( " ms" );
908 jackCaching->setValue(1000);
909 jackCaching->setAlignment( Qt::AlignRight );
910 jackPropLayout->addWidget( jackCaching, 1 , 2 );
913 jackPace = new QCheckBox(qtr( "Use VLC pace" ));
914 jackPropLayout->addWidget( jackPace, 2, 1 );
917 jackConnect = new QCheckBox( qtr( "Auto connection" ));
918 jackPropLayout->addWidget( jackConnect, 2, 2 );
921 CuMRL( jackChannels, valueChanged( int ) );
922 CuMRL( jackCaching, valueChanged( int ) );
923 CuMRL( jackPace, stateChanged( int ) );
924 CuMRL( jackConnect, stateChanged( int ) );
925 CuMRL( jackPortsSelected, textChanged( const QString& ) );
931 if( module_exists( "pvr" ) ){
932 addModuleAndLayouts( PVR_DEVICE, pvr, "PVR", QGridLayout );
935 QLabel *pvrDeviceLabel = new QLabel( qtr( "Device name" ) );
936 pvrDevLayout->addWidget( pvrDeviceLabel, 0, 0 );
938 pvrDevice = new QLineEdit;
939 pvrDevLayout->addWidget( pvrDevice, 0, 1 );
941 QLabel *pvrRadioDeviceLabel = new QLabel( qtr( "Radio device name" ) );
942 pvrDevLayout->addWidget( pvrRadioDeviceLabel, 1, 0 );
944 pvrRadioDevice = new QLineEdit;
945 pvrDevLayout->addWidget( pvrRadioDevice, 1, 1 );
947 /* PVR props panel */
948 QLabel *pvrNormLabel = new QLabel( qtr( "Norm" ) );
949 pvrPropLayout->addWidget( pvrNormLabel, 0, 0 );
951 pvrNormBox = new QComboBox;
952 setfillVLCConfigCombo( "pvr-norm", p_intf, pvrNormBox );
953 pvrPropLayout->addWidget( pvrNormBox, 0, 1 );
955 QLabel *pvrFreqLabel = new QLabel( qtr( "Frequency" ) );
956 pvrPropLayout->addWidget( pvrFreqLabel, 1, 0 );
958 pvrFreq = new QSpinBox;
959 pvrFreq->setAlignment( Qt::AlignRight );
960 pvrFreq->setSuffix(" kHz");
961 setSpinBoxFreq( pvrFreq );
962 pvrPropLayout->addWidget( pvrFreq, 1, 1 );
964 QLabel *pvrBitrLabel = new QLabel( qtr( "Bitrate" ) );
965 pvrPropLayout->addWidget( pvrBitrLabel, 2, 0 );
967 pvrBitr = new QSpinBox;
968 pvrBitr->setAlignment( Qt::AlignRight );
969 pvrBitr->setSuffix(" kHz");
970 setSpinBoxFreq( pvrBitr );
971 pvrPropLayout->addWidget( pvrBitr, 2, 1 );
972 pvrPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
976 CuMRL( pvrDevice, textChanged( const QString& ) );
977 CuMRL( pvrRadioDevice, textChanged( const QString& ) );
979 CuMRL( pvrFreq, valueChanged ( int ) );
980 CuMRL( pvrBitr, valueChanged ( int ) );
981 CuMRL( pvrNormBox, currentIndexChanged ( int ) );
987 if( module_exists( "dvb" ) ){
988 addModuleAndLayouts( DVB_DEVICE, dvb, "DVB", QGridLayout );
991 QLabel *dvbDeviceLabel = new QLabel( qtr( "Adapter card to tune" ) );
992 QLabel *dvbTypeLabel = new QLabel( qtr( "DVB Type:" ) );
994 dvbCard = new QSpinBox;
995 dvbCard->setAlignment( Qt::AlignRight );
996 dvbCard->setPrefix( "/dev/dvb/adapter" );
998 dvbDevLayout->addWidget( dvbDeviceLabel, 0, 0 );
999 dvbDevLayout->addWidget( dvbCard, 0, 2, 1, 2 );
1001 dvbs = new QRadioButton( "DVB-S" );
1002 dvbs->setChecked( true );
1003 dvbc = new QRadioButton( "DVB-C" );
1004 dvbt = new QRadioButton( "DVB-T" );
1006 dvbDevLayout->addWidget( dvbTypeLabel, 1, 0 );
1007 dvbDevLayout->addWidget( dvbs, 1, 1 );
1008 dvbDevLayout->addWidget( dvbc, 1, 2 );
1009 dvbDevLayout->addWidget( dvbt, 1, 3 );
1011 /* DVB Props panel */
1012 QLabel *dvbFreqLabel =
1013 new QLabel( qtr( "Transponder/multiplex frequency" ) );
1014 dvbPropLayout->addWidget( dvbFreqLabel, 0, 0 );
1016 dvbFreq = new QSpinBox;
1017 dvbFreq->setAlignment( Qt::AlignRight );
1018 dvbFreq->setSuffix(" kHz");
1019 dvbFreq->setSingleStep( 1000 );
1020 setSpinBoxFreq( dvbFreq );
1021 dvbPropLayout->addWidget( dvbFreq, 0, 1 );
1023 dvbSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
1024 dvbPropLayout->addWidget( dvbSrateLabel, 1, 0 );
1026 dvbSrate = new QSpinBox;
1027 dvbSrate->setAlignment( Qt::AlignRight );
1028 dvbSrate->setSuffix(" kHz");
1029 setSpinBoxFreq( dvbSrate );
1030 dvbPropLayout->addWidget( dvbSrate, 1, 1 );
1032 dvbBandLabel = new QLabel( qtr( "Bandwidth" ) );
1033 dvbPropLayout->addWidget( dvbBandLabel, 2, 0 );
1035 dvbBandBox = new QComboBox;
1036 /* This doesn't work since dvb-bandwidth doesn't seem to be a
1038 setfillVLCConfigCombo( "dvb-bandwidth", p_intf, bdaBandBox );
1040 dvbBandBox->addItem( qtr( "Auto" ), 0 );
1041 dvbBandBox->addItem( qtr( "6 MHz" ), 6 );
1042 dvbBandBox->addItem( qtr( "7 MHz" ), 7 );
1043 dvbBandBox->addItem( qtr( "8 MHz" ), 8 );
1044 dvbPropLayout->addWidget( dvbBandBox, 2, 1 );
1046 dvbBandLabel->hide();
1049 dvbPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
1053 CuMRL( dvbCard, valueChanged ( int ) );
1054 CuMRL( dvbFreq, valueChanged ( int ) );
1055 CuMRL( dvbSrate, valueChanged ( int ) );
1056 CuMRL( dvbBandBox, currentIndexChanged ( int ) );
1058 BUTTONACT( dvbs, updateButtons() );
1059 BUTTONACT( dvbt, updateButtons() );
1060 BUTTONACT( dvbc, updateButtons() );
1061 BUTTONACT( dvbs, updateMRL() );
1062 BUTTONACT( dvbt, updateMRL() );
1063 BUTTONACT( dvbc, updateMRL() );
1072 addModuleAndLayouts( SCREEN_DEVICE, screen, "Desktop", QGridLayout );
1073 QLabel *screenLabel = new QLabel( qtr( "Your display will be "
1074 "opened and played in order to stream or save it." ) );
1075 screenLabel->setWordWrap( true );
1076 screenDevLayout->addWidget( screenLabel, 0, 0 );
1078 QLabel *screenFPSLabel = new QLabel(
1079 qtr( "Desired frame rate for the capture." ) );
1080 screenPropLayout->addWidget( screenFPSLabel, 0, 0 );
1082 screenFPS = new QDoubleSpinBox;
1083 screenFPS->setValue( 1. );
1084 screenFPS->setRange( .01, 100. );
1085 screenFPS->setAlignment( Qt::AlignRight );
1086 /* xgettext: frames per second */
1087 screenFPS->setSuffix( qtr( " f/s" ) );
1088 screenPropLayout->addWidget( screenFPS, 0, 1 );
1090 /* Screen connect */
1091 CuMRL( screenFPS, valueChanged( double ) );
1093 /* General connects */
1094 CONNECT( ui.deviceCombo, activated( int ) ,
1095 stackedDevLayout, setCurrentIndex( int ) );
1096 CONNECT( ui.deviceCombo, activated( int ),
1097 stackedPropLayout, setCurrentIndex( int ) );
1098 CONNECT( ui.deviceCombo, activated( int ), this, updateMRL() );
1099 CONNECT( ui.deviceCombo, activated( int ), this, updateButtons() );
1102 #undef addModuleAndLayouts
1105 CaptureOpenPanel::~CaptureOpenPanel()
1109 void CaptureOpenPanel::clear()
1114 void CaptureOpenPanel::updateMRL()
1117 QStringList fileList;
1118 int i_devicetype = ui.deviceCombo->itemData(
1119 ui.deviceCombo->currentIndex() ).toInt();
1120 switch( i_devicetype )
1124 if( bdas->isChecked() ) mrl = "dvb-s://";
1125 else if( bdat->isChecked() ) mrl = "dvb-t://";
1126 else if( bdac->isChecked() ) mrl = "dvb-c://";
1127 else if( bdaa->isChecked() ) mrl = "atsc://";
1128 else if( bdaq->isChecked() ) mrl = "cqam://";
1130 mrl += "frequency=" + QString::number( bdaFreq->value() );
1131 if( bdac->isChecked() || bdat->isChecked() || bdaa->isChecked() )
1133 fileList << mrl; mrl = "";
1135 if( bdas->isChecked() || bdac->isChecked() )
1136 mrl += " :dvb-srate=" + QString::number( bdaSrate->value() );
1137 else if( bdat->isChecked() || bdaa->isChecked() )
1138 mrl += " :dvb-bandwidth=" +
1139 QString::number( bdaBandBox->itemData(
1140 bdaBandBox->currentIndex() ).toInt() );
1141 emit methodChanged( "dvb-caching" );
1144 fileList << "dshow://";
1145 mrl+= " :dshow-vdev=" +
1146 colon_escape( QString("%1").arg( vdevDshowW->getValue() ) );
1147 mrl+= " :dshow-adev=" +
1148 colon_escape( QString("%1").arg( adevDshowW->getValue() ) )+" ";
1149 if( dshowVSizeLine->isModified() )
1150 mrl += ":dshow-size=" + dshowVSizeLine->text();
1151 emit methodChanged( "dshow-caching" );
1155 fileList << "v4l://" + v4lVideoDevice->text();
1156 mrl += " :input-slave=alsa://" + v4lAudioDevice->text();
1157 mrl += " :v4l-norm=" + QString::number( v4lNormBox->currentIndex() );
1158 mrl += " :v4l-frequency=" + QString::number( v4lFreq->value() );
1161 fileList << "v4l2://" + v4l2VideoDevice->text();
1162 mrl += " :input-slave=alsa://" + v4l2AudioDevice->text();
1163 mrl += " :v4l2-standard=" + QString::number( v4l2StdBox->currentIndex() );
1167 mrl += "channels=" + QString::number( jackChannels->value() );
1168 mrl += ":ports=" + jackPortsSelected->text();
1169 fileList << mrl; mrl = "";
1171 mrl += " :jack-input-caching=" + QString::number( jackCaching->value() );
1172 if ( jackPace->isChecked() )
1174 mrl += " :jack-input-use-vlc-pace";
1176 if ( jackConnect->isChecked() )
1178 mrl += " :jack-input-auto-connect";
1182 fileList << "pvr://";
1183 mrl += " :pvr-device=" + pvrDevice->text();
1184 mrl += " :pvr-radio-device=" + pvrRadioDevice->text();
1185 mrl += " :pvr-norm=" + QString::number( pvrNormBox->currentIndex() );
1186 if( pvrFreq->value() )
1187 mrl += " :pvr-frequency=" + QString::number( pvrFreq->value() );
1188 if( pvrBitr->value() )
1189 mrl += " :pvr-bitrate=" + QString::number( pvrBitr->value() );
1193 mrl += "frequency=" + QString::number( dvbFreq->value() );
1194 if( dvbc->isChecked() || dvbt->isChecked() )
1196 fileList << mrl; mrl= "";
1198 mrl += " :dvb-adapter=" + QString::number( dvbCard->value() );
1199 if( dvbs->isChecked() || dvbc->isChecked() )
1200 mrl += " :dvb-srate=" + QString::number( dvbSrate->value() );
1201 else if( dvbt->isChecked() )
1202 mrl += " :dvb-bandwidth=" +
1203 QString::number( dvbBandBox->itemData(
1204 dvbBandBox->currentIndex() ).toInt() );
1209 fileList << "screen://";
1210 mrl = " :screen-fps=" + QString::number( screenFPS->value(), 'f' );
1211 emit methodChanged( "screen-caching" );
1216 if( !advMRL.isEmpty() ) mrl += advMRL;
1218 emit mrlUpdated( fileList, mrl );
1222 * Update the Buttons (show/hide) for the GUI as all device type don't
1223 * use the same ui. elements.
1225 void CaptureOpenPanel::updateButtons()
1227 /* Be sure to display the ui Elements in case they were hidden by
1228 * some Device Type (like Screen://) */
1229 ui.optionsBox->show();
1230 ui.advancedButton->show();
1231 /* Get the current Device Number */
1232 int i_devicetype = ui.deviceCombo->itemData(
1233 ui.deviceCombo->currentIndex() ).toInt();
1234 switch( i_devicetype )
1238 if( bdas->isChecked() || bdac->isChecked() )
1241 bdaSrateLabel->show();
1243 bdaBandLabel->hide();
1245 else if( bdat->isChecked() || bdaa->isChecked() )
1248 bdaSrateLabel->hide();
1250 bdaBandLabel->show();
1252 else if( bdaq->isChecked() )
1255 bdaSrateLabel->hide();
1257 bdaBandLabel->hide();
1262 if( dvbs->isChecked() || dvbc->isChecked() )
1265 dvbSrateLabel->show();
1267 dvbBandLabel->hide();
1269 else if( dvbt->isChecked() )
1272 dvbSrateLabel->hide();
1274 dvbBandLabel->show();
1279 //ui.optionsBox->hide();
1280 ui.advancedButton->hide();
1287 void CaptureOpenPanel::advancedDialog()
1289 /* Get selected device type */
1290 int i_devicetype = ui.deviceCombo->itemData(
1291 ui.deviceCombo->currentIndex() ).toInt();
1293 /* Get the corresponding module */
1294 module_t *p_module =
1295 module_find( psz_devModule[i_devicetype] );
1296 if( NULL == p_module ) return;
1299 QList<ConfigControl *> controls;
1301 /* Get the confsize */
1302 unsigned int i_confsize;
1303 module_config_t *p_config;
1304 p_config = module_config_get( p_module, &i_confsize );
1306 /* New Adv Prop dialog */
1307 adv = new QDialog( this );
1308 adv->setWindowTitle( qtr( "Advanced Options" ) );
1309 adv->setWindowRole( "vlc-advanced-options" );
1311 /* A main Layout with a Frame */
1312 QVBoxLayout *mainLayout = new QVBoxLayout( adv );
1313 QScrollArea *scroll = new QScrollArea;
1314 mainLayout->addWidget( scroll );
1316 QFrame *advFrame = new QFrame;
1317 /* GridLayout inside the Frame */
1318 QGridLayout *gLayout = new QGridLayout( advFrame );
1320 scroll->setWidgetResizable( true );
1321 scroll->setWidget( advFrame );
1323 /* Create the options inside the FrameLayout */
1324 for( int n = 0; n < (int)i_confsize; n++ )
1326 module_config_t *p_item = p_config + n;
1327 ConfigControl *config = ConfigControl::createControl(
1328 VLC_OBJECT( p_intf ), p_item, advFrame, gLayout, n );
1330 controls.append( config );
1334 QDialogButtonBox *advButtonBox = new QDialogButtonBox( adv );
1335 QPushButton *closeButton = new QPushButton( qtr( "OK" ) );
1336 QPushButton *cancelButton = new QPushButton( qtr( "Cancel" ) );
1338 CONNECT( closeButton, clicked(), adv, accept() );
1339 CONNECT( cancelButton, clicked(), adv, reject() );
1341 advButtonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
1342 advButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
1344 mainLayout->addWidget( advButtonBox );
1346 /* Creation of the MRL */
1349 QString tempMRL = "";
1350 for( int i = 0; i < controls.size(); i++ )
1352 ConfigControl *control = controls[i];
1354 tempMRL += (i ? " :" : ":");
1356 if( control->getType() == CONFIG_ITEM_BOOL )
1357 if( !(qobject_cast<VIntConfigControl *>(control)->getValue() ) )
1360 tempMRL += control->getName();
1362 switch( control->getType() )
1364 case CONFIG_ITEM_STRING:
1365 case CONFIG_ITEM_FILE:
1366 case CONFIG_ITEM_DIRECTORY:
1367 case CONFIG_ITEM_MODULE:
1368 tempMRL += colon_escape( QString("=%1").arg( qobject_cast<VStringConfigControl *>(control)->getValue() ) );
1370 case CONFIG_ITEM_INTEGER:
1371 tempMRL += QString("=%1").arg( qobject_cast<VIntConfigControl *>(control)->getValue() );
1373 case CONFIG_ITEM_FLOAT:
1374 tempMRL += QString("=%1").arg( qobject_cast<VFloatConfigControl *>(control)->getValue() );
1380 msg_Dbg( p_intf, "%s", qtu( advMRL ) );
1382 for( int i = 0; i < controls.size(); i++ )
1384 ConfigControl *control = controls[i];
1388 module_config_free( p_config );
1389 module_release (p_module);