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