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 /* We don't want to see a grip in the middle of the window, do we? */
63 dialogBox->setSizeGripEnabled( false );
64 dialogBox->setToolTip( qtr( "Select one or multiple files, or a folder" ));
66 // Add it to the layout
67 ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
69 // But hide the two OK/Cancel buttons. Enable them for debug.
71 findChild<QDialogButtonBox*>()->hide();
74 /* Ugly hacks to get the good Widget */
75 //This lineEdit is the normal line in the fileDialog.
76 lineFileEdit = findChildren<QLineEdit*>()[3];
79 /* Make a list of QLabel inside the QFileDialog to access the good ones */
80 QList<QLabel *> listLabel = findChildren<QLabel*>();
82 /* Hide the FileNames one. Enable it for debug */
84 /* Change the text that was uncool in the usual box */
85 listLabel[5]->setText( qtr( "Filter:" ) );
87 // Hide the subtitles control by default.
90 /* Build the subs size combo box */
91 module_config_t *p_item =
92 config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
95 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
97 ui.sizeSubComboBox->addItem(
98 qfu( p_item->ppsz_list_text[i_index] ),
99 QVariant( p_item->pi_list[i_index] ) );
100 if( p_item->value.i == p_item->pi_list[i_index] )
102 ui.sizeSubComboBox->setCurrentIndex( i_index );
107 /* Build the subs align combo box */
108 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
111 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
113 ui.alignSubComboBox->addItem(
114 qfu( p_item->ppsz_list_text[i_index] ),
115 QVariant( p_item->pi_list[i_index] ) );
116 if( p_item->value.i == p_item->pi_list[i_index] )
118 ui.alignSubComboBox->setCurrentIndex( i_index );
123 BUTTONACT( ui.subBrowseButton, browseFileSub() );
124 BUTTONACT( ui.subCheckBox, toggleSubtitleFrame());
126 CONNECT( ui.fileInput, editTextChanged(QString ), this, updateMRL());
127 CONNECT( ui.subInput, editTextChanged(QString ), this, updateMRL());
128 CONNECT( ui.alignSubComboBox, currentIndexChanged(int), this, updateMRL());
129 CONNECT( ui.sizeSubComboBox, currentIndexChanged(int), this, updateMRL());
130 CONNECT( lineFileEdit, textChanged( QString ), this, browseFile());
133 FileOpenPanel::~FileOpenPanel()
136 QStringList FileOpenPanel::browse(QString help)
138 return THEDP->showSimpleOpen( help );
141 void FileOpenPanel::browseFile()
143 QString fileString = "";
144 foreach( QString file, dialogBox->selectedFiles() ) {
145 fileString += "\"" + file + "\" ";
147 ui.fileInput->setEditText( fileString );
151 void FileOpenPanel::browseFileSub()
153 // FIXME Handle selection of more than one subtitles file
154 QStringList files = THEDP->showSimpleOpen( qtr("Open subtitles file"),
156 dialogBox->directory().absolutePath() );
157 if( files.isEmpty() ) return;
158 ui.subInput->setEditText( files.join(" ") );
162 void FileOpenPanel::updateMRL()
164 QString mrl = ui.fileInput->currentText();
166 if( ui.subCheckBox->isChecked() ) {
167 mrl.append( " :sub-file=" + ui.subInput->currentText() );
168 int align = ui.alignSubComboBox->itemData( ui.alignSubComboBox->currentIndex() ).toInt();
169 mrl.append( " :subsdec-align=" + QString().setNum( align ) );
170 int size = ui.sizeSubComboBox->itemData( ui.sizeSubComboBox->currentIndex() ).toInt();
171 mrl.append( " :freetype-rel-fontsize=" + QString().setNum( size ) );
173 emit mrlUpdated( mrl );
174 emit methodChanged( "file-caching" );
178 /* Function called by Open Dialog when clicke on Play/Enqueue */
179 void FileOpenPanel::accept()
181 ui.fileInput->addItem(ui.fileInput->currentText());
182 if ( ui.fileInput->count() > 8 ) ui.fileInput->removeItem(0);
185 void FileOpenBox::accept()
187 OpenDialog::getInstance( NULL, NULL )->play();
190 /* Function called by Open Dialog when clicked on cancel */
191 void FileOpenPanel::clear()
193 ui.fileInput->setEditText( "" );
194 ui.subInput->setEditText( "" );
197 void FileOpenPanel::toggleSubtitleFrame()
199 if (ui.subFrame->isVisible())
202 // setMinimumHeight(1);
214 /**************************************************************************
216 **************************************************************************/
217 DiskOpenPanel::DiskOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
218 OpenPanel( _parent, _p_intf )
222 CONNECT( ui.deviceCombo, editTextChanged(QString ), this, updateMRL());
223 BUTTONACT( ui.dvdRadioButton, updateMRL());
224 BUTTONACT( ui.vcdRadioButton, updateMRL());
225 BUTTONACT( ui.audioCDRadioButton, updateMRL());
227 CONNECT( ui.titleSpin, valueChanged(int), this, updateMRL());
228 CONNECT( ui.chapterSpin, valueChanged(int), this, updateMRL());
231 DiskOpenPanel::~DiskOpenPanel()
234 void DiskOpenPanel::clear()
236 ui.titleSpin->setValue(0);
237 ui.chapterSpin->setValue(0);
240 void DiskOpenPanel::updateMRL()
244 if( ui.dvdRadioButton->isChecked() ) {
245 mrl = "dvd://" + ui.deviceCombo->currentText();
246 emit methodChanged( "dvdnav-caching" );
248 if ( ui.titleSpin->value() > 0 ) {
249 mrl += QString("@%1").arg(ui.titleSpin->value());
250 if ( ui.chapterSpin->value() > 0 ) {
251 mrl+= QString(":%1").arg(ui.chapterSpin->value());
256 } else if (ui.vcdRadioButton->isChecked() ) {
257 mrl = "vcd://" + ui.deviceCombo->currentText();
258 emit methodChanged( "vcd-caching" );
260 if( ui.titleSpin->value() > 0 ) {
261 mrl += QString("@%1").arg(ui.titleSpin->value());
266 mrl = "cdda://" + ui.deviceCombo->currentText();
269 emit mrlUpdated(mrl);
274 /**************************************************************************
276 **************************************************************************/
277 NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
278 OpenPanel( _parent, _p_intf )
282 CONNECT( ui.protocolCombo, currentIndexChanged(int),
283 this, updateProtocol(int) );
284 CONNECT( ui.portSpin, valueChanged(int), this, updateMRL());
285 CONNECT( ui.addressText, textChanged(QString), this, updateAddress());
286 CONNECT( ui.timeShift, clicked(), this, updateMRL());
287 CONNECT( ui.ipv6, clicked(), this, updateMRL());
289 ui.protocolCombo->addItem("HTTP", QVariant("http"));
290 ui.protocolCombo->addItem("FTP", QVariant("ftp"));
291 ui.protocolCombo->addItem("MMS", QVariant("mms"));
292 ui.protocolCombo->addItem("RTSP", QVariant("rtsp"));
293 ui.protocolCombo->addItem("UDP/RTP (unicast)", QVariant("udp"));
294 ui.protocolCombo->addItem("UDP/RTP (multicast)", QVariant("udp"));
297 NetOpenPanel::~NetOpenPanel()
300 void NetOpenPanel::clear()
303 void NetOpenPanel::updateProtocol(int idx) {
304 QString addr = ui.addressText->text();
305 QString proto = ui.protocolCombo->itemData(idx).toString();
307 ui.timeShift->setEnabled( idx >= 4);
308 ui.ipv6->setEnabled( idx == 4 );
309 ui.addressText->setEnabled( idx != 4 );
310 ui.portSpin->setEnabled( idx >= 4 );
312 /* If we already have a protocol in the address, replace it */
313 if( addr.contains( "://")) {
314 msg_Err( p_intf, "replace");
315 addr.replace(QRegExp("^.*://"), proto + "://");
316 ui.addressText->setText(addr);
322 void NetOpenPanel::updateAddress() {
326 void NetOpenPanel::updateMRL() {
328 QString addr = ui.addressText->text();
329 int proto = ui.protocolCombo->currentIndex();
331 if( addr.contains( "://") && proto != 4 ) {
336 mrl = "http://" + addr;
337 emit methodChanged("http-caching");
340 mrl = "mms://" + addr;
341 emit methodChanged("mms-caching");
344 mrl = "ftp://" + addr;
345 emit methodChanged("ftp-caching");
348 mrl = "rtsp://" + addr;
349 emit methodChanged("rtsp-caching");
353 if( ui.ipv6->isEnabled() && ui.ipv6->isChecked() ) {
356 mrl += QString(":%1").arg(ui.portSpin->value());
357 emit methodChanged("udp-caching");
359 case 5: /* UDP multicast */
362 if ( addr.contains(':') && !addr.contains('[') ) {
363 mrl += "[" + addr + "]";
365 mrl += QString(":%1").arg(ui.portSpin->value());
366 emit methodChanged("udp-caching");
369 if( ui.timeShift->isEnabled() && ui.timeShift->isChecked() ) {
370 mrl += " :access-filter=timeshift";
372 emit mrlUpdated(mrl);
375 /**************************************************************************
377 **************************************************************************/
378 CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
379 OpenPanel( _parent, _p_intf )
384 CaptureOpenPanel::~CaptureOpenPanel()
387 void CaptureOpenPanel::clear()
390 void CaptureOpenPanel::updateMRL()
393 emit mrlUpdated(mrl);