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 bool _stream_after ) : QVLCDialog( parent, _p_intf )
44 b_stream_after = _stream_after;
47 setWindowTitle( qtr("Open" ) );
50 fileOpenPanel = new FileOpenPanel( ui.Tab , p_intf );
51 diskOpenPanel = new DiskOpenPanel( ui.Tab , p_intf );
52 netOpenPanel = new NetOpenPanel( ui.Tab , p_intf );
53 captureOpenPanel = new CaptureOpenPanel( ui.Tab, p_intf );
55 ui.Tab->addTab( fileOpenPanel, qtr( "&File" ) );
56 ui.Tab->addTab( diskOpenPanel, qtr( "&Disc" ) );
57 ui.Tab->addTab( netOpenPanel, qtr( "&Network" ) );
58 ui.Tab->addTab( captureOpenPanel, qtr( "Capture &Device" ) );
60 ui.advancedFrame->hide();
61 QMenu * openButtonMenu = new QMenu( "Open" );
63 /* Force MRL update on tab change */
64 CONNECT( ui.Tab, currentChanged(int), this, signalCurrent());
66 CONNECT( fileOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
67 CONNECT( netOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
68 CONNECT( diskOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
69 CONNECT( captureOpenPanel, mrlUpdated( QString ), this,
72 CONNECT( fileOpenPanel, methodChanged( QString ),
73 this, newMethod(QString) );
74 CONNECT( netOpenPanel, methodChanged( QString ),
75 this, newMethod(QString) );
76 CONNECT( diskOpenPanel, methodChanged( QString ),
77 this, newMethod(QString) );
79 CONNECT( ui.slaveText, textChanged(QString), this, updateMRL());
80 CONNECT( ui.cacheSpinBox, valueChanged(int), this, updateMRL());
82 openButtonMenu->addAction( qtr("&Enqueue"), this, SLOT( enqueue() ),
83 QKeySequence( "Alt+E") );
84 openButtonMenu->addAction( qtr("&Play"), this, SLOT( play() ),
85 QKeySequence( "Alt+P" ) );
86 openButtonMenu->addAction( qtr("&Stream"), this, SLOT( stream() ) ,
87 QKeySequence( "Alt+S" ) );
89 ui.playButton->setMenu( openButtonMenu );
91 BUTTONACT( ui.playButton, play());
93 if ( b_stream_after ) setAfter();
95 BUTTONACT( ui.cancelButton, cancel());
96 BUTTONACT( ui.advancedCheckBox , toggleAdvancedPanel() );
98 /* Initialize caching */
100 newMethod("file-caching");
102 mainHeight = advHeight = 0;
105 OpenDialog::~OpenDialog()
109 void OpenDialog::setAfter()
111 if (!b_stream_after )
113 ui.playButton->setText( qtr("&Play") );
114 BUTTONACT( ui.playButton, play() );
118 ui.playButton->setText( qtr("&Stream") );
119 BUTTONACT( ui.playButton, stream() );
123 void OpenDialog::showTab(int i_tab=0)
126 ui.Tab->setCurrentIndex(i_tab);
129 void OpenDialog::signalCurrent() {
130 if (ui.Tab->currentWidget() != NULL) {
131 (dynamic_cast<OpenPanel*>(ui.Tab->currentWidget()))->updateMRL();
137 /* If Cancel is pressed or escaped */
138 void OpenDialog::cancel()
140 fileOpenPanel->clear();
141 this->toggleVisible();
146 /* If EnterKey is pressed */
147 void OpenDialog::close()
149 if ( !b_stream_after )
160 void OpenDialog::play()
162 playOrEnqueue( false );
165 void OpenDialog::enqueue()
167 playOrEnqueue( true );
170 void OpenDialog::stream()
172 /* not finished FIXME */
173 THEDP->streamingDialog( mrl );
177 void OpenDialog::playOrEnqueue( bool b_enqueue = false )
179 this->toggleVisible();
180 mrl = ui.advancedLineInput->text();
184 QStringList tempMRL = SeparateEntries( mrl );
185 for( size_t i = 0; i < tempMRL.size(); i++ )
187 bool b_start = !i && !b_enqueue;
188 input_item_t *p_input;
189 const char *psz_utf8 = qtu( tempMRL[i] );
191 p_input = input_ItemNew( p_intf, psz_utf8, NULL );
194 while( i + 1 < tempMRL.size() && tempMRL[i + 1].startsWith( ":" ) )
197 psz_utf8 = qtu( tempMRL[i] );
198 input_ItemAddOption( p_input, psz_utf8 );
203 playlist_AddInput( THEPL, p_input,
204 PLAYLIST_APPEND | PLAYLIST_GO,
205 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
209 playlist_AddInput( THEPL, p_input,
210 PLAYLIST_APPEND|PLAYLIST_PREPARSE,
211 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
219 void OpenDialog::toggleAdvancedPanel()
221 //FIXME does not work under Windows
222 if (ui.advancedFrame->isVisible()) {
223 ui.advancedFrame->hide();
225 resize( width(), mainHeight );
228 if( mainHeight == 0 )
229 mainHeight = height();
231 ui.advancedFrame->show();
232 if( advHeight == 0 ) {
233 advHeight = height() - mainHeight;
235 resize( width(), mainHeight + advHeight );
239 void OpenDialog::updateMRL() {
241 if( ui.slaveCheckbox->isChecked() ) {
242 mrl += " :input-slave=" + ui.slaveText->text();
244 int i_cache = config_GetInt( p_intf, qta(storedMethod) );
245 if( i_cache != ui.cacheSpinBox->value() ) {
246 mrl += QString(" :%1=%2").arg(storedMethod).
247 arg(ui.cacheSpinBox->value());
249 ui.advancedLineInput->setText(mrl);
252 void OpenDialog::updateMRL(QString tempMRL)
258 void OpenDialog::newMethod(QString method)
260 if( method != storedMethod ) {
261 storedMethod = method;
262 int i_value = config_GetInt( p_intf, qta(storedMethod) );
263 ui.cacheSpinBox->setValue(i_value);
267 QStringList OpenDialog::SeparateEntries( QString entries )
269 bool b_quotes_mode = false;
271 QStringList entries_array;
275 while( index < entries.size() )
277 int delim_pos = entries.indexOf( QRegExp( "\\s+|\"" ), index );
278 if( delim_pos < 0 ) delim_pos = entries.size() - 1;
279 entry += entries.mid( index, delim_pos - index + 1 );
280 index = delim_pos + 1;
282 if( entry.isEmpty() ) continue;
284 if( !b_quotes_mode && entry.endsWith( "\"" ) )
286 /* Enters quotes mode */
287 entry.truncate( entry.size() - 1 );
288 b_quotes_mode = true;
290 else if( b_quotes_mode && entry.endsWith( "\"" ) )
292 /* Finished the quotes mode */
293 entry.truncate( entry.size() - 1 );
294 b_quotes_mode = false;
296 else if( !b_quotes_mode && !entry.endsWith( "\"" ) )
298 /* we found a non-quoted standalone string */
299 if( index < entries.size() ||
300 entry.endsWith( " " ) || entry.endsWith( "\t" ) ||
301 entry.endsWith( "\r" ) || entry.endsWith( "\n" ) )
302 entry.truncate( entry.size() - 1 );
303 if( !entry.isEmpty() ) entries_array.append( entry );
310 if( !entry.isEmpty() ) entries_array.append( entry );
312 return entries_array;