]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/open_panels.cpp
Qt: re-probe the disc drives on each change of FocusPanel()
[vlc] / modules / gui / qt4 / components / open_panels.cpp
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
7  *
8  * $Id$
9  *
10  * Authors: Clément Stenac <zorglub@videolan.org>
11  *          Jean-Baptiste Kempf <jb@videolan.org>
12  *          Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
13  *
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.
18  *
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.
23  *
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  *****************************************************************************/
28
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include "qt4.hpp"
34 #include "components/open_panels.hpp"
35 #include "dialogs/open.hpp"
36 #include "dialogs_provider.hpp" /* Open Subtitle file */
37 #include "util/qt_dirs.hpp"
38 #include <vlc_intf_strings.h>
39 #include <vlc_modules.h>
40 #ifdef WIN32
41   #include <vlc_charset.h> /* FromWide for Win32 */
42 #endif
43
44 #include <QFileDialog>
45 #include <QDialogButtonBox>
46 #include <QLineEdit>
47 #include <QStackedLayout>
48 #include <QListView>
49 #include <QCompleter>
50 #include <QDirModel>
51 #include <QScrollArea>
52 #include <QUrl>
53 #include <QStringListModel>
54 #include <QDropEvent>
55
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") )
59
60 /* Populate a combobox with the devices matching a pattern.
61    Combobox will automatically do autocompletion on the edit zone */
62 #define POPULATE_WITH_DEVS(ppsz_devlist, targetCombo) \
63     QStringList targetCombo ## StringList = QStringList(); \
64     for ( size_t i = 0; i< sizeof(ppsz_devlist) / sizeof(*ppsz_devlist); i++ ) \
65         targetCombo ## StringList << QString( ppsz_devlist[ i ] ); \
66     targetCombo->addItems( QDir( "/dev/" )\
67         .entryList( targetCombo ## StringList, QDir::System )\
68         .replaceInStrings( QRegExp("^"), "/dev/" ) \
69     );
70
71 static const char psz_devModule[][8] = { "v4l2", "pvr", "dtv",
72                                        "dshow", "screen", "jack" };
73
74 /**************************************************************************
75  * Open Files and subtitles                                               *
76  **************************************************************************/
77 FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
78                                 OpenPanel( _parent, _p_intf ), dialogBox( NULL )
79 {
80     /* Classic UI Setup */
81     ui.setupUi( this );
82
83     setAcceptDrops( true );
84
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(" *")); */
93
94
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" ) )
101     {
102         ui.tempWidget->hide();
103         BuildOldPanel();
104     }
105
106     /* Subtitles */
107     /* Deactivate the subtitles control by default. */
108     ui.subFrame->setEnabled( false );
109
110     /* Connects  */
111     BUTTONACT( ui.fileBrowseButton, browseFile() );
112     BUTTONACT( ui.removeFileButton, removeFile() );
113
114     BUTTONACT( ui.subBrowseButton, browseFileSub() );
115     CONNECT( ui.subCheckBox, toggled( bool ), this, toggleSubtitleFrame( bool ) );
116
117     CONNECT( ui.fileListWidg, itemChanged( QListWidgetItem * ), this, updateMRL() );
118     CONNECT( ui.subInput, textChanged( const QString& ), this, updateMRL() );
119     updateButtons();
120 }
121
122 inline void FileOpenPanel::BuildOldPanel()
123 {
124     /** BEGIN QFileDialog tweaking **/
125     /* Use a QFileDialog and customize it because we don't want to
126        rewrite it all. Be careful to your eyes cause there are a few hacks.
127        Be very careful and test correctly when you modify this. */
128
129     /* Make this QFileDialog a child of tempWidget from the ui. */
130     dialogBox = new FileOpenBox( ui.tempWidget, NULL,
131                                  p_intf->p_sys->filepath, "" );
132
133     dialogBox->setFileMode( QFileDialog::ExistingFiles );
134     dialogBox->setAcceptMode( QFileDialog::AcceptOpen );
135     dialogBox->restoreState(
136             getSettings()->value( "file-dialog-state" ).toByteArray() );
137
138     /* We don't want to see a grip in the middle of the window, do we? */
139     dialogBox->setSizeGripEnabled( false );
140
141     /* Add a tooltip */
142     dialogBox->setToolTip( qtr( "Select one or multiple files" ) );
143     dialogBox->setMinimumHeight( 250 );
144
145     // But hide the two OK/Cancel buttons. Enable them for debug.
146     QDialogButtonBox *fileDialogAcceptBox =
147                       dialogBox->findChildren<QDialogButtonBox*>()[0];
148     fileDialogAcceptBox->hide();
149
150     /* Ugly hacks to get the good Widget */
151     //This lineEdit is the normal line in the fileDialog.
152     QLineEdit *lineFileEdit = dialogBox->findChildren<QLineEdit*>()[0];
153     /* Make a list of QLabel inside the QFileDialog to access the good ones */
154     QList<QLabel *> listLabel = dialogBox->findChildren<QLabel*>();
155
156     /* Hide the FileNames one. Enable it for debug */
157     listLabel[1]->setText( qtr( "File names:" ) );
158     /* Change the text that was uncool in the usual box */
159     listLabel[2]->setText( qtr( "Filter:" ) );
160
161     dialogBox->layout()->setMargin( 0 );
162     dialogBox->layout()->setSizeConstraint( QLayout::SetNoConstraint );
163
164     /** END of QFileDialog tweaking **/
165
166     // Add the DialogBox to the layout
167     ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
168
169     CONNECT( lineFileEdit, textChanged( const QString& ), this, updateMRL() );
170     dialogBox->installEventFilter( this );
171 }
172
173 FileOpenPanel::~FileOpenPanel()
174 {
175     if( dialogBox )
176         getSettings()->setValue( "file-dialog-state", dialogBox->saveState() );
177 }
178
179 void FileOpenPanel::dragEnterEvent( QDragEnterEvent *event )
180 {
181     event->acceptProposedAction();
182 }
183
184 void FileOpenPanel::dragMoveEvent( QDragMoveEvent *event )
185 {
186     event->acceptProposedAction();
187 }
188
189 void FileOpenPanel::dragLeaveEvent( QDragLeaveEvent *event )
190 {
191     event->accept();
192 }
193
194 void FileOpenPanel::dropEvent( QDropEvent *event )
195 {
196     if( event->possibleActions() & Qt::CopyAction )
197        event->setDropAction( Qt::CopyAction );
198     else
199         return;
200
201     const QMimeData *mimeData = event->mimeData();
202     foreach( const QUrl &url, mimeData->urls() )
203     {
204         if( url.isValid() )
205         {
206             QListWidgetItem *item = new QListWidgetItem(
207                                          toNativeSeparators( url.toLocalFile() ),
208                                          ui.fileListWidg );
209             item->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled );
210             ui.fileListWidg->addItem( item );
211         }
212     }
213     updateMRL();
214     updateButtons();
215     event->accept();
216 }
217
218 void FileOpenPanel::browseFile()
219 {
220     QStringList files = QFileDialog::getOpenFileNames( this, qtr( "Select one or multiple files" ), p_intf->p_sys->filepath) ;
221     foreach( const QString &file, files )
222     {
223         QListWidgetItem *item =
224             new QListWidgetItem( toNativeSeparators( file ), ui.fileListWidg );
225         item->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled );
226         ui.fileListWidg->addItem( item );
227         savedirpathFromFile( file );
228     }
229     updateButtons();
230     updateMRL();
231 }
232
233 void FileOpenPanel::removeFile()
234 {
235     int i = ui.fileListWidg->currentRow();
236     if( i != -1 )
237     {
238         QListWidgetItem *temp = ui.fileListWidg->takeItem( i );
239         delete temp;
240     }
241
242     updateMRL();
243     updateButtons();
244 }
245
246 /* Show a fileBrowser to select a subtitle */
247 void FileOpenPanel::browseFileSub()
248 {
249     // TODO Handle selection of more than one subtitles file
250     QStringList files = THEDP->showSimpleOpen( qtr("Open subtitles file"),
251                            EXT_FILTER_SUBTITLE, p_intf->p_sys->filepath );
252
253     if( files.isEmpty() ) return;
254     ui.subInput->setText( toNativeSeparators( files.join(" ") ) );
255     updateMRL();
256 }
257
258 void FileOpenPanel::toggleSubtitleFrame( bool b )
259 {
260     ui.subFrame->setEnabled( b );
261
262     /* Update the MRL */
263     updateMRL();
264 }
265
266
267 /* Update the current MRL */
268 void FileOpenPanel::updateMRL()
269 {
270     QStringList fileList;
271     QString mrl;
272
273     /* File Listing */
274     if( dialogBox == NULL )
275         for( int i = 0; i < ui.fileListWidg->count(); i++ )
276         {
277             if( !ui.fileListWidg->item( i )->text().isEmpty() )
278                 fileList << toURI(ui.fileListWidg->item( i )->text());
279         }
280     else
281     {
282         fileList = dialogBox->selectedFiles();
283         for( int i = 0; i < fileList.count(); i++ )
284             fileList[i] = toURI( fileList[i] );
285     }
286
287     /* Options */
288     if( ui.subCheckBox->isChecked() &&  !ui.subInput->text().isEmpty() ) {
289         mrl.append( " :sub-file=" + colon_escape( ui.subInput->text() ) );
290     }
291
292     emit methodChanged( "file-caching" );
293     emit mrlUpdated( fileList, mrl );
294 }
295
296 /* Function called by Open Dialog when clicke on Play/Enqueue */
297 void FileOpenPanel::accept()
298 {
299     if( dialogBox )
300         p_intf->p_sys->filepath = dialogBox->directory().absolutePath();
301     ui.fileListWidg->clear();
302 }
303
304 /* Function called by Open Dialog when clicked on cancel */
305 void FileOpenPanel::clear()
306 {
307     ui.fileListWidg->clear();
308     ui.subInput->clear();
309 }
310
311 /* Update buttons depending on current selection */
312 void FileOpenPanel::updateButtons()
313 {
314     bool b_has_files = ( ui.fileListWidg->count() > 0 );
315     ui.removeFileButton->setEnabled( b_has_files );
316     ui.subCheckBox->setEnabled( b_has_files );
317 }
318
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 )
324 {
325     ui.setupUi( this );
326
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" );
331
332     /* State to avoid overwritting the users changes with the configuration */
333     m_discType = None;
334
335     ui.browseDiscButton->setToolTip( qtr( I_DEVICE_TOOLTIP ));
336     ui.deviceCombo->setToolTip( qtr(I_DEVICE_TOOLTIP) );
337     ui.deviceCombo->setInsertPolicy( QComboBox::InsertAtTop );
338
339     /* CONNECTs */
340     BUTTONACT( ui.dvdRadioButton, updateButtons() );
341     BUTTONACT( ui.vcdRadioButton, updateButtons() );
342     BUTTONACT( ui.audioCDRadioButton, updateButtons() );
343     BUTTONACT( ui.dvdsimple, updateButtons() );
344     BUTTONACT( ui.browseDiscButton, browseDevice() );
345     BUTTON_SET_ACT_I( ui.ejectButton, "", toolbar/eject, qtr( "Eject the disc" ),
346             eject() );
347
348     CONNECT( ui.deviceCombo, editTextChanged( QString ), this, updateMRL());
349     CONNECT( ui.deviceCombo, currentIndexChanged( QString ), this, updateMRL());
350     CONNECT( ui.titleSpin, valueChanged( int ), this, updateMRL());
351     CONNECT( ui.chapterSpin, valueChanged( int ), this, updateMRL());
352     CONNECT( ui.audioSpin, valueChanged( int ), this, updateMRL());
353     CONNECT( ui.subtitlesSpin, valueChanged( int ), this, updateMRL());
354
355     /* Run once the updateButtons function in order to fill correctly the comboBoxes */
356     updateButtons();
357 }
358
359 void DiscOpenPanel::onFocus()
360 {
361 #ifdef WIN32 /* Disc drives probing for Windows */
362     wchar_t szDrives[512];
363     szDrives[0] = '\0';
364     if( GetLogicalDriveStringsW( sizeof( szDrives ) - 1, szDrives ) )
365     {
366         wchar_t *drive = szDrives;
367         UINT oldMode = SetErrorMode( SEM_FAILCRITICALERRORS );
368         while( *drive )
369         {
370             if( GetDriveTypeW(drive) == DRIVE_CDROM )
371             {
372                 wchar_t psz_name[512] = L"";
373                 GetVolumeInformationW( drive, psz_name, 511, NULL, NULL, NULL, NULL, 0 );
374
375                 QString displayName = FromWide( drive );
376                 if( !*psz_name ) {
377                     displayName = displayName + " - "  + FromWide( psz_name );
378                 }
379
380                 ui.deviceCombo->addItem( displayName, FromWide( drive ) );
381             }
382
383             /* go to next drive */
384             while( *(drive++) );
385         }
386         SetErrorMode(oldMode);
387     }
388 #else /* Linux */
389     char const * const ppsz_discdevices[] = {
390         "sr*",
391         "sg*",
392         "scd*",
393         "dvd*",
394         "cd*"
395     };
396     QComboBox *discCombo = ui.deviceCombo; /* avoid namespacing in macro */
397     POPULATE_WITH_DEVS( ppsz_discdevices, discCombo );
398 #endif
399
400
401 }
402
403 DiscOpenPanel::~DiscOpenPanel()
404 {
405     free( psz_dvddiscpath );
406     free( psz_vcddiscpath );
407     free( psz_cddadiscpath );
408 }
409
410 void DiscOpenPanel::clear()
411 {
412     ui.titleSpin->setValue( 0 );
413     ui.chapterSpin->setValue( 0 );
414     ui.subtitlesSpin->setValue( -1 );
415     ui.audioSpin->setValue( -1 );
416     m_discType = None;
417 }
418
419 #ifdef WIN32
420     #define setDrive( psz_name ) {\
421     int index = ui.deviceCombo->findText( qfu( psz_name ) ); \
422     if( index != -1 ) ui.deviceCombo->setCurrentIndex( index );}
423 #else
424     #define setDrive( psz_name ) {\
425     ui.deviceCombo->setEditText( qfu( psz_name ) ); }
426 #endif
427
428 /* update the buttons according the type of device */
429 void DiscOpenPanel::updateButtons()
430 {
431     if ( ui.dvdRadioButton->isChecked() )
432     {
433         if( m_discType != Dvd )
434         {
435             setDrive( psz_dvddiscpath );
436             m_discType = Dvd;
437         }
438         ui.titleLabel->setText( qtr("Title") );
439         ui.chapterLabel->show();
440         ui.chapterSpin->show();
441         ui.diskOptionBox_2->show();
442         ui.dvdsimple->setEnabled( true );
443     }
444     if ( ui.bdRadioButton->isChecked() )
445     {
446         if( m_discType != BRD )
447         {
448             setDrive( psz_dvddiscpath );
449             m_discType = BRD;
450         }
451         ui.titleLabel->setText( qtr("Title") );
452         ui.chapterLabel->hide();
453         ui.chapterSpin->hide();
454         ui.diskOptionBox_2->hide();
455         ui.dvdsimple->setEnabled( true );
456     }
457     else if ( ui.vcdRadioButton->isChecked() )
458     {
459         if( m_discType != Vcd )
460         {
461             setDrive( psz_vcddiscpath );
462             m_discType = Vcd;
463         }
464         ui.titleLabel->setText( qtr("Entry") );
465         ui.chapterLabel->hide();
466         ui.chapterSpin->hide();
467         ui.diskOptionBox_2->show();
468         ui.dvdsimple->setEnabled( false );
469     }
470     else /* CDDA */
471     {
472         if( m_discType != Cdda )
473         {
474             setDrive( psz_cddadiscpath );
475             m_discType = Cdda;
476         }
477         ui.titleLabel->setText( qtr("Track") );
478         ui.chapterLabel->hide();
479         ui.chapterSpin->hide();
480         ui.diskOptionBox_2->hide();
481         ui.dvdsimple->setEnabled( false );
482     }
483
484     updateMRL();
485 }
486
487 #undef setDrive
488
489 #ifndef WIN32
490 # define LOCALHOST ""
491 #else
492 # define LOCALHOST "/"
493 #endif
494
495 /* Update the current MRL */
496 void DiscOpenPanel::updateMRL()
497 {
498     QString mrl;
499     QString discPath;
500     QStringList fileList;
501
502     if( ui.deviceCombo->itemData( ui.deviceCombo->currentIndex() ) != QVariant::Invalid )
503         discPath = ui.deviceCombo->itemData( ui.deviceCombo->currentIndex() ).toString();
504     else
505         discPath = ui.deviceCombo->currentText();
506
507     /* CDDAX and VCDX not implemented. TODO ? No. */
508     /* DVD */
509     if( ui.dvdRadioButton->isChecked() ) {
510         if( !ui.dvdsimple->isChecked() )
511             mrl = "dvd://" LOCALHOST + discPath;
512         else
513             mrl = "dvdsimple://" LOCALHOST + discPath;
514
515         if ( ui.titleSpin->value() > 0 ) {
516             mrl += QString("@%1").arg( ui.titleSpin->value() );
517             if ( ui.chapterSpin->value() > 0 ) {
518                 mrl+= QString(":%1").arg( ui.chapterSpin->value() );
519             }
520         }
521     } else if ( ui.bdRadioButton->isChecked() ) {
522         mrl = "bluray://" LOCALHOST + discPath;
523
524     /* VCD */
525     } else if ( ui.vcdRadioButton->isChecked() ) {
526         mrl = "vcd://" LOCALHOST + discPath;
527
528         if( ui.titleSpin->value() > 0 ) {
529             mrl += QString("@E%1").arg( ui.titleSpin->value() );
530         }
531
532     /* CDDA */
533     } else {
534         mrl = "cdda://" LOCALHOST + discPath;
535     }
536     emit methodChanged( "disc-caching" );
537
538     fileList << mrl; mrl = "";
539
540     if ( ui.dvdRadioButton->isChecked() || ui.vcdRadioButton->isChecked() )
541     {
542         if ( ui.audioSpin->value() >= 0 ) {
543             mrl += " :audio-track=" +
544                 QString("%1").arg( ui.audioSpin->value() );
545         }
546         if ( ui.subtitlesSpin->value() >= 0 ) {
547             mrl += " :sub-track=" +
548                 QString("%1").arg( ui.subtitlesSpin->value() );
549         }
550     }
551     else
552     {
553         if( ui.titleSpin->value() > 0 )
554             mrl += QString(" :cdda-track=%1").arg( ui.titleSpin->value() );
555     }
556     emit mrlUpdated( fileList, mrl );
557 }
558
559 void DiscOpenPanel::browseDevice()
560 {
561     QString dir = QFileDialog::getExistingDirectory( this,
562             qtr( I_DEVICE_TOOLTIP ) );
563     if( !dir.isEmpty() )
564     {
565         ui.deviceCombo->addItem( toNativeSepNoSlash( dir ) );
566         ui.deviceCombo->setCurrentIndex( ui.deviceCombo->findText( toNativeSepNoSlash( dir ) ) );
567         updateMRL();
568     }
569
570     updateMRL();
571 }
572
573 void DiscOpenPanel::eject()
574 {
575     intf_Eject( p_intf, qtu( ui.deviceCombo->currentText() ) );
576 }
577
578 void DiscOpenPanel::accept()
579 {}
580
581 /**************************************************************************
582  * Open Network streams and URL pages                                     *
583  **************************************************************************/
584 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
585                                 OpenPanel( _parent, _p_intf )
586 {
587     ui.setupUi( this );
588     CONNECT( ui.urlComboBox, editTextChanged( const QString& ), this, updateMRL());
589
590     /* */
591     if( var_InheritBool( p_intf, "qt-recentplay" ) )
592     {
593         b_recentList = true;
594         ui.urlComboBox->addItems( getSettings()->value( "Open/netMRL" ).toStringList() );
595         ui.urlComboBox->setMaxCount( 10 );
596     }
597     else
598         b_recentList = false;
599
600     /* Use a simple validator for URLs */
601     ui.urlComboBox->setValidator( new UrlValidator( this ) );
602     ui.urlComboBox->setFocus();
603 }
604
605 NetOpenPanel::~NetOpenPanel()
606 {
607     if( !b_recentList ) return;
608
609     /* Create the list with the current items */
610     QStringList mrlList;
611     for( int i = 0; i < ui.urlComboBox->count(); i++ )
612         mrlList << ui.urlComboBox->itemText( i );
613
614     /* Clean the list... */
615     mrlList.removeDuplicates();
616     /* ...and save the 8 last entries */
617     getSettings()->setValue( "Open/netMRL", mrlList );
618 }
619
620 void NetOpenPanel::clear()
621 {
622     ui.urlComboBox->clear();
623 }
624
625 void NetOpenPanel::onAccept()
626 {
627     if( ui.urlComboBox->findText( ui.urlComboBox->currentText() ) == -1 )
628         ui.urlComboBox->insertItem( 0, ui.urlComboBox->currentText());
629 }
630
631 void NetOpenPanel::onFocus()
632 {
633     ui.urlComboBox->setFocus();
634     ui.urlComboBox->lineEdit()->selectAll();
635 }
636
637 void NetOpenPanel::updateMRL()
638 {
639     QString url = ui.urlComboBox->lineEdit()->text();
640
641     if( url.isEmpty() )
642         return;
643
644     emit methodChanged( qfu( "network-caching" ) );
645
646     QStringList qsl;
647     qsl << url;
648     emit mrlUpdated( qsl, "" );
649 }
650
651 QValidator::State UrlValidator::validate( QString& str, int& ) const
652 {
653     if( str.contains( ' ' ) )
654         return QValidator::Invalid;
655     if( !str.contains( "://" ) )
656         return QValidator::Intermediate;
657     return QValidator::Acceptable;
658 }
659
660 void UrlValidator::fixup( QString& str ) const
661 {
662     str = str.trimmed();
663 }
664
665 /**************************************************************************
666  * Open Capture device ( DVB, PVR, V4L, and similar )                     *
667  **************************************************************************/
668 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
669                                 OpenPanel( _parent, _p_intf )
670 {
671     isInitialized = false;
672 }
673
674 void CaptureOpenPanel::initialize()
675 {
676     if( isInitialized ) return;
677
678     msg_Dbg( p_intf, "Initialization of Capture device panel" );
679     isInitialized = true;
680
681     ui.setupUi( this );
682
683     BUTTONACT( ui.advancedButton, advancedDialog() );
684
685     /* Create two stacked layouts in the main comboBoxes */
686     QStackedLayout *stackedDevLayout = new QStackedLayout;
687     ui.cardBox->setLayout( stackedDevLayout );
688
689     QStackedLayout *stackedPropLayout = new QStackedLayout;
690     ui.optionsBox->setLayout( stackedPropLayout );
691
692     /* Creation and connections of the WIdgets in the stacked layout */
693 #define addModuleAndLayouts( number, name, label, layout )            \
694     QWidget * name ## DevPage = new QWidget( this );                  \
695     QWidget * name ## PropPage = new QWidget( this );                 \
696     stackedDevLayout->addWidget( name ## DevPage );        \
697     stackedPropLayout->addWidget( name ## PropPage );      \
698     layout * name ## DevLayout = new layout;                \
699     layout * name ## PropLayout = new layout;               \
700     name ## DevPage->setLayout( name ## DevLayout );                  \
701     name ## PropPage->setLayout( name ## PropLayout );                \
702     ui.deviceCombo->addItem( qtr( label ), QVariant( number ) );
703
704 #define CuMRL( widget, slot ) CONNECT( widget , slot , this, updateMRL() );
705
706 #ifdef WIN32
707     /*********************
708      * DirectShow Stuffs *
709      *********************/
710     if( module_exists( "dshow" ) ){
711     addModuleAndLayouts( DSHOW_DEVICE, dshow, "DirectShow", QGridLayout );
712
713     /* dshow Main */
714     int line = 0;
715     module_config_t *p_config =
716         config_FindConfig( VLC_OBJECT(p_intf), "dshow-vdev" );
717     vdevDshowW = new StringListConfigControl(
718         VLC_OBJECT(p_intf), p_config, this, dshowDevLayout, line );
719     line++;
720
721     p_config = config_FindConfig( VLC_OBJECT(p_intf), "dshow-adev" );
722     adevDshowW = new StringListConfigControl(
723         VLC_OBJECT(p_intf), p_config, this, dshowDevLayout, line );
724     line++;
725
726     /* dshow Properties */
727     QLabel *dshowVSizeLabel = new QLabel( qtr( "Video size" ) );
728     dshowPropLayout->addWidget( dshowVSizeLabel, 0, 0 );
729
730     dshowVSizeLine = new QLineEdit;
731     dshowPropLayout->addWidget( dshowVSizeLine, 0, 1);
732     dshowPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
733             1, 0, 3, 1 );
734
735     /* dshow CONNECTs */
736     CuMRL( vdevDshowW->combo, currentIndexChanged ( int ) );
737     CuMRL( adevDshowW->combo, currentIndexChanged ( int ) );
738     CuMRL( dshowVSizeLine, textChanged( const QString& ) );
739     }
740 #else /* WIN32 */
741     /*******
742      * V4L2*
743      *******/
744     if( module_exists( "v4l2" ) ){
745     addModuleAndLayouts( V4L2_DEVICE, v4l2, "Video for Linux 2", QGridLayout );
746
747     char const * const ppsz_v4lvdevices[] = {
748         "video*"
749     };
750
751     /* V4L2 main panel */
752     QLabel *v4l2VideoDeviceLabel = new QLabel( qtr( "Video device name" ) );
753     v4l2DevLayout->addWidget( v4l2VideoDeviceLabel, 0, 0 );
754
755     v4l2VideoDevice = new QComboBox( this );
756     v4l2VideoDevice->setEditable( true );
757     POPULATE_WITH_DEVS( ppsz_v4lvdevices, v4l2VideoDevice );
758     v4l2VideoDevice->clearEditText();
759     v4l2DevLayout->addWidget( v4l2VideoDevice, 0, 1 );
760
761     QLabel *v4l2AudioDeviceLabel = new QLabel( qtr( "Audio device name" ) );
762     v4l2DevLayout->addWidget( v4l2AudioDeviceLabel, 1, 0 );
763
764     v4l2AudioDevice = new QComboBox( this );
765     v4l2AudioDevice->setEditable( true );
766     {
767         QStringList patterns = QStringList();
768         patterns << QString( "pcmC*D*c" );
769
770         QStringList nodes = QDir( "/dev/snd" ).entryList( patterns,
771                                                           QDir::System );
772         QStringList names = nodes.replaceInStrings( QRegExp("^pcmC"), "hw:" )
773                                  .replaceInStrings( QRegExp("c$"), "" )
774                                  .replaceInStrings( QRegExp("D"), "," );
775         v4l2AudioDevice->addItems( names );
776     }
777     v4l2AudioDevice->clearEditText();
778     v4l2DevLayout->addWidget( v4l2AudioDevice, 1, 1 );
779
780     /* v4l2 Props panel */
781     QLabel *v4l2StdLabel = new QLabel( qtr( "Video standard" ) );
782     v4l2PropLayout->addWidget( v4l2StdLabel, 0 , 0 );
783
784     v4l2StdBox = new QComboBox;
785     setfillVLCConfigCombo( "v4l2-standard", p_intf, v4l2StdBox );
786     v4l2PropLayout->addWidget( v4l2StdBox, 0 , 1 );
787     v4l2PropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
788             1, 0, 3, 2 );
789
790     /* v4l2 CONNECTs */
791     CuMRL( v4l2VideoDevice->lineEdit(), textChanged( const QString& ) );
792     CuMRL( v4l2VideoDevice,  currentIndexChanged ( int ) );
793     CuMRL( v4l2AudioDevice->lineEdit(), textChanged( const QString& ) );
794     CuMRL( v4l2AudioDevice,  currentIndexChanged ( int ) );
795     CuMRL( v4l2StdBox,  currentIndexChanged ( int ) );
796     }
797
798     /*******
799      * JACK *
800      *******/
801     if( module_exists( "jack" ) ){
802     addModuleAndLayouts( JACK_DEVICE, jack, "JACK Audio Connection Kit",
803                          QGridLayout);
804
805     /* Jack Main panel */
806     /* Channels */
807     QLabel *jackChannelsLabel = new QLabel( qtr( "Channels:" ) );
808     jackDevLayout->addWidget( jackChannelsLabel, 1, 0 );
809
810     jackChannels = new QSpinBox;
811     setSpinBoxFreq( jackChannels );
812     jackChannels->setMaximum(255);
813     jackChannels->setValue(2);
814     jackChannels->setAlignment( Qt::AlignRight );
815     jackDevLayout->addWidget( jackChannels, 1, 1 );
816
817     /* Selected ports */
818     QLabel *jackPortsLabel = new QLabel( qtr( "Selected ports:" ) );
819     jackDevLayout->addWidget( jackPortsLabel, 0 , 0 );
820
821     jackPortsSelected = new QLineEdit( qtr( ".*") );
822     jackPortsSelected->setAlignment( Qt::AlignRight );
823     jackDevLayout->addWidget( jackPortsSelected, 0, 1 );
824
825     /* Jack Props panel */
826
827     /* Pace */
828     jackPace = new QCheckBox(qtr( "Use VLC pace" ));
829     jackPropLayout->addWidget( jackPace, 1, 1 );
830
831     /* Auto Connect */
832     jackConnect = new QCheckBox( qtr( "Auto connection" ));
833     jackPropLayout->addWidget( jackConnect, 1, 2 );
834
835     /* Jack CONNECTs */
836     CuMRL( jackChannels, valueChanged( int ) );
837     CuMRL( jackPace, stateChanged( int ) );
838     CuMRL( jackConnect, stateChanged( int ) );
839     CuMRL( jackPortsSelected, textChanged( const QString& ) );
840     }
841
842     /************
843      * PVR      *
844      ************/
845     if( module_exists( "pvr" ) ){
846     addModuleAndLayouts( PVR_DEVICE, pvr, "PVR", QGridLayout );
847
848     /* PVR Main panel */
849     QLabel *pvrDeviceLabel = new QLabel( qtr( "Device name" ) );
850     pvrDevLayout->addWidget( pvrDeviceLabel, 0, 0 );
851
852     pvrDevice = new QLineEdit;
853     pvrDevLayout->addWidget( pvrDevice, 0, 1 );
854
855     QLabel *pvrRadioDeviceLabel = new QLabel( qtr( "Radio device name" ) );
856     pvrDevLayout->addWidget( pvrRadioDeviceLabel, 1, 0 );
857
858     pvrRadioDevice = new QLineEdit;
859     pvrDevLayout->addWidget( pvrRadioDevice, 1, 1 );
860
861     /* PVR props panel */
862     QLabel *pvrNormLabel = new QLabel( qtr( "Norm" ) );
863     pvrPropLayout->addWidget( pvrNormLabel, 0, 0 );
864
865     pvrNormBox = new QComboBox;
866     setfillVLCConfigCombo( "pvr-norm", p_intf, pvrNormBox );
867     pvrPropLayout->addWidget( pvrNormBox, 0, 1 );
868
869     QLabel *pvrFreqLabel = new QLabel( qtr( "Frequency" ) );
870     pvrPropLayout->addWidget( pvrFreqLabel, 1, 0 );
871
872     pvrFreq = new QSpinBox;
873     pvrFreq->setAlignment( Qt::AlignRight );
874     pvrFreq->setSuffix(" kHz");
875     setSpinBoxFreq( pvrFreq );
876     pvrPropLayout->addWidget( pvrFreq, 1, 1 );
877
878     QLabel *pvrBitrLabel = new QLabel( qtr( "Bitrate" ) );
879     pvrPropLayout->addWidget( pvrBitrLabel, 2, 0 );
880
881     pvrBitr = new QSpinBox;
882     pvrBitr->setAlignment( Qt::AlignRight );
883     pvrBitr->setSuffix(" kHz");
884     setSpinBoxFreq( pvrBitr );
885     pvrPropLayout->addWidget( pvrBitr, 2, 1 );
886     pvrPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
887             3, 0, 1, 1 );
888
889     /* PVR CONNECTs */
890     CuMRL( pvrDevice, textChanged( const QString& ) );
891     CuMRL( pvrRadioDevice, textChanged( const QString& ) );
892
893     CuMRL( pvrFreq, valueChanged ( int ) );
894     CuMRL( pvrBitr, valueChanged ( int ) );
895     CuMRL( pvrNormBox, currentIndexChanged ( int ) );
896     }
897 #endif
898     /*************
899      * DVB Stuff *
900      *************/
901     if( module_exists( "dtv" ) ){
902     addModuleAndLayouts( DTV_DEVICE, dvb, N_("TV (digital)"), QGridLayout );
903
904     /* DVB Main */
905     QLabel *dvbDeviceLabel = new QLabel( qtr( "Tuner card" ) );
906     QLabel *dvbTypeLabel = new QLabel( qtr( "Delivery system" ) );
907
908     dvbCard = new QSpinBox;
909     dvbCard->setAlignment( Qt::AlignRight );
910 #ifdef __linux__
911     dvbCard->setPrefix( "/dev/dvb/adapter" );
912 #endif
913     dvbDevLayout->addWidget( dvbDeviceLabel, 0, 0 );
914     dvbDevLayout->addWidget( dvbCard, 0, 1, 1, 2 );
915
916     dvbc = new QRadioButton( "DVB-C" );
917     dvbs = new QRadioButton( "DVB-S" );
918     dvbs2 = new QRadioButton( "DVB-S2" );
919     dvbt = new QRadioButton( "DVB-T" );
920     dvbt2 = new QRadioButton( "DVB-T2" );
921     atsc = new QRadioButton( "ATSC" );
922     cqam = new QRadioButton( "Clear QAM" );
923     dvbt->setChecked( true );
924
925     dvbDevLayout->addWidget( dvbTypeLabel, 1, 0, 2, 1 );
926     dvbDevLayout->addWidget( dvbc,  1, 1 );
927     dvbDevLayout->addWidget( dvbs,  1, 2 );
928     dvbDevLayout->addWidget( dvbs2, 2, 2 );
929     dvbDevLayout->addWidget( dvbt,  1, 3 );
930     dvbDevLayout->addWidget( dvbt2, 2, 3 );
931     dvbDevLayout->addWidget( atsc,  1, 4 );
932     dvbDevLayout->addWidget( cqam,  2, 4 );
933
934     /* DVB Props panel */
935     QLabel *dvbFreqLabel =
936                     new QLabel( qtr( "Transponder/multiplex frequency" ) );
937     dvbPropLayout->addWidget( dvbFreqLabel, 0, 0 );
938
939     dvbFreq = new QSpinBox;
940     dvbFreq->setAlignment( Qt::AlignRight );
941     dvbFreq->setSuffix(" kHz");
942     dvbFreq->setSingleStep( 1000 );
943     setSpinBoxFreq( dvbFreq  );
944     dvbPropLayout->addWidget( dvbFreq, 0, 1 );
945
946     dvbSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
947     dvbPropLayout->addWidget( dvbSrateLabel, 1, 0 );
948
949     dvbSrate = new QSpinBox;
950     dvbSrate->setAlignment( Qt::AlignRight );
951     dvbSrate->setSuffix(" bauds");
952     setSpinBoxFreq( dvbSrate );
953     dvbPropLayout->addWidget( dvbSrate, 1, 1 );
954
955     dvbModLabel = new QLabel( qtr( "Modulation / Constellation" ) );
956     dvbPropLayout->addWidget( dvbModLabel, 2, 0 );
957
958     dvbQamBox = new QComboBox;
959     dvbQamBox->addItem( qtr( "Automatic" ), qfu("QAM") );
960     dvbQamBox->addItem( "256-QAM", qfu("256QAM") );
961     dvbQamBox->addItem( "128-QAM", qfu("128QAM") );
962     dvbQamBox->addItem( "64-QAM", qfu("64QAM") );
963     dvbQamBox->addItem( "32-QAM", qfu("32QAM") );
964     dvbQamBox->addItem( "16-QAM", qfu("16QAM") );
965     dvbPropLayout->addWidget( dvbQamBox, 2, 1 );
966
967     dvbPskBox = new QComboBox;
968     dvbPskBox->addItem( "QPSK", qfu("QPSK") );
969     dvbPskBox->addItem( "DQPSK", qfu("DQPSK") );
970     dvbPskBox->addItem( "8-PSK", qfu("8PSK") );
971     dvbPskBox->addItem( "16-APSK", qfu("16APSK") );
972     dvbPskBox->addItem( "32-APSK", qfu("32APSK") );
973     dvbPropLayout->addWidget( dvbPskBox, 2, 1 );
974
975     dvbModLabel->hide();
976     dvbQamBox->hide();
977     dvbPskBox->hide();
978
979     dvbBandLabel = new QLabel( qtr( "Bandwidth" ) );
980     dvbPropLayout->addWidget( dvbBandLabel, 2, 0 );
981
982     dvbBandBox = new QComboBox;
983     setfillVLCConfigCombo( "dvb-bandwidth", p_intf, dvbBandBox );
984     dvbPropLayout->addWidget( dvbBandBox, 2, 1 );
985
986     dvbBandLabel->hide();
987     dvbBandBox->hide();
988
989     dvbPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
990             2, 0, 2, 1 );
991
992     /* DVB CONNECTs */
993     CuMRL( dvbCard, valueChanged ( int ) );
994     CuMRL( dvbFreq, valueChanged ( int ) );
995     CuMRL( dvbSrate, valueChanged ( int ) );
996     CuMRL( dvbQamBox, currentIndexChanged ( int ) );
997     CuMRL( dvbPskBox, currentIndexChanged ( int ) );
998     CuMRL( dvbBandBox, currentIndexChanged ( int ) );
999
1000     BUTTONACT( dvbc, updateButtons() );
1001     BUTTONACT( dvbs, updateButtons() );
1002     BUTTONACT( dvbs2, updateButtons() );
1003     BUTTONACT( dvbt, updateButtons() );
1004     BUTTONACT( dvbt2, updateButtons() );
1005     BUTTONACT( atsc, updateButtons() );
1006     BUTTONACT( cqam, updateButtons() );
1007     BUTTONACT( dvbc, updateMRL() );
1008     BUTTONACT( dvbt, updateMRL() );
1009     BUTTONACT( dvbt2, updateMRL() );
1010     BUTTONACT( dvbs, updateMRL() );
1011     BUTTONACT( dvbs2, updateMRL() );
1012     BUTTONACT( atsc, updateMRL() );
1013     BUTTONACT( cqam, updateMRL() );
1014     }
1015
1016     /**********
1017      * Screen *
1018      **********/
1019     addModuleAndLayouts( SCREEN_DEVICE, screen, "Desktop", QGridLayout );
1020     QLabel *screenLabel = new QLabel( qtr( "Your display will be "
1021             "opened and played in order to stream or save it." ) );
1022     screenLabel->setWordWrap( true );
1023     screenDevLayout->addWidget( screenLabel, 0, 0 );
1024
1025     QLabel *screenFPSLabel = new QLabel(
1026             qtr( "Desired frame rate for the capture." ) );
1027     screenPropLayout->addWidget( screenFPSLabel, 0, 0 );
1028
1029     screenFPS = new QDoubleSpinBox;
1030     screenFPS->setValue( 1. );
1031     screenFPS->setRange( .01, 100. );
1032     screenFPS->setAlignment( Qt::AlignRight );
1033     /* xgettext: frames per second */
1034     screenFPS->setSuffix( qtr( " f/s" ) );
1035     screenPropLayout->addWidget( screenFPS, 0, 1 );
1036
1037     /* Screen connect */
1038     CuMRL( screenFPS, valueChanged( double ) );
1039
1040     /* General connects */
1041     CONNECT( ui.deviceCombo, activated( int ) ,
1042              stackedDevLayout, setCurrentIndex( int ) );
1043     CONNECT( ui.deviceCombo, activated( int ),
1044              stackedPropLayout, setCurrentIndex( int ) );
1045     CONNECT( ui.deviceCombo, activated( int ), this, updateMRL() );
1046     CONNECT( ui.deviceCombo, activated( int ), this, updateButtons() );
1047
1048 #undef CuMRL
1049 #undef addModuleAndLayouts
1050 }
1051
1052 CaptureOpenPanel::~CaptureOpenPanel()
1053 {
1054 }
1055
1056 void CaptureOpenPanel::clear()
1057 {
1058     advMRL.clear();
1059 }
1060
1061 void CaptureOpenPanel::updateMRL()
1062 {
1063     QString mrl = "";
1064     QStringList fileList;
1065     int i_devicetype = ui.deviceCombo->itemData(
1066             ui.deviceCombo->currentIndex() ).toInt();
1067     switch( i_devicetype )
1068     {
1069 #ifdef WIN32
1070     case DSHOW_DEVICE:
1071         fileList << "dshow://";
1072         mrl+= " :dshow-vdev=" +
1073             colon_escape( QString("%1").arg( vdevDshowW->getValue() ) );
1074         mrl+= " :dshow-adev=" +
1075             colon_escape( QString("%1").arg( adevDshowW->getValue() ) )+" ";
1076         if( dshowVSizeLine->isModified() )
1077             mrl += ":dshow-size=" + dshowVSizeLine->text();
1078         break;
1079 #else
1080     case V4L2_DEVICE:
1081         fileList << "v4l2://" + v4l2VideoDevice->currentText();
1082         mrl += ":v4l2-standard="
1083             + v4l2StdBox->itemData( v4l2StdBox->currentIndex() ).toString();
1084         mrl += " :input-slave=alsa://" + v4l2AudioDevice->currentText();
1085         break;
1086     case JACK_DEVICE:
1087         mrl = "jack://";
1088         mrl += "channels=" + QString::number( jackChannels->value() );
1089         mrl += ":ports=" + jackPortsSelected->text();
1090         fileList << mrl; mrl = "";
1091
1092         if ( jackPace->isChecked() )
1093         {
1094                 mrl += " :jack-input-use-vlc-pace";
1095         }
1096         if ( jackConnect->isChecked() )
1097         {
1098                 mrl += " :jack-input-auto-connect";
1099         }
1100         break;
1101     case PVR_DEVICE:
1102         fileList << "pvr://";
1103         mrl += " :pvr-device=" + pvrDevice->text();
1104         mrl += " :pvr-radio-device=" + pvrRadioDevice->text();
1105         mrl += " :pvr-norm=" + QString::number( pvrNormBox->currentIndex() );
1106         if( pvrFreq->value() )
1107             mrl += " :pvr-frequency=" + QString::number( pvrFreq->value() );
1108         if( pvrBitr->value() )
1109             mrl += " :pvr-bitrate=" + QString::number( pvrBitr->value() );
1110         break;
1111 #endif
1112     case DTV_DEVICE:
1113         if( dvbc->isChecked() ) mrl = "dvb-c://";
1114         else
1115         if( dvbs->isChecked() ) mrl = "dvb-s://";
1116         else
1117         if( dvbs2->isChecked() ) mrl = "dvb-s2://";
1118         else
1119         if( dvbt->isChecked() ) mrl = "dvb-t://";
1120         else
1121         if( dvbt2->isChecked() ) mrl = "dvb-t2://";
1122         else
1123         if( atsc->isChecked() ) mrl = "atsc://";
1124         else
1125         if( cqam->isChecked() ) mrl = "cqam://";
1126
1127         mrl += "frequency=" + QString::number( dvbFreq->value() ) + "000";
1128
1129         if( dvbc->isChecked() || cqam->isChecked() )
1130             mrl += ":modulation="
1131                 + dvbQamBox->itemData( dvbQamBox->currentIndex() ).toString();
1132         if( dvbs2->isChecked() )
1133             mrl += ":modulation="
1134                 + dvbPskBox->itemData( dvbPskBox->currentIndex() ).toString();
1135         if( dvbc->isChecked() || dvbs->isChecked() || dvbs2->isChecked() )
1136             mrl += ":srate=" + QString::number( dvbSrate->value() );
1137         if( dvbt->isChecked() || dvbt2->isChecked() )
1138             mrl += ":bandwidth=" +
1139                 QString::number( dvbBandBox->itemData(
1140                     dvbBandBox->currentIndex() ).toInt() );
1141
1142         fileList << mrl; mrl= "";
1143         mrl += " :dvb-adapter=" + QString::number( dvbCard->value() );
1144         break;
1145     case SCREEN_DEVICE:
1146         fileList << "screen://";
1147         mrl = " :screen-fps=" + QString::number( screenFPS->value(), 'f' );
1148         updateButtons();
1149         break;
1150     }
1151     emit methodChanged( "live-caching" );
1152
1153     if( !advMRL.isEmpty() ) mrl += advMRL;
1154
1155     emit mrlUpdated( fileList, mrl );
1156 }
1157
1158 /**
1159  * Update the Buttons (show/hide) for the GUI as all device type don't
1160  * use the same ui. elements.
1161  **/
1162 void CaptureOpenPanel::updateButtons()
1163 {
1164     /*  Be sure to display the ui Elements in case they were hidden by
1165      *  some Device Type (like Screen://) */
1166     ui.optionsBox->show();
1167     ui.advancedButton->show();
1168     /* Get the current Device Number */
1169     int i_devicetype = ui.deviceCombo->itemData(
1170                                 ui.deviceCombo->currentIndex() ).toInt();
1171     switch( i_devicetype )
1172     {
1173     case DTV_DEVICE:
1174         dvbSrate->hide();
1175         dvbSrateLabel->hide();
1176         dvbQamBox->hide();
1177         dvbPskBox->hide();
1178         dvbModLabel->hide();
1179         dvbBandBox->hide();
1180         dvbBandLabel->hide();
1181
1182         if( dvbc->isChecked() )
1183         {
1184             dvbSrate->show();
1185             dvbSrateLabel->show();
1186             dvbQamBox->show();
1187             dvbModLabel->show();
1188         }
1189         else if( dvbs->isChecked() )
1190         {
1191             dvbSrate->show();
1192             dvbSrateLabel->show();
1193         }
1194         else if( dvbs2->isChecked() )
1195         {
1196             dvbSrate->show();
1197             dvbSrateLabel->show();
1198             dvbPskBox->show();
1199             dvbModLabel->show();
1200         }
1201         else if( dvbt->isChecked() || dvbt2->isChecked() )
1202         {
1203             dvbBandBox->show();
1204             dvbBandLabel->show();
1205         }
1206         break;
1207     case SCREEN_DEVICE:
1208         //ui.optionsBox->hide();
1209         ui.advancedButton->hide();
1210         break;
1211     }
1212
1213     advMRL.clear();
1214 }
1215
1216 void CaptureOpenPanel::advancedDialog()
1217 {
1218     /* Get selected device type */
1219     int i_devicetype = ui.deviceCombo->itemData(
1220                                 ui.deviceCombo->currentIndex() ).toInt();
1221
1222     /* Get the corresponding module */
1223     module_t *p_module =
1224         module_find( psz_devModule[i_devicetype] );
1225     if( NULL == p_module ) return;
1226
1227     /* Init */
1228     QList<ConfigControl *> controls;
1229
1230     /* Get the confsize  */
1231     unsigned int i_confsize;
1232     module_config_t *p_config;
1233     p_config = module_config_get( p_module, &i_confsize );
1234
1235     /* New Adv Prop dialog */
1236     adv = new QDialog( this );
1237     adv->setWindowTitle( qtr( "Advanced Options" ) );
1238     adv->setWindowRole( "vlc-advanced-options" );
1239
1240     /* A main Layout with a Frame */
1241     QVBoxLayout *mainLayout = new QVBoxLayout( adv );
1242     QScrollArea *scroll = new QScrollArea;
1243     mainLayout->addWidget( scroll );
1244
1245     QFrame *advFrame = new QFrame;
1246     /* GridLayout inside the Frame */
1247     QGridLayout *gLayout = new QGridLayout( advFrame );
1248
1249     scroll->setWidgetResizable( true );
1250     scroll->setWidget( advFrame );
1251
1252     /* Create the options inside the FrameLayout */
1253     for( int n = 0; n < (int)i_confsize; n++ )
1254     {
1255         module_config_t *p_item = p_config + n;
1256         ConfigControl *config = ConfigControl::createControl(
1257                         VLC_OBJECT( p_intf ), p_item, advFrame, gLayout, n );
1258         if ( config )
1259             controls.append( config );
1260     }
1261
1262     /* Button stuffs */
1263     QDialogButtonBox *advButtonBox = new QDialogButtonBox( adv );
1264     QPushButton *closeButton = new QPushButton( qtr( "OK" ) );
1265     QPushButton *cancelButton = new QPushButton( qtr( "Cancel" ) );
1266
1267     CONNECT( closeButton, clicked(), adv, accept() );
1268     CONNECT( cancelButton, clicked(), adv, reject() );
1269
1270     advButtonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
1271     advButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
1272
1273     mainLayout->addWidget( advButtonBox );
1274
1275     /* Creation of the MRL */
1276     if( adv->exec() )
1277     {
1278         QString tempMRL = "";
1279         for( int i = 0; i < controls.count(); i++ )
1280         {
1281             ConfigControl *control = controls[i];
1282
1283             tempMRL += (i ? " :" : ":");
1284
1285             if( control->getType() == CONFIG_ITEM_BOOL )
1286                 if( !(qobject_cast<VIntConfigControl *>(control)->getValue() ) )
1287                     tempMRL += "no-";
1288
1289             tempMRL += control->getName();
1290
1291             switch( control->getType() )
1292             {
1293                 case CONFIG_ITEM_STRING:
1294                 case CONFIG_ITEM_LOADFILE:
1295                 case CONFIG_ITEM_SAVEFILE:
1296                 case CONFIG_ITEM_DIRECTORY:
1297                 case CONFIG_ITEM_MODULE:
1298                     tempMRL += colon_escape( QString("=%1").arg( qobject_cast<VStringConfigControl *>(control)->getValue() ) );
1299                     break;
1300                 case CONFIG_ITEM_INTEGER:
1301                     tempMRL += QString("=%1").arg( qobject_cast<VIntConfigControl *>(control)->getValue() );
1302                     break;
1303                 case CONFIG_ITEM_FLOAT:
1304                     tempMRL += QString("=%1").arg( qobject_cast<VFloatConfigControl *>(control)->getValue() );
1305                     break;
1306             }
1307         }
1308         advMRL = tempMRL;
1309         updateMRL();
1310         msg_Dbg( p_intf, "%s", qtu( advMRL ) );
1311     }
1312     qDeleteAll( controls );
1313     delete adv;
1314     module_config_free( p_config );
1315 }
1316