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 discOpenPanel = new DiscOpenPanel( ui.Tab, p_intf );
53 netOpenPanel = new NetOpenPanel( ui.Tab, p_intf );
54 captureOpenPanel = new CaptureOpenPanel( ui.Tab, p_intf );
56 ui.Tab->insertTab( OPEN_FILE_TAB, fileOpenPanel, qtr( "&File" ) );
57 ui.Tab->insertTab( OPEN_DISC_TAB, discOpenPanel, qtr( "&Disc" ) );
58 ui.Tab->insertTab( OPEN_NETWORK_TAB, netOpenPanel, qtr( "&Network" ) );
59 ui.Tab->insertTab( OPEN_CAPTURE_TAB, captureOpenPanel,
60 qtr( "Capture &Device" ) );
62 /* Hide the advancedPanel */
63 ui.advancedFrame->hide();
65 /* Buttons Creation */
66 QSizePolicy buttonSizePolicy( static_cast<QSizePolicy::Policy>(7),
67 static_cast<QSizePolicy::Policy>(1) );
68 buttonSizePolicy.setHorizontalStretch(0);
69 buttonSizePolicy.setVerticalStretch(0);
71 playButton = new QToolButton();
72 playButton->setText( qtr( "&Play" ) );
73 playButton->setSizePolicy( buttonSizePolicy );
74 playButton->setMinimumSize( QSize(90, 0) );
75 playButton->setPopupMode( QToolButton::MenuButtonPopup );
76 playButton->setToolButtonStyle( Qt::ToolButtonTextOnly );
78 cancelButton = new QToolButton();
79 cancelButton->setText( qtr( "&Cancel" ) );
80 cancelButton->setSizePolicy( buttonSizePolicy );
82 QMenu * openButtonMenu = new QMenu( "Open" );
83 openButtonMenu->addAction( qtr("&Enqueue"), this, SLOT( enqueue() ),
84 QKeySequence( "Alt+E") );
85 openButtonMenu->addAction( qtr("&Play"), this, SLOT( play() ),
86 QKeySequence( "Alt+P" ) );
87 openButtonMenu->addAction( qtr("&Stream"), this, SLOT( stream() ) ,
88 QKeySequence( "Alt+S" ) );
90 playButton->setMenu( openButtonMenu );
92 ui.buttonsBox->addButton( playButton, QDialogButtonBox::AcceptRole );
93 ui.buttonsBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
96 /* Force MRL update on tab change */
97 CONNECT( ui.Tab, currentChanged(int), this, signalCurrent());
99 CONNECT( fileOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
100 CONNECT( netOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
101 CONNECT( discOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
102 CONNECT( captureOpenPanel, mrlUpdated( QString ), this,
103 updateMRL(QString) );
105 CONNECT( fileOpenPanel, methodChanged( QString ),
106 this, newMethod(QString) );
107 CONNECT( netOpenPanel, methodChanged( QString ),
108 this, newMethod(QString) );
109 CONNECT( discOpenPanel, methodChanged( QString ),
110 this, newMethod(QString) );
112 CONNECT( ui.slaveText, textChanged(QString), this, updateMRL());
113 CONNECT( ui.cacheSpinBox, valueChanged(int), this, updateMRL());
114 CONNECT( ui.startTimeSpinBox, valueChanged(int), this, updateMRL());
117 BUTTONACT( playButton, play());
118 BUTTONACT( cancelButton, cancel());
120 if ( b_stream_after ) setAfter();
122 BUTTONACT( ui.advancedCheckBox , toggleAdvancedPanel() );
124 /* Initialize caching */
126 newMethod("file-caching");
128 mainHeight = advHeight = 0;
131 OpenDialog::~OpenDialog()
135 void OpenDialog::setAfter()
137 if (!b_stream_after )
139 playButton->setText( qtr("&Play") );
140 BUTTONACT( playButton, play() );
144 playButton->setText( qtr("&Stream") );
145 BUTTONACT( playButton, stream() );
149 void OpenDialog::showTab(int i_tab=0)
152 ui.Tab->setCurrentIndex(i_tab);
155 void OpenDialog::signalCurrent() {
156 if (ui.Tab->currentWidget() != NULL) {
157 (dynamic_cast<OpenPanel*>(ui.Tab->currentWidget()))->updateMRL();
165 /* If Cancel is pressed or escaped */
166 void OpenDialog::cancel()
168 fileOpenPanel->clear();
169 this->toggleVisible();
174 /* If EnterKey is pressed */
175 void OpenDialog::close()
177 if ( !b_stream_after )
188 void OpenDialog::play()
190 playOrEnqueue( false );
193 void OpenDialog::enqueue()
195 playOrEnqueue( true );
198 void OpenDialog::stream()
200 /* not finished FIXME */
201 THEDP->streamingDialog( mrl );
205 void OpenDialog::playOrEnqueue( bool b_enqueue = false )
207 this->toggleVisible();
208 mrl = ui.advancedLineInput->text();
212 QStringList tempMRL = SeparateEntries( mrl );
213 for( size_t i = 0; i < tempMRL.size(); i++ )
215 bool b_start = !i && !b_enqueue;
216 input_item_t *p_input;
217 const char *psz_utf8 = qtu( tempMRL[i] );
219 p_input = input_ItemNew( p_intf, psz_utf8, NULL );
222 while( i + 1 < tempMRL.size() && tempMRL[i + 1].startsWith( ":" ) )
225 psz_utf8 = qtu( tempMRL[i] );
226 input_ItemAddOption( p_input, psz_utf8 );
231 playlist_AddInput( THEPL, p_input,
232 PLAYLIST_APPEND | PLAYLIST_GO,
233 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
237 playlist_AddInput( THEPL, p_input,
238 PLAYLIST_APPEND|PLAYLIST_PREPARSE,
239 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
247 void OpenDialog::toggleAdvancedPanel()
249 //FIXME does not work under Windows
250 if (ui.advancedFrame->isVisible()) {
251 ui.advancedFrame->hide();
253 resize( width(), mainHeight );
256 if( mainHeight == 0 )
257 mainHeight = height();
259 ui.advancedFrame->show();
260 if( advHeight == 0 ) {
261 advHeight = height() - mainHeight;
263 resize( width(), mainHeight + advHeight );
267 void OpenDialog::updateMRL() {
269 if( ui.slaveCheckbox->isChecked() ) {
270 mrl += " :input-slave=" + ui.slaveText->text();
272 int i_cache = config_GetInt( p_intf, qta(storedMethod) );
273 if( i_cache != ui.cacheSpinBox->value() ) {
274 mrl += QString(" :%1=%2").arg(storedMethod).
275 arg(ui.cacheSpinBox->value());
277 if( ui.startTimeSpinBox->value()) {
278 mrl += " :start-time=" + QString("%1").
279 arg(ui.startTimeSpinBox->value());
281 ui.advancedLineInput->setText(mrl);
284 void OpenDialog::updateMRL(QString tempMRL)
290 void OpenDialog::newMethod(QString method)
292 if( method != storedMethod ) {
293 storedMethod = method;
294 int i_value = config_GetInt( p_intf, qta(storedMethod) );
295 ui.cacheSpinBox->setValue(i_value);
299 QStringList OpenDialog::SeparateEntries( QString entries )
301 bool b_quotes_mode = false;
303 QStringList entries_array;
307 while( index < entries.size() )
309 int delim_pos = entries.indexOf( QRegExp( "\\s+|\"" ), index );
310 if( delim_pos < 0 ) delim_pos = entries.size() - 1;
311 entry += entries.mid( index, delim_pos - index + 1 );
312 index = delim_pos + 1;
314 if( entry.isEmpty() ) continue;
316 if( !b_quotes_mode && entry.endsWith( "\"" ) )
318 /* Enters quotes mode */
319 entry.truncate( entry.size() - 1 );
320 b_quotes_mode = true;
322 else if( b_quotes_mode && entry.endsWith( "\"" ) )
324 /* Finished the quotes mode */
325 entry.truncate( entry.size() - 1 );
326 b_quotes_mode = false;
328 else if( !b_quotes_mode && !entry.endsWith( "\"" ) )
330 /* we found a non-quoted standalone string */
331 if( index < entries.size() ||
332 entry.endsWith( " " ) || entry.endsWith( "\t" ) ||
333 entry.endsWith( "\r" ) || entry.endsWith( "\n" ) )
334 entry.truncate( entry.size() - 1 );
335 if( !entry.isEmpty() ) entries_array.append( entry );
342 if( !entry.isEmpty() ) entries_array.append( entry );
344 return entries_array;