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 /* Tab definition and creation */
51 fileOpenPanel = new FileOpenPanel( ui.Tab , p_intf );
52 diskOpenPanel = new DiskOpenPanel( ui.Tab , p_intf );
53 netOpenPanel = new NetOpenPanel( ui.Tab , p_intf );
54 captureOpenPanel = new CaptureOpenPanel( ui.Tab, p_intf );
56 ui.Tab->addTab( fileOpenPanel, qtr( "&File" ) );
57 ui.Tab->addTab( diskOpenPanel, qtr( "&Disc" ) );
58 ui.Tab->addTab( netOpenPanel, qtr( "&Network" ) );
59 ui.Tab->addTab( captureOpenPanel, qtr( "Capture &Device" ) );
61 /* Hide the advancedPanel */
62 ui.advancedFrame->hide();
64 /* Buttons Creation */
65 QSizePolicy buttonSizePolicy(static_cast<QSizePolicy::Policy>(7), static_cast<QSizePolicy::Policy>(1));
66 buttonSizePolicy.setHorizontalStretch(0);
67 buttonSizePolicy.setVerticalStretch(0);
69 playButton = new QToolButton();
70 playButton->setText( qtr( "&Play" ) );
71 playButton->setSizePolicy( buttonSizePolicy );
72 playButton->setMinimumSize(QSize(90, 0));
73 playButton->setPopupMode(QToolButton::MenuButtonPopup);
74 playButton->setToolButtonStyle(Qt::ToolButtonTextOnly);
76 cancelButton = new QToolButton();
77 cancelButton->setText( qtr( "&Cancel" ) );
78 cancelButton->setSizePolicy( buttonSizePolicy );
80 QMenu * openButtonMenu = new QMenu( "Open" );
81 openButtonMenu->addAction( qtr("&Enqueue"), this, SLOT( enqueue() ),
82 QKeySequence( "Alt+E") );
83 openButtonMenu->addAction( qtr("&Play"), this, SLOT( play() ),
84 QKeySequence( "Alt+P" ) );
85 openButtonMenu->addAction( qtr("&Stream"), this, SLOT( stream() ) ,
86 QKeySequence( "Alt+S" ) );
88 playButton->setMenu( openButtonMenu );
90 ui.buttonsBox->addButton( playButton, QDialogButtonBox::AcceptRole );
91 ui.buttonsBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
94 /* Force MRL update on tab change */
95 CONNECT( ui.Tab, currentChanged(int), this, signalCurrent());
97 CONNECT( fileOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
98 CONNECT( netOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
99 CONNECT( diskOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
100 CONNECT( captureOpenPanel, mrlUpdated( QString ), this,
101 updateMRL(QString) );
103 CONNECT( fileOpenPanel, methodChanged( QString ),
104 this, newMethod(QString) );
105 CONNECT( netOpenPanel, methodChanged( QString ),
106 this, newMethod(QString) );
107 CONNECT( diskOpenPanel, methodChanged( QString ),
108 this, newMethod(QString) );
110 CONNECT( ui.slaveText, textChanged(QString), this, updateMRL());
111 CONNECT( ui.cacheSpinBox, valueChanged(int), this, updateMRL());
112 CONNECT( ui.startTimeSpinBox, valueChanged(int), this, updateMRL());
115 BUTTONACT( playButton, play());
116 BUTTONACT( cancelButton, cancel());
118 if ( b_stream_after ) setAfter();
120 BUTTONACT( ui.advancedCheckBox , toggleAdvancedPanel() );
122 /* Initialize caching */
124 newMethod("file-caching");
126 mainHeight = advHeight = 0;
129 OpenDialog::~OpenDialog()
133 void OpenDialog::setAfter()
135 if (!b_stream_after )
137 playButton->setText( qtr("&Play") );
138 BUTTONACT( playButton, play() );
142 playButton->setText( qtr("&Stream") );
143 BUTTONACT( playButton, stream() );
147 void OpenDialog::showTab(int i_tab=0)
150 ui.Tab->setCurrentIndex(i_tab);
153 void OpenDialog::signalCurrent() {
154 if (ui.Tab->currentWidget() != NULL) {
155 (dynamic_cast<OpenPanel*>(ui.Tab->currentWidget()))->updateMRL();
163 /* If Cancel is pressed or escaped */
164 void OpenDialog::cancel()
166 fileOpenPanel->clear();
167 this->toggleVisible();
172 /* If EnterKey is pressed */
173 void OpenDialog::close()
175 if ( !b_stream_after )
186 void OpenDialog::play()
188 playOrEnqueue( false );
191 void OpenDialog::enqueue()
193 playOrEnqueue( true );
196 void OpenDialog::stream()
198 /* not finished FIXME */
199 THEDP->streamingDialog( mrl );
203 void OpenDialog::playOrEnqueue( bool b_enqueue = false )
205 this->toggleVisible();
206 mrl = ui.advancedLineInput->text();
210 QStringList tempMRL = SeparateEntries( mrl );
211 for( size_t i = 0; i < tempMRL.size(); i++ )
213 bool b_start = !i && !b_enqueue;
214 input_item_t *p_input;
215 const char *psz_utf8 = qtu( tempMRL[i] );
217 p_input = input_ItemNew( p_intf, psz_utf8, NULL );
220 while( i + 1 < tempMRL.size() && tempMRL[i + 1].startsWith( ":" ) )
223 psz_utf8 = qtu( tempMRL[i] );
224 input_ItemAddOption( p_input, psz_utf8 );
229 playlist_AddInput( THEPL, p_input,
230 PLAYLIST_APPEND | PLAYLIST_GO,
231 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
235 playlist_AddInput( THEPL, p_input,
236 PLAYLIST_APPEND|PLAYLIST_PREPARSE,
237 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
245 void OpenDialog::toggleAdvancedPanel()
247 //FIXME does not work under Windows
248 if (ui.advancedFrame->isVisible()) {
249 ui.advancedFrame->hide();
251 resize( width(), mainHeight );
254 if( mainHeight == 0 )
255 mainHeight = height();
257 ui.advancedFrame->show();
258 if( advHeight == 0 ) {
259 advHeight = height() - mainHeight;
261 resize( width(), mainHeight + advHeight );
265 void OpenDialog::updateMRL() {
267 if( ui.slaveCheckbox->isChecked() ) {
268 mrl += " :input-slave=" + ui.slaveText->text();
270 int i_cache = config_GetInt( p_intf, qta(storedMethod) );
271 if( i_cache != ui.cacheSpinBox->value() ) {
272 mrl += QString(" :%1=%2").arg(storedMethod).
273 arg(ui.cacheSpinBox->value());
275 if( ui.startTimeSpinBox->value()) {
276 mrl += " :start-time=" + QString("%1").
277 arg(ui.startTimeSpinBox->value());
279 ui.advancedLineInput->setText(mrl);
282 void OpenDialog::updateMRL(QString tempMRL)
288 void OpenDialog::newMethod(QString method)
290 if( method != storedMethod ) {
291 storedMethod = method;
292 int i_value = config_GetInt( p_intf, qta(storedMethod) );
293 ui.cacheSpinBox->setValue(i_value);
297 QStringList OpenDialog::SeparateEntries( QString entries )
299 bool b_quotes_mode = false;
301 QStringList entries_array;
305 while( index < entries.size() )
307 int delim_pos = entries.indexOf( QRegExp( "\\s+|\"" ), index );
308 if( delim_pos < 0 ) delim_pos = entries.size() - 1;
309 entry += entries.mid( index, delim_pos - index + 1 );
310 index = delim_pos + 1;
312 if( entry.isEmpty() ) continue;
314 if( !b_quotes_mode && entry.endsWith( "\"" ) )
316 /* Enters quotes mode */
317 entry.truncate( entry.size() - 1 );
318 b_quotes_mode = true;
320 else if( b_quotes_mode && entry.endsWith( "\"" ) )
322 /* Finished the quotes mode */
323 entry.truncate( entry.size() - 1 );
324 b_quotes_mode = false;
326 else if( !b_quotes_mode && !entry.endsWith( "\"" ) )
328 /* we found a non-quoted standalone string */
329 if( index < entries.size() ||
330 entry.endsWith( " " ) || entry.endsWith( "\t" ) ||
331 entry.endsWith( "\r" ) || entry.endsWith( "\n" ) )
332 entry.truncate( entry.size() - 1 );
333 if( !entry.isEmpty() ) entries_array.append( entry );
340 if( !entry.isEmpty() ) entries_array.append( entry );
342 return entries_array;