]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/dialogs/open.cpp
Fix segfault when canceling the open dialog. Patch by RĂ©mi Duraffort.
[vlc] / modules / gui / qt4 / dialogs / open.cpp
index 0f5eeb835956df593453e32374b892e7d9b25ef5..3449a820b156123885ff71a6ada63bf4ea37dfe9 100644 (file)
@@ -2,7 +2,7 @@
  * open.cpp : Advanced open dialog
  *****************************************************************************
  * Copyright (C) 2006-2007 the VideoLAN team
- * $Id: streaminfo.cpp 16816 2006-09-23 20:56:52Z jb $
+ * $Id$
  *
  * Authors: Jean-Baptiste Kempf <jb@videolan.org>
  *
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
+#include "input_manager.hpp"
+
+#include "dialogs/open.hpp"
+#include "components/open.hpp"
+
 #include <QTabWidget>
 #include <QGridLayout>
 #include <QFileDialog>
 #include <QRegExp>
 #include <QMenu>
-#include "dialogs/open.hpp"
-#include "components/open.hpp"
-
-#include "qt4.hpp"
-#include "util/qvlcframe.hpp"
-
-#include "input_manager.hpp"
 
 OpenDialog *OpenDialog::instance = NULL;
 
@@ -42,6 +40,7 @@ OpenDialog::OpenDialog( QWidget *parent, intf_thread_t *_p_intf, bool modal,
     setModal( modal );
     i_action_flag = _action_flag;
 
+    /* Basic Creation of the Window */
     ui.setupUi( this );
     setWindowTitle( qtr("Open" ) );
     resize( 410, 300);
@@ -52,21 +51,30 @@ OpenDialog::OpenDialog( QWidget *parent, intf_thread_t *_p_intf, bool modal,
     netOpenPanel = new NetOpenPanel( ui.Tab, p_intf );
     captureOpenPanel = new CaptureOpenPanel( ui.Tab, 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_CAPTURE_TAB, captureOpenPanel,
                                 qtr( "Capture &Device" ) );
 
+    /* Hide the Slave input widgets */
+    ui.slaveLabel->hide();
+    ui.slaveText->hide();
+    ui.slaveBrowseButton->hide();
+
     /* Hide the advancedPanel */
-    ui.advancedFrame->hide();
+    if(! config_GetInt( p_intf, "qt-adv-options") )
+        ui.advancedFrame->hide();
+    else
+        ui.advancedCheckBox->setCheckState( Qt::Checked );
 
     /* Buttons Creation */
-    QSizePolicy buttonSizePolicy( static_cast<QSizePolicy::Policy>(7),
-                                  static_cast<QSizePolicy::Policy>(1) );
+    QSizePolicy buttonSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
     buttonSizePolicy.setHorizontalStretch(0);
     buttonSizePolicy.setVerticalStretch(0);
 
+    /* Play Button */
     playButton = new QToolButton( this );
     playButton->setText( qtr( "&Play" ) );
     playButton->setSizePolicy( buttonSizePolicy );
@@ -74,10 +82,12 @@ OpenDialog::OpenDialog( QWidget *parent, intf_thread_t *_p_intf, bool modal,
     playButton->setPopupMode( QToolButton::MenuButtonPopup );
     playButton->setToolButtonStyle( Qt::ToolButtonTextOnly );
 
-    cancelButton = new QToolButton();
+    /* Cancel Button */
+    cancelButton = new QPushButton();
     cancelButton->setText( qtr( "&Cancel" ) );
     cancelButton->setSizePolicy( buttonSizePolicy );
 
+    /* Menu for the Play button */
     QMenu * openButtonMenu = new QMenu( "Open" );
     openButtonMenu->addAction( qtr("&Enqueue"), this, SLOT( enqueue() ),
                                     QKeySequence( "Alt+E") );
@@ -85,7 +95,7 @@ OpenDialog::OpenDialog( QWidget *parent, intf_thread_t *_p_intf, bool modal,
                                     QKeySequence( "Alt+P" ) );
     openButtonMenu->addAction( qtr("&Stream"), this, SLOT( stream() ) ,
                                     QKeySequence( "Alt+S" ) );
-    openButtonMenu->addAction( qtr("&Convert"), this, SLOT( transcode( ) ) ,
+    openButtonMenu->addAction( qtr("&Convert"), this, SLOT( transcode() ) ,
                                     QKeySequence( "Alt+C" ) );
 
     playButton->setMenu( openButtonMenu );
@@ -99,16 +109,16 @@ OpenDialog::OpenDialog( QWidget *parent, intf_thread_t *_p_intf, bool modal,
     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( captureOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
 
     CONNECT( fileOpenPanel, methodChanged( QString ),
-                                                 this, newMethod(QString) );
+                                                 this, newCachingMethod(QString) );
     CONNECT( netOpenPanel, methodChanged( QString ),
-                                                 this, newMethod(QString) );
+                                                 this, newCachingMethod(QString) );
     CONNECT( discOpenPanel, methodChanged( QString ),
-                                                 this, newMethod(QString) );
-    /* FIXME CAPTURE */
+                                                 this, newCachingMethod(QString) );
+    CONNECT( captureOpenPanel, methodChanged( QString ),
+                                                 this, newCachingMethod(QString) );
 
     /* Advanced frame Connects */
     CONNECT( ui.slaveText, textChanged(QString), this, updateMRL());
@@ -123,10 +133,9 @@ OpenDialog::OpenDialog( QWidget *parent, intf_thread_t *_p_intf, bool modal,
     /* At creation time, modify the default buttons */
     if ( i_action_flag ) setMenuAction();
 
-
     /* Initialize caching */
     storedMethod = "";
-    newMethod("file-caching");
+    newCachingMethod("file-caching");
 
     mainHeight = advHeight = 0;
 }
@@ -146,9 +155,9 @@ void OpenDialog::setMenuAction()
             break;
         case OPEN_AND_SAVE:
             playButton->setText( qtr("&Convert / Save") );
-            BUTTONACT( playButton, stream( true ) );
+            BUTTONACT( playButton, transcode() );
             break;
-        case ENQUEUE:
+        case OPEN_AND_ENQUEUE:
             playButton->setText( qtr("&Enqueue") );
             BUTTONACT( playButton, enqueue() );
             break;
@@ -159,15 +168,39 @@ void OpenDialog::setMenuAction()
    }
 }
 
-void OpenDialog::showTab(int i_tab=0)
+void OpenDialog::showTab( int i_tab=0 )
 {
     this->show();
-    ui.Tab->setCurrentIndex(i_tab);
+    ui.Tab->setCurrentIndex( i_tab );
 }
 
 void OpenDialog::signalCurrent() {
-    if (ui.Tab->currentWidget() != NULL) {
-        (dynamic_cast<OpenPanel*>(ui.Tab->currentWidget()))->updateMRL();
+    if (ui.Tab->currentWidget() != NULL)
+        (dynamic_cast<OpenPanel *>( ui.Tab->currentWidget() ))->updateMRL();
+}
+
+void OpenDialog::toggleAdvancedPanel()
+{
+    //FIXME does not work under Windows
+    if( ui.advancedFrame->isVisible() ) {
+        ui.advancedFrame->hide();
+#ifndef WIN32
+        setMinimumHeight(1);
+        resize( width(), mainHeight );
+#endif
+    } else {
+#ifndef WIN32
+        if( mainHeight == 0 )
+            mainHeight = height();
+#endif
+
+        ui.advancedFrame->show();
+#ifndef WIN32
+        if( advHeight == 0 ) {
+            advHeight = height() - mainHeight;
+        }
+        resize( width(), mainHeight + advHeight );
+#endif
     }
 }
 
@@ -178,10 +211,10 @@ void OpenDialog::signalCurrent() {
 /* If Cancel is pressed or escaped */
 void OpenDialog::cancel()
 {
-    fileOpenPanel->clear();
-    this->toggleVisible();
-    if( isModal() )
-        reject();
+    for( int i = 0; i < OPEN_TAB_MAX; i++ )
+        dynamic_cast<OpenPanel*>(ui.Tab->widget( i ))->clear();
+    toggleVisible();
+    if( isModal() ) reject();
 }
 
 /* If EnterKey is pressed */
@@ -223,7 +256,7 @@ void OpenDialog::stream( bool b_transcode_only )
 
 void OpenDialog::finish( bool b_enqueue = false )
 {
-    this->toggleVisible();
+    toggleVisible();
     mrl = ui.advancedLineInput->text();
 
     if( !isModal() )
@@ -233,18 +266,17 @@ void OpenDialog::finish( bool b_enqueue = false )
         {
             bool b_start = !i && !b_enqueue;
             input_item_t *p_input;
-            const char *psz_utf8 = qtu( tempMRL[i] );
 
-            p_input = input_ItemNew( p_intf, psz_utf8, NULL );
+            p_input = input_ItemNew( p_intf, qtu( tempMRL[i] ), NULL );
 
             /* Insert options */
             while( i + 1 < tempMRL.size() && tempMRL[i + 1].startsWith( ":" ) )
             {
                 i++;
-                psz_utf8 = qtu( tempMRL[i] );
-                input_ItemAddOption( p_input, psz_utf8 );
+                input_ItemAddOption( p_input, qtu( tempMRL[i] ) );
             }
 
+            /* Switch between enqueuing and starting the item */
             if( b_start )
             {
                 playlist_AddInput( THEPL, p_input,
@@ -254,7 +286,7 @@ void OpenDialog::finish( bool b_enqueue = false )
             else
             {
                 playlist_AddInput( THEPL, p_input,
-                                   PLAYLIST_APPEND|PLAYLIST_PREPARSE,
+                                   PLAYLIST_APPEND | PLAYLIST_PREPARSE,
                                    PLAYLIST_END, VLC_TRUE, VLC_FALSE );
             }
         }
@@ -263,24 +295,12 @@ void OpenDialog::finish( bool b_enqueue = false )
         accept();
 }
 
-void OpenDialog::toggleAdvancedPanel()
-{
-    //FIXME does not work under Windows
-    if (ui.advancedFrame->isVisible()) {
-        ui.advancedFrame->hide();
-        setMinimumHeight(1);
-        resize( width(), mainHeight );
-
-    } else {
-        if( mainHeight == 0 )
-            mainHeight = height();
 
-        ui.advancedFrame->show();
-        if( advHeight == 0 ) {
-            advHeight = height() - mainHeight;
-        }
-        resize( width(), mainHeight + advHeight );
-    }
+/* Update the MRL */
+void OpenDialog::updateMRL( QString tempMRL )
+{
+    mainMRL = tempMRL;
+    updateMRL();
 }
 
 void OpenDialog::updateMRL() {
@@ -300,18 +320,12 @@ void OpenDialog::updateMRL() {
     ui.advancedLineInput->setText(mrl);
 }
 
-void OpenDialog::updateMRL(QString tempMRL)
-{
-    mainMRL = tempMRL;
-    updateMRL();
-}
-
-void OpenDialog::newMethod(QString method)
+void OpenDialog::newCachingMethod( QString method )
 {
     if( method != storedMethod ) {
         storedMethod = method;
-        int i_value = config_GetInt( p_intf, qta(storedMethod) );
-        ui.cacheSpinBox->setValue(i_value);
+        int i_value = config_GetInt( p_intf, qta( storedMethod ) );
+        ui.cacheSpinBox->setValue( i_value );
     }
 }