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>
40 #include <QFileDialog>
41 #include <QDialogButtonBox>
43 #include <QStackedLayout>
47 #include <QScrollArea>
49 #include <QStringListModel>
53 #define I_DEVICE_TOOLTIP \
54 I_DIR_OR_FOLDER( N_("Select a device or a VIDEO_TS directory"), \
55 N_("Select a device or a VIDEO_TS folder") )
57 static const char *psz_devModule[] = { "v4l", "v4l2", "pvr", "dvb", "bda",
58 "dshow", "screen", "jack" };
60 /**************************************************************************
61 * Open Files and subtitles *
62 **************************************************************************/
63 FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
64 OpenPanel( _parent, _p_intf ), dialogBox( NULL )
66 /* Classic UI Setup */
69 setAcceptDrops( true );
71 /* Set Filters for file selection */
72 /* QString fileTypes = "";
73 ADD_FILTER_MEDIA( fileTypes );
74 ADD_FILTER_VIDEO( fileTypes );
75 ADD_FILTER_AUDIO( fileTypes );
76 ADD_FILTER_PLAYLIST( fileTypes );
77 ADD_FILTER_ALL( fileTypes );
78 fileTypes.replace( QString(";*"), QString(" *")); */
81 /* lineFileEdit = ui.fileEdit;
82 //TODO later: fill the fileCompleteList with previous items played.
83 QCompleter *fileCompleter = new QCompleter( fileCompleteList, this );
84 fileCompleter->setModel( new QDirModel( fileCompleter ) );
85 lineFileEdit->setCompleter( fileCompleter );*/
86 if( var_InheritBool( p_intf, "qt-embedded-open" ) )
88 ui.tempWidget->hide();
93 /* Deactivate the subtitles control by default. */
94 ui.subFrame->setEnabled( false );
95 /* Build the subs size combo box */
96 setfillVLCConfigCombo( "freetype-rel-fontsize" , p_intf,
98 /* Build the subs align combo box */
99 setfillVLCConfigCombo( "subsdec-align", p_intf, ui.alignSubComboBox );
102 BUTTONACT( ui.fileBrowseButton, browseFile() );
103 BUTTONACT( ui.removeFileButton, removeFile() );
105 BUTTONACT( ui.subBrowseButton, browseFileSub() );
106 CONNECT( ui.subCheckBox, toggled( bool ), this, toggleSubtitleFrame( bool ) );
108 CONNECT( ui.fileListWidg, itemChanged( QListWidgetItem * ), this, updateMRL() );
109 CONNECT( ui.subInput, textChanged( const QString& ), this, updateMRL() );
110 CONNECT( ui.alignSubComboBox, currentIndexChanged( int ), this, updateMRL() );
111 CONNECT( ui.sizeSubComboBox, currentIndexChanged( int ), this, updateMRL() );
115 inline void FileOpenPanel::BuildOldPanel()
117 /** BEGIN QFileDialog tweaking **/
118 /* Use a QFileDialog and customize it because we don't want to
119 rewrite it all. Be careful to your eyes cause there are a few hacks.
120 Be very careful and test correctly when you modify this. */
122 /* Make this QFileDialog a child of tempWidget from the ui. */
123 dialogBox = new FileOpenBox( ui.tempWidget, NULL,
124 p_intf->p_sys->filepath, "" );
126 dialogBox->setFileMode( QFileDialog::ExistingFiles );
127 dialogBox->setAcceptMode( QFileDialog::AcceptOpen );
128 dialogBox->restoreState(
129 getSettings()->value( "file-dialog-state" ).toByteArray() );
131 /* We don't want to see a grip in the middle of the window, do we? */
132 dialogBox->setSizeGripEnabled( false );
135 dialogBox->setToolTip( qtr( "Select one or multiple files" ) );
136 dialogBox->setMinimumHeight( 250 );
138 // But hide the two OK/Cancel buttons. Enable them for debug.
139 QDialogButtonBox *fileDialogAcceptBox =
140 dialogBox->findChildren<QDialogButtonBox*>()[0];
141 fileDialogAcceptBox->hide();
143 /* Ugly hacks to get the good Widget */
144 //This lineEdit is the normal line in the fileDialog.
145 QLineEdit *lineFileEdit = dialogBox->findChildren<QLineEdit*>()[0];
146 /* Make a list of QLabel inside the QFileDialog to access the good ones */
147 QList<QLabel *> listLabel = dialogBox->findChildren<QLabel*>();
149 /* Hide the FileNames one. Enable it for debug */
150 listLabel[1]->setText( qtr( "File names:" ) );
151 /* Change the text that was uncool in the usual box */
152 listLabel[2]->setText( qtr( "Filter:" ) );
154 dialogBox->layout()->setMargin( 0 );
155 dialogBox->layout()->setSizeConstraint( QLayout::SetNoConstraint );
157 /** END of QFileDialog tweaking **/
159 // Add the DialogBox to the layout
160 ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
162 CONNECT( lineFileEdit, textChanged( const QString& ), this, updateMRL() );
163 dialogBox->installEventFilter( this );
166 FileOpenPanel::~FileOpenPanel()
169 getSettings()->setValue( "file-dialog-state", dialogBox->saveState() );
172 void FileOpenPanel::dragEnterEvent( QDragEnterEvent *event )
174 event->acceptProposedAction();
177 void FileOpenPanel::dragMoveEvent( QDragMoveEvent *event )
179 event->acceptProposedAction();
182 void FileOpenPanel::dragLeaveEvent( QDragLeaveEvent *event )
187 void FileOpenPanel::dropEvent( QDropEvent *event )
189 if( event->possibleActions() & Qt::CopyAction )
190 event->setDropAction( Qt::CopyAction );
194 const QMimeData *mimeData = event->mimeData();
195 foreach( const QUrl &url, mimeData->urls() )
199 QListWidgetItem *item = new QListWidgetItem(
200 toNativeSeparators( url.toLocalFile() ),
202 item->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled );
203 ui.fileListWidg->addItem( item );
211 void FileOpenPanel::browseFile()
213 QStringList files = QFileDialog::getOpenFileNames( this, qtr( "Select one or multiple files" ), p_intf->p_sys->filepath) ;
214 foreach( const QString &file, files )
216 QListWidgetItem *item =
217 new QListWidgetItem( toNativeSeparators( file ), ui.fileListWidg );
218 item->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled );
219 ui.fileListWidg->addItem( item );
220 savedirpathFromFile( file );
226 void FileOpenPanel::removeFile()
228 int i = ui.fileListWidg->currentRow();
231 QListWidgetItem *temp = ui.fileListWidg->takeItem( i );
239 /* Show a fileBrowser to select a subtitle */
240 void FileOpenPanel::browseFileSub()
242 // TODO Handle selection of more than one subtitles file
243 QStringList files = THEDP->showSimpleOpen( qtr("Open subtitles file"),
244 EXT_FILTER_SUBTITLE, p_intf->p_sys->filepath );
246 if( files.isEmpty() ) return;
247 ui.subInput->setText( toNativeSeparators( files.join(" ") ) );
251 void FileOpenPanel::toggleSubtitleFrame( bool b )
253 ui.subFrame->setEnabled( b );
260 /* Update the current MRL */
261 void FileOpenPanel::updateMRL()
263 QStringList fileList;
267 if( dialogBox == NULL )
268 for( int i = 0; i < ui.fileListWidg->count(); i++ )
270 if( !ui.fileListWidg->item( i )->text().isEmpty() )
271 fileList << ui.fileListWidg->item( i )->text();
275 fileList = dialogBox->selectedFiles();
276 for( int i = 0; i < fileList.count(); i++ )
277 fileList[i] = toNativeSeparators( fileList[i] );
281 if( ui.subCheckBox->isChecked() && !ui.subInput->text().isEmpty() ) {
282 mrl.append( " :sub-file=" + colon_escape( ui.subInput->text() ) );
283 int align = ui.alignSubComboBox->itemData(
284 ui.alignSubComboBox->currentIndex() ).toInt();
285 mrl.append( " :subsdec-align=" + QString().setNum( align ) );
286 int size = ui.sizeSubComboBox->itemData(
287 ui.sizeSubComboBox->currentIndex() ).toInt();
288 mrl.append( " :freetype-rel-fontsize=" + QString().setNum( size ) );
291 emit mrlUpdated( fileList, mrl );
292 emit methodChanged( "file-caching" );
295 /* Function called by Open Dialog when clicke on Play/Enqueue */
296 void FileOpenPanel::accept()
299 p_intf->p_sys->filepath = dialogBox->directory().absolutePath();
300 ui.fileListWidg->clear();
303 /* Function called by Open Dialog when clicked on cancel */
304 void FileOpenPanel::clear()
306 ui.fileListWidg->clear();
307 ui.subInput->clear();
310 /* Update buttons depending on current selection */
311 void FileOpenPanel::updateButtons()
313 bool b_has_files = ( ui.fileListWidg->count() > 0 );
314 ui.removeFileButton->setEnabled( b_has_files );
315 ui.subCheckBox->setEnabled( b_has_files );
318 /**************************************************************************
319 * Open Discs ( DVD, CD, VCD and similar devices ) *
320 **************************************************************************/
321 DiscOpenPanel::DiscOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
322 OpenPanel( _parent, _p_intf )
326 /* Get the default configuration path for the devices */
327 psz_dvddiscpath = var_InheritString( p_intf, "dvd" );
328 psz_vcddiscpath = var_InheritString( p_intf, "vcd" );
329 psz_cddadiscpath = var_InheritString( p_intf, "cd-audio" );
331 /* State to avoid overwritting the users changes with the configuration */
336 ui.browseDiscButton->setToolTip( qtr( I_DEVICE_TOOLTIP ));
337 ui.deviceCombo->setToolTip( qtr(I_DEVICE_TOOLTIP) );
339 #ifdef WIN32 /* Disc drives probing for Windows */
342 if( GetLogicalDriveStringsA( sizeof( szDrives ) - 1, szDrives ) )
344 char *drive = szDrives;
345 UINT oldMode = SetErrorMode( SEM_FAILCRITICALERRORS );
348 if( GetDriveTypeA(drive) == DRIVE_CDROM )
349 ui.deviceCombo->addItem( drive );
351 /* go to next drive */
354 SetErrorMode(oldMode);
356 #else /* Use a Completer under Linux */
357 QCompleter *discCompleter = new QCompleter( this );
358 discCompleter->setModel( new QDirModel( discCompleter ) );
359 ui.deviceCombo->setCompleter( discCompleter );
363 BUTTONACT( ui.dvdRadioButton, updateButtons() );
364 BUTTONACT( ui.vcdRadioButton, updateButtons() );
365 BUTTONACT( ui.audioCDRadioButton, updateButtons() );
366 BUTTONACT( ui.dvdsimple, updateButtons() );
367 BUTTONACT( ui.browseDiscButton, browseDevice() );
368 BUTTON_SET_ACT_I( ui.ejectButton, "", toolbar/eject, qtr( "Eject the disc" ),
371 CONNECT( ui.deviceCombo, editTextChanged( QString ), this, updateMRL());
372 CONNECT( ui.titleSpin, valueChanged( int ), this, updateMRL());
373 CONNECT( ui.chapterSpin, valueChanged( int ), this, updateMRL());
374 CONNECT( ui.audioSpin, valueChanged( int ), this, updateMRL());
375 CONNECT( ui.subtitlesSpin, valueChanged( int ), this, updateMRL());
377 /* Run once the updateButtons function in order to fill correctly the comboBoxes */
381 DiscOpenPanel::~DiscOpenPanel()
383 free( psz_dvddiscpath );
384 free( psz_vcddiscpath );
385 free( psz_cddadiscpath );
388 void DiscOpenPanel::clear()
390 ui.titleSpin->setValue( 0 );
391 ui.chapterSpin->setValue( 0 );
392 ui.subtitlesSpin->setValue( -1 );
393 ui.audioSpin->setValue( -1 );
400 #define setDrive( psz_name ) {\
401 int index = ui.deviceCombo->findText( qfu( psz_name ) ); \
402 if( index != -1 ) ui.deviceCombo->setCurrentIndex( index );}
404 #define setDrive( psz_name ) {\
405 ui.deviceCombo->setEditText( qfu( psz_name ) ); }
408 /* update the buttons according the type of device */
409 void DiscOpenPanel::updateButtons()
411 if ( ui.dvdRadioButton->isChecked() )
415 setDrive( psz_dvddiscpath );
418 ui.titleLabel->setText( qtr("Title") );
419 ui.chapterLabel->show();
420 ui.chapterSpin->show();
421 ui.diskOptionBox_2->show();
422 ui.dvdsimple->setEnabled( true );
424 else if ( ui.vcdRadioButton->isChecked() )
428 setDrive( psz_vcddiscpath );
431 ui.titleLabel->setText( qtr("Entry") );
432 ui.chapterLabel->hide();
433 ui.chapterSpin->hide();
434 ui.diskOptionBox_2->show();
435 ui.dvdsimple->setEnabled( false );
441 setDrive( psz_cddadiscpath );
444 ui.titleLabel->setText( qtr("Track") );
445 ui.chapterLabel->hide();
446 ui.chapterSpin->hide();
447 ui.diskOptionBox_2->hide();
448 ui.dvdsimple->setEnabled( false );
456 /* Update the current MRL */
457 void DiscOpenPanel::updateMRL()
460 QStringList fileList;
462 /* CDDAX and VCDX not implemented. TODO ? No. */
464 if( ui.dvdRadioButton->isChecked() ) {
465 if( !ui.dvdsimple->isChecked() )
468 mrl = "dvdsimple://";
469 mrl += ui.deviceCombo->currentText();
470 if( !ui.dvdsimple->isChecked() )
471 emit methodChanged( "dvdnav-caching" );
473 emit methodChanged( "dvdread-caching" );
475 if ( ui.titleSpin->value() > 0 ) {
476 mrl += QString("@%1").arg( ui.titleSpin->value() );
477 if ( ui.chapterSpin->value() > 0 ) {
478 mrl+= QString(":%1").arg( ui.chapterSpin->value() );
483 } else if ( ui.vcdRadioButton->isChecked() ) {
484 mrl = "vcd://" + ui.deviceCombo->currentText();
485 emit methodChanged( "vcd-caching" );
487 if( ui.titleSpin->value() > 0 ) {
488 mrl += QString("@E%1").arg( ui.titleSpin->value() );
493 mrl = "cdda://" + ui.deviceCombo->currentText();
494 emit methodChanged( "cdda-caching" );
497 fileList << mrl; mrl = "";
499 if ( ui.dvdRadioButton->isChecked() || ui.vcdRadioButton->isChecked() )
501 if ( ui.audioSpin->value() >= 0 ) {
502 mrl += " :audio-track=" +
503 QString("%1").arg( ui.audioSpin->value() );
505 if ( ui.subtitlesSpin->value() >= 0 ) {
506 mrl += " :sub-track=" +
507 QString("%1").arg( ui.subtitlesSpin->value() );
512 if( ui.titleSpin->value() > 0 )
513 mrl += QString(" :cdda-track=%1").arg( ui.titleSpin->value() );
515 emit mrlUpdated( fileList, mrl );
518 void DiscOpenPanel::browseDevice()
520 QString dir = QFileDialog::getExistingDirectory( this,
521 qtr( I_DEVICE_TOOLTIP ) );
523 ui.deviceCombo->setEditText( toNativeSepNoSlash( dir ) );
528 void DiscOpenPanel::eject()
530 intf_Eject( p_intf, qtu( ui.deviceCombo->currentText() ) );
533 void DiscOpenPanel::accept()
536 /**************************************************************************
537 * Open Network streams and URL pages *
538 **************************************************************************/
539 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
540 OpenPanel( _parent, _p_intf )
545 CONNECT( ui.urlText, textChanged( const QString& ), this, updateMRL());
547 if( var_InheritBool( p_intf, "qt-recentplay" ) )
549 mrlList = new QStringListModel(
550 getSettings()->value( "Open/netMRL" ).toStringList() );
551 QCompleter *completer = new QCompleter( mrlList, this );
552 ui.urlText->setCompleter( completer );
554 CONNECT( ui.urlText, editingFinished(), this, updateCompleter() );
559 ui.urlText->setValidator( new UrlValidator( this ) );
562 NetOpenPanel::~NetOpenPanel()
564 if( !mrlList ) return;
566 QStringList tempL = mrlList->stringList();
567 while( tempL.size() > 8 ) tempL.removeFirst();
569 getSettings()->setValue( "Open/netMRL", tempL );
574 void NetOpenPanel::clear()
577 static int strcmp_void( const void *k, const void *e )
579 return strcmp( (const char *)k, (const char *)e );
582 void NetOpenPanel::updateMRL()
584 static const struct caching_map
589 { /* KEEP alphabetical order on first column!! */
607 QString url = ui.urlText->text();
608 if( !url.contains( "://") )
609 return; /* nothing to do this far */
611 /* Match the correct item in the comboBox */
612 QString proto = url.section( ':', 0, 0 );
613 const struct caching_map *r = (const struct caching_map *)
614 bsearch( qtu(proto), schemes, sizeof(schemes) / sizeof(schemes[0]),
615 sizeof(schemes[0]), strcmp_void );
617 emit methodChanged( qfu( r->caching ) + qfu( "-caching" ) );
621 emit mrlUpdated( qsl, "" );
624 void NetOpenPanel::updateCompleter()
627 QStringList tempL = mrlList->stringList();
628 if( !tempL.contains( ui.urlText->text() ) )
629 tempL.append( ui.urlText->text() );
630 mrlList->setStringList( tempL );
633 void UrlValidator::fixup( QString& str ) const
638 QValidator::State UrlValidator::validate( QString& str, int& pos ) const
640 if( str.contains( ' ' ) )
641 return QValidator::Invalid;
642 if( !str.contains( "://" ) )
643 return QValidator::Intermediate;
644 return QValidator::Acceptable;
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, false, 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, false, 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( "bda" ) ){
727 addModuleAndLayouts( BDA_DEVICE, bda, "DVB DirectShow", QGridLayout );
730 QLabel *bdaTypeLabel = new QLabel( qtr( "DVB Type:" ) );
732 bdas = new QRadioButton( "DVB-S" );
733 bdas->setChecked( true );
734 bdac = new QRadioButton( "DVB-C" );
735 bdat = new QRadioButton( "DVB-T" );
736 bdaa = new QRadioButton( "ATSC" );
738 bdaDevLayout->addWidget( bdaTypeLabel, 0, 0 );
739 bdaDevLayout->addWidget( bdas, 0, 1 );
740 bdaDevLayout->addWidget( bdac, 0, 2 );
741 bdaDevLayout->addWidget( bdat, 0, 3 );
742 bdaDevLayout->addWidget( bdaa, 0, 4 );
745 QLabel *bdaFreqLabel =
746 new QLabel( qtr( "Transponder/multiplex frequency" ) );
747 bdaPropLayout->addWidget( bdaFreqLabel, 0, 0 );
749 bdaFreq = new QSpinBox;
750 bdaFreq->setAlignment( Qt::AlignRight );
751 bdaFreq->setSuffix(" kHz");
752 bdaFreq->setSingleStep( 1000 );
753 setSpinBoxFreq( bdaFreq )
754 bdaPropLayout->addWidget( bdaFreq, 0, 1 );
756 bdaSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
757 bdaPropLayout->addWidget( bdaSrateLabel, 1, 0 );
759 bdaSrate = new QSpinBox;
760 bdaSrate->setAlignment( Qt::AlignRight );
761 bdaSrate->setSuffix(" kHz");
762 setSpinBoxFreq( bdaSrate );
763 bdaPropLayout->addWidget( bdaSrate, 1, 1 );
765 bdaBandLabel = new QLabel( qtr( "Bandwidth" ) );
766 bdaPropLayout->addWidget( bdaBandLabel, 2, 0 );
768 bdaBandBox = new QComboBox;
769 setfillVLCConfigCombo( "dvb-bandwidth", p_intf, bdaBandBox );
770 bdaPropLayout->addWidget( bdaBandBox, 2, 1 );
772 bdaBandLabel->hide();
774 bdaPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
778 CuMRL( bdaFreq, valueChanged ( int ) );
779 CuMRL( bdaSrate, valueChanged ( int ) );
780 CuMRL( bdaBandBox, currentIndexChanged ( int ) );
781 BUTTONACT( bdas, updateButtons() );
782 BUTTONACT( bdat, updateButtons() );
783 BUTTONACT( bdac, updateButtons() );
784 BUTTONACT( bdaa, updateButtons() );
785 BUTTONACT( bdas, updateMRL() );
786 BUTTONACT( bdat, updateMRL() );
787 BUTTONACT( bdac, updateMRL() );
788 BUTTONACT( bdaa, updateMRL() );
795 if( module_exists( "v4l2" ) ){
796 addModuleAndLayouts( V4L2_DEVICE, v4l2, "Video for Linux 2", QGridLayout );
799 QLabel *v4l2VideoDeviceLabel = new QLabel( qtr( "Video device name" ) );
800 v4l2DevLayout->addWidget( v4l2VideoDeviceLabel, 0, 0 );
802 v4l2VideoDevice = new QLineEdit;
803 v4l2DevLayout->addWidget( v4l2VideoDevice, 0, 1 );
805 QLabel *v4l2AudioDeviceLabel = new QLabel( qtr( "Audio device name" ) );
806 v4l2DevLayout->addWidget( v4l2AudioDeviceLabel, 1, 0 );
808 v4l2AudioDevice = new QLineEdit;
809 v4l2DevLayout->addWidget( v4l2AudioDevice, 1, 1 );
811 /* v4l2 Props panel */
812 QLabel *v4l2StdLabel = new QLabel( qtr( "Standard" ) );
813 v4l2PropLayout->addWidget( v4l2StdLabel, 0 , 0 );
815 v4l2StdBox = new QComboBox;
816 setfillVLCConfigCombo( "v4l2-standard", p_intf, v4l2StdBox );
817 v4l2PropLayout->addWidget( v4l2StdBox, 0 , 1 );
818 v4l2PropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
822 CuMRL( v4l2VideoDevice, textChanged( const QString& ) );
823 CuMRL( v4l2AudioDevice, textChanged( const QString& ) );
824 CuMRL( v4l2StdBox, currentIndexChanged ( int ) );
830 if( module_exists( "v4l" ) ){
831 addModuleAndLayouts( V4L_DEVICE, v4l, "Video for Linux", QGridLayout );
834 QLabel *v4lVideoDeviceLabel = new QLabel( qtr( "Video device name" ) );
835 v4lDevLayout->addWidget( v4lVideoDeviceLabel, 0, 0 );
837 v4lVideoDevice = new QLineEdit;
838 v4lDevLayout->addWidget( v4lVideoDevice, 0, 1 );
840 QLabel *v4lAudioDeviceLabel = new QLabel( qtr( "Audio device name" ) );
841 v4lDevLayout->addWidget( v4lAudioDeviceLabel, 1, 0 );
843 v4lAudioDevice = new QLineEdit;
844 v4lDevLayout->addWidget( v4lAudioDevice, 1, 1 );
846 /* V4l Props panel */
847 QLabel *v4lNormLabel = new QLabel( qtr( "Norm" ) );
848 v4lPropLayout->addWidget( v4lNormLabel, 0 , 0 );
850 v4lNormBox = new QComboBox;
851 setfillVLCConfigCombo( "v4l-norm", p_intf, v4lNormBox );
852 v4lPropLayout->addWidget( v4lNormBox, 0 , 1 );
854 QLabel *v4lFreqLabel = new QLabel( qtr( "Frequency" ) );
855 v4lPropLayout->addWidget( v4lFreqLabel, 1 , 0 );
857 v4lFreq = new QSpinBox;
858 v4lFreq->setAlignment( Qt::AlignRight );
859 v4lFreq->setSuffix(" kHz");
860 setSpinBoxFreq( v4lFreq );
861 v4lPropLayout->addWidget( v4lFreq, 1 , 1 );
862 v4lPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
866 CuMRL( v4lVideoDevice, textChanged( const QString& ) );
867 CuMRL( v4lAudioDevice, textChanged( const QString& ) );
868 CuMRL( v4lFreq, valueChanged ( int ) );
869 CuMRL( v4lNormBox, currentIndexChanged ( int ) );
875 if( module_exists( "jack" ) ){
876 addModuleAndLayouts( JACK_DEVICE, jack, "JACK Audio Connection Kit",
879 /* Jack Main panel */
881 QLabel *jackChannelsLabel = new QLabel( qtr( "Channels:" ) );
882 jackDevLayout->addWidget( jackChannelsLabel, 1, 0 );
884 jackChannels = new QSpinBox;
885 setSpinBoxFreq( jackChannels );
886 jackChannels->setMaximum(255);
887 jackChannels->setValue(2);
888 jackChannels->setAlignment( Qt::AlignRight );
889 jackDevLayout->addWidget( jackChannels, 1, 1 );
892 QLabel *jackPortsLabel = new QLabel( qtr( "Selected ports:" ) );
893 jackDevLayout->addWidget( jackPortsLabel, 0 , 0 );
895 jackPortsSelected = new QLineEdit( qtr( ".*") );
896 jackPortsSelected->setAlignment( Qt::AlignRight );
897 jackDevLayout->addWidget( jackPortsSelected, 0, 1 );
899 /* Jack Props panel */
902 QLabel *jackCachingLabel = new QLabel( qtr( "Input caching:" ) );
903 jackPropLayout->addWidget( jackCachingLabel, 1 , 0 );
904 jackCaching = new QSpinBox;
905 setSpinBoxFreq( jackCaching );
906 jackCaching->setSuffix( " ms" );
907 jackCaching->setValue(1000);
908 jackCaching->setAlignment( Qt::AlignRight );
909 jackPropLayout->addWidget( jackCaching, 1 , 2 );
912 jackPace = new QCheckBox(qtr( "Use VLC pace" ));
913 jackPropLayout->addWidget( jackPace, 2, 1 );
916 jackConnect = new QCheckBox( qtr( "Auto connection" ));
917 jackPropLayout->addWidget( jackConnect, 2, 2 );
920 CuMRL( jackChannels, valueChanged( int ) );
921 CuMRL( jackCaching, valueChanged( int ) );
922 CuMRL( jackPace, stateChanged( int ) );
923 CuMRL( jackConnect, stateChanged( int ) );
924 CuMRL( jackPortsSelected, textChanged( const QString& ) );
930 if( module_exists( "pvr" ) ){
931 addModuleAndLayouts( PVR_DEVICE, pvr, "PVR", QGridLayout );
934 QLabel *pvrDeviceLabel = new QLabel( qtr( "Device name" ) );
935 pvrDevLayout->addWidget( pvrDeviceLabel, 0, 0 );
937 pvrDevice = new QLineEdit;
938 pvrDevLayout->addWidget( pvrDevice, 0, 1 );
940 QLabel *pvrRadioDeviceLabel = new QLabel( qtr( "Radio device name" ) );
941 pvrDevLayout->addWidget( pvrRadioDeviceLabel, 1, 0 );
943 pvrRadioDevice = new QLineEdit;
944 pvrDevLayout->addWidget( pvrRadioDevice, 1, 1 );
946 /* PVR props panel */
947 QLabel *pvrNormLabel = new QLabel( qtr( "Norm" ) );
948 pvrPropLayout->addWidget( pvrNormLabel, 0, 0 );
950 pvrNormBox = new QComboBox;
951 setfillVLCConfigCombo( "pvr-norm", p_intf, pvrNormBox );
952 pvrPropLayout->addWidget( pvrNormBox, 0, 1 );
954 QLabel *pvrFreqLabel = new QLabel( qtr( "Frequency" ) );
955 pvrPropLayout->addWidget( pvrFreqLabel, 1, 0 );
957 pvrFreq = new QSpinBox;
958 pvrFreq->setAlignment( Qt::AlignRight );
959 pvrFreq->setSuffix(" kHz");
960 setSpinBoxFreq( pvrFreq );
961 pvrPropLayout->addWidget( pvrFreq, 1, 1 );
963 QLabel *pvrBitrLabel = new QLabel( qtr( "Bitrate" ) );
964 pvrPropLayout->addWidget( pvrBitrLabel, 2, 0 );
966 pvrBitr = new QSpinBox;
967 pvrBitr->setAlignment( Qt::AlignRight );
968 pvrBitr->setSuffix(" kHz");
969 setSpinBoxFreq( pvrBitr );
970 pvrPropLayout->addWidget( pvrBitr, 2, 1 );
971 pvrPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
975 CuMRL( pvrDevice, textChanged( const QString& ) );
976 CuMRL( pvrRadioDevice, textChanged( const QString& ) );
978 CuMRL( pvrFreq, valueChanged ( int ) );
979 CuMRL( pvrBitr, valueChanged ( int ) );
980 CuMRL( pvrNormBox, currentIndexChanged ( int ) );
986 if( module_exists( "dvb" ) ){
987 addModuleAndLayouts( DVB_DEVICE, dvb, "DVB", QGridLayout );
990 QLabel *dvbDeviceLabel = new QLabel( qtr( "Adapter card to tune" ) );
991 QLabel *dvbTypeLabel = new QLabel( qtr( "DVB Type:" ) );
993 dvbCard = new QSpinBox;
994 dvbCard->setAlignment( Qt::AlignRight );
995 dvbCard->setPrefix( "/dev/dvb/adapter" );
997 dvbDevLayout->addWidget( dvbDeviceLabel, 0, 0 );
998 dvbDevLayout->addWidget( dvbCard, 0, 2, 1, 2 );
1000 dvbs = new QRadioButton( "DVB-S" );
1001 dvbs->setChecked( true );
1002 dvbc = new QRadioButton( "DVB-C" );
1003 dvbt = new QRadioButton( "DVB-T" );
1005 dvbDevLayout->addWidget( dvbTypeLabel, 1, 0 );
1006 dvbDevLayout->addWidget( dvbs, 1, 1 );
1007 dvbDevLayout->addWidget( dvbc, 1, 2 );
1008 dvbDevLayout->addWidget( dvbt, 1, 3 );
1010 /* DVB Props panel */
1011 QLabel *dvbFreqLabel =
1012 new QLabel( qtr( "Transponder/multiplex frequency" ) );
1013 dvbPropLayout->addWidget( dvbFreqLabel, 0, 0 );
1015 dvbFreq = new QSpinBox;
1016 dvbFreq->setAlignment( Qt::AlignRight );
1017 dvbFreq->setSuffix(" kHz");
1018 dvbFreq->setSingleStep( 1000 );
1019 setSpinBoxFreq( dvbFreq );
1020 dvbPropLayout->addWidget( dvbFreq, 0, 1 );
1022 dvbSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
1023 dvbPropLayout->addWidget( dvbSrateLabel, 1, 0 );
1025 dvbSrate = new QSpinBox;
1026 dvbSrate->setAlignment( Qt::AlignRight );
1027 dvbSrate->setSuffix(" kHz");
1028 setSpinBoxFreq( dvbSrate );
1029 dvbPropLayout->addWidget( dvbSrate, 1, 1 );
1031 dvbBandLabel = new QLabel( qtr( "Bandwidth" ) );
1032 dvbPropLayout->addWidget( dvbBandLabel, 2, 0 );
1034 dvbBandBox = new QComboBox;
1035 /* This doesn't work since dvb-bandwidth doesn't seem to be a
1037 setfillVLCConfigCombo( "dvb-bandwidth", p_intf, bdaBandBox );
1039 dvbBandBox->addItem( qtr( "Auto" ), 0 );
1040 dvbBandBox->addItem( qtr( "6 MHz" ), 6 );
1041 dvbBandBox->addItem( qtr( "7 MHz" ), 7 );
1042 dvbBandBox->addItem( qtr( "8 MHz" ), 8 );
1043 dvbPropLayout->addWidget( dvbBandBox, 2, 1 );
1045 dvbBandLabel->hide();
1048 dvbPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
1052 CuMRL( dvbCard, valueChanged ( int ) );
1053 CuMRL( dvbFreq, valueChanged ( int ) );
1054 CuMRL( dvbSrate, valueChanged ( int ) );
1055 CuMRL( dvbBandBox, currentIndexChanged ( int ) );
1057 BUTTONACT( dvbs, updateButtons() );
1058 BUTTONACT( dvbt, updateButtons() );
1059 BUTTONACT( dvbc, updateButtons() );
1060 BUTTONACT( dvbs, updateMRL() );
1061 BUTTONACT( dvbt, updateMRL() );
1062 BUTTONACT( dvbc, updateMRL() );
1071 addModuleAndLayouts( SCREEN_DEVICE, screen, "Desktop", QGridLayout );
1072 QLabel *screenLabel = new QLabel( qtr( "Your display will be "
1073 "opened and played in order to stream or save it." ) );
1074 screenLabel->setWordWrap( true );
1075 screenDevLayout->addWidget( screenLabel, 0, 0 );
1077 QLabel *screenFPSLabel = new QLabel(
1078 qtr( "Desired frame rate for the capture." ) );
1079 screenPropLayout->addWidget( screenFPSLabel, 0, 0 );
1081 screenFPS = new QDoubleSpinBox;
1082 screenFPS->setValue( 1. );
1083 screenFPS->setRange( .01, 100. );
1084 screenFPS->setAlignment( Qt::AlignRight );
1085 /* xgettext: frames per second */
1086 screenFPS->setSuffix( qtr( " f/s" ) );
1087 screenPropLayout->addWidget( screenFPS, 0, 1 );
1089 /* Screen connect */
1090 CuMRL( screenFPS, valueChanged( double ) );
1092 /* General connects */
1093 CONNECT( ui.deviceCombo, activated( int ) ,
1094 stackedDevLayout, setCurrentIndex( int ) );
1095 CONNECT( ui.deviceCombo, activated( int ),
1096 stackedPropLayout, setCurrentIndex( int ) );
1097 CONNECT( ui.deviceCombo, activated( int ), this, updateMRL() );
1098 CONNECT( ui.deviceCombo, activated( int ), this, updateButtons() );
1101 #undef addModuleAndLayouts
1104 CaptureOpenPanel::~CaptureOpenPanel()
1108 void CaptureOpenPanel::clear()
1113 void CaptureOpenPanel::updateMRL()
1116 QStringList fileList;
1117 int i_devicetype = ui.deviceCombo->itemData(
1118 ui.deviceCombo->currentIndex() ).toInt();
1119 switch( i_devicetype )
1123 if( bdas->isChecked() ) mrl = "dvb-s://";
1124 else if( bdat->isChecked() ) mrl = "dvb-t://";
1125 else if( bdac->isChecked() ) mrl = "dvb-c://";
1126 else if( bdaa->isChecked() ) mrl = "atsc://";
1128 mrl += "frequency=" + QString::number( bdaFreq->value() );
1129 if( bdac->isChecked() || bdat->isChecked() || bdaa->isChecked() )
1131 fileList << mrl; mrl = "";
1133 if( bdas->isChecked() || bdac->isChecked() )
1134 mrl += " :dvb-srate=" + QString::number( bdaSrate->value() );
1135 else if( bdat->isChecked() || bdaa->isChecked() )
1136 mrl += " :dvb-bandwidth=" +
1137 QString::number( bdaBandBox->itemData(
1138 bdaBandBox->currentIndex() ).toInt() );
1139 emit methodChanged( "dvb-caching" );
1142 fileList << "dshow://";
1143 mrl+= " :dshow-vdev=" +
1144 colon_escape( QString("%1").arg( vdevDshowW->getValue() ) );
1145 mrl+= " :dshow-adev=" +
1146 colon_escape( QString("%1").arg( adevDshowW->getValue() ) )+" ";
1147 if( dshowVSizeLine->isModified() )
1148 mrl += ":dshow-size=" + dshowVSizeLine->text();
1149 emit methodChanged( "dshow-caching" );
1153 fileList << "v4l://" + v4lVideoDevice->text();
1154 mrl += " :input-slave=alsa://" + v4lAudioDevice->text();
1155 mrl += " :v4l-norm=" + QString::number( v4lNormBox->currentIndex() );
1156 mrl += " :v4l-frequency=" + QString::number( v4lFreq->value() );
1159 fileList << "v4l2://" + v4l2VideoDevice->text();
1160 mrl += " :input-slave=alsa://" + v4l2AudioDevice->text();
1161 mrl += " :v4l2-standard=" + QString::number( v4l2StdBox->currentIndex() );
1165 mrl += "channels=" + QString::number( jackChannels->value() );
1166 mrl += ":ports=" + jackPortsSelected->text();
1167 fileList << mrl; mrl = "";
1169 mrl += " :jack-input-caching=" + QString::number( jackCaching->value() );
1170 if ( jackPace->isChecked() )
1172 mrl += " :jack-input-use-vlc-pace";
1174 if ( jackConnect->isChecked() )
1176 mrl += " :jack-input-auto-connect";
1180 fileList << "pvr://";
1181 mrl += " :pvr-device=" + pvrDevice->text();
1182 mrl += " :pvr-radio-device=" + pvrRadioDevice->text();
1183 mrl += " :pvr-norm=" + QString::number( pvrNormBox->currentIndex() );
1184 if( pvrFreq->value() )
1185 mrl += " :pvr-frequency=" + QString::number( pvrFreq->value() );
1186 if( pvrBitr->value() )
1187 mrl += " :pvr-bitrate=" + QString::number( pvrBitr->value() );
1191 mrl += "frequency=" + QString::number( dvbFreq->value() );
1192 if( dvbc->isChecked() || dvbt->isChecked() )
1194 fileList << mrl; mrl= "";
1196 mrl += " :dvb-adapter=" + QString::number( dvbCard->value() );
1197 if( dvbs->isChecked() || dvbc->isChecked() )
1198 mrl += " :dvb-srate=" + QString::number( dvbSrate->value() );
1199 else if( dvbt->isChecked() )
1200 mrl += " :dvb-bandwidth=" +
1201 QString::number( dvbBandBox->itemData(
1202 dvbBandBox->currentIndex() ).toInt() );
1207 fileList << "screen://";
1208 mrl = " :screen-fps=" + QString::number( screenFPS->value(), 'f' );
1209 emit methodChanged( "screen-caching" );
1214 if( !advMRL.isEmpty() ) mrl += advMRL;
1216 emit mrlUpdated( fileList, mrl );
1220 * Update the Buttons (show/hide) for the GUI as all device type don't
1221 * use the same ui. elements.
1223 void CaptureOpenPanel::updateButtons()
1225 /* Be sure to display the ui Elements in case they were hidden by
1226 * some Device Type (like Screen://) */
1227 ui.optionsBox->show();
1228 ui.advancedButton->show();
1229 /* Get the current Device Number */
1230 int i_devicetype = ui.deviceCombo->itemData(
1231 ui.deviceCombo->currentIndex() ).toInt();
1232 switch( i_devicetype )
1236 if( bdas->isChecked() || bdac->isChecked() )
1239 bdaSrateLabel->show();
1241 bdaBandLabel->hide();
1243 else if( bdat->isChecked() || bdaa->isChecked() )
1246 bdaSrateLabel->hide();
1248 bdaBandLabel->show();
1253 if( dvbs->isChecked() || dvbc->isChecked() )
1256 dvbSrateLabel->show();
1258 dvbBandLabel->hide();
1260 else if( dvbt->isChecked() )
1263 dvbSrateLabel->hide();
1265 dvbBandLabel->show();
1270 //ui.optionsBox->hide();
1271 ui.advancedButton->hide();
1278 void CaptureOpenPanel::advancedDialog()
1280 /* Get selected device type */
1281 int i_devicetype = ui.deviceCombo->itemData(
1282 ui.deviceCombo->currentIndex() ).toInt();
1284 /* Get the corresponding module */
1285 module_t *p_module =
1286 module_find( psz_devModule[i_devicetype] );
1287 if( NULL == p_module ) return;
1290 QList<ConfigControl *> controls;
1292 /* Get the confsize */
1293 unsigned int i_confsize;
1294 module_config_t *p_config;
1295 p_config = module_config_get( p_module, &i_confsize );
1297 /* New Adv Prop dialog */
1298 adv = new QDialog( this );
1299 adv->setWindowTitle( qtr( "Advanced Options" ) );
1300 adv->setWindowRole( "vlc-advanced-options" );
1302 /* A main Layout with a Frame */
1303 QVBoxLayout *mainLayout = new QVBoxLayout( adv );
1304 QScrollArea *scroll = new QScrollArea;
1305 mainLayout->addWidget( scroll );
1307 QFrame *advFrame = new QFrame;
1308 /* GridLayout inside the Frame */
1309 QGridLayout *gLayout = new QGridLayout( advFrame );
1311 scroll->setWidgetResizable( true );
1312 scroll->setWidget( advFrame );
1314 /* Create the options inside the FrameLayout */
1315 for( int n = 0; n < (int)i_confsize; n++ )
1317 module_config_t *p_item = p_config + n;
1318 ConfigControl *config = ConfigControl::createControl(
1319 VLC_OBJECT( p_intf ), p_item, advFrame, gLayout, n );
1321 controls.append( config );
1325 QDialogButtonBox *advButtonBox = new QDialogButtonBox( adv );
1326 QPushButton *closeButton = new QPushButton( qtr( "OK" ) );
1327 QPushButton *cancelButton = new QPushButton( qtr( "Cancel" ) );
1329 CONNECT( closeButton, clicked(), adv, accept() );
1330 CONNECT( cancelButton, clicked(), adv, reject() );
1332 advButtonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
1333 advButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
1335 mainLayout->addWidget( advButtonBox );
1337 /* Creation of the MRL */
1340 QString tempMRL = "";
1341 for( int i = 0; i < controls.size(); i++ )
1343 ConfigControl *control = controls[i];
1345 tempMRL += (i ? " :" : ":");
1347 if( control->getType() == CONFIG_ITEM_BOOL )
1348 if( !(qobject_cast<VIntConfigControl *>(control)->getValue() ) )
1351 tempMRL += control->getName();
1353 switch( control->getType() )
1355 case CONFIG_ITEM_STRING:
1356 case CONFIG_ITEM_FILE:
1357 case CONFIG_ITEM_DIRECTORY:
1358 case CONFIG_ITEM_MODULE:
1359 tempMRL += colon_escape( QString("=%1").arg( qobject_cast<VStringConfigControl *>(control)->getValue() ) );
1361 case CONFIG_ITEM_INTEGER:
1362 tempMRL += QString("=%1").arg( qobject_cast<VIntConfigControl *>(control)->getValue() );
1364 case CONFIG_ITEM_FLOAT:
1365 tempMRL += QString("=%1").arg( qobject_cast<VFloatConfigControl *>(control)->getValue() );
1371 msg_Dbg( p_intf, "%s", qtu( advMRL ) );
1373 for( int i = 0; i < controls.size(); i++ )
1375 ConfigControl *control = controls[i];
1379 module_config_free( p_config );
1380 module_release (p_module);