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 | | ||||
23 | namespace KNSCore { | ||||
24 | | ||||
25 | /** | ||||
26 | * @brief Apply simple filtering logic to a list of tags | ||||
27 | * | ||||
28 | * == Examples of specifying tag filters == | ||||
29 | * Value for tag "tagname" must be exactly "tagdata": | ||||
30 | * tagname==tagdata | ||||
31 | * | ||||
32 | * Value for tag "tagname" must be different from "tagdata": | ||||
33 | * tagname!=tagdata | ||||
34 | * | ||||
35 | * == Tag filter list == | ||||
36 | * A tag filter list is a string list of filters as shown above, and a combination | ||||
37 | * of which might look like: | ||||
38 | * | ||||
39 | * - ghns_exclude!=1 | ||||
40 | * - data##mimetype==application/cbr+zip | ||||
41 | * - data##mimetype==application/cbr+rar | ||||
42 | * | ||||
43 | * which would filter out anything which has ghns_exclude set to 1, and | ||||
44 | * anything where the value of data##mimetype does not equal either | ||||
45 | * "application/cbr+zip" or "application/cbr+rar". | ||||
46 | * Notice in particular the two data##mimetype entries. Use this | ||||
47 | * for when a tag may have multiple values. | ||||
48 | * | ||||
49 | * The value does not current suppport wildcards. The list should be considered | ||||
50 | * a binary AND operation (that is, all filter entries must match for the data | ||||
51 | * entry to be included in the return data) | ||||
52 | */ | ||||
53 | class TagsFilterChecker { | ||||
54 | public: | ||||
55 | /** | ||||
56 | * Constructs an instance of the tags filter checker, prepopulated | ||||
57 | * with the list of tag filters in the tagFilter parameter. | ||||
58 | * | ||||
59 | * @param tagFilter The list of tag filters | ||||
60 | */ | ||||
61 | TagsFilterChecker(const QStringList& tagFilter); | ||||
62 | ~TagsFilterChecker(); | ||||
63 | | ||||
64 | /** | ||||
65 | * Check whether the filter list accepts the passed list of tags | ||||
66 | * | ||||
67 | * @param tags A list of tags in the form of key=value strings | ||||
68 | * @return True if the filter accepts the list, false if not | ||||
69 | */ | ||||
70 | bool filterAccepts(const QStringList& tags); | ||||
71 | | ||||
72 | private: | ||||
73 | class Private; | ||||
74 | Private *d; | ||||
75 | }; | ||||
76 | | ||||
77 | } | ||||
78 | | ||||
79 | #endif//KNSCORE_TAGSFILTERCHECKER_H |