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_maxRating(Danbooru::Safe),
 | 
				
			||||||
    m_maxPosts(10),
 | 
					    m_maxPosts(10),
 | 
				
			||||||
    m_currentPage(1),
 | 
					    m_currentPage(1),
 | 
				
			||||||
 | 
					    m_minimumWidth(-1),
 | 
				
			||||||
 | 
					    m_minimumHeight(-1),
 | 
				
			||||||
    m_tags(QStringList()),
 | 
					    m_tags(QStringList()),
 | 
				
			||||||
    m_postsToFetch(0)
 | 
					    m_postsToFetch(0)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
| 
						 | 
					@ -86,6 +88,16 @@ int DanbooruServiceBase::maxPosts() const
 | 
				
			||||||
    return m_maxPosts;
 | 
					    return m_maxPosts;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int DanbooruServiceBase::minimumHeight() const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return m_minimumHeight;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int DanbooruServiceBase::minimumWidth() const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return m_minimumWidth;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DanbooruServiceBase::nextPostPage()
 | 
					void DanbooruServiceBase::nextPostPage()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    m_currentPage++;
 | 
					    m_currentPage++;
 | 
				
			||||||
| 
						 | 
					@ -106,6 +118,9 @@ QStringList DanbooruServiceBase::postTags() const
 | 
				
			||||||
void DanbooruServiceBase::reset()
 | 
					void DanbooruServiceBase::reset()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    m_currentPage = 1;
 | 
					    m_currentPage = 1;
 | 
				
			||||||
 | 
					    m_minimumHeight = -1;
 | 
				
			||||||
 | 
					    m_minimumWidth = -1;
 | 
				
			||||||
 | 
					    m_maxRating = Danbooru::Safe;
 | 
				
			||||||
    m_tags = QStringList();
 | 
					    m_tags = QStringList();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -132,7 +147,7 @@ void DanbooruServiceBase::setBlacklist(const QStringList &blacklist)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    m_blacklist.clear();
 | 
					    m_blacklist.clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (auto element : blacklist) {
 | 
					    for (const auto &element : blacklist) {
 | 
				
			||||||
        m_blacklist.insert(element);
 | 
					        m_blacklist.insert(element);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -148,10 +163,7 @@ void DanbooruServiceBase::setCurrentPage(int page)
 | 
				
			||||||
    m_currentPage = page;
 | 
					    m_currentPage = page;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DanbooruServiceBase::setImageCache(KImageCache *cache)
 | 
					
 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    m_cache = cache;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DanbooruServiceBase::setMaximumAllowedRating(Danbooru::Rating rating)
 | 
					void DanbooruServiceBase::setMaximumAllowedRating(Danbooru::Rating rating)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -230,11 +242,6 @@ void DanbooruServiceBase::processPixmap(KJob* job) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    post->setPixmap(pix);
 | 
					    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
 | 
					    m_postsToFetch--; // One less post to do
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -277,7 +284,7 @@ void DanbooruServiceBase::processPostList(KJob *job)
 | 
				
			||||||
        // Special cases for pools
 | 
					        // Special cases for pools
 | 
				
			||||||
        QVariantMap postMap = parseResult(data, apiType(), Danbooru::Pool, &ok).at(0);
 | 
					        QVariantMap postMap = parseResult(data, apiType(), Danbooru::Pool, &ok).at(0);
 | 
				
			||||||
        auto postData = postMap.value("raw_post_data").toList();
 | 
					        auto postData = postMap.value("raw_post_data").toList();
 | 
				
			||||||
        for (const auto post: postData) {
 | 
					        for (const auto &post: postData) {
 | 
				
			||||||
            postList.append(extractPostData(post, apiType()));
 | 
					            postList.append(extractPostData(post, apiType()));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -307,7 +314,7 @@ void DanbooruServiceBase::processPostList(KJob *job)
 | 
				
			||||||
        postList = postList.mid(0, m_maxPosts);
 | 
					        postList = postList.mid(0, m_maxPosts);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (const QVariantMap element : qAsConst(postList)) {
 | 
					    for (const QVariantMap &element : qAsConst(postList)) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        DanbooruPost *post = new DanbooruPost(element);
 | 
					        DanbooruPost *post = new DanbooruPost(element);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -322,20 +329,6 @@ void DanbooruServiceBase::processPostList(KJob *job)
 | 
				
			||||||
        QPixmap pix;
 | 
					        QPixmap pix;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        qCDebug(LIBDANBOORU) << "About to download images";
 | 
					        qCDebug(LIBDANBOORU) << "About to download images";
 | 
				
			||||||
 | 
					 | 
				
			||||||
        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 {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        qCDebug(LIBDANBOORU) << "Downloading image" << post->thumbnailUrl();
 | 
					        qCDebug(LIBDANBOORU) << "Downloading image" << post->thumbnailUrl();
 | 
				
			||||||
        StoredTransferJob *pixmapJob = KIO::storedGet(post->thumbnailUrl(),
 | 
					        StoredTransferJob *pixmapJob = KIO::storedGet(post->thumbnailUrl(),
 | 
				
			||||||
                                        KIO::NoReload, KIO::HideProgressInfo);
 | 
					                                        KIO::NoReload, KIO::HideProgressInfo);
 | 
				
			||||||
| 
						 | 
					@ -356,6 +349,20 @@ void DanbooruServiceBase::processPostList(KJob *job)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void DanbooruServiceBase::setMinimumHeight(int height) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (height > 0) {
 | 
				
			||||||
 | 
					        m_minimumHeight = height;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void DanbooruServiceBase::setMinimumWidth(int width) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (width > 0) {
 | 
				
			||||||
 | 
					        m_minimumWidth = width;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace Danbooru
 | 
					} // namespace Danbooru
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -53,12 +53,12 @@ private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // URI functions
 | 
					    // URI functions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    virtual const QLatin1String postUri() const = 0;
 | 
					    virtual const QUrl postUri() const = 0;
 | 
				
			||||||
    virtual const QLatin1String poolUri() const = 0;
 | 
					    virtual const QUrl poolUri() const = 0;
 | 
				
			||||||
    virtual const QLatin1String artistUri() const = 0;
 | 
					    virtual const QUrl artistUri() const = 0;
 | 
				
			||||||
    virtual const QLatin1String tagUri() const = 0;
 | 
					    virtual const QUrl tagUri() const = 0;
 | 
				
			||||||
    virtual const QLatin1String poolDataUri() const = 0;
 | 
					    virtual const QUrl poolDataUri() const = 0;
 | 
				
			||||||
    virtual const QLatin1String relatedTagUri() const = 0;
 | 
					    virtual const QUrl relatedTagUri() const = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
protected:
 | 
					protected:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -71,12 +71,12 @@ protected:
 | 
				
			||||||
    Danbooru::Ratings m_maxRating;
 | 
					    Danbooru::Ratings m_maxRating;
 | 
				
			||||||
    int m_maxPosts;
 | 
					    int m_maxPosts;
 | 
				
			||||||
    int m_currentPage;
 | 
					    int m_currentPage;
 | 
				
			||||||
 | 
					    int m_minimumWidth;
 | 
				
			||||||
 | 
					    int m_minimumHeight;
 | 
				
			||||||
    QStringList m_tags;
 | 
					    QStringList m_tags;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    unsigned int m_postsToFetch; // To tell when to quit
 | 
					    unsigned int m_postsToFetch; // To tell when to quit
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    KImageCache *m_cache; // Pixmap cache
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    explicit DanbooruServiceBase(QUrl boardUrl = QUrl(), QObject* parent=nullptr);
 | 
					    explicit DanbooruServiceBase(QUrl boardUrl = QUrl(), QObject* parent=nullptr);
 | 
				
			||||||
| 
						 | 
					@ -97,7 +97,7 @@ public:
 | 
				
			||||||
    const QStringList allowedRatings() const;
 | 
					    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;
 | 
					    virtual Danbooru::ApiType apiType() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -132,6 +132,18 @@ public:
 | 
				
			||||||
     **/
 | 
					     **/
 | 
				
			||||||
    int maxPosts() const;
 | 
					    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.
 | 
					     * @brief Move to the next post page and retrieve new posts.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
| 
						 | 
					@ -188,14 +200,6 @@ public:
 | 
				
			||||||
     **/
 | 
					     **/
 | 
				
			||||||
    void setCurrentPage(int page);
 | 
					    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.
 | 
					     * @brief Set the maximum allowed rating for the board.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
| 
						 | 
					@ -210,6 +214,9 @@ public:
 | 
				
			||||||
     **/
 | 
					     **/
 | 
				
			||||||
    void setMaxPosts(int number);
 | 
					    void setMaxPosts(int number);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void setMinimumHeight(int height);
 | 
				
			||||||
 | 
					    void setMinimumWidth(int width);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * @brief Set the password used for login.
 | 
					     * @brief Set the password used for login.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue