| 1 | /* |
|---|---|
| 2 | SPDX-FileCopyrightText: 2014 Vishesh Handa <me@vhanda.in> |
| 3 | |
| 4 | SPDX-License-Identifier: LGPL-2.1-or-later |
| 5 | */ |
| 6 | |
| 7 | #ifndef KFILEMETADATA_EXTRACTOR_P_H |
| 8 | #define KFILEMETADATA_EXTRACTOR_P_H |
| 9 | |
| 10 | #include "extractorplugin.h" |
| 11 | #include "kfilemetadata_debug.h" |
| 12 | #include <QPluginLoader> |
| 13 | |
| 14 | namespace KFileMetaData { |
| 15 | |
| 16 | class ExtractorPlugin; |
| 17 | |
| 18 | class ExtractorPrivate |
| 19 | { |
| 20 | public: |
| 21 | ~ExtractorPrivate() { |
| 22 | if (m_autoDeletePlugin == Extractor::AutoDeletePlugin) { |
| 23 | delete m_plugin; |
| 24 | } |
| 25 | } |
| 26 | bool initPlugin(); |
| 27 | |
| 28 | ExtractorPlugin *m_plugin = nullptr; |
| 29 | |
| 30 | Extractor::ExtractorPluginOwnership m_autoDeletePlugin = Extractor::AutoDeletePlugin; |
| 31 | |
| 32 | QVariantMap m_metaData; |
| 33 | QString m_pluginPath; |
| 34 | }; |
| 35 | |
| 36 | inline bool ExtractorPrivate::initPlugin() |
| 37 | { |
| 38 | if (m_plugin) { |
| 39 | return true; |
| 40 | } |
| 41 | |
| 42 | QPluginLoader loader(m_pluginPath); |
| 43 | if (!loader.load()) { |
| 44 | qCWarning(KFILEMETADATA_LOG) << "Could not create Extractor:"<< m_pluginPath; |
| 45 | qCWarning(KFILEMETADATA_LOG) << loader.errorString(); |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | QObject* obj = loader.instance(); |
| 50 | if (!obj) { |
| 51 | qCWarning(KFILEMETADATA_LOG) << "Could not create instance:"<< m_pluginPath; |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | m_plugin = qobject_cast<ExtractorPlugin*>(object: obj); |
| 56 | if (!m_plugin) { |
| 57 | qCWarning(KFILEMETADATA_LOG) << "Could not convert to ExtractorPlugin:"<< m_pluginPath; |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | m_autoDeletePlugin = Extractor::DoNotDeletePlugin; |
| 62 | return true; |
| 63 | } |
| 64 | |
| 65 | } |
| 66 | |
| 67 | #endif |
| 68 |
