1 /*****************************************************************************
2 * open.cpp : Advanced open dialog
3 *****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
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 *****************************************************************************/
24 #include "input_manager.hpp"
26 #include "dialogs/open.hpp"
27 #include "components/open.hpp"
30 #include <QGridLayout>
31 #include <QFileDialog>
35 OpenDialog *OpenDialog::instance = NULL;
37 OpenDialog::OpenDialog( QWidget *parent, intf_thread_t *_p_intf, bool modal,
38 int _action_flag ) : QVLCDialog( parent, _p_intf )
41 i_action_flag = _action_flag;
43 /* Basic Creation of the Window */
45 setWindowTitle( qtr("Open" ) );
48 /* Tab definition and creation */
49 fileOpenPanel = new FileOpenPanel( ui.Tab, p_intf );
50 discOpenPanel = new DiscOpenPanel( ui.Tab, p_intf );
51 netOpenPanel = new NetOpenPanel( ui.Tab, p_intf );
52 captureOpenPanel = new CaptureOpenPanel( ui.Tab, p_intf );
55 ui.Tab->insertTab( OPEN_FILE_TAB, fileOpenPanel, qtr( "&File" ) );
56 ui.Tab->insertTab( OPEN_DISC_TAB, discOpenPanel, qtr( "&Disc" ) );
57 ui.Tab->insertTab( OPEN_NETWORK_TAB, netOpenPanel, qtr( "&Network" ) );
58 ui.Tab->insertTab( OPEN_CAPTURE_TAB, captureOpenPanel,
59 qtr( "Capture &Device" ) );
61 /* Hide the advancedPanel */
62 if(! config_GetInt( p_intf, "qt-adv-options") )
64 ui.advancedFrame->hide();
68 ui.advancedCheckBox->setCheckState( Qt::Checked );
71 ui.slaveLabel->hide();
73 ui.slaveBrowseButton->hide();
75 /* Buttons Creation */
76 QSizePolicy buttonSizePolicy( static_cast<QSizePolicy::Policy>(7),
77 static_cast<QSizePolicy::Policy>(1) );
78 buttonSizePolicy.setHorizontalStretch(0);
79 buttonSizePolicy.setVerticalStretch(0);
81 playButton = new QToolButton( this );
82 playButton->setText( qtr( "&Play" ) );
83 playButton->setSizePolicy( buttonSizePolicy );
84 playButton->setMinimumSize( QSize(90, 0) );
85 playButton->setPopupMode( QToolButton::MenuButtonPopup );
86 playButton->setToolButtonStyle( Qt::ToolButtonTextOnly );
88 cancelButton = new QPushButton();
89 cancelButton->setText( qtr( "&Cancel" ) );
90 cancelButton->setSizePolicy( buttonSizePolicy );
92 QMenu * openButtonMenu = new QMenu( "Open" );
93 openButtonMenu->addAction( qtr("&Enqueue"), this, SLOT( enqueue() ),
94 QKeySequence( "Alt+E") );
95 openButtonMenu->addAction( qtr("&Play"), this, SLOT( play() ),
96 QKeySequence( "Alt+P" ) );
97 openButtonMenu->addAction( qtr("&Stream"), this, SLOT( stream() ) ,
98 QKeySequence( "Alt+S" ) );
99 openButtonMenu->addAction( qtr("&Convert"), this, SLOT( transcode() ) ,
100 QKeySequence( "Alt+C" ) );
102 playButton->setMenu( openButtonMenu );
104 ui.buttonsBox->addButton( playButton, QDialogButtonBox::AcceptRole );
105 ui.buttonsBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
107 /* Force MRL update on tab change */
108 CONNECT( ui.Tab, currentChanged(int), this, signalCurrent());
110 CONNECT( fileOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
111 CONNECT( netOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
112 CONNECT( discOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
113 CONNECT( captureOpenPanel, mrlUpdated( QString ), this,
114 updateMRL(QString) );
116 CONNECT( fileOpenPanel, methodChanged( QString ),
117 this, newMethod(QString) );
118 CONNECT( netOpenPanel, methodChanged( QString ),
119 this, newMethod(QString) );
120 CONNECT( discOpenPanel, methodChanged( QString ),
121 this, newMethod(QString) );
122 CONNECT( captureOpenPanel, methodChanged( QString ),
123 this, newMethod(QString) );
125 /* Advanced frame Connects */
126 CONNECT( ui.slaveText, textChanged(QString), this, updateMRL());
127 CONNECT( ui.cacheSpinBox, valueChanged(int), this, updateMRL());
128 CONNECT( ui.startTimeSpinBox, valueChanged(int), this, updateMRL());
129 BUTTONACT( ui.advancedCheckBox , toggleAdvancedPanel() );
132 BUTTONACT( playButton, play());
133 BUTTONACT( cancelButton, cancel());
135 /* At creation time, modify the default buttons */
136 if ( i_action_flag ) setMenuAction();
139 /* Initialize caching */
141 newMethod("file-caching");
143 mainHeight = advHeight = 0;
146 OpenDialog::~OpenDialog()
150 /* Finish the dialog and decide if you open another one after */
151 void OpenDialog::setMenuAction()
153 switch ( i_action_flag )
155 case OPEN_AND_STREAM:
156 playButton->setText( qtr("&Stream") );
157 BUTTONACT( playButton, stream() );
160 playButton->setText( qtr("&Convert / Save") );
161 BUTTONACT( playButton, transcode() );
164 playButton->setText( qtr("&Enqueue") );
165 BUTTONACT( playButton, enqueue() );
169 playButton->setText( qtr("&Play") );
170 BUTTONACT( playButton, play() );
174 void OpenDialog::showTab(int i_tab=0)
177 ui.Tab->setCurrentIndex(i_tab);
180 void OpenDialog::signalCurrent() {
181 if (ui.Tab->currentWidget() != NULL) {
182 (dynamic_cast<OpenPanel*>(ui.Tab->currentWidget()))->updateMRL();
190 /* If Cancel is pressed or escaped */
191 void OpenDialog::cancel()
193 fileOpenPanel->clear();
194 this->toggleVisible();
199 /* If EnterKey is pressed */
200 void OpenDialog::close()
203 if ( !i_action_flag )
214 void OpenDialog::play()
219 void OpenDialog::enqueue()
224 void OpenDialog::transcode()
229 void OpenDialog::stream( bool b_transcode_only )
231 /* not finished FIXME */
232 /* Should go through the finish function */
233 THEDP->streamingDialog( mrl, b_transcode_only );
236 void OpenDialog::finish( bool b_enqueue = false )
238 this->toggleVisible();
239 mrl = ui.advancedLineInput->text();
243 QStringList tempMRL = SeparateEntries( mrl );
244 for( size_t i = 0; i < tempMRL.size(); i++ )
246 bool b_start = !i && !b_enqueue;
247 input_item_t *p_input;
248 const char *psz_utf8 = qtu( tempMRL[i] );
250 p_input = input_ItemNew( p_intf, psz_utf8, NULL );
253 while( i + 1 < tempMRL.size() && tempMRL[i + 1].startsWith( ":" ) )
256 psz_utf8 = qtu( tempMRL[i] );
257 input_ItemAddOption( p_input, psz_utf8 );
262 playlist_AddInput( THEPL, p_input,
263 PLAYLIST_APPEND | PLAYLIST_GO,
264 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
268 playlist_AddInput( THEPL, p_input,
269 PLAYLIST_APPEND|PLAYLIST_PREPARSE,
270 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
278 void OpenDialog::toggleAdvancedPanel()
280 //FIXME does not work under Windows
281 if( ui.advancedFrame->isVisible() ) {
282 ui.advancedFrame->hide();
285 resize( width(), mainHeight );
289 if( mainHeight == 0 )
290 mainHeight = height();
293 ui.advancedFrame->show();
295 if( advHeight == 0 ) {
296 advHeight = height() - mainHeight;
298 resize( width(), mainHeight + advHeight );
303 void OpenDialog::updateMRL() {
305 if( ui.slaveCheckbox->isChecked() ) {
306 mrl += " :input-slave=" + ui.slaveText->text();
308 int i_cache = config_GetInt( p_intf, qta(storedMethod) );
309 if( i_cache != ui.cacheSpinBox->value() ) {
310 mrl += QString(" :%1=%2").arg(storedMethod).
311 arg(ui.cacheSpinBox->value());
313 if( ui.startTimeSpinBox->value()) {
314 mrl += " :start-time=" + QString("%1").
315 arg(ui.startTimeSpinBox->value());
317 ui.advancedLineInput->setText(mrl);
320 void OpenDialog::updateMRL(QString tempMRL)
326 void OpenDialog::newMethod(QString method)
328 if( method != storedMethod ) {
329 storedMethod = method;
330 int i_value = config_GetInt( p_intf, qta(storedMethod) );
331 ui.cacheSpinBox->setValue(i_value);
335 QStringList OpenDialog::SeparateEntries( QString entries )
337 bool b_quotes_mode = false;
339 QStringList entries_array;
343 while( index < entries.size() )
345 int delim_pos = entries.indexOf( QRegExp( "\\s+|\"" ), index );
346 if( delim_pos < 0 ) delim_pos = entries.size() - 1;
347 entry += entries.mid( index, delim_pos - index + 1 );
348 index = delim_pos + 1;
350 if( entry.isEmpty() ) continue;
352 if( !b_quotes_mode && entry.endsWith( "\"" ) )
354 /* Enters quotes mode */
355 entry.truncate( entry.size() - 1 );
356 b_quotes_mode = true;
358 else if( b_quotes_mode && entry.endsWith( "\"" ) )
360 /* Finished the quotes mode */
361 entry.truncate( entry.size() - 1 );
362 b_quotes_mode = false;
364 else if( !b_quotes_mode && !entry.endsWith( "\"" ) )
366 /* we found a non-quoted standalone string */
367 if( index < entries.size() ||
368 entry.endsWith( " " ) || entry.endsWith( "\t" ) ||
369 entry.endsWith( "\r" ) || entry.endsWith( "\n" ) )
370 entry.truncate( entry.size() - 1 );
371 if( !entry.isEmpty() ) entries_array.append( entry );
378 if( !entry.isEmpty() ) entries_array.append( entry );
380 return entries_array;