Adapt the Donmai class to the change in the base class

This commit is contained in:
Luca Beltrame 2020-08-19 16:31:10 +02:00
parent 32fc63118d
commit 1a6fc34895
Signed by: einar
GPG key ID: 4707F46E9EC72DEC
2 changed files with 61 additions and 65 deletions

View file

@ -38,28 +38,39 @@ namespace Danbooru {
// URIs
///////
const QLatin1String DanbooruService::postUri() const {
return QLatin1String("posts.json");
const QUrl DanbooruService::postUri() const {
auto url = QUrl(m_url);
url.setPath("/posts.json");
return url;
}
const QLatin1String DanbooruService::poolUri() const {
return QLatin1String("pools.json");
const QUrl DanbooruService::poolUri() const {
auto url = QUrl(m_url);
url.setPath("/pools.json");
return url;
}
const QLatin1String DanbooruService::artistUri() const {
return QLatin1String("artists.json");
const QUrl DanbooruService::artistUri() const {
auto url = QUrl(m_url);
url.setPath("/artists.json");
return url;
}
const QLatin1String DanbooruService::tagUri() const {
return QLatin1String("tags.json");
const QUrl DanbooruService::tagUri() const {
auto url = QUrl(m_url);
url.setPath("/tags.json");
return url;
}
const QLatin1String DanbooruService::poolDataUri() const {
return QLatin1String("pools/%1.json");
const QUrl DanbooruService::poolDataUri() const {
return QUrl();
}
const QLatin1String DanbooruService::relatedTagUri() const {
return QLatin1String("related_tag.json");
const QUrl DanbooruService::relatedTagUri() const {
auto url = QUrl(m_url);
url.setPath("/related_tag.json");
return url;
}
////////////////
@ -83,7 +94,7 @@ void DanbooruService::getPostList() {
parameters.insert("limit", QString::number(m_maxPosts));
parameters.insert("page", QString::number(m_currentPage));
QUrl danbooruUrl = requestUrl(m_url, postUri(), m_username,
QUrl danbooruUrl = requestUrl(postUri(), m_username,
m_password, parameters, m_tags);
qCDebug(LIBDANBOORU) << "Final constructed post URL" << danbooruUrl;
@ -101,12 +112,12 @@ void DanbooruService::getPoolList(int limit)
QUrl danbooruUrl;
if (m_currentPage == 1) {
danbooruUrl = requestUrl(m_url, poolUri(), m_username, m_password);
danbooruUrl = requestUrl(poolUri(), m_username, m_password);
} else {
QMap<QString, QString> map;
map.insert("page", QString::number(m_currentPage));
danbooruUrl = requestUrl(m_url, poolUri(), m_username,
danbooruUrl = requestUrl(poolUri(), m_username,
m_password, map);
}
@ -161,9 +172,11 @@ void DanbooruService::getPool(int poolId, int page)
parameters.insert("page", QString::number(page));
}
const QString dataUri = QString(poolDataUri()).arg(poolId);
QUrl dataUri;
dataUri = QUrl(m_url);
dataUri.setPath(QString("pools/%1.json").arg(poolId));
QUrl danbooruUrl = requestUrl(m_url, dataUri, m_username,
QUrl danbooruUrl = requestUrl(dataUri, m_username,
m_password, parameters);
qCDebug(LIBDANBOORU) << "Final constructed URL pool" << danbooruUrl;
@ -192,8 +205,10 @@ void DanbooruService::getPool(int poolId, int page)
m_postsToFetch = postIds.length();
for (const auto postId: postIds) {
QUrl postUrl = requestUrl(m_url, QString("posts/%1.json").arg(postId.toString()), m_username,
for (const auto &postId: postIds) {
auto postUrl = QUrl(m_url);
postUrl.setPath(QString("/posts/%1.json").arg(postId.toString()));
postUrl = requestUrl(postUrl, m_username,
m_password);
StoredTransferJob* postJob = KIO::storedGet(postUrl, KIO::NoReload,
KIO::HideProgressInfo);
@ -213,7 +228,7 @@ void DanbooruService::getTagList(int limit, QString name)
}
parameters.insert("search[order]", "date");
QUrl danbooruUrl = requestUrl(m_url, tagUri(), m_username, m_password,
QUrl danbooruUrl = requestUrl(tagUri(), m_username, m_password,
parameters);
// qCDebug(LIBDANBOORU) << "Final constructed tag URL" << danbooruUrl.url();
@ -250,7 +265,7 @@ void DanbooruService::getRelatedTags(const QStringList &tags,
parameters.insert("type", type);
parameters.insert("query", tags.join(" "));
QUrl danbooruUrl = requestUrl(m_url, relatedTagUri(), m_username,
QUrl danbooruUrl = requestUrl(relatedTagUri(), m_username,
m_password, parameters);
// qCDebug(LIBDANBOORU) << "Final constructed related tag URL" << danbooruUrl;
@ -390,34 +405,15 @@ void DanbooruService::processSinglePost(KJob* job) {
QPixmap pix;
qCDebug(LIBDANBOORU) << "About to download image";
if (m_cache && m_cache->findPixmap(post->thumbnailUrl().url(), &pix)) {
post->setPixmap(pix);
Q_EMIT(postDownloaded(post));
m_postsToFetch--;
if (m_postsToFetch == 0) {
qCDebug(LIBDANBOORU) << "Post download finished";
Q_EMIT(postDownloadFinished());
}
} else {
StoredTransferJob *pixmapJob = KIO::storedGet(post->thumbnailUrl(),
KIO::NoReload, KIO::HideProgressInfo);
// We don't want to overload the servers, so set some rational
// priority
KIO::Scheduler::setJobPriority(static_cast<KIO::SimpleJob *>(pixmapJob), 1);
QVariant variant;
variant.setValue(post);
pixmapJob->setProperty("post", variant);
pixmapJob->setProperty("pixmap", pix);
connect(pixmapJob, &StoredTransferJob::result, this, &DanbooruServiceBase::processPixmap);
}
}

View file

@ -32,12 +32,12 @@ class DanbooruService: public DanbooruServiceBase {
Q_OBJECT
private:
const QLatin1String postUri() const override;
const QLatin1String poolUri() const override;
const QLatin1String artistUri() const override;
const QLatin1String tagUri() const override;
const QLatin1String poolDataUri() const override;
const QLatin1String relatedTagUri() const override;
const QUrl postUri() const override;
const QUrl poolUri() const override;
const QUrl artistUri() const override;
const QUrl tagUri() const override;
const QUrl poolDataUri() const override;
const QUrl relatedTagUri() const override;
public: