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"),
125 EXT_FILTER_SUBTITLE );
126 ui.subInput->setEditText( files.join(" ") );
130 void FileOpenPanel::updateMRL()
132 QString mrl = ui.fileInput->currentText();
134 if( ui.subCheckBox->isChecked() ) {
135 mrl.append( " :sub-file=" + ui.subInput->currentText() );
136 mrl.append( " :subsdec-align=" + ui.alignSubComboBox->currentText() );
137 mrl.append( " :sub-rel-fontsize=" + ui.sizeSubComboBox->currentText() );
139 emit mrlUpdated( mrl );
140 emit methodChanged( "file-caching" );
144 /* Function called by Open Dialog when clicke on Play/Enqueue */
145 void FileOpenPanel::accept()
147 ui.fileInput->addItem(ui.fileInput->currentText());
148 if ( ui.fileInput->count() > 8 ) ui.fileInput->removeItem(0);
152 /* Function called by Open Dialog when clicked on cancel */
153 void FileOpenPanel::clear()
155 ui.fileInput->setEditText( "" );
156 ui.subInput->setEditText( "" );
159 bool FileOpenPanel::eventFilter(QObject *object, QEvent *event)
161 if ( ( object == dialogBox ) && ( event->type() == QEvent::Hide ) )
166 // standard event processing
168 return QObject::eventFilter(object, event);
171 void FileOpenPanel::toggleSubtitleFrame()
173 if (ui.subFrame->isVisible())
176 // setMinimumHeight(1);
188 /**************************************************************************
190 **************************************************************************/
191 DiskOpenPanel::DiskOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
192 OpenPanel( _parent, _p_intf )
196 CONNECT( ui.deviceCombo, editTextChanged(QString ), this, updateMRL());
197 BUTTONACT( ui.dvdRadioButton, updateMRL());
198 BUTTONACT( ui.vcdRadioButton, updateMRL());
199 BUTTONACT( ui.audioCDRadioButton, updateMRL());
201 CONNECT( ui.titleSpin, valueChanged(int), this, updateMRL());
202 CONNECT( ui.chapterSpin, valueChanged(int), this, updateMRL());
205 DiskOpenPanel::~DiskOpenPanel()
208 void DiskOpenPanel::clear()
210 ui.titleSpin->setValue(0);
211 ui.chapterSpin->setValue(0);
214 void DiskOpenPanel::updateMRL()
218 if( ui.dvdRadioButton->isChecked() ) {
219 mrl = "dvd://" + ui.deviceCombo->currentText();
220 emit methodChanged( "dvdnav-caching" );
222 if ( ui.titleSpin->value() > 0 ) {
223 mrl += QString("@%1").arg(ui.titleSpin->value());
224 if ( ui.chapterSpin->value() > 0 ) {
225 mrl+= QString(":%1").arg(ui.chapterSpin->value());
230 } else if (ui.vcdRadioButton->isChecked() ) {
231 mrl = "vcd://" + ui.deviceCombo->currentText();
232 emit methodChanged( "vcd-caching" );
234 if( ui.titleSpin->value() > 0 ) {
235 mrl += QString("@%1").arg(ui.titleSpin->value());
240 mrl = "cdda://" + ui.deviceCombo->currentText();
243 emit mrlUpdated(mrl);
248 /**************************************************************************
250 **************************************************************************/
251 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
252 OpenPanel( _parent, _p_intf )
256 CONNECT( ui.protocolCombo, currentIndexChanged(int),
257 this, updateProtocol(int) );
258 CONNECT( ui.portSpin, valueChanged(int), this, updateMRL());
259 CONNECT( ui.addressText, textChanged(QString), this, updateAddress());
260 CONNECT( ui.timeShift, clicked(), this, updateMRL());
261 CONNECT( ui.ipv6, clicked(), this, updateMRL());
263 ui.protocolCombo->addItem("HTTP", QVariant("http"));
264 ui.protocolCombo->addItem("FTP", QVariant("ftp"));
265 ui.protocolCombo->addItem("MMS", QVariant("mms"));
266 ui.protocolCombo->addItem("RTSP", QVariant("rtsp"));
267 ui.protocolCombo->addItem("UDP/RTP (unicast)", QVariant("udp"));
268 ui.protocolCombo->addItem("UDP/RTP (multicast)", QVariant("udp"));
271 NetOpenPanel::~NetOpenPanel()
274 void NetOpenPanel::clear()
277 void NetOpenPanel::updateProtocol(int idx) {
278 QString addr = ui.addressText->text();
279 QString proto = ui.protocolCombo->itemData(idx).toString();
281 ui.timeShift->setEnabled( idx >= 4);
282 ui.ipv6->setEnabled( idx == 4 );
283 ui.addressText->setEnabled( idx != 4 );
284 ui.portSpin->setEnabled( idx >= 4 );
286 /* If we already have a protocol in the address, replace it */
287 if( addr.contains( "://")) {
288 msg_Err( p_intf, "replace");
289 addr.replace(QRegExp("^.*://"), proto + "://");
290 ui.addressText->setText(addr);
296 void NetOpenPanel::updateAddress() {
300 void NetOpenPanel::updateMRL() {
302 QString addr = ui.addressText->text();
303 int proto = ui.protocolCombo->currentIndex();
305 if( addr.contains( "://") && proto != 4 ) {
310 mrl = "http://" + addr;
311 emit methodChanged("http-caching");
314 mrl = "mms://" + addr;
315 emit methodChanged("mms-caching");
318 mrl = "ftp://" + addr;
319 emit methodChanged("ftp-caching");
322 mrl = "rtsp://" + addr;
323 emit methodChanged("rtsp-caching");
327 if( ui.ipv6->isEnabled() && ui.ipv6->isChecked() ) {
330 mrl += QString(":%1").arg(ui.portSpin->value());
331 emit methodChanged("udp-caching");
333 case 5: /* UDP multicast */
336 if ( addr.contains(':') && !addr.contains('[') ) {
337 mrl += "[" + addr + "]";
339 mrl += QString(":%1").arg(ui.portSpin->value());
340 emit methodChanged("udp-caching");
343 if( ui.timeShift->isEnabled() && ui.timeShift->isChecked() ) {
344 mrl += " :access-filter=timeshift";
346 emit mrlUpdated(mrl);
349 /**************************************************************************
351 **************************************************************************/
352 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
353 OpenPanel( _parent, _p_intf )
358 CaptureOpenPanel::~CaptureOpenPanel()
361 void CaptureOpenPanel::clear()
364 void CaptureOpenPanel::updateMRL()
367 emit mrlUpdated(mrl);