]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/open_panels.cpp
Qt: CaptureOpenPanel: fix layout
[vlc] / modules / gui / qt4 / components / open_panels.cpp
1 /*****************************************************************************
2  * open.cpp : Panels for the open dialogs
3  ****************************************************************************
4  * Copyright (C) 2006-2009 the VideoLAN team
5  * Copyright (C) 2007 Société des arts technologiques
6  * Copyright (C) 2007 Savoir-faire Linux
7  *
8  * $Id$
9  *
10  * Authors: Clément Stenac <zorglub@videolan.org>
11  *          Jean-Baptiste Kempf <jb@videolan.org>
12  *          Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
27  *****************************************************************************/
28
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include "qt4.hpp"
34 #include "components/open_panels.hpp"
35 #include "dialogs/open.hpp"
36 #include "dialogs_provider.hpp" /* Open Subtitle file */
37 #include "util/qt_dirs.hpp"
38 #include <vlc_intf_strings.h>
39 #include <vlc_modules.h>
40
41 #include <QFileDialog>
42 #include <QDialogButtonBox>
43 #include <QLineEdit>
44 #include <QStackedLayout>
45 #include <QListView>
46 #include <QCompleter>
47 #include <QDirModel>
48 #include <QScrollArea>
49 #include <QUrl>
50 #include <QStringListModel>
51 #include <QDropEvent>
52
53 #define I_DEVICE_TOOLTIP \
54     I_DIR_OR_FOLDER( N_("Select a device or a VIDEO_TS directory"), \
55                      N_("Select a device or a VIDEO_TS folder") )
56
57 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     {
275         fileList = dialogBox->selectedFiles();
276         for( int i = 0; i < fileList.count(); i++ )
277             fileList[i] = toNativeSeparators( fileList[i] );
278     }
279
280     /* Options */
281     if( ui.subCheckBox->isChecked() &&  !ui.subInput->text().isEmpty() ) {
282         mrl.append( " :sub-file=" + colon_escape( ui.subInput->text() ) );
283         int align = ui.alignSubComboBox->itemData(
284                     ui.alignSubComboBox->currentIndex() ).toInt();
285         mrl.append( " :subsdec-align=" + QString().setNum( align ) );
286         int size = ui.sizeSubComboBox->itemData(
287                    ui.sizeSubComboBox->currentIndex() ).toInt();
288         mrl.append( " :freetype-rel-fontsize=" + QString().setNum( size ) );
289     }
290
291     emit mrlUpdated( fileList, mrl );
292     emit methodChanged( "file-caching" );
293 }
294
295 /* Function called by Open Dialog when clicke on Play/Enqueue */
296 void FileOpenPanel::accept()
297 {
298     if( dialogBox )
299         p_intf->p_sys->filepath = dialogBox->directory().absolutePath();
300     ui.fileListWidg->clear();
301 }
302
303 /* Function called by Open Dialog when clicked on cancel */
304 void FileOpenPanel::clear()
305 {
306     ui.fileListWidg->clear();
307     ui.subInput->clear();
308 }
309
310 /* Update buttons depending on current selection */
311 void FileOpenPanel::updateButtons()
312 {
313     bool b_has_files = ( ui.fileListWidg->count() > 0 );
314     ui.removeFileButton->setEnabled( b_has_files );
315     ui.subCheckBox->setEnabled( b_has_files );
316 }
317
318 /**************************************************************************
319  * Open Discs ( DVD, CD, VCD and similar devices )                        *
320  **************************************************************************/
321 DiscOpenPanel::DiscOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
322                                 OpenPanel( _parent, _p_intf )
323 {
324     ui.setupUi( this );
325
326     /* Get the default configuration path for the devices */
327     psz_dvddiscpath = var_InheritString( p_intf, "dvd" );
328     psz_vcddiscpath = var_InheritString( p_intf, "vcd" );
329     psz_cddadiscpath = var_InheritString( p_intf, "cd-audio" );
330
331     /* State to avoid overwritting the users changes with the configuration */
332     m_discType = None;
333
334     ui.browseDiscButton->setToolTip( qtr( I_DEVICE_TOOLTIP ));
335     ui.deviceCombo->setToolTip( qtr(I_DEVICE_TOOLTIP) );
336
337 #ifdef WIN32 /* Disc drives probing for Windows */
338     char szDrives[512];
339     szDrives[0] = '\0';
340     if( GetLogicalDriveStringsA( sizeof( szDrives ) - 1, szDrives ) )
341     {
342         char *drive = szDrives;
343         UINT oldMode = SetErrorMode( SEM_FAILCRITICALERRORS );
344         while( *drive )
345         {
346             if( GetDriveTypeA(drive) == DRIVE_CDROM )
347                 ui.deviceCombo->addItem( drive );
348
349             /* go to next drive */
350             while( *(drive++) );
351         }
352         SetErrorMode(oldMode);
353     }
354 #else /* Use a Completer under Linux */
355     QCompleter *discCompleter = new QCompleter( this );
356     discCompleter->setModel( new QDirModel( discCompleter ) );
357     ui.deviceCombo->setCompleter( discCompleter );
358 #endif
359
360     /* CONNECTs */
361     BUTTONACT( ui.dvdRadioButton, updateButtons() );
362     BUTTONACT( ui.vcdRadioButton, updateButtons() );
363     BUTTONACT( ui.audioCDRadioButton, updateButtons() );
364     BUTTONACT( ui.dvdsimple, updateButtons() );
365     BUTTONACT( ui.browseDiscButton, browseDevice() );
366     BUTTON_SET_ACT_I( ui.ejectButton, "", toolbar/eject, qtr( "Eject the disc" ),
367             eject() );
368
369     CONNECT( ui.deviceCombo, editTextChanged( QString ), this, updateMRL());
370     CONNECT( ui.titleSpin, valueChanged( int ), this, updateMRL());
371     CONNECT( ui.chapterSpin, valueChanged( int ), this, updateMRL());
372     CONNECT( ui.audioSpin, valueChanged( int ), this, updateMRL());
373     CONNECT( ui.subtitlesSpin, valueChanged( int ), this, updateMRL());
374
375     /* Run once the updateButtons function in order to fill correctly the comboBoxes */
376     updateButtons();
377 }
378
379 DiscOpenPanel::~DiscOpenPanel()
380 {
381     free( psz_dvddiscpath );
382     free( psz_vcddiscpath );
383     free( psz_cddadiscpath );
384 }
385
386 void DiscOpenPanel::clear()
387 {
388     ui.titleSpin->setValue( 0 );
389     ui.chapterSpin->setValue( 0 );
390     ui.subtitlesSpin->setValue( -1 );
391     ui.audioSpin->setValue( -1 );
392     m_discType = None;
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( m_discType != Dvd )
410         {
411             setDrive( psz_dvddiscpath );
412             m_discType = Dvd;
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( m_discType != Vcd )
423         {
424             setDrive( psz_vcddiscpath );
425             m_discType = Vcd;
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( m_discType != Cdda )
436         {
437             setDrive( psz_cddadiscpath );
438             m_discType = Cdda;
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.urlComboBox->lineEdit(), textChanged( const QString& ), this, updateMRL());
542     CONNECT( ui.urlComboBox, currentIndexChanged( const QString& ), this, updateMRL());
543
544     if( var_InheritBool( p_intf, "qt-recentplay" ) )
545     {
546         mrlList = new QStringListModel(
547                 getSettings()->value( "Open/netMRL" ).toStringList() );
548         ui.urlComboBox->setModel( mrlList );
549         ui.urlComboBox->clearEditText();
550         CONNECT( ui.urlComboBox->lineEdit(), editingFinished(), this, updateModel() );
551     }
552     else
553         mrlList = NULL;
554
555     ui.urlComboBox->setValidator( new UrlValidator( this ) );
556     ui.urlComboBox->setFocus();
557 }
558
559 NetOpenPanel::~NetOpenPanel()
560 {
561     if( !mrlList ) return;
562
563     QStringList tempL = mrlList->stringList();
564     while( tempL.size() > 8 ) tempL.removeFirst();
565
566     getSettings()->setValue( "Open/netMRL", tempL );
567
568     delete mrlList;
569 }
570
571 void NetOpenPanel::clear()
572 {}
573
574 static int strcmp_void( const void *k, const void *e )
575 {
576     return strcmp( (const char *)k, (const char *)e );
577 }
578
579 void NetOpenPanel::updateMRL()
580 {
581     static const struct caching_map
582     {
583         char proto[6];
584         char caching[6];
585     } schemes[] =
586     {   /* KEEP alphabetical order on first column!! */
587         { "dccp",  "rtp"   },
588         { "ftp",   "ftp"   },
589         { "ftps",  "ftp"   },
590         { "http",  "http"  },
591         { "https", "http"  },
592         { "mms",   "mms"   },
593         { "mmsh",  "mms"   },
594         { "mmst",  "mms"   },
595         { "mmsu",  "mms"   },
596         { "sftp",  "sftp"  },
597         { "smb",   "smb"   },
598         { "rtmp",  "rtmp"  },
599         { "rtp",   "rtp"   },
600         { "rtsp",  "rtsp"  },
601         { "udp",   "udp"   },
602     };
603
604     QString url = ui.urlComboBox->lineEdit()->text();
605     if( !url.contains( "://") )
606         return; /* nothing to do this far */
607
608     /* Match the correct item in the comboBox */
609     QString proto = url.section( ':', 0, 0 );
610     const struct caching_map *r = (const struct caching_map *)
611         bsearch( qtu(proto), schemes, sizeof(schemes) / sizeof(schemes[0]),
612                  sizeof(schemes[0]), strcmp_void );
613     if( r )
614         emit methodChanged( qfu( r->caching ) + qfu( "-caching" ) );
615
616     QStringList qsl;
617     qsl << url;
618     emit mrlUpdated( qsl, "" );
619 }
620
621 void NetOpenPanel::updateModel()
622 {
623     assert( mrlList );
624     QStringList tempL = mrlList->stringList();
625     if( !tempL.contains( ui.urlComboBox->lineEdit()->text() ) )
626         tempL.append( ui.urlComboBox->lineEdit()->text() );
627     mrlList->setStringList( tempL );
628 }
629
630 void UrlValidator::fixup( QString& str ) const
631 {
632     str = str.trimmed();
633 }
634
635 QValidator::State UrlValidator::validate( QString& str, int& pos ) const
636 {
637     if( str.contains( ' ' ) )
638         return QValidator::Invalid;
639     if( !str.contains( "://" ) )
640         return QValidator::Intermediate;
641     return QValidator::Acceptable;
642 }
643
644 /**************************************************************************
645  * Open Capture device ( DVB, PVR, V4L, and similar )                     *
646  **************************************************************************/
647 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
648                                 OpenPanel( _parent, _p_intf )
649 {
650     isInitialized = false;
651 }
652
653 void CaptureOpenPanel::initialize()
654 {
655     if( isInitialized ) return;
656
657     msg_Dbg( p_intf, "Initialization of Capture device panel" );
658     isInitialized = true;
659
660     ui.setupUi( this );
661
662     BUTTONACT( ui.advancedButton, advancedDialog() );
663
664     /* Create two stacked layouts in the main comboBoxes */
665     QStackedLayout *stackedDevLayout = new QStackedLayout;
666     ui.cardBox->setLayout( stackedDevLayout );
667
668     QStackedLayout *stackedPropLayout = new QStackedLayout;
669     ui.optionsBox->setLayout( stackedPropLayout );
670
671     /* Creation and connections of the WIdgets in the stacked layout */
672 #define addModuleAndLayouts( number, name, label, layout )            \
673     QWidget * name ## DevPage = new QWidget( this );                  \
674     QWidget * name ## PropPage = new QWidget( this );                 \
675     stackedDevLayout->addWidget( name ## DevPage );        \
676     stackedPropLayout->addWidget( name ## PropPage );      \
677     layout * name ## DevLayout = new layout;                \
678     layout * name ## PropLayout = new layout;               \
679     name ## DevPage->setLayout( name ## DevLayout );                  \
680     name ## PropPage->setLayout( name ## PropLayout );                \
681     ui.deviceCombo->addItem( qtr( label ), QVariant( number ) );
682
683 #define CuMRL( widget, slot ) CONNECT( widget , slot , this, updateMRL() );
684
685 #ifdef WIN32
686     /*********************
687      * DirectShow Stuffs *
688      *********************/
689     if( module_exists( "dshow" ) ){
690     addModuleAndLayouts( DSHOW_DEVICE, dshow, "DirectShow", QGridLayout );
691
692     /* dshow Main */
693     int line = 0;
694     module_config_t *p_config =
695         config_FindConfig( VLC_OBJECT(p_intf), "dshow-vdev" );
696     vdevDshowW = new StringListConfigControl(
697         VLC_OBJECT(p_intf), p_config, this, false, dshowDevLayout, line );
698     line++;
699
700     p_config = config_FindConfig( VLC_OBJECT(p_intf), "dshow-adev" );
701     adevDshowW = new StringListConfigControl(
702         VLC_OBJECT(p_intf), p_config, this, false, dshowDevLayout, line );
703     line++;
704
705     /* dshow Properties */
706     QLabel *dshowVSizeLabel = new QLabel( qtr( "Video size" ) );
707     dshowPropLayout->addWidget( dshowVSizeLabel, 0, 0 );
708
709     dshowVSizeLine = new QLineEdit;
710     dshowPropLayout->addWidget( dshowVSizeLine, 0, 1);
711     dshowPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
712             1, 0, 3, 1 );
713
714     /* dshow CONNECTs */
715     CuMRL( vdevDshowW->combo, currentIndexChanged ( int ) );
716     CuMRL( adevDshowW->combo, currentIndexChanged ( int ) );
717     CuMRL( dshowVSizeLine, textChanged( const QString& ) );
718     }
719
720     /**************
721      * BDA Stuffs *
722      **************/
723     if( module_exists( "bda" ) ){
724     addModuleAndLayouts( BDA_DEVICE, bda, "DVB DirectShow", QGridLayout );
725
726     /* bda Main */
727     QLabel *bdaTypeLabel = new QLabel( qtr( "DVB Type:" ) );
728
729     bdas = new QRadioButton( "DVB-S" );
730     bdas->setChecked( true );
731     bdac = new QRadioButton( "DVB-C" );
732     bdat = new QRadioButton( "DVB-T" );
733     bdaa = new QRadioButton( "ATSC" );
734     bdaq = new QRadioButton( "Clear QAM" );
735
736     bdaDevLayout->addWidget( bdaTypeLabel, 0, 0 );
737     bdaDevLayout->addWidget( bdas, 0, 1 );
738     bdaDevLayout->addWidget( bdac, 0, 2 );
739     bdaDevLayout->addWidget( bdat, 0, 3 );
740     bdaDevLayout->addWidget( bdaa, 0, 4 );
741     bdaDevLayout->addWidget( bdaq, 0, 5 );
742
743     /* bda Props */
744     QLabel *bdaFreqLabel =
745                     new QLabel( qtr( "Transponder/multiplex frequency" ) );
746     bdaPropLayout->addWidget( bdaFreqLabel, 0, 0 );
747
748     bdaFreq = new QSpinBox;
749     bdaFreq->setAlignment( Qt::AlignRight );
750     bdaFreq->setSuffix(" kHz");
751     bdaFreq->setSingleStep( 1000 );
752     setSpinBoxFreq( bdaFreq )
753     bdaPropLayout->addWidget( bdaFreq, 0, 1 );
754
755     bdaSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
756     bdaPropLayout->addWidget( bdaSrateLabel, 1, 0 );
757
758     bdaSrate = new QSpinBox;
759     bdaSrate->setAlignment( Qt::AlignRight );
760     bdaSrate->setSuffix(" kHz");
761     setSpinBoxFreq( bdaSrate );
762     bdaPropLayout->addWidget( bdaSrate, 1, 1 );
763
764     bdaBandLabel = new QLabel( qtr( "Bandwidth" ) );
765     bdaPropLayout->addWidget( bdaBandLabel, 2, 0 );
766
767     bdaBandBox = new QComboBox;
768     setfillVLCConfigCombo( "dvb-bandwidth", p_intf, bdaBandBox );
769     bdaPropLayout->addWidget( bdaBandBox, 2, 1 );
770
771     bdaBandLabel->hide();
772     bdaBandBox->hide();
773     bdaPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
774             2, 0, 2, 1 );
775
776     /* bda CONNECTs */
777     CuMRL( bdaFreq, valueChanged ( int ) );
778     CuMRL( bdaSrate, valueChanged ( int ) );
779     CuMRL( bdaBandBox,  currentIndexChanged ( int ) );
780     BUTTONACT( bdas, updateButtons() );
781     BUTTONACT( bdat, updateButtons() );
782     BUTTONACT( bdac, updateButtons() );
783     BUTTONACT( bdaa, updateButtons() );
784     BUTTONACT( bdaq, updateButtons() );
785     BUTTONACT( bdas, updateMRL() );
786     BUTTONACT( bdat, updateMRL() );
787     BUTTONACT( bdac, updateMRL() );
788     BUTTONACT( bdaa, updateMRL() );
789     BUTTONACT( bdaq, updateMRL() );
790     }
791
792 #else /* WIN32 */
793     /*******
794      * V4L2*
795      *******/
796     if( module_exists( "v4l2" ) ){
797     addModuleAndLayouts( V4L2_DEVICE, v4l2, "Video for Linux 2", QGridLayout );
798
799     char const * const ppsz_v4lvdevices[] = {
800         "video*"
801     };
802
803     char const * const ppsz_v4ladevices[] = {
804         "dsp*",
805         "radio*"
806     };
807
808     #define POPULATE_WITH_DEVS(ppsz_devlist, targetCombo) \
809     QStringList targetCombo ## StringList = QStringList(); \
810     for ( int i = 0; i< sizeof(ppsz_devlist) / sizeof(*ppsz_devlist); i++ ) \
811         targetCombo ## StringList << QString( ppsz_devlist[ i ] ); \
812     QDir targetCombo ## Dir = QDir( "/dev/" ); \
813     targetCombo->addItems( \
814         targetCombo ## Dir\
815         .entryList( targetCombo ## StringList, QDir::System )\
816         .replaceInStrings( QRegExp("^"), "/dev/" ) \
817     );
818
819     /* V4l Main panel */
820     QLabel *v4l2VideoDeviceLabel = new QLabel( qtr( "Video device name" ) );
821     v4l2DevLayout->addWidget( v4l2VideoDeviceLabel, 0, 0 );
822
823     v4l2VideoDevice = new QComboBox( this );
824     v4l2VideoDevice->setEditable( true );
825     POPULATE_WITH_DEVS( ppsz_v4lvdevices, v4l2VideoDevice );
826     v4l2VideoDevice->clearEditText();
827     v4l2DevLayout->addWidget( v4l2VideoDevice, 0, 1 );
828
829     QLabel *v4l2AudioDeviceLabel = new QLabel( qtr( "Audio device name" ) );
830     v4l2DevLayout->addWidget( v4l2AudioDeviceLabel, 1, 0 );
831
832     v4l2AudioDevice = new QComboBox( this );
833     v4l2AudioDevice->setEditable( true );
834     POPULATE_WITH_DEVS( ppsz_v4ladevices, v4l2AudioDevice );
835     v4l2AudioDevice->clearEditText();
836     v4l2DevLayout->addWidget( v4l2AudioDevice, 1, 1 );
837
838     /* v4l2 Props panel */
839     QLabel *v4l2StdLabel = new QLabel( qtr( "Video standard" ) );
840     v4l2PropLayout->addWidget( v4l2StdLabel, 0 , 0 );
841
842     v4l2StdBox = new QComboBox;
843     setfillVLCConfigCombo( "v4l2-standard", p_intf, v4l2StdBox );
844     v4l2PropLayout->addWidget( v4l2StdBox, 0 , 1 );
845     v4l2PropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
846             1, 0, 3, 2 );
847
848     /* v4l2 CONNECTs */
849     CuMRL( v4l2VideoDevice->lineEdit(), textChanged( const QString& ) );
850     CuMRL( v4l2VideoDevice,  currentIndexChanged ( int ) );
851     CuMRL( v4l2AudioDevice->lineEdit(), textChanged( const QString& ) );
852     CuMRL( v4l2AudioDevice,  currentIndexChanged ( int ) );
853     CuMRL( v4l2StdBox,  currentIndexChanged ( int ) );
854     #undef POPULATE_WITH_DEVS
855     }
856
857     /*******
858      * V4L *
859      *******/
860     if( module_exists( "v4l" ) ){
861     addModuleAndLayouts( V4L_DEVICE, v4l, "Video for Linux", QGridLayout );
862
863     /* V4l Main panel */
864     QLabel *v4lVideoDeviceLabel = new QLabel( qtr( "Video device name" ) );
865     v4lDevLayout->addWidget( v4lVideoDeviceLabel, 0, 0 );
866
867     v4lVideoDevice = new QLineEdit;
868     v4lDevLayout->addWidget( v4lVideoDevice, 0, 1 );
869
870     QLabel *v4lAudioDeviceLabel = new QLabel( qtr( "Audio device name" ) );
871     v4lDevLayout->addWidget( v4lAudioDeviceLabel, 1, 0 );
872
873     v4lAudioDevice = new QLineEdit;
874     v4lDevLayout->addWidget( v4lAudioDevice, 1, 1 );
875
876     /* V4l Props panel */
877     QLabel *v4lNormLabel = new QLabel( qtr( "Norm" ) );
878     v4lPropLayout->addWidget( v4lNormLabel, 0 , 0 );
879
880     v4lNormBox = new QComboBox;
881     setfillVLCConfigCombo( "v4l-norm", p_intf, v4lNormBox );
882     v4lPropLayout->addWidget( v4lNormBox, 0 , 1 );
883
884     QLabel *v4lFreqLabel = new QLabel( qtr( "Frequency" ) );
885     v4lPropLayout->addWidget( v4lFreqLabel, 1 , 0 );
886
887     v4lFreq = new QSpinBox;
888     v4lFreq->setAlignment( Qt::AlignRight );
889     v4lFreq->setSuffix(" kHz");
890     setSpinBoxFreq( v4lFreq );
891     v4lPropLayout->addWidget( v4lFreq, 1 , 1 );
892     v4lPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
893             2, 0, 2, 1 );
894
895     /* v4l CONNECTs */
896     CuMRL( v4lVideoDevice, textChanged( const QString& ) );
897     CuMRL( v4lAudioDevice, textChanged( const QString& ) );
898     CuMRL( v4lFreq, valueChanged ( int ) );
899     CuMRL( v4lNormBox,  currentIndexChanged ( int ) );
900     }
901
902     /*******
903      * JACK *
904      *******/
905     if( module_exists( "jack" ) ){
906     addModuleAndLayouts( JACK_DEVICE, jack, "JACK Audio Connection Kit",
907                          QGridLayout);
908
909     /* Jack Main panel */
910     /* Channels */
911     QLabel *jackChannelsLabel = new QLabel( qtr( "Channels:" ) );
912     jackDevLayout->addWidget( jackChannelsLabel, 1, 0 );
913
914     jackChannels = new QSpinBox;
915     setSpinBoxFreq( jackChannels );
916     jackChannels->setMaximum(255);
917     jackChannels->setValue(2);
918     jackChannels->setAlignment( Qt::AlignRight );
919     jackDevLayout->addWidget( jackChannels, 1, 1 );
920
921     /* Selected ports */
922     QLabel *jackPortsLabel = new QLabel( qtr( "Selected ports:" ) );
923     jackDevLayout->addWidget( jackPortsLabel, 0 , 0 );
924
925     jackPortsSelected = new QLineEdit( qtr( ".*") );
926     jackPortsSelected->setAlignment( Qt::AlignRight );
927     jackDevLayout->addWidget( jackPortsSelected, 0, 1 );
928
929     /* Jack Props panel */
930
931     /* Caching */
932     QLabel *jackCachingLabel = new QLabel( qtr( "Input caching:" ) );
933     jackPropLayout->addWidget( jackCachingLabel, 1 , 0 );
934     jackCaching = new QSpinBox;
935     setSpinBoxFreq( jackCaching );
936     jackCaching->setSuffix( " ms" );
937     jackCaching->setValue(1000);
938     jackCaching->setAlignment( Qt::AlignRight );
939     jackPropLayout->addWidget( jackCaching, 1 , 2 );
940
941     /* Pace */
942     jackPace = new QCheckBox(qtr( "Use VLC pace" ));
943     jackPropLayout->addWidget( jackPace, 2, 1 );
944
945     /* Auto Connect */
946     jackConnect = new QCheckBox( qtr( "Auto connection" ));
947     jackPropLayout->addWidget( jackConnect, 2, 2 );
948
949     /* Jack CONNECTs */
950     CuMRL( jackChannels, valueChanged( int ) );
951     CuMRL( jackCaching, valueChanged( int ) );
952     CuMRL( jackPace, stateChanged( int ) );
953     CuMRL( jackConnect, stateChanged( int ) );
954     CuMRL( jackPortsSelected, textChanged( const QString& ) );
955     }
956
957     /************
958      * PVR      *
959      ************/
960     if( module_exists( "pvr" ) ){
961     addModuleAndLayouts( PVR_DEVICE, pvr, "PVR", QGridLayout );
962
963     /* PVR Main panel */
964     QLabel *pvrDeviceLabel = new QLabel( qtr( "Device name" ) );
965     pvrDevLayout->addWidget( pvrDeviceLabel, 0, 0 );
966
967     pvrDevice = new QLineEdit;
968     pvrDevLayout->addWidget( pvrDevice, 0, 1 );
969
970     QLabel *pvrRadioDeviceLabel = new QLabel( qtr( "Radio device name" ) );
971     pvrDevLayout->addWidget( pvrRadioDeviceLabel, 1, 0 );
972
973     pvrRadioDevice = new QLineEdit;
974     pvrDevLayout->addWidget( pvrRadioDevice, 1, 1 );
975
976     /* PVR props panel */
977     QLabel *pvrNormLabel = new QLabel( qtr( "Norm" ) );
978     pvrPropLayout->addWidget( pvrNormLabel, 0, 0 );
979
980     pvrNormBox = new QComboBox;
981     setfillVLCConfigCombo( "pvr-norm", p_intf, pvrNormBox );
982     pvrPropLayout->addWidget( pvrNormBox, 0, 1 );
983
984     QLabel *pvrFreqLabel = new QLabel( qtr( "Frequency" ) );
985     pvrPropLayout->addWidget( pvrFreqLabel, 1, 0 );
986
987     pvrFreq = new QSpinBox;
988     pvrFreq->setAlignment( Qt::AlignRight );
989     pvrFreq->setSuffix(" kHz");
990     setSpinBoxFreq( pvrFreq );
991     pvrPropLayout->addWidget( pvrFreq, 1, 1 );
992
993     QLabel *pvrBitrLabel = new QLabel( qtr( "Bitrate" ) );
994     pvrPropLayout->addWidget( pvrBitrLabel, 2, 0 );
995
996     pvrBitr = new QSpinBox;
997     pvrBitr->setAlignment( Qt::AlignRight );
998     pvrBitr->setSuffix(" kHz");
999     setSpinBoxFreq( pvrBitr );
1000     pvrPropLayout->addWidget( pvrBitr, 2, 1 );
1001     pvrPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
1002             3, 0, 1, 1 );
1003
1004     /* PVR CONNECTs */
1005     CuMRL( pvrDevice, textChanged( const QString& ) );
1006     CuMRL( pvrRadioDevice, textChanged( const QString& ) );
1007
1008     CuMRL( pvrFreq, valueChanged ( int ) );
1009     CuMRL( pvrBitr, valueChanged ( int ) );
1010     CuMRL( pvrNormBox, currentIndexChanged ( int ) );
1011     }
1012
1013     /**************
1014      * DVB Stuffs *
1015      **************/
1016     if( module_exists( "dvb" ) ){
1017     addModuleAndLayouts( DVB_DEVICE, dvb, "DVB", QGridLayout );
1018
1019     /* DVB Main */
1020     QLabel *dvbDeviceLabel = new QLabel( qtr( "Adapter card to tune" ) );
1021     QLabel *dvbTypeLabel = new QLabel( qtr( "DVB Type:" ) );
1022
1023     dvbCard = new QSpinBox;
1024     dvbCard->setAlignment( Qt::AlignRight );
1025     dvbCard->setPrefix( "/dev/dvb/adapter" );
1026
1027     dvbDevLayout->addWidget( dvbDeviceLabel, 0, 0 );
1028     dvbDevLayout->addWidget( dvbCard, 0, 2, 1, 2 );
1029
1030     dvbs = new QRadioButton( "DVB-S" );
1031     dvbs->setChecked( true );
1032     dvbc = new QRadioButton( "DVB-C" );
1033     dvbt = new QRadioButton( "DVB-T" );
1034
1035     dvbDevLayout->addWidget( dvbTypeLabel, 1, 0 );
1036     dvbDevLayout->addWidget( dvbs, 1, 1 );
1037     dvbDevLayout->addWidget( dvbc, 1, 2 );
1038     dvbDevLayout->addWidget( dvbt, 1, 3 );
1039
1040     /* DVB Props panel */
1041     QLabel *dvbFreqLabel =
1042                     new QLabel( qtr( "Transponder/multiplex frequency" ) );
1043     dvbPropLayout->addWidget( dvbFreqLabel, 0, 0 );
1044
1045     dvbFreq = new QSpinBox;
1046     dvbFreq->setAlignment( Qt::AlignRight );
1047     dvbFreq->setSuffix(" kHz");
1048     dvbFreq->setSingleStep( 1000 );
1049     setSpinBoxFreq( dvbFreq  );
1050     dvbPropLayout->addWidget( dvbFreq, 0, 1 );
1051
1052     dvbSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
1053     dvbPropLayout->addWidget( dvbSrateLabel, 1, 0 );
1054
1055     dvbSrate = new QSpinBox;
1056     dvbSrate->setAlignment( Qt::AlignRight );
1057     dvbSrate->setSuffix(" kHz");
1058     setSpinBoxFreq( dvbSrate );
1059     dvbPropLayout->addWidget( dvbSrate, 1, 1 );
1060
1061     dvbBandLabel = new QLabel( qtr( "Bandwidth" ) );
1062     dvbPropLayout->addWidget( dvbBandLabel, 2, 0 );
1063
1064     dvbBandBox = new QComboBox;
1065     /* This doesn't work since dvb-bandwidth doesn't seem to be a
1066        list of Integers
1067        setfillVLCConfigCombo( "dvb-bandwidth", p_intf, bdaBandBox );
1068      */
1069     dvbBandBox->addItem( qtr( "Auto" ), 0 );
1070     dvbBandBox->addItem( qtr( "6 MHz" ), 6 );
1071     dvbBandBox->addItem( qtr( "7 MHz" ), 7 );
1072     dvbBandBox->addItem( qtr( "8 MHz" ), 8 );
1073     dvbPropLayout->addWidget( dvbBandBox, 2, 1 );
1074
1075     dvbBandLabel->hide();
1076     dvbBandBox->hide();
1077
1078     dvbPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
1079             2, 0, 2, 1 );
1080
1081     /* DVB CONNECTs */
1082     CuMRL( dvbCard, valueChanged ( int ) );
1083     CuMRL( dvbFreq, valueChanged ( int ) );
1084     CuMRL( dvbSrate, valueChanged ( int ) );
1085     CuMRL( dvbBandBox, currentIndexChanged ( int ) );
1086
1087     BUTTONACT( dvbs, updateButtons() );
1088     BUTTONACT( dvbt, updateButtons() );
1089     BUTTONACT( dvbc, updateButtons() );
1090     BUTTONACT( dvbs, updateMRL() );
1091     BUTTONACT( dvbt, updateMRL() );
1092     BUTTONACT( dvbc, updateMRL() );
1093     }
1094
1095 #endif
1096
1097
1098     /**********
1099      * Screen *
1100      **********/
1101     addModuleAndLayouts( SCREEN_DEVICE, screen, "Desktop", QGridLayout );
1102     QLabel *screenLabel = new QLabel( qtr( "Your display will be "
1103             "opened and played in order to stream or save it." ) );
1104     screenLabel->setWordWrap( true );
1105     screenDevLayout->addWidget( screenLabel, 0, 0 );
1106
1107     QLabel *screenFPSLabel = new QLabel(
1108             qtr( "Desired frame rate for the capture." ) );
1109     screenPropLayout->addWidget( screenFPSLabel, 0, 0 );
1110
1111     screenFPS = new QDoubleSpinBox;
1112     screenFPS->setValue( 1. );
1113     screenFPS->setRange( .01, 100. );
1114     screenFPS->setAlignment( Qt::AlignRight );
1115     /* xgettext: frames per second */
1116     screenFPS->setSuffix( qtr( " f/s" ) );
1117     screenPropLayout->addWidget( screenFPS, 0, 1 );
1118
1119     /* Screen connect */
1120     CuMRL( screenFPS, valueChanged( double ) );
1121
1122     /* General connects */
1123     CONNECT( ui.deviceCombo, activated( int ) ,
1124              stackedDevLayout, setCurrentIndex( int ) );
1125     CONNECT( ui.deviceCombo, activated( int ),
1126              stackedPropLayout, setCurrentIndex( int ) );
1127     CONNECT( ui.deviceCombo, activated( int ), this, updateMRL() );
1128     CONNECT( ui.deviceCombo, activated( int ), this, updateButtons() );
1129
1130 #undef CuMRL
1131 #undef addModuleAndLayouts
1132 }
1133
1134 CaptureOpenPanel::~CaptureOpenPanel()
1135 {
1136 }
1137
1138 void CaptureOpenPanel::clear()
1139 {
1140     advMRL.clear();
1141 }
1142
1143 void CaptureOpenPanel::updateMRL()
1144 {
1145     QString mrl = "";
1146     QStringList fileList;
1147     int i_devicetype = ui.deviceCombo->itemData(
1148             ui.deviceCombo->currentIndex() ).toInt();
1149     switch( i_devicetype )
1150     {
1151 #ifdef WIN32
1152     case BDA_DEVICE:
1153         if( bdas->isChecked() ) mrl = "dvb-s://";
1154         else if(  bdat->isChecked() ) mrl = "dvb-t://";
1155         else if(  bdac->isChecked() ) mrl = "dvb-c://";
1156         else if(  bdaa->isChecked() ) mrl = "atsc://";
1157         else if(  bdaq->isChecked() ) mrl = "cqam://";
1158         else return;
1159         mrl += "frequency=" + QString::number( bdaFreq->value() );
1160         if( bdac->isChecked() || bdat->isChecked() || bdaa->isChecked() )
1161             mrl +="000";
1162         fileList << mrl; mrl = "";
1163
1164         if( bdas->isChecked() || bdac->isChecked() )
1165             mrl += " :dvb-srate=" + QString::number( bdaSrate->value() );
1166         else if( bdat->isChecked() || bdaa->isChecked() )
1167             mrl += " :dvb-bandwidth=" +
1168                 QString::number( bdaBandBox->itemData(
1169                     bdaBandBox->currentIndex() ).toInt() );
1170         emit methodChanged( "dvb-caching" );
1171         break;
1172     case DSHOW_DEVICE:
1173         fileList << "dshow://";
1174         mrl+= " :dshow-vdev=" +
1175             colon_escape( QString("%1").arg( vdevDshowW->getValue() ) );
1176         mrl+= " :dshow-adev=" +
1177             colon_escape( QString("%1").arg( adevDshowW->getValue() ) )+" ";
1178         if( dshowVSizeLine->isModified() )
1179             mrl += ":dshow-size=" + dshowVSizeLine->text();
1180         emit methodChanged( "dshow-caching" );
1181         break;
1182 #else
1183     case V4L_DEVICE:
1184         fileList << "v4l://" + v4lVideoDevice->text();
1185         mrl += " :input-slave=alsa://" + v4lAudioDevice->text();
1186         mrl += " :v4l-norm=" + QString::number( v4lNormBox->currentIndex() );
1187         mrl += " :v4l-frequency=" + QString::number( v4lFreq->value() );
1188         break;
1189     case V4L2_DEVICE:
1190         fileList << "v4l2://" + v4l2VideoDevice->currentText();
1191         mrl += " :input-slave=alsa://" + v4l2AudioDevice->currentText();
1192         mrl += " :v4l2-standard=" + QString::number( v4l2StdBox->currentIndex() );
1193         break;
1194     case JACK_DEVICE:
1195         mrl = "jack://";
1196         mrl += "channels=" + QString::number( jackChannels->value() );
1197         mrl += ":ports=" + jackPortsSelected->text();
1198         fileList << mrl; mrl = "";
1199
1200         mrl += " :jack-input-caching=" + QString::number( jackCaching->value() );
1201         if ( jackPace->isChecked() )
1202         {
1203                 mrl += " :jack-input-use-vlc-pace";
1204         }
1205         if ( jackConnect->isChecked() )
1206         {
1207                 mrl += " :jack-input-auto-connect";
1208         }
1209         break;
1210     case PVR_DEVICE:
1211         fileList << "pvr://";
1212         mrl += " :pvr-device=" + pvrDevice->text();
1213         mrl += " :pvr-radio-device=" + pvrRadioDevice->text();
1214         mrl += " :pvr-norm=" + QString::number( pvrNormBox->currentIndex() );
1215         if( pvrFreq->value() )
1216             mrl += " :pvr-frequency=" + QString::number( pvrFreq->value() );
1217         if( pvrBitr->value() )
1218             mrl += " :pvr-bitrate=" + QString::number( pvrBitr->value() );
1219         break;
1220     case DVB_DEVICE:
1221         mrl = "dvb://";
1222         mrl += "frequency=" + QString::number( dvbFreq->value() );
1223         if( dvbc->isChecked() || dvbt->isChecked() )
1224             mrl +="000";
1225         fileList << mrl; mrl= "";
1226
1227         mrl += " :dvb-adapter=" + QString::number( dvbCard->value() );
1228         if( dvbs->isChecked() || dvbc->isChecked() )
1229             mrl += " :dvb-srate=" + QString::number( dvbSrate->value() );
1230         else if( dvbt->isChecked() )
1231             mrl += " :dvb-bandwidth=" +
1232                 QString::number( dvbBandBox->itemData(
1233                     dvbBandBox->currentIndex() ).toInt() );
1234
1235         break;
1236 #endif
1237     case SCREEN_DEVICE:
1238         fileList << "screen://";
1239         mrl = " :screen-fps=" + QString::number( screenFPS->value(), 'f' );
1240         emit methodChanged( "screen-caching" );
1241         updateButtons();
1242         break;
1243     }
1244
1245     if( !advMRL.isEmpty() ) mrl += advMRL;
1246
1247     emit mrlUpdated( fileList, mrl );
1248 }
1249
1250 /**
1251  * Update the Buttons (show/hide) for the GUI as all device type don't
1252  * use the same ui. elements.
1253  **/
1254 void CaptureOpenPanel::updateButtons()
1255 {
1256     /*  Be sure to display the ui Elements in case they were hidden by
1257      *  some Device Type (like Screen://) */
1258     ui.optionsBox->show();
1259     ui.advancedButton->show();
1260     /* Get the current Device Number */
1261     int i_devicetype = ui.deviceCombo->itemData(
1262                                 ui.deviceCombo->currentIndex() ).toInt();
1263     switch( i_devicetype )
1264     {
1265 #ifdef WIN32
1266     case BDA_DEVICE:
1267         if( bdas->isChecked() || bdac->isChecked() )
1268         {
1269             bdaSrate->show();
1270             bdaSrateLabel->show();
1271             bdaBandBox->hide();
1272             bdaBandLabel->hide();
1273         }
1274         else if( bdat->isChecked() || bdaa->isChecked() )
1275         {
1276             bdaSrate->hide();
1277             bdaSrateLabel->hide();
1278             bdaBandBox->show();
1279             bdaBandLabel->show();
1280         }
1281         else if( bdaq->isChecked() )
1282         {
1283             bdaSrate->hide();
1284             bdaSrateLabel->hide();
1285             bdaBandBox->hide();
1286             bdaBandLabel->hide();
1287         }
1288         break;
1289 #else
1290     case DVB_DEVICE:
1291         if( dvbs->isChecked() || dvbc->isChecked() )
1292         {
1293             dvbSrate->show();
1294             dvbSrateLabel->show();
1295             dvbBandBox->hide();
1296             dvbBandLabel->hide();
1297         }
1298         else if( dvbt->isChecked() )
1299         {
1300             dvbSrate->hide();
1301             dvbSrateLabel->hide();
1302             dvbBandBox->show();
1303             dvbBandLabel->show();
1304         }
1305         break;
1306 #endif
1307     case SCREEN_DEVICE:
1308         //ui.optionsBox->hide();
1309         ui.advancedButton->hide();
1310         break;
1311     }
1312
1313     advMRL.clear();
1314 }
1315
1316 void CaptureOpenPanel::advancedDialog()
1317 {
1318     /* Get selected device type */
1319     int i_devicetype = ui.deviceCombo->itemData(
1320                                 ui.deviceCombo->currentIndex() ).toInt();
1321
1322     /* Get the corresponding module */
1323     module_t *p_module =
1324         module_find( psz_devModule[i_devicetype] );
1325     if( NULL == p_module ) return;
1326
1327     /* Init */
1328     QList<ConfigControl *> controls;
1329
1330     /* Get the confsize  */
1331     unsigned int i_confsize;
1332     module_config_t *p_config;
1333     p_config = module_config_get( p_module, &i_confsize );
1334
1335     /* New Adv Prop dialog */
1336     adv = new QDialog( this );
1337     adv->setWindowTitle( qtr( "Advanced Options" ) );
1338     adv->setWindowRole( "vlc-advanced-options" );
1339
1340     /* A main Layout with a Frame */
1341     QVBoxLayout *mainLayout = new QVBoxLayout( adv );
1342     QScrollArea *scroll = new QScrollArea;
1343     mainLayout->addWidget( scroll );
1344
1345     QFrame *advFrame = new QFrame;
1346     /* GridLayout inside the Frame */
1347     QGridLayout *gLayout = new QGridLayout( advFrame );
1348
1349     scroll->setWidgetResizable( true );
1350     scroll->setWidget( advFrame );
1351
1352     /* Create the options inside the FrameLayout */
1353     for( int n = 0; n < (int)i_confsize; n++ )
1354     {
1355         module_config_t *p_item = p_config + n;
1356         ConfigControl *config = ConfigControl::createControl(
1357                         VLC_OBJECT( p_intf ), p_item, advFrame, gLayout, n );
1358         if ( config )
1359             controls.append( config );
1360     }
1361
1362     /* Button stuffs */
1363     QDialogButtonBox *advButtonBox = new QDialogButtonBox( adv );
1364     QPushButton *closeButton = new QPushButton( qtr( "OK" ) );
1365     QPushButton *cancelButton = new QPushButton( qtr( "Cancel" ) );
1366
1367     CONNECT( closeButton, clicked(), adv, accept() );
1368     CONNECT( cancelButton, clicked(), adv, reject() );
1369
1370     advButtonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
1371     advButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
1372
1373     mainLayout->addWidget( advButtonBox );
1374
1375     /* Creation of the MRL */
1376     if( adv->exec() )
1377     {
1378         QString tempMRL = "";
1379         for( int i = 0; i < controls.size(); i++ )
1380         {
1381             ConfigControl *control = controls[i];
1382
1383             tempMRL += (i ? " :" : ":");
1384
1385             if( control->getType() == CONFIG_ITEM_BOOL )
1386                 if( !(qobject_cast<VIntConfigControl *>(control)->getValue() ) )
1387                     tempMRL += "no-";
1388
1389             tempMRL += control->getName();
1390
1391             switch( control->getType() )
1392             {
1393                 case CONFIG_ITEM_STRING:
1394                 case CONFIG_ITEM_FILE:
1395                 case CONFIG_ITEM_DIRECTORY:
1396                 case CONFIG_ITEM_MODULE:
1397                     tempMRL += colon_escape( QString("=%1").arg( qobject_cast<VStringConfigControl *>(control)->getValue() ) );
1398                     break;
1399                 case CONFIG_ITEM_INTEGER:
1400                     tempMRL += QString("=%1").arg( qobject_cast<VIntConfigControl *>(control)->getValue() );
1401                     break;
1402                 case CONFIG_ITEM_FLOAT:
1403                     tempMRL += QString("=%1").arg( qobject_cast<VFloatConfigControl *>(control)->getValue() );
1404                     break;
1405             }
1406         }
1407         advMRL = tempMRL;
1408         updateMRL();
1409         msg_Dbg( p_intf, "%s", qtu( advMRL ) );
1410     }
1411     for( int i = 0; i < controls.size(); i++ )
1412     {
1413         ConfigControl *control = controls[i];
1414         delete control ;
1415     }
1416     delete adv;
1417     module_config_free( p_config );
1418     module_release (p_module);
1419 }
1420