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, play());
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") );
153 BUTTONACT( playButton, stream() );
156 playButton->setText( qtr("&Convert / Save") );
157 BUTTONACT( playButton, transcode() );
159 case OPEN_AND_ENQUEUE:
160 playButton->setText( qtr("&Enqueue") );
161 BUTTONACT( playButton, enqueue() );
165 playButton->setText( qtr("&Play") );
166 BUTTONACT( playButton, play() );
170 void OpenDialog::showTab( int i_tab=0 )
173 ui.Tab->setCurrentIndex( i_tab );
176 void OpenDialog::signalCurrent() {
177 if (ui.Tab->currentWidget() != NULL)
178 (dynamic_cast<OpenPanel *>( ui.Tab->currentWidget() ))->updateMRL();
181 void OpenDialog::toggleAdvancedPanel()
183 //FIXME does not work under Windows
184 if( ui.advancedFrame->isVisible() ) {
185 ui.advancedFrame->hide();
188 resize( width(), mainHeight );
192 if( mainHeight == 0 )
193 mainHeight = height();
196 ui.advancedFrame->show();
198 if( advHeight == 0 ) {
199 advHeight = height() - mainHeight;
201 resize( width(), mainHeight + advHeight );
210 /* If Cancel is pressed or escaped */
211 void OpenDialog::cancel()
213 for( int i = 0; i < OPEN_TAB_MAX; i++ )
214 dynamic_cast<OpenPanel*>(ui.Tab->widget( i ))->clear();
216 if( isModal() ) reject();
219 /* If EnterKey is pressed */
220 void OpenDialog::close()
223 if ( !i_action_flag )
234 void OpenDialog::play()
239 void OpenDialog::enqueue()
244 void OpenDialog::transcode()
249 void OpenDialog::stream( bool b_transcode_only )
251 /* not finished FIXME */
252 /* Should go through the finish function */
253 THEDP->streamingDialog( mrl, b_transcode_only );
256 void OpenDialog::finish( bool b_enqueue = false )
259 mrl = ui.advancedLineInput->text();
263 QStringList tempMRL = SeparateEntries( mrl );
264 for( size_t i = 0; i < tempMRL.size(); i++ )
266 bool b_start = !i && !b_enqueue;
267 input_item_t *p_input;
269 p_input = input_ItemNew( p_intf, qtu( tempMRL[i] ), NULL );
272 while( i + 1 < tempMRL.size() && tempMRL[i + 1].startsWith( ":" ) )
275 input_ItemAddOption( p_input, qtu( tempMRL[i] ) );
278 /* Switch between enqueuing and starting the item */
281 playlist_AddInput( THEPL, p_input,
282 PLAYLIST_APPEND | PLAYLIST_GO,
283 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
287 playlist_AddInput( THEPL, p_input,
288 PLAYLIST_APPEND | PLAYLIST_PREPARSE,
289 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
299 void OpenDialog::updateMRL( QString tempMRL )
305 void OpenDialog::updateMRL() {
307 if( ui.slaveCheckbox->isChecked() ) {
308 mrl += " :input-slave=" + ui.slaveText->text();
310 int i_cache = config_GetInt( p_intf, qta(storedMethod) );
311 if( i_cache != ui.cacheSpinBox->value() ) {
312 mrl += QString(" :%1=%2").arg(storedMethod).
313 arg(ui.cacheSpinBox->value());
315 if( ui.startTimeSpinBox->value()) {
316 mrl += " :start-time=" + QString("%1").
317 arg(ui.startTimeSpinBox->value());
319 ui.advancedLineInput->setText(mrl);
322 void OpenDialog::newCachingMethod( QString method )
324 if( method != storedMethod ) {
325 storedMethod = method;
326 int i_value = config_GetInt( p_intf, qta( storedMethod ) );
327 ui.cacheSpinBox->setValue( i_value );
331 QStringList OpenDialog::SeparateEntries( QString entries )
333 bool b_quotes_mode = false;
335 QStringList entries_array;
339 while( index < entries.size() )
341 int delim_pos = entries.indexOf( QRegExp( "\\s+|\"" ), index );
342 if( delim_pos < 0 ) delim_pos = entries.size() - 1;
343 entry += entries.mid( index, delim_pos - index + 1 );
344 index = delim_pos + 1;
346 if( entry.isEmpty() ) continue;
348 if( !b_quotes_mode && entry.endsWith( "\"" ) )
350 /* Enters quotes mode */
351 entry.truncate( entry.size() - 1 );
352 b_quotes_mode = true;
354 else if( b_quotes_mode && entry.endsWith( "\"" ) )
356 /* Finished the quotes mode */
357 entry.truncate( entry.size() - 1 );
358 b_quotes_mode = false;
360 else if( !b_quotes_mode && !entry.endsWith( "\"" ) )
362 /* we found a non-quoted standalone string */
363 if( index < entries.size() ||
364 entry.endsWith( " " ) || entry.endsWith( "\t" ) ||
365 entry.endsWith( "\r" ) || entry.endsWith( "\n" ) )
366 entry.truncate( entry.size() - 1 );
367 if( !entry.isEmpty() ) entries_array.append( entry );
374 if( !entry.isEmpty() ) entries_array.append( entry );
376 return entries_array;