[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.
This commit is contained in:
		
					parent
					
						
							
								d99fd19d22
							
						
					
				
			
			
				commit
				
					
						66cd4f46d1
					
				
			
		
					 2 changed files with 32 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -174,4 +174,21 @@ namespace Danbooru {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool isPostBlacklisted(DanbooruPost *post, QSet<QString> 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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,6 +23,8 @@
 | 
			
		|||
#ifndef UTILS_H
 | 
			
		||||
#define UTILS_H
 | 
			
		||||
 | 
			
		||||
#include "danboorupost.h"
 | 
			
		||||
 | 
			
		||||
// Qt
 | 
			
		||||
 | 
			
		||||
#include <QtCore/QStringList>
 | 
			
		||||
| 
						 | 
				
			
			@ -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<QString> blacklist, DanbooruPost::Ratings maxRating );
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
#endif // UTILS_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue