diff --git a/src/libtomahawk/resolvers/ScriptJob.cpp b/src/libtomahawk/resolvers/ScriptJob.cpp index 4a1ff4828..574f582bd 100644 --- a/src/libtomahawk/resolvers/ScriptJob.cpp +++ b/src/libtomahawk/resolvers/ScriptJob.cpp @@ -34,12 +34,7 @@ ScriptJob::ScriptJob( const QString& id, ScriptObject* scriptObject, const QStri ScriptJob::~ScriptJob() { - //FIXME: probably not necessary if we change the inheritance order - if ( !m_id.isEmpty() ) - { - Q_ASSERT( m_scriptObject ); - m_scriptObject->removeJob( this ); - } + emit destroyed( m_id ); } void diff --git a/src/libtomahawk/resolvers/ScriptJob.h b/src/libtomahawk/resolvers/ScriptJob.h index de6ec827a..a8640a992 100644 --- a/src/libtomahawk/resolvers/ScriptJob.h +++ b/src/libtomahawk/resolvers/ScriptJob.h @@ -52,6 +52,8 @@ signals: void done( const QVariantMap& result ); void failed( const QVariantMap& reason ); + void destroyed( const QString& id ); + protected: // TODO: pimple QString m_id; diff --git a/src/libtomahawk/resolvers/ScriptObject.cpp b/src/libtomahawk/resolvers/ScriptObject.cpp index bdf22dbcb..3fbdc08be 100644 --- a/src/libtomahawk/resolvers/ScriptObject.cpp +++ b/src/libtomahawk/resolvers/ScriptObject.cpp @@ -59,14 +59,3 @@ ScriptObject::startJob( ScriptJob* scriptJob ) d->scriptPlugin->startJob( scriptJob ); } - - -void -ScriptObject::removeJob( ScriptJob* scriptJob ) -{ - Q_D( const ScriptObject ); - - Q_ASSERT( d->scriptPlugin ); - d->scriptPlugin->removeJob( scriptJob ); -} - diff --git a/src/libtomahawk/resolvers/ScriptObject.h b/src/libtomahawk/resolvers/ScriptObject.h index 68c7edfc2..118a839a3 100644 --- a/src/libtomahawk/resolvers/ScriptObject.h +++ b/src/libtomahawk/resolvers/ScriptObject.h @@ -46,7 +46,7 @@ protected: QString id() const; void startJob( ScriptJob* scriptJob ); - void removeJob( ScriptJob* scriptJob ); + private: Q_DECLARE_PRIVATE( ScriptObject ) QScopedPointer d_ptr; diff --git a/src/libtomahawk/resolvers/ScriptPlugin.cpp b/src/libtomahawk/resolvers/ScriptPlugin.cpp index cd19b63e4..a713747eb 100644 --- a/src/libtomahawk/resolvers/ScriptPlugin.cpp +++ b/src/libtomahawk/resolvers/ScriptPlugin.cpp @@ -41,19 +41,13 @@ ScriptPlugin::invoke( ScriptObject* scriptObject, const QString& methodName, con QString requestId = requestIdGenerator(); ScriptJob* job = new ScriptJob( requestId, scriptObject, methodName, arguments ); + connect( job, SIGNAL( destroyed( QString ) ), SLOT( onJobDeleted( QString ) ) ); m_jobs.insert( requestId, job ); return job; } -void -ScriptPlugin::removeJob( ScriptJob* job ) -{ - m_jobs.remove( job->id() ); -} - - void ScriptPlugin::reportScriptJobResult( const QVariantMap& result ) { @@ -100,3 +94,10 @@ ScriptPlugin::registerScriptPlugin( const QString& type, const QString& objectId Q_ASSERT( false ); } } + + +void +ScriptPlugin::onJobDeleted( const QString& jobId ) +{ + m_jobs.remove( jobId ); +} diff --git a/src/libtomahawk/resolvers/ScriptPlugin.h b/src/libtomahawk/resolvers/ScriptPlugin.h index add808f2c..5653be986 100644 --- a/src/libtomahawk/resolvers/ScriptPlugin.h +++ b/src/libtomahawk/resolvers/ScriptPlugin.h @@ -43,11 +43,12 @@ public: ScriptJob* invoke( ScriptObject* scriptObject, const QString& methodName, const QVariantMap& arguments ); virtual void startJob( ScriptJob* scriptJob ) = 0; - void removeJob( ScriptJob* ); void reportScriptJobResult( const QVariantMap& result ); void registerScriptPlugin( const QString& type, const QString& objectId ); +private slots: + void onJobDeleted( const QString& jobId ); private: // TODO: pimple, might be renamed before tho QHash< QString, ScriptJob* > m_jobs;