• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

Plasma

querymatch.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 "querymatch.h"
00021 
00022 #include <QAction>
00023 #include <QIcon>
00024 #include <QSharedData>
00025 #include <QStringList>
00026 #include <QVariant>
00027 #include <QWeakPointer>
00028 
00029 #include <kdebug.h>
00030 
00031 #include "abstractrunner.h"
00032 
00033 namespace Plasma
00034 {
00035 
00036 class QueryMatchPrivate : public QSharedData
00037 {
00038     public:
00039         QueryMatchPrivate(AbstractRunner *r)
00040             : QSharedData(),
00041               runner(r),
00042               type(QueryMatch::ExactMatch),
00043               relevance(.7),
00044               selAction(0),
00045               enabled(true),
00046               idSetByData(false)
00047         {
00048         }
00049 
00050         QWeakPointer<AbstractRunner> runner;
00051         QueryMatch::Type type;
00052         QString id;
00053         QString text;
00054         QString subtext;
00055         QIcon icon;
00056         QVariant data;
00057         qreal relevance;
00058         QAction *selAction;
00059         bool enabled : 1;
00060         bool idSetByData : 1;
00061 };
00062 
00063 QueryMatch::QueryMatch(AbstractRunner *runner)
00064     : d(new QueryMatchPrivate(runner))
00065 {
00066 //    kDebug() << "new match created";
00067 }
00068 
00069 QueryMatch::QueryMatch(const QueryMatch &other)
00070     : d(other.d)
00071 {
00072 }
00073 
00074 QueryMatch::~QueryMatch()
00075 {
00076 }
00077 
00078 bool QueryMatch::isValid() const
00079 {
00080     return d->runner != 0;
00081 }
00082 
00083 QString QueryMatch::id() const
00084 {
00085     if (d->id.isEmpty() && d->runner) {
00086         return d->runner.data()->id();
00087     }
00088 
00089     return d->id;
00090 }
00091 
00092 void QueryMatch::setType(Type type)
00093 {
00094     d->type = type;
00095 }
00096 
00097 QueryMatch::Type QueryMatch::type() const
00098 {
00099     return d->type;
00100 }
00101 
00102 void QueryMatch::setRelevance(qreal relevance)
00103 {
00104     d->relevance = qMax(qreal(0.0), relevance);
00105 }
00106 
00107 qreal QueryMatch::relevance() const
00108 {
00109     return d->relevance;
00110 }
00111 
00112 AbstractRunner* QueryMatch::runner() const
00113 {
00114     return d->runner.data();
00115 }
00116 
00117 void QueryMatch::setText(const QString &text)
00118 {
00119     d->text = text;
00120 }
00121 
00122 void QueryMatch::setSubtext(const QString &subtext)
00123 {
00124     d->subtext = subtext;
00125 }
00126 
00127 void QueryMatch::setData(const QVariant & data)
00128 {
00129     d->data = data;
00130 
00131     if (d->id.isEmpty() || d->idSetByData) {
00132         const QString id = data.toString();
00133         if (!id.isEmpty()) {
00134             setId(data.toString());
00135             d->idSetByData = true;
00136         }
00137     }
00138 }
00139 
00140 void QueryMatch::setId(const QString &id)
00141 {
00142     if (d->runner) {
00143         d->id = d->runner.data()->id();
00144     }
00145 
00146     if (!id.isEmpty()) {
00147         d->id.append('_').append(id);
00148     }
00149 
00150     d->idSetByData = false;
00151 }
00152 
00153 void QueryMatch::setIcon(const QIcon &icon)
00154 {
00155     d->icon = icon;
00156 }
00157 
00158 QVariant QueryMatch::data() const
00159 {
00160     return d->data;
00161 }
00162 
00163 QString QueryMatch::text() const
00164 {
00165     return d->text;
00166 }
00167 
00168 QString QueryMatch::subtext() const
00169 {
00170     return d->subtext;
00171 }
00172 
00173 QIcon QueryMatch::icon() const
00174 {
00175     return d->icon;
00176 }
00177 
00178 void QueryMatch::setEnabled(bool enabled)
00179 {
00180     d->enabled = enabled;
00181 }
00182 
00183 bool QueryMatch::isEnabled() const
00184 {
00185     return d->enabled && d->runner;
00186 }
00187 
00188 QAction* QueryMatch::selectedAction() const
00189 {
00190     return d->selAction;
00191 }
00192 
00193 void QueryMatch::setSelectedAction(QAction *action)
00194 {
00195     d->selAction = action;
00196 }
00197 
00198 bool QueryMatch::operator<(const QueryMatch &other) const
00199 {
00200     if (d->type == other.d->type) {
00201         if (isEnabled() != other.isEnabled()) {
00202             return other.isEnabled();
00203         }
00204 
00205         if (d->relevance != other.d->relevance) {
00206             return d->relevance < other.d->relevance;
00207         }
00208 
00209         // when resorting to sort by alpha, we want the
00210         // reverse sort order!
00211         return d->text > other.d->text;
00212     }
00213 
00214     return d->type < other.d->type;
00215 }
00216 
00217 QueryMatch &QueryMatch::operator=(const QueryMatch &other)
00218 {
00219     if (d != other.d) {
00220         d = other.d;
00221     }
00222 
00223     return *this;
00224 }
00225 
00226 bool QueryMatch::operator==(const QueryMatch &other) const
00227 {
00228     return (d == other.d);
00229 }
00230 
00231 void QueryMatch::run(const RunnerContext &context) const
00232 {
00233     //kDebug() << "we run the term" << context->query() << "whose type is" << context->mimetype();
00234     if (d->runner) {
00235         d->runner.data()->run(context, *this);
00236     }
00237 }
00238 
00239 bool QueryMatch::hasConfigurationInterface() const
00240 {
00241     return d->runner && d->runner.data()->hasRunOptions();
00242 }
00243 
00244 void QueryMatch::createConfigurationInterface(QWidget *parent)
00245 {
00246     if (hasConfigurationInterface()) {
00247         d->runner.data()->createRunOptions(parent);
00248     }
00249 }
00250 
00251 } // Plasma namespace
00252 

Plasma

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
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