]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/open.cpp
qt4: improve the layout of files in file 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  * $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 #ifdef HAVE_LIMITS_H
39 #   include <limits.h>
40 #endif
41
42 /**************************************************************************
43  * File open
44  **************************************************************************/
45 FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
46                                 OpenPanel( _parent, _p_intf )
47 {
48     /* Classic UI Setup */
49     ui.setupUi( this );
50
51     /* Use a QFileDialog and customize it because we don't want to
52        rewrite it all. Be careful to your eyes cause there are a few hacks.
53        Be very careful and test correctly when you modify this. */
54
55     /* Set Filters for file selection */
56     QString fileTypes = "";
57     ADD_FILTER_MEDIA( fileTypes );
58     ADD_FILTER_VIDEO( fileTypes );
59     ADD_FILTER_AUDIO( fileTypes );
60     ADD_FILTER_PLAYLIST( fileTypes );
61     ADD_FILTER_ALL( fileTypes );
62     fileTypes.replace( QString(";*"), QString(" *"));
63
64     // Make this QFileDialog a child of tempWidget from the ui.
65     dialogBox = new FileOpenBox( ui.tempWidget, NULL,
66             qfu( p_intf->p_libvlc->psz_homedir ), fileTypes );
67 /*    dialogBox->setFileMode( QFileDialog::ExistingFiles );*/
68     dialogBox->setAcceptMode( QFileDialog::AcceptOpen );
69
70     /* retrieve last known path used in file browsing */
71     char *psz_filepath = config_GetPsz( p_intf, "qt-filedialog-path" );
72     if( psz_filepath )
73     {
74         dialogBox->setDirectory( QString::fromUtf8( psz_filepath ) );
75         delete psz_filepath;
76     }
77
78     /* We don't want to see a grip in the middle of the window, do we? */
79     dialogBox->setSizeGripEnabled( false );
80     dialogBox->setToolTip( qtr( "Select one or multiple files, or a folder" ));
81
82     // Add it to the layout
83     ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
84
85     // But hide the two OK/Cancel buttons. Enable them for debug.
86     QDialogButtonBox *fileDialogAcceptBox =
87                         findChildren<QDialogButtonBox*>()[0];
88     fileDialogAcceptBox->hide();
89
90     /* Ugly hacks to get the good Widget */
91     //This lineEdit is the normal line in the fileDialog.
92     lineFileEdit = findChildren<QLineEdit*>()[3];
93     lineFileEdit->hide();
94
95     /* Make a list of QLabel inside the QFileDialog to access the good ones */
96     QList<QLabel *> listLabel = findChildren<QLabel*>();
97
98     /* Hide the FileNames one. Enable it for debug */
99     listLabel[4]->hide();
100     /* Change the text that was uncool in the usual box */
101     listLabel[5]->setText( qtr( "Filter:" ) );
102
103     QListView *fileListView = findChildren<QListView*>().first();
104     fileListView->setViewMode(QListView::ListMode);
105     fileListView->setResizeMode(QListView::Adjust);
106     fileListView->setWrapping(true);
107     fileListView->setFlow(QListView::TopToBottom);
108     fileListView->setUniformItemSizes(false);
109     fileListView->setLayoutMode(QListView::Batched);
110
111     // Hide the subtitles control by default.
112     ui.subFrame->hide();
113
114     /* Build the subs size combo box */
115     module_config_t *p_item =
116         config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
117     if( p_item )
118     {
119         for( int i_index = 0; i_index < p_item->i_list; i_index++ )
120         {
121             ui.sizeSubComboBox->addItem(
122                 qfu( p_item->ppsz_list_text[i_index] ),
123                 QVariant( p_item->pi_list[i_index] ) );
124             if( p_item->value.i == p_item->pi_list[i_index] )
125             {
126                 ui.sizeSubComboBox->setCurrentIndex( i_index );
127             }
128         }
129     }
130
131     /* Build the subs align combo box */
132     p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
133     if( p_item )
134     {
135         for( int i_index = 0; i_index < p_item->i_list; i_index++ )
136         {
137             ui.alignSubComboBox->addItem(
138                 qfu( p_item->ppsz_list_text[i_index] ),
139                 QVariant( p_item->pi_list[i_index] ) );
140             if( p_item->value.i == p_item->pi_list[i_index] )
141             {
142                 ui.alignSubComboBox->setCurrentIndex( i_index );
143             }
144         }
145     }
146
147     /* Connects  */
148     BUTTONACT( ui.subBrowseButton, browseFileSub() );
149     BUTTONACT( ui.subCheckBox, toggleSubtitleFrame());
150
151     CONNECT( ui.fileInput, editTextChanged( QString ), this, updateMRL());
152     CONNECT( ui.subInput, editTextChanged( QString ), this, updateMRL());
153     CONNECT( ui.alignSubComboBox, currentIndexChanged( int ), this, updateMRL());
154     CONNECT( ui.sizeSubComboBox, currentIndexChanged( int ), this, updateMRL());
155     CONNECT( lineFileEdit, textChanged( QString ), this, browseFile());
156 }
157
158 FileOpenPanel::~FileOpenPanel()
159 {}
160
161 QStringList FileOpenPanel::browse( QString help )
162 {
163     return THEDP->showSimpleOpen( help );
164 }
165
166 /* Unused. FIXME ? */
167 void FileOpenPanel::browseFile()
168 {
169     QString fileString = "";
170     foreach( QString file, dialogBox->selectedFiles() ) {
171          fileString += "\"" + file + "\" ";
172     }
173     ui.fileInput->setEditText( fileString );
174     updateMRL();
175 }
176
177 void FileOpenPanel::browseFileSub()
178 {
179     // FIXME Handle selection of more than one subtitles file
180     QStringList files = THEDP->showSimpleOpen( qtr("Open subtitles file"),
181                             EXT_FILTER_SUBTITLE,
182                             dialogBox->directory().absolutePath() );
183     if( files.isEmpty() ) return;
184     ui.subInput->setEditText( files.join(" ") );
185     updateMRL();
186 }
187
188 void FileOpenPanel::updateMRL()
189 {
190     QString mrl = ui.fileInput->currentText();
191
192     if( ui.subCheckBox->isChecked() ) {
193         mrl.append( " :sub-file=" + ui.subInput->currentText() );
194         int align = ui.alignSubComboBox->itemData(
195                     ui.alignSubComboBox->currentIndex() ).toInt();
196         mrl.append( " :subsdec-align=" + QString().setNum( align ) );
197         int size = ui.sizeSubComboBox->itemData(
198                    ui.sizeSubComboBox->currentIndex() ).toInt();
199         mrl.append( " :freetype-rel-fontsize=" + QString().setNum( size ) );
200     }
201
202     const char *psz_filepath = config_GetPsz( p_intf, "qt-filedialog-path" );
203     if( ( NULL == psz_filepath )
204       || strcmp( psz_filepath,dialogBox->directory().absolutePath().toUtf8()) )
205     {
206         /* set dialog box current directory as last known path */
207         config_PutPsz( p_intf, "qt-filedialog-path",
208                        dialogBox->directory().absolutePath().toUtf8() );
209     }
210     delete psz_filepath;
211
212     emit mrlUpdated( mrl );
213     emit methodChanged( "file-caching" );
214 }
215
216
217 /* Function called by Open Dialog when clicke on Play/Enqueue */
218 void FileOpenPanel::accept()
219 {
220     ui.fileInput->addItem( ui.fileInput->currentText());
221     if ( ui.fileInput->count() > 8 ) ui.fileInput->removeItem( 0 );
222 }
223
224 void FileOpenBox::accept()
225 {
226     OpenDialog::getInstance( NULL, NULL )->play();
227 }
228
229 /* Function called by Open Dialog when clicked on cancel */
230 void FileOpenPanel::clear()
231 {
232     ui.fileInput->setEditText( "" );
233     ui.subInput->setEditText( "" );
234 }
235
236 void FileOpenPanel::toggleSubtitleFrame()
237 {
238     if ( ui.subFrame->isVisible() )
239     {
240         ui.subFrame->hide();
241         updateGeometry();
242     /* FiXME Size */
243     }
244     else
245     {
246         ui.subFrame->show();
247     }
248
249     /* Update the MRL */
250     updateMRL();
251 }
252
253 /**************************************************************************
254  * Disk open
255  **************************************************************************/
256 DiscOpenPanel::DiscOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
257                                 OpenPanel( _parent, _p_intf )
258 {
259     ui.setupUi( this );
260
261     BUTTONACT( ui.dvdRadioButton, updateButtons());
262     BUTTONACT( ui.vcdRadioButton, updateButtons());
263     BUTTONACT( ui.audioCDRadioButton, updateButtons());
264     BUTTONACT( ui.dvdsimple,  updateButtons());
265
266     CONNECT( ui.deviceCombo, editTextChanged( QString ), this, updateMRL());
267     CONNECT( ui.titleSpin, valueChanged( int ), this, updateMRL());
268     CONNECT( ui.chapterSpin, valueChanged( int ), this, updateMRL());
269     CONNECT( ui.audioSpin, valueChanged( int ), this, updateMRL());
270     CONNECT( ui.subtitlesSpin, valueChanged( int ), this, updateMRL());
271 }
272
273 DiscOpenPanel::~DiscOpenPanel()
274 {}
275
276 void DiscOpenPanel::clear()
277 {
278     ui.titleSpin->setValue( 0 );
279     ui.chapterSpin->setValue( 0 );
280 }
281
282 void DiscOpenPanel::updateButtons()
283 {
284     if ( ui.dvdRadioButton->isChecked() )
285     {
286         ui.titleLabel->setText( qtr("Title") );
287         ui.chapterLabel->show();
288         ui.chapterSpin->show();
289         ui.diskOptionBox_2->show();
290     }
291     else if ( ui.vcdRadioButton->isChecked() )
292     {
293         ui.titleLabel->setText( qtr("Entry") );
294         ui.chapterLabel->hide();
295         ui.chapterSpin->hide();
296         ui.diskOptionBox_2->show();
297     }
298     else
299     {
300         ui.titleLabel->setText( qtr("Track") );
301         ui.chapterLabel->hide();
302         ui.chapterSpin->hide();
303         ui.diskOptionBox_2->hide();
304     }
305
306     updateMRL();
307 }
308
309
310 void DiscOpenPanel::updateMRL()
311 {
312     QString mrl = "";
313     /* DVD */
314     if( ui.dvdRadioButton->isChecked() ) {
315         if( !ui.dvdsimple->isChecked() )
316             mrl = "dvd://";
317         else
318             mrl = "dvdsimple://";
319         mrl += ui.deviceCombo->currentText();
320         emit methodChanged( "dvdnav-caching" );
321
322         if ( ui.titleSpin->value() > 0 ) {
323             mrl += QString("@%1").arg( ui.titleSpin->value() );
324             if ( ui.chapterSpin->value() > 0 ) {
325                 mrl+= QString(":%1").arg( ui.chapterSpin->value() );
326             }
327         }
328
329     /* VCD */
330     } else if ( ui.vcdRadioButton->isChecked() ) {
331         mrl = "vcd://" + ui.deviceCombo->currentText();
332         emit methodChanged( "vcd-caching" );
333
334         if( ui.titleSpin->value() > 0 ) {
335             mrl += QString("@E%1").arg( ui.titleSpin->value() );
336         }
337
338     /* CDDA */
339     } else {
340         mrl = "cdda://" + ui.deviceCombo->currentText();
341         if( ui.titleSpin->value() > 0 ) {
342             QString("@%1").arg( ui.titleSpin->value() );
343         }
344     }
345
346     if ( ui.dvdRadioButton->isChecked() || ui.vcdRadioButton->isChecked() )
347     {
348         if ( ui.audioSpin->value() >= 0 ) {
349             mrl += " :audio-track=" +
350                 QString("%1").arg( ui.audioSpin->value() );
351         }
352         if ( ui.subtitlesSpin->value() >= 0 ) {
353             mrl += " :sub-track=" +
354                 QString("%1").arg( ui.subtitlesSpin->value() );
355         }
356     }
357
358     emit mrlUpdated( mrl );
359 }
360
361
362
363 /**************************************************************************
364  * Net open
365  **************************************************************************/
366 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
367                                 OpenPanel( _parent, _p_intf )
368 {
369     ui.setupUi( this );
370
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 >= 4 );
398     ui.ipv6->setEnabled( idx == 4 );
399     ui.addressText->setEnabled( idx != 4 );
400     ui.portSpin->setEnabled( idx >= 4 );
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
409     updateMRL();
410 }
411
412 void NetOpenPanel::updateAddress() {
413     updateMRL();
414 }
415
416 void NetOpenPanel::updateMRL() {
417     QString mrl = "";
418     QString addr = ui.addressText->text();
419     int proto = ui.protocolCombo->currentIndex();
420
421     if( addr.contains( "://") && proto != 4 ) {
422         mrl = addr;
423     } else {
424         switch( proto ) {
425         case 0:
426         case 1:
427             mrl = "http://" + addr;
428             emit methodChanged("http-caching");
429             break;
430         case 3:
431             mrl = "mms://" + addr;
432             emit methodChanged("mms-caching");
433             break;
434         case 2:
435             mrl = "ftp://" + addr;
436             emit methodChanged("ftp-caching");
437             break;
438         case 4: /* RTSP */
439             mrl = "rtsp://" + addr;
440             emit methodChanged("rtsp-caching");
441             break;
442         case 5:
443             mrl = "udp://@";
444             if( ui.ipv6->isEnabled() && ui.ipv6->isChecked() ) {
445                 mrl += "[::]";
446             }
447             mrl += QString(":%1").arg( ui.portSpin->value() );
448             emit methodChanged("udp-caching");
449             break;
450         case 6: /* UDP multicast */
451             mrl = "udp://@";
452             /* Add [] to IPv6 */
453             if ( addr.contains(':') && !addr.contains('[') ) {
454                 mrl += "[" + addr + "]";
455             } else mrl += addr;
456             mrl += QString(":%1").arg( ui.portSpin->value() );
457             emit methodChanged("udp-caching");
458         }
459     }
460     if( ui.timeShift->isEnabled() && ui.timeShift->isChecked() ) {
461         mrl += " :access-filter=timeshift";
462     }
463     emit mrlUpdated( mrl );
464 }
465
466 /**************************************************************************
467  * Capture open
468  **************************************************************************/
469 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
470                                 OpenPanel( _parent, _p_intf )
471 {
472     ui.setupUi( this );
473
474     QStackedLayout *stackedDevLayout = new QStackedLayout;
475     ui.cardBox->setLayout( stackedDevLayout );
476
477     QStackedLayout *stackedPropLayout = new QStackedLayout;
478     ui.optionsBox->setLayout( stackedPropLayout );
479
480 #define addModuleAndLayouts( number, name, label )                    \
481     QWidget * name ## DevPage = new QWidget( this );                  \
482     QWidget * name ## PropPage = new QWidget( this );                 \
483     stackedDevLayout->addWidget( name ## DevPage );        \
484     stackedPropLayout->addWidget( name ## PropPage );      \
485     QGridLayout * name ## DevLayout = new QGridLayout;                \
486     QGridLayout * name ## PropLayout = new QGridLayout;               \
487     name ## DevPage->setLayout( name ## DevLayout );                  \
488     name ## PropPage->setLayout( name ## PropLayout );                \
489     ui.deviceCombo->addItem( qtr( label ), QVariant( number ) );
490
491 #define CuMRL( widget, slot ) CONNECT( widget , slot , this, updateMRL() );
492
493 #define setMaxBound( spinbox ) spinbox->setRange ( 0, INT_MAX );
494
495     /*******
496      * V4L *
497      *******/
498     /* V4l Main */
499     addModuleAndLayouts( V4L_DEVICE, v4l, "Video for Linux" );
500     QLabel *v4lVideoDeviceLabel = new QLabel( qtr( "Video device name" ) );
501     v4lDevLayout->addWidget( v4lVideoDeviceLabel, 0, 0 );
502     v4lVideoDevice = new QLineEdit;
503     v4lDevLayout->addWidget( v4lVideoDevice, 0, 1 );
504     QLabel *v4lAudioDeviceLabel = new QLabel( qtr( "Audio device name" ) );
505     v4lDevLayout->addWidget( v4lAudioDeviceLabel, 1, 0 );
506     v4lAudioDevice = new QLineEdit;
507     v4lDevLayout->addWidget( v4lAudioDevice, 1, 1 );
508
509     /* V4l Props */
510     v4lNormBox = new QComboBox;
511     v4lNormBox->insertItem( 3, qtr( "Automatic" ) );
512     v4lNormBox->insertItem( 0, "SECAM" );
513     v4lNormBox->insertItem( 1, "NTSC" );
514     v4lNormBox->insertItem( 2, "PAL" );
515
516     v4lFreq = new QSpinBox;
517     v4lFreq->setAlignment( Qt::AlignRight );
518     v4lFreq->setSuffix(" kHz");
519
520     QLabel *v4lNormLabel = new QLabel( qtr( "Norm" ) );
521     QLabel *v4lFreqLabel = new QLabel( qtr( "Frequency" ) );
522
523     v4lPropLayout->addWidget( v4lNormLabel, 0 , 0 );
524     v4lPropLayout->addWidget( v4lNormBox, 0 , 1 );
525
526     v4lPropLayout->addWidget( v4lFreqLabel, 1 , 0 );
527     v4lPropLayout->addWidget( v4lFreq, 1 , 1 );
528
529     /* v4l CONNECTs */
530     CuMRL( v4lVideoDevice, textChanged( QString ) );
531     CuMRL( v4lAudioDevice, textChanged( QString ) );
532     CuMRL( v4lFreq, valueChanged ( int ) );
533     CuMRL( v4lNormBox,  currentIndexChanged ( int ) );
534
535     /************
536      * PVR      *
537      ************/
538     addModuleAndLayouts( PVR_DEVICE, pvr, "PVR" );
539
540     /* PVR Main */
541     QLabel *pvrDeviceLabel = new QLabel( qtr( "Device name" ) );
542     pvrDevLayout->addWidget( pvrDeviceLabel, 0, 0 );
543     pvrDevice = new QLineEdit;
544     pvrDevLayout->addWidget( pvrDevice, 0, 1 );
545     QLabel *pvrRadioDeviceLabel = new QLabel( qtr( "Radio device name" ) );
546     pvrDevLayout->addWidget( pvrRadioDeviceLabel, 1, 0 );
547     pvrRadioDevice = new QLineEdit;
548     pvrDevLayout->addWidget( pvrRadioDevice, 1, 1 );
549
550     /* PVR props */
551     pvrNormBox = new QComboBox;
552     pvrNormBox->insertItem( 3, qtr( "Automatic" ) );
553     pvrNormBox->insertItem( 0, "SECAM" );
554     pvrNormBox->insertItem( 1, "NTSC" );
555     pvrNormBox->insertItem( 2, "PAL" );
556
557     pvrFreq = new QSpinBox;
558     pvrFreq->setAlignment( Qt::AlignRight );
559     pvrFreq->setSuffix(" kHz");
560     setMaxBound( pvrFreq );
561     pvrBitr = new QSpinBox;
562     pvrBitr->setAlignment( Qt::AlignRight );
563     pvrBitr->setSuffix(" kHz");
564     setMaxBound( pvrBitr );
565     QLabel *pvrNormLabel = new QLabel( qtr( "Norm" ) );
566     QLabel *pvrFreqLabel = new QLabel( qtr( "Frequency" ) );
567     QLabel *pvrBitrLabel = new QLabel( qtr( "Bitrate" ) );
568
569     pvrPropLayout->addWidget( pvrNormLabel, 0, 0 );
570     pvrPropLayout->addWidget( pvrNormBox, 0, 1 );
571
572     pvrPropLayout->addWidget( pvrFreqLabel, 1, 0 );
573     pvrPropLayout->addWidget( pvrFreq, 1, 1 );
574
575     pvrPropLayout->addWidget( pvrBitrLabel, 2, 0 );
576     pvrPropLayout->addWidget( pvrBitr, 2, 1 );
577
578     /* PVR CONNECTs */
579     CuMRL( pvrDevice, textChanged( QString ) );
580     CuMRL( pvrRadioDevice, textChanged( QString ) );
581
582     CuMRL( pvrFreq, valueChanged ( int ) );
583     CuMRL( pvrBitr, valueChanged ( int ) );
584     CuMRL( pvrNormBox,  currentIndexChanged ( int ) );
585
586     /*********************
587      * DirectShow Stuffs *
588      *********************/
589     addModuleAndLayouts( DSHOW_DEVICE, dshow, "DirectShow" );
590
591
592     /**************
593      * BDA Stuffs *
594      **************/
595     addModuleAndLayouts( BDA_DEVICE, bda, "DVB DirectShow" );
596
597     /* bda Main */
598     QLabel *bdaDeviceLabel = new QLabel( qtr( "Adapter card to tune" ) );
599     QLabel *bdaTypeLabel = new QLabel( qtr( "DVB Type:" ) );
600
601     bdaCard = new QSpinBox;
602     bdaCard->setAlignment( Qt::AlignRight );
603
604     bdaDevLayout->addWidget( bdaDeviceLabel, 0, 0 );
605     bdaDevLayout->addWidget( bdaCard, 0, 2, 1, 2 );
606
607     bdas = new QRadioButton( "DVB-S" );
608     bdas->setChecked( true );
609     bdac = new QRadioButton( "DVB-C" );
610     bdat = new QRadioButton( "DVB-T" );
611
612     bdaDevLayout->addWidget( bdaTypeLabel, 1, 0 );
613     bdaDevLayout->addWidget( bdas, 1, 1 );
614     bdaDevLayout->addWidget( bdac, 1, 2 );
615     bdaDevLayout->addWidget( bdat, 1, 3 );
616
617     /* bda Props */
618     QLabel *bdaFreqLabel =
619                     new QLabel( qtr( "Transponder/multiplex frequency" ) );
620     bdaFreq = new QSpinBox;
621     bdaFreq->setAlignment( Qt::AlignRight );
622     bdaFreq->setSuffix(" kHz");
623     setMaxBound( bdaFreq )
624     bdaPropLayout->addWidget( bdaFreqLabel, 0, 0 );
625     bdaPropLayout->addWidget( bdaFreq, 0, 1 );
626
627     bdaSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
628     bdaSrate = new QSpinBox;
629     bdaSrate->setAlignment( Qt::AlignRight );
630     bdaSrate->setSuffix(" kHz");
631     setMaxBound( bdaSrate );
632     bdaPropLayout->addWidget( bdaSrateLabel, 1, 0 );
633     bdaPropLayout->addWidget( bdaSrate, 1, 1 );
634
635     /* bda CONNECTs */
636     CuMRL( bdaCard, valueChanged ( int ) );
637     CuMRL( bdaFreq, valueChanged ( int ) );
638     CuMRL( bdaSrate, valueChanged ( int ) );
639     BUTTONACT( bdas, updateButtons() );
640     BUTTONACT( bdat, updateButtons() );
641     BUTTONACT( bdac, updateButtons() );
642     BUTTONACT( bdas, updateMRL() );
643     BUTTONACT( bdat, updateMRL() );
644     BUTTONACT( bdac, updateMRL() );
645
646     /**************
647      * DVB Stuffs *
648      **************/
649     addModuleAndLayouts( DVB_DEVICE, dvb, "DVB" );
650
651     /* DVB Main */
652     QLabel *dvbDeviceLabel = new QLabel( qtr( "Adapter card to tune" ) );
653     QLabel *dvbTypeLabel = new QLabel( qtr( "DVB Type:" ) );
654
655     dvbCard = new QSpinBox;
656     dvbCard->setAlignment( Qt::AlignRight );
657     dvbCard->setPrefix( "/dev/dvb/adapter" );
658
659     dvbDevLayout->addWidget( dvbDeviceLabel, 0, 0 );
660     dvbDevLayout->addWidget( dvbCard, 0, 2, 1, 2 );
661
662     dvbs = new QRadioButton( "DVB-S" );
663     dvbs->setChecked( true );
664     dvbc = new QRadioButton( "DVB-C" );
665     dvbt = new QRadioButton( "DVB-T" );
666
667     dvbDevLayout->addWidget( dvbTypeLabel, 1, 0 );
668     dvbDevLayout->addWidget( dvbs, 1, 1 );
669     dvbDevLayout->addWidget( dvbc, 1, 2 );
670     dvbDevLayout->addWidget( dvbt, 1, 3 );
671
672     /* DVB Props */
673     QLabel *dvbFreqLabel =
674                     new QLabel( qtr( "Transponder/multiplex frequency" ) );
675     dvbFreq = new QSpinBox;
676     dvbFreq->setAlignment( Qt::AlignRight );
677     dvbFreq->setSuffix(" kHz");
678     setMaxBound( dvbFreq  );
679     dvbPropLayout->addWidget( dvbFreqLabel, 0, 0 );
680     dvbPropLayout->addWidget( dvbFreq, 0, 1 );
681
682     QLabel *dvbSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
683     dvbSrate = new QSpinBox;
684     dvbSrate->setAlignment( Qt::AlignRight );
685     dvbSrate->setSuffix(" kHz");
686     setMaxBound( dvbSrate );
687     dvbPropLayout->addWidget( dvbSrateLabel, 1, 0 );
688     dvbPropLayout->addWidget( dvbSrate, 1, 1 );
689
690     /* DVB CONNECTs */
691     CuMRL( dvbCard, valueChanged ( int ) );
692     CuMRL( dvbFreq, valueChanged ( int ) );
693     CuMRL( dvbSrate, valueChanged ( int ) );
694     BUTTONACT( dvbs, updateButtons() );
695     BUTTONACT( dvbt, updateButtons() );
696     BUTTONACT( dvbc, updateButtons() );
697
698     /* General connects */
699     connect( ui.deviceCombo, SIGNAL( activated( int ) ),
700                      stackedDevLayout, SLOT( setCurrentIndex( int ) ) );
701     connect( ui.deviceCombo, SIGNAL( activated( int ) ),
702                      stackedPropLayout, SLOT( setCurrentIndex( int ) ) );
703     CONNECT( ui.deviceCombo, activated( int ), this, updateMRL() );
704
705 #undef addModule
706 }
707
708 CaptureOpenPanel::~CaptureOpenPanel()
709 {}
710
711 void CaptureOpenPanel::clear()
712 {}
713
714 void CaptureOpenPanel::updateMRL()
715 {
716     QString mrl = "";
717     int i_devicetype = ui.deviceCombo->itemData(
718             ui.deviceCombo->currentIndex() ).toInt();
719     msg_Dbg( p_intf, "Capture Type: %i", i_devicetype );
720     switch( i_devicetype )
721     {
722     case V4L_DEVICE:
723         mrl = "v4l://";
724         mrl += " :v4l-vdev=" + v4lVideoDevice->text();
725         mrl += " :v4l-adev=" + v4lAudioDevice->text();
726         mrl += " :v4l-norm=" + QString("%1").arg( v4lNormBox->currentIndex() );
727         mrl += " :v4l-frequency=" + QString("%1").arg( v4lFreq->value() );
728         break;
729     case PVR_DEVICE:
730         mrl = "pvr://";
731         mrl += " :pvr-device=" + pvrDevice->text();
732         mrl += " :pvr-radio-device=" + pvrRadioDevice->text();
733         mrl += " :pvr-norm=" + QString("%1").arg( pvrNormBox->currentIndex() );
734         if( pvrFreq->value() )
735             mrl += " :pvr-frequency=" + QString("%1").arg( pvrFreq->value() );
736         if( pvrBitr->value() )
737             mrl += " :pvr-bitrate=" + QString("%1").arg( pvrBitr->value() );
738         break;
739     case DVB_DEVICE:
740         mrl = "dvb://";
741         mrl += " :dvb-adapter=" + QString("%1").arg( dvbCard->value() );
742         mrl += " :dvb-frequency=" + QString("%1").arg( dvbFreq->value() );
743         mrl += " :dvb-srate=" + QString("%1").arg( dvbSrate->value() );
744         break;
745     case BDA_DEVICE:
746         if( bdas->isChecked() ) mrl = "dvb-s://";
747         else if(  bdat->isChecked() ) mrl = "dvb-t://";
748         else if(  bdac->isChecked() ) mrl = "dvb-c://";
749         else return;
750         mrl += " :dvb-adapter=" + QString("%1").arg( bdaCard->value() );
751         mrl += " :dvb-frequency=" + QString("%1").arg( bdaFreq->value() );
752         mrl += " :dvb-srate=" + QString("%1").arg( bdaSrate->value() );
753         break;
754   case DSHOW_DEVICE:
755         break;
756     }
757
758     emit mrlUpdated( mrl );
759 }
760
761 void CaptureOpenPanel::updateButtons()
762 {
763     int i_devicetype = ui.deviceCombo->itemData(
764             ui.deviceCombo->currentIndex() ).toInt();
765     msg_Dbg( p_intf, "Capture Type: %i", i_devicetype );
766     switch( i_devicetype )
767     {
768     case DVB_DEVICE:
769         if( dvbs->isChecked() ) dvbFreq->setSuffix(" kHz");
770         if( dvbc->isChecked() || dvbt->isChecked() ) dvbFreq->setSuffix(" Hz");
771         break;
772     case BDA_DEVICE:
773         if( bdas->isChecked() ) bdaFreq->setSuffix(" kHz");
774         if( bdac->isChecked() || bdat->isChecked() ) bdaFreq->setSuffix(" Hz");
775         if( bdas->isChecked() || bdac->isChecked() )
776         {
777             bdaSrate->show();
778             bdaSrateLabel->show();
779         }
780         else
781         {
782             bdaSrate->show();
783             bdaSrateLabel->hide();
784         }
785         break;
786     }
787 }