Remove cruft and fix style in RunnerManager

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=859706
This commit is contained in:
Ryan P. Bitanga 2008-09-11 06:37:09 +00:00
parent 057ad8b01a
commit d0863e43e8
2 changed files with 37 additions and 46 deletions

View File

@ -1,7 +1,7 @@
/*
* Copyright (C) 2007 Ryan P. Bitanga <ryan.bitanga@gmail.com>
* Copyright (C) 2006 Aaron Seigo <aseigo@kde.org>
* Copyright 2008 Jordi Polo <mumismo@gmail.com>
* Copyright (C) 2007 Ryan P. Bitanga <ryan.bitanga@gmail.com>
* Copyright (2) 2008 Jordi Polo <mumismo@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
@ -68,14 +68,13 @@ public:
return m_cap;
}
bool canRun(Job* job);
void free(Job* job);
void release(Job* job);
void destructed(Job* job);
bool canRun(Job *job);
void free(Job *job);
void release(Job *job);
void destructed(Job *job);
private:
RunnerRestrictionPolicy();
// QHash<QString, int> m_runCounts;
int m_count;
int m_cap;
QMutex m_mutex;
@ -98,43 +97,35 @@ RunnerRestrictionPolicy& RunnerRestrictionPolicy::instance()
return policy;
}
bool RunnerRestrictionPolicy::canRun(Job* job)
bool RunnerRestrictionPolicy::canRun(Job *job)
{
Q_UNUSED(job)
QMutexLocker l(&m_mutex);
// QString type = job->objectName();
if (m_count/*m_runCounts.value(type)*/ > m_cap) {
// kDebug() << "Denying job " << type << " because of " << m_count/*m_runCounts[type]*/ << " current jobs" << endl;
if (m_count > m_cap) {
return false;
} else {
// m_runCounts[type]++;
++m_count;
return true;
}
}
void RunnerRestrictionPolicy::free(Job* job)
void RunnerRestrictionPolicy::free(Job *job)
{
Q_UNUSED(job)
QMutexLocker l(&m_mutex);
// QString type = job->objectName();
--m_count;
// if (m_runCounts.value(type)) {
// m_runCounts[type]--;
// }
}
void RunnerRestrictionPolicy::release(Job* job)
void RunnerRestrictionPolicy::release(Job *job)
{
free(job);
}
void RunnerRestrictionPolicy::destructed(Job* job)
void RunnerRestrictionPolicy::destructed(Job *job)
{
Q_UNUSED(job)
}
/*****************************************************
* FindMatchesJob class
* Class to run queries in different threads
@ -142,7 +133,7 @@ void RunnerRestrictionPolicy::destructed(Job* job)
class FindMatchesJob : public Job
{
public:
FindMatchesJob(Plasma::AbstractRunner* runner, Plasma::RunnerContext* context, QObject* parent = 0);
FindMatchesJob(Plasma::AbstractRunner *runner, Plasma::RunnerContext *context, QObject *parent = 0);
int priority() const;
Plasma::AbstractRunner* runner() const;
@ -150,12 +141,12 @@ public:
protected:
void run();
private:
Plasma::RunnerContext* m_context;
Plasma::AbstractRunner* m_runner;
Plasma::RunnerContext *m_context;
Plasma::AbstractRunner *m_runner;
};
FindMatchesJob::FindMatchesJob(Plasma::AbstractRunner* runner,
Plasma::RunnerContext* context, QObject* parent)
FindMatchesJob::FindMatchesJob(Plasma::AbstractRunner *runner,
Plasma::RunnerContext *context, QObject *parent)
: ThreadWeaver::Job(parent),
m_context(context),
m_runner(runner)
@ -208,7 +199,7 @@ public:
emit q->matchesChanged(context.matches());
}
void loadConfiguration(KConfigGroup& conf)
void loadConfiguration(KConfigGroup &conf)
{
config = conf;
@ -247,7 +238,7 @@ public:
if (!loaded) {
QString api = service->property("X-Plasma-API").toString();
QString error;
AbstractRunner* runner = 0;
AbstractRunner *runner = 0;
if (api.isEmpty()) {
QVariantList args;
@ -269,7 +260,7 @@ public:
}
} else if (loaded) {
//Remove runner
AbstractRunner* runner = runners.take(runnerName);
AbstractRunner *runner = runners.take(runnerName);
kDebug() << "Removing runner: " << runnerName;
delete runner;
}
@ -278,7 +269,7 @@ public:
//kDebug() << "All runners loaded, total:" << runners.count();
}
void jobDone(ThreadWeaver::Job* job)
void jobDone(ThreadWeaver::Job *job)
{
FindMatchesJob *runJob = static_cast<FindMatchesJob*>(job);
if (deferredRun.isEnabled() && runJob->runner() == deferredRun.runner()) {
@ -317,7 +308,7 @@ RunnerManager::RunnerManager(QObject *parent)
}
RunnerManager::RunnerManager(KConfigGroup& config, QObject *parent)
RunnerManager::RunnerManager(KConfigGroup &config, QObject *parent)
: QObject(parent),
d(new RunnerManagerPrivate(this))
{
@ -419,7 +410,7 @@ void RunnerManager::launchQuery(const QString &term, const QString &runnerName)
runable = d->runners.values();
}
foreach (Plasma::AbstractRunner* r, runable) {
foreach (Plasma::AbstractRunner *r, runable) {
if ((r->ignoredTypes() & d->context.type()) == 0) {
// kDebug() << "launching" << r->name();
FindMatchesJob *job = new FindMatchesJob(r, &d->context, this);

View File

@ -1,7 +1,7 @@
/*
* Copyright (C) 2006-2007 Ryan P. Bitanga <ryan.bitanga@gmail.com>
* Copyright (C) 2006 Aaron Seigo <aseigo@kde.org>
* Copyright 2008 Jordi Polo <mumismo@gmail.com>
* Copyright (C) 2007 Ryan P. Bitanga <ryan.bitanga@gmail.com>
* Copyright (C) 2008 Jordi Polo <mumismo@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
@ -50,7 +50,7 @@ class PLASMA_EXPORT RunnerManager : public QObject
public:
explicit RunnerManager(QObject *parent=0);
explicit RunnerManager(KConfigGroup& config, QObject *parent=0);
explicit RunnerManager(KConfigGroup &config, QObject *parent=0);
~RunnerManager();
/**
@ -103,7 +103,7 @@ class PLASMA_EXPORT RunnerManager : public QObject
* @arg term the term we want to find matches for
* @arg runner optional, if only one specific runner is to be used
*/
void launchQuery(const QString &term, const QString & runnerName);
void launchQuery(const QString &term, const QString &runnerName);
/**
* Convenience version of above
@ -119,7 +119,7 @@ class PLASMA_EXPORT RunnerManager : public QObject
* @arg runner the runner we will use, it is mandatory
* @return 0 if nothing was launched, 1 if launched.
*/
bool execQuery(const QString &term, const QString & runnerName);
bool execQuery(const QString &term, const QString &runnerName);
/**
* Convenience version of above