/*****************************************************************************
* open.cpp : Advanced open dialog
*****************************************************************************
- * Copyright © 2006-2008 the VideoLAN team
- * $Id$
+ * Copyright © 2006-2011 the VideoLAN team
*
* Authors: Jean-Baptiste Kempf <jb@videolan.org>
*
#endif
#include "dialogs/open.hpp"
-
#include "dialogs_provider.hpp"
-
#include "recents.hpp"
+#include "util/qt_dirs.hpp"
#include <QTabWidget>
-#include <QGridLayout>
#include <QRegExp>
#include <QMenu>
+#ifndef NDEBUG
+# define DEBUG_QT 1
+#endif
+
OpenDialog *OpenDialog::instance = NULL;
OpenDialog* OpenDialog::getInstance( QWidget *parent, intf_thread_t *p_intf,
else if( !b_rawInstance )
{
/* Request the instance but change small details:
- - Button menu
- - Modality on top of the parent dialog */
+ - Button menu */
if( b_selectMode )
- {
- instance->setWindowModality( Qt::WindowModal );
_action_flag = SELECT; /* This should be useless, but we never know
if the call is correct */
- }
+ instance->setWindowModality( Qt::WindowModal );
instance->i_action_flag = _action_flag;
instance->b_pl = _b_pl;
instance->setMenuAction();
i_action_flag = _action_flag;
b_pl =_b_pl;
- /* Workaround the Win32 Vout that put the video on top at regular times */
-#ifdef WIN32
- setWindowFlags( Qt::WindowStaysOnTopHint | Qt::Dialog );
-#endif
-
if( b_selectMode ) /* Select mode */
- {
i_action_flag = SELECT;
- setWindowModality( Qt::WindowModal );
- }
/* Basic Creation of the Window */
ui.setupUi( this );
- setWindowTitle( qtr( "Open" ) );
- /* resize( 410, 600 ); */
- setMinimumSize( 520, 490 );
+ setWindowTitle( qtr( "Open Media" ) );
+ setWindowRole( "vlc-open-media" );
+ setWindowModality( Qt::WindowModal );
/* Tab definition and creation */
- fileOpenPanel = new FileOpenPanel( ui.Tab, p_intf );
- discOpenPanel = new DiscOpenPanel( ui.Tab, p_intf );
- netOpenPanel = new NetOpenPanel( ui.Tab, p_intf );
- captureOpenPanel = new CaptureOpenPanel( ui.Tab, p_intf );
+ fileOpenPanel = new FileOpenPanel( this, p_intf );
+ discOpenPanel = new DiscOpenPanel( this, p_intf );
+ netOpenPanel = new NetOpenPanel( this, p_intf );
+ captureOpenPanel = new CaptureOpenPanel( this, p_intf );
/* Insert the tabs */
- ui.Tab->insertTab( OPEN_FILE_TAB, fileOpenPanel, qtr( "&File" ) );
- ui.Tab->insertTab( OPEN_DISC_TAB, discOpenPanel, qtr( "&Disc" ) );
- ui.Tab->insertTab( OPEN_NETWORK_TAB, netOpenPanel, qtr( "&Network" ) );
+ ui.Tab->insertTab( OPEN_FILE_TAB, fileOpenPanel, QIcon( ":/type/folder-grey" ),
+ qtr( "&File" ) );
+ ui.Tab->insertTab( OPEN_DISC_TAB, discOpenPanel, QIcon( ":/type/disc" ),
+ qtr( "&Disc" ) );
+ ui.Tab->insertTab( OPEN_NETWORK_TAB, netOpenPanel, QIcon( ":/type/network" ),
+ qtr( "&Network" ) );
ui.Tab->insertTab( OPEN_CAPTURE_TAB, captureOpenPanel,
- qtr( "Capture &Device" ) );
+ QIcon( ":/type/capture-card" ), qtr( "Capture &Device" ) );
/* Hide the Slave input widgets */
ui.slaveLabel->hide();
QKeySequence( "Alt+P" ) );
openButtonMenu->addAction( qtr( "&Stream" ), this, SLOT( stream() ) ,
QKeySequence( "Alt+S" ) );
- openButtonMenu->addAction( qtr( "&Convert" ), this, SLOT( transcode() ) ,
- QKeySequence( "Alt+C" ) );
+ openButtonMenu->addAction( qtr( "C&onvert" ), this, SLOT( transcode() ) ,
+ QKeySequence( "Alt+O" ) );
- ui.menuButton->setMenu( openButtonMenu );
+ playButton->setMenu( openButtonMenu );
/* Add the three Buttons */
ui.buttonsBox->addButton( selectButton, QDialogButtonBox::AcceptRole );
/* Force MRL update on tab change */
CONNECT( ui.Tab, currentChanged( int ), this, signalCurrent( int ) );
- CONNECT( fileOpenPanel, mrlUpdated( QString ), this, updateMRL( QString ) );
- CONNECT( netOpenPanel, mrlUpdated( QString ), this, updateMRL( QString ) );
- CONNECT( discOpenPanel, mrlUpdated( QString ), this, updateMRL( QString ) );
- CONNECT( captureOpenPanel, mrlUpdated( QString ), this, updateMRL( QString ) );
-
- CONNECT( fileOpenPanel, methodChanged( QString ),
- this, newCachingMethod( QString ) );
- CONNECT( netOpenPanel, methodChanged( QString ),
- this, newCachingMethod( QString ) );
- CONNECT( discOpenPanel, methodChanged( QString ),
- this, newCachingMethod( QString ) );
- CONNECT( captureOpenPanel, methodChanged( QString ),
- this, newCachingMethod( QString ) );
+ CONNECT( fileOpenPanel, mrlUpdated( const QStringList&, const QString& ),
+ this, updateMRL( const QStringList&, const QString& ) );
+ CONNECT( netOpenPanel, mrlUpdated( const QStringList&, const QString& ),
+ this, updateMRL( const QStringList&, const QString& ) );
+ CONNECT( discOpenPanel, mrlUpdated( const QStringList&, const QString& ),
+ this, updateMRL( const QStringList&, const QString& ) );
+ CONNECT( captureOpenPanel, mrlUpdated( const QStringList&, const QString& ),
+ this, updateMRL( const QStringList&, const QString& ) );
+
+ CONNECT( fileOpenPanel, methodChanged( const QString& ),
+ this, newCachingMethod( const QString& ) );
+ CONNECT( netOpenPanel, methodChanged( const QString& ),
+ this, newCachingMethod( const QString& ) );
+ CONNECT( discOpenPanel, methodChanged( const QString& ),
+ this, newCachingMethod( const QString& ) );
+ CONNECT( captureOpenPanel, methodChanged( const QString& ),
+ this, newCachingMethod( const QString& ) );
/* Advanced frame Connects */
- CONNECT( ui.slaveText, textChanged( QString ), this, updateMRL() );
+ CONNECT( ui.slaveCheckbox, toggled( bool ), this, updateMRL() );
+ CONNECT( ui.slaveText, textChanged( const QString& ), this, updateMRL() );
CONNECT( ui.cacheSpinBox, valueChanged( int ), this, updateMRL() );
- CONNECT( ui.startTimeSpinBox, valueChanged( int ), this, updateMRL() );
+ CONNECT( ui.startTimeTimeEdit, timeChanged ( const QTime& ), this, updateMRL() );
BUTTONACT( ui.advancedCheckBox, toggleAdvancedPanel() );
BUTTONACT( ui.slaveBrowseButton, browseInputSlave() );
BUTTONACT( cancelButton, cancel() );
/* Hide the advancedPanel */
- if( !config_GetInt( p_intf, "qt-adv-options" ) )
+ if( !getSettings()->value( "OpenDialog/advanced", false ).toBool())
+ {
ui.advancedFrame->hide();
+ ui.advancedFrame->setEnabled( false );
+ }
else
ui.advancedCheckBox->setChecked( true );
storedMethod = "";
newCachingMethod( "file-caching" );
- resize( getSettings()->value( "opendialog-size", QSize( 520, 490 ) ).toSize() );
-}
+ /* enforce section due to .ui bug */
+ ui.startTimeTimeEdit->setCurrentSection( QDateTimeEdit::SecondSection );
-OpenDialog::~OpenDialog()
-{
- getSettings()->setValue( "opendialog-size", size() );
+ setMinimumSize( sizeHint() );
+ setMaximumWidth( 900 );
+ resize( getSettings()->value( "OpenDialog/size", QSize( 500, 400 ) ).toSize() );
}
/* Finish the dialog and decide if you open another one after */
playButton->setText( qtr( "&Stream" ) );
break;
case OPEN_AND_SAVE:
- playButton->setText( qtr( "&Convert / Save" ) );
+ playButton->setText( qtr( "C&onvert / Save" ) );
break;
case OPEN_AND_ENQUEUE:
playButton->setText( qtr( "&Enqueue" ) );
}
playButton->show();
selectButton->hide();
- playButton->setDefault( true );
}
}
-void OpenDialog::showTab( int i_tab )
+OpenDialog::~OpenDialog()
{
- if( i_tab == OPEN_CAPTURE_TAB ) captureOpenPanel->initialize();
- ui.Tab->setCurrentIndex( i_tab );
- show();
+ getSettings()->setValue( "OpenDialog/size", size() -
+ ( ui.advancedFrame->isEnabled() ?
+ QSize(0, ui.advancedFrame->height()) : QSize(0, 0) ) );
+ getSettings()->setValue( "OpenDialog/advanced", ui.advancedFrame->isVisible() );
}
-/* Function called on signal currentChanged triggered */
-void OpenDialog::signalCurrent( int i_tab )
+/* Used by VLM dialog and inputSlave selection */
+QString OpenDialog::getMRL( bool b_all )
{
- if( i_tab == OPEN_CAPTURE_TAB ) captureOpenPanel->initialize();
+ if( itemsMRL.count() == 0 ) return "";
+ return b_all ? itemsMRL[0] + getOptions()
+ : itemsMRL[0];
+}
+QString OpenDialog::getOptions()
+{
+ return ui.advancedLineInput->text();
+}
+
+void OpenDialog::showTab( int i_tab )
+{
+ if( i_tab == OPEN_CAPTURE_TAB ) captureOpenPanel->initialize();
+ ui.Tab->setCurrentIndex( i_tab );
+ show();
if( ui.Tab->currentWidget() != NULL )
- ( dynamic_cast<OpenPanel *>( ui.Tab->currentWidget() ) )->updateMRL();
+ {
+ OpenPanel *panel = qobject_cast<OpenPanel *>( ui.Tab->currentWidget() );
+ assert( panel );
+ panel->onFocus();
+ }
}
void OpenDialog::toggleAdvancedPanel()
if( ui.advancedFrame->isVisible() )
{
ui.advancedFrame->hide();
- //setMinimumSize( 520, 460 );
+ ui.advancedFrame->setEnabled( false );
if( size().isValid() )
resize( size().width(), size().height()
- ui.advancedFrame->height() );
else
{
ui.advancedFrame->show();
- //setMinimumSize( 520, 460 + ui.advancedFrame->height() );
+ ui.advancedFrame->setEnabled( true );
if( size().isValid() )
resize( size().width(), size().height()
+ ui.advancedFrame->height() );
}
}
+void OpenDialog::browseInputSlave()
+{
+ OpenDialog *od = new OpenDialog( this, p_intf, true, SELECT );
+ od->exec();
+ ui.slaveText->setText( od->getMRL( false ) );
+ delete od;
+}
+
+/* Function called on signal currentChanged triggered */
+void OpenDialog::signalCurrent( int i_tab )
+{
+ if( i_tab == OPEN_CAPTURE_TAB ) captureOpenPanel->initialize();
+ if( ui.Tab->currentWidget() != NULL )
+ {
+ OpenPanel *panel = qobject_cast<OpenPanel *>( ui.Tab->currentWidget() );
+ assert( panel );
+ panel->onFocus();
+ panel->updateMRL();
+ }
+}
+
/***********
* Actions *
***********/
{
/* Clear the panels */
for( int i = 0; i < OPEN_TAB_MAX; i++ )
- dynamic_cast<OpenPanel*>( ui.Tab->widget( i ) )->clear();
+ qobject_cast<OpenPanel*>( ui.Tab->widget( i ) )->clear();
/* Clear the variables */
- mrl.clear();
- mainMRL.clear();
+ itemsMRL.clear();
+ optionsMRL.clear();
/* If in Select Mode, reject instead of hiding */
if( i_action_flag == SELECT ) reject();
}
}
+/* Play Action, called from selectSlots or play Menu */
void OpenDialog::play()
{
- finish( false );
+ enqueue( false );
}
-void OpenDialog::enqueue()
+/* Enqueue Action, called from selectSlots or enqueue Menu */
+void OpenDialog::enqueue( bool b_enqueue )
{
- finish( true );
-}
+ toggleVisible();
+ if( i_action_flag == SELECT )
+ {
+ accept();
+ return;
+ }
-void OpenDialog::finish( bool b_enqueue = false )
-{
- toggleVisible();
- mrl = ui.advancedLineInput->text();
+ for( int i = 0; i < OPEN_TAB_MAX; i++ )
+ qobject_cast<OpenPanel*>( ui.Tab->widget( i ) )->onAccept();
+
+ /* Sort alphabetically */
+ itemsMRL.sort();
- if( i_action_flag != SELECT )
+ /* Go through the item list */
+ for( int i = 0; i < itemsMRL.count(); i++ )
{
- QStringList tempMRL = SeparateEntries( mrl );
- for( size_t i = 0; i < tempMRL.size(); i++ )
- {
- bool b_start = !i && !b_enqueue;
- input_item_t *p_input;
+ bool b_start = !i && !b_enqueue;
+
+ input_item_t *p_input_item;
+ p_input_item = input_item_New( qtu( itemsMRL[i] ), NULL );
- p_input = input_item_New( p_intf, qtu( tempMRL[i] ), NULL );
+ /* Take options from the UI, not from what we stored */
+ QStringList optionsList = getOptions().split( " :" );
- /* Insert options */
- while( i + 1 < tempMRL.size() && tempMRL[i + 1].startsWith( ":" ) )
+ /* Insert options */
+ for( int j = 0; j < optionsList.count(); j++ )
+ {
+ QString qs = colon_unescape( optionsList[j] );
+ if( !qs.isEmpty() )
{
- i++;
- input_item_AddOption( p_input, qtu( tempMRL[i] ) );
+ input_item_AddOption( p_input_item, qtu( qs ),
+ VLC_INPUT_OPTION_TRUSTED );
+#ifdef DEBUG_QT
+ msg_Warn( p_intf, "Input option: %s", qtu( qs ) );
+#endif
}
+ }
- /* Switch between enqueuing and starting the item */
- /* FIXME: playlist_AddInput() can fail */
- playlist_AddInput( THEPL, p_input,
+ /* Switch between enqueuing and starting the item */
+ /* FIXME: playlist_AddInput() can fail */
+ playlist_AddInput( THEPL, p_input_item,
PLAYLIST_APPEND | ( b_start ? PLAYLIST_GO : PLAYLIST_PREPARSE ),
PLAYLIST_END, b_pl ? true : false, pl_Unlocked );
- vlc_gc_decref( p_input );
+ vlc_gc_decref( p_input_item );
- /* Do not add the current MRL if playlist_AddInput fail */
- RecentsMRL::getInstance( p_intf )->addRecent( tempMRL[i] );
- }
+ /* Do not add the current MRL if playlist_AddInput fail */
+ RecentsMRL::getInstance( p_intf )->addRecent( itemsMRL[i] );
}
- else
- accept();
}
void OpenDialog::transcode()
void OpenDialog::stream( bool b_transcode_only )
{
- mrl = ui.advancedLineInput->text();
+ QString soutMRL = getMRL( false );
+ if( soutMRL.isEmpty() ) return;
toggleVisible();
- /* Separate the entries */
- QStringList listMRL = SeparateEntries( mrl );
-
- /* We can only take the first entry since we have no idea what
- to do with many files ? Gather ? */
- if( listMRL.size() > 0 )
- {
- /* First item */
- QString soutMRL = listMRL[0];
-
- /* Keep all the :xxx options because they are needed see v4l and dshow */
- for( int i = 1; i < listMRL.size(); i++ )
- {
- if( listMRL[i].at( 0 ) == ':' )
- soutMRL.append( " " + listMRL[i] );
- else
- break;
- }
-
- /* Dbg and send :D */
- msg_Dbg( p_intf, "MRL passed to the Sout: %s", qtu( soutMRL ) );
- THEDP->streamingDialog( this, soutMRL, b_transcode_only );
- }
+ /* Dbg and send :D */
+ msg_Dbg( p_intf, "MRL passed to the Sout: %s", qtu( soutMRL ) );
+ THEDP->streamingDialog( this, soutMRL, b_transcode_only,
+ getOptions().split( " :" ) );
}
-/* Update the MRL */
-void OpenDialog::updateMRL( QString tempMRL )
+/* Update the MRL items from the panels */
+void OpenDialog::updateMRL( const QStringList& item, const QString& tempMRL )
{
- mainMRL = tempMRL;
+ optionsMRL = tempMRL;
+ itemsMRL = item;
updateMRL();
}
+/* Update the complete MRL */
void OpenDialog::updateMRL() {
- mrl = mainMRL;
+ QString mrl = optionsMRL;
if( ui.slaveCheckbox->isChecked() ) {
mrl += " :input-slave=" + ui.slaveText->text();
}
- int i_cache = config_GetInt( p_intf, qtu( storedMethod ) );
- if( i_cache != ui.cacheSpinBox->value() ) {
- mrl += QString( " :%1=%2" ).arg( storedMethod ).
- arg( ui.cacheSpinBox->value() );
- }
- if( ui.startTimeSpinBox->value() ) {
- mrl += " :start-time=" + QString( "%1" ).
- arg( ui.startTimeSpinBox->value() );
+ mrl += QString( " :%1=%2" ).arg( storedMethod ).
+ arg( ui.cacheSpinBox->value() );
+ if( ui.startTimeTimeEdit->time() != ui.startTimeTimeEdit->minimumTime() ) {
+ mrl += QString( " :start-time=%1.%2" )
+ .arg( QString::number(
+ ui.startTimeTimeEdit->minimumTime().secsTo(
+ ui.startTimeTimeEdit->time()
+ ) ) )
+ .arg( ui.startTimeTimeEdit->time().msec(), 3, 10, QChar('0') );
}
ui.advancedLineInput->setText( mrl );
+ ui.mrlLine->setText( itemsMRL.join( " " ) );
}
-void OpenDialog::newCachingMethod( QString method )
+/* Change the caching combobox */
+void OpenDialog::newCachingMethod( const QString& method )
{
if( method != storedMethod ) {
storedMethod = method;
- int i_value = config_GetInt( p_intf, qtu( storedMethod ) );
+ int i_value = var_InheritInteger( p_intf, qtu( storedMethod ) );
ui.cacheSpinBox->setValue( i_value );
}
}
-QStringList OpenDialog::SeparateEntries( QString entries )
+/* Split the entries
+ * FIXME! */
+QStringList OpenDialog::SeparateEntries( const QString& entries )
{
bool b_quotes_mode = false;
QString entry;
int index = 0;
- while( index < entries.size() )
+ while( index < entries.count() )
{
int delim_pos = entries.indexOf( QRegExp( "\\s+|\"" ), index );
- if( delim_pos < 0 ) delim_pos = entries.size() - 1;
+ if( delim_pos < 0 ) delim_pos = entries.count() - 1;
entry += entries.mid( index, delim_pos - index + 1 );
index = delim_pos + 1;
if( !b_quotes_mode && entry.endsWith( "\"" ) )
{
/* Enters quotes mode */
- entry.truncate( entry.size() - 1 );
+ entry.truncate( entry.count() - 1 );
b_quotes_mode = true;
}
else if( b_quotes_mode && entry.endsWith( "\"" ) )
{
/* Finished the quotes mode */
- entry.truncate( entry.size() - 1 );
+ entry.truncate( entry.count() - 1 );
b_quotes_mode = false;
}
else if( !b_quotes_mode && !entry.endsWith( "\"" ) )
{
/* we found a non-quoted standalone string */
- if( index < entries.size() ||
+ if( index < entries.count() ||
entry.endsWith( " " ) || entry.endsWith( "\t" ) ||
entry.endsWith( "\r" ) || entry.endsWith( "\n" ) )
- entry.truncate( entry.size() - 1 );
+ entry.truncate( entry.count() - 1 );
if( !entry.isEmpty() ) entries_array.append( entry );
entry.clear();
}
return entries_array;
}
-void OpenDialog::browseInputSlave()
-{
- OpenDialog *od = new OpenDialog( this, p_intf, true, SELECT );
- od->exec();
- ui.slaveText->setText( od->getMRL() );
- delete od;
-}