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 <QGridLayout>
26 #include <QFileDialog>
29 #include "dialogs/open.hpp"
30 #include "components/open.hpp"
33 #include "util/qvlcframe.hpp"
35 #include "input_manager.hpp"
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;
46 setWindowTitle( qtr("Open" ) );
49 /* Tab definition and creation */
50 fileOpenPanel = new FileOpenPanel( ui.Tab, p_intf );
51 discOpenPanel = new DiscOpenPanel( ui.Tab, p_intf );
52 netOpenPanel = new NetOpenPanel( ui.Tab, p_intf );
53 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 advancedPanel */
62 ui.advancedFrame->hide();
64 /* Buttons Creation */
65 QSizePolicy buttonSizePolicy( static_cast<QSizePolicy::Policy>(7),
66 static_cast<QSizePolicy::Policy>(1) );
67 buttonSizePolicy.setHorizontalStretch(0);
68 buttonSizePolicy.setVerticalStretch(0);
70 playButton = new QToolButton( this );
71 playButton->setText( qtr( "&Play" ) );
72 playButton->setSizePolicy( buttonSizePolicy );
73 playButton->setMinimumSize( QSize(90, 0) );
74 playButton->setPopupMode( QToolButton::MenuButtonPopup );
75 playButton->setToolButtonStyle( Qt::ToolButtonTextOnly );
77 cancelButton = new QToolButton();
78 cancelButton->setText( qtr( "&Cancel" ) );
79 cancelButton->setSizePolicy( buttonSizePolicy );
81 QMenu * openButtonMenu = new QMenu( "Open" );
82 openButtonMenu->addAction( qtr("&Enqueue"), this, SLOT( enqueue() ),
83 QKeySequence( "Alt+E") );
84 openButtonMenu->addAction( qtr("&Play"), this, SLOT( play() ),
85 QKeySequence( "Alt+P" ) );
86 openButtonMenu->addAction( qtr("&Stream"), this, SLOT( stream() ) ,
87 QKeySequence( "Alt+S" ) );
88 openButtonMenu->addAction( qtr("&Convert"), this, SLOT( transcode( ) ) ,
89 QKeySequence( "Alt+C" ) );
91 playButton->setMenu( openButtonMenu );
93 ui.buttonsBox->addButton( playButton, QDialogButtonBox::AcceptRole );
94 ui.buttonsBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
96 /* Force MRL update on tab change */
97 CONNECT( ui.Tab, currentChanged(int), this, signalCurrent());
99 CONNECT( fileOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
100 CONNECT( netOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
101 CONNECT( discOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
102 CONNECT( captureOpenPanel, mrlUpdated( QString ), this,
103 updateMRL(QString) );
105 CONNECT( fileOpenPanel, methodChanged( QString ),
106 this, newMethod(QString) );
107 CONNECT( netOpenPanel, methodChanged( QString ),
108 this, newMethod(QString) );
109 CONNECT( discOpenPanel, methodChanged( QString ),
110 this, newMethod(QString) );
113 /* Advanced frame Connects */
114 CONNECT( ui.slaveText, textChanged(QString), this, updateMRL());
115 CONNECT( ui.cacheSpinBox, valueChanged(int), this, updateMRL());
116 CONNECT( ui.startTimeSpinBox, valueChanged(int), this, updateMRL());
117 BUTTONACT( ui.advancedCheckBox , toggleAdvancedPanel() );
120 BUTTONACT( playButton, play());
121 BUTTONACT( cancelButton, cancel());
123 /* At creation time, modify the default buttons */
124 if ( i_action_flag ) setMenuAction();
127 /* Initialize caching */
129 newMethod("file-caching");
131 mainHeight = advHeight = 0;
134 OpenDialog::~OpenDialog()
138 /* Finish the dialog and decide if you open another one after */
139 void OpenDialog::setMenuAction()
141 switch ( i_action_flag )
143 case OPEN_AND_STREAM:
144 playButton->setText( qtr("&Stream") );
145 BUTTONACT( playButton, stream() );
148 playButton->setText( qtr("&Convert / Save") );
149 BUTTONACT( playButton, stream( true ) );
153 playButton->setText( qtr("&Play") );
154 BUTTONACT( playButton, play() );
158 void OpenDialog::showTab(int i_tab=0)
161 ui.Tab->setCurrentIndex(i_tab);
164 void OpenDialog::signalCurrent() {
165 if (ui.Tab->currentWidget() != NULL) {
166 (dynamic_cast<OpenPanel*>(ui.Tab->currentWidget()))->updateMRL();
174 /* If Cancel is pressed or escaped */
175 void OpenDialog::cancel()
177 fileOpenPanel->clear();
178 this->toggleVisible();
183 /* If EnterKey is pressed */
184 void OpenDialog::close()
187 if ( !i_action_flag )
198 void OpenDialog::play()
203 void OpenDialog::enqueue()
208 void OpenDialog::transcode()
213 void OpenDialog::stream( bool b_transcode_only )
215 /* not finished FIXME */
216 /* Should go through the finish function */
217 THEDP->streamingDialog( mrl, b_transcode_only );
220 void OpenDialog::finish( bool b_enqueue = false )
222 this->toggleVisible();
223 mrl = ui.advancedLineInput->text();
227 QStringList tempMRL = SeparateEntries( mrl );
228 for( size_t i = 0; i < tempMRL.size(); i++ )
230 bool b_start = !i && !b_enqueue;
231 input_item_t *p_input;
232 const char *psz_utf8 = qtu( tempMRL[i] );
234 p_input = input_ItemNew( p_intf, psz_utf8, NULL );
237 while( i + 1 < tempMRL.size() && tempMRL[i + 1].startsWith( ":" ) )
240 psz_utf8 = qtu( tempMRL[i] );
241 input_ItemAddOption( p_input, psz_utf8 );
246 playlist_AddInput( THEPL, p_input,
247 PLAYLIST_APPEND | PLAYLIST_GO,
248 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
252 playlist_AddInput( THEPL, p_input,
253 PLAYLIST_APPEND|PLAYLIST_PREPARSE,
254 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
262 void OpenDialog::toggleAdvancedPanel()
264 //FIXME does not work under Windows
265 if (ui.advancedFrame->isVisible()) {
266 ui.advancedFrame->hide();
268 resize( width(), mainHeight );
271 if( mainHeight == 0 )
272 mainHeight = height();
274 ui.advancedFrame->show();
275 if( advHeight == 0 ) {
276 advHeight = height() - mainHeight;
278 resize( width(), mainHeight + advHeight );
282 void OpenDialog::updateMRL() {
284 if( ui.slaveCheckbox->isChecked() ) {
285 mrl += " :input-slave=" + ui.slaveText->text();
287 int i_cache = config_GetInt( p_intf, qta(storedMethod) );
288 if( i_cache != ui.cacheSpinBox->value() ) {
289 mrl += QString(" :%1=%2").arg(storedMethod).
290 arg(ui.cacheSpinBox->value());
292 if( ui.startTimeSpinBox->value()) {
293 mrl += " :start-time=" + QString("%1").
294 arg(ui.startTimeSpinBox->value());
296 ui.advancedLineInput->setText(mrl);
299 void OpenDialog::updateMRL(QString tempMRL)
305 void OpenDialog::newMethod(QString method)
307 if( method != storedMethod ) {
308 storedMethod = method;
309 int i_value = config_GetInt( p_intf, qta(storedMethod) );
310 ui.cacheSpinBox->setValue(i_value);
314 QStringList OpenDialog::SeparateEntries( QString entries )
316 bool b_quotes_mode = false;
318 QStringList entries_array;
322 while( index < entries.size() )
324 int delim_pos = entries.indexOf( QRegExp( "\\s+|\"" ), index );
325 if( delim_pos < 0 ) delim_pos = entries.size() - 1;
326 entry += entries.mid( index, delim_pos - index + 1 );
327 index = delim_pos + 1;
329 if( entry.isEmpty() ) continue;
331 if( !b_quotes_mode && entry.endsWith( "\"" ) )
333 /* Enters quotes mode */
334 entry.truncate( entry.size() - 1 );
335 b_quotes_mode = true;
337 else if( b_quotes_mode && entry.endsWith( "\"" ) )
339 /* Finished the quotes mode */
340 entry.truncate( entry.size() - 1 );
341 b_quotes_mode = false;
343 else if( !b_quotes_mode && !entry.endsWith( "\"" ) )
345 /* we found a non-quoted standalone string */
346 if( index < entries.size() ||
347 entry.endsWith( " " ) || entry.endsWith( "\t" ) ||
348 entry.endsWith( "\r" ) || entry.endsWith( "\n" ) )
349 entry.truncate( entry.size() - 1 );
350 if( !entry.isEmpty() ) entries_array.append( entry );
357 if( !entry.isEmpty() ) entries_array.append( entry );
359 return entries_array;