mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-25 02:09:48 +01:00
Handle ScriptJob tracking completely in the same class. Credits to xhochy for the idea.
This commit is contained in:
parent
cefa97af18
commit
8ecb67178b
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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 );
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ protected:
|
||||
QString id() const;
|
||||
|
||||
void startJob( ScriptJob* scriptJob );
|
||||
void removeJob( ScriptJob* scriptJob );
|
||||
|
||||
private:
|
||||
Q_DECLARE_PRIVATE( ScriptObject )
|
||||
QScopedPointer<ScriptObjectPrivate> d_ptr;
|
||||
|
@ -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 );
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user