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