diff --git a/private/runnerjobs.cpp b/private/runnerjobs.cpp index 7a3c5d6bb..87eb7a22f 100644 --- a/private/runnerjobs.cpp +++ b/private/runnerjobs.cpp @@ -167,6 +167,24 @@ Plasma::AbstractRunner* FindMatchesJob::runner() const return m_runner; } +DelayedJobCleaner::DelayedJobCleaner(QSet jobs, ThreadWeaver::WeaverInterface *weaver) + : QObject(weaver), + m_weaver(weaver), + m_jobs(jobs) +{ + connect(m_weaver, SIGNAL(finished()), this, SLOT(checkIfFinished())); +} + +void DelayedJobCleaner::checkIfFinished() +{ + if (m_weaver->isIdle()) { + qDeleteAll(m_jobs); + m_jobs.clear(); + deleteLater(); + } +} + + } // Plasma namespace // #include "runnerjobs.moc" diff --git a/private/runnerjobs.h b/private/runnerjobs.h index cee60eefb..70fa52111 100644 --- a/private/runnerjobs.h +++ b/private/runnerjobs.h @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -120,6 +121,21 @@ private: QTimer *m_timer; }; +class DelayedJobCleaner : public QObject +{ +public: + DelayedJobCleaner(QSet jobs, ThreadWeaver::WeaverInterface *weaver); + +private Q_SLOTS: + void jobDone(ThreadWeaver::Job*); + void checkIfFinished(); + //connect(ThreadWeaver::instance(), SIGNAL(finished()), this, SLOT(checkIfFinished())); + +private: + ThreadWeaver::WeaverInterface *m_weaver; + QSet m_jobs; +}; + } #endif diff --git a/runnermanager.cpp b/runnermanager.cpp index 6a57d0975..d96e219d5 100644 --- a/runnermanager.cpp +++ b/runnermanager.cpp @@ -160,7 +160,12 @@ public: void jobDone(ThreadWeaver::Job *job) { - FindMatchesJob *runJob = static_cast(job); + FindMatchesJob *runJob = dynamic_cast(job); + + if (!runJob) { + return; + } + if (deferredRun.isEnabled() && runJob->runner() == deferredRun.runner()) { //kDebug() << "job actually done, running now **************"; QueryMatch tmpRun = deferredRun; @@ -189,6 +194,17 @@ public: QObject::connect(dummy, SIGNAL(done(ThreadWeaver::Job*)), dummy, SLOT(deleteLater())); } + void checkIfFinished() + { + if (Weaver::instance()->isIdle()) { + qDeleteAll(searchJobs); + searchJobs.clear(); + qDeleteAll(oldSearchJobs); + oldSearchJobs.clear(); + q->deleteLater(); + } + } + // Delay in ms before slow runners are allowed to run static const int slowRunDelay = 400; @@ -230,6 +246,10 @@ RunnerManager::RunnerManager(KConfigGroup &c, QObject *parent) RunnerManager::~RunnerManager() { + if (!qApp->closingDown && (!d->searchJobs.isEmpty() || !d->oldSearchJobs.isEmpty())) { + new DelayedJobCleaner(d->searchJobs + d->oldSearchJobs, Weaver::instance()); + } + delete d; }