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_QUERYMATCH_H
21 #define PLASMA_QUERYMATCH_H
23 #include <QtCore/QList>
24 #include <QtCore/QSharedDataPointer>
26 #include <plasma/plasma_export.h>
38 class QueryMatchPrivate
;
41 * @class QueryMatch plasma/querymatch.h <Plasma/QueryMatch>
43 * @short A match returned by an AbstractRunner in response to a given
46 class PLASMA_EXPORT QueryMatch
50 * The type of match. Value is important here as it is used for sorting
53 NoMatch
= 0, /**< Null match */
54 CompletionMatch
= 10, /**< Possible completion for the data of the query */
55 PossibleMatch
= 30, /**< Something that may match the query */
56 InformationalMatch
= 50, /**< A purely informational, non-actionable match,
57 such as the answer to a question or calculation*/
58 HelperMatch
= 70, /**< A match that represents an action not directly related
59 to activating the given search term, such as a search
60 in an external tool or a command learning trigger. Helper
61 matches tend to be generic to the query and should not
62 be autoactivated just because the user hits "Enter"
63 while typing. They must be explicitly selected to
64 be activated, but unlike InformationalMatch cause
65 an action to be triggered. */
66 ExactMatch
= 100 /**< An exact match to the query */
70 * Constructs a PossibleMatch associated with a given RunnerContext
73 * @arg search the RunnerContext this match belongs to
74 * @arg runner the runner this match belongs to
76 explicit QueryMatch(AbstractRunner
*runner
);
81 QueryMatch(const QueryMatch
&other
);
88 * Sets the type of match this action represents.
90 void setType(Type type
);
93 * The type of action this is. Defaults to PossibleMatch.
98 * Sets the relevance of this action for the search
101 * @param relevance a number between 0 and 1.
103 void setRelevance(qreal relevance
);
106 * The relevance of this action to the search. By default,
107 * the relevance is 1.
109 * @return a number between 0 and 1
111 qreal
relevance() const;
114 * The runner associated with this action
116 AbstractRunner
*runner() const;
119 * A string that can be used as an ID for this match,
120 * even between different queries. It is based in part
121 * on the source of the match (the AbstractRunner) and
122 * distinguishing information provided by the runner,
123 * ensuring global uniqueness as well as consistency
124 * between query matches.
128 QString
text() const;
129 QString
subtext() const;
130 QVariant
data() const;
132 bool isEnabled() const;
134 bool operator<(const QueryMatch
&other
) const;
135 QueryMatch
&operator=(const QueryMatch
&other
);
138 * Requests this match to activae using the given context
140 * @param context the context to use in conjunction with this run
142 * @sa AbstractRunner::run
144 void run(const RunnerContext
&context
) const;
147 * Sets data to be used internally by the associated
150 * When set, it is also used to form
151 * part of the id() for this match. If that is innapropriate
152 * as an id, the runner may generate its own id and set that
153 * with setId(const QString&) directly after calling setData
155 void setData(const QVariant
&data
);
158 * Sets the id for this match; useful if the id does not
159 * match data().toString(). The id must be unique to all
160 * matches from this runner, and should remain constant
161 * for the same query for best results.
163 * @param id the new identifying string to use to refer
166 void setId(const QString
&id
);
168 void setText(const QString
&text
);
169 void setSubtext(const QString
&text
);
170 void setIcon(const QIcon
&icon
);
171 void setEnabled(bool enable
);
174 * The current action.
176 QAction
* selectedAction() const;
178 * Sets the selected action
180 void setSelectedAction(QAction
*action
);
183 QSharedDataPointer
<QueryMatchPrivate
> d
;