1 /*****************************************************************************
2 * open.cpp : Panels for the open dialogs
3 ****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
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.
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.
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 *****************************************************************************/
27 #include "components/open.hpp"
28 #include "dialogs/open.hpp"
29 #include "dialogs_provider.hpp"
30 #include "util/customwidgets.hpp"
32 #include <QFileDialog>
33 #include <QDialogButtonBox>
35 #include <QStackedLayout>
37 /**************************************************************************
39 **************************************************************************/
40 FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
41 OpenPanel( _parent, _p_intf )
43 /* Classic UI Setup */
46 /* Use a QFileDialog and customize it because we don't want to
47 rewrite it all. Be careful to your eyes cause there are a few hacks.
48 Be very careful and test correctly when you modify this. */
50 /* Set Filters for file selection */
51 QString fileTypes = "";
52 ADD_FILTER_MEDIA( fileTypes );
53 ADD_FILTER_VIDEO( fileTypes );
54 ADD_FILTER_AUDIO( fileTypes );
55 ADD_FILTER_PLAYLIST( fileTypes );
56 ADD_FILTER_ALL( fileTypes );
57 fileTypes.replace( QString(";*"), QString(" *"));
59 // Make this QFileDialog a child of tempWidget from the ui.
60 dialogBox = new FileOpenBox( ui.tempWidget, NULL,
61 qfu( p_intf->p_libvlc->psz_homedir ), fileTypes );
62 /* dialogBox->setFileMode( QFileDialog::ExistingFiles );*/
63 dialogBox->setAcceptMode( QFileDialog::AcceptOpen );
65 /* retrieve last known path used in file browsing */
66 char *psz_filepath = config_GetPsz( p_intf, "qt-filedialog-path" );
69 dialogBox->setDirectory( QString::fromUtf8( psz_filepath ) );
73 /* We don't want to see a grip in the middle of the window, do we? */
74 dialogBox->setSizeGripEnabled( false );
75 dialogBox->setToolTip( qtr( "Select one or multiple files, or a folder" ));
77 // Add it to the layout
78 ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
80 // But hide the two OK/Cancel buttons. Enable them for debug.
81 QDialogButtonBox *fileDialogAcceptBox =
82 findChildren<QDialogButtonBox*>()[0];
83 fileDialogAcceptBox->hide();
85 /* Ugly hacks to get the good Widget */
86 //This lineEdit is the normal line in the fileDialog.
87 lineFileEdit = findChildren<QLineEdit*>()[3];
90 /* Make a list of QLabel inside the QFileDialog to access the good ones */
91 QList<QLabel *> listLabel = findChildren<QLabel*>();
93 /* Hide the FileNames one. Enable it for debug */
95 /* Change the text that was uncool in the usual box */
96 listLabel[5]->setText( qtr( "Filter:" ) );
98 // Hide the subtitles control by default.
101 /* Build the subs size combo box */
102 module_config_t *p_item =
103 config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
106 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
108 ui.sizeSubComboBox->addItem(
109 qfu( p_item->ppsz_list_text[i_index] ),
110 QVariant( p_item->pi_list[i_index] ) );
111 if( p_item->value.i == p_item->pi_list[i_index] )
113 ui.sizeSubComboBox->setCurrentIndex( i_index );
118 /* Build the subs align combo box */
119 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
122 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
124 ui.alignSubComboBox->addItem(
125 qfu( p_item->ppsz_list_text[i_index] ),
126 QVariant( p_item->pi_list[i_index] ) );
127 if( p_item->value.i == p_item->pi_list[i_index] )
129 ui.alignSubComboBox->setCurrentIndex( i_index );
135 BUTTONACT( ui.subBrowseButton, browseFileSub() );
136 BUTTONACT( ui.subCheckBox, toggleSubtitleFrame());
138 CONNECT( ui.fileInput, editTextChanged( QString ), this, updateMRL());
139 CONNECT( ui.subInput, editTextChanged( QString ), this, updateMRL());
140 CONNECT( ui.alignSubComboBox, currentIndexChanged( int ), this, updateMRL());
141 CONNECT( ui.sizeSubComboBox, currentIndexChanged( int ), this, updateMRL());
142 CONNECT( lineFileEdit, textChanged( QString ), this, browseFile());
145 FileOpenPanel::~FileOpenPanel()
148 QStringList FileOpenPanel::browse( QString help )
150 return THEDP->showSimpleOpen( help );
153 /* Unused. FIXME ? */
154 void FileOpenPanel::browseFile()
156 QString fileString = "";
157 foreach( QString file, dialogBox->selectedFiles() ) {
158 fileString += "\"" + file + "\" ";
160 ui.fileInput->setEditText( fileString );
164 void FileOpenPanel::browseFileSub()
166 // FIXME Handle selection of more than one subtitles file
167 QStringList files = THEDP->showSimpleOpen( qtr("Open subtitles file"),
169 dialogBox->directory().absolutePath() );
170 if( files.isEmpty() ) return;
171 ui.subInput->setEditText( files.join(" ") );
175 void FileOpenPanel::updateMRL()
177 QString mrl = ui.fileInput->currentText();
179 if( ui.subCheckBox->isChecked() ) {
180 mrl.append( " :sub-file=" + ui.subInput->currentText() );
181 int align = ui.alignSubComboBox->itemData(
182 ui.alignSubComboBox->currentIndex() ).toInt();
183 mrl.append( " :subsdec-align=" + QString().setNum( align ) );
184 int size = ui.sizeSubComboBox->itemData(
185 ui.sizeSubComboBox->currentIndex() ).toInt();
186 mrl.append( " :freetype-rel-fontsize=" + QString().setNum( size ) );
189 const char *psz_filepath = config_GetPsz( p_intf, "qt-filedialog-path" );
190 if( ( NULL == psz_filepath )
191 || strcmp( psz_filepath,dialogBox->directory().absolutePath().toUtf8()) )
193 /* set dialog box current directory as last known path */
194 config_PutPsz( p_intf, "qt-filedialog-path",
195 dialogBox->directory().absolutePath().toUtf8() );
199 emit mrlUpdated( mrl );
200 emit methodChanged( "file-caching" );
204 /* Function called by Open Dialog when clicke on Play/Enqueue */
205 void FileOpenPanel::accept()
207 ui.fileInput->addItem( ui.fileInput->currentText());
208 if ( ui.fileInput->count() > 8 ) ui.fileInput->removeItem( 0 );
211 void FileOpenBox::accept()
213 OpenDialog::getInstance( NULL, NULL )->play();
216 /* Function called by Open Dialog when clicked on cancel */
217 void FileOpenPanel::clear()
219 ui.fileInput->setEditText( "" );
220 ui.subInput->setEditText( "" );
223 void FileOpenPanel::toggleSubtitleFrame()
225 if ( ui.subFrame->isVisible() )
240 /**************************************************************************
242 **************************************************************************/
243 DiscOpenPanel::DiscOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
244 OpenPanel( _parent, _p_intf )
248 BUTTONACT( ui.dvdRadioButton, updateButtons());
249 BUTTONACT( ui.vcdRadioButton, updateButtons());
250 BUTTONACT( ui.audioCDRadioButton, updateButtons());
251 BUTTONACT( ui.dvdsimple, updateButtons());
253 CONNECT( ui.deviceCombo, editTextChanged( QString ), this, updateMRL());
254 CONNECT( ui.titleSpin, valueChanged( int ), this, updateMRL());
255 CONNECT( ui.chapterSpin, valueChanged( int ), this, updateMRL());
256 CONNECT( ui.audioSpin, valueChanged( int ), this, updateMRL());
257 CONNECT( ui.subtitlesSpin, valueChanged( int ), this, updateMRL());
260 DiscOpenPanel::~DiscOpenPanel()
263 void DiscOpenPanel::clear()
265 ui.titleSpin->setValue( 0 );
266 ui.chapterSpin->setValue( 0 );
269 void DiscOpenPanel::updateButtons()
271 if ( ui.dvdRadioButton->isChecked() )
273 ui.titleLabel->setText( qtr("Title") );
274 ui.chapterLabel->show();
275 ui.chapterSpin->show();
276 ui.diskOptionBox_2->show();
278 else if ( ui.vcdRadioButton->isChecked() )
280 ui.titleLabel->setText( qtr("Entry") );
281 ui.chapterLabel->hide();
282 ui.chapterSpin->hide();
283 ui.diskOptionBox_2->show();
287 ui.titleLabel->setText( qtr("Track") );
288 ui.chapterLabel->hide();
289 ui.chapterSpin->hide();
290 ui.diskOptionBox_2->hide();
297 void DiscOpenPanel::updateMRL()
301 if( ui.dvdRadioButton->isChecked() ) {
302 if( !ui.dvdsimple->isChecked() )
305 mrl = "dvdsimple://";
306 mrl += ui.deviceCombo->currentText();
307 emit methodChanged( "dvdnav-caching" );
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() );
317 } else if ( ui.vcdRadioButton->isChecked() ) {
318 mrl = "vcd://" + ui.deviceCombo->currentText();
319 emit methodChanged( "vcd-caching" );
321 if( ui.titleSpin->value() > 0 ) {
322 mrl += QString("@E%1").arg( ui.titleSpin->value() );
327 mrl = "cdda://" + ui.deviceCombo->currentText();
328 if( ui.titleSpin->value() > 0 ) {
329 QString("@%1").arg( ui.titleSpin->value() );
333 if ( ui.dvdRadioButton->isChecked() || ui.vcdRadioButton->isChecked() )
335 if ( ui.audioSpin->value() >= 0 ) {
336 mrl += " :audio-track=" +
337 QString("%1").arg( ui.audioSpin->value() );
339 if ( ui.subtitlesSpin->value() >= 0 ) {
340 mrl += " :sub-track=" +
341 QString("%1").arg( ui.subtitlesSpin->value() );
345 emit mrlUpdated( mrl );
350 /**************************************************************************
352 **************************************************************************/
353 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
354 OpenPanel( _parent, _p_intf )
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());
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"));
374 NetOpenPanel::~NetOpenPanel()
377 void NetOpenPanel::clear()
380 void NetOpenPanel::updateProtocol( int idx ) {
381 QString addr = ui.addressText->text();
382 QString proto = ui.protocolCombo->itemData( idx ).toString();
384 ui.timeShift->setEnabled( idx >= 4 );
385 ui.ipv6->setEnabled( idx == 4 );
386 ui.addressText->setEnabled( idx != 4 );
387 ui.portSpin->setEnabled( idx >= 4 );
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 );
399 void NetOpenPanel::updateAddress() {
403 void NetOpenPanel::updateMRL() {
405 QString addr = ui.addressText->text();
406 int proto = ui.protocolCombo->currentIndex();
408 if( addr.contains( "://") && proto != 4 ) {
414 mrl = "http://" + addr;
415 emit methodChanged("http-caching");
418 mrl = "mms://" + addr;
419 emit methodChanged("mms-caching");
422 mrl = "ftp://" + addr;
423 emit methodChanged("ftp-caching");
426 mrl = "rtsp://" + addr;
427 emit methodChanged("rtsp-caching");
431 if( ui.ipv6->isEnabled() && ui.ipv6->isChecked() ) {
434 mrl += QString(":%1").arg( ui.portSpin->value() );
435 emit methodChanged("udp-caching");
437 case 6: /* UDP multicast */
440 if ( addr.contains(':') && !addr.contains('[') ) {
441 mrl += "[" + addr + "]";
443 mrl += QString(":%1").arg( ui.portSpin->value() );
444 emit methodChanged("udp-caching");
447 if( ui.timeShift->isEnabled() && ui.timeShift->isChecked() ) {
448 mrl += " :access-filter=timeshift";
450 emit mrlUpdated( mrl );
453 /**************************************************************************
455 **************************************************************************/
456 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
457 OpenPanel( _parent, _p_intf )
461 QStackedLayout *stackedDevLayout = new QStackedLayout;
462 ui.cardBox->setLayout( stackedDevLayout );
464 QStackedLayout *stackedPropLayout = new QStackedLayout;
465 ui.optionsBox->setLayout( stackedPropLayout );
467 #define addModuleAndLayouts( number, name, label ) \
468 QWidget * name ## DevPage = new QWidget( this ); \
469 QWidget * name ## PropPage = new QWidget( this ); \
470 stackedDevLayout->insertWidget( number, name ## DevPage ); \
471 stackedPropLayout->insertWidget( number, name ## PropPage ); \
472 QGridLayout * name ## DevLayout = new QGridLayout; \
473 QGridLayout * name ## PropLayout = new QGridLayout; \
474 name ## DevPage->setLayout( name ## DevLayout ); \
475 name ## PropPage->setLayout( name ## PropLayout ); \
476 ui.deviceCombo->insertItem( number, qtr( label ) );
478 #define CuMRL( widget, slot ) CONNECT( widget , slot , this, updateMRL() );
484 addModuleAndLayouts( V4L_DEVICE, v4l, "Video for Linux" );
485 QLabel *v4lVideoDeviceLabel = new QLabel( qtr( "Video device name" ) );
486 v4lDevLayout->addWidget( v4lVideoDeviceLabel, 0, 0 );
487 v4lVideoDevice = new QLineEdit;
488 v4lDevLayout->addWidget( v4lVideoDevice, 0, 1 );
489 QLabel *v4lAudioDeviceLabel = new QLabel( qtr( "Audio device name" ) );
490 v4lDevLayout->addWidget( v4lAudioDeviceLabel, 1, 0 );
491 v4lAudioDevice = new QLineEdit;
492 v4lDevLayout->addWidget( v4lAudioDevice, 1, 1 );
495 v4lNormBox = new QComboBox;
496 v4lNormBox->insertItem( 3, qtr( "Automatic" ) );
497 v4lNormBox->insertItem( 0, "SECAM" );
498 v4lNormBox->insertItem( 1, "NTSC" );
499 v4lNormBox->insertItem( 2, "PAL" );
501 v4lFreq = new QSpinBox;
502 v4lFreq->setAlignment( Qt::AlignRight );
503 v4lFreq->setSuffix(" kHz");
505 QLabel *v4lNormLabel = new QLabel( qtr( "Norm" ) );
506 QLabel *v4lFreqLabel = new QLabel( qtr( "Frequency" ) );
508 v4lPropLayout->addWidget( v4lNormLabel, 0 , 0 );
509 v4lPropLayout->addWidget( v4lNormBox, 0 , 1 );
511 v4lPropLayout->addWidget( v4lFreqLabel, 1 , 0 );
512 v4lPropLayout->addWidget( v4lFreq, 1 , 1 );
515 CuMRL( v4lVideoDevice, textChanged( QString ) );
516 CuMRL( v4lAudioDevice, textChanged( QString ) );
517 CuMRL( v4lFreq, valueChanged ( int ) );
518 CuMRL( v4lNormBox, currentIndexChanged ( int ) );
523 addModuleAndLayouts( PVR_DEVICE, pvr, "PVR" );
526 QLabel *pvrDeviceLabel = new QLabel( qtr( "Device name" ) );
527 pvrDevLayout->addWidget( pvrDeviceLabel, 0, 0 );
528 pvrDevice = new QLineEdit;
529 pvrDevLayout->addWidget( pvrDevice, 0, 1 );
530 QLabel *pvrRadioDeviceLabel = new QLabel( qtr( "Radio device name" ) );
531 pvrDevLayout->addWidget( pvrRadioDeviceLabel, 1, 0 );
532 pvrRadioDevice = new QLineEdit;
533 pvrDevLayout->addWidget( pvrRadioDevice, 1, 1 );
536 pvrNormBox = new QComboBox;
537 pvrNormBox->insertItem( 3, qtr( "Automatic" ) );
538 pvrNormBox->insertItem( 0, "SECAM" );
539 pvrNormBox->insertItem( 1, "NTSC" );
540 pvrNormBox->insertItem( 2, "PAL" );
542 pvrFreq = new QSpinBox;
543 pvrFreq->setAlignment( Qt::AlignRight );
544 pvrFreq->setSuffix(" kHz");
545 pvrBitr = new QSpinBox;
546 pvrBitr->setAlignment( Qt::AlignRight );
547 pvrBitr->setSuffix(" kHz");
548 QLabel *pvrNormLabel = new QLabel( qtr( "Norm" ) );
549 QLabel *pvrFreqLabel = new QLabel( qtr( "Frequency" ) );
550 QLabel *pvrBitrLabel = new QLabel( qtr( "Bitrate" ) );
552 pvrPropLayout->addWidget( pvrNormLabel, 0, 0 );
553 pvrPropLayout->addWidget( pvrNormBox, 0, 1 );
555 pvrPropLayout->addWidget( pvrFreqLabel, 1, 0 );
556 pvrPropLayout->addWidget( pvrFreq, 1, 1 );
558 pvrPropLayout->addWidget( pvrBitrLabel, 2, 0 );
559 pvrPropLayout->addWidget( pvrBitr, 2, 1 );
562 CuMRL( pvrDevice, textChanged( QString ) );
563 CuMRL( pvrRadioDevice, textChanged( QString ) );
565 CuMRL( pvrFreq, valueChanged ( int ) );
566 CuMRL( pvrBitr, valueChanged ( int ) );
567 CuMRL( pvrNormBox, currentIndexChanged ( int ) );
569 /*********************
570 * DirectShow Stuffs *
571 *********************/
572 addModuleAndLayouts( DSHOW_DEVICE, dshow, "DirectShow" );
578 addModuleAndLayouts( BDA_DEVICE, bda, "DVB / BDA" );
583 addModuleAndLayouts( DVB_DEVICE, dvb, "DVB" );
586 QLabel *dvbDeviceLabel = new QLabel( qtr( "Adapter card to tune" ) );
587 QLabel *dvbTyepLabel = new QLabel( qtr( "DVB Type:" ) );
589 dvbCard = new QSpinBox;
590 dvbCard->setAlignment( Qt::AlignRight );
591 dvbCard->setPrefix( "/dev/dvb/adapter" );
593 dvbDevLayout->addWidget( dvbDeviceLabel, 0, 0 );
594 dvbDevLayout->addWidget( dvbCard, 0, 2, 1, 2 );
596 dvbs = new QRadioButton( "DVB-S" );
597 dvbs->setChecked( true );
598 dvbc = new QRadioButton( "DVB-C" );
599 dvbt = new QRadioButton( "DVB-T" );
601 dvbDevLayout->addWidget( dvbTyepLabel, 1, 0 );
602 dvbDevLayout->addWidget( dvbs, 1, 1 );
603 dvbDevLayout->addWidget( dvbc, 1, 2 );
604 dvbDevLayout->addWidget( dvbt, 1, 3 );
607 QLabel *dvbFreqLabel =
608 new QLabel( qtr( "Transponder/multiplex frequency" ) );
609 dvbFreq = new QSpinBox;
610 dvbFreq->setAlignment( Qt::AlignRight );
611 dvbFreq->setSuffix(" kHz");
612 dvbPropLayout->addWidget( dvbFreqLabel, 0, 0 );
613 dvbPropLayout->addWidget( dvbFreq, 0, 1 );
615 QLabel *dvbSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
616 dvbSrate = new QSpinBox;
617 dvbSrate->setAlignment( Qt::AlignRight );
618 dvbSrate->setSuffix(" kHz");
619 dvbPropLayout->addWidget( dvbSrateLabel, 1, 0 );
620 dvbPropLayout->addWidget( dvbSrate, 1, 1 );
623 CuMRL( dvbCard, valueChanged ( int ) );
624 CuMRL( dvbFreq, valueChanged ( int ) );
625 CuMRL( dvbSrate, valueChanged ( int ) );
626 BUTTONACT( dvbs, updateButtons() );
627 BUTTONACT( dvbt, updateButtons() );
628 BUTTONACT( dvbc, updateButtons() );
630 /* General connects */
631 connect( ui.deviceCombo, SIGNAL( activated( int ) ),
632 stackedDevLayout, SLOT( setCurrentIndex( int ) ) );
633 connect( ui.deviceCombo, SIGNAL( activated( int ) ),
634 stackedPropLayout, SLOT( setCurrentIndex( int ) ) );
635 CONNECT( ui.deviceCombo, activated( int ), this, updateMRL() );
640 CaptureOpenPanel::~CaptureOpenPanel()
643 void CaptureOpenPanel::clear()
646 void CaptureOpenPanel::updateMRL()
649 int i_devicetype = ui.deviceCombo->currentIndex();
650 switch( i_devicetype )
654 mrl += " :v4l-vdev=" + v4lVideoDevice->text();
655 mrl += " :v4l-adev=" + v4lAudioDevice->text();
656 mrl += " :v4l-norm=" + QString("%1").arg( v4lNormBox->currentIndex() );
657 mrl += " :v4l-frequency=" + QString("%1").arg( v4lFreq->value() );
661 mrl += " :pvr-device=" + pvrDevice->text();
662 mrl += " :pvr-radio-device=" + pvrRadioDevice->text();
663 mrl += " :pvr-norm=" + QString("%1").arg( pvrNormBox->currentIndex() );
664 if( pvrFreq->value() )
665 mrl += " :pvr-frequency=" + QString("%1").arg( pvrFreq->value() );
666 if( pvrBitr->value() )
667 mrl += " :pvr-bitrate=" + QString("%1").arg( pvrBitr->value() );
671 mrl += " :dvb-adapter=" + QString("%1").arg( dvbCard->value() );
672 mrl += " :dvb-frequency=" + QString("%1").arg( dvbFreq->value() );
673 mrl += " :dvb-srate=" + QString("%1").arg( dvbSrate->value() );
681 emit mrlUpdated( mrl );
684 void CaptureOpenPanel::updateButtons()
686 if( dvbs->isChecked() ) dvbFreq->setSuffix(" kHz");
687 if( dvbc->isChecked() || dvbt->isChecked() ) dvbFreq->setSuffix(" Hz");