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