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