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