From df3332046ff21c226fd9df72c9a166b50ee74a40 Mon Sep 17 00:00:00 2001 From: iaom Date: Thu, 4 May 2023 14:11:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=90=9C=E7=B4=A2=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E7=94=9F=E5=91=BD=E5=91=A8=E6=9C=9F=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=86=85=E5=AD=98=E6=B3=84=E6=BC=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libsearch/pluginmanage/plugin-manager.cpp | 12 ++---------- libsearch/pluginmanage/plugin-manager.h | 5 ----- libsearch/pluginmanage/search-plugin-manager.cpp | 9 ++++----- libsearch/pluginmanage/search-plugin-manager.h | 2 -- 4 files changed, 6 insertions(+), 22 deletions(-) diff --git a/libsearch/pluginmanage/plugin-manager.cpp b/libsearch/pluginmanage/plugin-manager.cpp index b0f4611..522a249 100644 --- a/libsearch/pluginmanage/plugin-manager.cpp +++ b/libsearch/pluginmanage/plugin-manager.cpp @@ -37,11 +37,6 @@ PluginManager *PluginManager::getInstance() return global_instance; } -void PluginManager::setPluginEnableByName(const QString &pluginName, bool enable) -{ - m_hash.value(pluginName)->setEnable(enable); -} - PluginManager::PluginManager(QObject *parent) : QObject(parent) { QDir pluginsDir(PLUGIN_INSTALL_DIRS); @@ -73,12 +68,11 @@ PluginManager::PluginManager(QObject *parent) : QObject(parent) PluginInterface *piface = dynamic_cast(plugin); if (!piface) continue; - m_hash.insert(piface->name(), piface); switch (piface->pluginType()) { case PluginInterface::PluginType::SearchPlugin: { auto p = dynamic_cast(plugin); - if (!SearchPluginManager::getInstance()->registerExternalPlugin(p, pluginsDir.absoluteFilePath(fileName))) { - m_hash.erase(m_hash.find(piface->name())); + if(!SearchPluginManager::getInstance()->registerExternalPlugin(p, pluginsDir.absoluteFilePath(fileName))) { + delete p; } break; } @@ -96,6 +90,4 @@ PluginManager::PluginManager(QObject *parent) : QObject(parent) PluginManager::~PluginManager() { - m_hash.clear(); - SearchPluginManager::getInstance()->close(); } diff --git a/libsearch/pluginmanage/plugin-manager.h b/libsearch/pluginmanage/plugin-manager.h index 8ef4649..af1958a 100644 --- a/libsearch/pluginmanage/plugin-manager.h +++ b/libsearch/pluginmanage/plugin-manager.h @@ -41,16 +41,11 @@ public: Q_SIGNALS: void pluginStateChanged(const QString &pluginName, bool enable); -public Q_SLOTS: - void setPluginEnableByName(const QString &pluginName, bool enable); - private: explicit PluginManager(QObject *parent = nullptr); ~PluginManager(); - QHash m_hash; - }; } diff --git a/libsearch/pluginmanage/search-plugin-manager.cpp b/libsearch/pluginmanage/search-plugin-manager.cpp index 99896cd..6990591 100644 --- a/libsearch/pluginmanage/search-plugin-manager.cpp +++ b/libsearch/pluginmanage/search-plugin-manager.cpp @@ -58,6 +58,10 @@ bool SearchPluginManager::registerPlugin(UkuiSearch::SearchPluginIface *plugin) if (m_map.end() != m_map.find(plugin->name())) { qWarning() << "the plugin:" << plugin->name() << "has been registered."; + if (plugin) { + delete plugin; + plugin = nullptr; + } return res; } @@ -440,11 +444,6 @@ SearchPluginIface *SearchPluginManager::getPlugin(const QString &pluginId) return m_map[pluginId]; } -void SearchPluginManager::close() -{ - this->deleteLater(); -} - SearchPluginManager::~SearchPluginManager() { for (auto iter = m_map.begin(); iter != m_map.end();) { diff --git a/libsearch/pluginmanage/search-plugin-manager.h b/libsearch/pluginmanage/search-plugin-manager.h index c55e7dc..d441ffa 100644 --- a/libsearch/pluginmanage/search-plugin-manager.h +++ b/libsearch/pluginmanage/search-plugin-manager.h @@ -56,8 +56,6 @@ public: const QList getPluginIds(); SearchPluginIface *getPlugin(const QString &pluginId); - void close(); - private: explicit SearchPluginManager(QObject *parent = nullptr); ~SearchPluginManager();