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