2 * Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
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.
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
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.
20 #ifndef PLASMA_RUNNERCONTEXT_H
21 #define PLASMA_RUNNERCONTEXT_H
23 #include <QtCore/QList>
24 #include <QtCore/QObject>
25 #include <QtCore/QSharedDataPointer>
27 #include <plasma/plasma_export.h>
36 class RunnerContextPrivate
;
39 * @class RunnerContext plasma/runnercontext.h <Plasma/RunnerContext>
41 * @short The RunnerContext class provides information related to a search,
42 * including the search term, metadata on the search term and collected
45 class PLASMA_EXPORT RunnerContext
: public QObject
59 FileSystem
= Directory
| File
| Executable
| ShellCommand
62 Q_DECLARE_FLAGS(Types
, Type
)
64 explicit RunnerContext(QObject
*parent
= 0);
69 explicit RunnerContext(RunnerContext
&other
, QObject
*parent
= 0);
74 * Resets the search term for this object.
75 * This removes all current matches in the process.
80 * Sets the query term for this object and attempts to determine
81 * the type of the search.
83 void setQuery(const QString
&term
);
86 * @return the current search query term.
88 QString
query() const;
91 * The type of item the search term might refer to.
97 * The mimetype that the search term refers to, if discoverable.
99 * @return QString() if the mimetype can not be determined, otherwise
100 * the mimetype of the object being referred to by the search
103 QString
mimeType() const;
106 * @returns true if this context is no longer valid and therefore
107 * matching using it should abort. Most useful as an optimization technique
108 * inside of AbstractRunner subclasses in the match method, e.g.:
110 * while (.. a possibly large iteration) {
111 * if (!context.isValid()) {
115 * ... some processing ...
118 * While not required to be used within runners, it provies a nice way
119 * to avoid unecessary processing in runners that may run for an extended
120 * period (as measured in 10s of ms) and therefore improve the user experience.
125 * Appends lists of matches to the list of matches.
127 * This method is thread safe and causes the matchesChanged() signal to be emitted.
129 * @return true if matches were added, false if matches were e.g. outdated
131 // trueg: what do we need the term for? It is stored in the context anyway! Plus: matches() does not have a term parameter!
132 // plus: it is Q_UNUSED
133 bool addMatches(const QString
&term
, const QList
<QueryMatch
> &matches
);
136 * Appends a match to the existing list of matches.
138 * If you are going to be adding multiple matches, use addMatches instead.
140 * @arg term the search term that this match was generated for.
141 * @arg match the match to add
143 * @return true if the match was added, false otherwise.
145 // trueg: what do we need the term for? It is stored in the context anyway! Plus: matches() does not have a term parameter!
146 // plus: it is Q_UNUSED
147 bool addMatch(const QString
&term
, const QueryMatch
&match
);
150 * Retrieves all available matches for the current search term.
152 * @return a list of matches
154 QList
<QueryMatch
> matches() const;
157 * Retrieves a match by id.
159 * @param id the id of the match to return
160 * @return the match associated with this id, or an invalid QueryMatch object
161 * if the id does not eixst
163 QueryMatch
match(const QString
&id
) const;
166 void matchesChanged();
169 QExplicitlySharedDataPointer
<RunnerContextPrivate
> d
;
174 Q_DECLARE_OPERATORS_FOR_FLAGS(Plasma::RunnerContext::Types
)