File indexing completed on 2024-05-05 16:09:02

0001 /*
0002     SPDX-FileCopyrightText: 2012 Vishesh Handa <me@vhanda.in>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006 
0007 
0008 #ifndef _KFILEMETADATA_EXTRACTOR_PLUGIN_H
0009 #define _KFILEMETADATA_EXTRACTOR_PLUGIN_H
0010 
0011 #include <QStringList>
0012 #include <QDateTime>
0013 
0014 #include "kfilemetadata_export.h"
0015 #include "extractionresult.h"
0016 
0017 namespace KFileMetaData
0018 {
0019 
0020 /**
0021  * \class ExtractorPlugin extractorplugin.h <KFileMetaData/ExtractorPlugin>
0022  *
0023  * \brief The ExtractorPlugin is the base class for all file metadata
0024  * extractors. It is responsible for extracting the metadata in a file.
0025  *
0026  * Plugins should derive from this class and implement the mimetypes
0027  * and extract method.
0028  *
0029  * All Plugins should be synchronous and blocking.
0030  *
0031  * \author Vishesh Handa <me@vhanda.in>
0032  */
0033 class KFILEMETADATA_EXPORT ExtractorPlugin : public QObject
0034 {
0035     Q_OBJECT
0036 public:
0037     explicit ExtractorPlugin(QObject* parent);
0038     ~ExtractorPlugin() override;
0039 
0040     /**
0041      * Provide a list of mimetypes which are supported by this plugin.
0042      * Only files with those mimetypes will be provided to the plugin via
0043      * the extract function.
0044      *
0045      * This can also contains partial mimetypes like "text/", in that case
0046      * this plugin will be chosen only if a better plugin does not exist.
0047      *
0048      * \return A StringList containing the mimetypes.
0049      * \sa extract
0050      */
0051     virtual QStringList mimetypes() const = 0;
0052 
0053     /**
0054      * The main function of the plugin that is responsible for extracting
0055      * the data and filling up the ExtractionResult
0056      *
0057      * The \p result provides the input url and mimetype which
0058      * can be used to identify the file.
0059      *
0060      * This function is synchronous and should be reentrant as it
0061      * can be called by multiple threads.
0062      */
0063     virtual void extract(ExtractionResult* result) = 0;
0064 
0065     //
0066     // Helper functions
0067     //
0068 
0069     /**
0070      * Tries to extract a valid date time from the string provided.
0071      */
0072     static QDateTime dateTimeFromString(const QString& dateString);
0073 
0074     /**
0075      * Tries to split the string into names. It cleans up any superfluous words
0076      * and removes extra junk such as curly braces
0077      */
0078     static QStringList contactsFromString(const QString& string);
0079 
0080 protected:
0081     /**
0082      * Return the inherited mimetype which the extractor directly supports.
0083      *
0084      * The returned type is one of the types from \c mimetypes(),
0085      * and is one of the ancestors of the input \p mimetype
0086      * (including \p mimetype itself).
0087      *
0088      * In case the mimetype is not a subtype of the supported types,
0089      * an empty QString() is returned.
0090      *
0091      * \sa ExtractorCollection::fetchExtractors
0092      * \sa QMimeType::allAncestors
0093      * @since 5.57
0094      */
0095     QString getSupportedMimeType(const QString& mimetype) const;
0096 
0097 private:
0098     class ExtractorPluginPrivate;
0099     ExtractorPluginPrivate *d_placeholder; // Placeholder for future binary compatible extensions
0100 };
0101 }
0102 
0103 Q_DECLARE_INTERFACE(KFileMetaData::ExtractorPlugin, "org.kde.kf5.kfilemetadata.ExtractorPlugin")
0104 
0105 #endif // _KFILEMETADATA_EXTRACTOR_PLUGIN_H