Coding style
This commit is contained in:
parent
1de6786a9e
commit
bcecd30031
3 changed files with 548 additions and 548 deletions
|
@ -79,8 +79,6 @@ namespace Danbooru {
|
|||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Ratings for a Danbooru item
|
||||
*
|
||||
|
|
|
@ -40,18 +40,19 @@
|
|||
#include "danboorutag.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace Danbooru {
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
using KIO::StoredTransferJob;
|
||||
using KIO::StoredTransferJob;
|
||||
|
||||
const QString DanbooruService::POST_URL ="post/index.json" ;
|
||||
const QString DanbooruService::TAG_URL = "tag/index.xml";
|
||||
const QString DanbooruService::POOL_URL = "pool/index.json";
|
||||
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";
|
||||
const QString DanbooruService::POST_URL = "post/index.json" ;
|
||||
const QString DanbooruService::TAG_URL = "tag/index.xml";
|
||||
const QString DanbooruService::POOL_URL = "pool/index.json";
|
||||
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(KUrl& boardUrl, QString username,
|
||||
DanbooruService::DanbooruService(KUrl& boardUrl, QString username,
|
||||
QString password, KImageCache* cache,
|
||||
QObject* parent):
|
||||
QObject(parent),
|
||||
|
@ -61,21 +62,21 @@ namespace Danbooru {
|
|||
m_maxRating(Safe),
|
||||
m_currentPosts(0),
|
||||
m_cache(cache)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
DanbooruService::~DanbooruService()
|
||||
{
|
||||
DanbooruService::~DanbooruService()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DanbooruService::getPostList(int page, QStringList tags, int limit)
|
||||
{
|
||||
void DanbooruService::getPostList(int page, QStringList tags, int limit)
|
||||
{
|
||||
|
||||
// We can't fetch more than 100 items, API limitation
|
||||
|
||||
limit = limit > 100 ? 100: limit;
|
||||
limit = limit > 100 ? 100 : limit;
|
||||
|
||||
QMap<QString, QString> parameters;
|
||||
|
||||
|
@ -96,10 +97,10 @@ namespace Danbooru {
|
|||
connect(job, SIGNAL(result(KJob*)), this,
|
||||
SLOT(processPostList(KJob*)));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void DanbooruService::getTagList(int limit, QString name)
|
||||
{
|
||||
void DanbooruService::getTagList(int limit, QString name)
|
||||
{
|
||||
QMap<QString, QString> parameters;
|
||||
parameters.insert("limit", QString::number(limit));
|
||||
|
||||
|
@ -116,10 +117,10 @@ namespace Danbooru {
|
|||
KIO::HideProgressInfo);
|
||||
|
||||
connect(job, SIGNAL(result(KJob*)), this, SLOT(processTagList(KJob*)));
|
||||
}
|
||||
}
|
||||
|
||||
void DanbooruService::getPool(int poolId, int page)
|
||||
{
|
||||
void DanbooruService::getPool(int poolId, int page)
|
||||
{
|
||||
|
||||
QMap<QString, QString> parameters;
|
||||
|
||||
|
@ -146,10 +147,10 @@ namespace Danbooru {
|
|||
connect(job, SIGNAL(result(KJob*)), this,
|
||||
SLOT(processPostList(KJob*)));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void DanbooruService::getPoolList(int page)
|
||||
{
|
||||
void DanbooruService::getPoolList(int page)
|
||||
{
|
||||
|
||||
KUrl danbooruUrl;
|
||||
|
||||
|
@ -173,14 +174,14 @@ namespace Danbooru {
|
|||
connect(job, SIGNAL(result(KJob*)), this,
|
||||
SLOT(processPoolList(KJob*)));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void DanbooruService::getRelatedTags(const QStringList& tags,
|
||||
void DanbooruService::getRelatedTags(const QStringList& tags,
|
||||
Danbooru::TagType tagType)
|
||||
{
|
||||
{
|
||||
|
||||
QString type;
|
||||
switch(tagType) {
|
||||
switch (tagType) {
|
||||
case Danbooru::General:
|
||||
type = "general";
|
||||
break;
|
||||
|
@ -202,7 +203,7 @@ namespace Danbooru {
|
|||
parameters.insert("type", type);
|
||||
|
||||
KUrl danbooruUrl = requestUrl(m_url, RELATED_TAG_URL, m_username,
|
||||
m_password, parameters, tags );
|
||||
m_password, parameters, tags);
|
||||
|
||||
kDebug() << "Final constructed related tag URL" << danbooruUrl.url();
|
||||
|
||||
|
@ -214,27 +215,27 @@ namespace Danbooru {
|
|||
connect(job, SIGNAL(result(KJob*)), this,
|
||||
SLOT(processRelatedTagList(KJob*)));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Getters / setters
|
||||
// Getters / setters
|
||||
|
||||
void DanbooruService::setBlacklist(const QSet< QString >& blacklist)
|
||||
{
|
||||
void DanbooruService::setBlacklist(const QSet< QString >& blacklist)
|
||||
{
|
||||
|
||||
if (!blacklist.isEmpty()) {
|
||||
m_blacklist = blacklist;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const QSet< QString > DanbooruService::blacklist() const
|
||||
{
|
||||
const QSet< QString > DanbooruService::blacklist() const
|
||||
{
|
||||
return m_blacklist;
|
||||
}
|
||||
}
|
||||
|
||||
const QStringList DanbooruService::allowedRatings() const
|
||||
{
|
||||
const QStringList DanbooruService::allowedRatings() const
|
||||
{
|
||||
QStringList ratings;
|
||||
|
||||
if (m_maxRating.testFlag(Safe)) {
|
||||
|
@ -251,10 +252,10 @@ namespace Danbooru {
|
|||
|
||||
return ratings;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void DanbooruService::setMaximumAllowedRating(const Danbooru::Ratings& rating)
|
||||
{
|
||||
void DanbooruService::setMaximumAllowedRating(const Danbooru::Ratings& rating)
|
||||
{
|
||||
Ratings flags;
|
||||
|
||||
switch (rating) {
|
||||
|
@ -271,19 +272,19 @@ namespace Danbooru {
|
|||
|
||||
m_maxRating = flags;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
const Ratings DanbooruService::maximumAllowedRating() const
|
||||
{
|
||||
const Ratings DanbooruService::maximumAllowedRating() const
|
||||
{
|
||||
|
||||
return m_maxRating;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Slots
|
||||
// Slots
|
||||
|
||||
void DanbooruService::processPostList(KJob* job)
|
||||
{
|
||||
void DanbooruService::processPostList(KJob* job)
|
||||
{
|
||||
|
||||
//kDebug() << "Got post data OK";
|
||||
|
||||
|
@ -325,7 +326,7 @@ namespace Danbooru {
|
|||
|
||||
m_currentPosts = postList.length();
|
||||
|
||||
for (auto element: postList) {
|
||||
for (auto element : postList) {
|
||||
|
||||
QVariantMap map = element.toMap();
|
||||
|
||||
|
@ -408,10 +409,10 @@ namespace Danbooru {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void DanbooruService::processTagList(KJob* job)
|
||||
{
|
||||
void DanbooruService::processTagList(KJob* job)
|
||||
{
|
||||
|
||||
if (job->error()) {
|
||||
Q_EMIT(downloadError(job->errorString()));
|
||||
|
@ -438,16 +439,16 @@ namespace Danbooru {
|
|||
return;
|
||||
}
|
||||
|
||||
for (auto element: tagList) {
|
||||
for (auto element : tagList) {
|
||||
QVariantMap map = element.toMap();
|
||||
DanbooruTag* tag = new DanbooruTag(map);
|
||||
Q_EMIT(tagDownloaded(tag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DanbooruService::processRelatedTagList(KJob* job)
|
||||
{
|
||||
void DanbooruService::processRelatedTagList(KJob* job)
|
||||
{
|
||||
if (job->error()) {
|
||||
Q_EMIT(downloadError(job->errorString()));
|
||||
return;
|
||||
|
@ -478,7 +479,7 @@ namespace Danbooru {
|
|||
// we call getTagList. Unfortunately Danbooru doesn't have a method to
|
||||
// fetch all tags in batch, so this is done one by one.
|
||||
|
||||
for (iter=tagList.constBegin(); iter!=tagList.constEnd(); ++iter) {
|
||||
for (iter = tagList.constBegin(); iter != tagList.constEnd(); ++iter) {
|
||||
|
||||
QList<QVariant> tags = iter.value().toList();
|
||||
|
||||
|
@ -486,7 +487,7 @@ namespace Danbooru {
|
|||
continue;
|
||||
}
|
||||
|
||||
for (auto tag: tags) {
|
||||
for (auto tag : tags) {
|
||||
// We get the first element in the list, the second is
|
||||
// the ID which is useless (no API methods in Danbooru)
|
||||
QString tagName = tag.toList()[0].toString();
|
||||
|
@ -494,10 +495,10 @@ namespace Danbooru {
|
|||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DanbooruService::processPoolList(KJob* job)
|
||||
{
|
||||
void DanbooruService::processPoolList(KJob* job)
|
||||
{
|
||||
|
||||
|
||||
if (job->error()) {
|
||||
|
@ -523,7 +524,7 @@ namespace Danbooru {
|
|||
return;
|
||||
}
|
||||
|
||||
for (auto element: poolList) {
|
||||
for (auto element : poolList) {
|
||||
QVariantMap map = element.toMap();
|
||||
|
||||
DanbooruPool* pool = new DanbooruPool(map);
|
||||
|
@ -533,15 +534,15 @@ namespace Danbooru {
|
|||
kDebug() << "Pool download finished!";
|
||||
Q_EMIT(poolDownloadFinished());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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()) {
|
||||
Q_EMIT(downloadError(job->errorString()));
|
||||
|
@ -584,6 +585,6 @@ namespace Danbooru {
|
|||
Q_EMIT(postDownloadFinished());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Danbooru
|
||||
|
|
|
@ -22,11 +22,12 @@
|
|||
|
||||
#include "danboorutag.h"
|
||||
|
||||
namespace Danbooru {
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
DanbooruTag::DanbooruTag(const QVariantMap& postData, QObject* parent):
|
||||
DanbooruTag::DanbooruTag(const QVariantMap& postData, QObject* parent):
|
||||
QObject(parent)
|
||||
{
|
||||
{
|
||||
m_id = postData.value("id").toInt();
|
||||
m_name = postData.value("name").toString();
|
||||
m_count = postData.value("count").toInt();
|
||||
|
@ -54,32 +55,32 @@ namespace Danbooru {
|
|||
m_tagType = Unknown;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int DanbooruTag::id() const
|
||||
{
|
||||
int DanbooruTag::id() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
}
|
||||
|
||||
int DanbooruTag::count() const
|
||||
{
|
||||
int DanbooruTag::count() const
|
||||
{
|
||||
return m_count;
|
||||
}
|
||||
}
|
||||
|
||||
const QString DanbooruTag::name() const
|
||||
{
|
||||
const QString DanbooruTag::name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
}
|
||||
|
||||
bool DanbooruTag::ambiguous() const
|
||||
{
|
||||
bool DanbooruTag::ambiguous() const
|
||||
{
|
||||
return m_ambiguous;
|
||||
}
|
||||
}
|
||||
|
||||
TagType DanbooruTag::type() const
|
||||
{
|
||||
TagType DanbooruTag::type() const
|
||||
{
|
||||
return m_tagType;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}; // namespace Danbooru
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue