KFileMetaData

extractorplugin.h
1/*
2 SPDX-FileCopyrightText: 2012 Vishesh Handa <me@vhanda.in>
3
4 SPDX-License-Identifier: LGPL-2.1-or-later
5*/
6
7
8#ifndef _KFILEMETADATA_EXTRACTOR_PLUGIN_H
9#define _KFILEMETADATA_EXTRACTOR_PLUGIN_H
10
11#include <QStringList>
12#include <QDateTime>
13
14#include "kfilemetadata_export.h"
15#include "extractionresult.h"
16
17namespace KFileMetaData
18{
19
20/**
21 * \class ExtractorPlugin extractorplugin.h <KFileMetaData/ExtractorPlugin>
22 *
23 * \brief The ExtractorPlugin is the base class for all file metadata
24 * extractors.
25 *
26 * It is responsible for extracting the metadata in a file.
27 *
28 * Plugins should derive from this class and implement the \c mimetypes()
29 * and \c extract() method.
30 *
31 * The plugin must also specify the implemented interface and provide
32 * sufficient metadata:
33 *
34 * \code{cpp}
35 * class FooExtractor : public ExtractorPlugin
36 * {
37 * Q_OBJECT
38 * Q_PLUGIN_METADATA(IID kfilemetadata_extractor_iid
39 * FILE "fooextractor.json")
40 * Q_INTERFACES(KFileMetaData::ExtractorPlugin)
41 * ...
42 * };
43 * \endcode
44 * \code{json}
45 * {
46 * "Name" : "FooExtractor",
47 * "Id" : "org.kde.fooextractor",
48 * "MimeTypes" : { "application/x-foo" : { "Version" : "0.0" } }
49 * }
50 * \endcode
51 *
52 * \author Vishesh Handa <me@vhanda.in>
53 */
54class KFILEMETADATA_EXPORT ExtractorPlugin : public QObject
55{
57public:
58 explicit ExtractorPlugin(QObject* parent);
59 ~ExtractorPlugin() override;
60
61 /**
62 * Provide a list of MIME types which are supported by this plugin.
63 * Only files with those MIME types will be provided to the plugin via
64 * the extract function.
65 *
66 * This can also contains partial MIME types like "text/", in that case
67 * this plugin will be chosen only if a better plugin does not exist.
68 *
69 * \return A StringList containing the MIME types.
70 * \sa extract
71 */
72 virtual QStringList mimetypes() const = 0;
73
74 /**
75 * The main function of the plugin that is responsible for extracting
76 * the data and filling up the ExtractionResult
77 *
78 * The \p result provides the input URL and MIME type which
79 * can be used to identify the file.
80 *
81 * This function is synchronous and must be reentrant as it
82 * can be called by multiple threads.
83 */
84 virtual void extract(ExtractionResult* result) = 0;
85
86#if KFILEMETADATA_ENABLE_DEPRECATED_SINCE(6, 12)
87 //
88 // Helper functions
89 //
90
91 /**
92 * Tries to extract a valid date time from the string provided.
93 */
94 /// @deprecated since 6.12
95 static QDateTime dateTimeFromString(const QString& dateString);
96
97 /**
98 * Tries to split the string into names. It cleans up any superfluous words
99 * and removes extra junk such as curly braces
100 */
101 /// @deprecated since 6.12
102 static QStringList contactsFromString(const QString& string);
103#endif
104
105protected:
106 /**
107 * Return the inherited MIME type which the extractor directly supports.
108 *
109 * The returned type is one of the types from \c mimetypes(),
110 * and is one of the ancestors of the input \p mimetype
111 * (including \p mimetype itself).
112 *
113 * In case the MIME type is not a subtype of the supported types,
114 * an empty QString() is returned.
115 *
116 * \sa ExtractorCollection::fetchExtractors
117 * \sa QMimeType::allAncestors
118 * @since 5.57
119 */
120 QString getSupportedMimeType(const QString& mimetype) const;
121
122private:
123 class ExtractorPluginPrivate;
124 ExtractorPluginPrivate *d_placeholder; // Placeholder for future binary compatible extensions
125};
126}
127
128#define kfilemetadata_extractor_iid "org.kde.kf5.kfilemetadata.ExtractorPlugin"
129Q_DECLARE_INTERFACE(KFileMetaData::ExtractorPlugin, kfilemetadata_extractor_iid)
130
131#endif // _KFILEMETADATA_EXTRACTOR_PLUGIN_H
The ExtractionResult class is where all the data extracted by the indexer is saved.
The ExtractorPlugin is the base class for all file metadata extractors.
static QStringList contactsFromString(const QString &string)
Tries to split the string into names.
static QDateTime dateTimeFromString(const QString &dateString)
Tries to extract a valid date time from the string provided.
virtual QStringList mimetypes() const =0
Provide a list of MIME types which are supported by this plugin.
QString getSupportedMimeType(const QString &mimetype) const
Return the inherited MIME type which the extractor directly supports.
virtual void extract(ExtractionResult *result)=0
The main function of the plugin that is responsible for extracting the data and filling up the Extrac...
The KFileMetaData namespace.
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 21 2025 11:53:46 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.