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/open.hpp"
29 #include "dialogs_provider.hpp"
30 #include "util/customwidgets.hpp"
32 #include <QFileDialog>
33 #include <QDialogButtonBox>
36 /**************************************************************************
38 **************************************************************************/
39 FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
40 OpenPanel( _parent, _p_intf )
42 /* Classic UI Setup */
45 /* Use a QFileDialog and customize it because we don't want to
46 rewrite it all. Be careful to your eyes cause there are a few hacks.
47 Be very careful and test correctly when you modify this. */
49 /* Set Filters for file selection */
50 QString fileTypes = "";
51 ADD_FILTER_MEDIA( fileTypes );
52 ADD_FILTER_VIDEO( fileTypes );
53 ADD_FILTER_AUDIO( fileTypes );
54 ADD_FILTER_PLAYLIST( fileTypes );
55 ADD_FILTER_ALL( fileTypes );
56 fileTypes.replace(QString(";*"), QString(" *"));
58 // Make this QFileDialog a child of tempWidget from the ui.
59 dialogBox = new FileOpenBox( ui.tempWidget, NULL,
60 qfu( p_intf->p_libvlc->psz_homedir ), fileTypes );
61 dialogBox->setFileMode( QFileDialog::ExistingFiles );
62 dialogBox->setAcceptMode( QFileDialog::AcceptOpen );
64 /* We don't want to see a grip in the middle of the window, do we? */
65 dialogBox->setSizeGripEnabled( false );
66 dialogBox->setToolTip( qtr( "Select one or multiple files, or a folder" ));
68 // Add it to the layout
69 ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
71 // But hide the two OK/Cancel buttons. Enable them for debug.
72 fileDialogAcceptBox = findChildren<QDialogButtonBox*>()[0];
73 fileDialogAcceptBox->hide();
75 /* Ugly hacks to get the good Widget */
76 //This lineEdit is the normal line in the fileDialog.
77 lineFileEdit = findChildren<QLineEdit*>()[3];
80 /* Make a list of QLabel inside the QFileDialog to access the good ones */
81 QList<QLabel *> listLabel = findChildren<QLabel*>();
83 /* Hide the FileNames one. Enable it for debug */
85 /* Change the text that was uncool in the usual box */
86 listLabel[5]->setText( qtr( "Filter:" ) );
88 // Hide the subtitles control by default.
91 /* Build the subs size combo box */
92 module_config_t *p_item =
93 config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
96 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
98 ui.sizeSubComboBox->addItem(
99 qfu( p_item->ppsz_list_text[i_index] ),
100 QVariant( p_item->pi_list[i_index] ) );
101 if( p_item->value.i == p_item->pi_list[i_index] )
103 ui.sizeSubComboBox->setCurrentIndex( i_index );
108 /* Build the subs align combo box */
109 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
112 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
114 ui.alignSubComboBox->addItem(
115 qfu( p_item->ppsz_list_text[i_index] ),
116 QVariant( p_item->pi_list[i_index] ) );
117 if( p_item->value.i == p_item->pi_list[i_index] )
119 ui.alignSubComboBox->setCurrentIndex( i_index );
124 BUTTONACT( ui.subBrowseButton, browseFileSub() );
125 BUTTONACT( ui.subCheckBox, toggleSubtitleFrame());
127 CONNECT( ui.fileInput, editTextChanged(QString ), this, updateMRL());
128 CONNECT( ui.subInput, editTextChanged(QString ), this, updateMRL());
129 CONNECT( ui.alignSubComboBox, currentIndexChanged(int), this, updateMRL());
130 CONNECT( ui.sizeSubComboBox, currentIndexChanged(int), this, updateMRL());
131 CONNECT( lineFileEdit, textChanged( QString ), this, browseFile());
134 FileOpenPanel::~FileOpenPanel()
137 QStringList FileOpenPanel::browse(QString help)
139 return THEDP->showSimpleOpen( help );
142 void FileOpenPanel::browseFile()
144 QString fileString = "";
145 foreach( QString file, dialogBox->selectedFiles() ) {
146 fileString += "\"" + file + "\" ";
148 ui.fileInput->setEditText( fileString );
152 void FileOpenPanel::browseFileSub()
154 // FIXME Handle selection of more than one subtitles file
155 QStringList files = THEDP->showSimpleOpen( qtr("Open subtitles file"),
157 dialogBox->directory().absolutePath() );
158 if( files.isEmpty() ) return;
159 ui.subInput->setEditText( files.join(" ") );
163 void FileOpenPanel::updateMRL()
165 QString mrl = ui.fileInput->currentText();
167 if( ui.subCheckBox->isChecked() ) {
168 mrl.append( " :sub-file=" + ui.subInput->currentText() );
169 int align = ui.alignSubComboBox->itemData( ui.alignSubComboBox->currentIndex() ).toInt();
170 mrl.append( " :subsdec-align=" + QString().setNum( align ) );
171 int size = ui.sizeSubComboBox->itemData( ui.sizeSubComboBox->currentIndex() ).toInt();
172 mrl.append( " :freetype-rel-fontsize=" + QString().setNum( size ) );
174 emit mrlUpdated( mrl );
175 emit methodChanged( "file-caching" );
179 /* Function called by Open Dialog when clicke on Play/Enqueue */
180 void FileOpenPanel::accept()
182 ui.fileInput->addItem(ui.fileInput->currentText());
183 if ( ui.fileInput->count() > 8 ) ui.fileInput->removeItem(0);
186 void FileOpenBox::accept()
188 OpenDialog::getInstance( NULL, NULL )->play();
191 /* Function called by Open Dialog when clicked on cancel */
192 void FileOpenPanel::clear()
194 ui.fileInput->setEditText( "" );
195 ui.subInput->setEditText( "" );
198 void FileOpenPanel::toggleSubtitleFrame()
200 if (ui.subFrame->isVisible())
203 // setMinimumHeight(1);
215 /**************************************************************************
217 **************************************************************************/
218 DiscOpenPanel::DiscOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
219 OpenPanel( _parent, _p_intf )
223 CONNECT( ui.deviceCombo, editTextChanged(QString ), this, updateMRL());
224 BUTTONACT( ui.dvdRadioButton, updateMRL());
225 BUTTONACT( ui.vcdRadioButton, updateMRL());
226 BUTTONACT( ui.audioCDRadioButton, updateMRL());
228 CONNECT( ui.titleSpin, valueChanged(int), this, updateMRL());
229 CONNECT( ui.chapterSpin, valueChanged(int), this, updateMRL());
232 DiscOpenPanel::~DiscOpenPanel()
235 void DiscOpenPanel::clear()
237 ui.titleSpin->setValue(0);
238 ui.chapterSpin->setValue(0);
241 void DiscOpenPanel::updateMRL()
245 if( ui.dvdRadioButton->isChecked() ) {
246 mrl = "dvd://" + ui.deviceCombo->currentText();
247 emit methodChanged( "dvdnav-caching" );
249 if ( ui.titleSpin->value() > 0 ) {
250 mrl += QString("@%1").arg(ui.titleSpin->value());
251 if ( ui.chapterSpin->value() > 0 ) {
252 mrl+= QString(":%1").arg(ui.chapterSpin->value());
257 } else if (ui.vcdRadioButton->isChecked() ) {
258 mrl = "vcd://" + ui.deviceCombo->currentText();
259 emit methodChanged( "vcd-caching" );
261 if( ui.titleSpin->value() > 0 ) {
262 mrl += QString("@%1").arg(ui.titleSpin->value());
267 mrl = "cdda://" + ui.deviceCombo->currentText();
270 emit mrlUpdated(mrl);
275 /**************************************************************************
277 **************************************************************************/
278 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
279 OpenPanel( _parent, _p_intf )
283 CONNECT( ui.protocolCombo, currentIndexChanged(int),
284 this, updateProtocol(int) );
285 CONNECT( ui.portSpin, valueChanged(int), this, updateMRL());
286 CONNECT( ui.addressText, textChanged(QString), this, updateAddress());
287 CONNECT( ui.timeShift, clicked(), this, updateMRL());
288 CONNECT( ui.ipv6, clicked(), this, updateMRL());
290 ui.protocolCombo->addItem("HTTP", QVariant("http"));
291 ui.protocolCombo->addItem("FTP", QVariant("ftp"));
292 ui.protocolCombo->addItem("MMS", QVariant("mms"));
293 ui.protocolCombo->addItem("RTSP", QVariant("rtsp"));
294 ui.protocolCombo->addItem("UDP/RTP (unicast)", QVariant("udp"));
295 ui.protocolCombo->addItem("UDP/RTP (multicast)", QVariant("udp"));
298 NetOpenPanel::~NetOpenPanel()
301 void NetOpenPanel::clear()
304 void NetOpenPanel::updateProtocol(int idx) {
305 QString addr = ui.addressText->text();
306 QString proto = ui.protocolCombo->itemData(idx).toString();
308 ui.timeShift->setEnabled( idx >= 4);
309 ui.ipv6->setEnabled( idx == 4 );
310 ui.addressText->setEnabled( idx != 4 );
311 ui.portSpin->setEnabled( idx >= 4 );
313 /* If we already have a protocol in the address, replace it */
314 if( addr.contains( "://")) {
315 msg_Err( p_intf, "replace");
316 addr.replace(QRegExp("^.*://"), proto + "://");
317 ui.addressText->setText(addr);
323 void NetOpenPanel::updateAddress() {
327 void NetOpenPanel::updateMRL() {
329 QString addr = ui.addressText->text();
330 int proto = ui.protocolCombo->currentIndex();
332 if( addr.contains( "://") && proto != 4 ) {
337 mrl = "http://" + addr;
338 emit methodChanged("http-caching");
341 mrl = "mms://" + addr;
342 emit methodChanged("mms-caching");
345 mrl = "ftp://" + addr;
346 emit methodChanged("ftp-caching");
349 mrl = "rtsp://" + addr;
350 emit methodChanged("rtsp-caching");
354 if( ui.ipv6->isEnabled() && ui.ipv6->isChecked() ) {
357 mrl += QString(":%1").arg(ui.portSpin->value());
358 emit methodChanged("udp-caching");
360 case 5: /* UDP multicast */
363 if ( addr.contains(':') && !addr.contains('[') ) {
364 mrl += "[" + addr + "]";
366 mrl += QString(":%1").arg(ui.portSpin->value());
367 emit methodChanged("udp-caching");
370 if( ui.timeShift->isEnabled() && ui.timeShift->isChecked() ) {
371 mrl += " :access-filter=timeshift";
373 emit mrlUpdated(mrl);
376 /**************************************************************************
378 **************************************************************************/
379 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
380 OpenPanel( _parent, _p_intf )
385 CaptureOpenPanel::~CaptureOpenPanel()
388 void CaptureOpenPanel::clear()
391 void CaptureOpenPanel::updateMRL()
394 emit mrlUpdated(mrl);