diff --git a/src/runnerjobs.cpp b/src/runnerjobs.cpp --- a/src/runnerjobs.cpp +++ b/src/runnerjobs.cpp @@ -120,13 +120,23 @@ // Jobs //////////////////// +class FindMatchesJobInternal : public Job +{ +public: + FindMatchesJobInternal(FindMatchesJob* q) : q(q) {} + + void run(ThreadWeaver::JobPointer self, ThreadWeaver::Thread * thread) override; + +private: + FindMatchesJob* const q; +}; + FindMatchesJob::FindMatchesJob(Plasma::AbstractRunner *runner, Plasma::RunnerContext *context, QObject *) - : ThreadWeaver::Job(), + : ThreadWeaver::QObjectDecorator(new FindMatchesJobInternal(this)), m_context(*context, nullptr), m_runner(runner), - m_timer(nullptr), - m_decorator(new ThreadWeaver::QObjectDecorator(this, true)) + m_timer(nullptr) { QMutexLocker l(mutex()); Q_UNUSED(l); if (runner->speed() == Plasma::AbstractRunner::SlowSpeed) { @@ -150,12 +160,12 @@ m_timer = timer; } -void FindMatchesJob::run(ThreadWeaver::JobPointer, ThreadWeaver::Thread*) +void FindMatchesJobInternal::run(ThreadWeaver::JobPointer, ThreadWeaver::Thread*) { // qCDebug(KRUNNER) << "Running match for " << m_runner->objectName() // << " in Thread " << thread()->id() << endl; - if (m_context.isValid()) { - m_runner->performMatch(m_context); + if (q->m_context.isValid()) { + q->m_runner->performMatch(q->m_context); } } @@ -178,7 +188,7 @@ connect(m_weaver, SIGNAL(finished()), this, SLOT(checkIfFinished())); for (auto it = m_jobs.constBegin(); it != m_jobs.constEnd(); ++it) { - connect((*it)->decorator(), &ThreadWeaver::QObjectDecorator::done, this, &DelayedJobCleaner::jobDone); + connect(it->data(), &ThreadWeaver::QObjectDecorator::done, this, &DelayedJobCleaner::jobDone); } } diff --git a/src/runnerjobs_p.h b/src/runnerjobs_p.h --- a/src/runnerjobs_p.h +++ b/src/runnerjobs_p.h @@ -90,7 +90,7 @@ * FindMatchesJob class * Class to run queries in different threads */ -class FindMatchesJob : public Job +class FindMatchesJob : public ThreadWeaver::QObjectDecorator { public: FindMatchesJob(Plasma::AbstractRunner *runner, @@ -102,16 +102,12 @@ QTimer* delayTimer() const; void setDelayTimer(QTimer *timer); - ThreadWeaver::QObjectDecorator* decorator() const { return m_decorator; } protected: - void run(ThreadWeaver::JobPointer self, ThreadWeaver::Thread* thread) override; - -private: + friend class FindMatchesJobInternal; Plasma::RunnerContext m_context; Plasma::AbstractRunner *m_runner; QTimer *m_timer; - ThreadWeaver::QObjectDecorator* m_decorator; }; class DelayedJobCleaner : public QObject diff --git a/src/runnermanager.cpp b/src/runnermanager.cpp --- a/src/runnermanager.cpp +++ b/src/runnermanager.cpp @@ -35,6 +35,8 @@ #include #include #include +#include +#include #include "dbusrunner_p.h" #include "runnerjobs_p.h" @@ -251,7 +253,7 @@ while (it != searchJobs.end()) { auto &job = (*it); if (deadRunners.contains(job->runner())) { - QObject::disconnect(job->decorator(), SIGNAL(done(ThreadWeaver::JobPointer)), q, SLOT(jobDone(ThreadWeaver::JobPointer))); + QObject::disconnect(job.data(), SIGNAL(done(ThreadWeaver::JobPointer)), q, SLOT(jobDone(ThreadWeaver::JobPointer))); it = searchJobs.erase(it); deadJobs.insert(job); } else { @@ -355,6 +357,7 @@ emit q->matchesChanged(context.matches()); } + teardownRequested = true; checkTearDown(); } @@ -423,7 +426,7 @@ { if ((runner->ignoredTypes() & context.type()) == 0) { QSharedPointer job(new FindMatchesJob(runner, &context, Queue::instance())); - QObject::connect(job->decorator(), SIGNAL(done(ThreadWeaver::JobPointer)), q, SLOT(jobDone(ThreadWeaver::JobPointer))); + QObject::connect(job.data(), SIGNAL(done(ThreadWeaver::JobPointer)), q, SLOT(jobDone(ThreadWeaver::JobPointer))); if (runner->speed() == AbstractRunner::SlowSpeed) { job->setDelayTimer(&delayTimer); } @@ -844,6 +847,7 @@ } d->context.reset(); + emit queryFinished(); } } // Plasma namespace