From c840dbbf785db05c74f2da05a64a3f9d8ee5eff0 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Mon, 5 Jan 2015 04:11:17 +0100 Subject: [PATCH] Remove script objects automatically from ScriptAccount when they are deleted --- src/libtomahawk/resolvers/ScriptAccount.cpp | 8 ++++++++ src/libtomahawk/resolvers/ScriptAccount.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/libtomahawk/resolvers/ScriptAccount.cpp b/src/libtomahawk/resolvers/ScriptAccount.cpp index 4a97a72a9..cdf19ebef 100644 --- a/src/libtomahawk/resolvers/ScriptAccount.cpp +++ b/src/libtomahawk/resolvers/ScriptAccount.cpp @@ -92,6 +92,7 @@ ScriptAccount::registerScriptPlugin( const QString& type, const QString& objectI if( !object ) { object = new ScriptObject( objectId, this ); + connect( object, SIGNAL( destroyed( QObject* ) ), SLOT( onScriptObjectDeleted( QObject* ) ) ); m_objects.insert( objectId, object ); } @@ -99,6 +100,13 @@ ScriptAccount::registerScriptPlugin( const QString& type, const QString& objectI } +void +ScriptAccount::onScriptObjectDeleted( QObject* scriptObject ) +{ + m_objects.remove( m_objects.key( static_cast< ScriptObject* >( scriptObject ) ) ); +} + + void ScriptAccount::scriptPluginFactory( const QString& type, ScriptObject* object ) { diff --git a/src/libtomahawk/resolvers/ScriptAccount.h b/src/libtomahawk/resolvers/ScriptAccount.h index b3b37c6b2..a95ddcca2 100644 --- a/src/libtomahawk/resolvers/ScriptAccount.h +++ b/src/libtomahawk/resolvers/ScriptAccount.h @@ -55,6 +55,8 @@ public: private slots: void onJobDeleted( const QString& jobId ); + void onScriptObjectDeleted( QObject* scriptObject ); + private: // TODO: pimple, might be renamed before tho QString m_name; QHash< QString, ScriptJob* > m_jobs;