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