]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/open_panels.cpp
Qt4: remove V4L1
[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                 ui.deviceCombo->addItem( drive );
359
360             /* go to next drive */
361             while( *(drive++) );
362         }
363         SetErrorMode(oldMode);
364     }
365 #else /* Linux */
366     char const * const ppsz_discdevices[] = {
367         "sr*",
368         "sg*",
369         "scd*",
370         "dvd*",
371         "cd*"
372     };
373     QComboBox *discCombo = ui.deviceCombo; /* avoid namespacing in macro */
374     POPULATE_WITH_DEVS( ppsz_discdevices, discCombo );
375 #endif
376
377     /* CONNECTs */
378     BUTTONACT( ui.dvdRadioButton, updateButtons() );
379     BUTTONACT( ui.vcdRadioButton, updateButtons() );
380     BUTTONACT( ui.audioCDRadioButton, updateButtons() );
381     BUTTONACT( ui.dvdsimple, updateButtons() );
382     BUTTONACT( ui.browseDiscButton, browseDevice() );
383     BUTTON_SET_ACT_I( ui.ejectButton, "", toolbar/eject, qtr( "Eject the disc" ),
384             eject() );
385
386     CONNECT( ui.deviceCombo, editTextChanged( QString ), this, updateMRL());
387     CONNECT( ui.titleSpin, valueChanged( int ), this, updateMRL());
388     CONNECT( ui.chapterSpin, valueChanged( int ), this, updateMRL());
389     CONNECT( ui.audioSpin, valueChanged( int ), this, updateMRL());
390     CONNECT( ui.subtitlesSpin, valueChanged( int ), this, updateMRL());
391
392     /* Run once the updateButtons function in order to fill correctly the comboBoxes */
393     updateButtons();
394 }
395
396 DiscOpenPanel::~DiscOpenPanel()
397 {
398     free( psz_dvddiscpath );
399     free( psz_vcddiscpath );
400     free( psz_cddadiscpath );
401 }
402
403 void DiscOpenPanel::clear()
404 {
405     ui.titleSpin->setValue( 0 );
406     ui.chapterSpin->setValue( 0 );
407     ui.subtitlesSpin->setValue( -1 );
408     ui.audioSpin->setValue( -1 );
409     m_discType = None;
410 }
411
412 #ifdef WIN32
413     #define setDrive( psz_name ) {\
414     int index = ui.deviceCombo->findText( qfu( psz_name ) ); \
415     if( index != -1 ) ui.deviceCombo->setCurrentIndex( index );}
416 #else
417     #define setDrive( psz_name ) {\
418     ui.deviceCombo->setEditText( qfu( psz_name ) ); }
419 #endif
420
421 /* update the buttons according the type of device */
422 void DiscOpenPanel::updateButtons()
423 {
424     if ( ui.dvdRadioButton->isChecked() )
425     {
426         if( m_discType != Dvd )
427         {
428             setDrive( psz_dvddiscpath );
429             m_discType = Dvd;
430         }
431         ui.titleLabel->setText( qtr("Title") );
432         ui.chapterLabel->show();
433         ui.chapterSpin->show();
434         ui.diskOptionBox_2->show();
435         ui.dvdsimple->setEnabled( true );
436     }
437     else if ( ui.vcdRadioButton->isChecked() )
438     {
439         if( m_discType != Vcd )
440         {
441             setDrive( psz_vcddiscpath );
442             m_discType = Vcd;
443         }
444         ui.titleLabel->setText( qtr("Entry") );
445         ui.chapterLabel->hide();
446         ui.chapterSpin->hide();
447         ui.diskOptionBox_2->show();
448         ui.dvdsimple->setEnabled( false );
449     }
450     else /* CDDA */
451     {
452         if( m_discType != Cdda )
453         {
454             setDrive( psz_cddadiscpath );
455             m_discType = Cdda;
456         }
457         ui.titleLabel->setText( qtr("Track") );
458         ui.chapterLabel->hide();
459         ui.chapterSpin->hide();
460         ui.diskOptionBox_2->hide();
461         ui.dvdsimple->setEnabled( false );
462     }
463
464     updateMRL();
465 }
466
467 #undef setDrive
468
469 #ifndef WIN32
470 # define LOCALHOST ""
471 #else
472 # define LOCALHOST "/"
473 #endif
474
475 /* Update the current MRL */
476 void DiscOpenPanel::updateMRL()
477 {
478     QString mrl = "";
479     QStringList fileList;
480
481     /* CDDAX and VCDX not implemented. TODO ? No. */
482     /* DVD */
483     if( ui.dvdRadioButton->isChecked() ) {
484         if( !ui.dvdsimple->isChecked() )
485             mrl = "dvd://" LOCALHOST;
486         else
487             mrl = "dvdsimple://" LOCALHOST;
488         mrl += ui.deviceCombo->currentText();
489         if( !ui.dvdsimple->isChecked() )
490             emit methodChanged( "dvdnav-caching" );
491         else
492             emit methodChanged( "dvdread-caching" );
493
494         if ( ui.titleSpin->value() > 0 ) {
495             mrl += QString("@%1").arg( ui.titleSpin->value() );
496             if ( ui.chapterSpin->value() > 0 ) {
497                 mrl+= QString(":%1").arg( ui.chapterSpin->value() );
498             }
499         }
500
501     /* VCD */
502     } else if ( ui.vcdRadioButton->isChecked() ) {
503         mrl = "vcd://" LOCALHOST + ui.deviceCombo->currentText();
504         emit methodChanged( "vcd-caching" );
505
506         if( ui.titleSpin->value() > 0 ) {
507             mrl += QString("@E%1").arg( ui.titleSpin->value() );
508         }
509
510     /* CDDA */
511     } else {
512         mrl = "cdda://" LOCALHOST + ui.deviceCombo->currentText();
513         emit methodChanged( "cdda-caching" );
514     }
515
516     fileList << mrl; mrl = "";
517
518     if ( ui.dvdRadioButton->isChecked() || ui.vcdRadioButton->isChecked() )
519     {
520         if ( ui.audioSpin->value() >= 0 ) {
521             mrl += " :audio-track=" +
522                 QString("%1").arg( ui.audioSpin->value() );
523         }
524         if ( ui.subtitlesSpin->value() >= 0 ) {
525             mrl += " :sub-track=" +
526                 QString("%1").arg( ui.subtitlesSpin->value() );
527         }
528     }
529     else
530     {
531         if( ui.titleSpin->value() > 0 )
532             mrl += QString(" :cdda-track=%1").arg( ui.titleSpin->value() );
533     }
534     emit mrlUpdated( fileList, mrl );
535 }
536
537 void DiscOpenPanel::browseDevice()
538 {
539     QString dir = QFileDialog::getExistingDirectory( this,
540             qtr( I_DEVICE_TOOLTIP ) );
541     if (!dir.isEmpty())
542         ui.deviceCombo->setEditText( toNativeSepNoSlash( dir ) );
543
544     updateMRL();
545 }
546
547 void DiscOpenPanel::eject()
548 {
549     intf_Eject( p_intf, qtu( ui.deviceCombo->currentText() ) );
550 }
551
552 void DiscOpenPanel::accept()
553 {}
554
555 /**************************************************************************
556  * Open Network streams and URL pages                                     *
557  **************************************************************************/
558 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
559                                 OpenPanel( _parent, _p_intf )
560 {
561     ui.setupUi( this );
562
563     /* CONNECTs */
564     CONNECT( ui.urlComboBox->lineEdit(), textChanged( const QString& ), this, updateMRL());
565     CONNECT( ui.urlComboBox, currentIndexChanged( const QString& ), this, updateMRL());
566
567     if( var_InheritBool( p_intf, "qt-recentplay" ) )
568     {
569         mrlList = new QStringListModel(
570                 getSettings()->value( "Open/netMRL" ).toStringList() );
571         ui.urlComboBox->setModel( mrlList );
572         ui.urlComboBox->clearEditText();
573         CONNECT( ui.urlComboBox->lineEdit(), editingFinished(), this, updateModel() );
574     }
575     else
576         mrlList = NULL;
577
578     ui.urlComboBox->setValidator( new UrlValidator( this ) );
579     ui.urlComboBox->setFocus();
580 }
581
582 NetOpenPanel::~NetOpenPanel()
583 {
584     if( !mrlList ) return;
585
586     QStringList tempL = mrlList->stringList();
587     while( tempL.size() > 8 ) tempL.removeFirst();
588
589     getSettings()->setValue( "Open/netMRL", tempL );
590
591     delete mrlList;
592 }
593
594 void NetOpenPanel::clear()
595 {}
596
597 void NetOpenPanel::onFocus()
598 {
599     ui.urlComboBox->setFocus();
600     ui.urlComboBox->lineEdit()->selectAll();
601 }
602
603 static int strcmp_void( const void *k, const void *e )
604 {
605     return strcmp( (const char *)k, (const char *)e );
606 }
607
608 void NetOpenPanel::updateMRL()
609 {
610     static const struct caching_map
611     {
612         char proto[6];
613         char caching[6];
614     } schemes[] =
615     {   /* KEEP alphabetical order on first column!! */
616         { "dccp",  "rtp"   },
617         { "ftp",   "ftp"   },
618         { "ftps",  "ftp"   },
619         { "http",  "http"  },
620         { "https", "http"  },
621         { "mms",   "mms"   },
622         { "mmsh",  "mms"   },
623         { "mmst",  "mms"   },
624         { "mmsu",  "mms"   },
625         { "sftp",  "sftp"  },
626         { "smb",   "smb"   },
627         { "rtmp",  "rtmp"  },
628         { "rtp",   "rtp"   },
629         { "rtsp",  "rtsp"  },
630         { "udp",   "udp"   },
631     };
632
633     QString url = ui.urlComboBox->lineEdit()->text();
634     if( !url.contains( "://") )
635         return; /* nothing to do this far */
636
637     /* Match the correct item in the comboBox */
638     QString proto = url.section( ':', 0, 0 );
639     const struct caching_map *r = (const struct caching_map *)
640         bsearch( qtu(proto), schemes, sizeof(schemes) / sizeof(schemes[0]),
641                  sizeof(schemes[0]), strcmp_void );
642     if( r )
643         emit methodChanged( qfu( r->caching ) + qfu( "-caching" ) );
644
645     QStringList qsl;
646     qsl << url;
647     emit mrlUpdated( qsl, "" );
648 }
649
650 void NetOpenPanel::updateModel()
651 {
652     assert( mrlList );
653     QStringList tempL = mrlList->stringList();
654     if( !tempL.contains( ui.urlComboBox->lineEdit()->text() ) )
655         tempL.append( ui.urlComboBox->lineEdit()->text() );
656     mrlList->setStringList( tempL );
657 }
658
659 void UrlValidator::fixup( QString& str ) const
660 {
661     str = str.trimmed();
662 }
663
664 QValidator::State UrlValidator::validate( QString& str, int& pos ) const
665 {
666     if( str.contains( ' ' ) )
667         return QValidator::Invalid;
668     if( !str.contains( "://" ) )
669         return QValidator::Intermediate;
670     return QValidator::Acceptable;
671 }
672
673 /**************************************************************************
674  * Open Capture device ( DVB, PVR, V4L, and similar )                     *
675  **************************************************************************/
676 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
677                                 OpenPanel( _parent, _p_intf )
678 {
679     isInitialized = false;
680 }
681
682 void CaptureOpenPanel::initialize()
683 {
684     if( isInitialized ) return;
685
686     msg_Dbg( p_intf, "Initialization of Capture device panel" );
687     isInitialized = true;
688
689     ui.setupUi( this );
690
691     BUTTONACT( ui.advancedButton, advancedDialog() );
692
693     /* Create two stacked layouts in the main comboBoxes */
694     QStackedLayout *stackedDevLayout = new QStackedLayout;
695     ui.cardBox->setLayout( stackedDevLayout );
696
697     QStackedLayout *stackedPropLayout = new QStackedLayout;
698     ui.optionsBox->setLayout( stackedPropLayout );
699
700     /* Creation and connections of the WIdgets in the stacked layout */
701 #define addModuleAndLayouts( number, name, label, layout )            \
702     QWidget * name ## DevPage = new QWidget( this );                  \
703     QWidget * name ## PropPage = new QWidget( this );                 \
704     stackedDevLayout->addWidget( name ## DevPage );        \
705     stackedPropLayout->addWidget( name ## PropPage );      \
706     layout * name ## DevLayout = new layout;                \
707     layout * name ## PropLayout = new layout;               \
708     name ## DevPage->setLayout( name ## DevLayout );                  \
709     name ## PropPage->setLayout( name ## PropLayout );                \
710     ui.deviceCombo->addItem( qtr( label ), QVariant( number ) );
711
712 #define CuMRL( widget, slot ) CONNECT( widget , slot , this, updateMRL() );
713
714 #ifdef WIN32
715     /*********************
716      * DirectShow Stuffs *
717      *********************/
718     if( module_exists( "dshow" ) ){
719     addModuleAndLayouts( DSHOW_DEVICE, dshow, "DirectShow", QGridLayout );
720
721     /* dshow Main */
722     int line = 0;
723     module_config_t *p_config =
724         config_FindConfig( VLC_OBJECT(p_intf), "dshow-vdev" );
725     vdevDshowW = new StringListConfigControl(
726         VLC_OBJECT(p_intf), p_config, this, false, dshowDevLayout, line );
727     line++;
728
729     p_config = config_FindConfig( VLC_OBJECT(p_intf), "dshow-adev" );
730     adevDshowW = new StringListConfigControl(
731         VLC_OBJECT(p_intf), p_config, this, false, dshowDevLayout, line );
732     line++;
733
734     /* dshow Properties */
735     QLabel *dshowVSizeLabel = new QLabel( qtr( "Video size" ) );
736     dshowPropLayout->addWidget( dshowVSizeLabel, 0, 0 );
737
738     dshowVSizeLine = new QLineEdit;
739     dshowPropLayout->addWidget( dshowVSizeLine, 0, 1);
740     dshowPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
741             1, 0, 3, 1 );
742
743     /* dshow CONNECTs */
744     CuMRL( vdevDshowW->combo, currentIndexChanged ( int ) );
745     CuMRL( adevDshowW->combo, currentIndexChanged ( int ) );
746     CuMRL( dshowVSizeLine, textChanged( const QString& ) );
747     }
748
749     /**************
750      * BDA Stuffs *
751      **************/
752     if( module_exists( "bda" ) ){
753     addModuleAndLayouts( BDA_DEVICE, bda, "DVB DirectShow", QGridLayout );
754
755     /* bda Main */
756     QLabel *bdaTypeLabel = new QLabel( qtr( "DVB Type:" ) );
757
758     bdas = new QRadioButton( "DVB-S" );
759     bdas->setChecked( true );
760     bdac = new QRadioButton( "DVB-C" );
761     bdat = new QRadioButton( "DVB-T" );
762     bdaa = new QRadioButton( "ATSC" );
763     bdaq = new QRadioButton( "Clear QAM" );
764
765     bdaDevLayout->addWidget( bdaTypeLabel, 0, 0 );
766     bdaDevLayout->addWidget( bdas, 0, 1 );
767     bdaDevLayout->addWidget( bdac, 0, 2 );
768     bdaDevLayout->addWidget( bdat, 0, 3 );
769     bdaDevLayout->addWidget( bdaa, 0, 4 );
770     bdaDevLayout->addWidget( bdaq, 0, 5 );
771
772     /* bda Props */
773     QLabel *bdaFreqLabel =
774                     new QLabel( qtr( "Transponder/multiplex frequency" ) );
775     bdaPropLayout->addWidget( bdaFreqLabel, 0, 0 );
776
777     bdaFreq = new QSpinBox;
778     bdaFreq->setAlignment( Qt::AlignRight );
779     bdaFreq->setSuffix(" kHz");
780     bdaFreq->setSingleStep( 1000 );
781     setSpinBoxFreq( bdaFreq )
782     bdaPropLayout->addWidget( bdaFreq, 0, 1 );
783
784     bdaSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
785     bdaPropLayout->addWidget( bdaSrateLabel, 1, 0 );
786
787     bdaSrate = new QSpinBox;
788     bdaSrate->setAlignment( Qt::AlignRight );
789     bdaSrate->setSuffix(" kHz");
790     setSpinBoxFreq( bdaSrate );
791     bdaPropLayout->addWidget( bdaSrate, 1, 1 );
792
793     bdaBandLabel = new QLabel( qtr( "Bandwidth" ) );
794     bdaPropLayout->addWidget( bdaBandLabel, 2, 0 );
795
796     bdaBandBox = new QComboBox;
797     setfillVLCConfigCombo( "dvb-bandwidth", p_intf, bdaBandBox );
798     bdaPropLayout->addWidget( bdaBandBox, 2, 1 );
799
800     bdaBandLabel->hide();
801     bdaBandBox->hide();
802     bdaPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
803             2, 0, 2, 1 );
804
805     /* bda CONNECTs */
806     CuMRL( bdaFreq, valueChanged ( int ) );
807     CuMRL( bdaSrate, valueChanged ( int ) );
808     CuMRL( bdaBandBox,  currentIndexChanged ( int ) );
809     BUTTONACT( bdas, updateButtons() );
810     BUTTONACT( bdat, updateButtons() );
811     BUTTONACT( bdac, updateButtons() );
812     BUTTONACT( bdaa, updateButtons() );
813     BUTTONACT( bdaq, updateButtons() );
814     BUTTONACT( bdas, updateMRL() );
815     BUTTONACT( bdat, updateMRL() );
816     BUTTONACT( bdac, updateMRL() );
817     BUTTONACT( bdaa, updateMRL() );
818     BUTTONACT( bdaq, updateMRL() );
819     }
820
821 #else /* WIN32 */
822     /*******
823      * V4L2*
824      *******/
825     if( module_exists( "v4l2" ) ){
826     addModuleAndLayouts( V4L2_DEVICE, v4l2, "Video for Linux 2", QGridLayout );
827
828     char const * const ppsz_v4lvdevices[] = {
829         "video*"
830     };
831
832     char const * const ppsz_v4ladevices[] = {
833         "dsp*",
834         "radio*"
835     };
836
837     /* V4l Main panel */
838     QLabel *v4l2VideoDeviceLabel = new QLabel( qtr( "Video device name" ) );
839     v4l2DevLayout->addWidget( v4l2VideoDeviceLabel, 0, 0 );
840
841     v4l2VideoDevice = new QComboBox( this );
842     v4l2VideoDevice->setEditable( true );
843     POPULATE_WITH_DEVS( ppsz_v4lvdevices, v4l2VideoDevice );
844     v4l2VideoDevice->clearEditText();
845     v4l2DevLayout->addWidget( v4l2VideoDevice, 0, 1 );
846
847     QLabel *v4l2AudioDeviceLabel = new QLabel( qtr( "Audio device name" ) );
848     v4l2DevLayout->addWidget( v4l2AudioDeviceLabel, 1, 0 );
849
850     v4l2AudioDevice = new QComboBox( this );
851     v4l2AudioDevice->setEditable( true );
852     POPULATE_WITH_DEVS( ppsz_v4ladevices, v4l2AudioDevice );
853     v4l2AudioDevice->clearEditText();
854     v4l2DevLayout->addWidget( v4l2AudioDevice, 1, 1 );
855
856     /* v4l2 Props panel */
857     QLabel *v4l2StdLabel = new QLabel( qtr( "Video standard" ) );
858     v4l2PropLayout->addWidget( v4l2StdLabel, 0 , 0 );
859
860     v4l2StdBox = new QComboBox;
861     setfillVLCConfigCombo( "v4l2-standard", p_intf, v4l2StdBox );
862     v4l2PropLayout->addWidget( v4l2StdBox, 0 , 1 );
863     v4l2PropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
864             1, 0, 3, 2 );
865
866     /* v4l2 CONNECTs */
867     CuMRL( v4l2VideoDevice->lineEdit(), textChanged( const QString& ) );
868     CuMRL( v4l2VideoDevice,  currentIndexChanged ( int ) );
869     CuMRL( v4l2AudioDevice->lineEdit(), textChanged( const QString& ) );
870     CuMRL( v4l2AudioDevice,  currentIndexChanged ( int ) );
871     CuMRL( v4l2StdBox,  currentIndexChanged ( int ) );
872     }
873
874     /*******
875      * JACK *
876      *******/
877     if( module_exists( "jack" ) ){
878     addModuleAndLayouts( JACK_DEVICE, jack, "JACK Audio Connection Kit",
879                          QGridLayout);
880
881     /* Jack Main panel */
882     /* Channels */
883     QLabel *jackChannelsLabel = new QLabel( qtr( "Channels:" ) );
884     jackDevLayout->addWidget( jackChannelsLabel, 1, 0 );
885
886     jackChannels = new QSpinBox;
887     setSpinBoxFreq( jackChannels );
888     jackChannels->setMaximum(255);
889     jackChannels->setValue(2);
890     jackChannels->setAlignment( Qt::AlignRight );
891     jackDevLayout->addWidget( jackChannels, 1, 1 );
892
893     /* Selected ports */
894     QLabel *jackPortsLabel = new QLabel( qtr( "Selected ports:" ) );
895     jackDevLayout->addWidget( jackPortsLabel, 0 , 0 );
896
897     jackPortsSelected = new QLineEdit( qtr( ".*") );
898     jackPortsSelected->setAlignment( Qt::AlignRight );
899     jackDevLayout->addWidget( jackPortsSelected, 0, 1 );
900
901     /* Jack Props panel */
902
903     /* Caching */
904     QLabel *jackCachingLabel = new QLabel( qtr( "Input caching:" ) );
905     jackPropLayout->addWidget( jackCachingLabel, 1 , 0 );
906     jackCaching = new QSpinBox;
907     setSpinBoxFreq( jackCaching );
908     jackCaching->setSuffix( " ms" );
909     jackCaching->setValue(1000);
910     jackCaching->setAlignment( Qt::AlignRight );
911     jackPropLayout->addWidget( jackCaching, 1 , 2 );
912
913     /* Pace */
914     jackPace = new QCheckBox(qtr( "Use VLC pace" ));
915     jackPropLayout->addWidget( jackPace, 2, 1 );
916
917     /* Auto Connect */
918     jackConnect = new QCheckBox( qtr( "Auto connection" ));
919     jackPropLayout->addWidget( jackConnect, 2, 2 );
920
921     /* Jack CONNECTs */
922     CuMRL( jackChannels, valueChanged( int ) );
923     CuMRL( jackCaching, valueChanged( int ) );
924     CuMRL( jackPace, stateChanged( int ) );
925     CuMRL( jackConnect, stateChanged( int ) );
926     CuMRL( jackPortsSelected, textChanged( const QString& ) );
927     }
928
929     /************
930      * PVR      *
931      ************/
932     if( module_exists( "pvr" ) ){
933     addModuleAndLayouts( PVR_DEVICE, pvr, "PVR", QGridLayout );
934
935     /* PVR Main panel */
936     QLabel *pvrDeviceLabel = new QLabel( qtr( "Device name" ) );
937     pvrDevLayout->addWidget( pvrDeviceLabel, 0, 0 );
938
939     pvrDevice = new QLineEdit;
940     pvrDevLayout->addWidget( pvrDevice, 0, 1 );
941
942     QLabel *pvrRadioDeviceLabel = new QLabel( qtr( "Radio device name" ) );
943     pvrDevLayout->addWidget( pvrRadioDeviceLabel, 1, 0 );
944
945     pvrRadioDevice = new QLineEdit;
946     pvrDevLayout->addWidget( pvrRadioDevice, 1, 1 );
947
948     /* PVR props panel */
949     QLabel *pvrNormLabel = new QLabel( qtr( "Norm" ) );
950     pvrPropLayout->addWidget( pvrNormLabel, 0, 0 );
951
952     pvrNormBox = new QComboBox;
953     setfillVLCConfigCombo( "pvr-norm", p_intf, pvrNormBox );
954     pvrPropLayout->addWidget( pvrNormBox, 0, 1 );
955
956     QLabel *pvrFreqLabel = new QLabel( qtr( "Frequency" ) );
957     pvrPropLayout->addWidget( pvrFreqLabel, 1, 0 );
958
959     pvrFreq = new QSpinBox;
960     pvrFreq->setAlignment( Qt::AlignRight );
961     pvrFreq->setSuffix(" kHz");
962     setSpinBoxFreq( pvrFreq );
963     pvrPropLayout->addWidget( pvrFreq, 1, 1 );
964
965     QLabel *pvrBitrLabel = new QLabel( qtr( "Bitrate" ) );
966     pvrPropLayout->addWidget( pvrBitrLabel, 2, 0 );
967
968     pvrBitr = new QSpinBox;
969     pvrBitr->setAlignment( Qt::AlignRight );
970     pvrBitr->setSuffix(" kHz");
971     setSpinBoxFreq( pvrBitr );
972     pvrPropLayout->addWidget( pvrBitr, 2, 1 );
973     pvrPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
974             3, 0, 1, 1 );
975
976     /* PVR CONNECTs */
977     CuMRL( pvrDevice, textChanged( const QString& ) );
978     CuMRL( pvrRadioDevice, textChanged( const QString& ) );
979
980     CuMRL( pvrFreq, valueChanged ( int ) );
981     CuMRL( pvrBitr, valueChanged ( int ) );
982     CuMRL( pvrNormBox, currentIndexChanged ( int ) );
983     }
984
985     /**************
986      * DVB Stuffs *
987      **************/
988     if( module_exists( "dvb" ) ){
989     addModuleAndLayouts( DVB_DEVICE, dvb, "DVB", QGridLayout );
990
991     /* DVB Main */
992     QLabel *dvbDeviceLabel = new QLabel( qtr( "Adapter card to tune" ) );
993     QLabel *dvbTypeLabel = new QLabel( qtr( "DVB Type:" ) );
994
995     dvbCard = new QSpinBox;
996     dvbCard->setAlignment( Qt::AlignRight );
997     dvbCard->setPrefix( "/dev/dvb/adapter" );
998
999     dvbDevLayout->addWidget( dvbDeviceLabel, 0, 0 );
1000     dvbDevLayout->addWidget( dvbCard, 0, 2, 1, 2 );
1001
1002     dvbs = new QRadioButton( "DVB-S" );
1003     dvbs->setChecked( true );
1004     dvbc = new QRadioButton( "DVB-C" );
1005     dvbt = new QRadioButton( "DVB-T" );
1006
1007     dvbDevLayout->addWidget( dvbTypeLabel, 1, 0 );
1008     dvbDevLayout->addWidget( dvbs, 1, 1 );
1009     dvbDevLayout->addWidget( dvbc, 1, 2 );
1010     dvbDevLayout->addWidget( dvbt, 1, 3 );
1011
1012     /* DVB Props panel */
1013     QLabel *dvbFreqLabel =
1014                     new QLabel( qtr( "Transponder/multiplex frequency" ) );
1015     dvbPropLayout->addWidget( dvbFreqLabel, 0, 0 );
1016
1017     dvbFreq = new QSpinBox;
1018     dvbFreq->setAlignment( Qt::AlignRight );
1019     dvbFreq->setSuffix(" kHz");
1020     dvbFreq->setSingleStep( 1000 );
1021     setSpinBoxFreq( dvbFreq  );
1022     dvbPropLayout->addWidget( dvbFreq, 0, 1 );
1023
1024     dvbSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
1025     dvbPropLayout->addWidget( dvbSrateLabel, 1, 0 );
1026
1027     dvbSrate = new QSpinBox;
1028     dvbSrate->setAlignment( Qt::AlignRight );
1029     dvbSrate->setSuffix(" kHz");
1030     setSpinBoxFreq( dvbSrate );
1031     dvbPropLayout->addWidget( dvbSrate, 1, 1 );
1032
1033     dvbBandLabel = new QLabel( qtr( "Bandwidth" ) );
1034     dvbPropLayout->addWidget( dvbBandLabel, 2, 0 );
1035
1036     dvbBandBox = new QComboBox;
1037     /* This doesn't work since dvb-bandwidth doesn't seem to be a
1038        list of Integers
1039        setfillVLCConfigCombo( "dvb-bandwidth", p_intf, bdaBandBox );
1040      */
1041     dvbBandBox->addItem( qtr( "Auto" ), 0 );
1042     dvbBandBox->addItem( qtr( "6 MHz" ), 6 );
1043     dvbBandBox->addItem( qtr( "7 MHz" ), 7 );
1044     dvbBandBox->addItem( qtr( "8 MHz" ), 8 );
1045     dvbPropLayout->addWidget( dvbBandBox, 2, 1 );
1046
1047     dvbBandLabel->hide();
1048     dvbBandBox->hide();
1049
1050     dvbPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
1051             2, 0, 2, 1 );
1052
1053     /* DVB CONNECTs */
1054     CuMRL( dvbCard, valueChanged ( int ) );
1055     CuMRL( dvbFreq, valueChanged ( int ) );
1056     CuMRL( dvbSrate, valueChanged ( int ) );
1057     CuMRL( dvbBandBox, currentIndexChanged ( int ) );
1058
1059     BUTTONACT( dvbs, updateButtons() );
1060     BUTTONACT( dvbt, updateButtons() );
1061     BUTTONACT( dvbc, updateButtons() );
1062     BUTTONACT( dvbs, updateMRL() );
1063     BUTTONACT( dvbt, updateMRL() );
1064     BUTTONACT( dvbc, updateMRL() );
1065     }
1066
1067 #endif
1068
1069
1070     /**********
1071      * Screen *
1072      **********/
1073     addModuleAndLayouts( SCREEN_DEVICE, screen, "Desktop", QGridLayout );
1074     QLabel *screenLabel = new QLabel( qtr( "Your display will be "
1075             "opened and played in order to stream or save it." ) );
1076     screenLabel->setWordWrap( true );
1077     screenDevLayout->addWidget( screenLabel, 0, 0 );
1078
1079     QLabel *screenFPSLabel = new QLabel(
1080             qtr( "Desired frame rate for the capture." ) );
1081     screenPropLayout->addWidget( screenFPSLabel, 0, 0 );
1082
1083     screenFPS = new QDoubleSpinBox;
1084     screenFPS->setValue( 1. );
1085     screenFPS->setRange( .01, 100. );
1086     screenFPS->setAlignment( Qt::AlignRight );
1087     /* xgettext: frames per second */
1088     screenFPS->setSuffix( qtr( " f/s" ) );
1089     screenPropLayout->addWidget( screenFPS, 0, 1 );
1090
1091     /* Screen connect */
1092     CuMRL( screenFPS, valueChanged( double ) );
1093
1094     /* General connects */
1095     CONNECT( ui.deviceCombo, activated( int ) ,
1096              stackedDevLayout, setCurrentIndex( int ) );
1097     CONNECT( ui.deviceCombo, activated( int ),
1098              stackedPropLayout, setCurrentIndex( int ) );
1099     CONNECT( ui.deviceCombo, activated( int ), this, updateMRL() );
1100     CONNECT( ui.deviceCombo, activated( int ), this, updateButtons() );
1101
1102 #undef CuMRL
1103 #undef addModuleAndLayouts
1104 }
1105
1106 CaptureOpenPanel::~CaptureOpenPanel()
1107 {
1108 }
1109
1110 void CaptureOpenPanel::clear()
1111 {
1112     advMRL.clear();
1113 }
1114
1115 void CaptureOpenPanel::updateMRL()
1116 {
1117     QString mrl = "";
1118     QStringList fileList;
1119     int i_devicetype = ui.deviceCombo->itemData(
1120             ui.deviceCombo->currentIndex() ).toInt();
1121     switch( i_devicetype )
1122     {
1123 #ifdef WIN32
1124     case BDA_DEVICE:
1125         if( bdas->isChecked() ) mrl = "dvb-s://";
1126         else if(  bdat->isChecked() ) mrl = "dvb-t://";
1127         else if(  bdac->isChecked() ) mrl = "dvb-c://";
1128         else if(  bdaa->isChecked() ) mrl = "atsc://";
1129         else if(  bdaq->isChecked() ) mrl = "cqam://";
1130         else return;
1131         mrl += "frequency=" + QString::number( bdaFreq->value() );
1132         if( bdac->isChecked() || bdat->isChecked() || bdaa->isChecked() )
1133             mrl +="000";
1134         fileList << mrl; mrl = "";
1135
1136         if( bdas->isChecked() || bdac->isChecked() )
1137             mrl += " :dvb-srate=" + QString::number( bdaSrate->value() );
1138         else if( bdat->isChecked() || bdaa->isChecked() )
1139             mrl += " :dvb-bandwidth=" +
1140                 QString::number( bdaBandBox->itemData(
1141                     bdaBandBox->currentIndex() ).toInt() );
1142         emit methodChanged( "dvb-caching" );
1143         break;
1144     case DSHOW_DEVICE:
1145         fileList << "dshow://";
1146         mrl+= " :dshow-vdev=" +
1147             colon_escape( QString("%1").arg( vdevDshowW->getValue() ) );
1148         mrl+= " :dshow-adev=" +
1149             colon_escape( QString("%1").arg( adevDshowW->getValue() ) )+" ";
1150         if( dshowVSizeLine->isModified() )
1151             mrl += ":dshow-size=" + dshowVSizeLine->text();
1152         emit methodChanged( "dshow-caching" );
1153         break;
1154 #else
1155     case V4L2_DEVICE:
1156         fileList << "v4l2://" + v4l2VideoDevice->currentText();
1157         mrl += " :input-slave=alsa://" + v4l2AudioDevice->currentText();
1158         mrl += " :v4l2-standard=" + QString::number( v4l2StdBox->currentIndex() );
1159         break;
1160     case JACK_DEVICE:
1161         mrl = "jack://";
1162         mrl += "channels=" + QString::number( jackChannels->value() );
1163         mrl += ":ports=" + jackPortsSelected->text();
1164         fileList << mrl; mrl = "";
1165
1166         mrl += " :jack-input-caching=" + QString::number( jackCaching->value() );
1167         if ( jackPace->isChecked() )
1168         {
1169                 mrl += " :jack-input-use-vlc-pace";
1170         }
1171         if ( jackConnect->isChecked() )
1172         {
1173                 mrl += " :jack-input-auto-connect";
1174         }
1175         break;
1176     case PVR_DEVICE:
1177         fileList << "pvr://";
1178         mrl += " :pvr-device=" + pvrDevice->text();
1179         mrl += " :pvr-radio-device=" + pvrRadioDevice->text();
1180         mrl += " :pvr-norm=" + QString::number( pvrNormBox->currentIndex() );
1181         if( pvrFreq->value() )
1182             mrl += " :pvr-frequency=" + QString::number( pvrFreq->value() );
1183         if( pvrBitr->value() )
1184             mrl += " :pvr-bitrate=" + QString::number( pvrBitr->value() );
1185         break;
1186     case DVB_DEVICE:
1187         mrl = "dvb://";
1188         mrl += "frequency=" + QString::number( dvbFreq->value() );
1189         if( dvbc->isChecked() || dvbt->isChecked() )
1190             mrl +="000";
1191         fileList << mrl; mrl= "";
1192
1193         mrl += " :dvb-adapter=" + QString::number( dvbCard->value() );
1194         if( dvbs->isChecked() || dvbc->isChecked() )
1195             mrl += " :dvb-srate=" + QString::number( dvbSrate->value() );
1196         else if( dvbt->isChecked() )
1197             mrl += " :dvb-bandwidth=" +
1198                 QString::number( dvbBandBox->itemData(
1199                     dvbBandBox->currentIndex() ).toInt() );
1200
1201         break;
1202 #endif
1203     case SCREEN_DEVICE:
1204         fileList << "screen://";
1205         mrl = " :screen-fps=" + QString::number( screenFPS->value(), 'f' );
1206         emit methodChanged( "screen-caching" );
1207         updateButtons();
1208         break;
1209     }
1210
1211     if( !advMRL.isEmpty() ) mrl += advMRL;
1212
1213     emit mrlUpdated( fileList, mrl );
1214 }
1215
1216 /**
1217  * Update the Buttons (show/hide) for the GUI as all device type don't
1218  * use the same ui. elements.
1219  **/
1220 void CaptureOpenPanel::updateButtons()
1221 {
1222     /*  Be sure to display the ui Elements in case they were hidden by
1223      *  some Device Type (like Screen://) */
1224     ui.optionsBox->show();
1225     ui.advancedButton->show();
1226     /* Get the current Device Number */
1227     int i_devicetype = ui.deviceCombo->itemData(
1228                                 ui.deviceCombo->currentIndex() ).toInt();
1229     switch( i_devicetype )
1230     {
1231 #ifdef WIN32
1232     case BDA_DEVICE:
1233         if( bdas->isChecked() || bdac->isChecked() )
1234         {
1235             bdaSrate->show();
1236             bdaSrateLabel->show();
1237             bdaBandBox->hide();
1238             bdaBandLabel->hide();
1239         }
1240         else if( bdat->isChecked() || bdaa->isChecked() )
1241         {
1242             bdaSrate->hide();
1243             bdaSrateLabel->hide();
1244             bdaBandBox->show();
1245             bdaBandLabel->show();
1246         }
1247         else if( bdaq->isChecked() )
1248         {
1249             bdaSrate->hide();
1250             bdaSrateLabel->hide();
1251             bdaBandBox->hide();
1252             bdaBandLabel->hide();
1253         }
1254         break;
1255 #else
1256     case DVB_DEVICE:
1257         if( dvbs->isChecked() || dvbc->isChecked() )
1258         {
1259             dvbSrate->show();
1260             dvbSrateLabel->show();
1261             dvbBandBox->hide();
1262             dvbBandLabel->hide();
1263         }
1264         else if( dvbt->isChecked() )
1265         {
1266             dvbSrate->hide();
1267             dvbSrateLabel->hide();
1268             dvbBandBox->show();
1269             dvbBandLabel->show();
1270         }
1271         break;
1272 #endif
1273     case SCREEN_DEVICE:
1274         //ui.optionsBox->hide();
1275         ui.advancedButton->hide();
1276         break;
1277     }
1278
1279     advMRL.clear();
1280 }
1281
1282 void CaptureOpenPanel::advancedDialog()
1283 {
1284     /* Get selected device type */
1285     int i_devicetype = ui.deviceCombo->itemData(
1286                                 ui.deviceCombo->currentIndex() ).toInt();
1287
1288     /* Get the corresponding module */
1289     module_t *p_module =
1290         module_find( psz_devModule[i_devicetype] );
1291     if( NULL == p_module ) return;
1292
1293     /* Init */
1294     QList<ConfigControl *> controls;
1295
1296     /* Get the confsize  */
1297     unsigned int i_confsize;
1298     module_config_t *p_config;
1299     p_config = module_config_get( p_module, &i_confsize );
1300
1301     /* New Adv Prop dialog */
1302     adv = new QDialog( this );
1303     adv->setWindowTitle( qtr( "Advanced Options" ) );
1304     adv->setWindowRole( "vlc-advanced-options" );
1305
1306     /* A main Layout with a Frame */
1307     QVBoxLayout *mainLayout = new QVBoxLayout( adv );
1308     QScrollArea *scroll = new QScrollArea;
1309     mainLayout->addWidget( scroll );
1310
1311     QFrame *advFrame = new QFrame;
1312     /* GridLayout inside the Frame */
1313     QGridLayout *gLayout = new QGridLayout( advFrame );
1314
1315     scroll->setWidgetResizable( true );
1316     scroll->setWidget( advFrame );
1317
1318     /* Create the options inside the FrameLayout */
1319     for( int n = 0; n < (int)i_confsize; n++ )
1320     {
1321         module_config_t *p_item = p_config + n;
1322         ConfigControl *config = ConfigControl::createControl(
1323                         VLC_OBJECT( p_intf ), p_item, advFrame, gLayout, n );
1324         if ( config )
1325             controls.append( config );
1326     }
1327
1328     /* Button stuffs */
1329     QDialogButtonBox *advButtonBox = new QDialogButtonBox( adv );
1330     QPushButton *closeButton = new QPushButton( qtr( "OK" ) );
1331     QPushButton *cancelButton = new QPushButton( qtr( "Cancel" ) );
1332
1333     CONNECT( closeButton, clicked(), adv, accept() );
1334     CONNECT( cancelButton, clicked(), adv, reject() );
1335
1336     advButtonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
1337     advButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
1338
1339     mainLayout->addWidget( advButtonBox );
1340
1341     /* Creation of the MRL */
1342     if( adv->exec() )
1343     {
1344         QString tempMRL = "";
1345         for( int i = 0; i < controls.size(); i++ )
1346         {
1347             ConfigControl *control = controls[i];
1348
1349             tempMRL += (i ? " :" : ":");
1350
1351             if( control->getType() == CONFIG_ITEM_BOOL )
1352                 if( !(qobject_cast<VIntConfigControl *>(control)->getValue() ) )
1353                     tempMRL += "no-";
1354
1355             tempMRL += control->getName();
1356
1357             switch( control->getType() )
1358             {
1359                 case CONFIG_ITEM_STRING:
1360                 case CONFIG_ITEM_LOADFILE:
1361                 case CONFIG_ITEM_SAVEFILE:
1362                 case CONFIG_ITEM_DIRECTORY:
1363                 case CONFIG_ITEM_MODULE:
1364                     tempMRL += colon_escape( QString("=%1").arg( qobject_cast<VStringConfigControl *>(control)->getValue() ) );
1365                     break;
1366                 case CONFIG_ITEM_INTEGER:
1367                     tempMRL += QString("=%1").arg( qobject_cast<VIntConfigControl *>(control)->getValue() );
1368                     break;
1369                 case CONFIG_ITEM_FLOAT:
1370                     tempMRL += QString("=%1").arg( qobject_cast<VFloatConfigControl *>(control)->getValue() );
1371                     break;
1372             }
1373         }
1374         advMRL = tempMRL;
1375         updateMRL();
1376         msg_Dbg( p_intf, "%s", qtu( advMRL ) );
1377     }
1378     for( int i = 0; i < controls.size(); i++ )
1379     {
1380         ConfigControl *control = controls[i];
1381         delete control ;
1382     }
1383     delete adv;
1384     module_config_free( p_config );
1385     module_release (p_module);
1386 }
1387