File indexing completed on 2025-02-16 13:03:41
0001 /* 0002 SPDX-FileCopyrightText: 2013 Vishesh Handa <me@vhanda.in> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #ifndef _KFILEMETADATA_EXTRACTIONRESULT_H 0008 #define _KFILEMETADATA_EXTRACTIONRESULT_H 0009 0010 #include <QString> 0011 #include <QVariant> 0012 0013 #include <memory> 0014 0015 #include "kfilemetadata_export.h" 0016 #include "embeddedimagedata.h" 0017 #include "properties.h" 0018 #include "types.h" 0019 0020 namespace KFileMetaData { 0021 class ExtractionResultPrivate; 0022 /** 0023 * \class ExtractionResult extractionresult.h <KFileMetaData/ExtractionResult> 0024 * 0025 * \brief The ExtractionResult class is where all the data extracted by 0026 * the indexer is saved. This class acts as a base class which should be 0027 * derived from and then passed to the relevant plugins. 0028 * 0029 * The derived class needs to implement 3 pure virtual functions through 0030 * which it receives the extracted data. 0031 * 0032 * \author Vishesh Handa <me@vhanda.in> 0033 */ 0034 class KFILEMETADATA_EXPORT ExtractionResult 0035 { 0036 public: 0037 /** 0038 * @see Flags 0039 */ 0040 enum Flag { 0041 ExtractNothing = 0, 0042 ExtractMetaData = 1, 0043 ExtractPlainText = 2, 0044 ExtractImageData = 4, ///< @since 5.76 0045 #if KFILEMETADATA_ENABLE_DEPRECATED_SINCE(5, 76) 0046 /// @deprecated since 5.76, specify explicitly 0047 ExtractEverything KFILEMETADATA_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 5, 76, "Specify flags explicitly") = (ExtractMetaData | ExtractPlainText) 0048 #endif 0049 }; 0050 /** 0051 * Stores a combination of #Flag values. 0052 */ 0053 Q_DECLARE_FLAGS(Flags, Flag) 0054 0055 /** 0056 * Create an ExtractionResult which can be passed be to Extractors. The 0057 * extractors use the \p url, \p mimetype and \p flags in order to determine 0058 * which file the data should be extracted from and which data should 0059 * be extracted. 0060 */ 0061 ExtractionResult(const QString& url, const QString& mimetype = QString(), const Flags& flags = Flags{ExtractPlainText | ExtractMetaData}); 0062 ExtractionResult(const ExtractionResult& rhs); 0063 virtual ~ExtractionResult(); 0064 0065 /** 0066 * The input url which the plugins will use to locate the file 0067 */ 0068 QString inputUrl() const; 0069 0070 /** 0071 * The input mimetype. This mimetype should correspond with the 0072 * mimetypes supported with the relevant plugin when it is being 0073 * passed to the Extractor, or be a subtype thereof. 0074 * 0075 * \sa ExtractorCollection::fetchExtractors 0076 * \sa ExtractorPlugin::supportedMimeType 0077 */ 0078 QString inputMimetype() const; 0079 0080 /** 0081 * The flags which the extraction plugin should considering following 0082 * when extracting metadata from the file 0083 */ 0084 Flags inputFlags() const; 0085 0086 /** 0087 * This function is called by plugins when they wish for some plain 0088 * text to be indexed without any property. This generally corresponds 0089 * to the text content in a file 0090 */ 0091 virtual void append(const QString& text) = 0; 0092 0093 /** 0094 * This function is called by the plugins when they wish to 0095 * add a key value pair which should be indexed. This function may be 0096 * called multiple times for the same key. 0097 * 0098 * \p property This specifies a property name. It should be one of the 0099 * properties from the global list of properties. 0100 * 0101 * \p value The value of the property 0102 */ 0103 virtual void add(Property::Property property, const QVariant& value) = 0; 0104 0105 /** 0106 * This function is called by the plugins. 0107 * A type is a higher level classification of the file. A file can 0108 * have multiple types, but mostly when it does, those types are related. 0109 * Eg - Document and Presentation. 0110 * 0111 * Please choose one type from the list of available types 0112 */ 0113 virtual void addType(Type::Type type) = 0; 0114 0115 /** 0116 * This function is called by the plugins. 0117 * 0118 * \p images The images to add 0119 * \sa EmbeddedImageData 0120 * @since 5.76 0121 */ 0122 void addImageData(QMap<EmbeddedImageData::ImageType, QByteArray>&& images); 0123 0124 /** 0125 * Return embedded image data 0126 * 0127 * \sa Flags::ExtractImageData 0128 * @since 5.76 0129 */ 0130 QMap<EmbeddedImageData::ImageType, QByteArray> imageData() const; 0131 0132 private: 0133 const std::unique_ptr<ExtractionResultPrivate> d; 0134 }; 0135 0136 Q_DECLARE_OPERATORS_FOR_FLAGS(ExtractionResult::Flags) 0137 0138 } 0139 0140 #endif // _KFILEMETADATA_EXTRACTIONRESULT_H