Add a limit option to the pool retrieval functions
To download less than the maximum (and ease testing)
This commit is contained in:
parent
c5b8fccc6f
commit
08402657a0
3 changed files with 15 additions and 6 deletions
|
@ -106,7 +106,7 @@ void KonachanDanbooruService::getPostList() {
|
|||
|
||||
}
|
||||
|
||||
void KonachanDanbooruService::getPoolList()
|
||||
void KonachanDanbooruService::getPoolList(int limit)
|
||||
{
|
||||
|
||||
QUrl danbooruUrl;
|
||||
|
@ -130,7 +130,7 @@ void KonachanDanbooruService::getPoolList()
|
|||
|
||||
// connect(job, &KIO::StoredTransferJob::result, this, &DanbooruService::processPoolList);
|
||||
|
||||
connect(job, &KIO::StoredTransferJob::result, [this](KJob * job) {
|
||||
connect(job, &KIO::StoredTransferJob::result, [this, limit](KJob * job) {
|
||||
|
||||
if (job->error()) {
|
||||
Q_EMIT(downloadError(job->errorString()));
|
||||
|
@ -148,6 +148,10 @@ void KonachanDanbooruService::getPoolList()
|
|||
return;
|
||||
}
|
||||
|
||||
if (limit > 0 && poolList.length() > limit) {
|
||||
poolList = poolList.mid(0, limit);
|
||||
}
|
||||
|
||||
for (auto element : poolList) {
|
||||
QVariantMap map = element.toMap();
|
||||
|
||||
|
@ -378,7 +382,13 @@ void KonachanDanbooruService::processPostList(KJob *job)
|
|||
}
|
||||
|
||||
m_postsToFetch = postList.length();
|
||||
// qCDebug(LIBDANBOORU) << "Found " << m_postsToFetch << "posts to fetch";
|
||||
qCDebug(LIBDANBOORU) << "Found " << m_postsToFetch << "posts to fetch" << "with limit" << m_maxPosts;
|
||||
|
||||
// This is mostly needed for pools
|
||||
if (postList.length() > m_maxPosts) {
|
||||
m_postsToFetch = m_maxPosts;
|
||||
postList = postList.mid(0, m_maxPosts);
|
||||
}
|
||||
|
||||
for (auto element : postList) {
|
||||
|
||||
|
@ -446,7 +456,6 @@ void KonachanDanbooruService::processPostList(KJob *job)
|
|||
m_cache->insertPixmap(post->thumbnailUrl().url(), pix);
|
||||
}
|
||||
|
||||
|
||||
m_postsToFetch--; // One less post to do
|
||||
|
||||
qCDebug(LIBDANBOORU) << "Current posts remaining: " << m_postsToFetch;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue