18 #include "ActionRegistry.h"
22 #include <QQmlComponent>
23 #include "PluginRegistry.h"
25 Q_LOGGING_CATEGORY(PLUGIN_ACTION,
"dekko.plugman.action")
29 connect(
this, &ActionRegistry::locationChanged,
this, &ActionRegistry::loadActions);
32 ActionRegistry::~ActionRegistry()
34 qDeleteAll(m_actions);
37 QList<QObject *> ActionRegistry::actions()
const
42 QString ActionRegistry::location()
const
47 QQmlListProperty<QObject> ActionRegistry::defaultActions()
49 return QQmlListProperty<QObject>(
this, m_defaults);
52 void ActionRegistry::setLocation(QString location)
54 if (m_location == location)
57 m_location = location;
58 emit locationChanged(location);
61 void ActionRegistry::loadActions()
63 qCDebug(PLUGIN_ACTION) <<
"Loading actions for: " << m_location;
64 if (!m_actions.isEmpty()) {
65 qDeleteAll(m_actions);
68 m_actions << m_defaults;
69 auto plugins = PluginRegistry::instance()->getByLocation(m_location);
70 for (
auto plugin : plugins) {
71 if (
auto dp = qobject_cast<DekkoPlugin *>(plugin)) {
73 connect(incubator, &PluginIncubator::objectReady,
this, &ActionRegistry::finishLoading);
74 connect(incubator, &PluginIncubator::error,
this, &ActionRegistry::handleError);
75 incubator->setSourceUrl(qmlEngine(
this), QUrl::fromLocalFile(dp->component()));
76 m_incubators << incubator;
79 emit actionsChanged(m_actions);
82 void ActionRegistry::finishLoading()
85 if (incubator->status() == QQmlIncubator::Ready) {
86 QObject *action = incubator->object();
87 qCDebug(PLUGIN_ACTION) <<
"Finished incubating";
89 emit actionsChanged(m_actions);
90 qCDebug(PLUGIN_ACTION) <<
"Action loaded for " << m_location;
94 void ActionRegistry::handleError()
97 for (
auto error : incubator->errors()) {
98 qCDebug(PLUGIN_ACTION) <<
"Incubator Error: " << error.toString();