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