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.
93 BUTTONACT( ui.subBrowseButton, browseFileSub() );
94 BUTTONACT( ui.subCheckBox, toggleSubtitleFrame());
96 CONNECT( ui.fileInput, editTextChanged(QString ), this, updateMRL());
97 CONNECT( ui.subInput, editTextChanged(QString ), this, updateMRL());
98 CONNECT( ui.alignSubComboBox, currentIndexChanged(int), this, updateMRL());
99 CONNECT( ui.sizeSubComboBox, currentIndexChanged(int), this, updateMRL());
100 CONNECT( lineFileEdit, textChanged( QString ), this, browseFile());
103 FileOpenPanel::~FileOpenPanel()
106 QStringList FileOpenPanel::browse(QString help)
108 return THEDP->showSimpleOpen( help );
111 void FileOpenPanel::browseFile()
113 QString fileString = "";
114 foreach( QString file, dialogBox->selectedFiles() ) {
115 fileString += "\"" + file + "\" ";
117 ui.fileInput->setEditText( fileString );
121 void FileOpenPanel::browseFileSub()
123 // FIXME Handle selection of more than one subtitles file
124 QStringList files = THEDP->showSimpleOpen( qtr("Open subtitles file"),
126 dialogBox->directory().absolutePath() );
127 ui.subInput->setEditText( files.join(" ") );
131 void FileOpenPanel::updateMRL()
133 QString mrl = ui.fileInput->currentText();
135 if( ui.subCheckBox->isChecked() ) {
136 mrl.append( " :sub-file=" + ui.subInput->currentText() );
137 mrl.append( " :subsdec-align=" + ui.alignSubComboBox->currentText() );
138 mrl.append( " :sub-rel-fontsize=" + ui.sizeSubComboBox->currentText() );
140 emit mrlUpdated( mrl );
141 emit methodChanged( "file-caching" );
145 /* Function called by Open Dialog when clicke on Play/Enqueue */
146 void FileOpenPanel::accept()
148 ui.fileInput->addItem(ui.fileInput->currentText());
149 if ( ui.fileInput->count() > 8 ) ui.fileInput->removeItem(0);
153 /* Function called by Open Dialog when clicked on cancel */
154 void FileOpenPanel::clear()
156 ui.fileInput->setEditText( "" );
157 ui.subInput->setEditText( "" );
160 bool FileOpenPanel::eventFilter(QObject *object, QEvent *event)
162 if ( ( object == dialogBox ) && ( event->type() == QEvent::Hide ) )
167 // standard event processing
169 return QObject::eventFilter(object, event);
172 void FileOpenPanel::toggleSubtitleFrame()
174 if (ui.subFrame->isVisible())
177 // setMinimumHeight(1);
189 /**************************************************************************
191 **************************************************************************/
192 DiskOpenPanel::DiskOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
193 OpenPanel( _parent, _p_intf )
197 CONNECT( ui.deviceCombo, editTextChanged(QString ), this, updateMRL());
198 BUTTONACT( ui.dvdRadioButton, updateMRL());
199 BUTTONACT( ui.vcdRadioButton, updateMRL());
200 BUTTONACT( ui.audioCDRadioButton, updateMRL());
202 CONNECT( ui.titleSpin, valueChanged(int), this, updateMRL());
203 CONNECT( ui.chapterSpin, valueChanged(int), this, updateMRL());
206 DiskOpenPanel::~DiskOpenPanel()
209 void DiskOpenPanel::clear()
211 ui.titleSpin->setValue(0);
212 ui.chapterSpin->setValue(0);
215 void DiskOpenPanel::updateMRL()
219 if( ui.dvdRadioButton->isChecked() ) {
220 mrl = "dvd://" + ui.deviceCombo->currentText();
221 emit methodChanged( "dvdnav-caching" );
223 if ( ui.titleSpin->value() > 0 ) {
224 mrl += QString("@%1").arg(ui.titleSpin->value());
225 if ( ui.chapterSpin->value() > 0 ) {
226 mrl+= QString(":%1").arg(ui.chapterSpin->value());
231 } else if (ui.vcdRadioButton->isChecked() ) {
232 mrl = "vcd://" + ui.deviceCombo->currentText();
233 emit methodChanged( "vcd-caching" );
235 if( ui.titleSpin->value() > 0 ) {
236 mrl += QString("@%1").arg(ui.titleSpin->value());
241 mrl = "cdda://" + ui.deviceCombo->currentText();
244 emit mrlUpdated(mrl);
249 /**************************************************************************
251 **************************************************************************/
252 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
253 OpenPanel( _parent, _p_intf )
257 CONNECT( ui.protocolCombo, currentIndexChanged(int),
258 this, updateProtocol(int) );
259 CONNECT( ui.portSpin, valueChanged(int), this, updateMRL());
260 CONNECT( ui.addressText, textChanged(QString), this, updateAddress());
261 CONNECT( ui.timeShift, clicked(), this, updateMRL());
262 CONNECT( ui.ipv6, clicked(), this, updateMRL());
264 ui.protocolCombo->addItem("HTTP", QVariant("http"));
265 ui.protocolCombo->addItem("FTP", QVariant("ftp"));
266 ui.protocolCombo->addItem("MMS", QVariant("mms"));
267 ui.protocolCombo->addItem("RTSP", QVariant("rtsp"));
268 ui.protocolCombo->addItem("UDP/RTP (unicast)", QVariant("udp"));
269 ui.protocolCombo->addItem("UDP/RTP (multicast)", QVariant("udp"));
272 NetOpenPanel::~NetOpenPanel()
275 void NetOpenPanel::clear()
278 void NetOpenPanel::updateProtocol(int idx) {
279 QString addr = ui.addressText->text();
280 QString proto = ui.protocolCombo->itemData(idx).toString();
282 ui.timeShift->setEnabled( idx >= 4);
283 ui.ipv6->setEnabled( idx == 4 );
284 ui.addressText->setEnabled( idx != 4 );
285 ui.portSpin->setEnabled( idx >= 4 );
287 /* If we already have a protocol in the address, replace it */
288 if( addr.contains( "://")) {
289 msg_Err( p_intf, "replace");
290 addr.replace(QRegExp("^.*://"), proto + "://");
291 ui.addressText->setText(addr);
297 void NetOpenPanel::updateAddress() {
301 void NetOpenPanel::updateMRL() {
303 QString addr = ui.addressText->text();
304 int proto = ui.protocolCombo->currentIndex();
306 if( addr.contains( "://") && proto != 4 ) {
311 mrl = "http://" + addr;
312 emit methodChanged("http-caching");
315 mrl = "mms://" + addr;
316 emit methodChanged("mms-caching");
319 mrl = "ftp://" + addr;
320 emit methodChanged("ftp-caching");
323 mrl = "rtsp://" + addr;
324 emit methodChanged("rtsp-caching");
328 if( ui.ipv6->isEnabled() && ui.ipv6->isChecked() ) {
331 mrl += QString(":%1").arg(ui.portSpin->value());
332 emit methodChanged("udp-caching");
334 case 5: /* UDP multicast */
337 if ( addr.contains(':') && !addr.contains('[') ) {
338 mrl += "[" + addr + "]";
340 mrl += QString(":%1").arg(ui.portSpin->value());
341 emit methodChanged("udp-caching");
344 if( ui.timeShift->isEnabled() && ui.timeShift->isChecked() ) {
345 mrl += " :access-filter=timeshift";
347 emit mrlUpdated(mrl);
350 /**************************************************************************
352 **************************************************************************/
353 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
354 OpenPanel( _parent, _p_intf )
359 CaptureOpenPanel::~CaptureOpenPanel()
362 void CaptureOpenPanel::clear()
365 void CaptureOpenPanel::updateMRL()
368 emit mrlUpdated(mrl);