some more win32'fication to fix non-ascii filename handling
[kdelibs.git] / plasma / querymatch.h
blobf53b5da6e63e617bb942e50047be9bbbbdbe08a0
1 /*
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>
28 class QAction;
29 class QIcon;
30 class QVariant;
31 class QString;
33 namespace Plasma
36 class RunnerContext;
37 class AbstractRunner;
38 class QueryMatchPrivate;
40 /**
41 * @class QueryMatch plasma/querymatch.h <Plasma/QueryMatch>
43 * @short A match returned by an AbstractRunner in response to a given
44 * RunnerContext.
46 class PLASMA_EXPORT QueryMatch
48 public:
49 /**
50 * The type of match. Value is important here as it is used for sorting
52 enum Type {
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 */
69 /**
70 * Constructs a PossibleMatch associated with a given RunnerContext
71 * and runner.
73 * @arg search the RunnerContext this match belongs to
74 * @arg runner the runner this match belongs to
76 explicit QueryMatch(AbstractRunner *runner);
78 /**
79 * Copy constructor
81 QueryMatch(const QueryMatch &other);
83 ~QueryMatch();
85 bool isValid() const;
87 /**
88 * Sets the type of match this action represents.
90 void setType(Type type);
92 /**
93 * The type of action this is. Defaults to PossibleMatch.
95 Type type() const;
97 /**
98 * Sets the relevance of this action for the search
99 * it was created for.
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.
126 QString id() const;
128 QString text() const;
129 QString subtext() const;
130 QVariant data() const;
131 QIcon icon() 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
148 * AbstractRunner.
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
164 * to this entry
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);
182 private:
183 QSharedDataPointer<QueryMatchPrivate> d;
188 #endif