Changeset View
Standalone View
src/attica/atticaprovider.cpp
Show All 11 Lines | 1 | /* | |||
---|---|---|---|---|---|
12 | Lesser General Public License for more details. | 12 | Lesser General Public License for more details. | ||
13 | 13 | | |||
14 | You should have received a copy of the GNU Lesser General Public | 14 | You should have received a copy of the GNU Lesser General Public | ||
15 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | 15 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | 16 | */ | ||
17 | 17 | | |||
18 | #include "atticaprovider_p.h" | 18 | #include "atticaprovider_p.h" | ||
19 | 19 | | |||
20 | #include "commentsmodel.h" | ||||
20 | #include "question.h" | 21 | #include "question.h" | ||
21 | #include "tagsfilterchecker.h" | 22 | #include "tagsfilterchecker.h" | ||
22 | 23 | | |||
23 | #include <QCollator> | 24 | #include <QCollator> | ||
24 | #include <knewstuffcore_debug.h> | 25 | #include <knewstuffcore_debug.h> | ||
25 | #include <klocalizedstring.h> | 26 | #include <klocalizedstring.h> | ||
26 | 27 | | |||
27 | #include <attica/providermanager.h> | 28 | #include <attica/providermanager.h> | ||
Show All 16 Lines | 44 | { | |||
44 | // init categories map with invalid categories | 45 | // init categories map with invalid categories | ||
45 | for (const QString &category : categories) { | 46 | for (const QString &category : categories) { | ||
46 | mCategoryMap.insert(category, Attica::Category()); | 47 | mCategoryMap.insert(category, Attica::Category()); | ||
47 | } | 48 | } | ||
48 | 49 | | |||
49 | connect(&m_providerManager, &ProviderManager::providerAdded, this, &AtticaProvider::providerLoaded); | 50 | connect(&m_providerManager, &ProviderManager::providerAdded, this, &AtticaProvider::providerLoaded); | ||
50 | connect(&m_providerManager, SIGNAL(authenticationCredentialsMissing(Provider)), | 51 | connect(&m_providerManager, SIGNAL(authenticationCredentialsMissing(Provider)), | ||
51 | SLOT(authenticationCredentialsMissing(Provider))); | 52 | SLOT(authenticationCredentialsMissing(Provider))); | ||
53 | connect(this, &Provider::loadComments, this, &AtticaProvider::loadComments); | ||||
54 | connect(this, &Provider::loadPerson, this, &AtticaProvider::loadPerson); | ||||
52 | } | 55 | } | ||
53 | 56 | | |||
54 | AtticaProvider::AtticaProvider(const Attica::Provider &provider, const QStringList &categories) | 57 | AtticaProvider::AtticaProvider(const Attica::Provider &provider, const QStringList &categories) | ||
55 | : mEntryJob(nullptr) | 58 | : mEntryJob(nullptr) | ||
56 | , mInitialized(false) | 59 | , mInitialized(false) | ||
57 | { | 60 | { | ||
58 | // init categories map with invalid categories | 61 | // init categories map with invalid categories | ||
59 | for (const QString &category : categories) { | 62 | for (const QString &category : categories) { | ||
▲ Show 20 Lines • Show All 277 Lines • ▼ Show 20 Line(s) | 338 | } else { | |||
337 | connect(job, &BaseJob::finished, this, &AtticaProvider::downloadItemLoaded); | 340 | connect(job, &BaseJob::finished, this, &AtticaProvider::downloadItemLoaded); | ||
338 | mDownloadLinkJobs[job] = qMakePair(entry, linkId); | 341 | mDownloadLinkJobs[job] = qMakePair(entry, linkId); | ||
339 | job->start(); | 342 | job->start(); | ||
340 | 343 | | |||
341 | qCDebug(KNEWSTUFFCORE) << " link for " << entry.uniqueId(); | 344 | qCDebug(KNEWSTUFFCORE) << " link for " << entry.uniqueId(); | ||
342 | } | 345 | } | ||
343 | } | 346 | } | ||
344 | 347 | | |||
348 | void AtticaProvider::loadComments(const EntryInternal &entry, int commentsPerPage, int page) | ||||
349 | { | ||||
350 | ListJob<Attica::Comment> *job = m_provider.requestComments(Attica::Comment::ContentComment, entry.uniqueId(), QLatin1String("0"), page, commentsPerPage); | ||||
351 | connect(job, &BaseJob::finished, this, &AtticaProvider::loadedComments); | ||||
352 | job->start(); | ||||
353 | } | ||||
354 | | ||||
355 | QList<std::shared_ptr<KNSCore::Comment>> getCommentsList(const Attica::Comment::List &comments, std::shared_ptr<KNSCore::Comment> parent) { | ||||
ahiemstra: Since upstream Qt is starting to discourage usage of QList, maybe use QVector instead. | |||||
That'd be good, except the rest of the KNewStuff API is all QList based. It'll want doing for KF6, but since QList is being deprecated for that anyway, i'm thinking we'll end up with a general QList->QVector porting effort for that time anyway, and right now it'd just be introducing a different API style for seemingly no reason... Otherwise yes :) leinir: That'd be good, except the rest of the KNewStuff API is all QList based. It'll want doing for… | |||||
Fair enough. I do try to make sure to use vectors as much as possible in new API, but consistency is also a good argument. :) ahiemstra: Fair enough. I do try to make sure to use vectors as much as possible in new API, but… | |||||
Think i might just pop in a TODO KF6 comment... just sort of make sure that even if it ends up not being a wholesale policy, we do it here :) leinir: Think i might just pop in a TODO KF6 comment... just sort of make sure that even if it ends up… | |||||
356 | QList<std::shared_ptr<KNSCore::Comment>> knsComments; | ||||
357 | for (const Attica::Comment &comment : comments) { | ||||
358 | qDebug() << "Appending comment with id" << comment.id() << ", which has" << comment.childCount() << "children"; | ||||
359 | std::shared_ptr<KNSCore::Comment> knsComment(new KNSCore::Comment()); | ||||
Generally, it's recommended to use std::shared_ptr<KNSCore::Comment> knsComment = std::make_shared<KNSCore::Comment>(). As a bonus, that allows you to use auto knsComment. ahiemstra: Generally, it's recommended to use `std::shared_ptr<KNSCore::Comment> knsComment = std… | |||||
Handy :) One of those places where i'm not opposed to auto, as it's easily read from the right hand side ;) leinir: Handy :) One of those places where i'm not opposed to auto, as it's easily read from the right… | |||||
360 | knsComment->id = comment.id(); | ||||
361 | knsComment->subject = comment.subject(); | ||||
362 | knsComment->text = comment.text(); | ||||
363 | knsComment->childCount = comment.childCount(); | ||||
364 | knsComment->username = comment.user(); | ||||
365 | knsComment->date = comment.date(); | ||||
366 | knsComment->score = comment.score(); | ||||
367 | knsComment->parent = parent; | ||||
368 | knsComments << knsComment; | ||||
369 | if (comment.childCount() > 0) { | ||||
370 | qDebug() << "Getting more comments, as this one has children, and we currently have this number of comments:" << knsComments.count(); | ||||
ahiemstra: Probably better to use categorised logging for this? | |||||
leinir: Actually leftovers... but also yes :) | |||||
371 | knsComments << getCommentsList(comment.children(), knsComment); | ||||
372 | qDebug() << "After getting the children, we now have the following number of comments:" << knsComments.count(); | ||||
373 | } | ||||
374 | } | ||||
375 | return knsComments; | ||||
376 | } | ||||
377 | | ||||
378 | void AtticaProvider::loadedComments(Attica::BaseJob *baseJob) | ||||
379 | { | ||||
380 | if (!jobSuccess(baseJob)) { | ||||
381 | return; | ||||
382 | } | ||||
383 | | ||||
384 | ListJob<Attica::Comment> *job = static_cast<ListJob<Attica::Comment>*>(baseJob); | ||||
385 | Attica::Comment::List comments = job->itemList(); | ||||
386 | | ||||
387 | QList<std::shared_ptr<KNSCore::Comment>> receivedComments = getCommentsList(comments, nullptr); | ||||
388 | emit commentsLoaded(receivedComments); | ||||
389 | } | ||||
390 | | ||||
391 | void AtticaProvider::loadPerson(const QString& username) | ||||
392 | { | ||||
393 | if (m_provider.hasPersonService()) { | ||||
394 | ItemJob<Attica::Person> *job = m_provider.requestPerson(username); | ||||
395 | connect(job, &BaseJob::finished, this, &AtticaProvider::loadedPerson); | ||||
396 | job->start(); | ||||
397 | } | ||||
398 | } | ||||
399 | | ||||
400 | void AtticaProvider::loadedPerson(Attica::BaseJob *baseJob) | ||||
401 | { | ||||
402 | if (!jobSuccess(baseJob)) { | ||||
403 | return; | ||||
404 | } | ||||
405 | | ||||
406 | ItemJob<Attica::Person> *job = static_cast<ItemJob<Attica::Person>*>(baseJob); | ||||
407 | Attica::Person person = job->result(); | ||||
408 | | ||||
409 | std::shared_ptr<KNSCore::Author> author(new KNSCore::Author); | ||||
410 | author->setName(QString::fromLatin1("%1 %2").arg(person.firstName()).arg(person.lastName()).trimmed()); | ||||
ahiemstra: Like above, std::make_shared<KNSCore::Author> | |||||
411 | author->setHomepage(person.homepage()); | ||||
412 | author->setAvatarUrl(person.avatarUrl()); | ||||
413 | author->setDescription(person.extendedAttribute(QStringLiteral("description"))); | ||||
414 | emit personLoaded(author); | ||||
415 | } | ||||
416 | | ||||
345 | void AtticaProvider::accountBalanceLoaded(Attica::BaseJob *baseJob) | 417 | void AtticaProvider::accountBalanceLoaded(Attica::BaseJob *baseJob) | ||
346 | { | 418 | { | ||
347 | if (!jobSuccess(baseJob)) { | 419 | if (!jobSuccess(baseJob)) { | ||
348 | return; | 420 | return; | ||
349 | } | 421 | } | ||
350 | 422 | | |||
351 | ItemJob<AccountBalance> *job = static_cast<ItemJob<AccountBalance>*>(baseJob); | 423 | ItemJob<AccountBalance> *job = static_cast<ItemJob<AccountBalance>*>(baseJob); | ||
352 | AccountBalance item = job->result(); | 424 | AccountBalance item = job->result(); | ||
▲ Show 20 Lines • Show All 182 Lines • Show Last 20 Lines |
Since upstream Qt is starting to discourage usage of QList, maybe use QVector instead.