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.
22 *****************************************************************************/
25 #include <QGridLayout>
26 #include <QFileDialog>
29 #include "dialogs/open.hpp"
30 #include "components/open.hpp"
33 #include "util/qvlcframe.hpp"
35 #include "input_manager.hpp"
36 #include "dialogs_provider.hpp"
38 OpenDialog *OpenDialog::instance = NULL;
40 OpenDialog::OpenDialog( QWidget *parent, intf_thread_t *_p_intf, bool modal ) :
41 QVLCDialog( parent, _p_intf )
45 setWindowTitle( qtr("Open" ) );
48 fileOpenPanel = new FileOpenPanel( ui.Tab , p_intf );
49 diskOpenPanel = new DiskOpenPanel( ui.Tab , p_intf );
50 netOpenPanel = new NetOpenPanel( ui.Tab , p_intf );
51 captureOpenPanel = new CaptureOpenPanel( ui.Tab, p_intf );
53 ui.Tab->addTab( fileOpenPanel, qtr( "&File" ) );
54 ui.Tab->addTab( diskOpenPanel, qtr( "&Disc" ) );
55 ui.Tab->addTab( netOpenPanel, qtr( "&Network" ) );
56 ui.Tab->addTab( captureOpenPanel, qtr( "Capture &Device" ) );
58 ui.advancedFrame->hide();
60 QMenu * openButtonMenu = new QMenu( "Open" );
61 openButtonMenu->addAction( qtr("&Enqueue"), this, SLOT( enqueue() ),
62 QKeySequence( "Alt+E") );
63 openButtonMenu->addAction( qtr("&Stream"), this, SLOT( stream() ) ,
64 QKeySequence( "Alt+T" ) );
66 ui.playButton->setMenu( openButtonMenu );
67 /* Force MRL update on tab change */
68 CONNECT( ui.Tab, currentChanged(int), this, signalCurrent());
70 CONNECT( fileOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
71 CONNECT( netOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
72 CONNECT( diskOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
73 CONNECT( captureOpenPanel, mrlUpdated( QString ), this,
77 CONNECT( fileOpenPanel, methodChanged( QString ),
78 this, newMethod(QString) );
79 CONNECT( netOpenPanel, methodChanged( QString ),
80 this, newMethod(QString) );
81 CONNECT( diskOpenPanel, methodChanged( QString ),
82 this, newMethod(QString) );
84 CONNECT( ui.slaveText, textChanged(QString), this, updateMRL());
85 CONNECT( ui.cacheSpinBox, valueChanged(int), this, updateMRL());
87 BUTTONACT( ui.playButton, play());
88 BUTTONACT( ui.cancelButton, cancel());
89 BUTTONACT( ui.advancedCheckBox , toggleAdvancedPanel() );
91 /* Initialize caching */
93 newMethod("file-caching");
95 mainHeight = advHeight = 0;
98 OpenDialog::~OpenDialog()
102 void OpenDialog::showTab(int i_tab=0)
105 ui.Tab->setCurrentIndex(i_tab);
108 void OpenDialog::signalCurrent() {
109 if (ui.Tab->currentWidget() != NULL) {
110 (dynamic_cast<OpenPanel*>(ui.Tab->currentWidget()))->updateMRL();
114 void OpenDialog::cancel()
116 fileOpenPanel->clear();
117 this->toggleVisible();
122 void OpenDialog::close()
126 void OpenDialog::play()
128 playOrEnqueue( false );
131 void OpenDialog::enqueue()
133 playOrEnqueue( true );
136 void OpenDialog::playOrEnqueue( bool b_enqueue = false )
138 this->toggleVisible();
139 mrl = ui.advancedLineInput->text();
143 QStringList tempMRL = SeparateEntries( mrl );
144 for( size_t i = 0; i < tempMRL.size(); i++ )
146 bool b_start = !i && !b_enqueue;
147 input_item_t *p_input;
148 const char *psz_utf8 = qtu( tempMRL[i] );
150 p_input = input_ItemNew( p_intf, psz_utf8, NULL );
153 while( i + 1 < tempMRL.size() && tempMRL[i + 1].startsWith( ":" ) )
156 psz_utf8 = qtu( tempMRL[i] );
157 input_ItemAddOption( p_input, psz_utf8 );
162 playlist_AddInput( THEPL, p_input,
163 PLAYLIST_APPEND | PLAYLIST_GO,
164 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
168 playlist_AddInput( THEPL, p_input,
169 PLAYLIST_APPEND|PLAYLIST_PREPARSE,
170 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
178 void OpenDialog::stream()
180 //TODO. Policy not yet defined
183 void OpenDialog::toggleAdvancedPanel()
185 //FIXME does not work under Windows
186 if (ui.advancedFrame->isVisible()) {
187 ui.advancedFrame->hide();
189 resize( width(), mainHeight );
192 if( mainHeight == 0 )
193 mainHeight = height();
195 ui.advancedFrame->show();
196 if( advHeight == 0 ) {
197 advHeight = height() - mainHeight;
199 resize( width(), mainHeight + advHeight );
203 void OpenDialog::updateMRL() {
205 if( ui.slaveCheckbox->isChecked() ) {
206 mrl += " :input-slave=" + ui.slaveText->text();
208 int i_cache = config_GetInt( p_intf, qta(storedMethod) );
209 if( i_cache != ui.cacheSpinBox->value() ) {
210 mrl += QString(" :%1=%2").arg(storedMethod).
211 arg(ui.cacheSpinBox->value());
213 ui.advancedLineInput->setText(mrl);
216 void OpenDialog::updateMRL(QString tempMRL)
222 void OpenDialog::newMethod(QString method)
224 if( method != storedMethod ) {
225 storedMethod = method;
226 int i_value = config_GetInt( p_intf, qta(storedMethod) );
227 ui.cacheSpinBox->setValue(i_value);
231 QStringList OpenDialog::SeparateEntries( QString entries )
233 bool b_quotes_mode = false;
235 QStringList entries_array;
239 while( index < entries.size() )
241 int delim_pos = entries.indexOf( QRegExp( "\\s+|\"" ), index );
242 if( delim_pos < 0 ) delim_pos = entries.size() - 1;
243 entry += entries.mid( index, delim_pos - index + 1 );
244 index = delim_pos + 1;
246 if( entry.isEmpty() ) continue;
248 if( !b_quotes_mode && entry.endsWith( "\"" ) )
250 /* Enters quotes mode */
251 entry.truncate( entry.size() - 1 );
252 b_quotes_mode = true;
254 else if( b_quotes_mode && entry.endsWith( "\"" ) )
256 /* Finished the quotes mode */
257 entry.truncate( entry.size() - 1 );
258 b_quotes_mode = false;
260 else if( !b_quotes_mode && !entry.endsWith( "\"" ) )
262 /* we found a non-quoted standalone string */
263 if( index < entries.size() ||
264 entry.endsWith( " " ) || entry.endsWith( "\t" ) ||
265 entry.endsWith( "\r" ) || entry.endsWith( "\n" ) )
266 entry.truncate( entry.size() - 1 );
267 if( !entry.isEmpty() ) entries_array.append( entry );
274 if( !entry.isEmpty() ) entries_array.append( entry );
276 return entries_array;