diff --git a/core/libs/dplugins/setup/dpluginloader.cpp b/core/libs/dplugins/setup/dpluginloader.cpp index a8e29c4a2b..43ab1eb20b 100644 --- a/core/libs/dplugins/setup/dpluginloader.cpp +++ b/core/libs/dplugins/setup/dpluginloader.cpp @@ -1,328 +1,319 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2018-07-30 * Description : manager to load external plugins at run-time * * Copyright (C) 2018-2019 by Gilles Caulier * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software Foundation; * either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * ============================================================ */ #include "dpluginloader_p.h" // Qt includes #include // Local includes #include "digikam_config.h" #include "digikam_debug.h" #include "dplugingeneric.h" #include "dplugineditor.h" namespace Digikam { class Q_DECL_HIDDEN DPluginLoaderCreator { public: DPluginLoader object; }; Q_GLOBAL_STATIC(DPluginLoaderCreator, creator) // ----------------------------------------------------- DPluginLoader::DPluginLoader() : QObject(), d(new Private) { } DPluginLoader::~DPluginLoader() { delete d; } DPluginLoader* DPluginLoader::instance() { return &creator->object; } void DPluginLoader::init() { d->loadPlugins(); } void DPluginLoader::cleanUp() { foreach (QPluginLoader* const loader, d->allLoaders) { loader->unload(); } d->allLoaders.clear(); } QString DPluginLoader::configGroupName() const { return QLatin1String("EnabledDPlugins"); } QList DPluginLoader::allPlugins() const { return d->allPlugins; } QList DPluginLoader::pluginsActions(DPluginAction::ActionType type, QObject* const parent) const { QList list; foreach (DPlugin* const p, allPlugins()) { DPluginGeneric* const gene = dynamic_cast(p); if (gene) { foreach (DPluginAction* const ac, gene->actions(parent)) { if (ac && (ac->actionType() == type)) { list << ac; } } } } - if (!list.isEmpty()) + if (list.isEmpty()) { - std::sort(list.begin(), list.end(), DPluginAction::pluginActionLessThan); - return list; - } - - foreach (DPlugin* const p, allPlugins()) - { - DPluginEditor* const edit = dynamic_cast(p); - - if (edit) + foreach (DPlugin* const p, allPlugins()) { - foreach (DPluginAction* const ac, edit->actions(parent)) + DPluginEditor* const edit = dynamic_cast(p); + + if (edit) { - if (ac && (ac->actionType() == type)) + foreach (DPluginAction* const ac, edit->actions(parent)) { - list << ac; + if (ac && (ac->actionType() == type)) + { + list << ac; + } } } } } std::sort(list.begin(), list.end(), DPluginAction::pluginActionLessThan); return list; } QList DPluginLoader::pluginsActions(DPluginAction::ActionCategory cat, QObject* const parent) const { QList list; foreach (DPlugin* const p, allPlugins()) { DPluginGeneric* const gene = dynamic_cast(p); if (gene) { foreach (DPluginAction* const ac, gene->actions(parent)) { if (ac && (ac->actionCategory() == cat)) { list << ac; } } } - } - - if (!list.isEmpty()) - { - std::sort(list.begin(), list.end(), DPluginAction::pluginActionLessThan); - return list; } - foreach (DPlugin* const p, allPlugins()) + if (list.isEmpty()) { - DPluginEditor* const edit = dynamic_cast(p); - - if (edit) + foreach (DPlugin* const p, allPlugins()) { - foreach (DPluginAction* const ac, edit->actions(parent)) + DPluginEditor* const edit = dynamic_cast(p); + + if (edit) { - if (ac && (ac->actionCategory() == cat)) + foreach (DPluginAction* const ac, edit->actions(parent)) { - list << ac; + if (ac && (ac->actionCategory() == cat)) + { + list << ac; + } } } } - } + } - std::sort(list.begin(), list.end(), DPluginAction::pluginActionLessThan); - return list; + std::sort(list.begin(), list.end(), DPluginAction::pluginActionLessThan); + return list; } QList DPluginLoader::pluginActions(const QString& pluginIID, QObject* const parent) const { QList list; foreach (DPlugin* const p, allPlugins()) { DPluginGeneric* const gene = dynamic_cast(p); if (gene) { if (p->iid() == pluginIID) { foreach (DPluginAction* const ac, gene->actions(parent)) { list << ac; } break; } } } - if (!list.isEmpty()) - { - std::sort(list.begin(), list.end(), DPluginAction::pluginActionLessThan); - return list; - } - - foreach (DPlugin* const p, allPlugins()) + if (list.isEmpty()) { - DPluginEditor* const edit = dynamic_cast(p); - - if (edit) + foreach (DPlugin* const p, allPlugins()) { - if (p->iid() == pluginIID) + DPluginEditor* const edit = dynamic_cast(p); + + if (edit) { - foreach (DPluginAction* const ac, edit->actions(parent)) + if (p->iid() == pluginIID) { - list << ac; - } + foreach (DPluginAction* const ac, edit->actions(parent)) + { + list << ac; + } - break; + break; + } } } } std::sort(list.begin(), list.end(), DPluginAction::pluginActionLessThan); return list; } DPluginAction* DPluginLoader::pluginAction(const QString& actionName, QObject* const parent) const { foreach (DPlugin* const p, allPlugins()) { DPluginGeneric* const gene = dynamic_cast(p); if (gene) { foreach (DPluginAction* const ac, gene->actions(parent)) { if (ac && (ac->objectName() == actionName)) { return ac; } } } DPluginEditor* const edit = dynamic_cast(p); if (edit) { foreach (DPluginAction* const ac, edit->actions(parent)) { if (ac && (ac->objectName() == actionName)) { return ac; } } } } qCCritical(DIGIKAM_GENERAL_LOG) << "DPluginAction named" << actionName << "not found in" << parent->objectName() << "(" << parent << ")"; return 0; } QString DPluginLoader::pluginXmlSections(DPluginAction::ActionCategory cat, QObject* const parent) const { QString xml; foreach (DPluginAction* const ac, pluginsActions(cat, parent)) { xml.append(ac->xmlSection()); } return xml; } void DPluginLoader::appendPluginToBlackList(const QString& filename) { d->blacklist << filename; } void DPluginLoader::appendPluginToWhiteList(const QString& filename) { d->whitelist << filename; } void DPluginLoader::registerGenericPlugins(QObject* const parent) { foreach (DPlugin* const plugin, d->allPlugins) { DPluginGeneric* const gene = dynamic_cast(plugin); if (gene) { gene->setup(parent); gene->setVisible(plugin->shouldLoaded()); qCDebug(DIGIKAM_GENERAL_LOG) << "Generic plugin named" << gene->name() << "registered to" << parent; } } } void DPluginLoader::registerEditorPlugins(QObject* const parent) { foreach (DPlugin* const plugin, d->allPlugins) { DPluginEditor* const edit = dynamic_cast(plugin); if (edit) { edit->setup(parent); edit->setVisible(plugin->shouldLoaded()); qCDebug(DIGIKAM_GENERAL_LOG) << "Editor plugin named" << edit->name() << "registered to" << parent; } } } } // namepace Digikam