Add missing bits to the API and get rid of the cache
Cache added a lot of unecessarity complexity, in particular. It made no sense to add it to a class which handles network responses.
This commit is contained in:
parent
02bb6ffcaa
commit
32fc63118d
2 changed files with 72 additions and 58 deletions
|
@ -37,6 +37,8 @@ DanbooruServiceBase::DanbooruServiceBase(QUrl boardUrl, QObject* parent):
|
|||
m_maxRating(Danbooru::Safe),
|
||||
m_maxPosts(10),
|
||||
m_currentPage(1),
|
||||
m_minimumWidth(-1),
|
||||
m_minimumHeight(-1),
|
||||
m_tags(QStringList()),
|
||||
m_postsToFetch(0)
|
||||
{
|
||||
|
@ -86,6 +88,16 @@ int DanbooruServiceBase::maxPosts() const
|
|||
return m_maxPosts;
|
||||
}
|
||||
|
||||
int DanbooruServiceBase::minimumHeight() const
|
||||
{
|
||||
return m_minimumHeight;
|
||||
}
|
||||
|
||||
int DanbooruServiceBase::minimumWidth() const
|
||||
{
|
||||
return m_minimumWidth;
|
||||
}
|
||||
|
||||
void DanbooruServiceBase::nextPostPage()
|
||||
{
|
||||
m_currentPage++;
|
||||
|
@ -106,6 +118,9 @@ QStringList DanbooruServiceBase::postTags() const
|
|||
void DanbooruServiceBase::reset()
|
||||
{
|
||||
m_currentPage = 1;
|
||||
m_minimumHeight = -1;
|
||||
m_minimumWidth = -1;
|
||||
m_maxRating = Danbooru::Safe;
|
||||
m_tags = QStringList();
|
||||
|
||||
}
|
||||
|
@ -132,7 +147,7 @@ void DanbooruServiceBase::setBlacklist(const QStringList &blacklist)
|
|||
|
||||
m_blacklist.clear();
|
||||
|
||||
for (auto element : blacklist) {
|
||||
for (const auto &element : blacklist) {
|
||||
m_blacklist.insert(element);
|
||||
}
|
||||
|
||||
|
@ -148,10 +163,7 @@ void DanbooruServiceBase::setCurrentPage(int page)
|
|||
m_currentPage = page;
|
||||
}
|
||||
|
||||
void DanbooruServiceBase::setImageCache(KImageCache *cache)
|
||||
{
|
||||
m_cache = cache;
|
||||
}
|
||||
|
||||
|
||||
void DanbooruServiceBase::setMaximumAllowedRating(Danbooru::Rating rating)
|
||||
{
|
||||
|
@ -230,11 +242,6 @@ void DanbooruServiceBase::processPixmap(KJob* job) {
|
|||
|
||||
post->setPixmap(pix);
|
||||
|
||||
if (m_cache)
|
||||
{
|
||||
//qCDebug(LIBDANBOORU) << "Inserting item in cache";
|
||||
m_cache->insertPixmap(post->thumbnailUrl().url(), pix);
|
||||
}
|
||||
|
||||
m_postsToFetch--; // One less post to do
|
||||
|
||||
|
@ -277,7 +284,7 @@ void DanbooruServiceBase::processPostList(KJob *job)
|
|||
// Special cases for pools
|
||||
QVariantMap postMap = parseResult(data, apiType(), Danbooru::Pool, &ok).at(0);
|
||||
auto postData = postMap.value("raw_post_data").toList();
|
||||
for (const auto post: postData) {
|
||||
for (const auto &post: postData) {
|
||||
postList.append(extractPostData(post, apiType()));
|
||||
}
|
||||
|
||||
|
@ -307,7 +314,7 @@ void DanbooruServiceBase::processPostList(KJob *job)
|
|||
postList = postList.mid(0, m_maxPosts);
|
||||
}
|
||||
|
||||
for (const QVariantMap element : qAsConst(postList)) {
|
||||
for (const QVariantMap &element : qAsConst(postList)) {
|
||||
|
||||
DanbooruPost *post = new DanbooruPost(element);
|
||||
|
||||
|
@ -322,38 +329,38 @@ void DanbooruServiceBase::processPostList(KJob *job)
|
|||
QPixmap pix;
|
||||
|
||||
qCDebug(LIBDANBOORU) << "About to download images";
|
||||
qCDebug(LIBDANBOORU) << "Downloading image" << post->thumbnailUrl();
|
||||
StoredTransferJob *pixmapJob = KIO::storedGet(post->thumbnailUrl(),
|
||||
KIO::NoReload, KIO::HideProgressInfo);
|
||||
|
||||
if (m_cache && m_cache->findPixmap(post->thumbnailUrl().url(), &pix)) {
|
||||
// We don't want to overload the servers, so set some rational
|
||||
// priority
|
||||
|
||||
post->setPixmap(pix);
|
||||
Q_EMIT(postDownloaded(post));
|
||||
m_postsToFetch--;
|
||||
KIO::Scheduler::setJobPriority(static_cast<KIO::SimpleJob *>(pixmapJob), 1);
|
||||
|
||||
if (m_postsToFetch == 0) {
|
||||
qCDebug(LIBDANBOORU) << "Post download finished";
|
||||
Q_EMIT(postDownloadFinished());
|
||||
}
|
||||
QVariant variant;
|
||||
variant.setValue(post);
|
||||
pixmapJob->setProperty("post", variant);
|
||||
pixmapJob->setProperty("pix", pix);
|
||||
|
||||
} else {
|
||||
connect(pixmapJob, &StoredTransferJob::result, this, &DanbooruServiceBase::processPixmap);
|
||||
|
||||
qCDebug(LIBDANBOORU) << "Downloading image" << post->thumbnailUrl();
|
||||
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);
|
||||
void DanbooruServiceBase::setMinimumHeight(int height) {
|
||||
|
||||
QVariant variant;
|
||||
variant.setValue(post);
|
||||
pixmapJob->setProperty("post", variant);
|
||||
pixmapJob->setProperty("pix", pix);
|
||||
if (height > 0) {
|
||||
m_minimumHeight = height;
|
||||
}
|
||||
|
||||
connect(pixmapJob, &StoredTransferJob::result, this, &DanbooruServiceBase::processPixmap);
|
||||
}
|
||||
|
||||
}
|
||||
void DanbooruServiceBase::setMinimumWidth(int width) {
|
||||
|
||||
if (width > 0) {
|
||||
m_minimumWidth = width;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -53,12 +53,12 @@ private:
|
|||
|
||||
// URI functions
|
||||
|
||||
virtual const QLatin1String postUri() const = 0;
|
||||
virtual const QLatin1String poolUri() const = 0;
|
||||
virtual const QLatin1String artistUri() const = 0;
|
||||
virtual const QLatin1String tagUri() const = 0;
|
||||
virtual const QLatin1String poolDataUri() const = 0;
|
||||
virtual const QLatin1String relatedTagUri() const = 0;
|
||||
virtual const QUrl postUri() const = 0;
|
||||
virtual const QUrl poolUri() const = 0;
|
||||
virtual const QUrl artistUri() const = 0;
|
||||
virtual const QUrl tagUri() const = 0;
|
||||
virtual const QUrl poolDataUri() const = 0;
|
||||
virtual const QUrl relatedTagUri() const = 0;
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -71,12 +71,12 @@ protected:
|
|||
Danbooru::Ratings m_maxRating;
|
||||
int m_maxPosts;
|
||||
int m_currentPage;
|
||||
int m_minimumWidth;
|
||||
int m_minimumHeight;
|
||||
QStringList m_tags;
|
||||
|
||||
unsigned int m_postsToFetch; // To tell when to quit
|
||||
|
||||
KImageCache *m_cache; // Pixmap cache
|
||||
|
||||
public:
|
||||
|
||||
explicit DanbooruServiceBase(QUrl boardUrl = QUrl(), QObject* parent=nullptr);
|
||||
|
@ -97,7 +97,7 @@ public:
|
|||
const QStringList allowedRatings() const;
|
||||
|
||||
/**
|
||||
* @brief Return the api type of the searvice.
|
||||
* @brief Return the api type of the service.
|
||||
**/
|
||||
virtual Danbooru::ApiType apiType() const;
|
||||
|
||||
|
@ -132,6 +132,18 @@ public:
|
|||
**/
|
||||
int maxPosts() const;
|
||||
|
||||
/**
|
||||
* @return The minimum required height for a post to be considered
|
||||
*
|
||||
**/
|
||||
int minimumHeight() const;
|
||||
|
||||
/**
|
||||
* @return The minimum required width for a post to be considered
|
||||
*
|
||||
**/
|
||||
int minimumWidth() const;
|
||||
|
||||
/**
|
||||
* @brief Move to the next post page and retrieve new posts.
|
||||
*
|
||||
|
@ -188,14 +200,6 @@ public:
|
|||
**/
|
||||
void setCurrentPage(int page);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set an image cache to use.
|
||||
*
|
||||
* @param cache A pointer to an instance of KImageCache.
|
||||
*/
|
||||
void setImageCache(KImageCache *cache);
|
||||
|
||||
/**
|
||||
* @brief Set the maximum allowed rating for the board.
|
||||
*
|
||||
|
@ -210,6 +214,9 @@ public:
|
|||
**/
|
||||
void setMaxPosts(int number);
|
||||
|
||||
void setMinimumHeight(int height);
|
||||
void setMinimumWidth(int width);
|
||||
|
||||
/**
|
||||
* @brief Set the password used for login.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue