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 );
55 // Add it to the layout
56 ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
58 // But hide the two OK/Cancel buttons. Enable them for debug.
59 findChild<QDialogButtonBox*>()->hide();
61 /* Ugly hacks to get the good Widget */
62 //This lineEdit is the normal line in the fileDialog.
63 lineFileEdit = findChildren<QLineEdit*>()[3];
66 /* Make a list of QLabel inside the QFileDialog to access the good ones */
67 QList<QLabel *> listLabel = findChildren<QLabel*>();
69 /* Hide the FileNames one. Enable it for debug */
71 /* Change the text that was uncool in the usual box */
72 listLabel[5]->setText( qtr( "Filter:" ) );
74 /* Hacks Continued Catch the close event */
75 dialogBox->installEventFilter( this );
77 // Hide the subtitles control by default.
81 BUTTONACT( ui.subBrowseButton, browseFileSub() );
82 BUTTONACT( ui.subCheckBox, updateMRL());
84 CONNECT( ui.fileInput, editTextChanged(QString ), this, updateMRL());
85 CONNECT( ui.subInput, editTextChanged(QString ), this, updateMRL());
86 CONNECT( ui.alignSubComboBox, currentIndexChanged(int), this, updateMRL());
87 CONNECT( ui.sizeSubComboBox, currentIndexChanged(int), this, updateMRL());
88 CONNECT( lineFileEdit, textChanged( QString ), this, browseFile());
91 FileOpenPanel::~FileOpenPanel()
94 QStringList FileOpenPanel::browse(QString help)
96 return THEDP->showSimpleOpen( help );
99 void FileOpenPanel::browseFile()
101 QString fileString = "";
102 foreach( QString file, dialogBox->selectedFiles() ) {
103 fileString += "\"" + file + "\" ";
105 ui.fileInput->setEditText( fileString );
109 void FileOpenPanel::browseFileSub()
111 ui.subInput->setEditText( browse( qtr("Open subtitles file") ).join(" ") );
115 void FileOpenPanel::updateMRL()
117 QString mrl = ui.fileInput->currentText();
119 if( ui.subCheckBox->isChecked() ) {
120 mrl.append( " :sub-file=" + ui.subInput->currentText() );
121 mrl.append( " :subsdec-align=" + ui.alignSubComboBox->currentText() );
122 mrl.append( " :sub-rel-fontsize=" + ui.sizeSubComboBox->currentText() );
124 emit mrlUpdated( mrl );
125 emit methodChanged( "file-caching" );
129 /* Function called by Open Dialog when clicke on Play/Enqueue */
130 void FileOpenPanel::accept()
132 ui.fileInput->addItem(ui.fileInput->currentText());
133 if ( ui.fileInput->count() > 8 ) ui.fileInput->removeItem(0);
137 /* Function called by Open Dialog when clicked on cancel */
138 void FileOpenPanel::clear()
140 ui.fileInput->setEditText( "" );
141 ui.subInput->setEditText( "" );
144 bool FileOpenPanel::eventFilter(QObject *object, QEvent *event)
147 if ( ( object == dialogBox ) && ( event->type() == QEvent::Hide ) )
152 // standard event processing
154 return QObject::eventFilter(object, event);
157 /**************************************************************************
159 **************************************************************************/
160 DiskOpenPanel::DiskOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
161 OpenPanel( _parent, _p_intf )
165 CONNECT( ui.deviceCombo, editTextChanged(QString ), this, updateMRL());
166 BUTTONACT( ui.dvdRadioButton, updateMRL());
167 BUTTONACT( ui.vcdRadioButton, updateMRL());
168 BUTTONACT( ui.audioCDRadioButton, updateMRL());
170 CONNECT( ui.titleSpin, valueChanged(int), this, updateMRL());
171 CONNECT( ui.chapterSpin, valueChanged(int), this, updateMRL());
174 DiskOpenPanel::~DiskOpenPanel()
177 void DiskOpenPanel::clear()
179 ui.titleSpin->setValue(0);
180 ui.chapterSpin->setValue(0);
183 void DiskOpenPanel::updateMRL()
187 if( ui.dvdRadioButton->isChecked() ) {
188 mrl = "dvd://" + ui.deviceCombo->currentText();
189 emit methodChanged( "dvdnav-caching" );
191 if ( ui.titleSpin->value() > 0 ) {
192 mrl += QString("@%1").arg(ui.titleSpin->value());
193 if ( ui.chapterSpin->value() > 0 ) {
194 mrl+= QString(":%1").arg(ui.chapterSpin->value());
199 } else if (ui.vcdRadioButton->isChecked() ) {
200 mrl = "vcd://" + ui.deviceCombo->currentText();
201 emit methodChanged( "vcd-caching" );
203 if( ui.titleSpin->value() > 0 ) {
204 mrl += QString("@%1").arg(ui.titleSpin->value());
209 mrl = "cdda://" + ui.deviceCombo->currentText();
212 emit mrlUpdated(mrl);
217 /**************************************************************************
219 **************************************************************************/
220 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
221 OpenPanel( _parent, _p_intf )
225 CONNECT( ui.protocolCombo, currentIndexChanged(int),
226 this, updateProtocol(int) );
227 CONNECT( ui.portSpin, valueChanged(int), this, updateMRL());
228 CONNECT( ui.addressText, textChanged(QString), this, updateAddress());
229 CONNECT( ui.timeShift, clicked(), this, updateMRL());
230 CONNECT( ui.ipv6, clicked(), this, updateMRL());
232 ui.protocolCombo->addItem("HTTP", QVariant("http"));
233 ui.protocolCombo->addItem("FTP", QVariant("ftp"));
234 ui.protocolCombo->addItem("MMS", QVariant("mms"));
235 ui.protocolCombo->addItem("RTSP", QVariant("rtsp"));
236 ui.protocolCombo->addItem("UDP/RTP (unicast)", QVariant("udp"));
237 ui.protocolCombo->addItem("UDP/RTP (multicast)", QVariant("udp"));
240 NetOpenPanel::~NetOpenPanel()
243 void NetOpenPanel::clear()
246 void NetOpenPanel::updateProtocol(int idx) {
247 QString addr = ui.addressText->text();
248 QString proto = ui.protocolCombo->itemData(idx).toString();
250 ui.timeShift->setEnabled( idx >= 4);
251 ui.ipv6->setEnabled( idx == 4 );
252 ui.addressText->setEnabled( idx != 4 );
253 ui.portSpin->setEnabled( idx >= 4 );
255 /* If we already have a protocol in the address, replace it */
256 if( addr.contains( "://")) {
257 msg_Err( p_intf, "replace");
258 addr.replace(QRegExp("^.*://"), proto + "://");
259 ui.addressText->setText(addr);
265 void NetOpenPanel::updateAddress() {
269 void NetOpenPanel::updateMRL() {
271 QString addr = ui.addressText->text();
272 int proto = ui.protocolCombo->currentIndex();
274 if( addr.contains( "://") && proto != 4 ) {
279 mrl = "http://" + addr;
280 emit methodChanged("http-caching");
283 mrl = "mms://" + addr;
284 emit methodChanged("mms-caching");
287 mrl = "ftp://" + addr;
288 emit methodChanged("ftp-caching");
291 mrl = "rtsp://" + addr;
292 emit methodChanged("rtsp-caching");
296 if( ui.ipv6->isEnabled() && ui.ipv6->isChecked() ) {
299 mrl += QString(":%1").arg(ui.portSpin->value());
300 emit methodChanged("udp-caching");
302 case 5: /* UDP multicast */
305 if ( addr.contains(':') && !addr.contains('[') ) {
306 mrl += "[" + addr + "]";
308 mrl += QString(":%1").arg(ui.portSpin->value());
309 emit methodChanged("udp-caching");
312 if( ui.timeShift->isEnabled() && ui.timeShift->isChecked() ) {
313 mrl += " :access-filter=timeshift";
315 emit mrlUpdated(mrl);
318 /**************************************************************************
320 **************************************************************************/
321 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
322 OpenPanel( _parent, _p_intf )
327 CaptureOpenPanel::~CaptureOpenPanel()
330 void CaptureOpenPanel::clear()
333 void CaptureOpenPanel::updateMRL()
336 emit mrlUpdated(mrl);