File indexing completed on 2024-12-29 04:50:01
0001 /* 0002 SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 #ifndef KITINERARY_JSAPI_EXTRACTORENGINE_H 0007 #define KITINERARY_JSAPI_EXTRACTORENGINE_H 0008 0009 #include <KItinerary/ExtractorDocumentNode> 0010 #include <KItinerary/ExtractorEngine> 0011 0012 namespace KItinerary { 0013 0014 /** JavaScript API available to extractor scripts. */ 0015 namespace JsApi { 0016 0017 /** API to access the extractor engine for JS extractor scripts. */ 0018 class ExtractorEngine : public QObject 0019 { 0020 Q_OBJECT 0021 public: 0022 ///@cond internal 0023 explicit ExtractorEngine(QObject *parent = nullptr); 0024 ~ExtractorEngine(); 0025 0026 void setEngine(KItinerary::ExtractorEngine *engine); 0027 void setCurrentNode(const ExtractorDocumentNode &node); 0028 void clear(); 0029 ///@endcond 0030 0031 /** Run the extractor on @p data. 0032 * Use this if the data to extract needs to be decoded by an extractor script first 0033 * and is available as raw byte array. 0034 * You do not need to call this for document parts that the extractor recognizes itself. 0035 * 0036 * A new document node for @p data is added below the node currently processed, 0037 * and that node is returned. 0038 * 0039 * @see KItinerary::ExtractorEngine 0040 */ 0041 Q_INVOKABLE KItinerary::ExtractorDocumentNode extract(const QByteArray &data); 0042 /** Run the extractor on @p content of type @p mimeType. 0043 * Use this if the data to extract needs to be decoded by an extractor script first 0044 * and is available already in decoded form in a suitable data type. 0045 * You do not need to call this for document parts that the extractor recognizes itself. 0046 * 0047 * A new document node for @p data is added below the node currently processed, 0048 * and that node is returned. 0049 * 0050 * @see KItinerary::ExtractorEngine 0051 */ 0052 Q_INVOKABLE KItinerary::ExtractorDocumentNode extract(const QVariant &content, const QString &mimeType); 0053 0054 /** Run the generic price information extractor to @p text and apply the found 0055 * price value and currency to @p result, if any. 0056 * @param result Can be a single object or and array. 0057 */ 0058 Q_INVOKABLE void extractPrice(const QString &text, QJSValue result) const; 0059 0060 private: 0061 KItinerary::ExtractorEngine *m_engine = nullptr; 0062 KItinerary::ExtractorDocumentNode m_currentNode; 0063 int m_recursionDepth = 0; 0064 }; 0065 0066 } 0067 } 0068 0069 #endif // KITINERARY_JSAPI_EXTRACTORENGINE_H