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