ws, style fixes, use booleans rather than ints when returning a boolean

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=803034
This commit is contained in:
Aaron J. Seigo 2008-05-01 17:42:34 +00:00
parent 4c1e5b8e9d
commit da4f6c6e72
2 changed files with 29 additions and 33 deletions

View File

@ -190,14 +190,14 @@ public:
Private(RunnerManager *parent) Private(RunnerManager *parent)
: q(parent) : q(parent)
{
connect(&context, SIGNAL(matchesChanged()), q, SIGNAL(matchesChanged()));
connect(Weaver::instance(), SIGNAL(finished()), q, SIGNAL(matchesCompleted()));
}
void configure(KConfigGroup& conf)
{ {
config=conf; connect(&context, SIGNAL(matchesChanged()), q, SIGNAL(matchesChanged()));
connect(Weaver::instance(), SIGNAL(finished()), q, SIGNAL(matchesCompleted()));
}
void loadConfiguration(KConfigGroup& conf)
{
config = conf;
//The number of threads used scales with the number of processors. //The number of threads used scales with the number of processors.
const int numProcs = qMax(Solid::Device::listFromType(Solid::DeviceInterface::Processor).count(), 1); const int numProcs = qMax(Solid::Device::listFromType(Solid::DeviceInterface::Processor).count(), 1);
@ -212,15 +212,14 @@ public:
//If set, this list defines which runners won't be used at runtime //If set, this list defines which runners won't be used at runtime
blacklist = config.readEntry("blacklist", QStringList()); blacklist = config.readEntry("blacklist", QStringList());
} }
void loadAll() void loadAll()
{ {
AbstractRunner::List firstRunners; AbstractRunner::List firstRunners;
AbstractRunner::List normalRunners; AbstractRunner::List normalRunners;
AbstractRunner::List lastRunners; AbstractRunner::List lastRunners;
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Runner"); KService::List offers = KServiceTypeTrader::self()->query("Plasma/Runner");
QString error; QString error;
foreach (const KService::Ptr &service, offers) { foreach (const KService::Ptr &service, offers) {
@ -256,10 +255,10 @@ public:
kDebug() << "failed to load runner : " << service->name() << ". error reported: " << error; kDebug() << "failed to load runner : " << service->name() << ". error reported: " << error;
} }
} }
firstRunners << normalRunners << lastRunners; firstRunners << normalRunners << lastRunners;
runners.clear(); runners.clear();
runners = firstRunners; runners = firstRunners;
kDebug() << "All runners loaded, total:" << runners.count(); kDebug() << "All runners loaded, total:" << runners.count();
} }
@ -283,7 +282,7 @@ RunnerManager::RunnerManager(QObject *parent)
d(new Private(this)) d(new Private(this))
{ {
KConfigGroup config(KGlobal::config(), "PlasmaRunnerManager"); KConfigGroup config(KGlobal::config(), "PlasmaRunnerManager");
d->configure(config); d->loadConfiguration(config);
d->loadAll(); d->loadAll();
//ThreadWeaver::setDebugLevel(true, 4); //ThreadWeaver::setDebugLevel(true, 4);
@ -294,7 +293,7 @@ RunnerManager::RunnerManager(KConfigGroup& config, QObject *parent)
: QObject(parent), : QObject(parent),
d(new Private(this)) d(new Private(this))
{ {
d->configure(config); d->loadConfiguration(config);
d->loadAll(); d->loadAll();
//ThreadWeaver::setDebugLevel(true, 4); //ThreadWeaver::setDebugLevel(true, 4);
} }
@ -335,7 +334,6 @@ void RunnerManager::run(const SearchMatch *match)
match->run(&d->context); match->run(&d->context);
} }
void RunnerManager::launchQuery (const QString & term, const QString & runnerName) void RunnerManager::launchQuery (const QString & term, const QString & runnerName)
{ {
if (term.isEmpty()) { if (term.isEmpty()) {
@ -360,6 +358,7 @@ void RunnerManager::launchQuery (const QString & term, const QString & runnerNam
} else { } else {
runable = d->runners; runable = d->runners;
} }
bool jobsLaunched=false; bool jobsLaunched=false;
foreach (Plasma::AbstractRunner* r, runable) { foreach (Plasma::AbstractRunner* r, runable) {
if ((r->ignoredTypes() & d->context.type()) == 0) { if ((r->ignoredTypes() & d->context.type()) == 0) {
@ -370,21 +369,22 @@ void RunnerManager::launchQuery (const QString & term, const QString & runnerNam
d->searchJobs.append( job ); d->searchJobs.append( job );
} }
} }
if (!jobsLaunched) { if (!jobsLaunched) {
emit matchesCompleted(); emit matchesCompleted();
} }
} }
bool RunnerManager::execQuery (const QString & term, const QString & runnerName) bool RunnerManager::execQuery (const QString & term, const QString & runnerName)
{ {
if (term.isEmpty()) { if (term.isEmpty()) {
reset(); reset();
return 0; return false;
} }
if (d->context.searchTerm() == term) { if (d->context.searchTerm() == term) {
// we already are searching for this! // we already are searching for this!
return 0; return false;
} }
reset(); reset();
@ -394,26 +394,25 @@ bool RunnerManager::execQuery (const QString & term, const QString & runnerName)
AbstractRunner *r = runner(runnerName); AbstractRunner *r = runner(runnerName);
if (!r) { if (!r) {
return 0; return false;
} }
if ((r->ignoredTypes() & d->context.type()) != 0) { if ((r->ignoredTypes() & d->context.type()) != 0) {
return 0; return false;
} }
r->performMatch(d->context); r->performMatch(d->context);
emit matchesCompleted(); emit matchesCompleted();
return 1; return true;
} }
void RunnerManager::reset() 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(); d->searchJobs.clear();
} } else {
else {
Weaver::instance()->dequeue(); Weaver::instance()->dequeue();
} }
d->context.reset(); d->context.reset();

View File

@ -33,7 +33,7 @@ namespace Plasma
class SearchMatch; class SearchMatch;
class AbstractRunner; class AbstractRunner;
class SearchContext; class SearchContext;
/** /**
* @short The RunnerManager class decides what installed runners are runnable, * @short The RunnerManager class decides what installed runners are runnable,
* and their ratings. It is the main proxy to the runners. * and their ratings. It is the main proxy to the runners.
@ -41,10 +41,9 @@ namespace Plasma
class PLASMA_EXPORT RunnerManager : public QObject class PLASMA_EXPORT RunnerManager : public QObject
{ {
Q_OBJECT Q_OBJECT
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();
@ -67,7 +66,7 @@ class PLASMA_EXPORT RunnerManager : public QObject
* @return List of matches * @return List of matches
*/ */
QList<SearchMatch *> matches() const; QList<SearchMatch *> matches() const;
/** /**
* Runs a given match * Runs a given match
* @arg pointer to the match to be executed * @arg pointer to the match to be executed
@ -75,7 +74,6 @@ class PLASMA_EXPORT RunnerManager : public QObject
void run(const SearchMatch *match); void run(const SearchMatch *match);
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
@ -103,7 +101,6 @@ class PLASMA_EXPORT RunnerManager : public QObject
void reset(); void reset();
Q_SIGNALS: Q_SIGNALS:
/** /**
* Emited each time a new match is added to the list * Emited each time a new match is added to the list
*/ */
@ -113,7 +110,7 @@ class PLASMA_EXPORT RunnerManager : public QObject
* Emited when all the matches have been found * Emited when all the matches have been found
*/ */
void matchesCompleted(); void matchesCompleted();
private: private:
class Private; class Private;
Private * const d; Private * const d;