Changeset View
Changeset View
Standalone View
Standalone View
lib/runnerresultsmodel.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * This file is part of the KDE Milou Project | ||||
3 | * Copyright (C) 2019 Kai Uwe Broulik <kde@broulik.de> | ||||
4 | * | ||||
5 | * This library is free software; you can redistribute it and/or | ||||
6 | * modify it under the terms of the GNU Lesser General Public | ||||
7 | * License as published by the Free Software Foundation; either | ||||
8 | * version 2.1 of the License, or (at your option) version 3, or any | ||||
9 | * later version accepted by the membership of KDE e.V. (or its | ||||
10 | * successor approved by the membership of KDE e.V.), which shall | ||||
11 | * act as a proxy defined in Section 6 of version 3 of the license. | ||||
12 | * | ||||
13 | * This library is distributed in the hope that it will be useful, | ||||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
16 | * Lesser General Public License for more details. | ||||
17 | * | ||||
18 | * You should have received a copy of the GNU Lesser General Public | ||||
19 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
20 | * | ||||
21 | */ | ||||
22 | | ||||
23 | #pragma once | ||||
24 | | ||||
25 | #include <QAbstractItemModel> | ||||
26 | #include <QHash> | ||||
27 | #include <QTimer> | ||||
28 | #include <QString> | ||||
29 | | ||||
30 | #include <KRunner/QueryMatch> | ||||
31 | | ||||
32 | namespace Plasma { | ||||
33 | class RunnerManager; | ||||
34 | } | ||||
35 | | ||||
36 | namespace Milou { | ||||
37 | | ||||
38 | class RunnerResultsModel : public QAbstractItemModel | ||||
39 | { | ||||
40 | Q_OBJECT | ||||
41 | | ||||
42 | public: | ||||
43 | explicit RunnerResultsModel(QObject *parent = nullptr); | ||||
44 | ~RunnerResultsModel() override; | ||||
45 | | ||||
46 | QString queryString() const; | ||||
47 | void setQueryString(const QString &queryString); | ||||
48 | Q_SIGNAL void queryStringChanged(); | ||||
49 | | ||||
50 | bool querying() const; | ||||
51 | Q_SIGNAL void queryingChanged(); | ||||
52 | | ||||
53 | QString runner() const; | ||||
54 | void setRunner(const QString &runner); | ||||
55 | Q_SIGNAL void runnerChanged(); | ||||
56 | | ||||
57 | QString runnerName() const; | ||||
58 | QIcon runnerIcon() const; | ||||
59 | | ||||
60 | /** | ||||
61 | * Clears the model content and resets the runner context, i.e. no new items will appear. | ||||
62 | */ | ||||
63 | void clear(); | ||||
64 | | ||||
65 | bool run(const QModelIndex &idx); | ||||
66 | bool runAction(const QModelIndex &idx, int actionNumber); | ||||
67 | | ||||
68 | int columnCount(const QModelIndex &parent) const override; | ||||
69 | int rowCount(const QModelIndex &parent) const override; | ||||
70 | | ||||
71 | QVariant data(const QModelIndex &index, int role) const override; | ||||
72 | | ||||
73 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; | ||||
74 | QModelIndex parent(const QModelIndex &child) const override; | ||||
75 | | ||||
76 | QMimeData *mimeData(const QModelIndexList &indexes) const override; | ||||
77 | | ||||
78 | Q_SIGNALS: | ||||
79 | void queryStringChangeRequested(const QString &queryString, int pos); | ||||
80 | | ||||
81 | private: | ||||
82 | void setQuerying(bool querying); | ||||
83 | | ||||
84 | Plasma::QueryMatch fetchMatch(const QModelIndex &idx) const; | ||||
85 | | ||||
86 | void onMatchesChanged(const QList<Plasma::QueryMatch> &matches); | ||||
87 | | ||||
88 | Plasma::RunnerManager *m_manager; | ||||
89 | | ||||
90 | QString m_queryString; | ||||
91 | bool m_querying = false; | ||||
92 | | ||||
93 | QString m_runner; | ||||
94 | | ||||
95 | QTimer m_resetTimer; | ||||
96 | bool m_hasMatches = false; | ||||
97 | | ||||
98 | QStringList m_categories; | ||||
99 | QHash<QString /*category*/, QVector<Plasma::QueryMatch>> m_matches; | ||||
100 | | ||||
101 | }; | ||||
102 | | ||||
103 | } // namespace Milou |