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"
29 #include <QGridLayout>
30 #include <QFileDialog>
34 OpenDialog *OpenDialog::instance = NULL;
36 OpenDialog::OpenDialog( QWidget *parent, intf_thread_t *_p_intf, bool modal,
37 int _action_flag ) : QVLCDialog( parent, _p_intf )
40 i_action_flag = _action_flag;
42 /* Basic Creation of the Window */
44 setWindowTitle( qtr("Open" ) );
47 /* Tab definition and creation */
48 fileOpenPanel = new FileOpenPanel( ui.Tab, p_intf );
49 discOpenPanel = new DiscOpenPanel( ui.Tab, p_intf );
50 netOpenPanel = new NetOpenPanel( ui.Tab, p_intf );
51 captureOpenPanel = new CaptureOpenPanel( ui.Tab, p_intf );
54 ui.Tab->insertTab( OPEN_FILE_TAB, fileOpenPanel, qtr( "&File" ) );
55 ui.Tab->insertTab( OPEN_DISC_TAB, discOpenPanel, qtr( "&Disc" ) );
56 ui.Tab->insertTab( OPEN_NETWORK_TAB, netOpenPanel, qtr( "&Network" ) );
57 ui.Tab->insertTab( OPEN_CAPTURE_TAB, captureOpenPanel,
58 qtr( "Capture &Device" ) );
60 /* Hide the Slave input widgets */
61 ui.slaveLabel->hide();
63 ui.slaveBrowseButton->hide();
65 /* Hide the advancedPanel */
66 if(! config_GetInt( p_intf, "qt-adv-options") )
67 ui.advancedFrame->hide();
69 ui.advancedCheckBox->setCheckState( Qt::Checked );
71 /* Buttons Creation */
72 QSizePolicy buttonSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
73 buttonSizePolicy.setHorizontalStretch(0);
74 buttonSizePolicy.setVerticalStretch(0);
77 playButton = new QToolButton( this );
78 playButton->setText( qtr( "&Play" ) );
79 playButton->setSizePolicy( buttonSizePolicy );
80 playButton->setMinimumSize( QSize(90, 0) );
81 playButton->setPopupMode( QToolButton::MenuButtonPopup );
82 playButton->setToolButtonStyle( Qt::ToolButtonTextOnly );
85 cancelButton = new QPushButton();
86 cancelButton->setText( qtr( "&Cancel" ) );
87 cancelButton->setSizePolicy( buttonSizePolicy );
89 /* Menu for the Play button */
90 QMenu * openButtonMenu = new QMenu( "Open" );
91 openButtonMenu->addAction( qtr("&Enqueue"), this, SLOT( enqueue() ),
92 QKeySequence( "Alt+E") );
93 openButtonMenu->addAction( qtr("&Play"), this, SLOT( play() ),
94 QKeySequence( "Alt+P" ) );
95 openButtonMenu->addAction( qtr("&Stream"), this, SLOT( stream() ) ,
96 QKeySequence( "Alt+S" ) );
97 openButtonMenu->addAction( qtr("&Convert"), this, SLOT( transcode() ) ,
98 QKeySequence( "Alt+C" ) );
100 playButton->setMenu( openButtonMenu );
102 ui.buttonsBox->addButton( playButton, QDialogButtonBox::AcceptRole );
103 ui.buttonsBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
105 /* Force MRL update on tab change */
106 CONNECT( ui.Tab, currentChanged(int), this, signalCurrent());
108 CONNECT( fileOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
109 CONNECT( netOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
110 CONNECT( discOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
111 CONNECT( captureOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
113 CONNECT( fileOpenPanel, methodChanged( QString ),
114 this, newCachingMethod(QString) );
115 CONNECT( netOpenPanel, methodChanged( QString ),
116 this, newCachingMethod(QString) );
117 CONNECT( discOpenPanel, methodChanged( QString ),
118 this, newCachingMethod(QString) );
119 CONNECT( captureOpenPanel, methodChanged( QString ),
120 this, newCachingMethod(QString) );
122 /* Advanced frame Connects */
123 CONNECT( ui.slaveText, textChanged(QString), this, updateMRL());
124 CONNECT( ui.cacheSpinBox, valueChanged(int), this, updateMRL());
125 CONNECT( ui.startTimeSpinBox, valueChanged(int), this, updateMRL());
126 BUTTONACT( ui.advancedCheckBox , toggleAdvancedPanel() );
129 BUTTONACT( playButton, selectSlots());
130 BUTTONACT( cancelButton, cancel());
132 /* At creation time, modify the default buttons */
133 if ( i_action_flag ) setMenuAction();
135 /* Initialize caching */
137 newCachingMethod("file-caching");
139 mainHeight = advHeight = 0;
142 OpenDialog::~OpenDialog()
146 /* Finish the dialog and decide if you open another one after */
147 void OpenDialog::setMenuAction()
149 switch ( i_action_flag )
151 case OPEN_AND_STREAM:
152 playButton->setText( qtr("&Stream") );
155 playButton->setText( qtr("&Convert / Save") );
157 case OPEN_AND_ENQUEUE:
158 playButton->setText( qtr("&Enqueue") );
162 playButton->setText( qtr("&Play") );
166 void OpenDialog::showTab( int i_tab=0 )
169 ui.Tab->setCurrentIndex( i_tab );
172 void OpenDialog::signalCurrent() {
173 if (ui.Tab->currentWidget() != NULL)
174 (dynamic_cast<OpenPanel *>( ui.Tab->currentWidget() ))->updateMRL();
177 void OpenDialog::toggleAdvancedPanel()
179 //FIXME does not work under Windows
180 if( ui.advancedFrame->isVisible() ) {
181 ui.advancedFrame->hide();
184 resize( width(), mainHeight );
188 if( mainHeight == 0 )
189 mainHeight = height();
192 ui.advancedFrame->show();
194 if( advHeight == 0 ) {
195 advHeight = height() - mainHeight;
197 resize( width(), mainHeight + advHeight );
206 /* If Cancel is pressed or escaped */
207 void OpenDialog::cancel()
209 for( int i = 0; i < OPEN_TAB_MAX; i++ )
210 dynamic_cast<OpenPanel*>(ui.Tab->widget( i ))->clear();
212 if( isModal() ) reject();
215 /* If EnterKey is pressed */
216 void OpenDialog::close()
219 if ( !i_action_flag )
230 void OpenDialog::selectSlots()
232 switch ( i_action_flag )
234 case OPEN_AND_STREAM:
240 case OPEN_AND_ENQUEUE:
249 void OpenDialog::play()
254 void OpenDialog::enqueue()
259 void OpenDialog::transcode()
264 void OpenDialog::stream( bool b_transcode_only )
266 /* not finished FIXME */
267 /* Should go through the finish function */
268 THEDP->streamingDialog( mrl, b_transcode_only );
271 void OpenDialog::finish( bool b_enqueue = false )
274 mrl = ui.advancedLineInput->text();
278 QStringList tempMRL = SeparateEntries( mrl );
279 for( size_t i = 0; i < tempMRL.size(); i++ )
281 bool b_start = !i && !b_enqueue;
282 input_item_t *p_input;
284 p_input = input_ItemNew( p_intf, qtu( tempMRL[i] ), NULL );
287 while( i + 1 < tempMRL.size() && tempMRL[i + 1].startsWith( ":" ) )
290 input_ItemAddOption( p_input, qtu( tempMRL[i] ) );
293 /* Switch between enqueuing and starting the item */
296 playlist_AddInput( THEPL, p_input,
297 PLAYLIST_APPEND | PLAYLIST_GO,
298 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
302 playlist_AddInput( THEPL, p_input,
303 PLAYLIST_APPEND | PLAYLIST_PREPARSE,
304 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
314 void OpenDialog::updateMRL( QString tempMRL )
320 void OpenDialog::updateMRL() {
322 if( ui.slaveCheckbox->isChecked() ) {
323 mrl += " :input-slave=" + ui.slaveText->text();
325 int i_cache = config_GetInt( p_intf, qta(storedMethod) );
326 if( i_cache != ui.cacheSpinBox->value() ) {
327 mrl += QString(" :%1=%2").arg(storedMethod).
328 arg(ui.cacheSpinBox->value());
330 if( ui.startTimeSpinBox->value()) {
331 mrl += " :start-time=" + QString("%1").
332 arg(ui.startTimeSpinBox->value());
334 ui.advancedLineInput->setText(mrl);
337 void OpenDialog::newCachingMethod( QString method )
339 if( method != storedMethod ) {
340 storedMethod = method;
341 int i_value = config_GetInt( p_intf, qta( storedMethod ) );
342 ui.cacheSpinBox->setValue( i_value );
346 QStringList OpenDialog::SeparateEntries( QString entries )
348 bool b_quotes_mode = false;
350 QStringList entries_array;
354 while( index < entries.size() )
356 int delim_pos = entries.indexOf( QRegExp( "\\s+|\"" ), index );
357 if( delim_pos < 0 ) delim_pos = entries.size() - 1;
358 entry += entries.mid( index, delim_pos - index + 1 );
359 index = delim_pos + 1;
361 if( entry.isEmpty() ) continue;
363 if( !b_quotes_mode && entry.endsWith( "\"" ) )
365 /* Enters quotes mode */
366 entry.truncate( entry.size() - 1 );
367 b_quotes_mode = true;
369 else if( b_quotes_mode && entry.endsWith( "\"" ) )
371 /* Finished the quotes mode */
372 entry.truncate( entry.size() - 1 );
373 b_quotes_mode = false;
375 else if( !b_quotes_mode && !entry.endsWith( "\"" ) )
377 /* we found a non-quoted standalone string */
378 if( index < entries.size() ||
379 entry.endsWith( " " ) || entry.endsWith( "\t" ) ||
380 entry.endsWith( "\r" ) || entry.endsWith( "\n" ) )
381 entry.truncate( entry.size() - 1 );
382 if( !entry.isEmpty() ) entries_array.append( entry );
389 if( !entry.isEmpty() ) entries_array.append( entry );
391 return entries_array;