File indexing completed on 2024-12-29 04:49:58
0001 /* 0002 SPDX-FileCopyrightText: 2017-2021 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "kitinerary_export.h" 0010 0011 #include <QExplicitlySharedDataPointer> 0012 #include <qobjectdefs.h> 0013 0014 class QJsonObject; 0015 class QJSValue; 0016 0017 namespace KItinerary { 0018 0019 class ExtractorDocumentNode; 0020 class ExtractorFilterPrivate; 0021 0022 /** Determines whether an extractor is applicable to a given email. */ 0023 class KITINERARY_EXPORT ExtractorFilter 0024 { 0025 Q_GADGET 0026 public: 0027 ExtractorFilter(); 0028 ~ExtractorFilter(); 0029 ExtractorFilter(const ExtractorFilter&); 0030 ExtractorFilter(ExtractorFilter&&) noexcept; 0031 ExtractorFilter& operator=(const ExtractorFilter&); 0032 ExtractorFilter& operator=(ExtractorFilter&&); 0033 0034 /** MIME type of the document part this filter can match. */ 0035 QString mimeType() const; 0036 /** The field to filter on. */ 0037 QString fieldName() const; 0038 /** Check if @p data matches this filter. */ 0039 bool matches(const QString &data) const; 0040 /** Pattern to match field value against. */ 0041 QString pattern() const; 0042 0043 /** Specifies which document nodes should match this filter, relative to the one being extracted. */ 0044 enum Scope { 0045 Current, ///< match the node being extracted 0046 Parent, ///< match the direct parent node 0047 Children, ///< match the direct child nodes 0048 Ancestors, ///< match any direct or indirect parent nodes 0049 Descendants, ///< match any direct or indirect child nodes 0050 }; 0051 Q_ENUM(Scope) 0052 /** Evaluation scope of this filter, in relation to the node being extracted. */ 0053 Scope scope() const; 0054 0055 /** Checks whether this filter applies to @p node. */ 0056 bool matches(const ExtractorDocumentNode &node) const; 0057 0058 /** Checks whether this filter applies to @p node. 0059 * Unlike matches() this returns all nodes triggering this filter. 0060 * This matters in particular for matching child nodes, where multiple 0061 * ones can match the filter. 0062 */ 0063 void allMatches(const ExtractorDocumentNode &node, std::vector<ExtractorDocumentNode> &matches) const; 0064 0065 ///@cond internal 0066 /** Load filter from @p obj. */ 0067 bool load(const QJsonObject &obj); 0068 /** Serialize filter to a JSON object. */ 0069 QJsonObject toJson() const; 0070 /** Create a filter from a JS object value. */ 0071 static ExtractorFilter fromJSValue(const QJSValue &js); 0072 0073 void setMimeType(const QString &mimeType); 0074 void setFieldName(const QString &fieldName); 0075 void setPattern(const QString &pattern); 0076 void setScope(Scope scope); 0077 ///@endcond 0078 0079 private: 0080 QExplicitlySharedDataPointer<ExtractorFilterPrivate> d; 0081 }; 0082 0083 } 0084