Changeset View
Changeset View
Standalone View
Standalone View
src/core/engine.cpp
Show All 16 Lines | 1 | /* | |||
---|---|---|---|---|---|
17 | 17 | | |||
18 | You should have received a copy of the GNU Lesser General Public | 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/>. | 19 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #include "engine.h" | 22 | #include "engine.h" | ||
23 | 23 | | |||
24 | #include "../entry.h" | 24 | #include "../entry.h" | ||
25 | #include "commentsmodel.h" | ||||
25 | #include "installation.h" | 26 | #include "installation.h" | ||
26 | #include "xmlloader.h" | 27 | #include "xmlloader.h" | ||
27 | #include "imageloader_p.h" | 28 | #include "imageloader_p.h" | ||
28 | 29 | | |||
29 | #include <kconfig.h> | 30 | #include <kconfig.h> | ||
30 | #include <kconfiggroup.h> | 31 | #include <kconfiggroup.h> | ||
31 | #include <knewstuffcore_debug.h> | 32 | #include <knewstuffcore_debug.h> | ||
32 | #include <klocalizedstring.h> | 33 | #include <klocalizedstring.h> | ||
Show All 26 Lines | |||||
59 | 60 | | |||
60 | class EnginePrivate { | 61 | class EnginePrivate { | ||
61 | public: | 62 | public: | ||
62 | QList<Provider::CategoryMetadata> categoriesMetadata; | 63 | QList<Provider::CategoryMetadata> categoriesMetadata; | ||
63 | Attica::ProviderManager *m_atticaProviderManager = nullptr; | 64 | Attica::ProviderManager *m_atticaProviderManager = nullptr; | ||
64 | QStringList tagFilter; | 65 | QStringList tagFilter; | ||
65 | QStringList downloadTagFilter; | 66 | QStringList downloadTagFilter; | ||
66 | bool configLocationFallback = true; | 67 | bool configLocationFallback = true; | ||
68 | QString name; | ||||
69 | QMap<EntryInternal, CommentsModel*> commentsModels; | ||||
67 | }; | 70 | }; | ||
68 | 71 | | |||
69 | Engine::Engine(QObject *parent) | 72 | Engine::Engine(QObject *parent) | ||
70 | : QObject(parent) | 73 | : QObject(parent) | ||
71 | , m_installation(new Installation) | 74 | , m_installation(new Installation) | ||
72 | , m_cache() | 75 | , m_cache() | ||
73 | , m_searchTimer(new QTimer) | 76 | , m_searchTimer(new QTimer) | ||
74 | , d(new EnginePrivate) | 77 | , d(new EnginePrivate) | ||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | 139 | } else if (conf->hasGroup("KNewStuff2")) { | |||
137 | qCDebug(KNEWSTUFFCORE) << "Loading KNewStuff2 config: " << configfile; | 140 | qCDebug(KNEWSTUFFCORE) << "Loading KNewStuff2 config: " << configfile; | ||
138 | group = conf->group("KNewStuff2"); | 141 | group = conf->group("KNewStuff2"); | ||
139 | } else { | 142 | } else { | ||
140 | emit signalErrorCode(KNSCore::ConfigFileError, i18n("Configuration file is invalid: \"%1\"", configfile), configfile); | 143 | emit signalErrorCode(KNSCore::ConfigFileError, i18n("Configuration file is invalid: \"%1\"", configfile), configfile); | ||
141 | qCCritical(KNEWSTUFFCORE) << configfile << " doesn't contain a KNewStuff3 section."; | 144 | qCCritical(KNEWSTUFFCORE) << configfile << " doesn't contain a KNewStuff3 section."; | ||
142 | return false; | 145 | return false; | ||
143 | } | 146 | } | ||
144 | 147 | | |||
148 | d->name = group.readEntry("Name", QString()); | ||||
145 | m_categories = group.readEntry("Categories", QStringList()); | 149 | m_categories = group.readEntry("Categories", QStringList()); | ||
146 | m_adoptionCommand = group.readEntry("AdoptionCommand", QString()); | 150 | m_adoptionCommand = group.readEntry("AdoptionCommand", QString()); | ||
147 | 151 | | |||
148 | qCDebug(KNEWSTUFFCORE) << "Categories: " << m_categories; | 152 | qCDebug(KNEWSTUFFCORE) << "Categories: " << m_categories; | ||
149 | m_providerFileUrl = group.readEntry("ProvidersUrl", QString()); | 153 | m_providerFileUrl = group.readEntry("ProvidersUrl", QString()); | ||
150 | 154 | | |||
151 | d->tagFilter = group.readEntry("TagFilter", QStringList()); | 155 | d->tagFilter = group.readEntry("TagFilter", QStringList()); | ||
152 | if (d->tagFilter.isEmpty()) { | 156 | if (d->tagFilter.isEmpty()) { | ||
Show All 16 Lines | |||||
169 | m_initialized = true; | 173 | m_initialized = true; | ||
170 | 174 | | |||
171 | // load the providers | 175 | // load the providers | ||
172 | loadProviders(); | 176 | loadProviders(); | ||
173 | 177 | | |||
174 | return true; | 178 | return true; | ||
175 | } | 179 | } | ||
176 | 180 | | |||
181 | QString KNSCore::Engine::name() const | ||||
182 | { | ||||
183 | return d->name; | ||||
184 | } | ||||
185 | | ||||
177 | QStringList Engine::categories() const | 186 | QStringList Engine::categories() const | ||
178 | { | 187 | { | ||
179 | return m_categories; | 188 | return m_categories; | ||
180 | } | 189 | } | ||
181 | 190 | | |||
182 | QStringList Engine::categoriesFilter() const | 191 | QStringList Engine::categoriesFilter() const | ||
183 | { | 192 | { | ||
184 | return m_currentRequest.categories; | 193 | return m_currentRequest.categories; | ||
▲ Show 20 Lines • Show All 202 Lines • ▼ Show 20 Line(s) | |||||
387 | { | 396 | { | ||
388 | if (m_currentRequest.sortMode != mode) { | 397 | if (m_currentRequest.sortMode != mode) { | ||
389 | m_currentRequest.page = -1; | 398 | m_currentRequest.page = -1; | ||
390 | } | 399 | } | ||
391 | m_currentRequest.sortMode = mode; | 400 | m_currentRequest.sortMode = mode; | ||
392 | reloadEntries(); | 401 | reloadEntries(); | ||
393 | } | 402 | } | ||
394 | 403 | | |||
404 | Provider::SortMode KNSCore::Engine::sortMode() const | ||||
405 | { | ||||
406 | return m_currentRequest.sortMode; | ||||
407 | } | ||||
408 | | ||||
395 | void KNSCore::Engine::setFilter(Provider::Filter filter) | 409 | void KNSCore::Engine::setFilter(Provider::Filter filter) | ||
396 | { | 410 | { | ||
397 | if (m_currentRequest.filter != filter) { | 411 | if (m_currentRequest.filter != filter) { | ||
398 | m_currentRequest.page = -1; | 412 | m_currentRequest.page = -1; | ||
399 | } | 413 | } | ||
400 | m_currentRequest.filter = filter; | 414 | m_currentRequest.filter = filter; | ||
401 | reloadEntries(); | 415 | reloadEntries(); | ||
402 | } | 416 | } | ||
403 | 417 | | |||
418 | Provider::Filter KNSCore::Engine::filter() const | ||||
419 | { | ||||
420 | return m_currentRequest.filter; | ||||
421 | } | ||||
422 | | ||||
404 | void KNSCore::Engine::fetchEntryById(const QString& id) | 423 | void KNSCore::Engine::fetchEntryById(const QString &id) | ||
405 | { | 424 | { | ||
406 | m_searchTimer->stop(); | 425 | m_searchTimer->stop(); | ||
407 | m_currentRequest = KNSCore::Provider::SearchRequest(KNSCore::Provider::Newest, KNSCore::Provider::ExactEntryId, id); | 426 | m_currentRequest = KNSCore::Provider::SearchRequest(KNSCore::Provider::Newest, KNSCore::Provider::ExactEntryId, id); | ||
408 | m_currentRequest.pageSize = m_pageSize; | 427 | m_currentRequest.pageSize = m_pageSize; | ||
409 | 428 | | |||
410 | EntryInternal::List cache = m_cache->requestFromCache(m_currentRequest); | 429 | EntryInternal::List cache = m_cache->requestFromCache(m_currentRequest); | ||
411 | if (!cache.isEmpty()) { | 430 | if (!cache.isEmpty()) { | ||
412 | reloadEntries(); | 431 | reloadEntries(); | ||
Show All 9 Lines | 438 | { | |||
422 | EntryInternal::List cache = m_cache->requestFromCache(m_currentRequest); | 441 | EntryInternal::List cache = m_cache->requestFromCache(m_currentRequest); | ||
423 | if (!cache.isEmpty()) { | 442 | if (!cache.isEmpty()) { | ||
424 | reloadEntries(); | 443 | reloadEntries(); | ||
425 | } else { | 444 | } else { | ||
426 | m_searchTimer->start(); | 445 | m_searchTimer->start(); | ||
427 | } | 446 | } | ||
428 | } | 447 | } | ||
429 | 448 | | |||
449 | QString KNSCore::Engine::searchTerm() const | ||||
450 | { | ||||
451 | return m_currentRequest.searchTerm; | ||||
452 | } | ||||
453 | | ||||
430 | void Engine::setTagFilter(const QStringList &filter) | 454 | void Engine::setTagFilter(const QStringList &filter) | ||
431 | { | 455 | { | ||
432 | d->tagFilter = filter; | 456 | d->tagFilter = filter; | ||
433 | for (const QSharedPointer<KNSCore::Provider> &p : qAsConst(m_providers)) { | 457 | for (const QSharedPointer<KNSCore::Provider> &p : qAsConst(m_providers)) { | ||
434 | p->setTagFilter(d->tagFilter); | 458 | p->setTagFilter(d->tagFilter); | ||
435 | } | 459 | } | ||
436 | } | 460 | } | ||
437 | 461 | | |||
▲ Show 20 Lines • Show All 317 Lines • ▼ Show 20 Line(s) | 771 | { | |||
755 | } | 779 | } | ||
756 | return ret; | 780 | return ret; | ||
757 | } | 781 | } | ||
758 | 782 | | |||
759 | void KNSCore::Engine::setConfigLocationFallback(bool enableFallback) | 783 | void KNSCore::Engine::setConfigLocationFallback(bool enableFallback) | ||
760 | { | 784 | { | ||
761 | d->configLocationFallback = enableFallback; | 785 | d->configLocationFallback = enableFallback; | ||
762 | } | 786 | } | ||
787 | | ||||
788 | QSharedPointer<KNSCore::Provider> KNSCore::Engine::provider(const QString &providerId) const | ||||
789 | { | ||||
790 | return m_providers.value(providerId); | ||||
791 | } | ||||
792 | | ||||
793 | QSharedPointer<KNSCore::Provider> KNSCore::Engine::defaultProvider() const | ||||
794 | { | ||||
795 | if (m_providers.count() > 0) | ||||
796 | return m_providers.constBegin().value(); | ||||
797 | return nullptr; | ||||
798 | } | ||||
799 | | ||||
800 | KNSCore::CommentsModel *KNSCore::Engine::commentsForEntry(const KNSCore::EntryInternal &entry) | ||||
801 | { | ||||
802 | CommentsModel *model = d->commentsModels[entry]; | ||||
803 | if (!model) { | ||||
804 | model = new CommentsModel(this); | ||||
broulik: ah, so this is why it's not `const` | |||||
leinir: Indeed :) (and yes, that cache still needs to be made...) | |||||
805 | model->setEntry(entry); | ||||
806 | connect(model, &QObject::destroyed, this, [=](){ | ||||
807 | d->commentsModels.remove(entry); | ||||
808 | }); | ||||
809 | d->commentsModels[entry] = model; | ||||
810 | } | ||||
811 | return model; | ||||
812 | } |
ah, so this is why it's not const