1 /*****************************************************************************
2 * open.cpp : Advanced open dialog
3 *****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
5 * $Id: streaminfo.cpp 16816 2006-09-23 20:56:52Z jb $
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 *****************************************************************************/
25 #include "util/qvlcframe.hpp"
26 #include "input_manager.hpp"
28 #include "dialogs/open.hpp"
29 #include "components/open.hpp"
32 #include <QGridLayout>
33 #include <QFileDialog>
37 OpenDialog *OpenDialog::instance = NULL;
39 OpenDialog::OpenDialog( QWidget *parent, intf_thread_t *_p_intf, bool modal,
40 int _action_flag ) : QVLCDialog( parent, _p_intf )
43 i_action_flag = _action_flag;
45 /* Basic Creation of the Window */
47 setWindowTitle( qtr("Open" ) );
50 /* Tab definition and creation */
51 fileOpenPanel = new FileOpenPanel( ui.Tab, p_intf );
52 discOpenPanel = new DiscOpenPanel( ui.Tab, p_intf );
53 netOpenPanel = new NetOpenPanel( ui.Tab, p_intf );
54 captureOpenPanel = new CaptureOpenPanel( ui.Tab, p_intf );
57 ui.Tab->insertTab( OPEN_FILE_TAB, fileOpenPanel, qtr( "&File" ) );
58 ui.Tab->insertTab( OPEN_DISC_TAB, discOpenPanel, qtr( "&Disc" ) );
59 ui.Tab->insertTab( OPEN_NETWORK_TAB, netOpenPanel, qtr( "&Network" ) );
60 ui.Tab->insertTab( OPEN_CAPTURE_TAB, captureOpenPanel,
61 qtr( "Capture &Device" ) );
63 /* Hide the advancedPanel */
64 if(! config_GetInt( p_intf, "qt-adv-options") )
66 ui.advancedFrame->hide();
70 ui.advancedCheckBox->setCheckState( Qt::Checked );
73 ui.slaveLabel->hide();
75 ui.slaveBrowseButton->hide();
77 /* Buttons Creation */
78 QSizePolicy buttonSizePolicy( static_cast<QSizePolicy::Policy>(7),
79 static_cast<QSizePolicy::Policy>(1) );
80 buttonSizePolicy.setHorizontalStretch(0);
81 buttonSizePolicy.setVerticalStretch(0);
83 playButton = new QToolButton( this );
84 playButton->setText( qtr( "&Play" ) );
85 playButton->setSizePolicy( buttonSizePolicy );
86 playButton->setMinimumSize( QSize(90, 0) );
87 playButton->setPopupMode( QToolButton::MenuButtonPopup );
88 playButton->setToolButtonStyle( Qt::ToolButtonTextOnly );
90 cancelButton = new QPushButton();
91 cancelButton->setText( qtr( "&Cancel" ) );
92 cancelButton->setSizePolicy( buttonSizePolicy );
94 QMenu * openButtonMenu = new QMenu( "Open" );
95 openButtonMenu->addAction( qtr("&Enqueue"), this, SLOT( enqueue() ),
96 QKeySequence( "Alt+E") );
97 openButtonMenu->addAction( qtr("&Play"), this, SLOT( play() ),
98 QKeySequence( "Alt+P" ) );
99 openButtonMenu->addAction( qtr("&Stream"), this, SLOT( stream() ) ,
100 QKeySequence( "Alt+S" ) );
101 openButtonMenu->addAction( qtr("&Convert"), this, SLOT( transcode( ) ) ,
102 QKeySequence( "Alt+C" ) );
104 playButton->setMenu( openButtonMenu );
106 ui.buttonsBox->addButton( playButton, QDialogButtonBox::AcceptRole );
107 ui.buttonsBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
109 /* Force MRL update on tab change */
110 CONNECT( ui.Tab, currentChanged(int), this, signalCurrent());
112 CONNECT( fileOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
113 CONNECT( netOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
114 CONNECT( discOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
115 CONNECT( captureOpenPanel, mrlUpdated( QString ), this,
116 updateMRL(QString) );
118 CONNECT( fileOpenPanel, methodChanged( QString ),
119 this, newMethod(QString) );
120 CONNECT( netOpenPanel, methodChanged( QString ),
121 this, newMethod(QString) );
122 CONNECT( discOpenPanel, methodChanged( QString ),
123 this, newMethod(QString) );
124 CONNECT( captureOpenPanel, methodChanged( QString ),
125 this, newMethod(QString) );
127 /* Advanced frame Connects */
128 CONNECT( ui.slaveText, textChanged(QString), this, updateMRL());
129 CONNECT( ui.cacheSpinBox, valueChanged(int), this, updateMRL());
130 CONNECT( ui.startTimeSpinBox, valueChanged(int), this, updateMRL());
131 BUTTONACT( ui.advancedCheckBox , toggleAdvancedPanel() );
134 BUTTONACT( playButton, play());
135 BUTTONACT( cancelButton, cancel());
137 /* At creation time, modify the default buttons */
138 if ( i_action_flag ) setMenuAction();
141 /* Initialize caching */
143 newMethod("file-caching");
145 mainHeight = advHeight = 0;
148 OpenDialog::~OpenDialog()
152 /* Finish the dialog and decide if you open another one after */
153 void OpenDialog::setMenuAction()
155 switch ( i_action_flag )
157 case OPEN_AND_STREAM:
158 playButton->setText( qtr("&Stream") );
159 BUTTONACT( playButton, stream() );
162 playButton->setText( qtr("&Convert / Save") );
163 BUTTONACT( playButton, stream( true ) );
166 playButton->setText( qtr("&Enqueue") );
167 BUTTONACT( playButton, enqueue() );
171 playButton->setText( qtr("&Play") );
172 BUTTONACT( playButton, play() );
176 void OpenDialog::showTab(int i_tab=0)
179 ui.Tab->setCurrentIndex(i_tab);
182 void OpenDialog::signalCurrent() {
183 if (ui.Tab->currentWidget() != NULL) {
184 (dynamic_cast<OpenPanel*>(ui.Tab->currentWidget()))->updateMRL();
192 /* If Cancel is pressed or escaped */
193 void OpenDialog::cancel()
195 fileOpenPanel->clear();
196 this->toggleVisible();
201 /* If EnterKey is pressed */
202 void OpenDialog::close()
205 if ( !i_action_flag )
216 void OpenDialog::play()
221 void OpenDialog::enqueue()
226 void OpenDialog::transcode()
231 void OpenDialog::stream( bool b_transcode_only )
233 /* not finished FIXME */
234 /* Should go through the finish function */
235 THEDP->streamingDialog( mrl, b_transcode_only );
238 void OpenDialog::finish( bool b_enqueue = false )
240 this->toggleVisible();
241 mrl = ui.advancedLineInput->text();
245 QStringList tempMRL = SeparateEntries( mrl );
246 for( size_t i = 0; i < tempMRL.size(); i++ )
248 bool b_start = !i && !b_enqueue;
249 input_item_t *p_input;
250 const char *psz_utf8 = qtu( tempMRL[i] );
252 p_input = input_ItemNew( p_intf, psz_utf8, NULL );
255 while( i + 1 < tempMRL.size() && tempMRL[i + 1].startsWith( ":" ) )
258 psz_utf8 = qtu( tempMRL[i] );
259 input_ItemAddOption( p_input, psz_utf8 );
264 playlist_AddInput( THEPL, p_input,
265 PLAYLIST_APPEND | PLAYLIST_GO,
266 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
270 playlist_AddInput( THEPL, p_input,
271 PLAYLIST_APPEND|PLAYLIST_PREPARSE,
272 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
280 void OpenDialog::toggleAdvancedPanel()
282 //FIXME does not work under Windows
283 if (ui.advancedFrame->isVisible()) {
284 ui.advancedFrame->hide();
287 resize( width(), mainHeight );
291 if( mainHeight == 0 )
292 mainHeight = height();
295 ui.advancedFrame->show();
297 if( advHeight == 0 ) {
298 advHeight = height() - mainHeight;
300 resize( width(), mainHeight + advHeight );
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::updateMRL(QString tempMRL)
328 void OpenDialog::newMethod(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;