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