File indexing completed on 2024-05-05 03:54:40

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     };
0046     /**
0047      * Stores a combination of #Flag values.
0048      */
0049     Q_DECLARE_FLAGS(Flags, Flag)
0050 
0051     /**
0052      * Create an ExtractionResult which can be passed be to Extractors. The
0053      * extractors use the \p url, \p mimetype and \p flags in order to determine
0054      * which file the data should be extracted from and which data should
0055      * be extracted.
0056      */
0057     ExtractionResult(const QString& url, const QString& mimetype = QString(), const Flags& flags = Flags{ExtractPlainText | ExtractMetaData});
0058     ExtractionResult(const ExtractionResult& rhs);
0059     virtual ~ExtractionResult();
0060 
0061     /**
0062      * The input url which the plugins will use to locate the file
0063      */
0064     QString inputUrl() const;
0065 
0066     /**
0067      * The input mimetype. This mimetype should correspond with the
0068      * mimetypes supported with the relevant plugin when it is being
0069      * passed to the Extractor, or be a subtype thereof.
0070      *
0071      * \sa ExtractorCollection::fetchExtractors
0072      * \sa ExtractorPlugin::supportedMimeType
0073      */
0074     QString inputMimetype() const;
0075 
0076     /**
0077      * The flags which the extraction plugin should considering following
0078      * when extracting metadata from the file
0079      */
0080     Flags inputFlags() const;
0081 
0082     /**
0083      * This function is called by plugins when they wish for some plain
0084      * text to be indexed without any property. This generally corresponds
0085      * to the text content in a file
0086      */
0087     virtual void append(const QString& text) = 0;
0088 
0089     /**
0090      * This function is called by the plugins when they wish to
0091      * add a key value pair which should be indexed. This function may be
0092      * called multiple times for the same key.
0093      *
0094      * \p property This specifies a property name. It should be one of the
0095      *             properties from the global list of properties.
0096      *
0097      * \p value The value of the property
0098      */
0099     virtual void add(Property::Property property, const QVariant& value) = 0;
0100 
0101     /**
0102      * This function is called by the plugins.
0103      * A type is a higher level classification of the file. A file can
0104      * have multiple types, but mostly when it does, those types are related.
0105      * Eg - Document and Presentation.
0106      *
0107      * Please choose one type from the list of available types
0108      */
0109     virtual void addType(Type::Type type) = 0;
0110 
0111     /**
0112      * This function is called by the plugins.
0113      *
0114      * \p images The images to add
0115      * \sa EmbeddedImageData
0116      * @since 5.76
0117      */
0118     void addImageData(QMap<EmbeddedImageData::ImageType, QByteArray>&& images);
0119 
0120     /**
0121      * Return embedded image data
0122      *
0123      * \sa Flags::ExtractImageData
0124      * @since 5.76
0125      */
0126     QMap<EmbeddedImageData::ImageType, QByteArray> imageData() const;
0127 
0128 private:
0129     const std::unique_ptr<ExtractionResultPrivate> d;
0130 };
0131 
0132 Q_DECLARE_OPERATORS_FOR_FLAGS(ExtractionResult::Flags)
0133 
0134 }
0135 
0136 #endif // _KFILEMETADATA_EXTRACTIONRESULT_H