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 FileOpenBox( 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 // Hide the subtitles control by default.
89 /* Build the subs size combo box */
90 module_config_t *p_item =
91 config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
94 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
96 ui.sizeSubComboBox->addItem(
97 qfu( p_item->ppsz_list_text[i_index] ),
98 QVariant( p_item->pi_list[i_index] ) );
99 if( p_item->value.i == p_item->pi_list[i_index] )
101 ui.sizeSubComboBox->setCurrentIndex( i_index );
106 /* Build the subs align combo box */
107 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
110 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
112 ui.alignSubComboBox->addItem(
113 qfu( p_item->ppsz_list_text[i_index] ),
114 QVariant( p_item->pi_list[i_index] ) );
115 if( p_item->value.i == p_item->pi_list[i_index] )
117 ui.alignSubComboBox->setCurrentIndex( i_index );
122 BUTTONACT( ui.subBrowseButton, browseFileSub() );
123 BUTTONACT( ui.subCheckBox, toggleSubtitleFrame());
125 CONNECT( ui.fileInput, editTextChanged(QString ), this, updateMRL());
126 CONNECT( ui.subInput, editTextChanged(QString ), this, updateMRL());
127 CONNECT( ui.alignSubComboBox, currentIndexChanged(int), this, updateMRL());
128 CONNECT( ui.sizeSubComboBox, currentIndexChanged(int), this, updateMRL());
129 CONNECT( lineFileEdit, textChanged( QString ), this, browseFile());
132 FileOpenPanel::~FileOpenPanel()
135 QStringList FileOpenPanel::browse(QString help)
137 return THEDP->showSimpleOpen( help );
140 void FileOpenPanel::browseFile()
142 QString fileString = "";
143 foreach( QString file, dialogBox->selectedFiles() ) {
144 fileString += "\"" + file + "\" ";
146 ui.fileInput->setEditText( fileString );
150 void FileOpenPanel::browseFileSub()
152 // FIXME Handle selection of more than one subtitles file
153 QStringList files = THEDP->showSimpleOpen( qtr("Open subtitles file"),
155 dialogBox->directory().absolutePath() );
156 if( files.isEmpty() ) return;
157 ui.subInput->setEditText( files.join(" ") );
161 void FileOpenPanel::updateMRL()
163 QString mrl = ui.fileInput->currentText();
165 if( ui.subCheckBox->isChecked() ) {
166 mrl.append( " :sub-file=" + ui.subInput->currentText() );
167 int align = ui.alignSubComboBox->itemData( ui.alignSubComboBox->currentIndex() ).toInt();
168 mrl.append( " :subsdec-align=" + QString().setNum( align ) );
169 int size = ui.sizeSubComboBox->itemData( ui.sizeSubComboBox->currentIndex() ).toInt();
170 mrl.append( " :freetype-rel-fontsize=" + QString().setNum( size ) );
172 emit mrlUpdated( mrl );
173 emit methodChanged( "file-caching" );
177 /* Function called by Open Dialog when clicke on Play/Enqueue */
178 void FileOpenPanel::accept()
180 ui.fileInput->addItem(ui.fileInput->currentText());
181 if ( ui.fileInput->count() > 8 ) ui.fileInput->removeItem(0);
185 /* Function called by Open Dialog when clicked on cancel */
186 void FileOpenPanel::clear()
188 ui.fileInput->setEditText( "" );
189 ui.subInput->setEditText( "" );
192 void FileOpenPanel::toggleSubtitleFrame()
194 if (ui.subFrame->isVisible())
197 // setMinimumHeight(1);
209 /**************************************************************************
211 **************************************************************************/
212 DiskOpenPanel::DiskOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
213 OpenPanel( _parent, _p_intf )
217 CONNECT( ui.deviceCombo, editTextChanged(QString ), this, updateMRL());
218 BUTTONACT( ui.dvdRadioButton, updateMRL());
219 BUTTONACT( ui.vcdRadioButton, updateMRL());
220 BUTTONACT( ui.audioCDRadioButton, updateMRL());
222 CONNECT( ui.titleSpin, valueChanged(int), this, updateMRL());
223 CONNECT( ui.chapterSpin, valueChanged(int), this, updateMRL());
226 DiskOpenPanel::~DiskOpenPanel()
229 void DiskOpenPanel::clear()
231 ui.titleSpin->setValue(0);
232 ui.chapterSpin->setValue(0);
235 void DiskOpenPanel::updateMRL()
239 if( ui.dvdRadioButton->isChecked() ) {
240 mrl = "dvd://" + ui.deviceCombo->currentText();
241 emit methodChanged( "dvdnav-caching" );
243 if ( ui.titleSpin->value() > 0 ) {
244 mrl += QString("@%1").arg(ui.titleSpin->value());
245 if ( ui.chapterSpin->value() > 0 ) {
246 mrl+= QString(":%1").arg(ui.chapterSpin->value());
251 } else if (ui.vcdRadioButton->isChecked() ) {
252 mrl = "vcd://" + ui.deviceCombo->currentText();
253 emit methodChanged( "vcd-caching" );
255 if( ui.titleSpin->value() > 0 ) {
256 mrl += QString("@%1").arg(ui.titleSpin->value());
261 mrl = "cdda://" + ui.deviceCombo->currentText();
264 emit mrlUpdated(mrl);
269 /**************************************************************************
271 **************************************************************************/
272 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
273 OpenPanel( _parent, _p_intf )
277 CONNECT( ui.protocolCombo, currentIndexChanged(int),
278 this, updateProtocol(int) );
279 CONNECT( ui.portSpin, valueChanged(int), this, updateMRL());
280 CONNECT( ui.addressText, textChanged(QString), this, updateAddress());
281 CONNECT( ui.timeShift, clicked(), this, updateMRL());
282 CONNECT( ui.ipv6, clicked(), this, updateMRL());
284 ui.protocolCombo->addItem("HTTP", QVariant("http"));
285 ui.protocolCombo->addItem("FTP", QVariant("ftp"));
286 ui.protocolCombo->addItem("MMS", QVariant("mms"));
287 ui.protocolCombo->addItem("RTSP", QVariant("rtsp"));
288 ui.protocolCombo->addItem("UDP/RTP (unicast)", QVariant("udp"));
289 ui.protocolCombo->addItem("UDP/RTP (multicast)", QVariant("udp"));
292 NetOpenPanel::~NetOpenPanel()
295 void NetOpenPanel::clear()
298 void NetOpenPanel::updateProtocol(int idx) {
299 QString addr = ui.addressText->text();
300 QString proto = ui.protocolCombo->itemData(idx).toString();
302 ui.timeShift->setEnabled( idx >= 4);
303 ui.ipv6->setEnabled( idx == 4 );
304 ui.addressText->setEnabled( idx != 4 );
305 ui.portSpin->setEnabled( idx >= 4 );
307 /* If we already have a protocol in the address, replace it */
308 if( addr.contains( "://")) {
309 msg_Err( p_intf, "replace");
310 addr.replace(QRegExp("^.*://"), proto + "://");
311 ui.addressText->setText(addr);
317 void NetOpenPanel::updateAddress() {
321 void NetOpenPanel::updateMRL() {
323 QString addr = ui.addressText->text();
324 int proto = ui.protocolCombo->currentIndex();
326 if( addr.contains( "://") && proto != 4 ) {
331 mrl = "http://" + addr;
332 emit methodChanged("http-caching");
335 mrl = "mms://" + addr;
336 emit methodChanged("mms-caching");
339 mrl = "ftp://" + addr;
340 emit methodChanged("ftp-caching");
343 mrl = "rtsp://" + addr;
344 emit methodChanged("rtsp-caching");
348 if( ui.ipv6->isEnabled() && ui.ipv6->isChecked() ) {
351 mrl += QString(":%1").arg(ui.portSpin->value());
352 emit methodChanged("udp-caching");
354 case 5: /* UDP multicast */
357 if ( addr.contains(':') && !addr.contains('[') ) {
358 mrl += "[" + addr + "]";
360 mrl += QString(":%1").arg(ui.portSpin->value());
361 emit methodChanged("udp-caching");
364 if( ui.timeShift->isEnabled() && ui.timeShift->isChecked() ) {
365 mrl += " :access-filter=timeshift";
367 emit mrlUpdated(mrl);
370 /**************************************************************************
372 **************************************************************************/
373 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
374 OpenPanel( _parent, _p_intf )
379 CaptureOpenPanel::~CaptureOpenPanel()
382 void CaptureOpenPanel::clear()
385 void CaptureOpenPanel::updateMRL()
388 emit mrlUpdated(mrl);