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 Slave input widgets */
62 ui.slaveLabel->hide();
64 ui.slaveBrowseButton->hide();
66 /* Hide the advancedPanel */
67 if(! config_GetInt( p_intf, "qt-adv-options") )
68 ui.advancedFrame->hide();
70 ui.advancedCheckBox->setCheckState( Qt::Checked );
72 /* Buttons Creation */
73 QSizePolicy buttonSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
74 buttonSizePolicy.setHorizontalStretch(0);
75 buttonSizePolicy.setVerticalStretch(0);
78 playButton = new QToolButton( this );
79 playButton->setText( qtr( "&Play" ) );
80 playButton->setSizePolicy( buttonSizePolicy );
81 playButton->setMinimumSize( QSize(90, 0) );
82 playButton->setPopupMode( QToolButton::MenuButtonPopup );
83 playButton->setToolButtonStyle( Qt::ToolButtonTextOnly );
86 cancelButton = new QPushButton();
87 cancelButton->setText( qtr( "&Cancel" ) );
88 cancelButton->setSizePolicy( buttonSizePolicy );
90 /* Menu for the Play button */
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, updateMRL(QString) );
114 CONNECT( fileOpenPanel, methodChanged( QString ),
115 this, newMethod(QString) );
116 CONNECT( netOpenPanel, methodChanged( QString ),
117 this, newMethod(QString) );
118 CONNECT( discOpenPanel, methodChanged( QString ),
119 this, newMethod(QString) );
120 CONNECT( captureOpenPanel, methodChanged( QString ),
121 this, newMethod(QString) );
123 /* Advanced frame Connects */
124 CONNECT( ui.slaveText, textChanged(QString), this, updateMRL());
125 CONNECT( ui.cacheSpinBox, valueChanged(int), this, updateMRL());
126 CONNECT( ui.startTimeSpinBox, valueChanged(int), this, updateMRL());
127 BUTTONACT( ui.advancedCheckBox , toggleAdvancedPanel() );
130 BUTTONACT( playButton, play());
131 BUTTONACT( cancelButton, cancel());
133 /* At creation time, modify the default buttons */
134 if ( i_action_flag ) setMenuAction();
136 /* Initialize caching */
138 newMethod("file-caching");
140 mainHeight = advHeight = 0;
143 OpenDialog::~OpenDialog()
147 /* Finish the dialog and decide if you open another one after */
148 void OpenDialog::setMenuAction()
150 switch ( i_action_flag )
152 case OPEN_AND_STREAM:
153 playButton->setText( qtr("&Stream") );
154 BUTTONACT( playButton, stream() );
157 playButton->setText( qtr("&Convert / Save") );
158 BUTTONACT( playButton, transcode() );
160 case OPEN_AND_ENQUEUE:
161 playButton->setText( qtr("&Enqueue") );
162 BUTTONACT( playButton, enqueue() );
166 playButton->setText( qtr("&Play") );
167 BUTTONACT( playButton, play() );
171 void OpenDialog::showTab( int i_tab=0 )
174 ui.Tab->setCurrentIndex( i_tab );
177 void OpenDialog::signalCurrent() {
178 if (ui.Tab->currentWidget() != NULL)
179 (dynamic_cast<OpenPanel *>( ui.Tab->currentWidget() ))->updateMRL();
186 /* If Cancel is pressed or escaped */
187 void OpenDialog::cancel()
189 fileOpenPanel->clear();
190 this->toggleVisible();
191 if( isModal() ) reject();
194 /* If EnterKey is pressed */
195 void OpenDialog::close()
198 if ( !i_action_flag )
209 void OpenDialog::play()
214 void OpenDialog::enqueue()
219 void OpenDialog::transcode()
224 void OpenDialog::stream( bool b_transcode_only )
226 /* not finished FIXME */
227 /* Should go through the finish function */
228 THEDP->streamingDialog( mrl, b_transcode_only );
231 void OpenDialog::finish( bool b_enqueue = false )
233 this->toggleVisible();
234 mrl = ui.advancedLineInput->text();
238 QStringList tempMRL = SeparateEntries( mrl );
239 for( size_t i = 0; i < tempMRL.size(); i++ )
241 bool b_start = !i && !b_enqueue;
242 input_item_t *p_input;
243 const char *psz_utf8 = qtu( tempMRL[i] );
245 p_input = input_ItemNew( p_intf, psz_utf8, NULL );
248 while( i + 1 < tempMRL.size() && tempMRL[i + 1].startsWith( ":" ) )
251 psz_utf8 = qtu( tempMRL[i] );
252 input_ItemAddOption( p_input, psz_utf8 );
257 playlist_AddInput( THEPL, p_input,
258 PLAYLIST_APPEND | PLAYLIST_GO,
259 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
263 playlist_AddInput( THEPL, p_input,
264 PLAYLIST_APPEND|PLAYLIST_PREPARSE,
265 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
273 void OpenDialog::toggleAdvancedPanel()
275 //FIXME does not work under Windows
276 if( ui.advancedFrame->isVisible() ) {
277 ui.advancedFrame->hide();
280 resize( width(), mainHeight );
284 if( mainHeight == 0 )
285 mainHeight = height();
288 ui.advancedFrame->show();
290 if( advHeight == 0 ) {
291 advHeight = height() - mainHeight;
293 resize( width(), mainHeight + advHeight );
298 void OpenDialog::updateMRL() {
300 if( ui.slaveCheckbox->isChecked() ) {
301 mrl += " :input-slave=" + ui.slaveText->text();
303 int i_cache = config_GetInt( p_intf, qta(storedMethod) );
304 if( i_cache != ui.cacheSpinBox->value() ) {
305 mrl += QString(" :%1=%2").arg(storedMethod).
306 arg(ui.cacheSpinBox->value());
308 if( ui.startTimeSpinBox->value()) {
309 mrl += " :start-time=" + QString("%1").
310 arg(ui.startTimeSpinBox->value());
312 ui.advancedLineInput->setText(mrl);
315 void OpenDialog::updateMRL(QString tempMRL)
321 void OpenDialog::newMethod(QString method)
323 if( method != storedMethod ) {
324 storedMethod = method;
325 int i_value = config_GetInt( p_intf, qta(storedMethod) );
326 ui.cacheSpinBox->setValue(i_value);
330 QStringList OpenDialog::SeparateEntries( QString entries )
332 bool b_quotes_mode = false;
334 QStringList entries_array;
338 while( index < entries.size() )
340 int delim_pos = entries.indexOf( QRegExp( "\\s+|\"" ), index );
341 if( delim_pos < 0 ) delim_pos = entries.size() - 1;
342 entry += entries.mid( index, delim_pos - index + 1 );
343 index = delim_pos + 1;
345 if( entry.isEmpty() ) continue;
347 if( !b_quotes_mode && entry.endsWith( "\"" ) )
349 /* Enters quotes mode */
350 entry.truncate( entry.size() - 1 );
351 b_quotes_mode = true;
353 else if( b_quotes_mode && entry.endsWith( "\"" ) )
355 /* Finished the quotes mode */
356 entry.truncate( entry.size() - 1 );
357 b_quotes_mode = false;
359 else if( !b_quotes_mode && !entry.endsWith( "\"" ) )
361 /* we found a non-quoted standalone string */
362 if( index < entries.size() ||
363 entry.endsWith( " " ) || entry.endsWith( "\t" ) ||
364 entry.endsWith( "\r" ) || entry.endsWith( "\n" ) )
365 entry.truncate( entry.size() - 1 );
366 if( !entry.isEmpty() ) entries_array.append( entry );
373 if( !entry.isEmpty() ) entries_array.append( entry );
375 return entries_array;