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->setChecked( true );
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();
183 setMinimumHeight( 1 );
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 );
205 /* If Cancel is pressed or escaped */
206 void OpenDialog::cancel()
208 for( int i = 0; i < OPEN_TAB_MAX; i++ )
209 dynamic_cast<OpenPanel*>(ui.Tab->widget( i ))->clear();
211 if( isModal() ) reject();
214 /* If EnterKey is pressed */
215 void OpenDialog::close()
221 void OpenDialog::selectSlots()
223 switch ( i_action_flag )
225 case OPEN_AND_STREAM:
231 case OPEN_AND_ENQUEUE:
240 void OpenDialog::play()
245 void OpenDialog::enqueue()
250 void OpenDialog::transcode()
255 void OpenDialog::stream( bool b_transcode_only )
257 /* not finished FIXME */
258 /* Should go through the finish function */
259 THEDP->streamingDialog( mrl, b_transcode_only );
262 void OpenDialog::finish( bool b_enqueue = false )
265 mrl = ui.advancedLineInput->text();
269 QStringList tempMRL = SeparateEntries( mrl );
270 for( size_t i = 0; i < tempMRL.size(); i++ )
272 bool b_start = !i && !b_enqueue;
273 input_item_t *p_input;
275 p_input = input_ItemNew( p_intf, qtu( tempMRL[i] ), NULL );
278 while( i + 1 < tempMRL.size() && tempMRL[i + 1].startsWith( ":" ) )
281 input_ItemAddOption( p_input, qtu( tempMRL[i] ) );
284 /* Switch between enqueuing and starting the item */
287 playlist_AddInput( THEPL, p_input,
288 PLAYLIST_APPEND | PLAYLIST_GO,
289 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
293 playlist_AddInput( THEPL, p_input,
294 PLAYLIST_APPEND | PLAYLIST_PREPARSE,
295 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
305 void OpenDialog::updateMRL( QString tempMRL )
311 void OpenDialog::updateMRL() {
313 if( ui.slaveCheckbox->isChecked() ) {
314 mrl += " :input-slave=" + ui.slaveText->text();
316 int i_cache = config_GetInt( p_intf, qta( storedMethod ) );
317 if( i_cache != ui.cacheSpinBox->value() ) {
318 mrl += QString( " :%1=%2" ).arg( storedMethod ).
319 arg( ui.cacheSpinBox->value() );
321 if( ui.startTimeSpinBox->value() ) {
322 mrl += " :start-time=" + QString( "%1" ).
323 arg( ui.startTimeSpinBox->value() );
325 ui.advancedLineInput->setText( mrl );
328 void OpenDialog::newCachingMethod( QString method )
330 if( method != storedMethod ) {
331 storedMethod = method;
332 int i_value = config_GetInt( p_intf, qta( storedMethod ) );
333 ui.cacheSpinBox->setValue( i_value );
337 QStringList OpenDialog::SeparateEntries( QString entries )
339 bool b_quotes_mode = false;
341 QStringList entries_array;
345 while( index < entries.size() )
347 int delim_pos = entries.indexOf( QRegExp( "\\s+|\"" ), index );
348 if( delim_pos < 0 ) delim_pos = entries.size() - 1;
349 entry += entries.mid( index, delim_pos - index + 1 );
350 index = delim_pos + 1;
352 if( entry.isEmpty() ) continue;
354 if( !b_quotes_mode && entry.endsWith( "\"" ) )
356 /* Enters quotes mode */
357 entry.truncate( entry.size() - 1 );
358 b_quotes_mode = true;
360 else if( b_quotes_mode && entry.endsWith( "\"" ) )
362 /* Finished the quotes mode */
363 entry.truncate( entry.size() - 1 );
364 b_quotes_mode = false;
366 else if( !b_quotes_mode && !entry.endsWith( "\"" ) )
368 /* we found a non-quoted standalone string */
369 if( index < entries.size() ||
370 entry.endsWith( " " ) || entry.endsWith( "\t" ) ||
371 entry.endsWith( "\r" ) || entry.endsWith( "\n" ) )
372 entry.truncate( entry.size() - 1 );
373 if( !entry.isEmpty() ) entries_array.append( entry );
380 if( !entry.isEmpty() ) entries_array.append( entry );
382 return entries_array;