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( QWidget *parent, intf_thread_t *_p_intf, bool modal ) :
39 QVLCDialog( parent, _p_intf )
41 setWindowTitle( qtr("Open" ) );
44 fileOpenPanel = new FileOpenPanel(this , p_intf );
45 diskOpenPanel = new DiskOpenPanel(this , p_intf );
46 netOpenPanel = new NetOpenPanel(this , p_intf );
47 ui.Tab->addTab(fileOpenPanel, qtr("File"));
48 ui.Tab->addTab(diskOpenPanel, qtr("Disk"));
49 ui.Tab->addTab(netOpenPanel, qtr("Network"));
51 ui.advancedFrame->hide();
53 /* Force MRL update on tab change */
54 CONNECT( ui.Tab, currentChanged(int), this, signalCurrent());
56 CONNECT( fileOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
57 CONNECT( netOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
58 CONNECT( diskOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
60 CONNECT( fileOpenPanel, methodChanged( QString ),
61 this, newMethod(QString) );
62 CONNECT( netOpenPanel, methodChanged( QString ),
63 this, newMethod(QString) );
64 CONNECT( diskOpenPanel, methodChanged( QString ),
65 this, newMethod(QString) );
67 CONNECT( ui.slaveText, textChanged(QString), this, updateMRL());
68 CONNECT( ui.cacheSpinBox, valueChanged(int), this, updateMRL());
70 BUTTONACT( ui.closeButton, ok());
71 BUTTONACT( ui.cancelButton, cancel());
72 BUTTONACT( ui.advancedCheckBox , toggleAdvancedPanel() );
74 /* Initialize caching */
76 newMethod("file-caching");
78 mainHeight = advHeight = 0;
81 OpenDialog::~OpenDialog()
85 void OpenDialog::showTab(int i_tab=0)
87 printf ( "%i" , i_tab);
89 ui.Tab->setCurrentIndex(i_tab);
92 void OpenDialog::signalCurrent() {
93 if (ui.Tab->currentWidget() != NULL) {
94 (dynamic_cast<OpenPanel*>(ui.Tab->currentWidget()))->updateMRL();
98 void OpenDialog::cancel()
100 fileOpenPanel->clear();
101 this->toggleVisible();
106 void OpenDialog::ok()
108 this->toggleVisible();
109 mrl = ui.advancedLineInput->text();
110 QStringList tempMRL = mrl.split(" ");
113 for( size_t i = 0 ; i< tempMRL.size(); i++ )
115 const char * psz_utf8 = qtu( tempMRL[i] );
116 /* Play the first one, parse and enqueue the other ones */
117 playlist_Add( THEPL, psz_utf8, NULL,
118 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
119 ( i ? PLAYLIST_PREPARSE : 0 ),
120 PLAYLIST_END, VLC_TRUE );
128 void OpenDialog::toggleAdvancedPanel()
130 if (ui.advancedFrame->isVisible()) {
131 ui.advancedFrame->hide();
133 resize( width(), mainHeight );
136 if( mainHeight == 0 )
137 mainHeight = height();
139 ui.advancedFrame->show();
140 if( advHeight == 0 ) {
141 advHeight = height() - mainHeight;
143 resize( width(), mainHeight + advHeight );
149 void OpenDialog::updateMRL() {
151 if( ui.slaveCheckbox->isChecked() ) {
152 mrl += " :input-slave=" + ui.slaveText->text();
154 int i_cache = config_GetInt( p_intf, qta(storedMethod) );
155 if( i_cache != ui.cacheSpinBox->value() ) {
156 mrl += QString(" :%1=%2").arg(storedMethod).
157 arg(ui.cacheSpinBox->value());
159 ui.advancedLineInput->setText(mrl);
162 void OpenDialog::updateMRL(QString tempMRL)
168 void OpenDialog::newMethod(QString method)
170 if( method != storedMethod ) {
171 storedMethod = method;
172 int i_value = config_GetInt( p_intf, qta(storedMethod) );
173 ui.cacheSpinBox->setValue(i_value);