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

KDE's Doxygen guidelines are available online.