1 /*****************************************************************************
2 * open.cpp : Panels for the open dialogs
3 ****************************************************************************
4 * Copyright (C) 2006 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_provider.hpp"
29 #include "util/customwidgets.hpp"
31 #include <QFileDialog>
32 #include <QDialogButtonBox>
35 /**************************************************************************
37 **************************************************************************/
38 FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
39 OpenPanel( _parent, _p_intf )
41 /* Classic UI Setup */
44 /* Use a QFileDialog and customize it because we don't want to
45 rewrite it all. Be careful to your eyes cause there are a few hacks.
46 Be very careful and test correctly when you modify this. */
48 /* Set Filters for file selection */
49 QString fileTypes = "";
50 ADD_FILTER_MEDIA( fileTypes );
51 ADD_FILTER_VIDEO( fileTypes );
52 ADD_FILTER_AUDIO( fileTypes );
53 ADD_FILTER_PLAYLIST( fileTypes );
54 ADD_FILTER_ALL( fileTypes );
55 fileTypes.replace(QString(";*"), QString(" *"));
57 // Make this QFileDialog a child of tempWidget from the ui.
58 dialogBox = new QFileDialog( ui.tempWidget, NULL,
59 qfu( p_intf->p_libvlc->psz_homedir ), fileTypes );
60 dialogBox->setFileMode( QFileDialog::ExistingFiles );
61 /* We don't want to see a grip in the middle of the window, do we? */
62 dialogBox->setSizeGripEnabled( false );
63 dialogBox->setToolTip( qtr( "Select one or multiple files, or a folder" ));
65 // Add it to the layout
66 ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
68 // But hide the two OK/Cancel buttons. Enable them for debug.
70 findChild<QDialogButtonBox*>()->hide();
73 /* Ugly hacks to get the good Widget */
74 //This lineEdit is the normal line in the fileDialog.
75 lineFileEdit = findChildren<QLineEdit*>()[3];
78 /* Make a list of QLabel inside the QFileDialog to access the good ones */
79 QList<QLabel *> listLabel = findChildren<QLabel*>();
81 /* Hide the FileNames one. Enable it for debug */
83 /* Change the text that was uncool in the usual box */
84 listLabel[5]->setText( qtr( "Filter:" ) );
86 /* Hacks Continued Catch the close event */
87 dialogBox->installEventFilter( this );
89 // Hide the subtitles control by default.
92 /* Build the subs size combo box */
93 module_config_t *p_item =
94 config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
97 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
99 ui.sizeSubComboBox->addItem(
100 qfu( p_item->ppsz_list_text[i_index] ),
101 QVariant( p_item->pi_list[i_index] ) );
102 if( p_item->value.i == p_item->pi_list[i_index] )
104 ui.sizeSubComboBox->setCurrentIndex( i_index );
109 /* Build the subs align combo box */
110 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
113 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
115 ui.alignSubComboBox->addItem(
116 qfu( p_item->ppsz_list_text[i_index] ),
117 QVariant( p_item->pi_list[i_index] ) );
118 if( p_item->value.i == p_item->pi_list[i_index] )
120 ui.alignSubComboBox->setCurrentIndex( i_index );
125 BUTTONACT( ui.subBrowseButton, browseFileSub() );
126 BUTTONACT( ui.subCheckBox, toggleSubtitleFrame());
128 CONNECT( ui.fileInput, editTextChanged(QString ), this, updateMRL());
129 CONNECT( ui.subInput, editTextChanged(QString ), this, updateMRL());
130 CONNECT( ui.alignSubComboBox, currentIndexChanged(int), this, updateMRL());
131 CONNECT( ui.sizeSubComboBox, currentIndexChanged(int), this, updateMRL());
132 CONNECT( lineFileEdit, textChanged( QString ), this, browseFile());
135 FileOpenPanel::~FileOpenPanel()
138 QStringList FileOpenPanel::browse(QString help)
140 return THEDP->showSimpleOpen( help );
143 void FileOpenPanel::browseFile()
145 QString fileString = "";
146 foreach( QString file, dialogBox->selectedFiles() ) {
147 fileString += "\"" + file + "\" ";
149 ui.fileInput->setEditText( fileString );
153 void FileOpenPanel::browseFileSub()
155 // FIXME Handle selection of more than one subtitles file
156 QStringList files = THEDP->showSimpleOpen( qtr("Open subtitles file"),
158 dialogBox->directory().absolutePath() );
159 if( files.isEmpty() ) return;
160 ui.subInput->setEditText( files.join(" ") );
164 void FileOpenPanel::updateMRL()
166 QString mrl = ui.fileInput->currentText();
168 if( ui.subCheckBox->isChecked() ) {
169 mrl.append( " :sub-file=" + ui.subInput->currentText() );
170 int align = ui.alignSubComboBox->itemData( ui.alignSubComboBox->currentIndex() ).toInt();
171 mrl.append( " :subsdec-align=" + QString().setNum( align ) );
172 int size = ui.sizeSubComboBox->itemData( ui.sizeSubComboBox->currentIndex() ).toInt();
173 mrl.append( " :freetype-rel-fontsize=" + QString().setNum( size ) );
175 emit mrlUpdated( mrl );
176 emit methodChanged( "file-caching" );
180 /* Function called by Open Dialog when clicke on Play/Enqueue */
181 void FileOpenPanel::accept()
183 ui.fileInput->addItem(ui.fileInput->currentText());
184 if ( ui.fileInput->count() > 8 ) ui.fileInput->removeItem(0);
188 /* Function called by Open Dialog when clicked on cancel */
189 void FileOpenPanel::clear()
191 ui.fileInput->setEditText( "" );
192 ui.subInput->setEditText( "" );
195 bool FileOpenPanel::eventFilter(QObject *object, QEvent *event)
197 if ( ( object == dialogBox ) && ( event->type() == QEvent::Hide ) )
202 // standard event processing
204 return QObject::eventFilter(object, event);
207 void FileOpenPanel::toggleSubtitleFrame()
209 if (ui.subFrame->isVisible())
212 // setMinimumHeight(1);
224 /**************************************************************************
226 **************************************************************************/
227 DiskOpenPanel::DiskOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
228 OpenPanel( _parent, _p_intf )
232 CONNECT( ui.deviceCombo, editTextChanged(QString ), this, updateMRL());
233 BUTTONACT( ui.dvdRadioButton, updateMRL());
234 BUTTONACT( ui.vcdRadioButton, updateMRL());
235 BUTTONACT( ui.audioCDRadioButton, updateMRL());
237 CONNECT( ui.titleSpin, valueChanged(int), this, updateMRL());
238 CONNECT( ui.chapterSpin, valueChanged(int), this, updateMRL());
241 DiskOpenPanel::~DiskOpenPanel()
244 void DiskOpenPanel::clear()
246 ui.titleSpin->setValue(0);
247 ui.chapterSpin->setValue(0);
250 void DiskOpenPanel::updateMRL()
254 if( ui.dvdRadioButton->isChecked() ) {
255 mrl = "dvd://" + ui.deviceCombo->currentText();
256 emit methodChanged( "dvdnav-caching" );
258 if ( ui.titleSpin->value() > 0 ) {
259 mrl += QString("@%1").arg(ui.titleSpin->value());
260 if ( ui.chapterSpin->value() > 0 ) {
261 mrl+= QString(":%1").arg(ui.chapterSpin->value());
266 } else if (ui.vcdRadioButton->isChecked() ) {
267 mrl = "vcd://" + ui.deviceCombo->currentText();
268 emit methodChanged( "vcd-caching" );
270 if( ui.titleSpin->value() > 0 ) {
271 mrl += QString("@%1").arg(ui.titleSpin->value());
276 mrl = "cdda://" + ui.deviceCombo->currentText();
279 emit mrlUpdated(mrl);
284 /**************************************************************************
286 **************************************************************************/
287 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
288 OpenPanel( _parent, _p_intf )
292 CONNECT( ui.protocolCombo, currentIndexChanged(int),
293 this, updateProtocol(int) );
294 CONNECT( ui.portSpin, valueChanged(int), this, updateMRL());
295 CONNECT( ui.addressText, textChanged(QString), this, updateAddress());
296 CONNECT( ui.timeShift, clicked(), this, updateMRL());
297 CONNECT( ui.ipv6, clicked(), this, updateMRL());
299 ui.protocolCombo->addItem("HTTP", QVariant("http"));
300 ui.protocolCombo->addItem("FTP", QVariant("ftp"));
301 ui.protocolCombo->addItem("MMS", QVariant("mms"));
302 ui.protocolCombo->addItem("RTSP", QVariant("rtsp"));
303 ui.protocolCombo->addItem("UDP/RTP (unicast)", QVariant("udp"));
304 ui.protocolCombo->addItem("UDP/RTP (multicast)", QVariant("udp"));
307 NetOpenPanel::~NetOpenPanel()
310 void NetOpenPanel::clear()
313 void NetOpenPanel::updateProtocol(int idx) {
314 QString addr = ui.addressText->text();
315 QString proto = ui.protocolCombo->itemData(idx).toString();
317 ui.timeShift->setEnabled( idx >= 4);
318 ui.ipv6->setEnabled( idx == 4 );
319 ui.addressText->setEnabled( idx != 4 );
320 ui.portSpin->setEnabled( idx >= 4 );
322 /* If we already have a protocol in the address, replace it */
323 if( addr.contains( "://")) {
324 msg_Err( p_intf, "replace");
325 addr.replace(QRegExp("^.*://"), proto + "://");
326 ui.addressText->setText(addr);
332 void NetOpenPanel::updateAddress() {
336 void NetOpenPanel::updateMRL() {
338 QString addr = ui.addressText->text();
339 int proto = ui.protocolCombo->currentIndex();
341 if( addr.contains( "://") && proto != 4 ) {
346 mrl = "http://" + addr;
347 emit methodChanged("http-caching");
350 mrl = "mms://" + addr;
351 emit methodChanged("mms-caching");
354 mrl = "ftp://" + addr;
355 emit methodChanged("ftp-caching");
358 mrl = "rtsp://" + addr;
359 emit methodChanged("rtsp-caching");
363 if( ui.ipv6->isEnabled() && ui.ipv6->isChecked() ) {
366 mrl += QString(":%1").arg(ui.portSpin->value());
367 emit methodChanged("udp-caching");
369 case 5: /* UDP multicast */
372 if ( addr.contains(':') && !addr.contains('[') ) {
373 mrl += "[" + addr + "]";
375 mrl += QString(":%1").arg(ui.portSpin->value());
376 emit methodChanged("udp-caching");
379 if( ui.timeShift->isEnabled() && ui.timeShift->isChecked() ) {
380 mrl += " :access-filter=timeshift";
382 emit mrlUpdated(mrl);
385 /**************************************************************************
387 **************************************************************************/
388 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
389 OpenPanel( _parent, _p_intf )
394 CaptureOpenPanel::~CaptureOpenPanel()
397 void CaptureOpenPanel::clear()
400 void CaptureOpenPanel::updateMRL()
403 emit mrlUpdated(mrl);