18#include "PluginRegistry.h"
21#include <SnapStandardPaths.h>
23Q_LOGGING_CATEGORY(PLUGIN_REGISTRY,
"dekko.plugman.registry")
27 m_regConf(SnapStandardPaths::writableLocation(SnapStandardPaths::AppConfigLocation) +
30 m_regConf.setValue(
"version",
"0.1");
33PluginRegistry::~PluginRegistry()
35 qDeleteAll(m_registry);
39static QPointer<PluginRegistry> s_registry;
42 if (s_registry.isNull()) {
43 qCDebug(PLUGIN_REGISTRY) <<
"Creating instance";
49Registry PluginRegistry::registry()
const
54bool PluginRegistry::supportsLocation(
const QString &location)
56 return m_locations.contains(location);
59QStringList PluginRegistry::pluginLocations()
const
64void PluginRegistry::setPluginLocations(
const QStringList &locations)
66 m_locations = locations;
69void PluginRegistry::loadPlugins(
const QStringList &paths)
71 qDeleteAll(m_registry);
73 if (!m_loader.isNull()) {
74 m_loader->setPluginPaths(paths);
75 m_loader->loadPlugins(m_registry);
80QList<PluginInfo *> PluginRegistry::getAllPlugins(
const bool enabledOnly)
83 QList<PluginInfo *> plugins;
84 for (
auto plugin : m_registry.values()) {
85 m_regConf.beginGroup(plugin->pluginId());
86 const bool enabled = m_regConf.value(QStringLiteral(
"enabled"),
true).toBool();
94 return m_registry.values();
97QList<PluginInfo *> PluginRegistry::getByLocation(
const QString &key,
const bool enabledOnly)
99 if (!m_locations.contains(key)) {
100 qCWarning(PLUGIN_REGISTRY) <<
"Location not supported: " << key;
101 return QList<PluginInfo *>();
104 qCDebug(PLUGIN_REGISTRY) <<
"Getting all enabled plugins";
105 QList<PluginInfo *> plugins;
106 for (
auto plugin : m_registry.values(key)) {
107 m_regConf.beginGroup(plugin->pluginId());
108 bool enabled = m_regConf.value(QStringLiteral(
"enabled"),
true).toBool();
109 m_regConf.endGroup();
111 qCDebug(PLUGIN_REGISTRY) <<
"Plugin enabled: " << plugin->pluginId();
112 enablePlugin(plugin->pluginId());
118 return m_registry.values(key);
121void PluginRegistry::enablePlugin(
const QString &
id)
123 m_regConf.beginGroup(
id);
124 m_regConf.setValue(
"enabled",
true);
125 m_regConf.endGroup();
128void PluginRegistry::disablePlugin(
const QString &
id)
130 m_regConf.beginGroup(
id);
131 m_regConf.setValue(
"enabled",
false);
132 m_regConf.endGroup();
135void PluginRegistry::updateRegistryConf()
137 const QStringList keys = m_regConf.childGroups();
139 for (
auto plugin : m_registry.values()) {
140 if (!keys.contains(plugin->pluginId())) {
141 qCDebug(PLUGIN_REGISTRY) << plugin->pluginId() <<
"Not in" << keys;
142 enablePlugin(plugin->pluginId());