| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2018 Dan Leinir Turthra Jensen <admin@leinir.dk> |
| 3 | |
| 4 | SPDX-License-Identifier: LGPL-2.1-or-later |
| 5 | */ |
| 6 | |
| 7 | #ifndef KNSCORE_TAGSFILTERCHECKER_H |
| 8 | #define KNSCORE_TAGSFILTERCHECKER_H |
| 9 | |
| 10 | #include "knewstuffcore_export.h" |
| 11 | #include <QStringList> |
| 12 | |
| 13 | #include <memory> |
| 14 | |
| 15 | namespace KNSCore |
| 16 | { |
| 17 | class TagsFilterCheckerPrivate; |
| 18 | /*! |
| 19 | * \class KNSCore::TagsFilterChecker |
| 20 | * \inmodule KNewStuffCore |
| 21 | * |
| 22 | * \brief Apply simple filtering logic to a list of tags. |
| 23 | * |
| 24 | * == Examples of specifying tag filters == |
| 25 | * Value for tag "tagname" must be exactly "tagdata": |
| 26 | * tagname==tagdata |
| 27 | * |
| 28 | * Value for tag "tagname" must be different from "tagdata": |
| 29 | * tagname!=tagdata |
| 30 | * |
| 31 | * == Tag filter list == |
| 32 | * A tag filter list is a string list of filters as shown above, and a combination |
| 33 | * of which might look like: |
| 34 | * |
| 35 | * - ghns_excluded!=1 |
| 36 | * - data##mimetype==application/cbr+zip |
| 37 | * - data##mimetype==application/cbr+rar |
| 38 | * |
| 39 | * which would filter out anything which has ghns_excluded set to 1, and |
| 40 | * anything where the value of data##mimetype does not equal either |
| 41 | * "application/cbr+zip" or "application/cbr+rar". |
| 42 | * Notice in particular the two data##mimetype entries. Use this |
| 43 | * for when a tag may have multiple values. |
| 44 | * |
| 45 | * The value does not current support wildcards. The list should be considered |
| 46 | * a binary AND operation (that is, all filter entries must match for the data |
| 47 | * entry to be included in the return data) |
| 48 | * \since 5.51 |
| 49 | */ |
| 50 | // TODO KF7: privatize this class. it's not used by the outside |
| 51 | class KNEWSTUFFCORE_EXPORT TagsFilterChecker |
| 52 | { |
| 53 | public: |
| 54 | /*! |
| 55 | * Constructs an instance of the tags filter checker, prepopulated |
| 56 | * with the list of tag filters in the tagFilter parameter. |
| 57 | * |
| 58 | * \a tagFilter The list of tag filters |
| 59 | * |
| 60 | * \since 5.51 |
| 61 | */ |
| 62 | explicit TagsFilterChecker(const QStringList &tagFilter); |
| 63 | ~TagsFilterChecker(); |
| 64 | |
| 65 | TagsFilterChecker(const TagsFilterChecker &) = delete; |
| 66 | TagsFilterChecker &operator=(const TagsFilterChecker &) = delete; |
| 67 | |
| 68 | /*! |
| 69 | * Check whether the filter list accepts the passed list of tags |
| 70 | * |
| 71 | * \a tags A list of tags in the form of key=value strings |
| 72 | * |
| 73 | * Returns True if the filter accepts the list, false if not |
| 74 | * \since 5.51 |
| 75 | */ |
| 76 | bool filterAccepts(const QStringList &tags); |
| 77 | |
| 78 | private: |
| 79 | const std::unique_ptr<TagsFilterCheckerPrivate> d; |
| 80 | }; |
| 81 | |
| 82 | } |
| 83 | |
| 84 | #endif // KNSCORE_TAGSFILTERCHECKER_H |
| 85 | |