• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

libplasma

abstractrunner.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
00003  *
00004  *   This program is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU Library General Public License as
00006  *   published by the Free Software Foundation; either version 2, or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details
00013  *
00014  *   You should have received a copy of the GNU Library General Public
00015  *   License along with this program; if not, write to the
00016  *   Free Software Foundation, Inc.,
00017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018  */
00019 
00020 #include "abstractrunner.h"
00021 #include "searchcontext.h"
00022 
00023 #include <KDebug>
00024 #include <KServiceTypeTrader>
00025 
00026 namespace Plasma
00027 {
00028 
00029 class AbstractRunner::Private
00030 {
00031     public:
00032         bool hasMatchOptions;
00033         bool hasConfig;
00034         Speed speed;
00035     Private()
00036       : speed(NormalSpeed)
00037     {}
00038 };
00039 
00040 AbstractRunner::AbstractRunner(QObject* parent)
00041     : QObject(parent),
00042       d(new Private())
00043 {
00044 }
00045 
00046 AbstractRunner::~AbstractRunner()
00047 {
00048     delete d;
00049 }
00050 
00051 KConfigGroup AbstractRunner::config() const
00052 {
00053     QString group = objectName();
00054     if (group.isEmpty()) {
00055         group = "UnnamedRunner";
00056     }
00057 
00058     KConfigGroup runners(KGlobal::config(), "Runners");
00059     return KConfigGroup(&runners, group);
00060 }
00061 
00062 void AbstractRunner::performMatch( Plasma::SearchContext &globalContext )
00063 {
00064     Plasma::SearchContext localContext( 0, globalContext );
00065     //Keep track of global context list sizes so we know which pointers are our responsibility to delete
00066     int exactEnd = localContext.exactMatches().count();
00067     int possibleEnd = localContext.possibleMatches().count();
00068     int infoEnd = localContext.informationalMatches().count();
00069 
00070     match( &localContext );
00071 
00072     QList<SearchMatch *> exact = localContext.exactMatches().mid(exactEnd);
00073     QList<SearchMatch *> possible = localContext.possibleMatches().mid(possibleEnd);
00074     QList<SearchMatch *> info = localContext.informationalMatches().mid(infoEnd);
00075 
00076     //If matches were not added, delete items on the heap
00077     if (!globalContext.addMatches(localContext.searchTerm(), exact, possible, info)) {
00078         qDeleteAll(exact);
00079         qDeleteAll(possible);
00080         qDeleteAll(info);
00081     }
00082 }
00083 
00084 bool AbstractRunner::hasMatchOptions()
00085 {
00086     return d->hasMatchOptions;
00087 }
00088 
00089 void AbstractRunner::setHasMatchOptions(bool hasMatchOptions)
00090 {
00091     d->hasMatchOptions = hasMatchOptions;
00092 }
00093 
00094 void AbstractRunner::createMatchOptions(QWidget *parent)
00095 {
00096     Q_UNUSED(parent)
00097 }
00098 
00099 bool AbstractRunner::isConfigurable()
00100 {
00101     return d->hasConfig;
00102 }
00103 
00104 void AbstractRunner::setIsConfigurable(bool hasConfig)
00105 {
00106     d->hasConfig = hasConfig;
00107 }
00108 
00109 void AbstractRunner::createConfigurationInterface(QWidget *widget)
00110 {
00111     Q_UNUSED(widget)
00112 }
00113 
00114 AbstractRunner::Speed AbstractRunner::speed() const
00115 {
00116     return d->speed;
00117 }
00118 
00119 void AbstractRunner::setSpeed(Speed speed)
00120 {
00121     d->speed = speed;
00122 }
00123 
00124 void AbstractRunner::exec(Plasma::SearchMatch *action)
00125 {
00126     Q_UNUSED(action)
00127 }
00128 
00129 AbstractRunner::List AbstractRunner::loadRunners(QObject* parent, const QStringList& whitelist)
00130 {
00131     List firstRunners;
00132     List runners;
00133     List lastRunners;
00134 
00135     KService::List offers = KServiceTypeTrader::self()->query("Plasma/Runner");
00136     QString error;
00137     foreach (KService::Ptr service, offers) {
00138         if( whitelist.empty() || whitelist.contains( service->name() ) ) {
00139             AbstractRunner* runner = service->createInstance<AbstractRunner>(parent, QVariantList(), &error);
00140             if (runner) {
00141                 //kDebug() << "loaded runner : " << service->name();
00142                 QString phase = service->property("X-Plasma-RunnerPhase").toString();
00143                 if (phase == "last") {
00144                     lastRunners.append(runner);
00145                 } else if (phase == "first") {
00146                     firstRunners.append(runner);
00147                 } else {
00148                     runners.append(runner);
00149                 }
00150             }
00151             else {
00152                 kDebug() << "failed to load runner : " << service->name() << ". error reported: " << error;
00153             }
00154         }
00155     }
00156 
00157     firstRunners << runners << lastRunners;
00158     return firstRunners;
00159 }
00160 
00161 } // Plasma namespace
00162 
00163 #include "abstractrunner.moc"

libplasma

Skip menu "libplasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libplasma
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal