From 66cd4f46d1743e95a78fe704a08b61c71e89e232 Mon Sep 17 00:00:00 2001 From: Luca Beltrame Date: Sat, 4 Oct 2014 15:35:03 +0200 Subject: [PATCH] [libdanbooru/utils] Add a convenience function to check if a post is unwanted This is mainly done to reduce the complexity of the post handing in DanbooruService. --- src/libdanbooru/utils.cpp | 17 +++++++++++++++++ src/libdanbooru/utils.h | 15 +++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/libdanbooru/utils.cpp b/src/libdanbooru/utils.cpp index 7c042ca..2c75804 100644 --- a/src/libdanbooru/utils.cpp +++ b/src/libdanbooru/utils.cpp @@ -174,4 +174,21 @@ namespace Danbooru { } +bool isPostBlacklisted(DanbooruPost *post, QSet blacklist, DanbooruPost::Ratings maxRating ) { + + if (post->rating() > maxRating) { + return true; + } + + for (auto tag: post->tags()) { + + if (blacklist.contains(tag)) { + return true; + } + } + + return false; + +} + } // namespace Danbooru diff --git a/src/libdanbooru/utils.h b/src/libdanbooru/utils.h index 67f4c35..ebe5ce4 100644 --- a/src/libdanbooru/utils.h +++ b/src/libdanbooru/utils.h @@ -23,6 +23,8 @@ #ifndef UTILS_H #define UTILS_H +#include "danboorupost.h" + // Qt #include @@ -108,6 +110,19 @@ namespace Danbooru { 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 blacklist, DanbooruPost::Ratings maxRating ); } #endif // UTILS_H