Changeset View
Changeset View
Standalone View
Standalone View
src/attica/atticaprovider.cpp
Show All 36 Lines | |||||
37 | namespace KNSCore | 37 | namespace KNSCore | ||
38 | { | 38 | { | ||
39 | 39 | | |||
40 | AtticaProvider::AtticaProvider(const QStringList &categories) | 40 | AtticaProvider::AtticaProvider(const QStringList &categories) | ||
41 | : mEntryJob(nullptr) | 41 | : mEntryJob(nullptr) | ||
42 | , mInitialized(false) | 42 | , mInitialized(false) | ||
43 | { | 43 | { | ||
44 | // init categories map with invalid categories | 44 | // init categories map with invalid categories | ||
45 | foreach (const QString &category, categories) { | 45 | for (const QString &category : categories) { | ||
46 | mCategoryMap.insert(category, Attica::Category()); | 46 | mCategoryMap.insert(category, Attica::Category()); | ||
47 | } | 47 | } | ||
48 | 48 | | |||
49 | connect(&m_providerManager, &ProviderManager::providerAdded, this, &AtticaProvider::providerLoaded); | 49 | connect(&m_providerManager, &ProviderManager::providerAdded, this, &AtticaProvider::providerLoaded); | ||
50 | connect(&m_providerManager, SIGNAL(authenticationCredentialsMissing(Provider)), | 50 | connect(&m_providerManager, SIGNAL(authenticationCredentialsMissing(Provider)), | ||
51 | SLOT(authenticationCredentialsMissing(Provider))); | 51 | SLOT(authenticationCredentialsMissing(Provider))); | ||
52 | } | 52 | } | ||
53 | 53 | | |||
54 | AtticaProvider::AtticaProvider(const Attica::Provider &provider, const QStringList &categories) | 54 | AtticaProvider::AtticaProvider(const Attica::Provider &provider, const QStringList &categories) | ||
55 | : mEntryJob(nullptr) | 55 | : mEntryJob(nullptr) | ||
56 | , mInitialized(false) | 56 | , mInitialized(false) | ||
57 | { | 57 | { | ||
58 | // init categories map with invalid categories | 58 | // init categories map with invalid categories | ||
59 | foreach (const QString &category, categories) { | 59 | for (const QString &category : categories) { | ||
60 | mCategoryMap.insert(category, Attica::Category()); | 60 | mCategoryMap.insert(category, Attica::Category()); | ||
61 | } | 61 | } | ||
62 | providerLoaded(provider); | 62 | providerLoaded(provider); | ||
63 | } | 63 | } | ||
64 | 64 | | |||
65 | QString AtticaProvider::id() const | 65 | QString AtticaProvider::id() const | ||
66 | { | 66 | { | ||
67 | return m_providerId; | 67 | return m_providerId; | ||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | |||||
117 | { | 117 | { | ||
118 | if (!jobSuccess(listJob)) { | 118 | if (!jobSuccess(listJob)) { | ||
119 | return; | 119 | return; | ||
120 | } | 120 | } | ||
121 | 121 | | |||
122 | qCDebug(KNEWSTUFFCORE) << "loading categories: " << mCategoryMap.keys(); | 122 | qCDebug(KNEWSTUFFCORE) << "loading categories: " << mCategoryMap.keys(); | ||
123 | 123 | | |||
124 | Attica::ListJob<Attica::Category> *job = static_cast<Attica::ListJob<Attica::Category>*>(listJob); | 124 | Attica::ListJob<Attica::Category> *job = static_cast<Attica::ListJob<Attica::Category>*>(listJob); | ||
125 | Category::List categoryList = job->itemList(); | 125 | const Category::List categoryList = job->itemList(); | ||
126 | 126 | | |||
127 | QList<CategoryMetadata> categoryMetadataList; | 127 | QList<CategoryMetadata> categoryMetadataList; | ||
128 | foreach (const Category &category, categoryList) { | 128 | for (const Category &category : categoryList) { | ||
129 | if (mCategoryMap.contains(category.name())) { | 129 | if (mCategoryMap.contains(category.name())) { | ||
130 | qCDebug(KNEWSTUFFCORE) << "Adding category: " << category.name() << category.displayName(); | 130 | qCDebug(KNEWSTUFFCORE) << "Adding category: " << category.name() << category.displayName(); | ||
131 | //If there is only the placeholder category, replace it | 131 | //If there is only the placeholder category, replace it | ||
132 | if (mCategoryMap.contains(category.name()) && !mCategoryMap.value(category.name()).isValid()) { | 132 | if (mCategoryMap.contains(category.name()) && !mCategoryMap.value(category.name()).isValid()) { | ||
133 | mCategoryMap.insert(category.name(), category); | 133 | mCategoryMap.insert(category.name(), category); | ||
134 | } else { | 134 | } else { | ||
135 | mCategoryMap.insertMulti(category.name(), category); | 135 | mCategoryMap.insertMulti(category.name(), category); | ||
136 | } | 136 | } | ||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Line(s) | 176 | { | |||
204 | Attica::Provider::SortMode sorting = atticaSortMode(request.sortMode); | 204 | Attica::Provider::SortMode sorting = atticaSortMode(request.sortMode); | ||
205 | Attica::Category::List categoriesToSearch; | 205 | Attica::Category::List categoriesToSearch; | ||
206 | 206 | | |||
207 | if (request.categories.isEmpty()) { | 207 | if (request.categories.isEmpty()) { | ||
208 | // search in all categories | 208 | // search in all categories | ||
209 | categoriesToSearch = mCategoryMap.values(); | 209 | categoriesToSearch = mCategoryMap.values(); | ||
210 | } else { | 210 | } else { | ||
211 | categoriesToSearch.reserve(request.categories.size()); | 211 | categoriesToSearch.reserve(request.categories.size()); | ||
212 | foreach (const QString &categoryName, request.categories) { | 212 | for (const QString &categoryName : qAsConst(request.categories)) { | ||
213 | categoriesToSearch.append(mCategoryMap.values(categoryName)); | 213 | categoriesToSearch.append(mCategoryMap.values(categoryName)); | ||
214 | } | 214 | } | ||
215 | } | 215 | } | ||
216 | 216 | | |||
217 | ListJob<Content> *job = m_provider.searchContents(categoriesToSearch, request.searchTerm, sorting, request.page, request.pageSize); | 217 | ListJob<Content> *job = m_provider.searchContents(categoriesToSearch, request.searchTerm, sorting, request.page, request.pageSize); | ||
218 | connect(job, &BaseJob::finished, this, &AtticaProvider::categoryContentsLoaded); | 218 | connect(job, &BaseJob::finished, this, &AtticaProvider::categoryContentsLoaded); | ||
219 | 219 | | |||
220 | mEntryJob = job; | 220 | mEntryJob = job; | ||
221 | job->start(); | 221 | job->start(); | ||
222 | } | 222 | } | ||
223 | 223 | | |||
224 | void AtticaProvider::checkForUpdates() | 224 | void AtticaProvider::checkForUpdates() | ||
225 | { | 225 | { | ||
226 | foreach (const EntryInternal &e, mCachedEntries) { | 226 | for (const EntryInternal &e : qAsConst(mCachedEntries)) { | ||
227 | ItemJob<Content> *job = m_provider.requestContent(e.uniqueId()); | 227 | ItemJob<Content> *job = m_provider.requestContent(e.uniqueId()); | ||
228 | connect(job, &BaseJob::finished, this, &AtticaProvider::detailsLoaded); | 228 | connect(job, &BaseJob::finished, this, &AtticaProvider::detailsLoaded); | ||
229 | m_updateJobs.insert(job); | 229 | m_updateJobs.insert(job); | ||
230 | job->start(); | 230 | job->start(); | ||
231 | qCDebug(KNEWSTUFFCORE) << "Checking for update: " << e.name(); | 231 | qCDebug(KNEWSTUFFCORE) << "Checking for update: " << e.name(); | ||
232 | } | 232 | } | ||
233 | } | 233 | } | ||
234 | 234 | | |||
Show All 12 Lines | 244 | if (jobSuccess(job)) { | |||
247 | EntryInternal entry = entryFromAtticaContent(content); | 247 | EntryInternal entry = entryFromAtticaContent(content); | ||
248 | emit entryDetailsLoaded(entry); | 248 | emit entryDetailsLoaded(entry); | ||
249 | qCDebug(KNEWSTUFFCORE) << "check update finished: " << entry.name(); | 249 | qCDebug(KNEWSTUFFCORE) << "check update finished: " << entry.name(); | ||
250 | } | 250 | } | ||
251 | 251 | | |||
252 | if (m_updateJobs.remove(job) && m_updateJobs.isEmpty()) { | 252 | if (m_updateJobs.remove(job) && m_updateJobs.isEmpty()) { | ||
253 | qCDebug(KNEWSTUFFCORE) << "check update finished."; | 253 | qCDebug(KNEWSTUFFCORE) << "check update finished."; | ||
254 | QList<EntryInternal> updatable; | 254 | QList<EntryInternal> updatable; | ||
255 | foreach (const EntryInternal &entry, mCachedEntries) { | 255 | for (const EntryInternal &entry : qAsConst(mCachedEntries)) { | ||
256 | if (entry.status() == KNS3::Entry::Updateable) { | 256 | if (entry.status() == KNS3::Entry::Updateable) { | ||
257 | updatable.append(entry); | 257 | updatable.append(entry); | ||
258 | } | 258 | } | ||
259 | } | 259 | } | ||
260 | emit loadingFinished(mCurrentRequest, updatable); | 260 | emit loadingFinished(mCurrentRequest, updatable); | ||
261 | } | 261 | } | ||
262 | } | 262 | } | ||
263 | 263 | | |||
▲ Show 20 Lines • Show All 126 Lines • ▼ Show 20 Line(s) | 382 | { | |||
390 | EntryInternal entry = mDownloadLinkJobs.take(job).first; | 390 | EntryInternal entry = mDownloadLinkJobs.take(job).first; | ||
391 | entry.setPayload(QString(item.url().toString())); | 391 | entry.setPayload(QString(item.url().toString())); | ||
392 | emit payloadLinkLoaded(entry); | 392 | emit payloadLinkLoaded(entry); | ||
393 | } | 393 | } | ||
394 | 394 | | |||
395 | EntryInternal::List AtticaProvider::installedEntries() const | 395 | EntryInternal::List AtticaProvider::installedEntries() const | ||
396 | { | 396 | { | ||
397 | EntryInternal::List entries; | 397 | EntryInternal::List entries; | ||
398 | foreach (const EntryInternal &entry, mCachedEntries) { | 398 | for (const EntryInternal &entry : qAsConst(mCachedEntries)) { | ||
399 | if (entry.status() == KNS3::Entry::Installed || entry.status() == KNS3::Entry::Updateable) { | 399 | if (entry.status() == KNS3::Entry::Installed || entry.status() == KNS3::Entry::Updateable) { | ||
400 | entries.append(entry); | 400 | entries.append(entry); | ||
401 | } | 401 | } | ||
402 | } | 402 | } | ||
403 | return entries; | 403 | return entries; | ||
404 | } | 404 | } | ||
405 | 405 | | |||
406 | void AtticaProvider::vote(const EntryInternal &entry, uint rating) | 406 | void AtticaProvider::vote(const EntryInternal &entry, uint rating) | ||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Line(s) | 457 | { | |||
505 | 505 | | |||
506 | entry.setSource(EntryInternal::Online); | 506 | entry.setSource(EntryInternal::Online); | ||
507 | entry.setSummary(content.description()); | 507 | entry.setSummary(content.description()); | ||
508 | entry.setShortSummary(content.summary()); | 508 | entry.setShortSummary(content.summary()); | ||
509 | entry.setChangelog(content.changelog()); | 509 | entry.setChangelog(content.changelog()); | ||
510 | entry.setTags(content.tags()); | 510 | entry.setTags(content.tags()); | ||
511 | 511 | | |||
512 | entry.clearDownloadLinkInformation(); | 512 | entry.clearDownloadLinkInformation(); | ||
513 | QList<Attica::DownloadDescription> descs = content.downloadUrlDescriptions(); | 513 | const QList<Attica::DownloadDescription> descs = content.downloadUrlDescriptions(); | ||
514 | foreach (const Attica::DownloadDescription &desc, descs) { | 514 | for (const Attica::DownloadDescription &desc : descs) { | ||
515 | EntryInternal::DownloadLinkInformation info; | 515 | EntryInternal::DownloadLinkInformation info; | ||
516 | info.name = desc.name(); | 516 | info.name = desc.name(); | ||
517 | info.priceAmount = desc.priceAmount(); | 517 | info.priceAmount = desc.priceAmount(); | ||
518 | info.distributionType = desc.distributionType(); | 518 | info.distributionType = desc.distributionType(); | ||
519 | info.descriptionLink = desc.link(); | 519 | info.descriptionLink = desc.link(); | ||
520 | info.id = desc.id(); | 520 | info.id = desc.id(); | ||
521 | info.size = desc.size(); | 521 | info.size = desc.size(); | ||
522 | info.isDownloadtypeLink = desc.type() == Attica::DownloadDescription::LinkDownload; | 522 | info.isDownloadtypeLink = desc.type() == Attica::DownloadDescription::LinkDownload; | ||
Show All 9 Lines |