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. It is responsible for extracting the metadata in a file.
25 *
26 * Plugins should derive from this class and implement the mimetypes
27 * and extract method.
28 *
29 * All Plugins should be synchronous and blocking.
30 *
31 * \author Vishesh Handa <me@vhanda.in>
32 */
33class KFILEMETADATA_EXPORT ExtractorPlugin : public QObject
34{
35 Q_OBJECT
36public:
37 explicit ExtractorPlugin(QObject* parent);
38 ~ExtractorPlugin() override;
39
40 /**
41 * Provide a list of mimetypes which are supported by this plugin.
42 * Only files with those mimetypes will be provided to the plugin via
43 * the extract function.
44 *
45 * This can also contains partial mimetypes like "text/", in that case
46 * this plugin will be chosen only if a better plugin does not exist.
47 *
48 * \return A StringList containing the mimetypes.
49 * \sa extract
50 */
51 virtual QStringList mimetypes() const = 0;
52
53 /**
54 * The main function of the plugin that is responsible for extracting
55 * the data and filling up the ExtractionResult
56 *
57 * The \p result provides the input url and mimetype which
58 * can be used to identify the file.
59 *
60 * This function is synchronous and should be reentrant as it
61 * can be called by multiple threads.
62 */
63 virtual void extract(ExtractionResult* result) = 0;
64
65 //
66 // Helper functions
67 //
68
69 /**
70 * Tries to extract a valid date time from the string provided.
71 */
72 static QDateTime dateTimeFromString(const QString& dateString);
73
74 /**
75 * Tries to split the string into names. It cleans up any superfluous words
76 * and removes extra junk such as curly braces
77 */
78 static QStringList contactsFromString(const QString& string);
79
80protected:
81 /**
82 * Return the inherited mimetype which the extractor directly supports.
83 *
84 * The returned type is one of the types from \c mimetypes(),
85 * and is one of the ancestors of the input \p mimetype
86 * (including \p mimetype itself).
87 *
88 * In case the mimetype is not a subtype of the supported types,
89 * an empty QString() is returned.
90 *
91 * \sa ExtractorCollection::fetchExtractors
92 * \sa QMimeType::allAncestors
93 * @since 5.57
94 */
95 QString getSupportedMimeType(const QString& mimetype) const;
96
97private:
98 class ExtractorPluginPrivate;
99 ExtractorPluginPrivate *d_placeholder; // Placeholder for future binary compatible extensions
100};
101}
102
103Q_DECLARE_INTERFACE(KFileMetaData::ExtractorPlugin, "org.kde.kf5.kfilemetadata.ExtractorPlugin")
104
105#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.
virtual QStringList mimetypes() const =0
Provide a list of mimetypes which are supported by this plugin.
virtual void extract(ExtractionResult *result)=0
The main function of the plugin that is responsible for extracting the data and filling up the Extrac...
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:17:53 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.