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