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