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