Changeset View
Changeset View
Standalone View
Standalone View
src/qtquick/quickengine.cpp
Show All 19 Lines | |||||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #include "quickengine.h" | 22 | #include "quickengine.h" | ||
23 | 23 | | |||
24 | #include <KAuthorized> | 24 | #include <KAuthorized> | ||
25 | #include <KLocalizedString> | 25 | #include <KLocalizedString> | ||
26 | 26 | | |||
27 | #include "categoriesmodel.h" | 27 | #include "categoriesmodel.h" | ||
28 | #include "entrywrapper.h" | ||||
28 | #include "quickquestionlistener.h" | 29 | #include "quickquestionlistener.h" | ||
29 | 30 | | |||
30 | #include "engine.h" | 31 | #include "engine.h" | ||
31 | 32 | | |||
32 | class Engine::Private | 33 | class Engine::Private | ||
33 | { | 34 | { | ||
34 | public: | 35 | public: | ||
35 | Private() | 36 | Private() | ||
36 | : engine(nullptr) | 37 | : engine(nullptr) | ||
37 | , categoriesModel(nullptr) | 38 | , categoriesModel(nullptr) | ||
38 | {} | 39 | {} | ||
39 | KNSCore::Engine *engine; | 40 | KNSCore::Engine *engine; | ||
40 | bool isLoading{false}; | 41 | bool isLoading{false}; | ||
41 | CategoriesModel *categoriesModel; | 42 | CategoriesModel *categoriesModel; | ||
42 | QString configFile; | 43 | QString configFile; | ||
44 | | ||||
43 | KNSCore::EntryInternal::List changedEntries; | 45 | KNSCore::EntryInternal::List changedEntries; | ||
46 | static QObject *getChangedEntry(QQmlListProperty<QObject>* property, int i) | ||||
47 | { | ||||
48 | QObject *entry{nullptr}; | ||||
49 | if (property) { | ||||
50 | Private* d = static_cast<Engine::Private*>(property->data); | ||||
51 | if (d) { | ||||
52 | if (i >= 0 && i < d->changedEntries.count()) { | ||||
53 | // Lifetime management for these objects should be done by the consumer, | ||||
54 | // but are also parented for auto-delete on application shutdown | ||||
55 | entry = new KNSCore::EntryWrapper(d->changedEntries[i], property->object); | ||||
56 | } | ||||
57 | } | ||||
58 | } | ||||
59 | return entry; | ||||
60 | } | ||||
61 | static int getChangedEntriesCount(QQmlListProperty<QObject>* property) | ||||
62 | { | ||||
63 | int count{0}; | ||||
64 | if (property) { | ||||
65 | Private* d = static_cast<Engine::Private*>(property->data); | ||||
66 | if (d) { | ||||
67 | count = d->changedEntries.count(); | ||||
68 | } | ||||
69 | } | ||||
70 | return count; | ||||
71 | } | ||||
44 | }; | 72 | }; | ||
45 | 73 | | |||
46 | Engine::Engine(QObject *parent) | 74 | Engine::Engine(QObject *parent) | ||
47 | : QObject(parent) | 75 | : QObject(parent) | ||
48 | , d(new Private) | 76 | , d(new Private) | ||
49 | { | 77 | { | ||
50 | } | 78 | } | ||
51 | 79 | | |||
Show All 37 Lines | 115 | if (errorCode == KNSCore::ProviderError) { | |||
89 | // initialisation. It also means the engine is done loading, but that nothing will | 117 | // initialisation. It also means the engine is done loading, but that nothing will | ||
90 | // work, and we need to inform the user of this. | 118 | // work, and we need to inform the user of this. | ||
91 | d->isLoading = false; | 119 | d->isLoading = false; | ||
92 | emit isLoadingChanged(); | 120 | emit isLoadingChanged(); | ||
93 | } | 121 | } | ||
94 | emit errorMessage(message); | 122 | emit errorMessage(message); | ||
95 | }); | 123 | }); | ||
96 | connect(d->engine, &KNSCore::Engine::signalEntryChanged, this, [this](const KNSCore::EntryInternal &entry){ | 124 | connect(d->engine, &KNSCore::Engine::signalEntryChanged, this, [this](const KNSCore::EntryInternal &entry){ | ||
125 | if (d->changedEntries.contains(entry) ) { | ||||
126 | d->changedEntries.removeAll(entry); | ||||
127 | } | ||||
97 | d->changedEntries << entry; | 128 | d->changedEntries << entry; | ||
98 | emit changedEntriesChanged(); | 129 | emit changedEntriesChanged(); | ||
99 | }); | 130 | }); | ||
100 | emit engineChanged(); | 131 | emit engineChanged(); | ||
101 | KNewStuffQuick::QuickQuestionListener::instance(); | 132 | KNewStuffQuick::QuickQuestionListener::instance(); | ||
102 | d->categoriesModel = new CategoriesModel(this); | 133 | d->categoriesModel = new CategoriesModel(this); | ||
103 | emit categoriesChanged(); | 134 | emit categoriesChanged(); | ||
104 | } | 135 | } | ||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Line(s) | 248 | { | |||
221 | } | 252 | } | ||
222 | } | 253 | } | ||
223 | 254 | | |||
224 | void Engine::resetSearchTerm() | 255 | void Engine::resetSearchTerm() | ||
225 | { | 256 | { | ||
226 | setSearchTerm(QString{}); | 257 | setSearchTerm(QString{}); | ||
227 | } | 258 | } | ||
228 | 259 | | |||
229 | KNSCore::EntryInternal::List Engine::changedEntries() const | 260 | QQmlListProperty<QObject> Engine::changedEntries() | ||
230 | { | 261 | { | ||
231 | return d->changedEntries; | 262 | return QQmlListProperty<QObject>(this, d, &Private::getChangedEntriesCount, &Private::getChangedEntry); | ||
232 | } | 263 | } | ||
233 | 264 | | |||
234 | int Engine::changedEntriesCount() const | 265 | int Engine::changedEntriesCount() const | ||
235 | { | 266 | { | ||
236 | return d->changedEntries.count(); | 267 | return d->changedEntries.count(); | ||
237 | } | 268 | } | ||
238 | 269 | | |||
239 | void Engine::resetChangedEntries() | 270 | void Engine::resetChangedEntries() | ||
240 | { | 271 | { | ||
241 | d->changedEntries.clear(); | 272 | d->changedEntries.clear(); | ||
242 | emit changedEntriesChanged(); | 273 | emit changedEntriesChanged(); | ||
243 | } | 274 | } |