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