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( QSizePolicy::Expanding, QSizePolicy::GrowFlag );
77 buttonSizePolicy.setHorizontalStretch(0);
78 buttonSizePolicy.setVerticalStretch(0);
80 playButton = new QToolButton( this );
81 playButton->setText( qtr( "&Play" ) );
82 playButton->setSizePolicy( buttonSizePolicy );
83 playButton->setMinimumSize( QSize(90, 0) );
84 playButton->setPopupMode( QToolButton::MenuButtonPopup );
85 playButton->setToolButtonStyle( Qt::ToolButtonTextOnly );
87 cancelButton = new QPushButton();
88 cancelButton->setText( qtr( "&Cancel" ) );
89 cancelButton->setSizePolicy( buttonSizePolicy );
91 QMenu * openButtonMenu = new QMenu( "Open" );
92 openButtonMenu->addAction( qtr("&Enqueue"), this, SLOT( enqueue() ),
93 QKeySequence( "Alt+E") );
94 openButtonMenu->addAction( qtr("&Play"), this, SLOT( play() ),
95 QKeySequence( "Alt+P" ) );
96 openButtonMenu->addAction( qtr("&Stream"), this, SLOT( stream() ) ,
97 QKeySequence( "Alt+S" ) );
98 openButtonMenu->addAction( qtr("&Convert"), this, SLOT( transcode() ) ,
99 QKeySequence( "Alt+C" ) );
101 playButton->setMenu( openButtonMenu );
103 ui.buttonsBox->addButton( playButton, QDialogButtonBox::AcceptRole );
104 ui.buttonsBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
106 /* Force MRL update on tab change */
107 CONNECT( ui.Tab, currentChanged(int), this, signalCurrent());
109 CONNECT( fileOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
110 CONNECT( netOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
111 CONNECT( discOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
112 CONNECT( captureOpenPanel, mrlUpdated( QString ), this,
113 updateMRL(QString) );
115 CONNECT( fileOpenPanel, methodChanged( QString ),
116 this, newMethod(QString) );
117 CONNECT( netOpenPanel, methodChanged( QString ),
118 this, newMethod(QString) );
119 CONNECT( discOpenPanel, methodChanged( QString ),
120 this, newMethod(QString) );
121 CONNECT( captureOpenPanel, methodChanged( QString ),
122 this, newMethod(QString) );
124 /* Advanced frame Connects */
125 CONNECT( ui.slaveText, textChanged(QString), this, updateMRL());
126 CONNECT( ui.cacheSpinBox, valueChanged(int), this, updateMRL());
127 CONNECT( ui.startTimeSpinBox, valueChanged(int), this, updateMRL());
128 BUTTONACT( ui.advancedCheckBox , toggleAdvancedPanel() );
131 BUTTONACT( playButton, play());
132 BUTTONACT( cancelButton, cancel());
134 /* At creation time, modify the default buttons */
135 if ( i_action_flag ) setMenuAction();
138 /* Initialize caching */
140 newMethod("file-caching");
142 mainHeight = advHeight = 0;
145 OpenDialog::~OpenDialog()
149 /* Finish the dialog and decide if you open another one after */
150 void OpenDialog::setMenuAction()
152 switch ( i_action_flag )
154 case OPEN_AND_STREAM:
155 playButton->setText( qtr("&Stream") );
156 BUTTONACT( playButton, stream() );
159 playButton->setText( qtr("&Convert / Save") );
160 BUTTONACT( playButton, transcode() );
163 playButton->setText( qtr("&Enqueue") );
164 BUTTONACT( playButton, enqueue() );
168 playButton->setText( qtr("&Play") );
169 BUTTONACT( playButton, play() );
173 void OpenDialog::showTab(int i_tab=0)
176 ui.Tab->setCurrentIndex(i_tab);
179 void OpenDialog::signalCurrent() {
180 if (ui.Tab->currentWidget() != NULL) {
181 (dynamic_cast<OpenPanel*>(ui.Tab->currentWidget()))->updateMRL();
189 /* If Cancel is pressed or escaped */
190 void OpenDialog::cancel()
192 fileOpenPanel->clear();
193 this->toggleVisible();
198 /* If EnterKey is pressed */
199 void OpenDialog::close()
202 if ( !i_action_flag )
213 void OpenDialog::play()
218 void OpenDialog::enqueue()
223 void OpenDialog::transcode()
228 void OpenDialog::stream( bool b_transcode_only )
230 /* not finished FIXME */
231 /* Should go through the finish function */
232 THEDP->streamingDialog( mrl, b_transcode_only );
235 void OpenDialog::finish( bool b_enqueue = false )
237 this->toggleVisible();
238 mrl = ui.advancedLineInput->text();
242 QStringList tempMRL = SeparateEntries( mrl );
243 for( size_t i = 0; i < tempMRL.size(); i++ )
245 bool b_start = !i && !b_enqueue;
246 input_item_t *p_input;
247 const char *psz_utf8 = qtu( tempMRL[i] );
249 p_input = input_ItemNew( p_intf, psz_utf8, NULL );
252 while( i + 1 < tempMRL.size() && tempMRL[i + 1].startsWith( ":" ) )
255 psz_utf8 = qtu( tempMRL[i] );
256 input_ItemAddOption( p_input, psz_utf8 );
261 playlist_AddInput( THEPL, p_input,
262 PLAYLIST_APPEND | PLAYLIST_GO,
263 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
267 playlist_AddInput( THEPL, p_input,
268 PLAYLIST_APPEND|PLAYLIST_PREPARSE,
269 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
277 void OpenDialog::toggleAdvancedPanel()
279 //FIXME does not work under Windows
280 if( ui.advancedFrame->isVisible() ) {
281 ui.advancedFrame->hide();
284 resize( width(), mainHeight );
288 if( mainHeight == 0 )
289 mainHeight = height();
292 ui.advancedFrame->show();
294 if( advHeight == 0 ) {
295 advHeight = height() - mainHeight;
297 resize( width(), mainHeight + advHeight );
302 void OpenDialog::updateMRL() {
304 if( ui.slaveCheckbox->isChecked() ) {
305 mrl += " :input-slave=" + ui.slaveText->text();
307 int i_cache = config_GetInt( p_intf, qta(storedMethod) );
308 if( i_cache != ui.cacheSpinBox->value() ) {
309 mrl += QString(" :%1=%2").arg(storedMethod).
310 arg(ui.cacheSpinBox->value());
312 if( ui.startTimeSpinBox->value()) {
313 mrl += " :start-time=" + QString("%1").
314 arg(ui.startTimeSpinBox->value());
316 ui.advancedLineInput->setText(mrl);
319 void OpenDialog::updateMRL(QString tempMRL)
325 void OpenDialog::newMethod(QString method)
327 if( method != storedMethod ) {
328 storedMethod = method;
329 int i_value = config_GetInt( p_intf, qta(storedMethod) );
330 ui.cacheSpinBox->setValue(i_value);
334 QStringList OpenDialog::SeparateEntries( QString entries )
336 bool b_quotes_mode = false;
338 QStringList entries_array;
342 while( index < entries.size() )
344 int delim_pos = entries.indexOf( QRegExp( "\\s+|\"" ), index );
345 if( delim_pos < 0 ) delim_pos = entries.size() - 1;
346 entry += entries.mid( index, delim_pos - index + 1 );
347 index = delim_pos + 1;
349 if( entry.isEmpty() ) continue;
351 if( !b_quotes_mode && entry.endsWith( "\"" ) )
353 /* Enters quotes mode */
354 entry.truncate( entry.size() - 1 );
355 b_quotes_mode = true;
357 else if( b_quotes_mode && entry.endsWith( "\"" ) )
359 /* Finished the quotes mode */
360 entry.truncate( entry.size() - 1 );
361 b_quotes_mode = false;
363 else if( !b_quotes_mode && !entry.endsWith( "\"" ) )
365 /* we found a non-quoted standalone string */
366 if( index < entries.size() ||
367 entry.endsWith( " " ) || entry.endsWith( "\t" ) ||
368 entry.endsWith( "\r" ) || entry.endsWith( "\n" ) )
369 entry.truncate( entry.size() - 1 );
370 if( !entry.isEmpty() ) entries_array.append( entry );
377 if( !entry.isEmpty() ) entries_array.append( entry );
379 return entries_array;