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