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