]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/open.cpp
76a959b14d671c824745473926392b62f24d6add
[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  * $Id$
8  *
9  * Authors: Clément Stenac <zorglub@videolan.org>
10  *          Jean-Baptiste Kempf <jb@videolan.org>
11  *          Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26  *****************************************************************************/
27
28
29 #include "qt4.hpp"
30 #include "components/open.hpp"
31 #include "dialogs/open.hpp"
32 #include "dialogs_provider.hpp"
33 #include "util/customwidgets.hpp"
34
35 #include <QFileDialog>
36 #include <QDialogButtonBox>
37 #include <QLineEdit>
38 #include <QStackedLayout>
39 #include <QListView>
40
41 /**************************************************************************
42  * Open Files and subtitles                                               *
43  **************************************************************************/
44 FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
45                                 OpenPanel( _parent, _p_intf )
46 {
47     /* Classic UI Setup */
48     ui.setupUi( this );
49
50     /* Use a QFileDialog and customize it because we don't want to
51        rewrite it all. Be careful to your eyes cause there are a few hacks.
52        Be very careful and test correctly when you modify this. */
53
54     /* Set Filters for file selection */
55     QString fileTypes = "";
56     ADD_FILTER_MEDIA( fileTypes );
57     ADD_FILTER_VIDEO( fileTypes );
58     ADD_FILTER_AUDIO( fileTypes );
59     ADD_FILTER_PLAYLIST( fileTypes );
60     ADD_FILTER_ALL( fileTypes );
61     fileTypes.replace( QString(";*"), QString(" *"));
62
63     // Make this QFileDialog a child of tempWidget from the ui.
64     dialogBox = new FileOpenBox( ui.tempWidget, NULL,
65             qfu( p_intf->p_libvlc->psz_homedir ), fileTypes );
66
67     dialogBox->setFileMode( QFileDialog::ExistingFiles );
68     dialogBox->setAcceptMode( QFileDialog::AcceptOpen );
69
70     /* retrieve last known path used in file browsing */
71     char *psz_filepath = config_GetPsz( p_intf, "qt-filedialog-path" );
72     if( psz_filepath )
73     {
74         dialogBox->setDirectory( qfu( psz_filepath ) );
75         delete psz_filepath;
76     }
77
78     /* We don't want to see a grip in the middle of the window, do we? */
79     dialogBox->setSizeGripEnabled( false );
80
81     /* Add a tooltip */
82     dialogBox->setToolTip( qtr( "Select one or multiple files, or a folder" ) );
83
84     // Add it to the layout
85     ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
86
87     // But hide the two OK/Cancel buttons. Enable them for debug.
88     QDialogButtonBox *fileDialogAcceptBox =
89                                         findChildren<QDialogButtonBox*>()[0];
90     fileDialogAcceptBox->hide();
91
92     /* Ugly hacks to get the good Widget */
93     //This lineEdit is the normal line in the fileDialog.
94 #if QT43
95     lineFileEdit = findChildren<QLineEdit*>()[2];
96 #else
97     lineFileEdit = findChildren<QLineEdit*>()[3];
98 #endif
99 //    lineFileEdit->hide();
100
101     /* Make a list of QLabel inside the QFileDialog to access the good ones */
102     QList<QLabel *> listLabel = findChildren<QLabel*>();
103
104     /* Hide the FileNames one. Enable it for debug */
105     listLabel[4]->hide();
106     /* Change the text that was uncool in the usual box */
107     listLabel[5]->setText( qtr( "Filter:" ) );
108
109
110     QListView *fileListView = findChildren<QListView*>().first();
111 #if WIN32
112     /* QFileDialog is quite buggy make it brerable on win32 by tweaking
113        the followin */
114     fileListView->setLayoutMode(QListView::Batched);
115     fileListView->setViewMode(QListView::ListMode);
116     fileListView->setResizeMode(QListView::Adjust);
117     fileListView->setUniformItemSizes(false);
118     fileListView->setFlow(QListView::TopToBottom);
119     fileListView->setWrapping(true);
120 #endif
121
122     // Hide the subtitles control by default.
123     ui.subFrame->hide();
124
125     /* Build the subs size combo box */
126     setfillVLCConfigCombo( "freetype-rel-fontsize" , p_intf,
127                             ui.sizeSubComboBox );
128
129     /* Build the subs align combo box */
130     setfillVLCConfigCombo( "subsdec-align", p_intf, ui.alignSubComboBox );
131
132     /* Connects  */
133     BUTTONACT( ui.subBrowseButton, browseFileSub() );
134     BUTTONACT( ui.subCheckBox, toggleSubtitleFrame());
135
136 #if QT43
137     CONNECT( fileListView, clicked( QModelIndex ), this, updateMRL() );
138 #else
139     CONNECT( ui.fileInput, editTextChanged( QString ), this, updateMRL() );
140 #endif
141     CONNECT( ui.subInput, editTextChanged( QString ), this, updateMRL() );
142     CONNECT( ui.alignSubComboBox, currentIndexChanged( int ), this,
143                                                             updateMRL() );
144     CONNECT( ui.sizeSubComboBox, currentIndexChanged( int ), this,
145                                                             updateMRL() );
146
147     CONNECT( lineFileEdit, textChanged( QString ), this, browseFile() );
148 }
149
150 FileOpenPanel::~FileOpenPanel()
151 {}
152
153 QStringList FileOpenPanel::browse( QString help )
154 {
155     return THEDP->showSimpleOpen( help );
156 }
157
158 void FileOpenPanel::browseFile()
159 {
160     QString fileString = "";
161     foreach( QString file, dialogBox->selectedFiles() ) {
162          fileString += "\"" + file + "\" ";
163     }
164     ui.fileInput->setEditText( fileString );
165     updateMRL();
166 }
167
168 void FileOpenPanel::browseFileSub()
169 {
170     // FIXME Handle selection of more than one subtitles file
171     QStringList files = THEDP->showSimpleOpen( qtr("Open subtitles file"),
172                             EXT_FILTER_SUBTITLE,
173                             dialogBox->directory().absolutePath() );
174     if( files.isEmpty() ) return;
175     ui.subInput->setEditText( files.join(" ") );
176     updateMRL();
177 }
178
179 void FileOpenPanel::updateMRL()
180 {
181     msg_Dbg( p_intf, "I was here" );
182     QString mrl = ui.fileInput->currentText();
183
184     if( ui.subCheckBox->isChecked() ) {
185         mrl.append( " :sub-file=" + ui.subInput->currentText() );
186         int align = ui.alignSubComboBox->itemData(
187                     ui.alignSubComboBox->currentIndex() ).toInt();
188         mrl.append( " :subsdec-align=" + QString().setNum( align ) );
189         int size = ui.sizeSubComboBox->itemData(
190                    ui.sizeSubComboBox->currentIndex() ).toInt();
191         mrl.append( " :freetype-rel-fontsize=" + QString().setNum( size ) );
192     }
193
194     const char *psz_filepath = config_GetPsz( p_intf, "qt-filedialog-path" );
195     if( ( NULL == psz_filepath )
196       || strcmp( psz_filepath, qtu( dialogBox->directory().absolutePath() )) )
197     {
198         /* set dialog box current directory as last known path */
199         config_PutPsz( p_intf, "qt-filedialog-path",
200                        qtu( dialogBox->directory().absolutePath() ) );
201     }
202     delete psz_filepath;
203
204     emit mrlUpdated( mrl );
205     emit methodChanged( "file-caching" );
206 }
207
208
209 /* Function called by Open Dialog when clicke on Play/Enqueue */
210 void FileOpenPanel::accept()
211 {
212     ui.fileInput->addItem( ui.fileInput->currentText());
213     if ( ui.fileInput->count() > 8 ) ui.fileInput->removeItem( 0 );
214 }
215
216 void FileOpenBox::accept()
217 {
218     OpenDialog::getInstance( NULL, NULL )->play();
219 }
220
221 /* Function called by Open Dialog when clicked on cancel */
222 void FileOpenPanel::clear()
223 {
224     ui.fileInput->setEditText( "" );
225     ui.subInput->setEditText( "" );
226 }
227
228 void FileOpenPanel::toggleSubtitleFrame()
229 {
230     if ( ui.subFrame->isVisible() )
231     {
232         ui.subFrame->hide();
233         updateGeometry();
234     /* FiXME Size */
235     }
236     else
237     {
238         ui.subFrame->show();
239     }
240
241     /* Update the MRL */
242     updateMRL();
243 }
244
245 /**************************************************************************
246  * Open Discs ( DVD, CD, VCD and similar devices )                        *
247  **************************************************************************/
248 DiscOpenPanel::DiscOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
249                                 OpenPanel( _parent, _p_intf )
250 {
251     ui.setupUi( this );
252
253 #if WIN32 /* Disc drives probing for Windows */
254     char szDrives[512];
255     szDrives[0] = '\0';
256     if( GetLogicalDriveStringsA( sizeof( szDrives ) - 1, szDrives ) )
257     {
258         char *drive = szDrives;
259         UINT oldMode = SetErrorMode( SEM_FAILCRITICALERRORS );
260         while( *drive )
261         {
262             if( GetDriveTypeA(drive) == DRIVE_CDROM )
263                 ui.deviceCombo->addItem( drive );
264
265             /* go to next drive */
266             while( *(drive++) );
267         }
268         SetErrorMode(oldMode);
269     }
270 #endif /* Disc Probing under Windows */
271
272     /* CONNECTs */
273     BUTTONACT( ui.dvdRadioButton, updateButtons());
274     BUTTONACT( ui.vcdRadioButton, updateButtons());
275     BUTTONACT( ui.audioCDRadioButton, updateButtons());
276     BUTTONACT( ui.dvdsimple,  updateButtons());
277
278     CONNECT( ui.deviceCombo, editTextChanged( QString ), this, updateMRL());
279     CONNECT( ui.titleSpin, valueChanged( int ), this, updateMRL());
280     CONNECT( ui.chapterSpin, valueChanged( int ), this, updateMRL());
281     CONNECT( ui.audioSpin, valueChanged( int ), this, updateMRL());
282     CONNECT( ui.subtitlesSpin, valueChanged( int ), this, updateMRL());
283 }
284
285 DiscOpenPanel::~DiscOpenPanel()
286 {}
287
288 void DiscOpenPanel::clear()
289 {
290     ui.titleSpin->setValue( 0 );
291     ui.chapterSpin->setValue( 0 );
292 }
293
294 void DiscOpenPanel::updateButtons()
295 {
296     if ( ui.dvdRadioButton->isChecked() )
297     {
298         ui.titleLabel->setText( qtr("Title") );
299         ui.chapterLabel->show();
300         ui.chapterSpin->show();
301         ui.diskOptionBox_2->show();
302     }
303     else if ( ui.vcdRadioButton->isChecked() )
304     {
305         ui.titleLabel->setText( qtr("Entry") );
306         ui.chapterLabel->hide();
307         ui.chapterSpin->hide();
308         ui.diskOptionBox_2->show();
309     }
310     else
311     {
312         ui.titleLabel->setText( qtr("Track") );
313         ui.chapterLabel->hide();
314         ui.chapterSpin->hide();
315         ui.diskOptionBox_2->hide();
316     }
317
318     updateMRL();
319 }
320
321
322 void DiscOpenPanel::updateMRL()
323 {
324     QString mrl = "";
325
326     /* CDDAX and VCDX not implemented. FIXME ? */
327     /* DVD */
328     if( ui.dvdRadioButton->isChecked() ) {
329         if( !ui.dvdsimple->isChecked() )
330             mrl = "dvd://";
331         else
332             mrl = "dvdsimple://";
333         mrl += ui.deviceCombo->currentText();
334         emit methodChanged( "dvdnav-caching" );
335
336         if ( ui.titleSpin->value() > 0 ) {
337             mrl += QString("@%1").arg( ui.titleSpin->value() );
338             if ( ui.chapterSpin->value() > 0 ) {
339                 mrl+= QString(":%1").arg( ui.chapterSpin->value() );
340             }
341         }
342
343     /* VCD */
344     } else if ( ui.vcdRadioButton->isChecked() ) {
345         mrl = "vcd://" + ui.deviceCombo->currentText();
346         emit methodChanged( "vcd-caching" );
347
348         if( ui.titleSpin->value() > 0 ) {
349             mrl += QString("@E%1").arg( ui.titleSpin->value() );
350         }
351
352     /* CDDA */
353     } else {
354         mrl = "cdda://" + ui.deviceCombo->currentText();
355         if( ui.titleSpin->value() > 0 ) {
356             QString("@%1").arg( ui.titleSpin->value() );
357         }
358     }
359
360     if ( ui.dvdRadioButton->isChecked() || ui.vcdRadioButton->isChecked() )
361     {
362         if ( ui.audioSpin->value() >= 0 ) {
363             mrl += " :audio-track=" +
364                 QString("%1").arg( ui.audioSpin->value() );
365         }
366         if ( ui.subtitlesSpin->value() >= 0 ) {
367             mrl += " :sub-track=" +
368                 QString("%1").arg( ui.subtitlesSpin->value() );
369         }
370     }
371     emit mrlUpdated( mrl );
372 }
373
374
375 /**************************************************************************
376  * Open Network streams and URL pages                                     *
377  **************************************************************************/
378 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
379                                 OpenPanel( _parent, _p_intf )
380 {
381     ui.setupUi( this );
382
383     /* CONNECTs */
384     CONNECT( ui.protocolCombo, currentIndexChanged( int ),
385              this, updateProtocol( int ) );
386     CONNECT( ui.portSpin, valueChanged( int ), this, updateMRL() );
387     CONNECT( ui.addressText, textChanged( QString ), this, updateAddress());
388     CONNECT( ui.timeShift, clicked(), this, updateMRL());
389     CONNECT( ui.ipv6, clicked(), this, updateMRL());
390
391     ui.protocolCombo->addItem("HTTP", QVariant("http"));
392     ui.protocolCombo->addItem("HTTPS", QVariant("https"));
393     ui.protocolCombo->addItem("FTP", QVariant("ftp"));
394     ui.protocolCombo->addItem("MMS", QVariant("mms"));
395     ui.protocolCombo->addItem("RTSP", QVariant("rtsp"));
396     ui.protocolCombo->addItem("UDP/RTP (unicast)", QVariant("udp"));
397     ui.protocolCombo->addItem("UDP/RTP (multicast)", QVariant("udp"));
398 }
399
400 NetOpenPanel::~NetOpenPanel()
401 {}
402
403 void NetOpenPanel::clear()
404 {}
405
406 void NetOpenPanel::updateProtocol( int idx ) {
407     QString addr = ui.addressText->text();
408     QString proto = ui.protocolCombo->itemData( idx ).toString();
409
410     ui.timeShift->setEnabled( idx >= 5 );
411     ui.ipv6->setEnabled( idx == 5 );
412     ui.addressText->setEnabled( idx != 5 );
413     ui.portSpin->setEnabled( idx >= 5 );
414
415     /* If we already have a protocol in the address, replace it */
416     if( addr.contains( "://")) {
417         msg_Err( p_intf, "replace");
418         addr.replace( QRegExp("^.*://"), proto + "://");
419         ui.addressText->setText( addr );
420     }
421     updateMRL();
422 }
423
424 void NetOpenPanel::updateAddress() {
425     updateMRL();
426 }
427
428 void NetOpenPanel::updateMRL() {
429     QString mrl = "";
430     QString addr = ui.addressText->text();
431     int proto = ui.protocolCombo->currentIndex();
432
433     if( addr.contains( "://") && proto != 5 ) {
434         mrl = addr;
435     } else {
436         switch( proto ) {
437         case 0:
438             mrl = "http://" + addr;
439         case 1:
440             mrl = "https://" + addr;
441             emit methodChanged("http-caching");
442             break;
443         case 3:
444             mrl = "mms://" + addr;
445             emit methodChanged("mms-caching");
446             break;
447         case 2:
448             mrl = "ftp://" + addr;
449             emit methodChanged("ftp-caching");
450             break;
451         case 4: /* RTSP */
452             mrl = "rtsp://" + addr;
453             emit methodChanged("rtsp-caching");
454             break;
455         case 5:
456             mrl = "udp://@";
457             if( ui.ipv6->isEnabled() && ui.ipv6->isChecked() ) {
458                 mrl += "[::]";
459             }
460             mrl += QString(":%1").arg( ui.portSpin->value() );
461             emit methodChanged("udp-caching");
462             break;
463         case 6: /* UDP multicast */
464             mrl = "udp://@";
465             /* Add [] to IPv6 */
466             if ( addr.contains(':') && !addr.contains('[') ) {
467                 mrl += "[" + addr + "]";
468             } else mrl += addr;
469             mrl += QString(":%1").arg( ui.portSpin->value() );
470             emit methodChanged("udp-caching");
471         }
472     }
473     if( ui.timeShift->isEnabled() && ui.timeShift->isChecked() ) {
474         mrl += " :access-filter=timeshift";
475     }
476     emit mrlUpdated( mrl );
477 }
478
479 /**************************************************************************
480  * Open Capture device ( DVB, PVR, V4L, and similar )                     *
481  **************************************************************************/
482 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
483                                 OpenPanel( _parent, _p_intf )
484 {
485     ui.setupUi( this );
486
487     /* Create two stacked layouts in the main comboBoxes */
488     QStackedLayout *stackedDevLayout = new QStackedLayout;
489     ui.cardBox->setLayout( stackedDevLayout );
490
491     QStackedLayout *stackedPropLayout = new QStackedLayout;
492     ui.optionsBox->setLayout( stackedPropLayout );
493
494     /* Creation and connections of the WIdgets in the stacked layout */
495 #define addModuleAndLayouts( number, name, label )                    \
496     QWidget * name ## DevPage = new QWidget( this );                  \
497     QWidget * name ## PropPage = new QWidget( this );                 \
498     stackedDevLayout->addWidget( name ## DevPage );        \
499     stackedPropLayout->addWidget( name ## PropPage );      \
500     QGridLayout * name ## DevLayout = new QGridLayout;                \
501     QGridLayout * name ## PropLayout = new QGridLayout;               \
502     name ## DevPage->setLayout( name ## DevLayout );                  \
503     name ## PropPage->setLayout( name ## PropLayout );                \
504     ui.deviceCombo->addItem( qtr( label ), QVariant( number ) );
505
506 #define CuMRL( widget, slot ) CONNECT( widget , slot , this, updateMRL() );
507
508     /*******
509      * V4L *
510      *******/
511     addModuleAndLayouts( V4L_DEVICE, v4l, "Video for Linux" );
512
513     /* V4l Main panel */
514     QLabel *v4lVideoDeviceLabel = new QLabel( qtr( "Video device name" ) );
515     v4lDevLayout->addWidget( v4lVideoDeviceLabel, 0, 0 );
516
517     v4lVideoDevice = new QLineEdit;
518     v4lDevLayout->addWidget( v4lVideoDevice, 0, 1 );
519
520     QLabel *v4lAudioDeviceLabel = new QLabel( qtr( "Audio device name" ) );
521     v4lDevLayout->addWidget( v4lAudioDeviceLabel, 1, 0 );
522
523     v4lAudioDevice = new QLineEdit;
524     v4lDevLayout->addWidget( v4lAudioDevice, 1, 1 );
525
526     /* V4l Props panel */
527     QLabel *v4lNormLabel = new QLabel( qtr( "Norm" ) );
528     v4lPropLayout->addWidget( v4lNormLabel, 0 , 0 );
529
530     v4lNormBox = new QComboBox;
531     setfillVLCConfigCombo( "v4l-norm", p_intf, v4lNormBox );
532     v4lPropLayout->addWidget( v4lNormBox, 0 , 1 );
533
534     QLabel *v4lFreqLabel = new QLabel( qtr( "Frequency" ) );
535     v4lPropLayout->addWidget( v4lFreqLabel, 1 , 0 );
536
537     v4lFreq = new QSpinBox;
538     v4lFreq->setAlignment( Qt::AlignRight );
539     v4lFreq->setSuffix(" kHz");
540     setSpinBoxFreq( v4lFreq );
541     v4lPropLayout->addWidget( v4lFreq, 1 , 1 );
542
543     /* v4l CONNECTs */
544     CuMRL( v4lVideoDevice, textChanged( QString ) );
545     CuMRL( v4lAudioDevice, textChanged( QString ) );
546     CuMRL( v4lFreq, valueChanged ( int ) );
547     CuMRL( v4lNormBox,  currentIndexChanged ( int ) );
548
549     /*******
550      * JACK *
551      *******/
552     addModuleAndLayouts( JACK_DEVICE, jack, "JACK Audio Connection Kit" );
553
554     /* Jack Main panel */
555     /* Channels */
556     QLabel *jackChannelsLabel = new QLabel( qtr( "Channels :" ) );
557     jackDevLayout->addWidget( jackChannelsLabel, 1, 0 );
558
559     jackChannels = new QSpinBox;
560     setSpinBoxFreq( jackChannels );
561     jackChannels->setMaximum(255);
562     jackChannels->setValue(2);
563     jackChannels->setAlignment( Qt::AlignRight );
564     jackDevLayout->addWidget( jackChannels, 1, 1 );
565
566     /* Jack Props panel */
567  
568     /* Selected ports */
569     QLabel *jackPortsLabel = new QLabel( qtr( "Selected ports :" ) );
570     jackPropLayout->addWidget( jackPortsLabel, 0 , 0 );
571
572     jackPortsSelected = new QLineEdit( qtr( ".*") );
573     jackPortsSelected->setAlignment( Qt::AlignRight );
574     jackPropLayout->addWidget( jackPortsSelected, 0, 1 );
575  
576     /* Caching */
577     QLabel *jackCachingLabel = new QLabel( qtr( "Input caching :" ) );
578     jackPropLayout->addWidget( jackCachingLabel, 1 , 0 );
579     jackCaching = new QSpinBox;
580     setSpinBoxFreq( jackCaching );
581     jackCaching->setSuffix( " ms" );
582     jackCaching->setValue(1000);
583     jackCaching->setAlignment( Qt::AlignRight );
584     jackPropLayout->addWidget( jackCaching, 1 , 1 );
585  
586     /* Pace */
587     jackPace = new QCheckBox(qtr( "Use VLC pace" ));
588     jackPropLayout->addWidget( jackPace, 2, 1 );
589  
590     /* Auto Connect */
591     jackConnect = new QCheckBox( qtr( "Auto connnection" ));
592     jackPropLayout->addWidget( jackConnect, 3, 1 );
593  
594     /* Jack CONNECTs */
595     CuMRL( jackChannels, valueChanged( int ) );
596     CuMRL( jackCaching, valueChanged( int ) );
597     CuMRL( jackPace, stateChanged( int ) );
598     CuMRL( jackConnect, stateChanged( int ) );
599     CuMRL( jackPortsSelected, textChanged( QString ) );
600
601     /************
602      * PVR      *
603      ************/
604     addModuleAndLayouts( PVR_DEVICE, pvr, "PVR" );
605
606     /* PVR Main panel */
607     QLabel *pvrDeviceLabel = new QLabel( qtr( "Device name" ) );
608     pvrDevLayout->addWidget( pvrDeviceLabel, 0, 0 );
609
610     pvrDevice = new QLineEdit;
611     pvrDevLayout->addWidget( pvrDevice, 0, 1 );
612
613     QLabel *pvrRadioDeviceLabel = new QLabel( qtr( "Radio device name" ) );
614     pvrDevLayout->addWidget( pvrRadioDeviceLabel, 1, 0 );
615
616     pvrRadioDevice = new QLineEdit;
617     pvrDevLayout->addWidget( pvrRadioDevice, 1, 1 );
618
619     /* PVR props panel */
620     QLabel *pvrNormLabel = new QLabel( qtr( "Norm" ) );
621     pvrPropLayout->addWidget( pvrNormLabel, 0, 0 );
622
623     pvrNormBox = new QComboBox;
624     setfillVLCConfigCombo( "pvr-norm", p_intf, pvrNormBox );
625     pvrPropLayout->addWidget( pvrNormBox, 0, 1 );
626
627     QLabel *pvrFreqLabel = new QLabel( qtr( "Frequency" ) );
628     pvrPropLayout->addWidget( pvrFreqLabel, 1, 0 );
629
630     pvrFreq = new QSpinBox;
631     pvrFreq->setAlignment( Qt::AlignRight );
632     pvrFreq->setSuffix(" kHz");
633     setSpinBoxFreq( pvrFreq );
634     pvrPropLayout->addWidget( pvrFreq, 1, 1 );
635
636     QLabel *pvrBitrLabel = new QLabel( qtr( "Bitrate" ) );
637     pvrPropLayout->addWidget( pvrBitrLabel, 2, 0 );
638
639     pvrBitr = new QSpinBox;
640     pvrBitr->setAlignment( Qt::AlignRight );
641     pvrBitr->setSuffix(" kHz");
642     setSpinBoxFreq( pvrBitr );
643     pvrPropLayout->addWidget( pvrBitr, 2, 1 );
644
645     /* PVR CONNECTs */
646     CuMRL( pvrDevice, textChanged( QString ) );
647     CuMRL( pvrRadioDevice, textChanged( QString ) );
648
649     CuMRL( pvrFreq, valueChanged ( int ) );
650     CuMRL( pvrBitr, valueChanged ( int ) );
651     CuMRL( pvrNormBox,  currentIndexChanged ( int ) );
652
653     /*********************
654      * DirectShow Stuffs *
655      *********************/
656     addModuleAndLayouts( DSHOW_DEVICE, dshow, "DirectShow" );
657
658     /* dshow Main */
659
660     QLabel *dshowVDeviceLabel = new QLabel( qtr( "Video Device Name " ) );
661     dshowDevLayout->addWidget( dshowVDeviceLabel, 0, 0 );
662
663     QLabel *dshowADeviceLabel = new QLabel( qtr( "Audio Device Name " ) );
664     dshowDevLayout->addWidget( dshowADeviceLabel, 1, 0 );
665
666     QComboBox *dshowVDevice = new QComboBox;
667     dshowDevLayout->addWidget( dshowVDevice, 0, 1 );
668
669     QComboBox *dshowADevice = new QComboBox;
670     dshowDevLayout->addWidget( dshowADevice, 1, 1 );
671
672     QPushButton *dshowVRefresh = new QPushButton( qtr( "Update List" ) );
673     dshowDevLayout->addWidget( dshowVRefresh, 0, 2 );
674
675     QPushButton *dshowARefresh = new QPushButton( qtr( "Update List" ) );
676     dshowDevLayout->addWidget( dshowARefresh, 1, 2 );
677
678     QPushButton *dshowVConfig = new QPushButton( qtr( "Configure" ) );
679     dshowDevLayout->addWidget( dshowVConfig, 0, 3 );
680
681     QPushButton *dshowAConfig = new QPushButton( qtr( "Configure" ) );
682     dshowDevLayout->addWidget( dshowAConfig, 1, 3 );
683
684     /* dshow Properties */
685
686     QLabel *dshowVSizeLabel = new QLabel( qtr( "Video size" ) );
687     dshowPropLayout->addWidget( dshowVSizeLabel, 0, 0 );
688
689     QLineEdit *dshowVSizeLine = new QLineEdit;
690     dshowPropLayout->addWidget( dshowVSizeLine, 0, 1);
691
692     /* dshow CONNECTs */
693     CuMRL( dshowVDevice, currentIndexChanged ( int ) );
694     CuMRL( dshowADevice, currentIndexChanged ( int ) );
695     CuMRL( dshowVSizeLine, textChanged( QString ) );
696
697     /**************
698      * BDA Stuffs *
699      **************/
700     addModuleAndLayouts( BDA_DEVICE, bda, "DVB DirectShow" );
701
702     /* bda Main */
703     QLabel *bdaTypeLabel = new QLabel( qtr( "DVB Type:" ) );
704
705     bdas = new QRadioButton( "DVB-S" );
706     bdas->setChecked( true );
707     bdac = new QRadioButton( "DVB-C" );
708     bdat = new QRadioButton( "DVB-T" );
709
710     bdaDevLayout->addWidget( bdaTypeLabel, 0, 0 );
711     bdaDevLayout->addWidget( bdas, 0, 1 );
712     bdaDevLayout->addWidget( bdac, 0, 2 );
713     bdaDevLayout->addWidget( bdat, 0, 3 );
714
715     /* bda Props */
716     QLabel *bdaFreqLabel =
717                     new QLabel( qtr( "Transponder/multiplex frequency" ) );
718     bdaPropLayout->addWidget( bdaFreqLabel, 0, 0 );
719
720     bdaFreq = new QSpinBox;
721     bdaFreq->setAlignment( Qt::AlignRight );
722     bdaFreq->setSuffix(" kHz");
723     bdaFreq->setSingleStep( 1000 );
724     setSpinBoxFreq( bdaFreq )
725     bdaPropLayout->addWidget( bdaFreq, 0, 1 );
726
727     bdaSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
728     bdaPropLayout->addWidget( bdaSrateLabel, 1, 0 );
729
730     bdaSrate = new QSpinBox;
731     bdaSrate->setAlignment( Qt::AlignRight );
732     bdaSrate->setSuffix(" kHz");
733     setSpinBoxFreq( bdaSrate );
734     bdaPropLayout->addWidget( bdaSrate, 1, 1 );
735
736     bdaBandLabel = new QLabel( qtr( "Bandwidth" ) );
737     bdaPropLayout->addWidget( bdaBandLabel, 2, 0 );
738
739     bdaBandBox = new QComboBox;
740     setfillVLCConfigCombo( "dvb-bandwidth", p_intf, bdaBandBox );
741     bdaPropLayout->addWidget( bdaBandBox, 2, 1 );
742
743     bdaBandLabel->hide();
744     bdaBandBox->hide();
745
746     /* bda CONNECTs */
747     CuMRL( bdaFreq, valueChanged ( int ) );
748     CuMRL( bdaSrate, valueChanged ( int ) );
749     CuMRL( bdaBandBox,  currentIndexChanged ( int ) );
750     BUTTONACT( bdas, updateButtons() );
751     BUTTONACT( bdat, updateButtons() );
752     BUTTONACT( bdac, updateButtons() );
753     BUTTONACT( bdas, updateMRL() );
754     BUTTONACT( bdat, updateMRL() );
755     BUTTONACT( bdac, updateMRL() );
756
757     /**************
758      * DVB Stuffs *
759      **************/
760     addModuleAndLayouts( DVB_DEVICE, dvb, "DVB" );
761
762     /* DVB Main */
763     QLabel *dvbDeviceLabel = new QLabel( qtr( "Adapter card to tune" ) );
764     QLabel *dvbTypeLabel = new QLabel( qtr( "DVB Type:" ) );
765
766     dvbCard = new QSpinBox;
767     dvbCard->setAlignment( Qt::AlignRight );
768     dvbCard->setPrefix( "/dev/dvb/adapter" );
769
770     dvbDevLayout->addWidget( dvbDeviceLabel, 0, 0 );
771     dvbDevLayout->addWidget( dvbCard, 0, 2, 1, 2 );
772
773     dvbs = new QRadioButton( "DVB-S" );
774     dvbs->setChecked( true );
775     dvbc = new QRadioButton( "DVB-C" );
776     dvbt = new QRadioButton( "DVB-T" );
777
778     dvbDevLayout->addWidget( dvbTypeLabel, 1, 0 );
779     dvbDevLayout->addWidget( dvbs, 1, 1 );
780     dvbDevLayout->addWidget( dvbc, 1, 2 );
781     dvbDevLayout->addWidget( dvbt, 1, 3 );
782
783     /* DVB Props panel */
784     QLabel *dvbFreqLabel =
785                     new QLabel( qtr( "Transponder/multiplex frequency" ) );
786     dvbPropLayout->addWidget( dvbFreqLabel, 0, 0 );
787
788     dvbFreq = new QSpinBox;
789     dvbFreq->setAlignment( Qt::AlignRight );
790     dvbFreq->setSuffix(" kHz");
791     setSpinBoxFreq( dvbFreq  );
792     dvbPropLayout->addWidget( dvbFreq, 0, 1 );
793
794     QLabel *dvbSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
795     dvbPropLayout->addWidget( dvbSrateLabel, 1, 0 );
796
797     dvbSrate = new QSpinBox;
798     dvbSrate->setAlignment( Qt::AlignRight );
799     dvbSrate->setSuffix(" kHz");
800     setSpinBoxFreq( dvbSrate );
801     dvbPropLayout->addWidget( dvbSrate, 1, 1 );
802
803     /* DVB CONNECTs */
804     CuMRL( dvbCard, valueChanged ( int ) );
805     CuMRL( dvbFreq, valueChanged ( int ) );
806     CuMRL( dvbSrate, valueChanged ( int ) );
807
808     BUTTONACT( dvbs, updateButtons() );
809     BUTTONACT( dvbt, updateButtons() );
810     BUTTONACT( dvbc, updateButtons() );
811
812     /**********
813      * Screen *
814      **********/
815     addModuleAndLayouts( SCREEN_DEVICE, screen, "Desktop" );
816     QLabel *screenLabel = new QLabel( "This option will open your own "
817             "desktop in order to save or stream it.");
818     screenLabel->setWordWrap( true );
819     screenDevLayout->addWidget( screenLabel, 0, 0 );
820
821     /* General connects */
822     connect( ui.deviceCombo, SIGNAL( activated( int ) ),
823                      stackedDevLayout, SLOT( setCurrentIndex( int ) ) );
824     connect( ui.deviceCombo, SIGNAL( activated( int ) ),
825                      stackedPropLayout, SLOT( setCurrentIndex( int ) ) );
826     CONNECT( ui.deviceCombo, activated( int ), this, updateMRL() );
827     CONNECT( ui.deviceCombo, activated( int ), this, updateButtons() );
828
829 #undef addModule
830 }
831
832 CaptureOpenPanel::~CaptureOpenPanel()
833 {}
834
835 void CaptureOpenPanel::clear()
836 {}
837
838 void CaptureOpenPanel::updateMRL()
839 {
840     QString mrl = "";
841     int i_devicetype = ui.deviceCombo->itemData(
842             ui.deviceCombo->currentIndex() ).toInt();
843     switch( i_devicetype )
844     {
845     case V4L_DEVICE:
846         mrl = "v4l://";
847         mrl += " :v4l-vdev=" + v4lVideoDevice->text();
848         mrl += " :v4l-adev=" + v4lAudioDevice->text();
849         mrl += " :v4l-norm=" + QString("%1").arg( v4lNormBox->currentIndex() );
850         mrl += " :v4l-frequency=" + QString("%1").arg( v4lFreq->value() );
851         break;
852     case JACK_DEVICE:
853         mrl = "jack://";
854         mrl += "channels=" + QString("%1").arg( jackChannels->value() );
855         mrl += ":ports=" + jackPortsSelected->text();
856         mrl += " --jack-input-caching=" + QString("%1").arg( jackCaching->value() );
857         if ( jackPace->isChecked() )
858         {
859                 mrl += " --jack-input-use-vlc-pace";
860         }
861         if ( jackConnect->isChecked() )
862         {
863                 mrl += " --jack-input-auto-connect";
864         }
865         break;
866     case PVR_DEVICE:
867         mrl = "pvr://";
868         mrl += " :pvr-device=" + pvrDevice->text();
869         mrl += " :pvr-radio-device=" + pvrRadioDevice->text();
870         mrl += " :pvr-norm=" + QString("%1").arg( pvrNormBox->currentIndex() );
871         if( pvrFreq->value() )
872             mrl += " :pvr-frequency=" + QString("%1").arg( pvrFreq->value() );
873         if( pvrBitr->value() )
874             mrl += " :pvr-bitrate=" + QString("%1").arg( pvrBitr->value() );
875         break;
876     case DVB_DEVICE:
877         mrl = "dvb://";
878         mrl += " :dvb-adapter=" + QString("%1").arg( dvbCard->value() );
879         mrl += " :dvb-frequency=" + QString("%1").arg( dvbFreq->value() );
880         mrl += " :dvb-srate=" + QString("%1").arg( dvbSrate->value() );
881         break;
882     case BDA_DEVICE:
883         if( bdas->isChecked() ) mrl = "dvb-s://";
884         else if(  bdat->isChecked() ) mrl = "dvb-t://";
885         else if(  bdac->isChecked() ) mrl = "dvb-c://";
886         else return;
887         mrl += " :dvb-frequency=" + QString("%1").arg( bdaFreq->value() );
888         if( bdas->isChecked() || bdac->isChecked() )
889             mrl += " :dvb-srate=" + QString("%1").arg( bdaSrate->value() );
890         else
891             mrl += " :dvb-bandwidth=" +
892                 QString("%1").arg( bdaBandBox->itemData(
893                     bdaBandBox->currentIndex() ).toInt() );
894         break;
895     case DSHOW_DEVICE:
896         break;
897     case SCREEN_DEVICE:
898         mrl = "screen://";
899         updateButtons();
900         break;
901     }
902     emit mrlUpdated( mrl );
903 }
904
905 /**
906  * Update the Buttons (show/hide) for the GUI as all device type don't
907  * use the same ui. elements.
908  **/
909 void CaptureOpenPanel::updateButtons()
910 {
911     /*  Be sure to display the ui Elements in case they were hidden by
912      *  some Device Type (like Screen://) */
913     ui.optionsBox->show();
914     ui.advancedButton->show();
915     /* Get the current Device Number */
916     int i_devicetype = ui.deviceCombo->itemData(
917                                 ui.deviceCombo->currentIndex() ).toInt();
918     msg_Dbg( p_intf, "Capture Type: %i", i_devicetype );
919     switch( i_devicetype )
920     {
921     case DVB_DEVICE:
922         if( dvbs->isChecked() ) dvbFreq->setSuffix(" kHz");
923         if( dvbc->isChecked() || dvbt->isChecked() ) dvbFreq->setSuffix(" Hz");
924         break;
925     case BDA_DEVICE:
926         if( bdas->isChecked() || bdac->isChecked() )
927         {
928             bdaSrate->show();
929             bdaSrateLabel->show();
930             bdaBandBox->hide();
931             bdaBandLabel->hide();
932         }
933         else
934         {
935             bdaSrate->hide();
936             bdaSrateLabel->hide();
937             bdaBandBox->show();
938             bdaBandLabel->show();
939         }
940         break;
941     case SCREEN_DEVICE:
942         ui.optionsBox->hide();
943         ui.advancedButton->hide();
944         break;
945     }
946 }