2007-02-28 01:41:09 +01:00
|
|
|
/*
|
2007-08-06 13:20:02 +02:00
|
|
|
* Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
|
2007-02-28 01:41:09 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2007-08-06 13:20:02 +02:00
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
2007-02-28 01:41:09 +01:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2007-05-21 16:28:03 +02:00
|
|
|
#include "abstractrunner.h"
|
2007-12-02 08:11:50 +01:00
|
|
|
#include "searchcontext.h"
|
2007-05-21 16:28:03 +02:00
|
|
|
|
2007-10-06 00:21:25 +02:00
|
|
|
#include <KDebug>
|
2007-10-31 05:44:09 +01:00
|
|
|
#include <KServiceTypeTrader>
|
2007-02-28 01:41:09 +01:00
|
|
|
|
2007-03-02 06:27:33 +01:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2007-10-31 05:44:09 +01:00
|
|
|
class AbstractRunner::Private
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool hasMatchOptions;
|
|
|
|
bool hasConfig;
|
2007-12-10 17:20:46 +01:00
|
|
|
Speed speed;
|
|
|
|
Private()
|
|
|
|
: speed(NormalSpeed)
|
|
|
|
{}
|
2007-10-31 05:44:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
AbstractRunner::AbstractRunner(QObject* parent)
|
|
|
|
: QObject(parent),
|
|
|
|
d(new Private())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractRunner::~AbstractRunner()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2007-12-11 17:53:40 +01:00
|
|
|
KConfigGroup AbstractRunner::config() const
|
|
|
|
{
|
|
|
|
QString group = objectName();
|
|
|
|
if (group.isEmpty()) {
|
|
|
|
group = "UnnamedRunner";
|
|
|
|
}
|
|
|
|
|
2007-12-11 23:30:05 +01:00
|
|
|
KConfigGroup runners(KGlobal::config(), "Runners");
|
|
|
|
return KConfigGroup(&runners, group);
|
2007-12-11 17:53:40 +01:00
|
|
|
}
|
|
|
|
|
2007-12-02 08:11:50 +01:00
|
|
|
void AbstractRunner::performMatch( Plasma::SearchContext &globalContext )
|
|
|
|
{
|
|
|
|
Plasma::SearchContext localContext( 0, globalContext );
|
|
|
|
//Keep track of global context list sizes so we know which pointers are our responsibility to delete
|
|
|
|
int exactEnd = localContext.exactMatches().count();
|
|
|
|
int possibleEnd = localContext.possibleMatches().count();
|
|
|
|
int infoEnd = localContext.informationalMatches().count();
|
|
|
|
|
|
|
|
match( &localContext );
|
|
|
|
|
2007-12-03 18:18:28 +01:00
|
|
|
QList<SearchMatch *> exact = localContext.exactMatches().mid(exactEnd);
|
|
|
|
QList<SearchMatch *> possible = localContext.possibleMatches().mid(possibleEnd);
|
|
|
|
QList<SearchMatch *> info = localContext.informationalMatches().mid(infoEnd);
|
2007-12-02 08:11:50 +01:00
|
|
|
|
|
|
|
//If matches were not added, delete items on the heap
|
|
|
|
if (!globalContext.addMatches(localContext.searchTerm(), exact, possible, info)) {
|
|
|
|
qDeleteAll(exact);
|
|
|
|
qDeleteAll(possible);
|
|
|
|
qDeleteAll(info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-31 05:44:09 +01:00
|
|
|
bool AbstractRunner::hasMatchOptions()
|
|
|
|
{
|
|
|
|
return d->hasMatchOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractRunner::setHasMatchOptions(bool hasMatchOptions)
|
|
|
|
{
|
|
|
|
d->hasMatchOptions = hasMatchOptions;
|
|
|
|
}
|
|
|
|
|
2007-10-31 06:25:07 +01:00
|
|
|
void AbstractRunner::createMatchOptions(QWidget *parent)
|
2007-10-31 05:44:09 +01:00
|
|
|
{
|
|
|
|
Q_UNUSED(parent)
|
|
|
|
}
|
|
|
|
|
2007-11-22 10:08:58 +01:00
|
|
|
bool AbstractRunner::isConfigurable()
|
2007-10-31 05:44:09 +01:00
|
|
|
{
|
|
|
|
return d->hasConfig;
|
|
|
|
}
|
|
|
|
|
2007-11-22 10:08:58 +01:00
|
|
|
void AbstractRunner::setIsConfigurable(bool hasConfig)
|
2007-10-31 05:44:09 +01:00
|
|
|
{
|
|
|
|
d->hasConfig = hasConfig;
|
|
|
|
}
|
|
|
|
|
2007-10-31 06:25:07 +01:00
|
|
|
void AbstractRunner::createConfigurationInterface(QWidget *widget)
|
|
|
|
{
|
|
|
|
Q_UNUSED(widget)
|
|
|
|
}
|
|
|
|
|
2007-12-10 17:20:46 +01:00
|
|
|
AbstractRunner::Speed AbstractRunner::speed() const
|
|
|
|
{
|
|
|
|
return d->speed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractRunner::setSpeed(Speed speed)
|
|
|
|
{
|
|
|
|
d->speed = speed;
|
|
|
|
}
|
|
|
|
|
2007-12-03 18:18:28 +01:00
|
|
|
void AbstractRunner::exec(Plasma::SearchMatch *action)
|
2007-10-31 05:44:09 +01:00
|
|
|
{
|
|
|
|
Q_UNUSED(action)
|
2007-02-28 04:55:22 +01:00
|
|
|
}
|
|
|
|
|
2007-11-22 10:08:58 +01:00
|
|
|
AbstractRunner::List AbstractRunner::loadRunners(QObject* parent, const QStringList& whitelist)
|
2007-03-02 01:06:52 +01:00
|
|
|
{
|
2007-10-09 05:20:02 +02:00
|
|
|
List firstRunners;
|
2007-03-02 01:06:52 +01:00
|
|
|
List runners;
|
2007-10-09 05:20:02 +02:00
|
|
|
List lastRunners;
|
|
|
|
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Runner");
|
2007-08-29 05:06:48 +02:00
|
|
|
QString error;
|
|
|
|
foreach (KService::Ptr service, offers) {
|
2007-11-22 10:08:58 +01:00
|
|
|
if( whitelist.empty() || whitelist.contains( service->name() ) ) {
|
|
|
|
AbstractRunner* runner = service->createInstance<AbstractRunner>(parent, QVariantList(), &error);
|
|
|
|
if (runner) {
|
2008-01-07 21:50:31 +01:00
|
|
|
//kDebug(1209) << "loaded runner : " << service->name();
|
2007-11-22 10:08:58 +01:00
|
|
|
QString phase = service->property("X-Plasma-RunnerPhase").toString();
|
|
|
|
if (phase == "last") {
|
|
|
|
lastRunners.append(runner);
|
|
|
|
} else if (phase == "first") {
|
|
|
|
firstRunners.append(runner);
|
|
|
|
} else {
|
|
|
|
runners.append(runner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2008-01-07 21:50:31 +01:00
|
|
|
kDebug(1209) << "failed to load runner : " << service->name() << ". error reported: " << error;
|
2007-10-09 05:20:02 +02:00
|
|
|
}
|
2007-03-02 01:06:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-09 05:20:02 +02:00
|
|
|
firstRunners << runners << lastRunners;
|
|
|
|
return firstRunners;
|
2007-03-02 01:06:52 +01:00
|
|
|
}
|
|
|
|
|
2007-03-02 06:27:33 +01:00
|
|
|
} // Plasma namespace
|
|
|
|
|
2007-03-20 18:37:44 +01:00
|
|
|
#include "abstractrunner.moc"
|