1 /*****************************************************************************
2 * open.cpp : Advanced open dialog
3 ****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
5 * $Id: streaminfo.cpp 16816 2006-09-23 20:56:52Z jb $
7 * Authors: Jean-Baptiste Kempf <jb@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/
24 #include <QGridLayout>
25 #include <QFileDialog>
27 #include "dialogs/open.hpp"
28 #include "components/open.hpp"
31 #include "util/qvlcframe.hpp"
33 #include "input_manager.hpp"
34 #include "dialogs_provider.hpp"
36 OpenDialog *OpenDialog::instance = NULL;
38 OpenDialog::OpenDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
40 setWindowTitle( qtr("Open" ) );
42 fileOpenPanel = new FileOpenPanel(this , p_intf );
43 diskOpenPanel = new DiskOpenPanel(this , p_intf );
44 netOpenPanel = new NetOpenPanel(this , p_intf );
45 ui.Tab->addTab(fileOpenPanel, qtr("File"));
46 ui.Tab->addTab(diskOpenPanel, qtr("Disk"));
47 ui.Tab->addTab(netOpenPanel, qtr("Network"));
49 ui.advancedFrame->hide();
51 /* Force MRL update on tab change */
52 CONNECT( ui.Tab, currentChanged(int), this, signalCurrent());
54 CONNECT( fileOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
55 CONNECT( netOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
56 CONNECT( diskOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
58 CONNECT( fileOpenPanel, methodChanged( QString ),
59 this, newMethod(QString) );
60 CONNECT( netOpenPanel, methodChanged( QString ),
61 this, newMethod(QString) );
62 CONNECT( diskOpenPanel, methodChanged( QString ),
63 this, newMethod(QString) );
65 CONNECT( ui.slaveText, textChanged(QString), this, updateMRL());
66 CONNECT( ui.cacheSpinBox, valueChanged(int), this, updateMRL());
68 BUTTONACT( ui.closeButton, ok());
69 BUTTONACT( ui.cancelButton, cancel());
70 BUTTONACT( ui.advancedCheckBox , toggleAdvancedPanel() );
72 /* Initialize caching */
74 newMethod("file-caching");
76 mainHeight = advHeight = 0;
79 OpenDialog::~OpenDialog()
83 void OpenDialog::showTab(int i_tab=0)
86 ui.Tab->setCurrentIndex(i_tab);
89 void OpenDialog::signalCurrent() {
90 if (ui.Tab->currentWidget() != NULL) {
91 (dynamic_cast<OpenPanel*>(ui.Tab->currentWidget()))->updateMRL();
95 void OpenDialog::cancel()
97 fileOpenPanel->clear();
98 this->toggleVisible();
101 void OpenDialog::ok()
103 QString mrl = ui.advancedLineInput->text();
104 QStringList tempMRL = mrl.split(" ");
105 for( size_t i = 0 ; i< tempMRL.size(); i++ )
107 const char * psz_utf8 = qtu( tempMRL[i] );
108 /* Play the first one, parse and enqueue the other ones */
109 playlist_Add( THEPL, psz_utf8, NULL,
110 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
111 ( i ? PLAYLIST_PREPARSE : 0 ),
112 PLAYLIST_END, VLC_TRUE );
115 this->toggleVisible();
118 void OpenDialog::changedTab()
122 void OpenDialog::toggleAdvancedPanel()
124 if (ui.advancedFrame->isVisible()) {
125 ui.advancedFrame->hide();
127 resize( width(), mainHeight );
130 if( mainHeight == 0 )
131 mainHeight = height();
133 ui.advancedFrame->show();
134 if( advHeight == 0 ) {
135 advHeight = height() - mainHeight;
137 resize( width(), mainHeight + advHeight );
141 void OpenDialog::updateMRL() {
142 QString mrl = mainMRL;
143 if( ui.slaveCheckbox->isChecked() ) {
144 mrl += " :input-slave=" + ui.slaveText->text();
146 int i_cache = config_GetInt( p_intf, qta(storedMethod) );
147 if( i_cache != ui.cacheSpinBox->value() ) {
148 mrl += QString(" :%1=%2").arg(storedMethod).
149 arg(ui.cacheSpinBox->value());
151 ui.advancedLineInput->setText(mrl);
154 void OpenDialog::updateMRL(QString tempMRL)
160 void OpenDialog::newMethod(QString method)
162 if( method != storedMethod ) {
163 storedMethod = method;
164 int i_value = config_GetInt( p_intf, qta(storedMethod) );
165 ui.cacheSpinBox->setValue(i_value);