Changeset View
Changeset View
Standalone View
Standalone View
src/core/tagsfilterchecker.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright (c) 2018 Dan Leinir Turthra Jensen <admin@leinir.dk> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Lesser General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2.1 of the License, or (at your option) any later version. | ||||
8 | | ||||
9 | This library is distributed in the hope that it will be useful, | ||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | Lesser General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU Lesser General Public | ||||
15 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
16 | */ | ||||
17 | | ||||
18 | #ifndef KNSCORE_TAGSFILTERCHECKER_H | ||||
19 | #define KNSCORE_TAGSFILTERCHECKER_H | ||||
20 | | ||||
21 | #include <QStringList> | ||||
22 | #include "knewstuffcore_export.h" | ||||
23 | | ||||
24 | namespace KNSCore { | ||||
25 | | ||||
26 | /** | ||||
27 | * @brief Apply simple filtering logic to a list of tags | ||||
28 | * | ||||
29 | * == Examples of specifying tag filters == | ||||
30 | * Value for tag "tagname" must be exactly "tagdata": | ||||
31 | * tagname==tagdata | ||||
32 | * | ||||
33 | * Value for tag "tagname" must be different from "tagdata": | ||||
34 | * tagname!=tagdata | ||||
35 | * | ||||
36 | * == Tag filter list == | ||||
37 | * A tag filter list is a string list of filters as shown above, and a combination | ||||
38 | * of which might look like: | ||||
39 | * | ||||
40 | * - ghns_exclude!=1 | ||||
41 | * - data##mimetype==application/cbr+zip | ||||
42 | * - data##mimetype==application/cbr+rar | ||||
43 | * | ||||
44 | * which would filter out anything which has ghns_exclude set to 1, and | ||||
45 | * anything where the value of data##mimetype does not equal either | ||||
46 | * "application/cbr+zip" or "application/cbr+rar". | ||||
47 | * Notice in particular the two data##mimetype entries. Use this | ||||
48 | * for when a tag may have multiple values. | ||||
49 | * | ||||
50 | * The value does not current suppport wildcards. The list should be considered | ||||
51 | * a binary AND operation (that is, all filter entries must match for the data | ||||
52 | * entry to be included in the return data) | ||||
53 | * @since 5.51 | ||||
54 | */ | ||||
55 | class KNEWSTUFFCORE_EXPORT TagsFilterChecker { | ||||
56 | public: | ||||
57 | /** | ||||
58 | * Constructs an instance of the tags filter checker, prepopulated | ||||
59 | * with the list of tag filters in the tagFilter parameter. | ||||
60 | * | ||||
61 | * @param tagFilter The list of tag filters | ||||
62 | * @since 5.51 | ||||
63 | */ | ||||
64 | TagsFilterChecker(const QStringList &tagFilter); | ||||
65 | ~TagsFilterChecker(); | ||||
66 | | ||||
67 | /** | ||||
68 | * Check whether the filter list accepts the passed list of tags | ||||
69 | * | ||||
70 | * @param tags A list of tags in the form of key=value strings | ||||
71 | * @return True if the filter accepts the list, false if not | ||||
72 | * @since 5.51 | ||||
73 | */ | ||||
74 | bool filterAccepts(const QStringList &tags); | ||||
75 | | ||||
76 | private: | ||||
77 | class Private; | ||||
78 | Private *d; | ||||
79 | }; | ||||
80 | | ||||
81 | } | ||||
82 | | ||||
83 | #endif//KNSCORE_TAGSFILTERCHECKER_H |