From 235f81fa368e8bf48e4b5be84b81bd5925d4bf3f Mon Sep 17 00:00:00 2001 From: Jacopo De Simoi Date: Tue, 3 Mar 2009 08:02:13 +0000 Subject: [PATCH] Added a stale flag to searchJobs; less pollution from old queries; fixed a misplaced brace in previous commit that made krunner unable to run any command :( svn path=/trunk/KDE/kdelibs/; revision=934467 --- private/runnerjobs.cpp | 3 ++- private/runnerjobs.h | 4 ++++ runnercontext.cpp | 21 +++++++++++++++++---- runnermanager.cpp | 24 ++++++++++++++++++++---- 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/private/runnerjobs.cpp b/private/runnerjobs.cpp index b1bc58b5f..caba338c5 100644 --- a/private/runnerjobs.cpp +++ b/private/runnerjobs.cpp @@ -127,7 +127,8 @@ FindMatchesJob::FindMatchesJob(Plasma::AbstractRunner *runner, : ThreadWeaver::Job(parent), m_context(context), m_runner(runner), - m_timer(0) + m_timer(0), + m_stale(false) { if (runner->speed() == Plasma::AbstractRunner::SlowSpeed) { assignQueuePolicy(&DelayedRunnerPolicy::instance()); diff --git a/private/runnerjobs.h b/private/runnerjobs.h index e6258ac48..a0d88dc8b 100644 --- a/private/runnerjobs.h +++ b/private/runnerjobs.h @@ -107,6 +107,9 @@ public: int priority() const; Plasma::AbstractRunner* runner() const; + void setStale(); + bool isStale() const; + QTimer* delayTimer() const; void setDelayTimer(QTimer *timer); @@ -118,6 +121,7 @@ private: Plasma::RunnerContext *m_context; Plasma::AbstractRunner *m_runner; QTimer *m_timer; + bool m_stale; }; } diff --git a/runnercontext.cpp b/runnercontext.cpp index cfe84569b..4967816a3 100644 --- a/runnercontext.cpp +++ b/runnercontext.cpp @@ -242,8 +242,15 @@ void RunnerContext::reset() { // We will detach if we are a copy of someone. But we will reset // if we are the 'main' context others copied from. Resetting - // one RunnerContext makes all the copies oneobsolete. + // one RunnerContext makes all the copies obsolete. + + d->q = 0; //we need to mark the q pointer of the detached RunnerContextPrivate + //as dirty on detach to avoid receiving results for old queries + d.detach(); + + d->q = this; //now that we detached the d pointer we need to mark its q pointer as + //this to receive the signals // we still have to remove all the matches, since if the // ref count was 1 (e.g. only the RunnerContext is using @@ -251,7 +258,7 @@ void RunnerContext::reset() if (!d->matches.isEmpty()) { d->matchesById.clear(); d->matches.clear(); - emit d->q->matchesChanged(); + emit matchesChanged(); } d->term.clear(); @@ -294,7 +301,7 @@ bool RunnerContext::addMatches(const QString &term, const QList &mat { Q_UNUSED(term) - if (matches.isEmpty()) { + if (matches.isEmpty() || (!d->q)) { //Bail out if the query is empty or the qptr is dirty return false; } @@ -314,6 +321,7 @@ bool RunnerContext::addMatches(const QString &term, const QList &mat // we always want to sent the signal of the object that created // the d pointer emit d->q->matchesChanged(); + return true; } @@ -321,12 +329,17 @@ bool RunnerContext::addMatch(const QString &term, const QueryMatch &match) { Q_UNUSED(term) + if (!d->q) { // Bail out if the qptr is dirty + return false; + } + LOCK_FOR_WRITE(this) d->matches.append(match); d->matchesById.insert(match.id(), &d->matches.at(d->matches.size() - 1)); UNLOCK(this); //kDebug()<< "added match" << match->text(); - emit d->q->matchesChanged(); + emit d->q->matchesChanged(); + return true; } diff --git a/runnermanager.cpp b/runnermanager.cpp index 7efa7bdd1..df6f5b9e5 100644 --- a/runnermanager.cpp +++ b/runnermanager.cpp @@ -194,6 +194,16 @@ public: KConfigGroup config; }; +void FindMatchesJob::setStale() +{ + m_stale = true; +} + +bool FindMatchesJob::isStale() const +{ + return m_stale; +} + /***************************************************** * RunnerManager::Public class * @@ -264,8 +274,8 @@ void RunnerManager::run(const QueryMatch &match) AbstractRunner *runner = match.runner(); foreach (FindMatchesJob *job, d->searchJobs) { - if (job->runner() == runner && !job->isFinished()) { - //kDebug() << "!!!!!!!!!!!!!!!!!!! uh oh!"; + if (job->runner() == runner && !job->isFinished() && !job->isStale()) { + kDebug() << "!!!!!!!!!!!!!!!!!!! uh oh!"; d->deferredRun = match; return; } @@ -273,11 +283,12 @@ void RunnerManager::run(const QueryMatch &match) if (d->deferredRun.isValid()) { d->deferredRun = QueryMatch(0); - + } + match.run(d->context); - } + } QList RunnerManager::actionsForMatch(const QueryMatch &match) @@ -399,6 +410,11 @@ void RunnerManager::reset() d->searchJobs.clear(); } else { Weaver::instance()->dequeue(); + // Since we cannot safely delete the jobs, mark them as stale + // TODO: delete them eventually? + foreach (FindMatchesJob *job, d->searchJobs) { + job->setStale(); + } } if (d->deferredRun.isEnabled()) {