Run astyle-kdelibs on the source
This commit is contained in:
parent
4b85d63d68
commit
39aac8c95b
22 changed files with 1227 additions and 1264 deletions
|
@ -32,8 +32,8 @@
|
|||
* @file danbooru.h
|
||||
*
|
||||
**/
|
||||
namespace Danbooru {
|
||||
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
}; // namespace Danbooru
|
||||
|
||||
|
|
|
@ -22,10 +22,11 @@
|
|||
|
||||
#include "danboorupool.h"
|
||||
|
||||
namespace Danbooru {
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
DanbooruPool::DanbooruPool(const QVariantMap& postData, QObject* parent):
|
||||
QObject(parent), m_posts(QList<int>())
|
||||
DanbooruPool::DanbooruPool(const QVariantMap &postData, QObject *parent):
|
||||
QObject(parent), m_posts(QList<int>())
|
||||
{
|
||||
m_id = postData.value("id").toInt();
|
||||
m_name = postData.value("name").toString();
|
||||
|
@ -68,13 +69,12 @@ void DanbooruPool::addPosts(QList< int > posts)
|
|||
m_posts.append(posts);
|
||||
}
|
||||
|
||||
void DanbooruPool::addPosts(const QStringList& posts)
|
||||
void DanbooruPool::addPosts(const QStringList &posts)
|
||||
{
|
||||
|
||||
for (auto post: posts) {
|
||||
for (auto post : posts) {
|
||||
m_posts.append(post.toInt());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Danbooru
|
||||
|
|
|
@ -37,74 +37,75 @@
|
|||
#include <QtCore/QStringList>
|
||||
#include <QtXml/QXmlStreamAttributes>
|
||||
|
||||
namespace Danbooru {
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief Class representing a Danbooru pool.
|
||||
*
|
||||
* Pools are organized groups of images, often by a common theme, for
|
||||
* example taken from the same artbook. They are identified by unique IDs
|
||||
* and are represented by a name, a description, and the posts they
|
||||
* contain.
|
||||
*
|
||||
* @author Luca Beltrame (lbeltrame@kde.org)
|
||||
*
|
||||
* **/
|
||||
class DanbooruPool : public QObject
|
||||
{
|
||||
/**
|
||||
* @brief Class representing a Danbooru pool.
|
||||
*
|
||||
* Pools are organized groups of images, often by a common theme, for
|
||||
* example taken from the same artbook. They are identified by unique IDs
|
||||
* and are represented by a name, a description, and the posts they
|
||||
* contain.
|
||||
*
|
||||
* @author Luca Beltrame (lbeltrame@kde.org)
|
||||
*
|
||||
* **/
|
||||
class DanbooruPool : public QObject
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
int m_id;
|
||||
int m_postCount;
|
||||
QString m_name;
|
||||
QString m_description;
|
||||
QList<int> m_posts;
|
||||
private:
|
||||
int m_id;
|
||||
int m_postCount;
|
||||
QString m_name;
|
||||
QString m_description;
|
||||
QList<int> m_posts;
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Construct a Danbooru pool from a QVariantMap.
|
||||
*
|
||||
* This form is the easiest to use and should be used when dealing with
|
||||
* responses in JSON format. Unfortunately most Danbooru
|
||||
* implementations produce broken JSON for some responses.
|
||||
*
|
||||
* @param postData A QVariantMap from parsed JSON representing the
|
||||
* data from a single pool.
|
||||
*
|
||||
*
|
||||
**/
|
||||
DanbooruPool(const QVariantMap& postData, QObject* parent = 0);
|
||||
/**
|
||||
* @brief Construct a Danbooru pool from a QVariantMap.
|
||||
*
|
||||
* This form is the easiest to use and should be used when dealing with
|
||||
* responses in JSON format. Unfortunately most Danbooru
|
||||
* implementations produce broken JSON for some responses.
|
||||
*
|
||||
* @param postData A QVariantMap from parsed JSON representing the
|
||||
* data from a single pool.
|
||||
*
|
||||
*
|
||||
**/
|
||||
DanbooruPool(const QVariantMap &postData, QObject *parent = 0);
|
||||
|
||||
/**
|
||||
* @brief Construct a Danbooru pool from a QVariantMap.
|
||||
*
|
||||
* This form is the easiest to use and should be used when dealing with
|
||||
* responses in JSON format. Unfortunately most Danbooru
|
||||
* implementations produce broken JSON for some responses.
|
||||
*
|
||||
* @param postData A QXmlStreamAttributes instance holding the
|
||||
* attributes for the given pool.
|
||||
*
|
||||
*
|
||||
**/
|
||||
DanbooruPool(const QXmlStreamAttributes& postData, QObject* parent=0);
|
||||
/**
|
||||
* @brief Construct a Danbooru pool from a QVariantMap.
|
||||
*
|
||||
* This form is the easiest to use and should be used when dealing with
|
||||
* responses in JSON format. Unfortunately most Danbooru
|
||||
* implementations produce broken JSON for some responses.
|
||||
*
|
||||
* @param postData A QXmlStreamAttributes instance holding the
|
||||
* attributes for the given pool.
|
||||
*
|
||||
*
|
||||
**/
|
||||
DanbooruPool(const QXmlStreamAttributes &postData, QObject *parent = 0);
|
||||
|
||||
int id() const;
|
||||
int postCount() const;
|
||||
QString name() const;
|
||||
QString description() const;
|
||||
QList<int> posts() const;
|
||||
int id() const;
|
||||
int postCount() const;
|
||||
QString name() const;
|
||||
QString description() const;
|
||||
QList<int> posts() const;
|
||||
|
||||
void addPost(int post);
|
||||
void addPosts(QList<int> posts);
|
||||
void addPosts(const QStringList& posts);
|
||||
};
|
||||
void addPost(int post);
|
||||
void addPosts(QList<int> posts);
|
||||
void addPosts(const QStringList &posts);
|
||||
};
|
||||
|
||||
}; // namespace Danbooru
|
||||
|
||||
Q_DECLARE_METATYPE(Danbooru::DanbooruPool*)
|
||||
Q_DECLARE_METATYPE(Danbooru::DanbooruPool *)
|
||||
|
||||
#endif // DANBOORUPOOL_H
|
||||
|
|
|
@ -33,14 +33,13 @@
|
|||
|
||||
#include "danboorupost.h"
|
||||
|
||||
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
const QMap<QString, DanbooruPost::Rating> DanbooruPost::RATING_MAP = initRatingMap();
|
||||
|
||||
DanbooruPost::DanbooruPost(QVariantMap postData, QPixmap pixmap,
|
||||
QObject* parent):
|
||||
QObject *parent):
|
||||
QObject(parent),
|
||||
m_pixmap(pixmap)
|
||||
{
|
||||
|
@ -57,7 +56,7 @@ DanbooruPost::DanbooruPost(QVariantMap postData, QPixmap pixmap,
|
|||
|
||||
}
|
||||
|
||||
DanbooruPost::DanbooruPost(QXmlStreamAttributes& postData, QPixmap pixmap, QObject* parent):
|
||||
DanbooruPost::DanbooruPost(QXmlStreamAttributes &postData, QPixmap pixmap, QObject *parent):
|
||||
QObject(parent),
|
||||
m_pixmap(pixmap)
|
||||
{
|
||||
|
@ -73,12 +72,10 @@ DanbooruPost::DanbooruPost(QXmlStreamAttributes& postData, QPixmap pixmap, QObje
|
|||
m_rating = RATING_MAP.value(postData.value("rating").toString());
|
||||
}
|
||||
|
||||
|
||||
DanbooruPost::~DanbooruPost()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
const QMap< QString, DanbooruPost::Rating > DanbooruPost::initRatingMap()
|
||||
{
|
||||
|
||||
|
@ -91,13 +88,11 @@ const QMap< QString, DanbooruPost::Rating > DanbooruPost::initRatingMap()
|
|||
|
||||
}
|
||||
|
||||
|
||||
bool DanbooruPost::operator==(const Danbooru::DanbooruPost& other)
|
||||
bool DanbooruPost::operator==(const Danbooru::DanbooruPost &other)
|
||||
{
|
||||
return m_url == other.m_url && m_id == other.m_id;
|
||||
}
|
||||
|
||||
|
||||
void DanbooruPost::setPixmap(const QPixmap &pixmap)
|
||||
{
|
||||
m_pixmap = pixmap;
|
||||
|
@ -155,7 +150,5 @@ Danbooru::DanbooruPost::Rating DanbooruPost::rating() const
|
|||
return m_rating;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Danbooru
|
||||
|
||||
|
||||
|
|
|
@ -45,28 +45,28 @@
|
|||
|
||||
#include "danbooru.h"
|
||||
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
namespace Danbooru {
|
||||
|
||||
/**
|
||||
* @brief A class representing a Danbooru post.
|
||||
*
|
||||
* A Danbooru post is an object that models the posts present in a
|
||||
* Danbooru board, that is an image with associated information.
|
||||
*
|
||||
* In particular, posts contain information on the id, size and dimensions
|
||||
* of the image, its tags, "preview url" (URL to the thumbnail) and
|
||||
* file URL.
|
||||
*
|
||||
* This is used directly by the DanbooruService class.
|
||||
*
|
||||
* @author Luca Beltrame (lbeltrame@kde.org)
|
||||
*
|
||||
* @see DanbooruService, DanbooruPool
|
||||
*
|
||||
**/
|
||||
class DanbooruPost : public QObject
|
||||
{
|
||||
/**
|
||||
* @brief A class representing a Danbooru post.
|
||||
*
|
||||
* A Danbooru post is an object that models the posts present in a
|
||||
* Danbooru board, that is an image with associated information.
|
||||
*
|
||||
* In particular, posts contain information on the id, size and dimensions
|
||||
* of the image, its tags, "preview url" (URL to the thumbnail) and
|
||||
* file URL.
|
||||
*
|
||||
* This is used directly by the DanbooruService class.
|
||||
*
|
||||
* @author Luca Beltrame (lbeltrame@kde.org)
|
||||
*
|
||||
* @see DanbooruService, DanbooruPool
|
||||
*
|
||||
**/
|
||||
class DanbooruPost : public QObject
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -76,7 +76,7 @@ namespace Danbooru {
|
|||
Q_PROPERTY(QSet<QString> tags READ tags)
|
||||
Q_PROPERTY(QUrl thumbnailUrl READ thumbnailUrl)
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Ratings for a Danbooru item
|
||||
|
@ -88,140 +88,136 @@ namespace Danbooru {
|
|||
Safe = 1, /**< Safe for the general public **/
|
||||
Questionable = 2, /**< Might contain hints of risqueness of violence **/
|
||||
Explicit = 4 /**< Explicit material **/
|
||||
};
|
||||
Q_DECLARE_FLAGS(Ratings, DanbooruPost::Rating)
|
||||
|
||||
|
||||
private:
|
||||
|
||||
QPixmap m_pixmap;
|
||||
|
||||
// basic features of a post
|
||||
|
||||
int m_id;
|
||||
int m_height;
|
||||
int m_width;
|
||||
int m_size;
|
||||
|
||||
QUrl m_url;
|
||||
QUrl m_thumbnailUrl;
|
||||
QSet<QString> m_tags;
|
||||
DanbooruPost::Rating m_rating;
|
||||
|
||||
static const QMap<QString, Rating> RATING_MAP;
|
||||
|
||||
// Private functions
|
||||
|
||||
static const QMap< QString, Rating > initRatingMap();
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Construct a Danbooru post from a QVariantMap.
|
||||
*
|
||||
* This form is the easiest to use and should be used when dealing with
|
||||
* responses in JSON format. Unfortunately most Danbooru
|
||||
* implementations produce broken JSON for some responses.
|
||||
*
|
||||
* @param postData A QVariantMap from parsed JSON representing the
|
||||
* data from a single post.
|
||||
* @param pixmap A QPixmap pointer to the post thumbnail.
|
||||
* @param parent A pointer to the parent QObject.
|
||||
*
|
||||
**/
|
||||
explicit DanbooruPost(QVariantMap postData, QPixmap pixmap = QPixmap(),
|
||||
QObject* parent = 0);
|
||||
|
||||
/**
|
||||
* @brief Construct a Danbooru post from XML attributes
|
||||
*
|
||||
* This is an overloaded function which uses XML attributes rather
|
||||
* than JSON. It should be used in case the JSON responses aren't
|
||||
* complete or broken (for example pools' posts in most Danbooru
|
||||
* instances).
|
||||
*
|
||||
* @param postData A QXmlStreamAttributes instance holding the
|
||||
* attributes for the given post.
|
||||
* @param pixmap A QPixmap pointer to the post thumbnail.
|
||||
* @param parent A pointer to the parent QObject.
|
||||
*
|
||||
**/
|
||||
explicit DanbooruPost(QXmlStreamAttributes& postData,
|
||||
QPixmap pixmap = QPixmap(), QObject* parent =0);
|
||||
|
||||
bool operator==(const DanbooruPost&);
|
||||
|
||||
~DanbooruPost();
|
||||
|
||||
// Post attributes
|
||||
|
||||
/**
|
||||
* @return The ID of the post.
|
||||
**/
|
||||
int id() const;
|
||||
|
||||
/**
|
||||
* @return The height in pixels of the post's image.
|
||||
**/
|
||||
int height() const;
|
||||
|
||||
/**
|
||||
* @return The width in pixels of the post's image.
|
||||
**/
|
||||
int width() const;
|
||||
|
||||
/**
|
||||
* @return The size in bytes of the post's image.
|
||||
**/
|
||||
int size() const;
|
||||
|
||||
/**
|
||||
* @return The URL to the post's image.
|
||||
**/
|
||||
const QUrl fileUrl() const;
|
||||
|
||||
/**
|
||||
* @return The tags associated to the post.
|
||||
**/
|
||||
const QSet< QString > tags() const;
|
||||
|
||||
/**
|
||||
* @return The URL to the post's thumbnail.
|
||||
**/
|
||||
const QUrl thumbnailUrl() const;
|
||||
|
||||
/**
|
||||
* @return A pointer to the thumbnail's pixmap.
|
||||
**/
|
||||
QPixmap pixmap() const;
|
||||
|
||||
/**
|
||||
* @return The current post's rating.
|
||||
**/
|
||||
Rating rating() const;
|
||||
|
||||
/**
|
||||
* Set the post's pixmap to a specific QPixmap instance's pointer.
|
||||
*
|
||||
**/
|
||||
void setPixmap(const QPixmap& pixmap);
|
||||
|
||||
/**
|
||||
* @return A string representation of the post.
|
||||
*
|
||||
* **/
|
||||
const QString toString();
|
||||
|
||||
|
||||
|
||||
};
|
||||
Q_DECLARE_FLAGS(Ratings, DanbooruPost::Rating)
|
||||
|
||||
private:
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(DanbooruPost::Ratings)
|
||||
QPixmap m_pixmap;
|
||||
|
||||
// basic features of a post
|
||||
|
||||
int m_id;
|
||||
int m_height;
|
||||
int m_width;
|
||||
int m_size;
|
||||
|
||||
QUrl m_url;
|
||||
QUrl m_thumbnailUrl;
|
||||
QSet<QString> m_tags;
|
||||
DanbooruPost::Rating m_rating;
|
||||
|
||||
static const QMap<QString, Rating> RATING_MAP;
|
||||
|
||||
// Private functions
|
||||
|
||||
static const QMap< QString, Rating > initRatingMap();
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Construct a Danbooru post from a QVariantMap.
|
||||
*
|
||||
* This form is the easiest to use and should be used when dealing with
|
||||
* responses in JSON format. Unfortunately most Danbooru
|
||||
* implementations produce broken JSON for some responses.
|
||||
*
|
||||
* @param postData A QVariantMap from parsed JSON representing the
|
||||
* data from a single post.
|
||||
* @param pixmap A QPixmap pointer to the post thumbnail.
|
||||
* @param parent A pointer to the parent QObject.
|
||||
*
|
||||
**/
|
||||
explicit DanbooruPost(QVariantMap postData, QPixmap pixmap = QPixmap(),
|
||||
QObject *parent = 0);
|
||||
|
||||
/**
|
||||
* @brief Construct a Danbooru post from XML attributes
|
||||
*
|
||||
* This is an overloaded function which uses XML attributes rather
|
||||
* than JSON. It should be used in case the JSON responses aren't
|
||||
* complete or broken (for example pools' posts in most Danbooru
|
||||
* instances).
|
||||
*
|
||||
* @param postData A QXmlStreamAttributes instance holding the
|
||||
* attributes for the given post.
|
||||
* @param pixmap A QPixmap pointer to the post thumbnail.
|
||||
* @param parent A pointer to the parent QObject.
|
||||
*
|
||||
**/
|
||||
explicit DanbooruPost(QXmlStreamAttributes &postData,
|
||||
QPixmap pixmap = QPixmap(), QObject *parent = 0);
|
||||
|
||||
bool operator==(const DanbooruPost &);
|
||||
|
||||
~DanbooruPost();
|
||||
|
||||
// Post attributes
|
||||
|
||||
/**
|
||||
* @return The ID of the post.
|
||||
**/
|
||||
int id() const;
|
||||
|
||||
/**
|
||||
* @return The height in pixels of the post's image.
|
||||
**/
|
||||
int height() const;
|
||||
|
||||
/**
|
||||
* @return The width in pixels of the post's image.
|
||||
**/
|
||||
int width() const;
|
||||
|
||||
/**
|
||||
* @return The size in bytes of the post's image.
|
||||
**/
|
||||
int size() const;
|
||||
|
||||
/**
|
||||
* @return The URL to the post's image.
|
||||
**/
|
||||
const QUrl fileUrl() const;
|
||||
|
||||
/**
|
||||
* @return The tags associated to the post.
|
||||
**/
|
||||
const QSet< QString > tags() const;
|
||||
|
||||
/**
|
||||
* @return The URL to the post's thumbnail.
|
||||
**/
|
||||
const QUrl thumbnailUrl() const;
|
||||
|
||||
/**
|
||||
* @return A pointer to the thumbnail's pixmap.
|
||||
**/
|
||||
QPixmap pixmap() const;
|
||||
|
||||
/**
|
||||
* @return The current post's rating.
|
||||
**/
|
||||
Rating rating() const;
|
||||
|
||||
/**
|
||||
* Set the post's pixmap to a specific QPixmap instance's pointer.
|
||||
*
|
||||
**/
|
||||
void setPixmap(const QPixmap &pixmap);
|
||||
|
||||
/**
|
||||
* @return A string representation of the post.
|
||||
*
|
||||
* **/
|
||||
const QString toString();
|
||||
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(DanbooruPost::Ratings)
|
||||
|
||||
}; // namespace Danbooru
|
||||
|
||||
Q_DECLARE_METATYPE(Danbooru::DanbooruPost*)
|
||||
Q_DECLARE_METATYPE(Danbooru::DanbooruPost *)
|
||||
|
||||
#endif // DANBOORUPOST_H
|
||||
|
||||
|
|
|
@ -53,9 +53,9 @@ const QString DanbooruService::ARTIST_URL = "artist/index.json";
|
|||
const QString DanbooruService::POOL_DATA_URL = "pool/show.xml";
|
||||
const QString DanbooruService::RELATED_TAG_URL = "tag/related.json";
|
||||
|
||||
DanbooruService::DanbooruService(QUrl& boardUrl, QString username,
|
||||
QString password, KImageCache* cache,
|
||||
QObject* parent):
|
||||
DanbooruService::DanbooruService(QUrl &boardUrl, QString username,
|
||||
QString password, KImageCache *cache,
|
||||
QObject *parent):
|
||||
QObject(parent),
|
||||
m_url(boardUrl),
|
||||
m_username(username),
|
||||
|
@ -71,7 +71,6 @@ DanbooruService::~DanbooruService()
|
|||
|
||||
}
|
||||
|
||||
|
||||
void DanbooruService::getPostList(int page, QStringList tags, int limit)
|
||||
{
|
||||
|
||||
|
@ -89,7 +88,7 @@ void DanbooruService::getPostList(int page, QStringList tags, int limit)
|
|||
|
||||
// qDebug() << "Final constructed post URL" << danbooruUrl.url();
|
||||
|
||||
KIO::StoredTransferJob* job = KIO::storedGet(danbooruUrl, KIO::NoReload,
|
||||
KIO::StoredTransferJob *job = KIO::storedGet(danbooruUrl, KIO::NoReload,
|
||||
KIO::HideProgressInfo);
|
||||
|
||||
// This job can use JSON data
|
||||
|
@ -97,7 +96,6 @@ void DanbooruService::getPostList(int page, QStringList tags, int limit)
|
|||
|
||||
connect(job, &KIO::StoredTransferJob::result, this, &DanbooruService::processPostList);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void DanbooruService::getTagList(int limit, QString name)
|
||||
|
@ -114,38 +112,38 @@ void DanbooruService::getTagList(int limit, QString name)
|
|||
parameters);
|
||||
//qDebug() << "Final constructed tag URL" << danbooruUrl.url();
|
||||
|
||||
KIO::StoredTransferJob* job = KIO::storedGet(danbooruUrl, KIO::NoReload,
|
||||
KIO::StoredTransferJob *job = KIO::storedGet(danbooruUrl, KIO::NoReload,
|
||||
KIO::HideProgressInfo);
|
||||
|
||||
connect(job, &KIO::StoredTransferJob::result, [this](KJob* job) {
|
||||
|
||||
if (job->error()) {
|
||||
Q_EMIT(downloadError(job->errorString()));
|
||||
return;
|
||||
}
|
||||
|
||||
StoredTransferJob* jobResult = qobject_cast<StoredTransferJob*>(job);
|
||||
QByteArray data = jobResult->data();
|
||||
|
||||
bool ok;
|
||||
|
||||
// Most Danbooru implementations return tags in wrong order when
|
||||
// using JSON, so we have to fall back to XML
|
||||
QList<QVariant> tagList = parseDanbooruResult(data, "tag", &ok);
|
||||
|
||||
if (!ok) {
|
||||
Q_EMIT(downloadError(QString("Unable to decode data")));
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto element : tagList) {
|
||||
QVariantMap map = element.toMap();
|
||||
DanbooruTag* tag = new DanbooruTag(map);
|
||||
Q_EMIT(tagDownloaded(tag));
|
||||
}
|
||||
connect(job, &KIO::StoredTransferJob::result, [this](KJob * job) {
|
||||
|
||||
if (job->error()) {
|
||||
Q_EMIT(downloadError(job->errorString()));
|
||||
return;
|
||||
}
|
||||
);
|
||||
|
||||
StoredTransferJob *jobResult = qobject_cast<StoredTransferJob *>(job);
|
||||
QByteArray data = jobResult->data();
|
||||
|
||||
bool ok;
|
||||
|
||||
// Most Danbooru implementations return tags in wrong order when
|
||||
// using JSON, so we have to fall back to XML
|
||||
QList<QVariant> tagList = parseDanbooruResult(data, "tag", &ok);
|
||||
|
||||
if (!ok) {
|
||||
Q_EMIT(downloadError(QString("Unable to decode data")));
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto element : tagList) {
|
||||
QVariantMap map = element.toMap();
|
||||
DanbooruTag *tag = new DanbooruTag(map);
|
||||
Q_EMIT(tagDownloaded(tag));
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void DanbooruService::getPool(int poolId, int page)
|
||||
|
@ -164,8 +162,7 @@ void DanbooruService::getPool(int poolId, int page)
|
|||
|
||||
//qDebug() << "Final constructed pool URL" << danbooruUrl.url();
|
||||
|
||||
|
||||
KIO::StoredTransferJob* job = KIO::storedGet(danbooruUrl, KIO::NoReload,
|
||||
KIO::StoredTransferJob *job = KIO::storedGet(danbooruUrl, KIO::NoReload,
|
||||
KIO::HideProgressInfo);
|
||||
|
||||
//HACK: Most Danbooru implementations don't provide valid data on
|
||||
|
@ -194,21 +191,21 @@ void DanbooruService::getPoolList(int page)
|
|||
|
||||
//qDebug() << "Final constructed pool list URL" << danbooruUrl.url();
|
||||
|
||||
KIO::StoredTransferJob* job = KIO::storedGet(danbooruUrl, KIO::NoReload,
|
||||
KIO::StoredTransferJob *job = KIO::storedGet(danbooruUrl, KIO::NoReload,
|
||||
KIO::HideProgressInfo);
|
||||
// This job can use JSON data
|
||||
job->setProperty("needsXML", false);
|
||||
|
||||
// connect(job, &KIO::StoredTransferJob::result, this, &DanbooruService::processPoolList);
|
||||
|
||||
connect(job, &KIO::StoredTransferJob::result, [this] (KJob* job) {
|
||||
connect(job, &KIO::StoredTransferJob::result, [this](KJob * job) {
|
||||
|
||||
if (job->error()) {
|
||||
Q_EMIT(downloadError(job->errorString()));
|
||||
return;
|
||||
}
|
||||
|
||||
StoredTransferJob* jobResult = qobject_cast<StoredTransferJob*>(job);
|
||||
StoredTransferJob *jobResult = qobject_cast<StoredTransferJob *>(job);
|
||||
QByteArray data = jobResult->data();
|
||||
|
||||
bool ok;
|
||||
|
@ -222,7 +219,7 @@ void DanbooruService::getPoolList(int page)
|
|||
for (auto element : poolList) {
|
||||
QVariantMap map = element.toMap();
|
||||
|
||||
DanbooruPool* pool = new DanbooruPool(map);
|
||||
DanbooruPool *pool = new DanbooruPool(map);
|
||||
Q_EMIT(poolDownloaded(pool));
|
||||
}
|
||||
|
||||
|
@ -230,11 +227,11 @@ void DanbooruService::getPoolList(int page)
|
|||
Q_EMIT(poolDownloadFinished());
|
||||
}
|
||||
|
||||
);
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
void DanbooruService::getRelatedTags(const QStringList& tags,
|
||||
void DanbooruService::getRelatedTags(const QStringList &tags,
|
||||
DanbooruTag::TagType tagType)
|
||||
{
|
||||
|
||||
|
@ -265,19 +262,19 @@ void DanbooruService::getRelatedTags(const QStringList& tags,
|
|||
|
||||
//qDebug() << "Final constructed related tag URL" << danbooruUrl.url();
|
||||
|
||||
StoredTransferJob* job = KIO::storedGet(
|
||||
StoredTransferJob *job = KIO::storedGet(
|
||||
danbooruUrl, KIO::NoReload,
|
||||
KIO::HideProgressInfo
|
||||
);
|
||||
|
||||
connect(job, &StoredTransferJob::result, [this](KJob* job) {
|
||||
connect(job, &StoredTransferJob::result, [this](KJob * job) {
|
||||
|
||||
if (job->error()) {
|
||||
Q_EMIT(downloadError(job->errorString()));
|
||||
return;
|
||||
Q_EMIT(downloadError(job->errorString()));
|
||||
return;
|
||||
}
|
||||
|
||||
StoredTransferJob* jobResult = qobject_cast<StoredTransferJob*>(job);
|
||||
StoredTransferJob *jobResult = qobject_cast<StoredTransferJob *>(job);
|
||||
QByteArray data = jobResult->data();
|
||||
bool ok;
|
||||
|
||||
|
@ -314,13 +311,13 @@ void DanbooruService::getRelatedTags(const QStringList& tags,
|
|||
|
||||
}
|
||||
|
||||
);
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
// Getters / setters
|
||||
|
||||
void DanbooruService::setBlacklist(const QSet< QString >& blacklist)
|
||||
void DanbooruService::setBlacklist(const QSet< QString > &blacklist)
|
||||
{
|
||||
|
||||
if (!blacklist.isEmpty()) {
|
||||
|
@ -329,7 +326,6 @@ void DanbooruService::setBlacklist(const QSet< QString >& blacklist)
|
|||
|
||||
}
|
||||
|
||||
|
||||
const QSet< QString > DanbooruService::blacklist() const
|
||||
{
|
||||
return m_blacklist;
|
||||
|
@ -384,7 +380,7 @@ const DanbooruPost::Ratings DanbooruService::maximumAllowedRating() const
|
|||
|
||||
// Slots
|
||||
|
||||
void DanbooruService::processPostList(KJob* job)
|
||||
void DanbooruService::processPostList(KJob *job)
|
||||
{
|
||||
|
||||
// qDebug() << "Got post data OK";
|
||||
|
@ -393,7 +389,7 @@ void DanbooruService::processPostList(KJob* job)
|
|||
Q_EMIT(downloadError(job->errorString()));
|
||||
}
|
||||
|
||||
StoredTransferJob* jobResult = qobject_cast<StoredTransferJob*>(job);
|
||||
StoredTransferJob *jobResult = qobject_cast<StoredTransferJob *>(job);
|
||||
|
||||
if (jobResult == 0) {
|
||||
Q_EMIT(downloadError(QString("Internal error")));
|
||||
|
@ -427,7 +423,7 @@ void DanbooruService::processPostList(KJob* job)
|
|||
for (auto element : postList) {
|
||||
|
||||
QVariantMap map = element.toMap();
|
||||
DanbooruPost* post = new DanbooruPost(map);
|
||||
DanbooruPost *post = new DanbooruPost(map);
|
||||
|
||||
// Remove unwanted posts
|
||||
|
||||
|
@ -453,11 +449,11 @@ void DanbooruService::processPostList(KJob* job)
|
|||
|
||||
} else {
|
||||
|
||||
StoredTransferJob* pixmapJob = KIO::storedGet(post->thumbnailUrl(),
|
||||
KIO::NoReload, KIO::HideProgressInfo
|
||||
);
|
||||
StoredTransferJob *pixmapJob = KIO::storedGet(post->thumbnailUrl(),
|
||||
KIO::NoReload, KIO::HideProgressInfo
|
||||
);
|
||||
|
||||
KIO::Scheduler::setJobPriority(static_cast<KIO::SimpleJob*>(job), 1);
|
||||
KIO::Scheduler::setJobPriority(static_cast<KIO::SimpleJob *>(job), 1);
|
||||
|
||||
QVariant variant;
|
||||
variant.setValue(post);
|
||||
|
@ -467,23 +463,26 @@ void DanbooruService::processPostList(KJob* job)
|
|||
|
||||
pixmapJob->setProperty("danbooruPost", variant);
|
||||
|
||||
connect(pixmapJob, &StoredTransferJob::result, [post, this, pix] (KJob* job) mutable {
|
||||
connect(pixmapJob, &StoredTransferJob::result, [post, this, pix](KJob * job) mutable {
|
||||
|
||||
if (job->error()) {
|
||||
if (job->error())
|
||||
{
|
||||
Q_EMIT(downloadError(job->errorString()));
|
||||
return;
|
||||
}
|
||||
|
||||
StoredTransferJob* jobResult = qobject_cast<StoredTransferJob*>(job);
|
||||
StoredTransferJob *jobResult = qobject_cast<StoredTransferJob *>(job);
|
||||
|
||||
if (!pix.loadFromData(jobResult->data())) {
|
||||
Q_EMIT(downloadError(QString("Pixmap data could not be loaded")));
|
||||
return;
|
||||
if (!pix.loadFromData(jobResult->data()))
|
||||
{
|
||||
Q_EMIT(downloadError(QString("Pixmap data could not be loaded")));
|
||||
return;
|
||||
}
|
||||
|
||||
post->setPixmap(pix);
|
||||
|
||||
if (m_cache) {
|
||||
if (m_cache)
|
||||
{
|
||||
//qDebug() << "Inserting item in cache";
|
||||
m_cache->insertPixmap(post->thumbnailUrl().url(), pix);
|
||||
}
|
||||
|
@ -493,7 +492,8 @@ void DanbooruService::processPostList(KJob* job)
|
|||
//qDebug() << "Current posts remaining" << m_currentPosts;
|
||||
Q_EMIT(postDownloaded(post));
|
||||
|
||||
if (m_postsToFetch == 0) {
|
||||
if (m_postsToFetch == 0)
|
||||
{
|
||||
qDebug() << "Post download finished";
|
||||
Q_EMIT(postDownloadFinished());
|
||||
}
|
||||
|
@ -504,30 +504,26 @@ void DanbooruService::processPostList(KJob* job)
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void DanbooruService::processTagList(KJob* job)
|
||||
void DanbooruService::processTagList(KJob *job)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void DanbooruService::processRelatedTagList(KJob* job)
|
||||
void DanbooruService::processRelatedTagList(KJob *job)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DanbooruService::processPoolList(KJob* job)
|
||||
void DanbooruService::processPoolList(KJob *job)
|
||||
{
|
||||
|
||||
|
||||
if (job->error()) {
|
||||
Q_EMIT(downloadError(job->errorString()));
|
||||
}
|
||||
|
||||
StoredTransferJob* jobResult = qobject_cast<StoredTransferJob*>(job);
|
||||
StoredTransferJob *jobResult = qobject_cast<StoredTransferJob *>(job);
|
||||
|
||||
if (jobResult == 0) {
|
||||
Q_EMIT(downloadError(QString("Internal error")));
|
||||
|
@ -549,7 +545,7 @@ void DanbooruService::processPoolList(KJob* job)
|
|||
for (auto element : poolList) {
|
||||
QVariantMap map = element.toMap();
|
||||
|
||||
DanbooruPool* pool = new DanbooruPool(map);
|
||||
DanbooruPool *pool = new DanbooruPool(map);
|
||||
Q_EMIT(poolDownloaded(pool));
|
||||
}
|
||||
|
||||
|
@ -558,12 +554,12 @@ void DanbooruService::processPoolList(KJob* job)
|
|||
|
||||
}
|
||||
|
||||
void DanbooruService::downloadAllTags(KJob* job)
|
||||
void DanbooruService::downloadAllTags(KJob *job)
|
||||
{
|
||||
Q_UNUSED(job)
|
||||
}
|
||||
|
||||
void DanbooruService::downloadThumbnail(KJob* job)
|
||||
void DanbooruService::downloadThumbnail(KJob *job)
|
||||
{
|
||||
|
||||
if (job->error()) {
|
||||
|
@ -572,11 +568,11 @@ void DanbooruService::downloadThumbnail(KJob* job)
|
|||
|
||||
QVariant postData = job->property("danbooruPost");
|
||||
|
||||
DanbooruPost* post = postData.value<DanbooruPost*>();
|
||||
DanbooruPost *post = postData.value<DanbooruPost *>();
|
||||
QPixmap pix;
|
||||
// QPixmap* pix = new QPixmap();
|
||||
|
||||
StoredTransferJob* jobResult = qobject_cast<StoredTransferJob*>(job);
|
||||
StoredTransferJob *jobResult = qobject_cast<StoredTransferJob *>(job);
|
||||
|
||||
if (jobResult == 0) {
|
||||
Q_EMIT(downloadError(QString("Internal error")));
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#ifndef DANBOORUSERVICE_H
|
||||
#define DANBOORUSERVICE_H
|
||||
|
||||
|
||||
/**
|
||||
* @brief Classes to interact with Danbooru boards
|
||||
* @file danbooruservice.h
|
||||
|
@ -56,214 +55,214 @@ class KJob;
|
|||
|
||||
using Danbooru::DanbooruTag;
|
||||
|
||||
namespace Danbooru {
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
class DanbooruPool;
|
||||
class DanbooruPool;
|
||||
|
||||
using KIO::StoredTransferJob;
|
||||
using KIO::StoredTransferJob;
|
||||
|
||||
/**
|
||||
* @brief A class which provides a wrapper around Danbooru's RESTful API.
|
||||
*
|
||||
* This class provides access to Danbooru-based image boards
|
||||
* by making the appropriate RESTful calls to the service and then
|
||||
* retrieving and parsing the reuslts.
|
||||
*
|
||||
* @author Luca Beltrame (lbeltrame@kde.org)
|
||||
*
|
||||
*
|
||||
**/
|
||||
class DanbooruService : public QObject
|
||||
{
|
||||
/**
|
||||
* @brief A class which provides a wrapper around Danbooru's RESTful API.
|
||||
*
|
||||
* This class provides access to Danbooru-based image boards
|
||||
* by making the appropriate RESTful calls to the service and then
|
||||
* retrieving and parsing the reuslts.
|
||||
*
|
||||
* @author Luca Beltrame (lbeltrame@kde.org)
|
||||
*
|
||||
*
|
||||
**/
|
||||
class DanbooruService : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
// URL fragments
|
||||
// URL fragments
|
||||
|
||||
static const QString POST_URL;
|
||||
static const QString TAG_URL;
|
||||
static const QString POOL_URL;
|
||||
static const QString ARTIST_URL;
|
||||
static const QString POOL_DATA_URL;
|
||||
static const QString RELATED_TAG_URL;
|
||||
static const QString POST_URL;
|
||||
static const QString TAG_URL;
|
||||
static const QString POOL_URL;
|
||||
static const QString ARTIST_URL;
|
||||
static const QString POOL_DATA_URL;
|
||||
static const QString RELATED_TAG_URL;
|
||||
|
||||
// member variables
|
||||
// member variables
|
||||
|
||||
QUrl m_url;
|
||||
QString m_username;
|
||||
QString m_password;
|
||||
QSet<QString> m_blacklist;
|
||||
DanbooruPost::Ratings m_maxRating;
|
||||
QUrl m_url;
|
||||
QString m_username;
|
||||
QString m_password;
|
||||
QSet<QString> m_blacklist;
|
||||
DanbooruPost::Ratings m_maxRating;
|
||||
|
||||
unsigned int m_postsToFetch; // To tell when to quit
|
||||
unsigned int m_postsToFetch; // To tell when to quit
|
||||
|
||||
KImageCache* m_cache; // Pixmap cache
|
||||
KImageCache *m_cache; // Pixmap cache
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Construct a default instance of the service.
|
||||
*
|
||||
* @param boardUrl The URL to connect to.
|
||||
* @param username Username to use (optional)
|
||||
* @param password Password to use (optional)
|
||||
* @param cache A pointer to a KImageCache instance to enable caching
|
||||
* of downloaded pixmaps.
|
||||
* @param parent The parent QObject
|
||||
*
|
||||
**/
|
||||
DanbooruService(QUrl& boardUrl, QString username = QString(),
|
||||
QString password = QString(), KImageCache* cache = 0,
|
||||
QObject* parent = 0);
|
||||
/**
|
||||
* @brief Construct a default instance of the service.
|
||||
*
|
||||
* @param boardUrl The URL to connect to.
|
||||
* @param username Username to use (optional)
|
||||
* @param password Password to use (optional)
|
||||
* @param cache A pointer to a KImageCache instance to enable caching
|
||||
* of downloaded pixmaps.
|
||||
* @param parent The parent QObject
|
||||
*
|
||||
**/
|
||||
DanbooruService(QUrl &boardUrl, QString username = QString(),
|
||||
QString password = QString(), KImageCache *cache = 0,
|
||||
QObject *parent = 0);
|
||||
|
||||
/**
|
||||
* Default destructor.
|
||||
**/
|
||||
~DanbooruService();
|
||||
/**
|
||||
* Default destructor.
|
||||
**/
|
||||
~DanbooruService();
|
||||
|
||||
/**
|
||||
*@brief Get posts from a the board.
|
||||
*
|
||||
* @param page The page containing posts (default: 1)
|
||||
* @param tags The specific tags to query for (default: all tags)
|
||||
* @param limit The number of posts to fetch (maximum 100)
|
||||
*
|
||||
**/
|
||||
void getPostList(int page=1, QStringList tags=QStringList(),
|
||||
int limit=100);
|
||||
/**
|
||||
*@brief Get posts from a the board.
|
||||
*
|
||||
* @param page The page containing posts (default: 1)
|
||||
* @param tags The specific tags to query for (default: all tags)
|
||||
* @param limit The number of posts to fetch (maximum 100)
|
||||
*
|
||||
**/
|
||||
void getPostList(int page = 1, QStringList tags = QStringList(),
|
||||
int limit = 100);
|
||||
|
||||
/**
|
||||
* @brief Get a list of pools from the board.
|
||||
*
|
||||
* @param page The page to get pools from (default: 1)
|
||||
*
|
||||
**/
|
||||
void getPoolList(int page = 1);
|
||||
/**
|
||||
* @brief Get a list of pools from the board.
|
||||
*
|
||||
* @param page The page to get pools from (default: 1)
|
||||
*
|
||||
**/
|
||||
void getPoolList(int page = 1);
|
||||
|
||||
/**
|
||||
* @brief Get the posts associated with a specific pool ID.
|
||||
*
|
||||
* @param poolId The ID of the pool to fetch posts from.
|
||||
* @param page The page of the pool posts (if > 100)
|
||||
*
|
||||
**/
|
||||
void getPool(int poolId, int page=1);
|
||||
/**
|
||||
* @brief Get the posts associated with a specific pool ID.
|
||||
*
|
||||
* @param poolId The ID of the pool to fetch posts from.
|
||||
* @param page The page of the pool posts (if > 100)
|
||||
*
|
||||
**/
|
||||
void getPool(int poolId, int page = 1);
|
||||
|
||||
/**
|
||||
* @brief Get a list of tags from the board
|
||||
*
|
||||
* If name is supplied, a list of tags including the exact name of the
|
||||
* tag is fetched from Danbooru, otherwise the most recent tags are
|
||||
* retrieved.
|
||||
*
|
||||
* The tagDownloaded signal is emitted every time a tag has been
|
||||
* retrieved.
|
||||
*
|
||||
* @param limit The number of tags to get.
|
||||
* @param name The name of the tag to retrieve, or an empty string
|
||||
*
|
||||
**/
|
||||
void getTagList(int limit=10, QString name="");
|
||||
/**
|
||||
* @brief Get a list of tags from the board
|
||||
*
|
||||
* If name is supplied, a list of tags including the exact name of the
|
||||
* tag is fetched from Danbooru, otherwise the most recent tags are
|
||||
* retrieved.
|
||||
*
|
||||
* The tagDownloaded signal is emitted every time a tag has been
|
||||
* retrieved.
|
||||
*
|
||||
* @param limit The number of tags to get.
|
||||
* @param name The name of the tag to retrieve, or an empty string
|
||||
*
|
||||
**/
|
||||
void getTagList(int limit = 10, QString name = "");
|
||||
|
||||
/**
|
||||
* @brief Get tags related to a specific, user supplied list.
|
||||
*
|
||||
* @param tags The tags to query for related terms
|
||||
* @param tagType The type of tag to query for
|
||||
**/
|
||||
void getRelatedTags(const QStringList& tags, DanbooruTag::TagType tagType = DanbooruTag::General);
|
||||
/**
|
||||
* @brief Get tags related to a specific, user supplied list.
|
||||
*
|
||||
* @param tags The tags to query for related terms
|
||||
* @param tagType The type of tag to query for
|
||||
**/
|
||||
void getRelatedTags(const QStringList &tags, DanbooruTag::TagType tagType = DanbooruTag::General);
|
||||
|
||||
/**
|
||||
* @return The currently allowed ratings when downloading posts.
|
||||
**/
|
||||
const QStringList allowedRatings() const;
|
||||
/**
|
||||
* @return The currently allowed ratings when downloading posts.
|
||||
**/
|
||||
const QStringList allowedRatings() const;
|
||||
|
||||
/**
|
||||
* @return The maximum allowed rating for a post.
|
||||
**/
|
||||
const DanbooruPost::Ratings maximumAllowedRating() const;
|
||||
/**
|
||||
* @return The maximum allowed rating for a post.
|
||||
**/
|
||||
const DanbooruPost::Ratings maximumAllowedRating() const;
|
||||
|
||||
/**
|
||||
* @return The currently blacklisted tags.
|
||||
**/
|
||||
const QSet<QString> blacklist() const;
|
||||
/**
|
||||
* @return The currently blacklisted tags.
|
||||
**/
|
||||
const QSet<QString> blacklist() const;
|
||||
|
||||
void setBlacklist(const QSet<QString>& blacklist);
|
||||
void setBlacklist(const QSet<QString> &blacklist);
|
||||
|
||||
/**
|
||||
* @brief Set the maximum allowed rating for the board.
|
||||
*
|
||||
* Posts whose rating is higher than the maximuk allowed will not be
|
||||
* downloaded.
|
||||
*
|
||||
**/
|
||||
void setMaximumAllowedRating(DanbooruPost::Rating rating);
|
||||
/**
|
||||
* @brief Set the maximum allowed rating for the board.
|
||||
*
|
||||
* Posts whose rating is higher than the maximuk allowed will not be
|
||||
* downloaded.
|
||||
*
|
||||
**/
|
||||
void setMaximumAllowedRating(DanbooruPost::Rating rating);
|
||||
|
||||
/**
|
||||
* @brief Set the tag blacklist.
|
||||
*
|
||||
* If a tag is in the blacklist, posts tagged with it will not be downloaded.
|
||||
*
|
||||
**/
|
||||
void setBlackList(QStringList blacklist);
|
||||
/**
|
||||
* @brief Set the tag blacklist.
|
||||
*
|
||||
* If a tag is in the blacklist, posts tagged with it will not be downloaded.
|
||||
*
|
||||
**/
|
||||
void setBlackList(QStringList blacklist);
|
||||
|
||||
private Q_SLOTS:
|
||||
void processPostList(KJob* job);
|
||||
void processPoolList(KJob* job);
|
||||
void processTagList(KJob* job);
|
||||
void processRelatedTagList(KJob* job);
|
||||
void downloadThumbnail(KJob* job);
|
||||
void downloadAllTags(KJob* job);
|
||||
private Q_SLOTS:
|
||||
void processPostList(KJob *job);
|
||||
void processPoolList(KJob *job);
|
||||
void processTagList(KJob *job);
|
||||
void processRelatedTagList(KJob *job);
|
||||
void downloadThumbnail(KJob *job);
|
||||
void downloadAllTags(KJob *job);
|
||||
|
||||
Q_SIGNALS:
|
||||
Q_SIGNALS:
|
||||
|
||||
/**
|
||||
* Emitted when there are no more posts to download.
|
||||
*
|
||||
* Connect to this signal to know when downloading is complete.
|
||||
*
|
||||
**/
|
||||
void postDownloadFinished();
|
||||
/**
|
||||
* Emitted when there are no more posts to download.
|
||||
*
|
||||
* Connect to this signal to know when downloading is complete.
|
||||
*
|
||||
**/
|
||||
void postDownloadFinished();
|
||||
|
||||
/**
|
||||
* Emitted when there are no more pools to download.
|
||||
**/
|
||||
void poolDownloadFinished();
|
||||
/**
|
||||
* Emitted when there are no more pools to download.
|
||||
**/
|
||||
void poolDownloadFinished();
|
||||
|
||||
/**
|
||||
* Emitted when a download error occurred.
|
||||
*
|
||||
* The parameter contains the error string.
|
||||
*
|
||||
**/
|
||||
void downloadError(QString error);
|
||||
|
||||
/**
|
||||
* Emitted when a download error occurred.
|
||||
*
|
||||
* The parameter contains the error string.
|
||||
*
|
||||
**/
|
||||
void downloadError(QString error);
|
||||
/**
|
||||
* Emitted when a post has been downloaded.
|
||||
*
|
||||
* The parameter contains a pointer to the post that has been
|
||||
* downloaded.
|
||||
**/
|
||||
void postDownloaded(Danbooru::DanbooruPost *post);
|
||||
|
||||
/**
|
||||
* Emitted when a post has been downloaded.
|
||||
*
|
||||
* The parameter contains a pointer to the post that has been
|
||||
* downloaded.
|
||||
**/
|
||||
void postDownloaded(Danbooru::DanbooruPost* post);
|
||||
/**
|
||||
* Emitted when a pool has been downloaded.
|
||||
*
|
||||
* The parameter contains a pointer to the pool that has been
|
||||
* downloaded.
|
||||
**/
|
||||
void poolDownloaded(Danbooru::DanbooruPool *pool);
|
||||
|
||||
/**
|
||||
* Emitted when a pool has been downloaded.
|
||||
*
|
||||
* The parameter contains a pointer to the pool that has been
|
||||
* downloaded.
|
||||
**/
|
||||
void poolDownloaded(Danbooru::DanbooruPool* pool);
|
||||
/**
|
||||
* Emitted when a tag has been downloaded.
|
||||
*
|
||||
* The parameter contains a pointer to the tag that has been
|
||||
* downloaded.
|
||||
**/
|
||||
void tagDownloaded(Danbooru::DanbooruTag *tag);
|
||||
|
||||
/**
|
||||
* Emitted when a tag has been downloaded.
|
||||
*
|
||||
* The parameter contains a pointer to the tag that has been
|
||||
* downloaded.
|
||||
**/
|
||||
void tagDownloaded(Danbooru::DanbooruTag* tag);
|
||||
|
||||
};
|
||||
};
|
||||
};
|
||||
#endif // DANBOORUSERVICE_H
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
namespace Danbooru
|
||||
{
|
||||
|
||||
DanbooruTag::DanbooruTag(const QVariantMap& postData, QObject* parent):
|
||||
DanbooruTag::DanbooruTag(const QVariantMap &postData, QObject *parent):
|
||||
QObject(parent)
|
||||
{
|
||||
m_id = postData.value("id").toInt();
|
||||
|
@ -82,5 +82,4 @@ Danbooru::DanbooruTag::TagType DanbooruTag::type() const
|
|||
return m_tagType;
|
||||
}
|
||||
|
||||
|
||||
}; // namespace Danbooru
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef DANBOORUTAG_H
|
||||
#define DANBOORUTAG_H
|
||||
|
||||
|
@ -29,54 +28,55 @@
|
|||
|
||||
#include "danbooru.h"
|
||||
|
||||
namespace Danbooru {
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
class DanbooruTag : public QObject
|
||||
{
|
||||
class DanbooruTag : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Types of tags
|
||||
*
|
||||
* A Danbooru tag is not simply a string, but carries some (limited)
|
||||
* semantic information. In particular, tags are organized in what they
|
||||
* refer to, either something related to the image itself, or to the
|
||||
* artist that drew it, or the copyrights associated to the image, or even
|
||||
* the characters that are represented in it.
|
||||
*
|
||||
**/
|
||||
public:
|
||||
/**
|
||||
* @brief Types of tags
|
||||
*
|
||||
* A Danbooru tag is not simply a string, but carries some (limited)
|
||||
* semantic information. In particular, tags are organized in what they
|
||||
* refer to, either something related to the image itself, or to the
|
||||
* artist that drew it, or the copyrights associated to the image, or even
|
||||
* the characters that are represented in it.
|
||||
*
|
||||
**/
|
||||
|
||||
enum TagType {
|
||||
General = 1, /**< Generic tags **/
|
||||
Artist = 2, /**< Tags related to artists **/
|
||||
Copyright = 4, /**<Tags related to copyrights **/
|
||||
Character= 8, /**<Tags related to characters **/
|
||||
Character = 8, /**<Tags related to characters **/
|
||||
Unknown = 16 /**< Unknown tags **/
|
||||
};
|
||||
|
||||
private:
|
||||
int m_id;
|
||||
int m_count;
|
||||
QString m_name;
|
||||
bool m_ambiguous;
|
||||
TagType m_tagType;
|
||||
|
||||
public:
|
||||
DanbooruTag(const QVariantMap& postData, QObject* parent=0);
|
||||
int id() const;
|
||||
int count() const;
|
||||
const QString name() const;
|
||||
bool ambiguous() const;
|
||||
TagType type() const;
|
||||
private:
|
||||
int m_id;
|
||||
int m_count;
|
||||
QString m_name;
|
||||
bool m_ambiguous;
|
||||
TagType m_tagType;
|
||||
|
||||
};
|
||||
public:
|
||||
DanbooruTag(const QVariantMap &postData, QObject *parent = 0);
|
||||
int id() const;
|
||||
int count() const;
|
||||
const QString name() const;
|
||||
bool ambiguous() const;
|
||||
TagType type() const;
|
||||
|
||||
};
|
||||
|
||||
Q_DECLARE_FLAGS(TagTypes, DanbooruTag::TagType)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(TagTypes)
|
||||
|
||||
Q_DECLARE_FLAGS(TagTypes, DanbooruTag::TagType)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(TagTypes)
|
||||
|
||||
}; // namespace Danbooru
|
||||
|
||||
Q_DECLARE_METATYPE(Danbooru::DanbooruTag*)
|
||||
Q_DECLARE_METATYPE(Danbooru::DanbooruTag *)
|
||||
|
||||
#endif // DANBOORUTAG_H
|
||||
|
|
|
@ -34,156 +34,157 @@
|
|||
|
||||
#include <QDebug>
|
||||
|
||||
namespace Danbooru {
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
QUrl requestUrl(QUrl& url, const QString& path,
|
||||
const QString& username, const QString& password,
|
||||
const dictMap& parameters, const QStringList& tags)
|
||||
{
|
||||
QUrl requestUrl(QUrl &url, const QString &path,
|
||||
const QString &username, const QString &password,
|
||||
const dictMap ¶meters, const QStringList &tags)
|
||||
{
|
||||
|
||||
QUrl danbooruUrl = QUrl(url);
|
||||
danbooruUrl = danbooruUrl.adjusted(QUrl::StripTrailingSlash);
|
||||
danbooruUrl.setPath(danbooruUrl.path() + '/' + path);
|
||||
QUrl danbooruUrl = QUrl(url);
|
||||
danbooruUrl = danbooruUrl.adjusted(QUrl::StripTrailingSlash);
|
||||
danbooruUrl.setPath(danbooruUrl.path() + '/' + path);
|
||||
|
||||
// If we have parameters, add them
|
||||
// If we have parameters, add them
|
||||
|
||||
if (!parameters.isEmpty()) {
|
||||
|
||||
for (auto key: parameters.keys()) {
|
||||
danbooruUrl.addQueryItem(key, parameters.value(key));
|
||||
}
|
||||
if (!parameters.isEmpty()) {
|
||||
|
||||
for (auto key : parameters.keys()) {
|
||||
danbooruUrl.addQueryItem(key, parameters.value(key));
|
||||
}
|
||||
|
||||
// Now, let's add tags should we have them
|
||||
|
||||
if (!tags.isEmpty()) {
|
||||
QByteArray encoded_tags = QUrl::toPercentEncoding(tags.join(" "));
|
||||
danbooruUrl.addEncodedQueryItem("tags", encoded_tags);
|
||||
}
|
||||
|
||||
if (!username.isEmpty() && !password.isEmpty()) {
|
||||
danbooruUrl.setUserName(username);
|
||||
danbooruUrl.setPassword(password);
|
||||
}
|
||||
|
||||
return danbooruUrl;
|
||||
}
|
||||
|
||||
QUrl requestUrl(QUrl& url, const QString& path, const QString& username,
|
||||
const QString& password, const dictMap& parameters)
|
||||
{
|
||||
// Now, let's add tags should we have them
|
||||
|
||||
QUrl danbooruUrl = QUrl(url);
|
||||
danbooruUrl = danbooruUrl.adjusted(QUrl::StripTrailingSlash);
|
||||
danbooruUrl.setPath(danbooruUrl.path() + '/' + path);
|
||||
|
||||
// If we have parameters, add them
|
||||
|
||||
if (!parameters.isEmpty()) {
|
||||
|
||||
for (auto key: parameters.keys()) {
|
||||
danbooruUrl.addQueryItem(key, parameters.value(key));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!username.isEmpty() && !password.isEmpty()) {
|
||||
danbooruUrl.setUserName(username);
|
||||
danbooruUrl.setPassword(password);
|
||||
}
|
||||
|
||||
return danbooruUrl;
|
||||
if (!tags.isEmpty()) {
|
||||
QByteArray encoded_tags = QUrl::toPercentEncoding(tags.join(" "));
|
||||
danbooruUrl.addEncodedQueryItem("tags", encoded_tags);
|
||||
}
|
||||
|
||||
QUrl requestUrl(QUrl& url, const QString& path, const QString& username,
|
||||
const QString& password)
|
||||
{
|
||||
QUrl danbooruUrl = QUrl(url);
|
||||
danbooruUrl = danbooruUrl.adjusted(QUrl::StripTrailingSlash);
|
||||
danbooruUrl.setPath(danbooruUrl.path() + '/' + path);
|
||||
|
||||
if (!username.isEmpty() && !password.isEmpty()) {
|
||||
danbooruUrl.setUserName(username);
|
||||
danbooruUrl.setPassword(password);
|
||||
}
|
||||
|
||||
return danbooruUrl;
|
||||
if (!username.isEmpty() && !password.isEmpty()) {
|
||||
danbooruUrl.setUserName(username);
|
||||
danbooruUrl.setPassword(password);
|
||||
}
|
||||
|
||||
QList< QVariant > parseDanbooruResult(QByteArray data, QString elementName,
|
||||
bool* result)
|
||||
{
|
||||
return danbooruUrl;
|
||||
}
|
||||
|
||||
QXmlStreamReader reader;
|
||||
reader.addData(data);
|
||||
QUrl requestUrl(QUrl &url, const QString &path, const QString &username,
|
||||
const QString &password, const dictMap ¶meters)
|
||||
{
|
||||
|
||||
QList<QVariant> postData;
|
||||
QUrl danbooruUrl = QUrl(url);
|
||||
danbooruUrl = danbooruUrl.adjusted(QUrl::StripTrailingSlash);
|
||||
danbooruUrl.setPath(danbooruUrl.path() + '/' + path);
|
||||
|
||||
while(!reader.atEnd() && !reader.hasError()) {
|
||||
// If we have parameters, add them
|
||||
|
||||
QXmlStreamReader::TokenType token = reader.readNext();
|
||||
if (!parameters.isEmpty()) {
|
||||
|
||||
if (token == QXmlStreamReader::StartDocument) {
|
||||
continue;
|
||||
}
|
||||
for (auto key : parameters.keys()) {
|
||||
danbooruUrl.addQueryItem(key, parameters.value(key));
|
||||
}
|
||||
|
||||
if(token == QXmlStreamReader::StartElement &&
|
||||
reader.name() == elementName) {
|
||||
}
|
||||
|
||||
QVariantMap values;
|
||||
if (!username.isEmpty() && !password.isEmpty()) {
|
||||
danbooruUrl.setUserName(username);
|
||||
danbooruUrl.setPassword(password);
|
||||
}
|
||||
|
||||
QXmlStreamAttributes attributes = reader.attributes();
|
||||
return danbooruUrl;
|
||||
}
|
||||
|
||||
QUrl requestUrl(QUrl &url, const QString &path, const QString &username,
|
||||
const QString &password)
|
||||
{
|
||||
QUrl danbooruUrl = QUrl(url);
|
||||
danbooruUrl = danbooruUrl.adjusted(QUrl::StripTrailingSlash);
|
||||
danbooruUrl.setPath(danbooruUrl.path() + '/' + path);
|
||||
|
||||
if (!username.isEmpty() && !password.isEmpty()) {
|
||||
danbooruUrl.setUserName(username);
|
||||
danbooruUrl.setPassword(password);
|
||||
}
|
||||
|
||||
return danbooruUrl;
|
||||
}
|
||||
|
||||
QList< QVariant > parseDanbooruResult(QByteArray data, QString elementName,
|
||||
bool *result)
|
||||
{
|
||||
|
||||
QXmlStreamReader reader;
|
||||
reader.addData(data);
|
||||
|
||||
QList<QVariant> postData;
|
||||
|
||||
while (!reader.atEnd() && !reader.hasError()) {
|
||||
|
||||
QXmlStreamReader::TokenType token = reader.readNext();
|
||||
|
||||
if (token == QXmlStreamReader::StartDocument) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (token == QXmlStreamReader::StartElement &&
|
||||
reader.name() == elementName) {
|
||||
|
||||
QVariantMap values;
|
||||
|
||||
QXmlStreamAttributes attributes = reader.attributes();
|
||||
|
||||
// qDebug() << attributes;
|
||||
|
||||
for (auto attribute: attributes) {
|
||||
values.insert(attribute.name().toString(),
|
||||
attribute.value().toString());
|
||||
}
|
||||
|
||||
if (values.isEmpty()) {
|
||||
*result = false;
|
||||
qWarning() << "No results found when parsing XML";
|
||||
return QList<QVariant>();
|
||||
}
|
||||
|
||||
QVariant converted = QVariant(values);
|
||||
|
||||
postData.append(converted);
|
||||
for (auto attribute : attributes) {
|
||||
values.insert(attribute.name().toString(),
|
||||
attribute.value().toString());
|
||||
}
|
||||
|
||||
if (values.isEmpty()) {
|
||||
*result = false;
|
||||
qWarning() << "No results found when parsing XML";
|
||||
return QList<QVariant>();
|
||||
}
|
||||
|
||||
QVariant converted = QVariant(values);
|
||||
|
||||
postData.append(converted);
|
||||
}
|
||||
*result = true;
|
||||
return postData;
|
||||
}
|
||||
*result = true;
|
||||
return postData;
|
||||
}
|
||||
|
||||
QVariant parseDanbooruResult(QByteArray data, bool *result)
|
||||
{
|
||||
|
||||
QJsonDocument parsed = QJsonDocument::fromJson(data);
|
||||
|
||||
if (parsed.isNull()) {
|
||||
return QList<QVariant>();
|
||||
}
|
||||
|
||||
QVariant parseDanbooruResult(QByteArray data, bool* result)
|
||||
{
|
||||
QVariant postData = parsed.toVariant();
|
||||
|
||||
QJsonDocument parsed = QJsonDocument::fromJson(data);
|
||||
*result = true;
|
||||
|
||||
if (parsed.isNull()) {
|
||||
return QList<QVariant>();
|
||||
}
|
||||
return postData;
|
||||
}
|
||||
|
||||
QVariant postData = parsed.toVariant();
|
||||
|
||||
*result = true;
|
||||
|
||||
return postData;
|
||||
}
|
||||
|
||||
|
||||
bool isPostBlacklisted(DanbooruPost *post, QSet<QString> blacklist, DanbooruPost::Ratings maxRating ) {
|
||||
bool isPostBlacklisted(DanbooruPost *post, QSet<QString> blacklist, DanbooruPost::Ratings maxRating)
|
||||
{
|
||||
|
||||
if (post->rating() > maxRating) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (auto tag: post->tags()) {
|
||||
for (auto tag : post->tags()) {
|
||||
|
||||
if (blacklist.contains(tag)) {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,90 +39,88 @@
|
|||
*
|
||||
**/
|
||||
|
||||
namespace Danbooru {
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
typedef QMap<QString,QString> dictMap;
|
||||
typedef QMap<QString, QString> dictMap;
|
||||
|
||||
/** @brief Generate a request URL for a Danbooru board.
|
||||
*
|
||||
* Given an URL and an API path, this function builds a
|
||||
* proper URL which is used for the specific API operation.
|
||||
* The processing follows the "normal" way of encoding URLs.
|
||||
*
|
||||
* @param url The board URL.
|
||||
* @param path The API path of the call to use
|
||||
* @param username The username to supply (optional)
|
||||
* @param password The password to use (optional)
|
||||
* @param parameters A map of key,values representing the parameters
|
||||
* to use.
|
||||
* @param tags The tags to supply (optional).
|
||||
*
|
||||
* @return A constructed URL to be used for a Danbooru API call.
|
||||
* @author Luca Beltrame (lbeltrame@kde.org)
|
||||
*
|
||||
*
|
||||
**/
|
||||
QUrl requestUrl(QUrl& url, const QString& path, const QString& username,
|
||||
const QString& password, const dictMap& parameters,
|
||||
const QStringList& tags);
|
||||
/** @brief Generate a request URL for a Danbooru board.
|
||||
*
|
||||
* Given an URL and an API path, this function builds a
|
||||
* proper URL which is used for the specific API operation.
|
||||
* The processing follows the "normal" way of encoding URLs.
|
||||
*
|
||||
* @param url The board URL.
|
||||
* @param path The API path of the call to use
|
||||
* @param username The username to supply (optional)
|
||||
* @param password The password to use (optional)
|
||||
* @param parameters A map of key,values representing the parameters
|
||||
* to use.
|
||||
* @param tags The tags to supply (optional).
|
||||
*
|
||||
* @return A constructed URL to be used for a Danbooru API call.
|
||||
* @author Luca Beltrame (lbeltrame@kde.org)
|
||||
*
|
||||
*
|
||||
**/
|
||||
QUrl requestUrl(QUrl &url, const QString &path, const QString &username,
|
||||
const QString &password, const dictMap ¶meters,
|
||||
const QStringList &tags);
|
||||
|
||||
/** @brief Generate a request URL for a Danbooru board.
|
||||
*
|
||||
* This is an overloaded function provided for convenience.
|
||||
*
|
||||
*
|
||||
* @param url The board URL.
|
||||
* @param path The API path of the call to use
|
||||
* @param username The username to supply (optional)
|
||||
* @param password The password to use (optional)
|
||||
* @param parameters A map of key,values representing the parameters
|
||||
* to use.
|
||||
*
|
||||
* @return A constructed URL to be used for a Danbooru API call.
|
||||
* @author Luca Beltrame (lbeltrame@kde.org)
|
||||
*
|
||||
*
|
||||
**/
|
||||
QUrl requestUrl(QUrl &url, const QString &path, const QString &username,
|
||||
const QString &password, const dictMap ¶meters);
|
||||
|
||||
/** @brief Generate a request URL for a Danbooru board.
|
||||
*
|
||||
* This is an overloaded function provided for convenience.
|
||||
*
|
||||
*
|
||||
* @param url The board URL.
|
||||
* @param path The API path of the call to use
|
||||
* @param username The username to supply (optional)
|
||||
* @param password The password to use (optional)
|
||||
* @param parameters A map of key,values representing the parameters
|
||||
* to use.
|
||||
*
|
||||
* @return A constructed URL to be used for a Danbooru API call.
|
||||
* @author Luca Beltrame (lbeltrame@kde.org)
|
||||
*
|
||||
*
|
||||
**/
|
||||
QUrl requestUrl(QUrl& url, const QString& path, const QString& username,
|
||||
const QString& password, const dictMap& parameters);
|
||||
/** @brief Generate a request URL for a Danbooru board.
|
||||
*
|
||||
* This is an overloaded function provided for convenience.
|
||||
*
|
||||
* @param url The board URL.
|
||||
* @param path The API path of the call to use
|
||||
* @param username The username to supply (optional)
|
||||
* @param password The password to use (optional)
|
||||
*
|
||||
* @return A constructed URL to be used for a Danbooru API call.
|
||||
* @author Luca Beltrame (lbeltrame@kde.org)
|
||||
*
|
||||
*
|
||||
**/
|
||||
QUrl requestUrl(QUrl &url, const QString &path, const QString &username,
|
||||
const QString &password);
|
||||
|
||||
QList<QVariant> parseDanbooruResult(QByteArray data, QString xlmElement,
|
||||
bool *result);
|
||||
QVariant parseDanbooruResult(QByteArray data, bool *result);
|
||||
|
||||
/** @brief Generate a request URL for a Danbooru board.
|
||||
*
|
||||
* This is an overloaded function provided for convenience.
|
||||
*
|
||||
* @param url The board URL.
|
||||
* @param path The API path of the call to use
|
||||
* @param username The username to supply (optional)
|
||||
* @param password The password to use (optional)
|
||||
*
|
||||
* @return A constructed URL to be used for a Danbooru API call.
|
||||
* @author Luca Beltrame (lbeltrame@kde.org)
|
||||
*
|
||||
*
|
||||
**/
|
||||
QUrl requestUrl(QUrl& url, const QString& path, const QString& username,
|
||||
const QString& password);
|
||||
|
||||
|
||||
QList<QVariant> parseDanbooruResult(QByteArray data, QString xlmElement,
|
||||
bool* result);
|
||||
QVariant parseDanbooruResult(QByteArray data, bool* result);
|
||||
|
||||
/**
|
||||
* @brief Check if a post can be allowed.
|
||||
*
|
||||
* This convenience function checks if a DanbooruPost is not allowed, either because it
|
||||
* contains blacklisted tags, or because it has a higher rating than allowed.
|
||||
*
|
||||
* @param post A DanbooruPost pointer.
|
||||
* @param blacklist A QSet containing unwanted tag names as QStrings.
|
||||
* @param maxRating The maximum allowed rating expressed as a DanbooruPost::Ratings flag.
|
||||
* @return true if the post is unwanted, false otherwise.
|
||||
* @author Luca Beltrame (lbeltrame@kde.org)
|
||||
*/
|
||||
bool isPostBlacklisted(DanbooruPost *post, QSet<QString> blacklist, DanbooruPost::Ratings maxRating );
|
||||
/**
|
||||
* @brief Check if a post can be allowed.
|
||||
*
|
||||
* This convenience function checks if a DanbooruPost is not allowed, either because it
|
||||
* contains blacklisted tags, or because it has a higher rating than allowed.
|
||||
*
|
||||
* @param post A DanbooruPost pointer.
|
||||
* @param blacklist A QSet containing unwanted tag names as QStrings.
|
||||
* @param maxRating The maximum allowed rating expressed as a DanbooruPost::Ratings flag.
|
||||
* @return true if the post is unwanted, false otherwise.
|
||||
* @author Luca Beltrame (lbeltrame@kde.org)
|
||||
*/
|
||||
bool isPostBlacklisted(DanbooruPost *post, QSet<QString> blacklist, DanbooruPost::Ratings maxRating);
|
||||
|
||||
}
|
||||
#endif // UTILS_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue