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
This commit is contained in:
Jacopo De Simoi 2009-03-03 08:02:13 +00:00
parent 218093c467
commit 235f81fa36
4 changed files with 43 additions and 9 deletions

View File

@ -127,7 +127,8 @@ FindMatchesJob::FindMatchesJob(Plasma::AbstractRunner *runner,
: ThreadWeaver::Job(parent), : ThreadWeaver::Job(parent),
m_context(context), m_context(context),
m_runner(runner), m_runner(runner),
m_timer(0) m_timer(0),
m_stale(false)
{ {
if (runner->speed() == Plasma::AbstractRunner::SlowSpeed) { if (runner->speed() == Plasma::AbstractRunner::SlowSpeed) {
assignQueuePolicy(&DelayedRunnerPolicy::instance()); assignQueuePolicy(&DelayedRunnerPolicy::instance());

View File

@ -107,6 +107,9 @@ public:
int priority() const; int priority() const;
Plasma::AbstractRunner* runner() const; Plasma::AbstractRunner* runner() const;
void setStale();
bool isStale() const;
QTimer* delayTimer() const; QTimer* delayTimer() const;
void setDelayTimer(QTimer *timer); void setDelayTimer(QTimer *timer);
@ -118,6 +121,7 @@ private:
Plasma::RunnerContext *m_context; Plasma::RunnerContext *m_context;
Plasma::AbstractRunner *m_runner; Plasma::AbstractRunner *m_runner;
QTimer *m_timer; QTimer *m_timer;
bool m_stale;
}; };
} }

View File

@ -242,16 +242,23 @@ void RunnerContext::reset()
{ {
// We will detach if we are a copy of someone. But we will 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 // 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.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 // we still have to remove all the matches, since if the
// ref count was 1 (e.g. only the RunnerContext is using // ref count was 1 (e.g. only the RunnerContext is using
// the dptr) then we won't get a copy made // the dptr) then we won't get a copy made
if (!d->matches.isEmpty()) { if (!d->matches.isEmpty()) {
d->matchesById.clear(); d->matchesById.clear();
d->matches.clear(); d->matches.clear();
emit d->q->matchesChanged(); emit matchesChanged();
} }
d->term.clear(); d->term.clear();
@ -294,7 +301,7 @@ bool RunnerContext::addMatches(const QString &term, const QList<QueryMatch> &mat
{ {
Q_UNUSED(term) 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; return false;
} }
@ -314,6 +321,7 @@ bool RunnerContext::addMatches(const QString &term, const QList<QueryMatch> &mat
// we always want to sent the signal of the object that created // we always want to sent the signal of the object that created
// the d pointer // the d pointer
emit d->q->matchesChanged(); emit d->q->matchesChanged();
return true; return true;
} }
@ -321,6 +329,10 @@ bool RunnerContext::addMatch(const QString &term, const QueryMatch &match)
{ {
Q_UNUSED(term) Q_UNUSED(term)
if (!d->q) { // Bail out if the qptr is dirty
return false;
}
LOCK_FOR_WRITE(this) LOCK_FOR_WRITE(this)
d->matches.append(match); d->matches.append(match);
d->matchesById.insert(match.id(), &d->matches.at(d->matches.size() - 1)); d->matchesById.insert(match.id(), &d->matches.at(d->matches.size() - 1));
@ -328,6 +340,7 @@ bool RunnerContext::addMatch(const QString &term, const QueryMatch &match)
//kDebug()<< "added match" << match->text(); //kDebug()<< "added match" << match->text();
emit d->q->matchesChanged(); emit d->q->matchesChanged();
return true; return true;
} }

View File

@ -194,6 +194,16 @@ public:
KConfigGroup config; KConfigGroup config;
}; };
void FindMatchesJob::setStale()
{
m_stale = true;
}
bool FindMatchesJob::isStale() const
{
return m_stale;
}
/***************************************************** /*****************************************************
* RunnerManager::Public class * RunnerManager::Public class
* *
@ -264,8 +274,8 @@ void RunnerManager::run(const QueryMatch &match)
AbstractRunner *runner = match.runner(); AbstractRunner *runner = match.runner();
foreach (FindMatchesJob *job, d->searchJobs) { foreach (FindMatchesJob *job, d->searchJobs) {
if (job->runner() == runner && !job->isFinished()) { if (job->runner() == runner && !job->isFinished() && !job->isStale()) {
//kDebug() << "!!!!!!!!!!!!!!!!!!! uh oh!"; kDebug() << "!!!!!!!!!!!!!!!!!!! uh oh!";
d->deferredRun = match; d->deferredRun = match;
return; return;
} }
@ -273,11 +283,12 @@ void RunnerManager::run(const QueryMatch &match)
if (d->deferredRun.isValid()) { if (d->deferredRun.isValid()) {
d->deferredRun = QueryMatch(0); d->deferredRun = QueryMatch(0);
}
match.run(d->context); match.run(d->context);
}
} }
QList<QAction*> RunnerManager::actionsForMatch(const QueryMatch &match) QList<QAction*> RunnerManager::actionsForMatch(const QueryMatch &match)
@ -399,6 +410,11 @@ void RunnerManager::reset()
d->searchJobs.clear(); d->searchJobs.clear();
} else { } else {
Weaver::instance()->dequeue(); 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()) { if (d->deferredRun.isEnabled()) {