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