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());
114 BUTTONACT( playButton, play());
115 BUTTONACT( cancelButton, cancel());
117 if ( b_stream_after ) setAfter();
119 BUTTONACT( ui.advancedCheckBox , toggleAdvancedPanel() );
121 /* Initialize caching */
123 newMethod("file-caching");
125 mainHeight = advHeight = 0;
128 OpenDialog::~OpenDialog()
132 void OpenDialog::setAfter()
134 if (!b_stream_after )
136 playButton->setText( qtr("&Play") );
137 BUTTONACT( playButton, play() );
141 playButton->setText( qtr("&Stream") );
142 BUTTONACT( playButton, stream() );
146 void OpenDialog::showTab(int i_tab=0)
149 ui.Tab->setCurrentIndex(i_tab);
152 void OpenDialog::signalCurrent() {
153 if (ui.Tab->currentWidget() != NULL) {
154 (dynamic_cast<OpenPanel*>(ui.Tab->currentWidget()))->updateMRL();
162 /* If Cancel is pressed or escaped */
163 void OpenDialog::cancel()
165 fileOpenPanel->clear();
166 this->toggleVisible();
171 /* If EnterKey is pressed */
172 void OpenDialog::close()
174 if ( !b_stream_after )
185 void OpenDialog::play()
187 playOrEnqueue( false );
190 void OpenDialog::enqueue()
192 playOrEnqueue( true );
195 void OpenDialog::stream()
197 /* not finished FIXME */
198 THEDP->streamingDialog( mrl );
202 void OpenDialog::playOrEnqueue( bool b_enqueue = false )
204 this->toggleVisible();
205 mrl = ui.advancedLineInput->text();
209 QStringList tempMRL = SeparateEntries( mrl );
210 for( size_t i = 0; i < tempMRL.size(); i++ )
212 bool b_start = !i && !b_enqueue;
213 input_item_t *p_input;
214 const char *psz_utf8 = qtu( tempMRL[i] );
216 p_input = input_ItemNew( p_intf, psz_utf8, NULL );
219 while( i + 1 < tempMRL.size() && tempMRL[i + 1].startsWith( ":" ) )
222 psz_utf8 = qtu( tempMRL[i] );
223 input_ItemAddOption( p_input, psz_utf8 );
228 playlist_AddInput( THEPL, p_input,
229 PLAYLIST_APPEND | PLAYLIST_GO,
230 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
234 playlist_AddInput( THEPL, p_input,
235 PLAYLIST_APPEND|PLAYLIST_PREPARSE,
236 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
244 void OpenDialog::toggleAdvancedPanel()
246 //FIXME does not work under Windows
247 if (ui.advancedFrame->isVisible()) {
248 ui.advancedFrame->hide();
250 resize( width(), mainHeight );
253 if( mainHeight == 0 )
254 mainHeight = height();
256 ui.advancedFrame->show();
257 if( advHeight == 0 ) {
258 advHeight = height() - mainHeight;
260 resize( width(), mainHeight + advHeight );
264 void OpenDialog::updateMRL() {
266 if( ui.slaveCheckbox->isChecked() ) {
267 mrl += " :input-slave=" + ui.slaveText->text();
269 int i_cache = config_GetInt( p_intf, qta(storedMethod) );
270 if( i_cache != ui.cacheSpinBox->value() ) {
271 mrl += QString(" :%1=%2").arg(storedMethod).
272 arg(ui.cacheSpinBox->value());
274 ui.advancedLineInput->setText(mrl);
277 void OpenDialog::updateMRL(QString tempMRL)
283 void OpenDialog::newMethod(QString method)
285 if( method != storedMethod ) {
286 storedMethod = method;
287 int i_value = config_GetInt( p_intf, qta(storedMethod) );
288 ui.cacheSpinBox->setValue(i_value);
292 QStringList OpenDialog::SeparateEntries( QString entries )
294 bool b_quotes_mode = false;
296 QStringList entries_array;
300 while( index < entries.size() )
302 int delim_pos = entries.indexOf( QRegExp( "\\s+|\"" ), index );
303 if( delim_pos < 0 ) delim_pos = entries.size() - 1;
304 entry += entries.mid( index, delim_pos - index + 1 );
305 index = delim_pos + 1;
307 if( entry.isEmpty() ) continue;
309 if( !b_quotes_mode && entry.endsWith( "\"" ) )
311 /* Enters quotes mode */
312 entry.truncate( entry.size() - 1 );
313 b_quotes_mode = true;
315 else if( b_quotes_mode && entry.endsWith( "\"" ) )
317 /* Finished the quotes mode */
318 entry.truncate( entry.size() - 1 );
319 b_quotes_mode = false;
321 else if( !b_quotes_mode && !entry.endsWith( "\"" ) )
323 /* we found a non-quoted standalone string */
324 if( index < entries.size() ||
325 entry.endsWith( " " ) || entry.endsWith( "\t" ) ||
326 entry.endsWith( "\r" ) || entry.endsWith( "\n" ) )
327 entry.truncate( entry.size() - 1 );
328 if( !entry.isEmpty() ) entries_array.append( entry );
335 if( !entry.isEmpty() ) entries_array.append( entry );
337 return entries_array;