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 // Make this QFileDialog a child of tempWidget from the ui.
49 dialogBox = new QFileDialog( ui.tempWidget );
50 dialogBox->setFileMode( QFileDialog::ExistingFiles );
51 dialogBox->setDirectory( qfu( p_intf->p_libvlc->psz_homedir ) );
52 /* We don't want to see a grip in the middle of the window, do we? */
53 dialogBox->setSizeGripEnabled( false );
54 dialogBox->setToolTip( qtr( "Select one or multiple files, or a folder" ));
56 /* Set Filters for file selection */
57 QString fileTypes = "";
58 ADD_FILTER_MEDIA( fileTypes );
59 ADD_FILTER_VIDEO( fileTypes );
60 ADD_FILTER_AUDIO( fileTypes );
61 ADD_FILTER_PLAYLIST( fileTypes );
62 ADD_FILTER_ALL( fileTypes );
63 fileTypes.replace(QString(";*"), QString(" *"));
65 dialogBox->setFilter( fileTypes );
67 // Add it to the layout
68 ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
70 // But hide the two OK/Cancel buttons. Enable them for debug.
71 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 ui.subInput->setEditText( browse( qtr("Open subtitles file") ).join(" ") );
127 void FileOpenPanel::updateMRL()
129 QString mrl = ui.fileInput->currentText();
131 if( ui.subCheckBox->isChecked() ) {
132 mrl.append( " :sub-file=" + ui.subInput->currentText() );
133 mrl.append( " :subsdec-align=" + ui.alignSubComboBox->currentText() );
134 mrl.append( " :sub-rel-fontsize=" + ui.sizeSubComboBox->currentText() );
136 emit mrlUpdated( mrl );
137 emit methodChanged( "file-caching" );
141 /* Function called by Open Dialog when clicke on Play/Enqueue */
142 void FileOpenPanel::accept()
144 ui.fileInput->addItem(ui.fileInput->currentText());
145 if ( ui.fileInput->count() > 8 ) ui.fileInput->removeItem(0);
149 /* Function called by Open Dialog when clicked on cancel */
150 void FileOpenPanel::clear()
152 ui.fileInput->setEditText( "" );
153 ui.subInput->setEditText( "" );
156 bool FileOpenPanel::eventFilter(QObject *object, QEvent *event)
158 if ( ( object == dialogBox ) && ( event->type() == QEvent::Hide ) )
163 // standard event processing
165 return QObject::eventFilter(object, event);
168 void FileOpenPanel::toggleSubtitleFrame()
170 if (ui.subFrame->isVisible())
173 // setMinimumHeight(1);
185 /**************************************************************************
187 **************************************************************************/
188 DiskOpenPanel::DiskOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
189 OpenPanel( _parent, _p_intf )
193 CONNECT( ui.deviceCombo, editTextChanged(QString ), this, updateMRL());
194 BUTTONACT( ui.dvdRadioButton, updateMRL());
195 BUTTONACT( ui.vcdRadioButton, updateMRL());
196 BUTTONACT( ui.audioCDRadioButton, updateMRL());
198 CONNECT( ui.titleSpin, valueChanged(int), this, updateMRL());
199 CONNECT( ui.chapterSpin, valueChanged(int), this, updateMRL());
202 DiskOpenPanel::~DiskOpenPanel()
205 void DiskOpenPanel::clear()
207 ui.titleSpin->setValue(0);
208 ui.chapterSpin->setValue(0);
211 void DiskOpenPanel::updateMRL()
215 if( ui.dvdRadioButton->isChecked() ) {
216 mrl = "dvd://" + ui.deviceCombo->currentText();
217 emit methodChanged( "dvdnav-caching" );
219 if ( ui.titleSpin->value() > 0 ) {
220 mrl += QString("@%1").arg(ui.titleSpin->value());
221 if ( ui.chapterSpin->value() > 0 ) {
222 mrl+= QString(":%1").arg(ui.chapterSpin->value());
227 } else if (ui.vcdRadioButton->isChecked() ) {
228 mrl = "vcd://" + ui.deviceCombo->currentText();
229 emit methodChanged( "vcd-caching" );
231 if( ui.titleSpin->value() > 0 ) {
232 mrl += QString("@%1").arg(ui.titleSpin->value());
237 mrl = "cdda://" + ui.deviceCombo->currentText();
240 emit mrlUpdated(mrl);
245 /**************************************************************************
247 **************************************************************************/
248 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
249 OpenPanel( _parent, _p_intf )
253 CONNECT( ui.protocolCombo, currentIndexChanged(int),
254 this, updateProtocol(int) );
255 CONNECT( ui.portSpin, valueChanged(int), this, updateMRL());
256 CONNECT( ui.addressText, textChanged(QString), this, updateAddress());
257 CONNECT( ui.timeShift, clicked(), this, updateMRL());
258 CONNECT( ui.ipv6, clicked(), this, updateMRL());
260 ui.protocolCombo->addItem("HTTP", QVariant("http"));
261 ui.protocolCombo->addItem("FTP", QVariant("ftp"));
262 ui.protocolCombo->addItem("MMS", QVariant("mms"));
263 ui.protocolCombo->addItem("RTSP", QVariant("rtsp"));
264 ui.protocolCombo->addItem("UDP/RTP (unicast)", QVariant("udp"));
265 ui.protocolCombo->addItem("UDP/RTP (multicast)", QVariant("udp"));
268 NetOpenPanel::~NetOpenPanel()
271 void NetOpenPanel::clear()
274 void NetOpenPanel::updateProtocol(int idx) {
275 QString addr = ui.addressText->text();
276 QString proto = ui.protocolCombo->itemData(idx).toString();
278 ui.timeShift->setEnabled( idx >= 4);
279 ui.ipv6->setEnabled( idx == 4 );
280 ui.addressText->setEnabled( idx != 4 );
281 ui.portSpin->setEnabled( idx >= 4 );
283 /* If we already have a protocol in the address, replace it */
284 if( addr.contains( "://")) {
285 msg_Err( p_intf, "replace");
286 addr.replace(QRegExp("^.*://"), proto + "://");
287 ui.addressText->setText(addr);
293 void NetOpenPanel::updateAddress() {
297 void NetOpenPanel::updateMRL() {
299 QString addr = ui.addressText->text();
300 int proto = ui.protocolCombo->currentIndex();
302 if( addr.contains( "://") && proto != 4 ) {
307 mrl = "http://" + addr;
308 emit methodChanged("http-caching");
311 mrl = "mms://" + addr;
312 emit methodChanged("mms-caching");
315 mrl = "ftp://" + addr;
316 emit methodChanged("ftp-caching");
319 mrl = "rtsp://" + addr;
320 emit methodChanged("rtsp-caching");
324 if( ui.ipv6->isEnabled() && ui.ipv6->isChecked() ) {
327 mrl += QString(":%1").arg(ui.portSpin->value());
328 emit methodChanged("udp-caching");
330 case 5: /* UDP multicast */
333 if ( addr.contains(':') && !addr.contains('[') ) {
334 mrl += "[" + addr + "]";
336 mrl += QString(":%1").arg(ui.portSpin->value());
337 emit methodChanged("udp-caching");
340 if( ui.timeShift->isEnabled() && ui.timeShift->isChecked() ) {
341 mrl += " :access-filter=timeshift";
343 emit mrlUpdated(mrl);
346 /**************************************************************************
348 **************************************************************************/
349 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
350 OpenPanel( _parent, _p_intf )
355 CaptureOpenPanel::~CaptureOpenPanel()
358 void CaptureOpenPanel::clear()
361 void CaptureOpenPanel::updateMRL()
364 emit mrlUpdated(mrl);