1/*
2 SPDX-FileCopyrightText: 2013 Vishesh Handa <me@vhanda.in>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#ifndef _KFILEMETADATA_EXTRACTIONRESULT_H
8#define _KFILEMETADATA_EXTRACTIONRESULT_H
9
10#include <QString>
11#include <QVariant>
12
13#include <memory>
14
15#include "kfilemetadata_export.h"
16#include "embeddedimagedata.h"
17#include "properties.h"
18#include "types.h"
19
20namespace KFileMetaData {
21class ExtractionResultPrivate;
22/*!
23 * \class KFileMetaData::ExtractionResult
24 * \inheaderfile KFileMetaData/ExtractionResult
25 * \inmodule KFileMetaData
26 *
27 * \brief The ExtractionResult class is where all the data extracted by
28 * the indexer is saved.
29 *
30 * This class acts as a base class which should be
31 * derived from and then passed to the relevant plugins.
32 *
33 * The derived class needs to implement 3 pure virtual functions through
34 * which it receives the extracted data.
35 */
36class KFILEMETADATA_EXPORT ExtractionResult
37{
38public:
39 /*!
40 * \value ExtractNothing
41 * \value ExtractMetaData
42 * \value ExtractPlainText
43 * \value[since 5.76] ExtractImageData
44 */
45 enum Flag {
46 ExtractNothing = 0,
47 ExtractMetaData = 1,
48 ExtractPlainText = 2,
49 ExtractImageData = 4,
50 };
51 Q_DECLARE_FLAGS(Flags, Flag)
52
53 /*!
54 * Create an ExtractionResult which can be passed be to Extractors. The
55 * extractors use the \a url, \a mimetype and \a flags in order to determine
56 * which file the data should be extracted from and which data should
57 * be extracted.
58 */
59 ExtractionResult(const QString& url, const QString& mimetype = QString(), const Flags& flags = Flags{ExtractPlainText | ExtractMetaData});
60 ExtractionResult(const ExtractionResult& rhs);
61 virtual ~ExtractionResult();
62
63 /*!
64 * The input URL which the plugins will use to locate the file
65 */
66 QString inputUrl() const;
67
68 /*!
69 * The input MIME type. This MIME type should correspond with the
70 * MIME types supported with the relevant plugin when it is being
71 * passed to the Extractor, or be a subtype thereof.
72 *
73 * \sa ExtractorCollection::fetchExtractors
74 * \sa ExtractorPlugin::supportedMimeType
75 */
76 QString inputMimetype() const;
77
78 /*!
79 * The flags which the extraction plugin should considering following
80 * when extracting metadata from the file
81 */
82 Flags inputFlags() const;
83
84 /*!
85 * This function is called by plugins when they wish for some plain
86 * text to be indexed without any property. This generally corresponds
87 * to the text content in a file
88 */
89 virtual void append(const QString& text) = 0;
90
91 /*!
92 * This function is called by the plugins when they wish to
93 * add a key value pair which should be indexed. This function may be
94 * called multiple times for the same key.
95 *
96 * \a property This specifies a property name. It should be one of the
97 * properties from the global list of properties.
98 *
99 * \a value The value of the property
100 */
101 virtual void add(Property::Property property, const QVariant& value) = 0;
102
103 /*!
104 * This function is called by the plugins.
105 *
106 * A type is a higher level classification of the file. A file can
107 * have multiple types, but mostly when it does, those types are related.
108 * Eg - Document and Presentation.
109 *
110 * Please choose one type from the list of available types
111 */
112 virtual void addType(Type::Type type) = 0;
113
114 /*!
115 * This function is called by the plugins.
116 *
117 * \a images The images to add
118 *
119 * \sa EmbeddedImageData
120 *
121 * \since 5.76
122 */
123 void addImageData(QMap<EmbeddedImageData::ImageType, QByteArray>&& images);
124
125 /*!
126 * Return embedded image data
127 *
128 * \since 5.76
129 */
130 QMap<EmbeddedImageData::ImageType, QByteArray> imageData() const;
131
132private:
133 const std::unique_ptr<ExtractionResultPrivate> d;
134};
135
136Q_DECLARE_OPERATORS_FOR_FLAGS(ExtractionResult::Flags)
137
138} // namespace KFileMetaData
139
140Q_DECLARE_METATYPE(KFileMetaData::ExtractionResult::Flag)
141Q_DECLARE_METATYPE(KFileMetaData::ExtractionResult::Flags)
142
143#endif // _KFILEMETADATA_EXTRACTIONRESULT_H
144

source code of kfilemetadata/src/extractionresult.h