]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/open.cpp
Removes trailing spaces. Removes tabs.
[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     /*Win 32 Probe  as in WX ? */
254
255     /* CONNECTs */
256     BUTTONACT( ui.dvdRadioButton, updateButtons());
257     BUTTONACT( ui.vcdRadioButton, updateButtons());
258     BUTTONACT( ui.audioCDRadioButton, updateButtons());
259     BUTTONACT( ui.dvdsimple,  updateButtons());
260
261     CONNECT( ui.deviceCombo, editTextChanged( QString ), this, updateMRL());
262     CONNECT( ui.titleSpin, valueChanged( int ), this, updateMRL());
263     CONNECT( ui.chapterSpin, valueChanged( int ), this, updateMRL());
264     CONNECT( ui.audioSpin, valueChanged( int ), this, updateMRL());
265     CONNECT( ui.subtitlesSpin, valueChanged( int ), this, updateMRL());
266 }
267
268 DiscOpenPanel::~DiscOpenPanel()
269 {}
270
271 void DiscOpenPanel::clear()
272 {
273     ui.titleSpin->setValue( 0 );
274     ui.chapterSpin->setValue( 0 );
275 }
276
277 void DiscOpenPanel::updateButtons()
278 {
279     if ( ui.dvdRadioButton->isChecked() )
280     {
281         ui.titleLabel->setText( qtr("Title") );
282         ui.chapterLabel->show();
283         ui.chapterSpin->show();
284         ui.diskOptionBox_2->show();
285     }
286     else if ( ui.vcdRadioButton->isChecked() )
287     {
288         ui.titleLabel->setText( qtr("Entry") );
289         ui.chapterLabel->hide();
290         ui.chapterSpin->hide();
291         ui.diskOptionBox_2->show();
292     }
293     else
294     {
295         ui.titleLabel->setText( qtr("Track") );
296         ui.chapterLabel->hide();
297         ui.chapterSpin->hide();
298         ui.diskOptionBox_2->hide();
299     }
300
301     updateMRL();
302 }
303
304
305 void DiscOpenPanel::updateMRL()
306 {
307     QString mrl = "";
308
309     /* CDDAX and VCDX not implemented. FIXME ? */
310     /* DVD */
311     if( ui.dvdRadioButton->isChecked() ) {
312         if( !ui.dvdsimple->isChecked() )
313             mrl = "dvd://";
314         else
315             mrl = "dvdsimple://";
316         mrl += ui.deviceCombo->currentText();
317         emit methodChanged( "dvdnav-caching" );
318
319         if ( ui.titleSpin->value() > 0 ) {
320             mrl += QString("@%1").arg( ui.titleSpin->value() );
321             if ( ui.chapterSpin->value() > 0 ) {
322                 mrl+= QString(":%1").arg( ui.chapterSpin->value() );
323             }
324         }
325
326     /* VCD */
327     } else if ( ui.vcdRadioButton->isChecked() ) {
328         mrl = "vcd://" + ui.deviceCombo->currentText();
329         emit methodChanged( "vcd-caching" );
330
331         if( ui.titleSpin->value() > 0 ) {
332             mrl += QString("@E%1").arg( ui.titleSpin->value() );
333         }
334
335     /* CDDA */
336     } else {
337         mrl = "cdda://" + ui.deviceCombo->currentText();
338         if( ui.titleSpin->value() > 0 ) {
339             QString("@%1").arg( ui.titleSpin->value() );
340         }
341     }
342
343     if ( ui.dvdRadioButton->isChecked() || ui.vcdRadioButton->isChecked() )
344     {
345         if ( ui.audioSpin->value() >= 0 ) {
346             mrl += " :audio-track=" +
347                 QString("%1").arg( ui.audioSpin->value() );
348         }
349         if ( ui.subtitlesSpin->value() >= 0 ) {
350             mrl += " :sub-track=" +
351                 QString("%1").arg( ui.subtitlesSpin->value() );
352         }
353     }
354     emit mrlUpdated( mrl );
355 }
356
357
358 /**************************************************************************
359  * Open Network streams and URL pages                                     *
360  **************************************************************************/
361 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
362                                 OpenPanel( _parent, _p_intf )
363 {
364     ui.setupUi( this );
365
366     /* CONNECTs */
367     CONNECT( ui.protocolCombo, currentIndexChanged( int ),
368              this, updateProtocol( int ) );
369     CONNECT( ui.portSpin, valueChanged( int ), this, updateMRL() );
370     CONNECT( ui.addressText, textChanged( QString ), this, updateAddress());
371     CONNECT( ui.timeShift, clicked(), this, updateMRL());
372     CONNECT( ui.ipv6, clicked(), this, updateMRL());
373
374     ui.protocolCombo->addItem("HTTP", QVariant("http"));
375     ui.protocolCombo->addItem("HTTPS", QVariant("https"));
376     ui.protocolCombo->addItem("FTP", QVariant("ftp"));
377     ui.protocolCombo->addItem("MMS", QVariant("mms"));
378     ui.protocolCombo->addItem("RTSP", QVariant("rtsp"));
379     ui.protocolCombo->addItem("UDP/RTP (unicast)", QVariant("udp"));
380     ui.protocolCombo->addItem("UDP/RTP (multicast)", QVariant("udp"));
381 }
382
383 NetOpenPanel::~NetOpenPanel()
384 {}
385
386 void NetOpenPanel::clear()
387 {}
388
389 void NetOpenPanel::updateProtocol( int idx ) {
390     QString addr = ui.addressText->text();
391     QString proto = ui.protocolCombo->itemData( idx ).toString();
392
393     ui.timeShift->setEnabled( idx >= 5 );
394     ui.ipv6->setEnabled( idx == 5 );
395     ui.addressText->setEnabled( idx != 5 );
396     ui.portSpin->setEnabled( idx >= 5 );
397
398     /* If we already have a protocol in the address, replace it */
399     if( addr.contains( "://")) {
400         msg_Err( p_intf, "replace");
401         addr.replace( QRegExp("^.*://"), proto + "://");
402         ui.addressText->setText( addr );
403     }
404     updateMRL();
405 }
406
407 void NetOpenPanel::updateAddress() {
408     updateMRL();
409 }
410
411 void NetOpenPanel::updateMRL() {
412     QString mrl = "";
413     QString addr = ui.addressText->text();
414     int proto = ui.protocolCombo->currentIndex();
415
416     if( addr.contains( "://") && proto != 5 ) {
417         mrl = addr;
418     } else {
419         switch( proto ) {
420         case 0:
421             mrl = "http://" + addr;
422         case 1:
423             mrl = "https://" + addr;
424             emit methodChanged("http-caching");
425             break;
426         case 3:
427             mrl = "mms://" + addr;
428             emit methodChanged("mms-caching");
429             break;
430         case 2:
431             mrl = "ftp://" + addr;
432             emit methodChanged("ftp-caching");
433             break;
434         case 4: /* RTSP */
435             mrl = "rtsp://" + addr;
436             emit methodChanged("rtsp-caching");
437             break;
438         case 5:
439             mrl = "udp://@";
440             if( ui.ipv6->isEnabled() && ui.ipv6->isChecked() ) {
441                 mrl += "[::]";
442             }
443             mrl += QString(":%1").arg( ui.portSpin->value() );
444             emit methodChanged("udp-caching");
445             break;
446         case 6: /* UDP multicast */
447             mrl = "udp://@";
448             /* Add [] to IPv6 */
449             if ( addr.contains(':') && !addr.contains('[') ) {
450                 mrl += "[" + addr + "]";
451             } else mrl += addr;
452             mrl += QString(":%1").arg( ui.portSpin->value() );
453             emit methodChanged("udp-caching");
454         }
455     }
456     if( ui.timeShift->isEnabled() && ui.timeShift->isChecked() ) {
457         mrl += " :access-filter=timeshift";
458     }
459     emit mrlUpdated( mrl );
460 }
461
462 /**************************************************************************
463  * Open Capture device ( DVB, PVR, V4L, and similar )                     *
464  **************************************************************************/
465 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
466                                 OpenPanel( _parent, _p_intf )
467 {
468     ui.setupUi( this );
469
470     /* Create two stacked layouts in the main comboBoxes */
471     QStackedLayout *stackedDevLayout = new QStackedLayout;
472     ui.cardBox->setLayout( stackedDevLayout );
473
474     QStackedLayout *stackedPropLayout = new QStackedLayout;
475     ui.optionsBox->setLayout( stackedPropLayout );
476
477     /* Creation and connections of the WIdgets in the stacked layout */
478 #define addModuleAndLayouts( number, name, label )                    \
479     QWidget * name ## DevPage = new QWidget( this );                  \
480     QWidget * name ## PropPage = new QWidget( this );                 \
481     stackedDevLayout->addWidget( name ## DevPage );        \
482     stackedPropLayout->addWidget( name ## PropPage );      \
483     QGridLayout * name ## DevLayout = new QGridLayout;                \
484     QGridLayout * name ## PropLayout = new QGridLayout;               \
485     name ## DevPage->setLayout( name ## DevLayout );                  \
486     name ## PropPage->setLayout( name ## PropLayout );                \
487     ui.deviceCombo->addItem( qtr( label ), QVariant( number ) );
488
489 #define CuMRL( widget, slot ) CONNECT( widget , slot , this, updateMRL() );
490
491     /*******
492      * V4L *
493      *******/
494     addModuleAndLayouts( V4L_DEVICE, v4l, "Video for Linux" );
495
496     /* V4l Main panel */
497     QLabel *v4lVideoDeviceLabel = new QLabel( qtr( "Video device name" ) );
498     v4lDevLayout->addWidget( v4lVideoDeviceLabel, 0, 0 );
499
500     v4lVideoDevice = new QLineEdit;
501     v4lDevLayout->addWidget( v4lVideoDevice, 0, 1 );
502
503     QLabel *v4lAudioDeviceLabel = new QLabel( qtr( "Audio device name" ) );
504     v4lDevLayout->addWidget( v4lAudioDeviceLabel, 1, 0 );
505
506     v4lAudioDevice = new QLineEdit;
507     v4lDevLayout->addWidget( v4lAudioDevice, 1, 1 );
508
509     /* V4l Props panel */
510     QLabel *v4lNormLabel = new QLabel( qtr( "Norm" ) );
511     v4lPropLayout->addWidget( v4lNormLabel, 0 , 0 );
512
513     v4lNormBox = new QComboBox;
514     setfillVLCConfigCombo( "v4l-norm", p_intf, v4lNormBox );
515     v4lPropLayout->addWidget( v4lNormBox, 0 , 1 );
516
517     QLabel *v4lFreqLabel = new QLabel( qtr( "Frequency" ) );
518     v4lPropLayout->addWidget( v4lFreqLabel, 1 , 0 );
519
520     v4lFreq = new QSpinBox;
521     v4lFreq->setAlignment( Qt::AlignRight );
522     v4lFreq->setSuffix(" kHz");
523     setSpinBoxFreq( v4lFreq );
524     v4lPropLayout->addWidget( v4lFreq, 1 , 1 );
525
526     /* v4l CONNECTs */
527     CuMRL( v4lVideoDevice, textChanged( QString ) );
528     CuMRL( v4lAudioDevice, textChanged( QString ) );
529     CuMRL( v4lFreq, valueChanged ( int ) );
530     CuMRL( v4lNormBox,  currentIndexChanged ( int ) );
531
532     /*******
533      * JACK *
534      *******/
535     addModuleAndLayouts( JACK_DEVICE, jack, "JACK Audio Connection Kit" );
536
537     /* Jack Main panel */
538     /* Channels */
539     QLabel *jackChannelsLabel = new QLabel( qtr( "Channels :" ) );
540     jackDevLayout->addWidget( jackChannelsLabel, 1, 0 );
541
542     jackChannels = new QSpinBox;
543     setSpinBoxFreq( jackChannels );
544     jackChannels->setMaximum(255);
545     jackChannels->setValue(2);
546     jackChannels->setAlignment( Qt::AlignRight );
547     jackDevLayout->addWidget( jackChannels, 1, 1 );
548
549     /* Jack Props panel */
550  
551     /* Selected ports */
552     QLabel *jackPortsLabel = new QLabel( qtr( "Selected ports :" ) );
553     jackPropLayout->addWidget( jackPortsLabel, 0 , 0 );
554
555     jackPortsSelected = new QLineEdit( qtr( ".*") );
556     jackPortsSelected->setAlignment( Qt::AlignRight );
557     jackPropLayout->addWidget( jackPortsSelected, 0, 1 );
558  
559     /* Caching */
560     QLabel *jackCachingLabel = new QLabel( qtr( "Input caching :" ) );
561     jackPropLayout->addWidget( jackCachingLabel, 1 , 0 );
562     jackCaching = new QSpinBox;
563     setSpinBoxFreq( jackCaching );
564     jackCaching->setSuffix( " ms" );
565     jackCaching->setValue(1000);
566     jackCaching->setAlignment( Qt::AlignRight );
567     jackPropLayout->addWidget( jackCaching, 1 , 1 );
568  
569     /* Pace */
570     jackPace = new QCheckBox(qtr( "Use VLC pace" ));
571     jackPropLayout->addWidget( jackPace, 2, 1 );
572  
573     /* Auto Connect */
574     jackConnect = new QCheckBox( qtr( "Auto connnection" ));
575     jackPropLayout->addWidget( jackConnect, 3, 1 );
576  
577     /* Jack CONNECTs */
578     CuMRL( jackChannels, valueChanged( int ) );
579     CuMRL( jackCaching, valueChanged( int ) );
580     CuMRL( jackPace, stateChanged( int ) );
581     CuMRL( jackConnect, stateChanged( int ) );
582     CuMRL( jackPortsSelected, textChanged( QString ) );
583
584     /************
585      * PVR      *
586      ************/
587     addModuleAndLayouts( PVR_DEVICE, pvr, "PVR" );
588
589     /* PVR Main panel */
590     QLabel *pvrDeviceLabel = new QLabel( qtr( "Device name" ) );
591     pvrDevLayout->addWidget( pvrDeviceLabel, 0, 0 );
592
593     pvrDevice = new QLineEdit;
594     pvrDevLayout->addWidget( pvrDevice, 0, 1 );
595
596     QLabel *pvrRadioDeviceLabel = new QLabel( qtr( "Radio device name" ) );
597     pvrDevLayout->addWidget( pvrRadioDeviceLabel, 1, 0 );
598
599     pvrRadioDevice = new QLineEdit;
600     pvrDevLayout->addWidget( pvrRadioDevice, 1, 1 );
601
602     /* PVR props panel */
603     QLabel *pvrNormLabel = new QLabel( qtr( "Norm" ) );
604     pvrPropLayout->addWidget( pvrNormLabel, 0, 0 );
605
606     pvrNormBox = new QComboBox;
607     setfillVLCConfigCombo( "pvr-norm", p_intf, pvrNormBox );
608     pvrPropLayout->addWidget( pvrNormBox, 0, 1 );
609
610     QLabel *pvrFreqLabel = new QLabel( qtr( "Frequency" ) );
611     pvrPropLayout->addWidget( pvrFreqLabel, 1, 0 );
612
613     pvrFreq = new QSpinBox;
614     pvrFreq->setAlignment( Qt::AlignRight );
615     pvrFreq->setSuffix(" kHz");
616     setSpinBoxFreq( pvrFreq );
617     pvrPropLayout->addWidget( pvrFreq, 1, 1 );
618
619     QLabel *pvrBitrLabel = new QLabel( qtr( "Bitrate" ) );
620     pvrPropLayout->addWidget( pvrBitrLabel, 2, 0 );
621
622     pvrBitr = new QSpinBox;
623     pvrBitr->setAlignment( Qt::AlignRight );
624     pvrBitr->setSuffix(" kHz");
625     setSpinBoxFreq( pvrBitr );
626     pvrPropLayout->addWidget( pvrBitr, 2, 1 );
627
628     /* PVR CONNECTs */
629     CuMRL( pvrDevice, textChanged( QString ) );
630     CuMRL( pvrRadioDevice, textChanged( QString ) );
631
632     CuMRL( pvrFreq, valueChanged ( int ) );
633     CuMRL( pvrBitr, valueChanged ( int ) );
634     CuMRL( pvrNormBox,  currentIndexChanged ( int ) );
635
636     /*********************
637      * DirectShow Stuffs *
638      *********************/
639     addModuleAndLayouts( DSHOW_DEVICE, dshow, "DirectShow" );
640
641     /* dshow Main */
642
643     QLabel *dshowVDeviceLabel = new QLabel( qtr( "Video Device Name " ) );
644     dshowDevLayout->addWidget( dshowVDeviceLabel, 0, 0 );
645
646     QLabel *dshowADeviceLabel = new QLabel( qtr( "Audio Device Name " ) );
647     dshowDevLayout->addWidget( dshowADeviceLabel, 1, 0 );
648
649     QComboBox *dshowVDevice = new QComboBox;
650     dshowDevLayout->addWidget( dshowVDevice, 0, 1 );
651
652     QComboBox *dshowADevice = new QComboBox;
653     dshowDevLayout->addWidget( dshowADevice, 1, 1 );
654
655     QPushButton *dshowVRefresh = new QPushButton( qtr( "Update List" ) );
656     dshowDevLayout->addWidget( dshowVRefresh, 0, 2 );
657
658     QPushButton *dshowARefresh = new QPushButton( qtr( "Update List" ) );
659     dshowDevLayout->addWidget( dshowARefresh, 1, 2 );
660
661     QPushButton *dshowVConfig = new QPushButton( qtr( "Configure" ) );
662     dshowDevLayout->addWidget( dshowVConfig, 0, 3 );
663
664     QPushButton *dshowAConfig = new QPushButton( qtr( "Configure" ) );
665     dshowDevLayout->addWidget( dshowAConfig, 1, 3 );
666
667     /* dshow Properties */
668
669     QLabel *dshowVSizeLabel = new QLabel( qtr( "Video size" ) );
670     dshowPropLayout->addWidget( dshowVSizeLabel, 0, 0 );
671
672     QLineEdit *dshowVSizeLine = new QLineEdit;
673     dshowPropLayout->addWidget( dshowVSizeLine, 0, 1);
674
675     /* dshow CONNECTs */
676     CuMRL( dshowVDevice, currentIndexChanged ( int ) );
677     CuMRL( dshowADevice, currentIndexChanged ( int ) );
678     CuMRL( dshowVSizeLine, textChanged( QString ) );
679
680     /**************
681      * BDA Stuffs *
682      **************/
683     addModuleAndLayouts( BDA_DEVICE, bda, "DVB DirectShow" );
684
685     /* bda Main */
686     QLabel *bdaTypeLabel = new QLabel( qtr( "DVB Type:" ) );
687
688     bdas = new QRadioButton( "DVB-S" );
689     bdas->setChecked( true );
690     bdac = new QRadioButton( "DVB-C" );
691     bdat = new QRadioButton( "DVB-T" );
692
693     bdaDevLayout->addWidget( bdaTypeLabel, 0, 0 );
694     bdaDevLayout->addWidget( bdas, 0, 1 );
695     bdaDevLayout->addWidget( bdac, 0, 2 );
696     bdaDevLayout->addWidget( bdat, 0, 3 );
697
698     /* bda Props */
699     QLabel *bdaFreqLabel =
700                     new QLabel( qtr( "Transponder/multiplex frequency" ) );
701     bdaPropLayout->addWidget( bdaFreqLabel, 0, 0 );
702
703     bdaFreq = new QSpinBox;
704     bdaFreq->setAlignment( Qt::AlignRight );
705     bdaFreq->setSuffix(" kHz");
706     bdaFreq->setSingleStep( 1000 );
707     setSpinBoxFreq( bdaFreq )
708     bdaPropLayout->addWidget( bdaFreq, 0, 1 );
709
710     bdaSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
711     bdaPropLayout->addWidget( bdaSrateLabel, 1, 0 );
712
713     bdaSrate = new QSpinBox;
714     bdaSrate->setAlignment( Qt::AlignRight );
715     bdaSrate->setSuffix(" kHz");
716     setSpinBoxFreq( bdaSrate );
717     bdaPropLayout->addWidget( bdaSrate, 1, 1 );
718
719     bdaBandLabel = new QLabel( qtr( "Bandwidth" ) );
720     bdaPropLayout->addWidget( bdaBandLabel, 2, 0 );
721
722     bdaBandBox = new QComboBox;
723     setfillVLCConfigCombo( "dvb-bandwidth", p_intf, bdaBandBox );
724     bdaPropLayout->addWidget( bdaBandBox, 2, 1 );
725
726     bdaBandLabel->hide();
727     bdaBandBox->hide();
728
729     /* bda CONNECTs */
730     CuMRL( bdaFreq, valueChanged ( int ) );
731     CuMRL( bdaSrate, valueChanged ( int ) );
732     CuMRL( bdaBandBox,  currentIndexChanged ( int ) );
733     BUTTONACT( bdas, updateButtons() );
734     BUTTONACT( bdat, updateButtons() );
735     BUTTONACT( bdac, updateButtons() );
736     BUTTONACT( bdas, updateMRL() );
737     BUTTONACT( bdat, updateMRL() );
738     BUTTONACT( bdac, updateMRL() );
739
740     /**************
741      * DVB Stuffs *
742      **************/
743     addModuleAndLayouts( DVB_DEVICE, dvb, "DVB" );
744
745     /* DVB Main */
746     QLabel *dvbDeviceLabel = new QLabel( qtr( "Adapter card to tune" ) );
747     QLabel *dvbTypeLabel = new QLabel( qtr( "DVB Type:" ) );
748
749     dvbCard = new QSpinBox;
750     dvbCard->setAlignment( Qt::AlignRight );
751     dvbCard->setPrefix( "/dev/dvb/adapter" );
752
753     dvbDevLayout->addWidget( dvbDeviceLabel, 0, 0 );
754     dvbDevLayout->addWidget( dvbCard, 0, 2, 1, 2 );
755
756     dvbs = new QRadioButton( "DVB-S" );
757     dvbs->setChecked( true );
758     dvbc = new QRadioButton( "DVB-C" );
759     dvbt = new QRadioButton( "DVB-T" );
760
761     dvbDevLayout->addWidget( dvbTypeLabel, 1, 0 );
762     dvbDevLayout->addWidget( dvbs, 1, 1 );
763     dvbDevLayout->addWidget( dvbc, 1, 2 );
764     dvbDevLayout->addWidget( dvbt, 1, 3 );
765
766     /* DVB Props panel */
767     QLabel *dvbFreqLabel =
768                     new QLabel( qtr( "Transponder/multiplex frequency" ) );
769     dvbPropLayout->addWidget( dvbFreqLabel, 0, 0 );
770
771     dvbFreq = new QSpinBox;
772     dvbFreq->setAlignment( Qt::AlignRight );
773     dvbFreq->setSuffix(" kHz");
774     setSpinBoxFreq( dvbFreq  );
775     dvbPropLayout->addWidget( dvbFreq, 0, 1 );
776
777     QLabel *dvbSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
778     dvbPropLayout->addWidget( dvbSrateLabel, 1, 0 );
779
780     dvbSrate = new QSpinBox;
781     dvbSrate->setAlignment( Qt::AlignRight );
782     dvbSrate->setSuffix(" kHz");
783     setSpinBoxFreq( dvbSrate );
784     dvbPropLayout->addWidget( dvbSrate, 1, 1 );
785
786     /* DVB CONNECTs */
787     CuMRL( dvbCard, valueChanged ( int ) );
788     CuMRL( dvbFreq, valueChanged ( int ) );
789     CuMRL( dvbSrate, valueChanged ( int ) );
790
791     BUTTONACT( dvbs, updateButtons() );
792     BUTTONACT( dvbt, updateButtons() );
793     BUTTONACT( dvbc, updateButtons() );
794
795     /**********
796      * Screen *
797      **********/
798     addModuleAndLayouts( SCREEN_DEVICE, screen, "Desktop" );
799     QLabel *screenLabel = new QLabel( "This option will open your own "
800             "desktop in order to save or stream it.");
801     screenLabel->setWordWrap( true );
802     screenDevLayout->addWidget( screenLabel, 0, 0 );
803
804     /* General connects */
805     connect( ui.deviceCombo, SIGNAL( activated( int ) ),
806                      stackedDevLayout, SLOT( setCurrentIndex( int ) ) );
807     connect( ui.deviceCombo, SIGNAL( activated( int ) ),
808                      stackedPropLayout, SLOT( setCurrentIndex( int ) ) );
809     CONNECT( ui.deviceCombo, activated( int ), this, updateMRL() );
810     CONNECT( ui.deviceCombo, activated( int ), this, updateButtons() );
811
812 #undef addModule
813 }
814
815 CaptureOpenPanel::~CaptureOpenPanel()
816 {}
817
818 void CaptureOpenPanel::clear()
819 {}
820
821 void CaptureOpenPanel::updateMRL()
822 {
823     QString mrl = "";
824     int i_devicetype = ui.deviceCombo->itemData(
825             ui.deviceCombo->currentIndex() ).toInt();
826     switch( i_devicetype )
827     {
828     case V4L_DEVICE:
829         mrl = "v4l://";
830         mrl += " :v4l-vdev=" + v4lVideoDevice->text();
831         mrl += " :v4l-adev=" + v4lAudioDevice->text();
832         mrl += " :v4l-norm=" + QString("%1").arg( v4lNormBox->currentIndex() );
833         mrl += " :v4l-frequency=" + QString("%1").arg( v4lFreq->value() );
834         break;
835     case JACK_DEVICE:
836         mrl = "jack://";
837         mrl += "channels=" + QString("%1").arg( jackChannels->value() );
838         mrl += ":ports=" + jackPortsSelected->text();
839         mrl += " --jack-input-caching=" + QString("%1").arg( jackCaching->value() );
840         if ( jackPace->isChecked() )
841         {
842                 mrl += " --jack-input-use-vlc-pace";
843         }
844         if ( jackConnect->isChecked() )
845         {
846                 mrl += " --jack-input-auto-connect";
847         }
848         break;
849     case PVR_DEVICE:
850         mrl = "pvr://";
851         mrl += " :pvr-device=" + pvrDevice->text();
852         mrl += " :pvr-radio-device=" + pvrRadioDevice->text();
853         mrl += " :pvr-norm=" + QString("%1").arg( pvrNormBox->currentIndex() );
854         if( pvrFreq->value() )
855             mrl += " :pvr-frequency=" + QString("%1").arg( pvrFreq->value() );
856         if( pvrBitr->value() )
857             mrl += " :pvr-bitrate=" + QString("%1").arg( pvrBitr->value() );
858         break;
859     case DVB_DEVICE:
860         mrl = "dvb://";
861         mrl += " :dvb-adapter=" + QString("%1").arg( dvbCard->value() );
862         mrl += " :dvb-frequency=" + QString("%1").arg( dvbFreq->value() );
863         mrl += " :dvb-srate=" + QString("%1").arg( dvbSrate->value() );
864         break;
865     case BDA_DEVICE:
866         if( bdas->isChecked() ) mrl = "dvb-s://";
867         else if(  bdat->isChecked() ) mrl = "dvb-t://";
868         else if(  bdac->isChecked() ) mrl = "dvb-c://";
869         else return;
870         mrl += " :dvb-frequency=" + QString("%1").arg( bdaFreq->value() );
871         if( bdas->isChecked() || bdac->isChecked() )
872             mrl += " :dvb-srate=" + QString("%1").arg( bdaSrate->value() );
873         else
874             mrl += " :dvb-bandwidth=" +
875                 QString("%1").arg( bdaBandBox->itemData(
876                     bdaBandBox->currentIndex() ).toInt() );
877         break;
878     case DSHOW_DEVICE:
879         break;
880     case SCREEN_DEVICE:
881         mrl = "screen://";
882         updateButtons();
883         break;
884     }
885     emit mrlUpdated( mrl );
886 }
887
888 /**
889  * Update the Buttons (show/hide) for the GUI as all device type don't
890  * use the same ui. elements.
891  **/
892 void CaptureOpenPanel::updateButtons()
893 {
894     /*  Be sure to display the ui Elements in case they were hidden by
895      *  some Device Type (like Screen://) */
896     ui.optionsBox->show();
897     ui.advancedButton->show();
898     /* Get the current Device Number */
899     int i_devicetype = ui.deviceCombo->itemData(
900                                 ui.deviceCombo->currentIndex() ).toInt();
901     msg_Dbg( p_intf, "Capture Type: %i", i_devicetype );
902     switch( i_devicetype )
903     {
904     case DVB_DEVICE:
905         if( dvbs->isChecked() ) dvbFreq->setSuffix(" kHz");
906         if( dvbc->isChecked() || dvbt->isChecked() ) dvbFreq->setSuffix(" Hz");
907         break;
908     case BDA_DEVICE:
909         if( bdas->isChecked() || bdac->isChecked() )
910         {
911             bdaSrate->show();
912             bdaSrateLabel->show();
913             bdaBandBox->hide();
914             bdaBandLabel->hide();
915         }
916         else
917         {
918             bdaSrate->hide();
919             bdaSrateLabel->hide();
920             bdaBandBox->show();
921             bdaBandLabel->show();
922         }
923         break;
924     case SCREEN_DEVICE:
925         ui.optionsBox->hide();
926         ui.advancedButton->hide();
927         break;
928     }
929 }