File indexing completed on 2024-11-10 04:40:25

0001 /*
0002     SPDX-FileCopyrightText: 2010 Bertjan Broeksema <broeksema@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 #include "agentpluginloader.h"
0007 #include "akonadiagentserver_debug.h"
0008 
0009 #include "shared/akdebug.h"
0010 
0011 #include <QPluginLoader>
0012 
0013 AgentPluginLoader::AgentPluginLoader()
0014 {
0015 }
0016 
0017 AgentPluginLoader::~AgentPluginLoader()
0018 {
0019     qDeleteAll(m_pluginLoaders);
0020     m_pluginLoaders.clear();
0021 }
0022 
0023 QPluginLoader *AgentPluginLoader::load(const QString &pluginName)
0024 {
0025     QPluginLoader *loader = m_pluginLoaders.value(pluginName);
0026     if (loader) {
0027         return loader;
0028     } else {
0029         loader = new QPluginLoader(pluginName);
0030         if (!loader->load()) {
0031             qCWarning(AKONADIAGENTSERVER_LOG) << "Failed to load agent: " << loader->errorString();
0032             delete loader;
0033             return nullptr;
0034         }
0035         m_pluginLoaders.insert(pluginName, loader);
0036         return loader;
0037     }
0038 }