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