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:
parent
218093c467
commit
235f81fa36
@ -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());
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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<QueryMatch> &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<QueryMatch> &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;
|
||||
}
|
||||
|
@ -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<QAction*> 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()) {
|
||||
|
Loading…
Reference in New Issue
Block a user