KRunner 5.109.0
runnercontext.h
1/*
2 SPDX-FileCopyrightText: 2006-2007 Aaron Seigo <aseigo@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef PLASMA_RUNNERCONTEXT_H
8#define PLASMA_RUNNERCONTEXT_H
9
10#include <QList>
11#include <QObject>
12#include <QSharedDataPointer>
13
14#include "krunner_export.h"
15
16class KConfigGroup;
17
18namespace Plasma
19{
20class QueryMatch;
21class AbstractRunner;
22class RunnerContextPrivate;
23
31class KRUNNER_EXPORT RunnerContext : public QObject
32{
33 Q_OBJECT
34
35public:
36 enum Type {
37 None = 0,
38 UnknownType = 1,
39 Directory = 2,
40 File = 4,
41 NetworkLocation = 8,
42 Executable = 16,
43 ShellCommand = 32,
44 Help = 64,
45 FileSystem = Directory | File | Executable | ShellCommand,
46 };
47
48 Q_DECLARE_FLAGS(Types, Type)
49
50 explicit RunnerContext(QObject *parent = nullptr);
51
55 RunnerContext(RunnerContext &other, QObject *parent = nullptr);
56
62
63 ~RunnerContext() override;
64
70 void reset();
71
76 void setQuery(const QString &term);
77
81 QString query() const;
82
83#if KRUNNER_ENABLE_DEPRECATED_SINCE(5, 76)
89 KRUNNER_DEPRECATED_VERSION(5, 76, "feature is deprecated. Do the checks manually inside of the match logic")
90 Type type() const;
91#endif
92
93#if KRUNNER_ENABLE_DEPRECATED_SINCE(5, 76)
100 KRUNNER_DEPRECATED_VERSION(5, 76, "feature is unused and not supported by most runners")
101 QStringList enabledCategories() const;
102#endif
103
104#if KRUNNER_ENABLE_DEPRECATED_SINCE(5, 76)
111 KRUNNER_DEPRECATED_VERSION(5, 76, "feature is unused and not supported by most runners")
112 void setEnabledCategories(const QStringList &categories);
113#endif
114
115#if KRUNNER_ENABLE_DEPRECATED_SINCE(5, 76)
124 KRUNNER_DEPRECATED_VERSION(5, 76, "feature is unused, determine the mime type manually if needed")
125 QString mimeType() const;
126#endif
127
146 bool isValid() const;
147
154 bool addMatches(const QList<QueryMatch> &matches);
155
164 bool addMatch(const QueryMatch &match);
165
166#if KRUNNER_ENABLE_DEPRECATED_SINCE(5, 81)
178 KRUNNER_DEPRECATED_VERSION(5, 81, "feature is unused, aggregate and filter the matches before adding them to the runnercontext instead")
179 bool removeMatch(const QString matchId);
180#endif
181
182#if KRUNNER_ENABLE_DEPRECATED_SINCE(5, 81)
194 KRUNNER_DEPRECATED_VERSION(5, 81, "feature is unused, aggregate and filter the matches before adding them to the runnercontext instead")
195 bool removeMatches(const QStringList matchIdList);
196#endif
197
198#if KRUNNER_ENABLE_DEPRECATED_SINCE(5, 81)
210 KRUNNER_DEPRECATED_VERSION(5, 81, "feature is unused, aggregate and filter the matches before adding them to the runnercontext instead")
211 bool removeMatches(AbstractRunner *runner);
212#endif
213
219 QList<QueryMatch> matches() const;
220
221#if KRUNNER_ENABLE_DEPRECATED_SINCE(5, 79)
230 KRUNNER_DEPRECATED_VERSION(5, 79, "Deprecated due to lack of usage, instead filter the matches manually based on the id")
231 QueryMatch match(const QString &id) const;
232#endif
233
244 void requestQueryStringUpdate(const QString &text, int cursorPosition) const;
245
255 // TODO KF6 Make private
256 void setSingleRunnerQueryMode(bool enabled);
257
263
270
281 void restore(const KConfigGroup &config);
282
286 void save(KConfigGroup &config);
287
296 void run(const QueryMatch &match);
297
298Q_SIGNALS:
299 void matchesChanged();
300
301private:
302 KRUNNER_NO_EXPORT QString requestedQueryString() const;
303 KRUNNER_NO_EXPORT int requestedCursorPosition() const;
304 KRUNNER_NO_EXPORT bool shouldIgnoreCurrentMatchForHistory() const;
305 friend class RunnerManager;
306 QExplicitlySharedDataPointer<RunnerContextPrivate> d;
307};
308
309Q_DECLARE_OPERATORS_FOR_FLAGS(RunnerContext::Types)
310
311}
312
313#endif
An abstract base class for Plasma Runner plugins.
Definition abstractrunner.h:69
A match returned by an AbstractRunner in response to a given RunnerContext.
Definition querymatch.h:35
The RunnerContext class provides information related to a search, including the search term,...
Definition runnercontext.h:32
void save(KConfigGroup &config)
bool addMatch(const QueryMatch &match)
Appends a match to the existing list of matches.
void setQuery(const QString &term)
Sets the query term for this object and attempts to determine the type of the search.
bool singleRunnerQueryMode() const
bool addMatches(const QList< QueryMatch > &matches)
Appends lists of matches to the list of matches.
RunnerContext(RunnerContext &other, QObject *parent=nullptr)
Copy constructor.
void reset()
Resets the search term for this object.
void run(const QueryMatch &match)
Run a match using the information from this context.
void restore(const KConfigGroup &config)
Sets the launch counts for the associated match ids.
void requestQueryStringUpdate(const QString &text, int cursorPosition) const
Request that KRunner updates the query string and stasy open, even after running a match.
void setSingleRunnerQueryMode(bool enabled)
Sets single runner query mode.
RunnerContext & operator=(const RunnerContext &other)
Assignment operator.
QString query() const
void ignoreCurrentMatchForHistory() const
Set this to true in the AbstractRunner::run method to prevent the entry from being saved to the histo...
QList< QueryMatch > matches() const
Retrieves all available matches for the current search term.
bool isValid() const
The RunnerManager class decides what installed runners are runnable, and their ratings.
Definition runnermanager.h:47