File indexing completed on 2025-02-16 13:03:41
0001 /* 0002 SPDX-FileCopyrightText: 2014 Vishesh Handa <me@vhanda.in> 0003 0004 SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #ifndef KFILEMETADATA_EXTRACTOR_P_H 0008 #define KFILEMETADATA_EXTRACTOR_P_H 0009 0010 #include "extractorplugin.h" 0011 #include "kfilemetadata_debug.h" 0012 #include <QPluginLoader> 0013 0014 namespace KFileMetaData { 0015 0016 class ExtractorPlugin; 0017 0018 class ExtractorPrivate 0019 { 0020 public: 0021 ~ExtractorPrivate() { 0022 if (m_autoDeletePlugin == Extractor::AutoDeletePlugin) { 0023 delete m_plugin; 0024 } 0025 } 0026 bool initPlugin(); 0027 0028 ExtractorPlugin *m_plugin = nullptr; 0029 0030 Extractor::ExtractorPluginOwnership m_autoDeletePlugin = Extractor::AutoDeletePlugin; 0031 0032 QVariantMap m_metaData; 0033 QString m_pluginPath; 0034 }; 0035 0036 inline bool ExtractorPrivate::initPlugin() 0037 { 0038 if (m_plugin) { 0039 return true; 0040 } 0041 0042 QPluginLoader loader(m_pluginPath); 0043 if (!loader.load()) { 0044 qCWarning(KFILEMETADATA_LOG) << "Could not create Extractor:" << m_pluginPath; 0045 qCWarning(KFILEMETADATA_LOG) << loader.errorString(); 0046 return false; 0047 } 0048 0049 QObject* obj = loader.instance(); 0050 if (!obj) { 0051 qCWarning(KFILEMETADATA_LOG) << "Could not create instance:" << m_pluginPath; 0052 return false; 0053 } 0054 0055 m_plugin = qobject_cast<ExtractorPlugin*>(obj); 0056 if (!m_plugin) { 0057 qCWarning(KFILEMETADATA_LOG) << "Could not convert to ExtractorPlugin:" << m_pluginPath; 0058 return false; 0059 } 0060 0061 m_autoDeletePlugin = Extractor::DoNotDeletePlugin; 0062 return true; 0063 } 0064 0065 } 0066 0067 #endif