]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/dialogs/open.cpp
Fix advanced panel height saving. Fixes #3858
[vlc] / modules / gui / qt4 / dialogs / open.cpp
index 1bda5aa0b65675ce7249e71b1e21668df2647b16..d755fddc12502268dff82fcc7f4d8cd2ff452157 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * open.cpp : Advanced open dialog
  *****************************************************************************
- * Copyright © 2006-2007 the VideoLAN team
+ * Copyright © 2006-2009 the VideoLAN team
  * $Id$
  *
  * Authors: Jean-Baptiste Kempf <jb@videolan.org>
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
-#include "input_manager.hpp"
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include "dialogs/open.hpp"
 
+#include "dialogs_provider.hpp"
+
+#include "recents.hpp"
+#include "util/qt_dirs.hpp"
+
 #include <QTabWidget>
 #include <QGridLayout>
-#include <QFileDialog>
 #include <QRegExp>
 #include <QMenu>
 
+#define DEBUG_QT 1
+
 OpenDialog *OpenDialog::instance = NULL;
 
 OpenDialog* OpenDialog::getInstance( QWidget *parent, intf_thread_t *p_intf,
-        int _action_flag, bool modal )
+        bool b_rawInstance, int _action_flag, bool b_selectMode, bool _b_pl )
 {
     /* Creation */
     if( !instance )
-        instance = new OpenDialog( parent, p_intf, modal, _action_flag );
-    else
+        instance = new OpenDialog( parent, p_intf, b_selectMode,
+                                   _action_flag, _b_pl );
+    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 )
+            _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();
-        if( modal ) instance->setWindowModality( Qt::WindowModal );
     }
     return instance;
 }
 
 OpenDialog::OpenDialog( QWidget *parent,
                         intf_thread_t *_p_intf,
-                        bool modal,
-                        int _action_flag )  :  QVLCDialog( parent, _p_intf )
+                        bool b_selectMode,
+                        int _action_flag,
+                        bool _b_pl)  :  QVLCDialog( parent, _p_intf )
 {
     i_action_flag = _action_flag;
+    b_pl =_b_pl;
 
-    if( modal ) /* Select mode */
-    {
-        setWindowModality( Qt::WindowModal );
+    if( b_selectMode ) /* Select mode */
         i_action_flag = SELECT;
-    }
 
     /* Basic Creation of the Window */
     ui.setupUi( this );
-    setWindowTitle( qtr( "Open" ) );
-    resize( 410, 300 );
+    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();
@@ -88,27 +103,14 @@ OpenDialog::OpenDialog( QWidget *parent,
     ui.slaveBrowseButton->hide();
 
     /* Buttons Creation */
-    QSizePolicy buttonSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
-    buttonSizePolicy.setHorizontalStretch( 0 );
-    buttonSizePolicy.setVerticalStretch( 0 );
-
     /* Play Button */
-    playButton = new QToolButton;
-    playButton->setText( qtr( "&Play" ) );
-    playButton->setSizePolicy( buttonSizePolicy );
-    playButton->setMinimumSize( QSize( 90, 0 ) );
-    playButton->setPopupMode( QToolButton::MenuButtonPopup );
-    playButton->setToolButtonStyle( Qt::ToolButtonTextOnly );
+    playButton = ui.playButton;
 
     /* Cancel Button */
-    cancelButton = new QToolButton;
-    cancelButton->setText( qtr( "&Cancel" ) );
-    cancelButton->setSizePolicy( buttonSizePolicy );
+    cancelButton = new QPushButton( qtr( "&Cancel" ) );
 
     /* Select Button */
-    selectButton = new QToolButton;
-    selectButton->setText( qtr( "Select" ) );
-    selectButton->setSizePolicy( buttonSizePolicy );
+    selectButton = new QPushButton( qtr( "&Select" ) );
 
     /* Menu for the Play button */
     QMenu * openButtonMenu = new QMenu( "Open" );
@@ -124,7 +126,6 @@ OpenDialog::OpenDialog( QWidget *parent,
     playButton->setMenu( openButtonMenu );
 
     /* Add the three Buttons */
-    ui.buttonsBox->addButton( playButton, QDialogButtonBox::ActionRole );
     ui.buttonsBox->addButton( selectButton, QDialogButtonBox::AcceptRole );
     ui.buttonsBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
 
@@ -132,27 +133,33 @@ OpenDialog::OpenDialog( QWidget *parent,
     setMenuAction();
 
     /* Force MRL update on tab change */
-    CONNECT( ui.Tab, currentChanged( int ), this, signalCurrent() );
-
-    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( ui.Tab, currentChanged( int ), this, signalCurrent( int ) );
+
+    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() );
-    BUTTONACT( ui.advancedCheckBox , toggleAdvancedPanel() );
+    CONNECT( ui.startTimeDoubleSpinBox, valueChanged( double ), this, updateMRL() );
+    BUTTONACT( ui.advancedCheckBox, toggleAdvancedPanel() );
+    BUTTONACT( ui.slaveBrowseButton, browseInputSlave() );
 
     /* Buttons action */
     BUTTONACT( playButton, selectSlots() );
@@ -160,18 +167,37 @@ OpenDialog::OpenDialog( QWidget *parent,
     BUTTONACT( cancelButton, cancel() );
 
     /* Hide the advancedPanel */
-    if( !config_GetInt( p_intf, "qt-adv-options" ) )
+    if( !var_InheritBool( p_intf, "qt-adv-options" ) )
+    {
         ui.advancedFrame->hide();
+        ui.advancedFrame->setEnabled( false );
+    }
     else
         ui.advancedCheckBox->setChecked( true );
 
     /* Initialize caching */
     storedMethod = "";
     newCachingMethod( "file-caching" );
+
+    setMinimumSize( sizeHint() );
+    setMaximumWidth( 900 );
+    resize( getSettings()->value( "opendialog-size", QSize( 500, 490 ) ).toSize() );
 }
 
 OpenDialog::~OpenDialog()
-{}
+{
+    getSettings()->setValue( "opendialog-size", size() -
+                 ( ui.advancedFrame->isEnabled() ?
+                   QSize(0, ui.advancedFrame->height()) : QSize(0, 0) ) );
+}
+
+/* Used by VLM dialog and inputSlave selection */
+QString OpenDialog::getMRL( bool b_all )
+{
+    if( itemsMRL.size() == 0 ) return "";
+    return b_all ? itemsMRL[0] + ui.advancedLineInput->text()
+                 : itemsMRL[0];
+}
 
 /* Finish the dialog and decide if you open another one after */
 void OpenDialog::setMenuAction()
@@ -180,6 +206,7 @@ void OpenDialog::setMenuAction()
     {
         playButton->hide();
         selectButton->show();
+        selectButton->setDefault( true );
     }
     else
     {
@@ -203,15 +230,18 @@ void OpenDialog::setMenuAction()
     }
 }
 
-void OpenDialog::showTab( int i_tab=0 )
+void OpenDialog::showTab( int i_tab )
 {
+    if( i_tab == OPEN_CAPTURE_TAB ) captureOpenPanel->initialize();
     ui.Tab->setCurrentIndex( i_tab );
     show();
 }
 
 /* Function called on signal currentChanged triggered */
-void OpenDialog::signalCurrent()
+void OpenDialog::signalCurrent( int i_tab )
 {
+    if( i_tab == OPEN_CAPTURE_TAB ) captureOpenPanel->initialize();
+
     if( ui.Tab->currentWidget() != NULL )
         ( dynamic_cast<OpenPanel *>( ui.Tab->currentWidget() ) )->updateMRL();
 }
@@ -221,12 +251,18 @@ void OpenDialog::toggleAdvancedPanel()
     if( ui.advancedFrame->isVisible() )
     {
         ui.advancedFrame->hide();
-        //FIXME: Clear Bug here. Qt ?
-        resize( size().width(), size().height() - ui.advancedFrame->height() );
+        ui.advancedFrame->setEnabled( false );
+        if( size().isValid() )
+            resize( size().width(), size().height()
+                    - ui.advancedFrame->height() );
     }
     else
     {
         ui.advancedFrame->show();
+        ui.advancedFrame->setEnabled( true );
+        if( size().isValid() )
+            resize( size().width(), size().height()
+                    + ui.advancedFrame->height() );
     }
 }
 
@@ -241,18 +277,19 @@ void OpenDialog::cancel()
         dynamic_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( windowModality() != Qt::NonModal ) reject();
+    if( i_action_flag == SELECT ) reject();
     else hide();
 }
 
 /* If EnterKey is pressed */
 void OpenDialog::close()
 {
-    if( windowModality() != Qt::NonModal )
+    /* If in Select Mode, accept instead of selecting a Slot */
+    if( i_action_flag == SELECT )
         accept();
     else
         selectSlots();
@@ -292,42 +329,58 @@ void OpenDialog::enqueue()
 void OpenDialog::finish( bool b_enqueue = false )
 {
     toggleVisible();
-    mrl = ui.advancedLineInput->text();
 
-    if( windowModality() == Qt::NonModal )
+    if( i_action_flag == SELECT )
     {
-        QStringList tempMRL = SeparateEntries( mrl );
-        for( size_t i = 0; i < tempMRL.size(); i++ )
-        {
-            bool b_start = !i && !b_enqueue;
-            input_item_t *p_input;
+        accept();
+        return;
+    }
 
-            p_input = input_ItemNew( p_intf, qtu( tempMRL[i] ), NULL );
+    /* Sort alphabetically */
+    itemsMRL.sort();
 
-            /* Insert options */
-            while( i + 1 < tempMRL.size() && tempMRL[i + 1].startsWith( ":" ) )
-            {
-                i++;
-                input_ItemAddOption( p_input, qtu( tempMRL[i] ) );
-            }
+    /* Go through the item list */
+    for( int i = 0; i < itemsMRL.size(); i++ )
+    {
+        bool b_start = !i && !b_enqueue;
 
-            /* Switch between enqueuing and starting the item */
-            if( b_start )
-            {
-                playlist_AddInput( THEPL, p_input,
-                                   PLAYLIST_APPEND | PLAYLIST_GO,
-                                   PLAYLIST_END, VLC_TRUE, VLC_FALSE );
-            }
-            else
+        input_item_t *p_input;
+        char* psz_uri = make_URI( qtu( itemsMRL[i] ), "file" );
+        p_input = input_item_New( p_intf, psz_uri, NULL );
+        free( psz_uri );
+
+        /* Insert options only for the first element.
+           We don't know how to edit that anyway. */
+        if( i == 0 )
+        {
+            /* Take options from the UI, not from what we stored */
+            QStringList optionsList = ui.advancedLineInput->text().split( " :" );
+
+            /* Insert options */
+            for( int j = 0; j < optionsList.size(); j++ )
             {
-                playlist_AddInput( THEPL, p_input,
-                                   PLAYLIST_APPEND | PLAYLIST_PREPARSE,
-                                   PLAYLIST_END, VLC_TRUE, VLC_FALSE );
+                QString qs = colon_unescape( optionsList[j] );
+                if( !qs.isEmpty() )
+                {
+                    input_item_AddOption( p_input, 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,
+                PLAYLIST_APPEND | ( b_start ? PLAYLIST_GO : PLAYLIST_PREPARSE ),
+                PLAYLIST_END, b_pl ? true : false, pl_Unlocked );
+        vlc_gc_decref( p_input );
+
+        /* Do not add the current MRL if playlist_AddInput fail */
+        RecentsMRL::getInstance( p_intf )->addRecent( itemsMRL[i] );
     }
-    else
-        accept();
 }
 
 void OpenDialog::transcode()
@@ -337,45 +390,48 @@ void OpenDialog::transcode()
 
 void OpenDialog::stream( bool b_transcode_only )
 {
-    mrl = ui.advancedLineInput->text();
+    QString soutMRL = getMRL( false );
+    if( soutMRL.isEmpty() ) return;
     toggleVisible();
-    THEDP->streamingDialog( this, mrl, 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,
+                            ui.advancedLineInput->text().split( " :" ) );
 }
 
 /* Update the MRL */
-void OpenDialog::updateMRL( QString tempMRL )
+void OpenDialog::updateMRL( const QStringList& item, const QString& tempMRL )
 {
-    mainMRL = tempMRL;
+    optionsMRL = tempMRL;
+    itemsMRL = item;
     updateMRL();
 }
 
 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, qta( 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.startTimeDoubleSpinBox->value() ) {
+        mrl += " :start-time=" + QString::number( ui.startTimeDoubleSpinBox->value() );
     }
     ui.advancedLineInput->setText( mrl );
+    ui.mrlLine->setText( itemsMRL.join( " " ) );
 }
 
-void OpenDialog::newCachingMethod( QString method )
+void OpenDialog::newCachingMethod( const QString& method )
 {
     if( method != storedMethod ) {
         storedMethod = method;
-        int i_value = config_GetInt( p_intf, qta( storedMethod ) );
+        int i_value = var_InheritInteger( p_intf, qtu( storedMethod ) );
         ui.cacheSpinBox->setValue( i_value );
     }
 }
 
-QStringList OpenDialog::SeparateEntries( QString entries )
+QStringList OpenDialog::SeparateEntries( const QString& entries )
 {
     bool b_quotes_mode = false;
 
@@ -422,3 +478,11 @@ QStringList OpenDialog::SeparateEntries( QString entries )
 
     return entries_array;
 }
+
+void OpenDialog::browseInputSlave()
+{
+    OpenDialog *od = new OpenDialog( this, p_intf, true, SELECT );
+    od->exec();
+    ui.slaveText->setText( od->getMRL( false ) );
+    delete od;
+}