]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/input_manager.cpp
Qt: Avoid using dangling pointers and fix memleaks
[vlc] / modules / gui / qt4 / input_manager.cpp
index aa87c808c2572a4938cf8b0aa6263deed45a643a..c07f712f26da722f3a756d8d37977deaf4a84e3d 100644 (file)
 #endif
 
 #include "input_manager.hpp"
-#include <vlc_keys.h>
-#include <vlc_url.h>
-#include <vlc_strings.h>
-#include <vlc_aout.h>
+#include "recents.hpp"
+
+#include <vlc_keys.h>           /* ACTION_ID */
+#include <vlc_url.h>            /* decode_URI */
+#include <vlc_strings.h>        /* str_format_meta */
+#include <vlc_aout.h>           /* audio_output_t */
 
 #include <QApplication>
 #include <QFile>
 #include <QDir>
 #include <QSignalMapper>
+#include <QMessageBox>
 
 #include <assert.h>
 
@@ -108,6 +111,7 @@ void InputManager::setInput( input_thread_t *_p_input )
         msg_Dbg( p_intf, "IM: Setting an input" );
         vlc_object_hold( p_input );
         addCallbacks();
+
         UpdateStatus();
         UpdateName();
         UpdateArt();
@@ -117,6 +121,22 @@ void InputManager::setInput( input_thread_t *_p_input )
 
         p_item = input_GetItem( p_input );
         emit rateChanged( var_GetFloat( p_input, "rate" ) );
+
+        /* Get Saved Time */
+        int i_time = RecentsMRL::getInstance( p_intf )->time( p_item->psz_uri );
+        if( i_time > 0 )
+        {
+            THEMIM->togglePlayPause();
+
+            if( QMessageBox::question( NULL,
+                        _("Continue playback?"),
+                        _("Do you want to restart the playback where left off?"),
+                        QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes )
+                    == QMessageBox::Yes )
+                var_SetTime( p_input, "time", (int64_t)i_time * 1000 );
+
+            THEMIM->togglePlayPause();
+        }
     }
     else
     {
@@ -134,6 +154,15 @@ void InputManager::delInput()
     if( !p_input ) return;
     msg_Dbg( p_intf, "IM: Deleting the input" );
 
+    /* Save time / position */
+    float f_pos = var_GetFloat( p_input , "position" );
+    int64_t i_time = var_GetTime( p_input, "time");
+    int i_length = var_GetTime( p_input , "length" ) / CLOCK_FREQ;
+    if( f_pos < 0.05 || f_pos > 0.95 || i_length < 60) {
+        i_time = -1;
+    }
+    RecentsMRL::getInstance( p_intf )->setTime( p_item->psz_uri, i_time );
+
     delCallbacks();
     i_old_playing_status = END_S;
     p_item               = NULL;
@@ -167,6 +196,7 @@ void InputManager::delInput()
 
     /* Reset all InfoPanels but stats */
     emit artChanged( NULL );
+    emit artChanged( "" );
     emit infoChanged( NULL );
     emit currentMetaChanged( (input_item_t *)NULL );
 
@@ -467,7 +497,7 @@ void InputManager::UpdateName()
 
     /* Try to get the nowplaying */
     char *format = var_InheritString( p_intf, "input-title-format" );
-    char *formated = str_format_meta( THEPL, format );
+    char *formated = str_format_meta( p_input, format );
     free( format );
     name = qfu(formated);
     free( formated );
@@ -635,7 +665,7 @@ void InputManager::UpdateCaching()
     }
 }
 
-void InputManager::requestArtUpdate( input_item_t *p_item )
+void InputManager::requestArtUpdate( input_item_t *p_item, bool b_forced )
 {
     bool b_current_item = false;
     if ( !p_item && hasInput() )
@@ -647,13 +677,15 @@ void InputManager::requestArtUpdate( input_item_t *p_item )
     if ( p_item )
     {
         /* check if it has already been enqueued */
-        if ( p_item->p_meta )
+        if ( p_item->p_meta && !b_forced )
         {
             int status = vlc_meta_GetStatus( p_item->p_meta );
             if ( status & ( ITEM_ART_NOTFOUND|ITEM_ART_FETCHED ) )
                 return;
         }
-        playlist_AskForArtEnqueue( pl_Get(p_intf), p_item );
+        libvlc_ArtRequest( p_intf->p_libvlc, p_item,
+                           (b_forced) ? META_REQUEST_OPTION_SCOPE_ANY
+                                      : META_REQUEST_OPTION_NONE );
         /* No input will signal the cover art to update,
              * let's do it ourself */
         if ( b_current_item )
@@ -950,11 +982,8 @@ void InputManager::setAtoB()
 /* Function called regularly when in an AtoB loop */
 void InputManager::AtoBLoop( float, int64_t i_time, int )
 {
-    if( timeB )
-    {
-        if( i_time >= timeB || i_time < timeA )
-            var_SetTime( THEMIM->getInput(), "time" , timeA );
-    }
+    if( timeB && i_time >= timeB )
+        var_SetTime( THEMIM->getInput(), "time" , timeA );
 }
 
 /**********************************************************************
@@ -989,7 +1018,7 @@ MainInputManager::MainInputManager( intf_thread_t *_p_intf )
               im, setInput( input_thread_t * ) );
 
     /* initialize p_input (an input can already be running) */
-    p_input = playlist_CurrentInput( pl_Get(p_intf) );
+    p_input = playlist_CurrentInput( THEPL );
     if( p_input )
         emit inputChanged( p_input );
 
@@ -1057,7 +1086,7 @@ void MainInputManager::customEvent( QEvent *event )
 
     if( p_input != NULL )
         vlc_object_release( p_input );
-    p_input = playlist_CurrentInput( pl_Get(p_intf) );
+    p_input = playlist_CurrentInput( THEPL );
     emit inputChanged( p_input );
 }
 
@@ -1165,11 +1194,12 @@ void MainInputManager::loopRepeatLoopStatus()
 void MainInputManager::activatePlayQuit( bool b_exit )
 {
     var_SetBool( THEPL, "play-and-exit", b_exit );
+    config_PutInt( p_intf, "play-and-exit", b_exit );
 }
 
 bool MainInputManager::getPlayExitState()
 {
-    return var_GetBool( THEPL, "play-and-exit" );
+    return var_InheritBool( THEPL, "play-and-exit" );
 }
 
 bool MainInputManager::hasEmptyPlaylist()
@@ -1187,6 +1217,7 @@ static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
                         vlc_value_t oldval, vlc_value_t val, void *param )
 {
     VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
+    VLC_UNUSED( val );
 
     MainInputManager *mim = (MainInputManager*)param;