File indexing completed on 2024-04-28 15:28:59
0001 /* 0002 SPDX-FileCopyrightText: 2018 Dan Leinir Turthra Jensen <admin@leinir.dk> 0003 0004 SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #ifndef KNSCORE_TAGSFILTERCHECKER_H 0008 #define KNSCORE_TAGSFILTERCHECKER_H 0009 0010 #include "knewstuffcore_export.h" 0011 #include <QStringList> 0012 0013 #include <memory> 0014 0015 namespace KNSCore 0016 { 0017 class TagsFilterCheckerPrivate; 0018 /** 0019 * @brief Apply simple filtering logic to a list of tags 0020 * 0021 * == Examples of specifying tag filters == 0022 * Value for tag "tagname" must be exactly "tagdata": 0023 * tagname==tagdata 0024 * 0025 * Value for tag "tagname" must be different from "tagdata": 0026 * tagname!=tagdata 0027 * 0028 * == Tag filter list == 0029 * A tag filter list is a string list of filters as shown above, and a combination 0030 * of which might look like: 0031 * 0032 * - ghns_excluded!=1 0033 * - data##mimetype==application/cbr+zip 0034 * - data##mimetype==application/cbr+rar 0035 * 0036 * which would filter out anything which has ghns_excluded set to 1, and 0037 * anything where the value of data##mimetype does not equal either 0038 * "application/cbr+zip" or "application/cbr+rar". 0039 * Notice in particular the two data##mimetype entries. Use this 0040 * for when a tag may have multiple values. 0041 * 0042 * The value does not current support wildcards. The list should be considered 0043 * a binary AND operation (that is, all filter entries must match for the data 0044 * entry to be included in the return data) 0045 * @since 5.51 0046 */ 0047 class KNEWSTUFFCORE_EXPORT TagsFilterChecker 0048 { 0049 public: 0050 /** 0051 * Constructs an instance of the tags filter checker, prepopulated 0052 * with the list of tag filters in the tagFilter parameter. 0053 * 0054 * @param tagFilter The list of tag filters 0055 * @since 5.51 0056 */ 0057 TagsFilterChecker(const QStringList &tagFilter); 0058 ~TagsFilterChecker(); 0059 0060 TagsFilterChecker(const TagsFilterChecker &) = delete; 0061 TagsFilterChecker &operator=(const TagsFilterChecker &) = delete; 0062 0063 /** 0064 * Check whether the filter list accepts the passed list of tags 0065 * 0066 * @param tags A list of tags in the form of key=value strings 0067 * @return True if the filter accepts the list, false if not 0068 * @since 5.51 0069 */ 0070 bool filterAccepts(const QStringList &tags); 0071 0072 private: 0073 const std::unique_ptr<TagsFilterCheckerPrivate> d; 0074 }; 0075 0076 } 0077 0078 #endif // KNSCORE_TAGSFILTERCHECKER_H