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>
36 /**************************************************************************
38 **************************************************************************/
39 FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
40 OpenPanel( _parent, _p_intf )
42 /* Classic UI Setup */
45 /* Use a QFileDialog and customize it because we don't want to
46 rewrite it all. Be careful to your eyes cause there are a few hacks.
47 Be very careful and test correctly when you modify this. */
49 /* Set Filters for file selection */
50 QString fileTypes = "";
51 ADD_FILTER_MEDIA( fileTypes );
52 ADD_FILTER_VIDEO( fileTypes );
53 ADD_FILTER_AUDIO( fileTypes );
54 ADD_FILTER_PLAYLIST( fileTypes );
55 ADD_FILTER_ALL( fileTypes );
56 fileTypes.replace(QString(";*"), QString(" *"));
58 // Make this QFileDialog a child of tempWidget from the ui.
59 dialogBox = new FileOpenBox( ui.tempWidget, NULL,
60 qfu( p_intf->p_libvlc->psz_homedir ), fileTypes );
61 /* dialogBox->setFileMode( QFileDialog::ExistingFiles );*/
62 dialogBox->setAcceptMode( QFileDialog::AcceptOpen );
64 /* retrieve last known path used in file browsing */
65 char *psz_filepath = config_GetPsz( p_intf, "qt-filedialog-path" );
68 dialogBox->setDirectory( QString::fromUtf8(psz_filepath) );
72 /* We don't want to see a grip in the middle of the window, do we? */
73 dialogBox->setSizeGripEnabled( false );
74 dialogBox->setToolTip( qtr( "Select one or multiple files, or a folder" ));
76 // Add it to the layout
77 ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
79 // But hide the two OK/Cancel buttons. Enable them for debug.
80 QDialogButtonBox *fileDialogAcceptBox =
81 findChildren<QDialogButtonBox*>()[0];
82 fileDialogAcceptBox->hide();
84 /* Ugly hacks to get the good Widget */
85 //This lineEdit is the normal line in the fileDialog.
86 lineFileEdit = findChildren<QLineEdit*>()[3];
89 /* Make a list of QLabel inside the QFileDialog to access the good ones */
90 QList<QLabel *> listLabel = findChildren<QLabel*>();
92 /* Hide the FileNames one. Enable it for debug */
94 /* Change the text that was uncool in the usual box */
95 listLabel[5]->setText( qtr( "Filter:" ) );
97 // Hide the subtitles control by default.
100 /* Build the subs size combo box */
101 module_config_t *p_item =
102 config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
105 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
107 ui.sizeSubComboBox->addItem(
108 qfu( p_item->ppsz_list_text[i_index] ),
109 QVariant( p_item->pi_list[i_index] ) );
110 if( p_item->value.i == p_item->pi_list[i_index] )
112 ui.sizeSubComboBox->setCurrentIndex( i_index );
117 /* Build the subs align combo box */
118 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
121 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
123 ui.alignSubComboBox->addItem(
124 qfu( p_item->ppsz_list_text[i_index] ),
125 QVariant( p_item->pi_list[i_index] ) );
126 if( p_item->value.i == p_item->pi_list[i_index] )
128 ui.alignSubComboBox->setCurrentIndex( i_index );
133 BUTTONACT( ui.subBrowseButton, browseFileSub() );
134 BUTTONACT( ui.subCheckBox, toggleSubtitleFrame());
136 CONNECT( ui.fileInput, editTextChanged(QString ), this, updateMRL());
137 CONNECT( ui.subInput, editTextChanged(QString ), this, updateMRL());
138 CONNECT( ui.alignSubComboBox, currentIndexChanged(int), this, updateMRL());
139 CONNECT( ui.sizeSubComboBox, currentIndexChanged(int), this, updateMRL());
140 CONNECT( lineFileEdit, textChanged( QString ), this, browseFile());
143 FileOpenPanel::~FileOpenPanel()
146 QStringList FileOpenPanel::browse(QString help)
148 return THEDP->showSimpleOpen( help );
151 void FileOpenPanel::browseFile()
153 QString fileString = "";
154 foreach( QString file, dialogBox->selectedFiles() ) {
155 fileString += "\"" + file + "\" ";
157 ui.fileInput->setEditText( fileString );
161 void FileOpenPanel::browseFileSub()
163 // FIXME Handle selection of more than one subtitles file
164 QStringList files = THEDP->showSimpleOpen( qtr("Open subtitles file"),
166 dialogBox->directory().absolutePath() );
167 if( files.isEmpty() ) return;
168 ui.subInput->setEditText( files.join(" ") );
172 void FileOpenPanel::updateMRL()
174 QString mrl = ui.fileInput->currentText();
176 if( ui.subCheckBox->isChecked() ) {
177 mrl.append( " :sub-file=" + ui.subInput->currentText() );
178 int align = ui.alignSubComboBox->itemData( ui.alignSubComboBox->currentIndex() ).toInt();
179 mrl.append( " :subsdec-align=" + QString().setNum( align ) );
180 int size = ui.sizeSubComboBox->itemData( ui.sizeSubComboBox->currentIndex() ).toInt();
181 mrl.append( " :freetype-rel-fontsize=" + QString().setNum( size ) );
184 const char *psz_filepath = config_GetPsz( p_intf, "qt-filedialog-path" );
185 if( (NULL == psz_filepath)
186 || strcmp(psz_filepath,dialogBox->directory().absolutePath().toUtf8()) )
188 /* set dialog box current directory as last known path */
189 config_PutPsz( p_intf, "qt-filedialog-path",
190 dialogBox->directory().absolutePath().toUtf8() );
194 emit mrlUpdated( mrl );
195 emit methodChanged( "file-caching" );
199 /* Function called by Open Dialog when clicke on Play/Enqueue */
200 void FileOpenPanel::accept()
202 ui.fileInput->addItem(ui.fileInput->currentText());
203 if ( ui.fileInput->count() > 8 ) ui.fileInput->removeItem(0);
206 void FileOpenBox::accept()
208 OpenDialog::getInstance( NULL, NULL )->play();
211 /* Function called by Open Dialog when clicked on cancel */
212 void FileOpenPanel::clear()
214 ui.fileInput->setEditText( "" );
215 ui.subInput->setEditText( "" );
218 void FileOpenPanel::toggleSubtitleFrame()
220 if (ui.subFrame->isVisible())
235 /**************************************************************************
237 **************************************************************************/
238 DiscOpenPanel::DiscOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
239 OpenPanel( _parent, _p_intf )
243 BUTTONACT( ui.dvdRadioButton, updateButtons());
244 BUTTONACT( ui.vcdRadioButton, updateButtons());
245 BUTTONACT( ui.audioCDRadioButton, updateButtons());
246 BUTTONACT( ui.dvdsimple, updateButtons());
248 CONNECT( ui.deviceCombo, editTextChanged(QString ), this, updateMRL());
249 CONNECT( ui.titleSpin, valueChanged(int), this, updateMRL());
250 CONNECT( ui.chapterSpin, valueChanged(int), this, updateMRL());
251 CONNECT( ui.audioSpin, valueChanged(int), this, updateMRL());
252 CONNECT( ui.subtitlesSpin, valueChanged(int), this, updateMRL());
255 DiscOpenPanel::~DiscOpenPanel()
258 void DiscOpenPanel::clear()
260 ui.titleSpin->setValue(0);
261 ui.chapterSpin->setValue(0);
264 void DiscOpenPanel::updateButtons()
266 if ( ui.dvdRadioButton->isChecked() )
268 ui.titleLabel->setText( qtr("Title") );
269 ui.chapterLabel->show();
270 ui.chapterSpin->show();
271 ui.diskOptionBox_2->show();
273 else if ( ui.vcdRadioButton->isChecked() )
275 ui.titleLabel->setText( qtr("Entry") );
276 ui.chapterLabel->hide();
277 ui.chapterSpin->hide();
278 ui.diskOptionBox_2->show();
282 ui.titleLabel->setText( qtr("Track") );
283 ui.chapterLabel->hide();
284 ui.chapterSpin->hide();
285 ui.diskOptionBox_2->hide();
292 void DiscOpenPanel::updateMRL()
296 if( ui.dvdRadioButton->isChecked() ) {
297 if( !ui.dvdsimple->isChecked() )
300 mrl = "dvdsimple://";
301 mrl += ui.deviceCombo->currentText();
302 emit methodChanged( "dvdnav-caching" );
304 if ( ui.titleSpin->value() > 0 ) {
305 mrl += QString("@%1").arg(ui.titleSpin->value());
306 if ( ui.chapterSpin->value() > 0 ) {
307 mrl+= QString(":%1").arg(ui.chapterSpin->value());
312 } else if (ui.vcdRadioButton->isChecked() ) {
313 mrl = "vcd://" + ui.deviceCombo->currentText();
314 emit methodChanged( "vcd-caching" );
316 if( ui.titleSpin->value() > 0 ) {
317 mrl += QString("@E%1").arg(ui.titleSpin->value());
322 mrl = "cdda://" + ui.deviceCombo->currentText();
323 if( ui.titleSpin->value() > 0 ) {
324 QString("@%1").arg(ui.titleSpin->value());
328 if ( ui.dvdRadioButton->isChecked() || ui.vcdRadioButton->isChecked() )
330 if ( ui.audioSpin->value() >= 0 ) {
331 mrl += " :audio-track=" + QString("%1").arg(ui.audioSpin->value());
333 if ( ui.subtitlesSpin->value() >= 0 ) {
334 mrl += " :sub-track=" +
335 QString("%1").arg(ui.subtitlesSpin->value());
339 emit mrlUpdated(mrl);
344 /**************************************************************************
346 **************************************************************************/
347 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
348 OpenPanel( _parent, _p_intf )
352 CONNECT( ui.protocolCombo, currentIndexChanged(int),
353 this, updateProtocol(int) );
354 CONNECT( ui.portSpin, valueChanged(int), this, updateMRL());
355 CONNECT( ui.addressText, textChanged(QString), this, updateAddress());
356 CONNECT( ui.timeShift, clicked(), this, updateMRL());
357 CONNECT( ui.ipv6, clicked(), this, updateMRL());
359 ui.protocolCombo->addItem("HTTP", QVariant("http"));
360 ui.protocolCombo->addItem("HTTPS", QVariant("https"));
361 ui.protocolCombo->addItem("FTP", QVariant("ftp"));
362 ui.protocolCombo->addItem("MMS", QVariant("mms"));
363 ui.protocolCombo->addItem("RTSP", QVariant("rtsp"));
364 ui.protocolCombo->addItem("UDP/RTP (unicast)", QVariant("udp"));
365 ui.protocolCombo->addItem("UDP/RTP (multicast)", QVariant("udp"));
368 NetOpenPanel::~NetOpenPanel()
371 void NetOpenPanel::clear()
374 void NetOpenPanel::updateProtocol(int idx) {
375 QString addr = ui.addressText->text();
376 QString proto = ui.protocolCombo->itemData(idx).toString();
378 ui.timeShift->setEnabled( idx >= 4);
379 ui.ipv6->setEnabled( idx == 4 );
380 ui.addressText->setEnabled( idx != 4 );
381 ui.portSpin->setEnabled( idx >= 4 );
383 /* If we already have a protocol in the address, replace it */
384 if( addr.contains( "://")) {
385 msg_Err( p_intf, "replace");
386 addr.replace(QRegExp("^.*://"), proto + "://");
387 ui.addressText->setText(addr);
393 void NetOpenPanel::updateAddress() {
397 void NetOpenPanel::updateMRL() {
399 QString addr = ui.addressText->text();
400 int proto = ui.protocolCombo->currentIndex();
402 if( addr.contains( "://") && proto != 4 ) {
408 mrl = "http://" + addr;
409 emit methodChanged("http-caching");
412 mrl = "mms://" + addr;
413 emit methodChanged("mms-caching");
416 mrl = "ftp://" + addr;
417 emit methodChanged("ftp-caching");
420 mrl = "rtsp://" + addr;
421 emit methodChanged("rtsp-caching");
425 if( ui.ipv6->isEnabled() && ui.ipv6->isChecked() ) {
428 mrl += QString(":%1").arg(ui.portSpin->value());
429 emit methodChanged("udp-caching");
431 case 6: /* UDP multicast */
434 if ( addr.contains(':') && !addr.contains('[') ) {
435 mrl += "[" + addr + "]";
437 mrl += QString(":%1").arg(ui.portSpin->value());
438 emit methodChanged("udp-caching");
441 if( ui.timeShift->isEnabled() && ui.timeShift->isChecked() ) {
442 mrl += " :access-filter=timeshift";
444 emit mrlUpdated(mrl);
447 /**************************************************************************
449 **************************************************************************/
450 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
451 OpenPanel( _parent, _p_intf )
456 CaptureOpenPanel::~CaptureOpenPanel()
459 void CaptureOpenPanel::clear()
462 void CaptureOpenPanel::updateMRL()
465 emit mrlUpdated(mrl);