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