Backporting 93708-9 by aseigo

Set the compression timeout to 50ms to improve consistency

svn path=/branches/KDE/4.2/kdelibs/; revision=943287
This commit is contained in:
Jacopo De Simoi 2009-03-23 16:06:22 +00:00
parent 1b85d9edb9
commit 01932833a7

View File

@ -138,23 +138,19 @@ public:
int priority() const; int priority() const;
Plasma::AbstractRunner *runner() const; Plasma::AbstractRunner *runner() const;
void setStale();
bool isStale() const;
protected: protected:
void run(); void run();
private: private:
Plasma::RunnerContext m_context; Plasma::RunnerContext m_context;
Plasma::AbstractRunner *m_runner; Plasma::AbstractRunner *m_runner;
bool m_stale;
}; };
FindMatchesJob::FindMatchesJob(Plasma::AbstractRunner *runner, FindMatchesJob::FindMatchesJob(Plasma::AbstractRunner *runner,
Plasma::RunnerContext *context, QObject *parent) Plasma::RunnerContext *context, QObject *parent)
: ThreadWeaver::Job(parent), : ThreadWeaver::Job(parent),
m_context(*context, 0), m_context(*context, 0),
m_runner(runner), m_runner(runner)
m_stale(false)
{ {
if (runner->speed() == Plasma::AbstractRunner::SlowSpeed) { if (runner->speed() == Plasma::AbstractRunner::SlowSpeed) {
assignQueuePolicy(&RunnerRestrictionPolicy::instance()); assignQueuePolicy(&RunnerRestrictionPolicy::instance());
@ -178,16 +174,6 @@ Plasma::AbstractRunner *FindMatchesJob::runner() const
return m_runner; return m_runner;
} }
void FindMatchesJob::setStale()
{
m_stale = true;
}
bool FindMatchesJob::isStale() const
{
return m_stale;
}
/***************************************************** /*****************************************************
* RunnerManager::Private class * RunnerManager::Private class
* *
@ -207,7 +193,7 @@ public:
void scheduleMatchesChanged() void scheduleMatchesChanged()
{ {
matchChangeTimer.start(0); matchChangeTimer.start(50);
} }
void matchesChanged() void matchesChanged()
@ -305,8 +291,17 @@ public:
deferredRun = QueryMatch(0); deferredRun = QueryMatch(0);
tmpRun.run(context); tmpRun.run(context);
} }
searchJobs.removeAll(runJob);
searchJobs.remove(runJob);
oldSearchJobs.remove(runJob);
delete runJob; delete runJob;
if (searchJobs.isEmpty() && context.matches().isEmpty()) {
// we finished our run, and there are no valid matches, and so no
// signal will have been sent out. so we need to emit the signal
// ourselves here
emit q->matchesChanged(context.matches());
}
} }
RunnerManager *q; RunnerManager *q;
@ -314,7 +309,8 @@ public:
RunnerContext context; RunnerContext context;
QTimer matchChangeTimer; QTimer matchChangeTimer;
QHash<QString, AbstractRunner*> runners; QHash<QString, AbstractRunner*> runners;
QList<FindMatchesJob*> searchJobs; QSet<FindMatchesJob*> searchJobs;
QSet<FindMatchesJob*> oldSearchJobs;
// QStringList prioritylist; // QStringList prioritylist;
bool loadAll; bool loadAll;
KConfigGroup config; KConfigGroup config;
@ -390,8 +386,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() && !job->isStale()) { if (job->runner() == runner && !job->isFinished()) {
kDebug() << "!!!!!!!!!!!!!!!!!!! uh oh!"; kDebug() << "deferred run";
d->deferredRun = match; d->deferredRun = match;
return; return;
} }
@ -402,9 +398,6 @@ void RunnerManager::run(const QueryMatch &match)
} }
match.run(d->context); match.run(d->context);
} }
QList<QAction*> RunnerManager::actionsForMatch(const QueryMatch &match) QList<QAction*> RunnerManager::actionsForMatch(const QueryMatch &match)
@ -460,7 +453,7 @@ void RunnerManager::launchQuery(const QString &term, const QString &runnerName)
FindMatchesJob *job = new FindMatchesJob(r, &d->context, this); FindMatchesJob *job = new FindMatchesJob(r, &d->context, this);
connect(job, SIGNAL(done(ThreadWeaver::Job*)), this, SLOT(jobDone(ThreadWeaver::Job*))); connect(job, SIGNAL(done(ThreadWeaver::Job*)), this, SLOT(jobDone(ThreadWeaver::Job*)));
Weaver::instance()->enqueue(job); Weaver::instance()->enqueue(job);
d->searchJobs.append(job); d->searchJobs.insert(job);
} }
} }
} }
@ -518,16 +511,15 @@ void RunnerManager::reset()
// If ThreadWeaver is idle, it is safe to clear previous jobs // If ThreadWeaver is idle, it is safe to clear previous jobs
if (Weaver::instance()->isIdle()) { if (Weaver::instance()->isIdle()) {
qDeleteAll(d->searchJobs); qDeleteAll(d->searchJobs);
d->searchJobs.clear(); qDeleteAll(d->oldSearchJobs);
d->oldSearchJobs.clear();
} else { } else {
Weaver::instance()->dequeue(); Weaver::instance()->dequeue();
// Since we cannot safely delete the jobs, mark them as stale d->oldSearchJobs += d->searchJobs;
// TODO: delete them eventually?
foreach (FindMatchesJob *job, d->searchJobs) {
job->setStale();
}
} }
d->searchJobs.clear();
if (d->deferredRun.isEnabled()) { if (d->deferredRun.isEnabled()) {
//kDebug() << "job actually done, running now **************"; //kDebug() << "job actually done, running now **************";
QueryMatch tmpRun = d->deferredRun; QueryMatch tmpRun = d->deferredRun;