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