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 BUTTONACT( ui.subBrowseButton, browseFileSub() );
76 BUTTONACT( ui.subGroupBox, updateMRL());
77 CONNECT( ui.fileInput, editTextChanged(QString ), this, updateMRL());
78 CONNECT( ui.subInput, editTextChanged(QString ), this, updateMRL());
79 CONNECT( ui.alignSubComboBox, currentIndexChanged(int), this, updateMRL());
80 CONNECT( ui.sizeSubComboBox, currentIndexChanged(int), this, updateMRL());
81 CONNECT( lineFileEdit, textChanged( QString ), this, browseFile());
84 FileOpenPanel::~FileOpenPanel()
87 QStringList FileOpenPanel::browse(QString help)
89 return THEDP->showSimpleOpen( help );
92 void FileOpenPanel::browseFile()
94 QString fileString = "";
95 foreach( QString file, dialogBox->selectedFiles() ) {
96 fileString += "\"" + file + "\" ";
98 ui.fileInput->setEditText( fileString );
102 void FileOpenPanel::browseFileSub()
104 ui.subInput->setEditText( browse( qtr("Open subtitles file") ).join(" ") );
108 void FileOpenPanel::updateMRL()
110 QString mrl = ui.fileInput->currentText();
112 if( ui.subGroupBox->isChecked() ) {
113 mrl.append( " :sub-file=" + ui.subInput->currentText() );
114 mrl.append( " :subsdec-align=" + ui.alignSubComboBox->currentText() );
115 mrl.append( " :sub-rel-fontsize=" + ui.sizeSubComboBox->currentText() );
117 emit mrlUpdated( mrl );
118 emit methodChanged( "file-caching" );
122 /* Function called by Open Dialog when clicke on Play/Enqueue */
123 void FileOpenPanel::accept()
125 ui.fileInput->addItem(ui.fileInput->currentText());
126 if ( ui.fileInput->count() > 8 ) ui.fileInput->removeItem(0);
130 /* Function called by Open Dialog when clicked on cancel */
131 void FileOpenPanel::clear()
133 ui.fileInput->setEditText( "" );
134 ui.subInput->setEditText( "" );
138 /**************************************************************************
140 **************************************************************************/
141 DiskOpenPanel::DiskOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
142 OpenPanel( _parent, _p_intf )
146 CONNECT( ui.deviceCombo, editTextChanged(QString ), this, updateMRL());
147 BUTTONACT( ui.dvdRadioButton, updateMRL());
148 BUTTONACT( ui.vcdRadioButton, updateMRL());
149 BUTTONACT( ui.audioCDRadioButton, updateMRL());
151 CONNECT( ui.titleSpin, valueChanged(int), this, updateMRL());
152 CONNECT( ui.chapterSpin, valueChanged(int), this, updateMRL());
155 DiskOpenPanel::~DiskOpenPanel()
158 void DiskOpenPanel::clear()
160 ui.titleSpin->setValue(0);
161 ui.chapterSpin->setValue(0);
164 void DiskOpenPanel::updateMRL()
168 if( ui.dvdRadioButton->isChecked() ) {
169 mrl = "dvd://" + ui.deviceCombo->currentText();
170 emit methodChanged( "dvdnav-caching" );
172 if ( ui.titleSpin->value() > 0 ) {
173 mrl += QString("@%1").arg(ui.titleSpin->value());
174 if ( ui.chapterSpin->value() > 0 ) {
175 mrl+= QString(":%1").arg(ui.chapterSpin->value());
180 } else if (ui.vcdRadioButton->isChecked() ) {
181 mrl = "vcd://" + ui.deviceCombo->currentText();
182 emit methodChanged( "vcd-caching" );
184 if( ui.titleSpin->value() > 0 ) {
185 mrl += QString("@%1").arg(ui.titleSpin->value());
190 mrl = "cdda://" + ui.deviceCombo->currentText();
193 emit mrlUpdated(mrl);
198 /**************************************************************************
200 **************************************************************************/
201 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
202 OpenPanel( _parent, _p_intf )
206 CONNECT( ui.protocolCombo, currentIndexChanged(int),
207 this, updateProtocol(int) );
208 CONNECT( ui.portSpin, valueChanged(int), this, updateMRL());
209 CONNECT( ui.addressText, textChanged(QString), this, updateAddress());
210 CONNECT( ui.timeShift, clicked(), this, updateMRL());
211 CONNECT( ui.ipv6, clicked(), this, updateMRL());
213 ui.protocolCombo->addItem("HTTP", QVariant("http"));
214 ui.protocolCombo->addItem("FTP", QVariant("ftp"));
215 ui.protocolCombo->addItem("MMS", QVariant("mms"));
216 ui.protocolCombo->addItem("RTSP", QVariant("rtsp"));
217 ui.protocolCombo->addItem("UDP/RTP (unicast)", QVariant("udp"));
218 ui.protocolCombo->addItem("UDP/RTP (multicast)", QVariant("udp"));
221 NetOpenPanel::~NetOpenPanel()
224 void NetOpenPanel::clear()
227 void NetOpenPanel::updateProtocol(int idx) {
228 QString addr = ui.addressText->text();
229 QString proto = ui.protocolCombo->itemData(idx).toString();
231 ui.timeShift->setEnabled( idx >= 4);
232 ui.ipv6->setEnabled( idx == 4 );
233 ui.addressText->setEnabled( idx != 4 );
234 ui.portSpin->setEnabled( idx >= 4 );
236 /* If we already have a protocol in the address, replace it */
237 if( addr.contains( "://")) {
238 msg_Err( p_intf, "replace");
239 addr.replace(QRegExp("^.*://"), proto + "://");
240 ui.addressText->setText(addr);
246 void NetOpenPanel::updateAddress() {
250 void NetOpenPanel::updateMRL() {
252 QString addr = ui.addressText->text();
253 int proto = ui.protocolCombo->currentIndex();
255 if( addr.contains( "://") && proto != 4 ) {
260 mrl = "http://" + addr;
261 emit methodChanged("http-caching");
264 mrl = "mms://" + addr;
265 emit methodChanged("mms-caching");
268 mrl = "ftp://" + addr;
269 emit methodChanged("ftp-caching");
272 mrl = "rtsp://" + addr;
273 emit methodChanged("rtsp-caching");
277 if( ui.ipv6->isEnabled() && ui.ipv6->isChecked() ) {
280 mrl += QString(":%1").arg(ui.portSpin->value());
281 emit methodChanged("udp-caching");
283 case 5: /* UDP multicast */
286 if ( addr.contains(':') && !addr.contains('[') ) {
287 mrl += "[" + addr + "]";
289 mrl += QString(":%1").arg(ui.portSpin->value());
290 emit methodChanged("udp-caching");
293 if( ui.timeShift->isEnabled() && ui.timeShift->isChecked() ) {
294 mrl += " :access-filter=timeshift";
296 emit mrlUpdated(mrl);
299 /**************************************************************************
301 **************************************************************************/
302 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
303 OpenPanel( _parent, _p_intf )
308 CaptureOpenPanel::~CaptureOpenPanel()
311 void CaptureOpenPanel::clear()
314 void CaptureOpenPanel::updateMRL()
317 emit mrlUpdated(mrl);