KRunner

runnermodel.h
1 /*
2  SPDX-FileCopyrightText: 2011 Aaron Seigo <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef RUNNERMODEL_H
8 #define RUNNERMODEL_H
9 
10 #include <QAbstractListModel>
11 #include <QStringList>
12 
13 #include <KRunner/QueryMatch>
14 
15 namespace Plasma
16 {
17 class RunnerManager;
18 class QueryMatch;
19 } // namespace Plasma
20 
21 class QTimer;
22 
23 /**
24  * This model provides bindings to use KRunner from QML
25  *
26  * @author Aaron Seigo <[email protected]>
27  */
29 {
30  Q_OBJECT
31 
32  /**
33  * @property string set the KRunner query
34  */
35  Q_PROPERTY(QString query WRITE scheduleQuery READ currentQuery NOTIFY queryChanged)
36 
37  /**
38  * @property Array The list of all allowed runner plugins that will be executed
39  */
40  Q_PROPERTY(QStringList runners WRITE setRunners READ runners NOTIFY runnersChanged)
41 
42  /**
43  * @property int The number of rows of the model
44  */
45  Q_PROPERTY(int count READ count NOTIFY countChanged)
46 
47  /**
48  * @property bool running: true when queries are in execution
49  */
50  Q_PROPERTY(bool running READ isRunning NOTIFY runningChanged)
51 
52 public:
53  /**
54  * @enum Roles of the model, they will be accessible from delegates
55  */
56  enum Roles {
57  Type = Qt::UserRole + 1,
58  Label,
59  Icon,
60  Relevance,
61  Data,
62  Id,
63  SubText,
64  Enabled,
65  RunnerId,
66  RunnerName,
67  Actions,
68  };
69 
70  explicit RunnerModel(QObject *parent = nullptr);
71  QHash<int, QByteArray> roleNames() const override;
72 
73  QString currentQuery() const;
74 
75  QStringList runners() const;
76  void setRunners(const QStringList &allowedRunners);
77 
78  Q_SCRIPTABLE void run(int row);
79 
80  bool isRunning() const;
81 
82  int rowCount(const QModelIndex &) const override;
83  int count() const;
84  QVariant data(const QModelIndex &, int) const override;
85 
86 public Q_SLOTS:
87  void scheduleQuery(const QString &query);
88 
89 Q_SIGNALS:
90  void queryChanged();
91  void countChanged();
92  void runnersChanged();
93  void runningChanged(bool running);
94 
95 private Q_SLOTS:
96  void startQuery();
97 
98 private:
99  bool createManager();
100 
101 private Q_SLOTS:
102  void matchesChanged(const QList<Plasma::QueryMatch> &matches);
103  void queryHasFinished();
104 
105 private:
106  Plasma::RunnerManager *m_manager = nullptr;
107  QList<Plasma::QueryMatch> m_matches;
108  QStringList m_pendingRunnersList;
109  QString m_singleRunnerId;
110  QString m_pendingQuery;
111  QTimer *const m_startQueryTimer;
112  QTimer *const m_runningChangedTimeout;
113  bool m_running = false;
114 };
115 
116 #endif
Q_OBJECTQ_OBJECT
This model provides bindings to use KRunner from QML.
Definition: runnermodel.h:28
Q_PROPERTY(...)
The RunnerManager class decides what installed runners are runnable, and their ratings....
Definition: runnermanager.h:46
UserRole
Q_SLOTSQ_SLOTS
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sat Dec 2 2023 03:51:00 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.