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

Plasma

  • sources
  • kde-4.12
  • kdelibs
  • plasma
querymatch.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Library General Public License as
6  * published by the Free Software Foundation; either version 2, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
20 #include "querymatch.h"
21 
22 #include <QAction>
23 #include <QIcon>
24 #include <QReadWriteLock>
25 #include <QSharedData>
26 #include <QStringList>
27 #include <QVariant>
28 #include <QWeakPointer>
29 
30 #include <kdebug.h>
31 
32 #include "abstractrunner.h"
33 
34 namespace Plasma
35 {
36 
37 class QueryMatchPrivate : public QSharedData
38 {
39  public:
40  QueryMatchPrivate(AbstractRunner *r)
41  : QSharedData(),
42  lock(new QReadWriteLock(QReadWriteLock::Recursive)),
43  runner(r),
44  type(QueryMatch::ExactMatch),
45  relevance(.7),
46  selAction(0),
47  enabled(true),
48  idSetByData(false)
49  {
50  }
51 
52  QueryMatchPrivate(const QueryMatchPrivate &other)
53  : QSharedData(other),
54  lock(new QReadWriteLock(QReadWriteLock::Recursive))
55  {
56  QReadLocker lock(other.lock);
57  runner = other.runner;
58  type = other.type;
59  relevance = other.relevance;
60  selAction = other.selAction;
61  enabled = other.enabled;
62  idSetByData = other.idSetByData;
63  id = other.id;
64  text = other.text;
65  subtext = other.subtext;
66  icon = other.icon;
67  data = other.data;
68  }
69 
70  ~QueryMatchPrivate()
71  {
72  delete lock;
73  }
74 
75  QReadWriteLock *lock;
76  QWeakPointer<AbstractRunner> runner;
77  QueryMatch::Type type;
78  QString id;
79  QString text;
80  QString subtext;
81  QIcon icon;
82  QVariant data;
83  qreal relevance;
84  QAction *selAction;
85  bool enabled : 1;
86  bool idSetByData : 1;
87 };
88 
89 QueryMatch::QueryMatch(AbstractRunner *runner)
90  : d(new QueryMatchPrivate(runner))
91 {
92 // kDebug() << "new match created";
93 }
94 
95 QueryMatch::QueryMatch(const QueryMatch &other)
96  : d(other.d)
97 {
98 }
99 
100 QueryMatch::~QueryMatch()
101 {
102 }
103 
104 bool QueryMatch::isValid() const
105 {
106  return d->runner != 0;
107 }
108 
109 QString QueryMatch::id() const
110 {
111  if (d->id.isEmpty() && d->runner) {
112  return d->runner.data()->id();
113  }
114 
115  return d->id;
116 }
117 
118 void QueryMatch::setType(Type type)
119 {
120  d->type = type;
121 }
122 
123 QueryMatch::Type QueryMatch::type() const
124 {
125  return d->type;
126 }
127 
128 void QueryMatch::setRelevance(qreal relevance)
129 {
130  d->relevance = qMax(qreal(0.0), relevance);
131 }
132 
133 qreal QueryMatch::relevance() const
134 {
135  return d->relevance;
136 }
137 
138 AbstractRunner* QueryMatch::runner() const
139 {
140  return d->runner.data();
141 }
142 
143 void QueryMatch::setText(const QString &text)
144 {
145  QWriteLocker locker(d->lock);
146  d->text = text;
147 }
148 
149 void QueryMatch::setSubtext(const QString &subtext)
150 {
151  QWriteLocker locker(d->lock);
152  d->subtext = subtext;
153 }
154 
155 void QueryMatch::setData(const QVariant & data)
156 {
157  QWriteLocker locker(d->lock);
158  d->data = data;
159 
160  if (d->id.isEmpty() || d->idSetByData) {
161  const QString id = data.toString();
162  if (!id.isEmpty()) {
163  setId(data.toString());
164  d->idSetByData = true;
165  }
166  }
167 }
168 
169 void QueryMatch::setId(const QString &id)
170 {
171  QWriteLocker locker(d->lock);
172  if (d->runner) {
173  d->id = d->runner.data()->id();
174  }
175 
176  if (!id.isEmpty()) {
177  d->id.append('_').append(id);
178  }
179 
180  d->idSetByData = false;
181 }
182 
183 void QueryMatch::setIcon(const QIcon &icon)
184 {
185  QWriteLocker locker(d->lock);
186  d->icon = icon;
187 }
188 
189 QVariant QueryMatch::data() const
190 {
191  QReadLocker locker(d->lock);
192  return d->data;
193 }
194 
195 QString QueryMatch::text() const
196 {
197  QReadLocker locker(d->lock);
198  return d->text;
199 }
200 
201 QString QueryMatch::subtext() const
202 {
203  QReadLocker locker(d->lock);
204  return d->subtext;
205 }
206 
207 QIcon QueryMatch::icon() const
208 {
209  QReadLocker locker(d->lock);
210  return d->icon;
211 }
212 
213 void QueryMatch::setEnabled(bool enabled)
214 {
215  d->enabled = enabled;
216 }
217 
218 bool QueryMatch::isEnabled() const
219 {
220  return d->enabled && d->runner;
221 }
222 
223 QAction* QueryMatch::selectedAction() const
224 {
225  return d->selAction;
226 }
227 
228 void QueryMatch::setSelectedAction(QAction *action)
229 {
230  d->selAction = action;
231 }
232 
233 bool QueryMatch::operator<(const QueryMatch &other) const
234 {
235  if (d->type == other.d->type) {
236  if (isEnabled() != other.isEnabled()) {
237  return other.isEnabled();
238  }
239 
240  if (d->relevance != other.d->relevance) {
241  return d->relevance < other.d->relevance;
242  }
243 
244  QReadLocker locker(d->lock);
245  QReadLocker otherLocker(other.d->lock);
246  // when resorting to sort by alpha, we want the
247  // reverse sort order!
248  return d->text > other.d->text;
249  }
250 
251  return d->type < other.d->type;
252 }
253 
254 QueryMatch &QueryMatch::operator=(const QueryMatch &other)
255 {
256  if (d != other.d) {
257  d = other.d;
258  }
259 
260  return *this;
261 }
262 
263 bool QueryMatch::operator==(const QueryMatch &other) const
264 {
265  return (d == other.d);
266 }
267 
268 bool QueryMatch::operator!=(const QueryMatch &other) const
269 {
270  return (d != other.d);
271 }
272 
273 void QueryMatch::run(const RunnerContext &context) const
274 {
275  //kDebug() << "we run the term" << context->query() << "whose type is" << context->mimetype();
276  if (d->runner) {
277  d->runner.data()->run(context, *this);
278  }
279 }
280 
281 bool QueryMatch::hasConfigurationInterface() const
282 {
283  return d->runner && d->runner.data()->hasRunOptions();
284 }
285 
286 void QueryMatch::createConfigurationInterface(QWidget *parent)
287 {
288  if (hasConfigurationInterface()) {
289  d->runner.data()->createRunOptions(parent);
290  }
291 }
292 
293 } // Plasma namespace
294 
abstractrunner.h
Plasma::QueryMatch::operator!=
bool operator!=(const QueryMatch &other) const
Definition: querymatch.cpp:268
Plasma::QueryMatch::relevance
qreal relevance() const
The relevance of this action to the search.
Definition: querymatch.cpp:133
QWidget
Plasma::AbstractRunner
An abstract base class for Plasma Runner plugins.
Definition: abstractrunner.h:63
Plasma::QueryMatch::setSelectedAction
void setSelectedAction(QAction *action)
Sets the selected action.
Definition: querymatch.cpp:228
Plasma::QueryMatch::setEnabled
void setEnabled(bool enable)
Sets whether or not this match can be activited.
Definition: querymatch.cpp:213
Plasma::QueryMatch::operator==
bool operator==(const QueryMatch &other) const
Definition: querymatch.cpp:263
Plasma::QueryMatch::setId
void setId(const QString &id)
Sets the id for this match; useful if the id does not match data().toString().
Definition: querymatch.cpp:169
Plasma::QueryMatch::createConfigurationInterface
void createConfigurationInterface(QWidget *parent)
If hasConfigurationInterface() returns true, this method may be called to get a widget displaying the...
Definition: querymatch.cpp:286
Plasma::QueryMatch::Type
Type
The type of match.
Definition: querymatch.h:53
Plasma::QueryMatch::icon
QIcon icon() const
Definition: querymatch.cpp:207
Plasma::QueryMatch::run
void run(const RunnerContext &context) const
Requests this match to activae using the given context.
Definition: querymatch.cpp:273
Plasma::QueryMatch::setIcon
void setIcon(const QIcon &icon)
Sets the icon associated with this match.
Definition: querymatch.cpp:183
Plasma::QueryMatch::isEnabled
bool isEnabled() const
Definition: querymatch.cpp:218
Plasma::QueryMatch::text
QString text() const
Definition: querymatch.cpp:195
Plasma::QueryMatch::setSubtext
void setSubtext(const QString &text)
Sets the descriptive text for this match; can be longer than the main title text. ...
Definition: querymatch.cpp:149
Plasma::QueryMatch::subtext
QString subtext() const
Definition: querymatch.cpp:201
Plasma::QueryMatch::type
Type type() const
The type of action this is.
Definition: querymatch.cpp:123
Plasma::QueryMatch::setText
void setText(const QString &text)
Sets the main title text for this match; should be short enough to fit nicely on one line in a user i...
Definition: querymatch.cpp:143
Plasma::QueryMatch::~QueryMatch
~QueryMatch()
Definition: querymatch.cpp:100
Plasma::QueryMatch::setData
void setData(const QVariant &data)
Sets data to be used internally by the associated AbstractRunner.
Definition: querymatch.cpp:155
Plasma::QueryMatch::data
QVariant data() const
Definition: querymatch.cpp:189
Plasma::QueryMatch::setType
void setType(Type type)
Sets the type of match this action represents.
Definition: querymatch.cpp:118
Plasma::QueryMatch::id
QString id() const
a string that can be used as an ID for this match, even between different queries.
Definition: querymatch.cpp:109
Plasma::RunnerContext
The RunnerContext class provides information related to a search, including the search term...
Definition: runnercontext.h:46
Plasma::QueryMatch::selectedAction
QAction * selectedAction() const
The current action.
Definition: querymatch.cpp:223
Plasma::QueryMatch::QueryMatch
QueryMatch(AbstractRunner *runner)
Constructs a PossibleMatch associated with a given RunnerContext and runner.
Definition: querymatch.cpp:89
Plasma::QueryMatch::operator=
QueryMatch & operator=(const QueryMatch &other)
Definition: querymatch.cpp:254
Plasma::type
static QScriptValue type(QScriptContext *ctx, QScriptEngine *eng)
Definition: easingcurve.cpp:63
Plasma::QueryMatch
A match returned by an AbstractRunner in response to a given RunnerContext.
Definition: querymatch.h:47
Plasma::QueryMatch::setRelevance
void setRelevance(qreal relevance)
Sets the relevance of this action for the search it was created for.
Definition: querymatch.cpp:128
Plasma::QueryMatch::runner
AbstractRunner * runner() const
Definition: querymatch.cpp:138
querymatch.h
Plasma::QueryMatch::operator<
bool operator<(const QueryMatch &other) const
Definition: querymatch.cpp:233
Plasma::QueryMatch::hasConfigurationInterface
bool hasConfigurationInterface() const
Definition: querymatch.cpp:281
Plasma::QueryMatch::isValid
bool isValid() const
Definition: querymatch.cpp:104
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:34 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Plasma

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal