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