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