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