Remove cruft and fix style in RunnerManager
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=859706
This commit is contained in:
parent
057ad8b01a
commit
d0863e43e8
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2007 Ryan P. Bitanga <ryan.bitanga@gmail.com>
|
* Copyright (C) 2006 Aaron Seigo <aseigo@kde.org>
|
||||||
* Copyright (C) 2006 Aaron Seigo <aseigo@kde.org>
|
* Copyright (C) 2007 Ryan P. Bitanga <ryan.bitanga@gmail.com>
|
||||||
* Copyright 2008 Jordi Polo <mumismo@gmail.com>
|
* Copyright (2) 2008 Jordi Polo <mumismo@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License as
|
* it under the terms of the GNU Library General Public License as
|
||||||
@ -68,14 +68,13 @@ public:
|
|||||||
return m_cap;
|
return m_cap;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool canRun(Job* job);
|
bool canRun(Job *job);
|
||||||
void free(Job* job);
|
void free(Job *job);
|
||||||
void release(Job* job);
|
void release(Job *job);
|
||||||
void destructed(Job* job);
|
void destructed(Job *job);
|
||||||
private:
|
private:
|
||||||
RunnerRestrictionPolicy();
|
RunnerRestrictionPolicy();
|
||||||
|
|
||||||
// QHash<QString, int> m_runCounts;
|
|
||||||
int m_count;
|
int m_count;
|
||||||
int m_cap;
|
int m_cap;
|
||||||
QMutex m_mutex;
|
QMutex m_mutex;
|
||||||
@ -98,43 +97,35 @@ RunnerRestrictionPolicy& RunnerRestrictionPolicy::instance()
|
|||||||
return policy;
|
return policy;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RunnerRestrictionPolicy::canRun(Job* job)
|
bool RunnerRestrictionPolicy::canRun(Job *job)
|
||||||
{
|
{
|
||||||
Q_UNUSED(job)
|
Q_UNUSED(job)
|
||||||
QMutexLocker l(&m_mutex);
|
QMutexLocker l(&m_mutex);
|
||||||
// QString type = job->objectName();
|
if (m_count > m_cap) {
|
||||||
if (m_count/*m_runCounts.value(type)*/ > m_cap) {
|
|
||||||
// kDebug() << "Denying job " << type << " because of " << m_count/*m_runCounts[type]*/ << " current jobs" << endl;
|
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
// m_runCounts[type]++;
|
|
||||||
++m_count;
|
++m_count;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunnerRestrictionPolicy::free(Job* job)
|
void RunnerRestrictionPolicy::free(Job *job)
|
||||||
{
|
{
|
||||||
Q_UNUSED(job)
|
Q_UNUSED(job)
|
||||||
QMutexLocker l(&m_mutex);
|
QMutexLocker l(&m_mutex);
|
||||||
// QString type = job->objectName();
|
|
||||||
--m_count;
|
--m_count;
|
||||||
// if (m_runCounts.value(type)) {
|
|
||||||
// m_runCounts[type]--;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunnerRestrictionPolicy::release(Job* job)
|
void RunnerRestrictionPolicy::release(Job *job)
|
||||||
{
|
{
|
||||||
free(job);
|
free(job);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunnerRestrictionPolicy::destructed(Job* job)
|
void RunnerRestrictionPolicy::destructed(Job *job)
|
||||||
{
|
{
|
||||||
Q_UNUSED(job)
|
Q_UNUSED(job)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************
|
/*****************************************************
|
||||||
* FindMatchesJob class
|
* FindMatchesJob class
|
||||||
* Class to run queries in different threads
|
* Class to run queries in different threads
|
||||||
@ -142,7 +133,7 @@ void RunnerRestrictionPolicy::destructed(Job* job)
|
|||||||
class FindMatchesJob : public Job
|
class FindMatchesJob : public Job
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FindMatchesJob(Plasma::AbstractRunner* runner, Plasma::RunnerContext* context, QObject* parent = 0);
|
FindMatchesJob(Plasma::AbstractRunner *runner, Plasma::RunnerContext *context, QObject *parent = 0);
|
||||||
|
|
||||||
int priority() const;
|
int priority() const;
|
||||||
Plasma::AbstractRunner* runner() const;
|
Plasma::AbstractRunner* runner() const;
|
||||||
@ -150,12 +141,12 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
void run();
|
void run();
|
||||||
private:
|
private:
|
||||||
Plasma::RunnerContext* m_context;
|
Plasma::RunnerContext *m_context;
|
||||||
Plasma::AbstractRunner* m_runner;
|
Plasma::AbstractRunner *m_runner;
|
||||||
};
|
};
|
||||||
|
|
||||||
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),
|
m_context(context),
|
||||||
m_runner(runner)
|
m_runner(runner)
|
||||||
@ -208,7 +199,7 @@ public:
|
|||||||
emit q->matchesChanged(context.matches());
|
emit q->matchesChanged(context.matches());
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadConfiguration(KConfigGroup& conf)
|
void loadConfiguration(KConfigGroup &conf)
|
||||||
{
|
{
|
||||||
config = conf;
|
config = conf;
|
||||||
|
|
||||||
@ -247,7 +238,7 @@ public:
|
|||||||
if (!loaded) {
|
if (!loaded) {
|
||||||
QString api = service->property("X-Plasma-API").toString();
|
QString api = service->property("X-Plasma-API").toString();
|
||||||
QString error;
|
QString error;
|
||||||
AbstractRunner* runner = 0;
|
AbstractRunner *runner = 0;
|
||||||
|
|
||||||
if (api.isEmpty()) {
|
if (api.isEmpty()) {
|
||||||
QVariantList args;
|
QVariantList args;
|
||||||
@ -269,7 +260,7 @@ public:
|
|||||||
}
|
}
|
||||||
} else if (loaded) {
|
} else if (loaded) {
|
||||||
//Remove runner
|
//Remove runner
|
||||||
AbstractRunner* runner = runners.take(runnerName);
|
AbstractRunner *runner = runners.take(runnerName);
|
||||||
kDebug() << "Removing runner: " << runnerName;
|
kDebug() << "Removing runner: " << runnerName;
|
||||||
delete runner;
|
delete runner;
|
||||||
}
|
}
|
||||||
@ -278,7 +269,7 @@ public:
|
|||||||
//kDebug() << "All runners loaded, total:" << runners.count();
|
//kDebug() << "All runners loaded, total:" << runners.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
void jobDone(ThreadWeaver::Job* job)
|
void jobDone(ThreadWeaver::Job *job)
|
||||||
{
|
{
|
||||||
FindMatchesJob *runJob = static_cast<FindMatchesJob*>(job);
|
FindMatchesJob *runJob = static_cast<FindMatchesJob*>(job);
|
||||||
if (deferredRun.isEnabled() && runJob->runner() == deferredRun.runner()) {
|
if (deferredRun.isEnabled() && runJob->runner() == deferredRun.runner()) {
|
||||||
@ -308,7 +299,7 @@ public:
|
|||||||
*
|
*
|
||||||
*****************************************************/
|
*****************************************************/
|
||||||
RunnerManager::RunnerManager(QObject *parent)
|
RunnerManager::RunnerManager(QObject *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
d(new RunnerManagerPrivate(this))
|
d(new RunnerManagerPrivate(this))
|
||||||
{
|
{
|
||||||
KConfigGroup config(KGlobal::config(), "PlasmaRunnerManager");
|
KConfigGroup config(KGlobal::config(), "PlasmaRunnerManager");
|
||||||
@ -317,8 +308,8 @@ RunnerManager::RunnerManager(QObject *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RunnerManager::RunnerManager(KConfigGroup& config, QObject *parent)
|
RunnerManager::RunnerManager(KConfigGroup &config, QObject *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
d(new RunnerManagerPrivate(this))
|
d(new RunnerManagerPrivate(this))
|
||||||
{
|
{
|
||||||
d->loadConfiguration(config);
|
d->loadConfiguration(config);
|
||||||
@ -416,10 +407,10 @@ void RunnerManager::launchQuery(const QString &term, const QString &runnerName)
|
|||||||
if (!runnerName.isEmpty()) {
|
if (!runnerName.isEmpty()) {
|
||||||
runable.append(runner(runnerName));
|
runable.append(runner(runnerName));
|
||||||
} else {
|
} else {
|
||||||
runable = d->runners.values();
|
runable = d->runners.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Plasma::AbstractRunner* r, runable) {
|
foreach (Plasma::AbstractRunner *r, runable) {
|
||||||
if ((r->ignoredTypes() & d->context.type()) == 0) {
|
if ((r->ignoredTypes() & d->context.type()) == 0) {
|
||||||
// kDebug() << "launching" << r->name();
|
// kDebug() << "launching" << r->name();
|
||||||
FindMatchesJob *job = new FindMatchesJob(r, &d->context, this);
|
FindMatchesJob *job = new FindMatchesJob(r, &d->context, this);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2006-2007 Ryan P. Bitanga <ryan.bitanga@gmail.com>
|
* Copyright (C) 2006 Aaron Seigo <aseigo@kde.org>
|
||||||
* Copyright (C) 2006 Aaron Seigo <aseigo@kde.org>
|
* Copyright (C) 2007 Ryan P. Bitanga <ryan.bitanga@gmail.com>
|
||||||
* Copyright 2008 Jordi Polo <mumismo@gmail.com>
|
* Copyright (C) 2008 Jordi Polo <mumismo@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License as
|
* it under the terms of the GNU Library General Public License as
|
||||||
@ -34,7 +34,7 @@ namespace Plasma
|
|||||||
{
|
{
|
||||||
class QueryMatch;
|
class QueryMatch;
|
||||||
class AbstractRunner;
|
class AbstractRunner;
|
||||||
class RunnerContext;
|
class RunnerContext;
|
||||||
class RunnerManagerPrivate;
|
class RunnerManagerPrivate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,13 +50,13 @@ class PLASMA_EXPORT RunnerManager : public QObject
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit RunnerManager(QObject *parent=0);
|
explicit RunnerManager(QObject *parent=0);
|
||||||
explicit RunnerManager(KConfigGroup& config, QObject *parent=0);
|
explicit RunnerManager(KConfigGroup &config, QObject *parent=0);
|
||||||
~RunnerManager();
|
~RunnerManager();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds and returns a loaded runner or NULL
|
* Finds and returns a loaded runner or NULL
|
||||||
* @arg name the name of the runner
|
* @arg name the name of the runner
|
||||||
* @return Pointer to the runner
|
* @return Pointer to the runner
|
||||||
*/
|
*/
|
||||||
AbstractRunner* runner(const QString &name) const;
|
AbstractRunner* runner(const QString &name) const;
|
||||||
|
|
||||||
@ -96,14 +96,14 @@ class PLASMA_EXPORT RunnerManager : public QObject
|
|||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
/**
|
/**
|
||||||
* Launch a query, this will create threads and return inmediately.
|
* Launch a query, this will create threads and return inmediately.
|
||||||
* When the information will be available can be known using the
|
* When the information will be available can be known using the
|
||||||
* matchesChanged signal.
|
* matchesChanged signal.
|
||||||
*
|
*
|
||||||
* @arg term the term we want to find matches for
|
* @arg term the term we want to find matches for
|
||||||
* @arg runner optional, if only one specific runner is to be used
|
* @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
|
* Convenience version of above
|
||||||
@ -119,7 +119,7 @@ class PLASMA_EXPORT RunnerManager : public QObject
|
|||||||
* @arg runner the runner we will use, it is mandatory
|
* @arg runner the runner we will use, it is mandatory
|
||||||
* @return 0 if nothing was launched, 1 if launched.
|
* @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
|
* Convenience version of above
|
||||||
|
Loading…
Reference in New Issue
Block a user