Changeset View
Changeset View
Standalone View
Standalone View
libdiscover/backends/KNSBackend/KNSBackend.cpp
Show All 25 Lines | |||||
26 | #include <QTimer> | 26 | #include <QTimer> | ||
27 | #include <QDirIterator> | 27 | #include <QDirIterator> | ||
28 | 28 | | |||
29 | // Attica includes | 29 | // Attica includes | ||
30 | #include <attica/content.h> | 30 | #include <attica/content.h> | ||
31 | #include <attica/providermanager.h> | 31 | #include <attica/providermanager.h> | ||
32 | 32 | | |||
33 | // KDE includes | 33 | // KDE includes | ||
34 | #include <knewstuffcore_version.h> | ||||
34 | #include <KNSCore/Engine> | 35 | #include <KNSCore/Engine> | ||
35 | #include <KNSCore/QuestionManager> | 36 | #include <KNSCore/QuestionManager> | ||
36 | #include <KConfigGroup> | 37 | #include <KConfigGroup> | ||
37 | #include <KDesktopFile> | 38 | #include <KDesktopFile> | ||
38 | #include <KLocalizedString> | 39 | #include <KLocalizedString> | ||
39 | 40 | | |||
40 | // DiscoverCommon includes | 41 | // DiscoverCommon includes | ||
41 | #include "Transaction/Transaction.h" | 42 | #include "Transaction/Transaction.h" | ||
Show All 34 Lines | 66 | { | |||
76 | return ret; | 77 | return ret; | ||
77 | } | 78 | } | ||
78 | }; | 79 | }; | ||
79 | 80 | | |||
80 | KNSBackend::KNSBackend(QObject* parent, const QString& iconName, const QString &knsrc) | 81 | KNSBackend::KNSBackend(QObject* parent, const QString& iconName, const QString &knsrc) | ||
81 | : AbstractResourcesBackend(parent) | 82 | : AbstractResourcesBackend(parent) | ||
82 | , m_fetching(false) | 83 | , m_fetching(false) | ||
83 | , m_isValid(true) | 84 | , m_isValid(true) | ||
84 | , m_page(0) | | |||
85 | , m_reviews(new KNSReviews(this)) | 85 | , m_reviews(new KNSReviews(this)) | ||
86 | , m_name(knsrc) | 86 | , m_name(knsrc) | ||
87 | , m_iconName(iconName) | 87 | , m_iconName(iconName) | ||
88 | , m_updater(new StandardBackendUpdater(this)) | 88 | , m_updater(new StandardBackendUpdater(this)) | ||
89 | { | 89 | { | ||
90 | const QString fileName = QFileInfo(m_name).fileName(); | 90 | const QString fileName = QFileInfo(m_name).fileName(); | ||
91 | setName(fileName); | 91 | setName(fileName); | ||
92 | setObjectName(knsrc); | 92 | setObjectName(knsrc); | ||
93 | 93 | | |||
94 | const KConfig conf(m_name); | 94 | const KConfig conf(m_name); | ||
95 | if (!conf.hasGroup("KNewStuff3")) { | 95 | if (!conf.hasGroup("KNewStuff3")) { | ||
96 | markInvalid(QStringLiteral("Config group not found! Check your KNS3 installation.")); | 96 | markInvalid(QStringLiteral("Config group not found! Check your KNS3 installation.")); | ||
97 | return; | 97 | return; | ||
98 | } | 98 | } | ||
99 | 99 | | |||
100 | m_categories = QStringList{ fileName }; | 100 | m_categories = QStringList{ fileName }; | ||
101 | 101 | | |||
102 | const KConfigGroup group = conf.group("KNewStuff3"); | 102 | const KConfigGroup group = conf.group("KNewStuff3"); | ||
103 | m_extends = group.readEntry("Extends", QStringList()); | 103 | m_extends = group.readEntry("Extends", QStringList()); | ||
104 | m_reviews->setProviderUrl(QUrl(group.readEntry("ProvidersUrl", QString()))); | 104 | m_reviews->setProviderUrl(QUrl(group.readEntry("ProvidersUrl", QString()))); | ||
105 | 105 | | |||
106 | setFetching(true); | 106 | setFetching(true); | ||
107 | 107 | | |||
108 | m_engine = new KNSCore::Engine(this); | 108 | m_engine = new KNSCore::Engine(this); | ||
109 | m_engine->init(m_name); | 109 | m_engine->init(m_name); | ||
apol: Add an `#if KNEWSTUFF_VERSION_MAJOR==5 && KNEWSTUFF_VERSION_MINOR==36`
We always end up… | |||||
Very true, yes - to be quite frank, i forgot about the preprocessor for a moment, there ;) leinir: Very true, yes - to be quite frank, i forgot about the preprocessor for a moment, there ;) | |||||
110 | #if KNEWSTUFFCORE_VERSION_MAJOR==5 && KNEWSTUFFCORE_VERSION_MAJOR>=36 | ||||
111 | m_engine->setPageSize(100); | ||||
112 | #endif | ||||
110 | // Setting setFetching to false when we get an error ensures we don't end up in an eternally-fetching state | 113 | // Setting setFetching to false when we get an error ensures we don't end up in an eternally-fetching state | ||
111 | connect(m_engine, &KNSCore::Engine::signalError, this, [this](const QString &error) { | 114 | connect(m_engine, &KNSCore::Engine::signalError, this, [this](const QString &error) { | ||
112 | if(error == QLatin1Literal("All categories are missing")) { | 115 | if(error == QLatin1Literal("All categories are missing")) { | ||
113 | markInvalid(error); | 116 | markInvalid(error); | ||
114 | } | 117 | } | ||
115 | m_responsePending = false; | 118 | m_responsePending = false; | ||
116 | Q_EMIT searchFinished(); | 119 | Q_EMIT searchFinished(); | ||
117 | Q_EMIT availableForQueries(); | 120 | Q_EMIT availableForQueries(); | ||
118 | this->setFetching(false); | 121 | this->setFetching(false); | ||
119 | qWarning() << "kns error" << objectName() << error; | 122 | qWarning() << "kns error" << objectName() << error; | ||
120 | }); | 123 | }); | ||
121 | connect(m_engine, &KNSCore::Engine::signalEntriesLoaded, this, &KNSBackend::receivedEntries, Qt::QueuedConnection); | 124 | connect(m_engine, &KNSCore::Engine::signalEntriesLoaded, this, &KNSBackend::receivedEntries, Qt::QueuedConnection); | ||
122 | connect(m_engine, &KNSCore::Engine::signalEntryChanged, this, &KNSBackend::statusChanged); | 125 | connect(m_engine, &KNSCore::Engine::signalEntryChanged, this, &KNSBackend::statusChanged); | ||
123 | connect(m_engine, &KNSCore::Engine::signalEntryDetailsLoaded, this, &KNSBackend::statusChanged); | 126 | connect(m_engine, &KNSCore::Engine::signalEntryDetailsLoaded, this, &KNSBackend::statusChanged); | ||
124 | m_page = -1; | | |||
125 | connect(m_engine, &KNSCore::Engine::signalProvidersLoaded, m_engine, &KNSCore::Engine::checkForInstalled); | 127 | connect(m_engine, &KNSCore::Engine::signalProvidersLoaded, m_engine, &KNSCore::Engine::checkForInstalled); | ||
128 | connect(m_engine, &KNSCore::Engine::signalResetView, this, [this](){ | ||||
129 | // If KNS tells us we should reset the view, what that means here is to remove | ||||
130 | // references to all the resources we've already told the agregator model about | ||||
Good, maybe we should also delete them? apol: Good, maybe we should also delete them?
Can you see if the StandardUpdater is listening to… | |||||
Yes, that does seem like a good idea, if we're reasonably certain they're not accessed in other places... leinir: Yes, that does seem like a good idea, if we're reasonably certain they're not accessed in other… | |||||
131 | // from the model, as they will be added again... | ||||
132 | foreach(AbstractResource* res, m_resourcesByName.values()) { | ||||
133 | resourceRemoved(res); | ||||
134 | res->deleteLater(); | ||||
135 | } | ||||
136 | m_resourcesByName.clear(); | ||||
137 | }); | ||||
126 | m_responsePending = true; | 138 | m_responsePending = true; | ||
127 | 139 | | |||
128 | const QVector<QPair<FilterType, QString>> filters = { {CategoryFilter, fileName } }; | 140 | const QVector<QPair<FilterType, QString>> filters = { {CategoryFilter, fileName } }; | ||
129 | const QSet<QString> backendName = { name() }; | 141 | const QSet<QString> backendName = { name() }; | ||
130 | QString displayName = group.readEntry("Name", QString()); | 142 | QString displayName = group.readEntry("Name", QString()); | ||
131 | if (displayName.isEmpty()) { | 143 | if (displayName.isEmpty()) { | ||
132 | displayName = fileName.mid(0, fileName.indexOf(QLatin1Char('.'))); | 144 | displayName = fileName.mid(0, fileName.indexOf(QLatin1Char('.'))); | ||
133 | displayName[0] = displayName[0].toUpper(); | 145 | displayName[0] = displayName[0].toUpper(); | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | |||||
186 | { | 198 | { | ||
187 | m_responsePending = false; | 199 | m_responsePending = false; | ||
188 | 200 | | |||
189 | const auto resources = kTransform<QVector<AbstractResource*>>(entries, [this](const KNSCore::EntryInternal& entry){ return resourceForEntry(entry); }); | 201 | const auto resources = kTransform<QVector<AbstractResource*>>(entries, [this](const KNSCore::EntryInternal& entry){ return resourceForEntry(entry); }); | ||
190 | if (!resources.isEmpty()) { | 202 | if (!resources.isEmpty()) { | ||
191 | Q_EMIT receivedResources(resources); | 203 | Q_EMIT receivedResources(resources); | ||
192 | } | 204 | } | ||
193 | 205 | | |||
194 | if(resources.isEmpty() || m_page < 0) { | 206 | if(resources.isEmpty()) { | ||
195 | Q_EMIT searchFinished(); | 207 | Q_EMIT searchFinished(); | ||
196 | Q_EMIT availableForQueries(); | 208 | Q_EMIT availableForQueries(); | ||
197 | setFetching(false); | 209 | setFetching(false); | ||
198 | return; | 210 | return; | ||
199 | } | 211 | } | ||
200 | // qDebug() << "received" << objectName() << this << m_page << m_resourcesByName.count(); | 212 | // qDebug() << "received" << objectName() << this << m_resourcesByName.count(); | ||
201 | if (!m_responsePending) { | 213 | if (!m_responsePending) { | ||
202 | ++m_page; | | |||
203 | // We _have_ to set this first. If we do not, we may run into a situation where the | 214 | // We _have_ to set this first. If we do not, we may run into a situation where the | ||
204 | // data request will conclude immediately, causing m_responsePending to remain true | 215 | // data request will conclude immediately, causing m_responsePending to remain true | ||
205 | // for perpetuity as the slots will be called before the function returns. | 216 | // for perpetuity as the slots will be called before the function returns. | ||
206 | m_responsePending = true; | 217 | m_responsePending = true; | ||
207 | m_engine->requestData(m_page, 100); | 218 | m_engine->requestMoreData(); | ||
208 | } else { | 219 | } else { | ||
209 | Q_EMIT availableForQueries(); | 220 | Q_EMIT availableForQueries(); | ||
210 | } | 221 | } | ||
211 | } | 222 | } | ||
212 | 223 | | |||
213 | void KNSBackend::statusChanged(const KNSCore::EntryInternal& entry) | 224 | void KNSBackend::statusChanged(const KNSCore::EntryInternal& entry) | ||
214 | { | 225 | { | ||
215 | resourceForEntry(entry); | 226 | resourceForEntry(entry); | ||
▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Line(s) | 315 | { | |||
322 | return voidStream(); | 333 | return voidStream(); | ||
323 | } | 334 | } | ||
324 | 335 | | |||
325 | ResultsStream * KNSBackend::searchStream(const QString &searchText) | 336 | ResultsStream * KNSBackend::searchStream(const QString &searchText) | ||
326 | { | 337 | { | ||
327 | Q_EMIT startingSearch(); | 338 | Q_EMIT startingSearch(); | ||
328 | 339 | | |||
329 | auto stream = new ResultsStream(QStringLiteral("KNS-search-")+name()); | 340 | auto stream = new ResultsStream(QStringLiteral("KNS-search-")+name()); | ||
330 | auto start = [this, stream, searchText]() { | | |||
331 | m_engine->setSearchTerm(searchText); | | |||
332 | m_engine->requestData(0, 100); | | |||
333 | m_responsePending = true; | | |||
334 | m_page = 0; | | |||
335 | connect(this, &KNSBackend::receivedResources, stream, &ResultsStream::resourcesFound); | 341 | connect(this, &KNSBackend::receivedResources, stream, &ResultsStream::resourcesFound); | ||
336 | connect(this, &KNSBackend::searchFinished, stream, &ResultsStream::finish); | 342 | connect(this, &KNSBackend::searchFinished, stream, &ResultsStream::finish); | ||
337 | connect(this, &KNSBackend::startingSearch, stream, &ResultsStream::finish); | 343 | connect(this, &KNSBackend::startingSearch, stream, &ResultsStream::finish); | ||
344 | auto start = [this, searchText]() { | ||||
345 | // No need to explicitly launch a search, setting the search term already does that for us | ||||
346 | m_engine->setSearchTerm(searchText); | ||||
347 | m_responsePending = true; | ||||
338 | }; | 348 | }; | ||
339 | if (m_responsePending) { | 349 | if (m_responsePending) { | ||
340 | connect(this, &KNSBackend::availableForQueries, stream, start, Qt::QueuedConnection); | 350 | connect(this, &KNSBackend::availableForQueries, stream, start, Qt::QueuedConnection); | ||
341 | } else { | 351 | } else { | ||
342 | start(); | 352 | start(); | ||
343 | } | 353 | } | ||
344 | return stream; | 354 | return stream; | ||
345 | } | 355 | } | ||
▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines |
Add an #if KNEWSTUFF_VERSION_MAJOR==5 && KNEWSTUFF_VERSION_MINOR==36
We always end up forgetting these fixme