Large refactoring of DanbooruService

The idea is to use a long-lived DanbooruService instance, rather than
recreating it, so move most of the parameters via setters and getters.

Still needs some adjustments for resetting.
This commit is contained in:
Luca Beltrame 2015-02-12 21:31:30 +01:00
parent e1045e1fa6
commit f4566d3aca
2 changed files with 119 additions and 49 deletions

View file

@ -95,7 +95,9 @@ private:
QString m_password;
QSet<QString> m_blacklist;
DanbooruPost::Ratings m_maxRating;
QHash<int, DanbooruPost*> m_posts;
int m_maxPosts;
int m_currentPage;
QStringList m_tags;
unsigned int m_postsToFetch; // To tell when to quit
@ -124,6 +126,9 @@ public:
**/
~DanbooruService();
int currentPage() const;
/**
* @brief Get posts from a the board.
*
@ -132,16 +137,13 @@ public:
* @param limit The number of posts to fetch (maximum 100)
*
**/
Q_INVOKABLE void getPostList(int page = 1, QStringList tags = QStringList(),
int limit = 100);
Q_INVOKABLE void getPostList();
/**
* @brief Get a list of pools from the board.
*
* @param page The page to get pools from (default: 1)
*
**/
void getPoolList(int page = 1);
void getPoolList();
/**
* @brief Get the posts associated with a specific pool ID.
@ -191,6 +193,23 @@ public:
**/
const QSet<QString> blacklist() const;
/**
* @return The number of posts downloaded for each page (max 100)
**/
int maxPosts() const;
void nextPostPage();
QStringList postTags() const;
/**
* @brief Set blacklisted tags.
*
* Posts with blacklisted tags are not downloaded.
*
* @param blacklist A QSet<QString> including unwanted tags.
* @return void
*/
void setBlacklist(const QSet<QString> &blacklist);
/**
@ -236,8 +255,24 @@ public:
*/
void setUserName(const QString& username);
/**
* @brief Set the password used for login.
*
* It should not be the password itself, but a SHA1 hash
* with a specific salt (which is board-dependent; check their
* API access rules).
*
* @param username The salted password to use.
* @return void
*/
void setPassword(const QString& password);
void setMaxPosts(int number);
void setCurrentPage(int page);
void setPostTags(const QStringList& tags);
private Q_SLOTS:
void processPostList(KJob *job);