]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/dialogs/open.cpp
Fix potential segfault.
[vlc] / modules / gui / qt4 / dialogs / open.cpp
index 0e0b5b212761ce29d1b35af7ad5b2e565e4017d3..3a13ca9e67ecbedc17f71a907cbd0f9dae43338c 100644 (file)
 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 )
 {
     /* Creation */
     if( !instance )
-        instance = new OpenDialog( parent, p_intf, modal, _action_flag );
-    else
+        instance = new OpenDialog( parent, p_intf, b_selectMode, _action_flag );
+    else if( !b_rawInstance )
     {
         /* Request the instance but change small details:
            - Button menu
            - Modality on top of the parent dialog */
+        if( b_selectMode )
+        {
+            instance->setWindowModality( Qt::WindowModal );
+            _action_flag = SELECT; /* This should be useless, but we never know
+                                      if the call is correct */
+        }
         instance->i_action_flag = _action_flag;
         instance->setMenuAction();
-        if( modal ) instance->setWindowModality( Qt::WindowModal );
     }
     return instance;
 }
 
 OpenDialog::OpenDialog( QWidget *parent,
                         intf_thread_t *_p_intf,
-                        bool modal,
+                        bool b_selectMode,
                         int _action_flag )  :  QVLCDialog( parent, _p_intf )
 {
     i_action_flag = _action_flag;
 
-    if( modal ) /* Select mode */
+    if( b_selectMode ) /* Select mode */
     {
         setWindowModality( Qt::WindowModal );
         i_action_flag = SELECT;
@@ -99,7 +104,7 @@ OpenDialog::OpenDialog( QWidget *parent,
     cancelButton = new QPushButton( qtr( "&Cancel" ) );
 
     /* Select Button */
-    selectButton = new QPushButton( qtr( "Select" ) );
+    selectButton = new QPushButton( qtr( "&Select" ) );
 
     /* Menu for the Play button */
     QMenu * openButtonMenu = new QMenu( "Open" );
@@ -142,7 +147,8 @@ OpenDialog::OpenDialog( QWidget *parent,
     CONNECT( ui.slaveText, textChanged( QString ), this, updateMRL() );
     CONNECT( ui.cacheSpinBox, valueChanged( int ), this, updateMRL() );
     CONNECT( ui.startTimeSpinBox, valueChanged( int ), this, updateMRL() );
-    BUTTONACT( ui.advancedCheckBox , toggleAdvancedPanel() );
+    BUTTONACT( ui.advancedCheckBox, toggleAdvancedPanel() );
+    BUTTONACT( ui.slaveBrowseButton, browseInputSlave() );
 
     /* Buttons action */
     BUTTONACT( playButton, selectSlots() );
@@ -190,12 +196,12 @@ void OpenDialog::setMenuAction()
             playButton->setText( qtr( "&Play" ) );
         }
         playButton->show();
-        playButton->setDefault( true );
         selectButton->hide();
+        playButton->setDefault( true );
     }
 }
 
-void OpenDialog::showTab( int i_tab=0 )
+void OpenDialog::showTab( int i_tab )
 {
     ui.Tab->setCurrentIndex( i_tab );
     show();
@@ -243,14 +249,15 @@ void OpenDialog::cancel()
     mainMRL.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,7 +299,7 @@ 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++ )
@@ -313,7 +320,8 @@ void OpenDialog::finish( bool b_enqueue = false )
             /* FIXME: playlist_AddInput() can fail */
             playlist_AddInput( THEPL, p_input,
                 PLAYLIST_APPEND | ( b_start ? PLAYLIST_GO : PLAYLIST_PREPARSE ),
-                PLAYLIST_END, VLC_TRUE, VLC_FALSE );
+                PLAYLIST_END, true, pl_Unlocked );
+            vlc_gc_decref( p_input );
         }
     }
     else
@@ -329,7 +337,9 @@ void OpenDialog::stream( bool b_transcode_only )
 {
     mrl = ui.advancedLineInput->text();
     toggleVisible();
-    THEDP->streamingDialog( this, mrl, b_transcode_only );
+    QStringList listMRL = SeparateEntries( mrl );
+    if( listMRL.size() > 0 )
+    THEDP->streamingDialog( this, SeparateEntries( mrl )[0], b_transcode_only );
 }
 
 /* Update the MRL */
@@ -412,3 +422,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() );
+    delete od;
+}