Merge PR #854: Only load plugin configs on demand
commit
4e6979e44b
|
|
@ -139,6 +139,7 @@
|
|||
#include "energy/energylogs.h"
|
||||
#include "energy/powerbalancelogs.h"
|
||||
#include "energy/thingpowerlogs.h"
|
||||
#include "pluginconfigmanager.h"
|
||||
|
||||
#include <QtQml/qqml.h>
|
||||
|
||||
|
|
@ -250,6 +251,7 @@ void registerQmlTypes() {
|
|||
qmlRegisterUncreatableType<Plugin>(uri, 1, 0, "Plugin", "Can't create this in QML. Get it from the Plugins.");
|
||||
qmlRegisterUncreatableType<Plugins>(uri, 1, 0, "Plugins", "Can't create this in QML. Get it from the ThingManager.");
|
||||
qmlRegisterType<PluginsProxy>(uri, 1, 0, "PluginsProxy");
|
||||
qmlRegisterType<PluginConfigManager>(uri, 1, 0, "PluginConfigManager");
|
||||
|
||||
qmlRegisterUncreatableType<NymeaConfiguration>(uri, 1, 0, "NymeaConfiguration", "Get it from Engine");
|
||||
qmlRegisterUncreatableType<ServerConfiguration>(uri, 1, 0, "ServerConfiguration", "Get it from NymeaConfiguration");
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ SOURCES += \
|
|||
$$PWD/energy/thingpowerlogs.cpp \
|
||||
$$PWD/connection/tunnelproxytransport.cpp \
|
||||
$$PWD/models/scriptsproxymodel.cpp \
|
||||
$$PWD/pluginconfigmanager.cpp \
|
||||
$$PWD/tagwatcher.cpp \
|
||||
$$PWD/zigbee/zigbeenode.cpp \
|
||||
$$PWD/zigbee/zigbeenodes.cpp \
|
||||
|
|
@ -188,6 +189,7 @@ HEADERS += \
|
|||
$$PWD/energy/thingpowerlogs.h \
|
||||
$$PWD/connection/tunnelproxytransport.h \
|
||||
$$PWD/models/scriptsproxymodel.h \
|
||||
$$PWD/pluginconfigmanager.h \
|
||||
$$PWD/tagwatcher.h \
|
||||
$$PWD/zigbee/zigbeenode.h \
|
||||
$$PWD/zigbee/zigbeenodes.h \
|
||||
|
|
|
|||
|
|
@ -0,0 +1,80 @@
|
|||
#include "pluginconfigmanager.h"
|
||||
|
||||
PluginConfigManager::PluginConfigManager(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
m_params = new Params(this);
|
||||
}
|
||||
|
||||
Engine *PluginConfigManager::engine() const
|
||||
{
|
||||
return m_engine;
|
||||
}
|
||||
|
||||
void PluginConfigManager::setEngine(Engine *engine)
|
||||
{
|
||||
if (m_engine != engine) {
|
||||
if (m_engine) {
|
||||
m_engine->jsonRpcClient()->unregisterNotificationHandler(this);
|
||||
}
|
||||
|
||||
m_engine = engine;
|
||||
emit engineChanged();
|
||||
|
||||
if (m_engine) {
|
||||
m_engine->jsonRpcClient()->registerNotificationHandler(this, "ThingManager", "notificationReceived");
|
||||
|
||||
if (m_plugin) {
|
||||
m_engine->jsonRpcClient()->sendCommand("Integrations.GetPluginConfiguration", {{"pluginId", m_plugin->pluginId()}}, this, "getPluginConfigResponse");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Plugin *PluginConfigManager::plugin() const
|
||||
{
|
||||
return m_plugin;
|
||||
}
|
||||
|
||||
void PluginConfigManager::setPlugin(Plugin *plugin)
|
||||
{
|
||||
if (m_plugin != plugin) {
|
||||
m_plugin = plugin;
|
||||
emit pluginChanged();
|
||||
|
||||
if (m_plugin && m_engine) {
|
||||
m_engine->jsonRpcClient()->sendCommand("Integrations.GetPluginConfiguration", {{"pluginId", m_plugin->pluginId()}}, this, "getPluginConfigResponse");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Params *PluginConfigManager::params()
|
||||
{
|
||||
return m_params;
|
||||
}
|
||||
|
||||
void PluginConfigManager::getPluginConfigResponse(int /*commandId*/, const QVariantMap ¶ms)
|
||||
{
|
||||
qCWarning(dcThingManager) << "plugin config response" << params;
|
||||
m_params->clearModel();
|
||||
|
||||
QVariantList pluginParams = params.value("configuration").toList();
|
||||
foreach (const QVariant ¶mVariant, pluginParams) {
|
||||
Param* param = new Param();
|
||||
param->setParamTypeId(paramVariant.toMap().value("paramTypeId").toString());
|
||||
param->setValue(paramVariant.toMap().value("value"));
|
||||
m_params->addParam(param);
|
||||
}
|
||||
}
|
||||
|
||||
int PluginConfigManager::savePluginConfig()
|
||||
{
|
||||
QVariantMap params;
|
||||
params.insert("pluginId", m_plugin->pluginId());
|
||||
QVariantList pluginParams;
|
||||
for (int i = 0; i < m_params->rowCount(); i++) {
|
||||
pluginParams.append(QVariantMap{{"paramTypeId", m_params->get(i)->paramTypeId()}, {"value", m_params->get(i)->value()}});
|
||||
}
|
||||
params.insert("configuration", pluginParams);
|
||||
return m_engine->jsonRpcClient()->sendCommand("Integrations.SetPluginConfiguration", params, this, "setPluginConfigResponse");
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
#ifndef PLUGINCONFIGMANAGER_H
|
||||
#define PLUGINCONFIGMANAGER_H
|
||||
|
||||
#include "types/params.h"
|
||||
#include "types/paramtypes.h"
|
||||
#include "engine.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class PluginConfigManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(Engine* engine READ engine WRITE setEngine NOTIFY engineChanged)
|
||||
Q_PROPERTY(Plugin* plugin READ plugin WRITE setPlugin NOTIFY pluginChanged)
|
||||
|
||||
Q_PROPERTY(Params *params READ params CONSTANT)
|
||||
|
||||
public:
|
||||
explicit PluginConfigManager(QObject *parent = nullptr);
|
||||
|
||||
Engine* engine() const;
|
||||
void setEngine(Engine *engine);
|
||||
|
||||
Plugin* plugin() const;
|
||||
void setPlugin(Plugin *plugin);
|
||||
|
||||
Params *params();
|
||||
void setParams(Params *params);
|
||||
|
||||
Q_INVOKABLE int savePluginConfig();
|
||||
|
||||
signals:
|
||||
void engineChanged();
|
||||
void pluginChanged();
|
||||
|
||||
private slots:
|
||||
void getPluginConfigResponse(int commandId, const QVariantMap &data);
|
||||
|
||||
private:
|
||||
Engine *m_engine = nullptr;
|
||||
Plugin* m_plugin = nullptr;
|
||||
Params *m_params = nullptr;
|
||||
|
||||
};
|
||||
|
||||
#endif // PLUGINCONFIGMANAGER_H
|
||||
|
|
@ -59,6 +59,19 @@ void PluginsProxy::setShowOnlyConfigurable(bool showOnlyConfigurable)
|
|||
if (m_showOnlyConfigurable != showOnlyConfigurable) {
|
||||
m_showOnlyConfigurable = showOnlyConfigurable;
|
||||
emit showOnlyConfigurableChanged();
|
||||
}
|
||||
}
|
||||
|
||||
QString PluginsProxy::filter() const
|
||||
{
|
||||
return m_filter;
|
||||
}
|
||||
|
||||
void PluginsProxy::setFilter(const QString &filter)
|
||||
{
|
||||
if (m_filter != filter) {
|
||||
m_filter = filter;
|
||||
emit filterChanged();
|
||||
invalidateFilter();
|
||||
}
|
||||
}
|
||||
|
|
@ -78,5 +91,11 @@ bool PluginsProxy::filterAcceptsRow(int source_row, const QModelIndex &source_pa
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_filter.isEmpty()) {
|
||||
if (!plugin->name().toLower().contains(m_filter.toLower())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ class PluginsProxy : public QSortFilterProxyModel
|
|||
Q_OBJECT
|
||||
Q_PROPERTY(Plugins* plugins READ plugins WRITE setPlugins NOTIFY pluginsChanged)
|
||||
Q_PROPERTY(bool showOnlyConfigurable READ showOnlyConfigurable WRITE setShowOnlyConfigurable NOTIFY showOnlyConfigurableChanged)
|
||||
Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged)
|
||||
public:
|
||||
explicit PluginsProxy(QObject *parent = nullptr);
|
||||
|
||||
|
|
@ -50,6 +51,9 @@ public:
|
|||
bool showOnlyConfigurable() const;
|
||||
void setShowOnlyConfigurable(bool showOnlyConfigurable);
|
||||
|
||||
QString filter() const;
|
||||
void setFilter(const QString &filter);
|
||||
|
||||
Q_INVOKABLE Plugin* get(int index) const;
|
||||
protected:
|
||||
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
|
||||
|
|
@ -57,10 +61,12 @@ protected:
|
|||
signals:
|
||||
void pluginsChanged();
|
||||
void showOnlyConfigurableChanged();
|
||||
void filterChanged();
|
||||
|
||||
private:
|
||||
Plugins *m_plugins = nullptr;
|
||||
bool m_showOnlyConfigurable = false;
|
||||
QString m_filter;
|
||||
};
|
||||
|
||||
#endif // PLUGINSPROXY_H
|
||||
|
|
|
|||
|
|
@ -266,36 +266,6 @@ void ThingManager::getPluginsResponse(int /*commandId*/, const QVariantMap ¶
|
|||
}
|
||||
}
|
||||
m_jsonClient->sendCommand("Integrations.GetVendors", this, "getVendorsResponse");
|
||||
|
||||
if (m_plugins->count() > 0) {
|
||||
m_currentGetConfigIndex = 0;
|
||||
QVariantMap configRequestParams;
|
||||
configRequestParams.insert("pluginId", m_plugins->get(m_currentGetConfigIndex)->pluginId());
|
||||
m_jsonClient->sendCommand("Integrations.GetPluginConfiguration", configRequestParams, this, "getPluginConfigResponse");
|
||||
}
|
||||
}
|
||||
|
||||
void ThingManager::getPluginConfigResponse(int /*commandId*/, const QVariantMap ¶ms)
|
||||
{
|
||||
// qDebug() << "plugin config response" << params;
|
||||
Plugin *p = m_plugins->get(m_currentGetConfigIndex);
|
||||
if (!p) {
|
||||
qDebug() << "Received a plugin config for a plugin we don't know";
|
||||
return;
|
||||
}
|
||||
QVariantList pluginParams = params.value("configuration").toList();
|
||||
foreach (const QVariant ¶mVariant, pluginParams) {
|
||||
Param* param = new Param();
|
||||
unpackParam(paramVariant.toMap(), param);
|
||||
p->params()->addParam(param);
|
||||
}
|
||||
|
||||
m_currentGetConfigIndex++;
|
||||
if (m_plugins->count() > m_currentGetConfigIndex) {
|
||||
QVariantMap configRequestParams;
|
||||
configRequestParams.insert("pluginId", m_plugins->get(m_currentGetConfigIndex)->pluginId());
|
||||
m_jsonClient->sendCommand("Integrations.GetPluginConfiguration", configRequestParams, this, "getPluginConfigResponse");
|
||||
}
|
||||
}
|
||||
|
||||
void ThingManager::getThingsResponse(int /*commandId*/, const QVariantMap ¶ms)
|
||||
|
|
@ -410,23 +380,6 @@ void ThingManager::reconfigureThingResponse(int commandId, const QVariantMap &pa
|
|||
emit reconfigureThingReply(commandId, errorFromString(params.value("thingError").toByteArray()), params.value("displayMessage").toString());
|
||||
}
|
||||
|
||||
int ThingManager::savePluginConfig(const QUuid &pluginId)
|
||||
{
|
||||
Plugin *p = m_plugins->getPlugin(pluginId);
|
||||
if (!p) {
|
||||
qWarning()<< "Error: can't find plugin with id" << pluginId;
|
||||
return -1;
|
||||
}
|
||||
QVariantMap params;
|
||||
params.insert("pluginId", pluginId);
|
||||
QVariantList pluginParams;
|
||||
for (int i = 0; i < p->params()->rowCount(); i++) {
|
||||
pluginParams.append(packParam(p->params()->get(i)));
|
||||
}
|
||||
params.insert("configuration", pluginParams);
|
||||
return m_jsonClient->sendCommand("Integrations.SetPluginConfiguration", params, this, "setPluginConfigResponse");
|
||||
}
|
||||
|
||||
ThingGroup *ThingManager::createGroup(Interface *interface, ThingsProxy *things)
|
||||
{
|
||||
ThingGroup* group = new ThingGroup(this, interface->createThingClass(), things, this);
|
||||
|
|
|
|||
|
|
@ -107,7 +107,6 @@ private:
|
|||
Q_INVOKABLE void getVendorsResponse(int commandId, const QVariantMap ¶ms);
|
||||
Q_INVOKABLE void getThingClassesResponse(int commandId, const QVariantMap ¶ms);
|
||||
Q_INVOKABLE void getPluginsResponse(int commandId, const QVariantMap ¶ms);
|
||||
Q_INVOKABLE void getPluginConfigResponse(int commandId, const QVariantMap ¶ms);
|
||||
Q_INVOKABLE void getThingsResponse(int commandId, const QVariantMap ¶ms);
|
||||
Q_INVOKABLE void addThingResponse(int commandId, const QVariantMap ¶ms);
|
||||
Q_INVOKABLE void removeThingResponse(int commandId, const QVariantMap ¶ms);
|
||||
|
|
@ -126,8 +125,6 @@ private:
|
|||
Q_INVOKABLE void disconnectIOResponse(int commandId, const QVariantMap ¶ms);
|
||||
|
||||
public slots:
|
||||
int savePluginConfig(const QUuid &pluginId);
|
||||
|
||||
ThingGroup* createGroup(Interface *interface, ThingsProxy *things);
|
||||
|
||||
signals:
|
||||
|
|
@ -177,8 +174,6 @@ private:
|
|||
|
||||
bool m_fetchingData = true;
|
||||
|
||||
int m_currentGetConfigIndex = 0;
|
||||
|
||||
JsonRpcClient *m_jsonClient = nullptr;
|
||||
|
||||
QHash<int, QPointer<BrowserItems> > m_browsingRequests;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
Plugin::Plugin(QObject *parent) : QObject(parent)
|
||||
{
|
||||
m_params = new Params(this);
|
||||
|
||||
}
|
||||
|
||||
QString Plugin::name() const
|
||||
|
|
@ -64,14 +64,3 @@ void Plugin::setParamTypes(ParamTypes *paramTypes)
|
|||
{
|
||||
m_paramTypes = paramTypes;
|
||||
}
|
||||
|
||||
Params *Plugin::params()
|
||||
{
|
||||
return m_params;
|
||||
}
|
||||
|
||||
void Plugin::setParams(Params *params)
|
||||
{
|
||||
m_params = params;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ class Plugin : public QObject
|
|||
Q_PROPERTY(QString name READ name CONSTANT)
|
||||
Q_PROPERTY(QUuid pluginId READ pluginId CONSTANT)
|
||||
Q_PROPERTY(ParamTypes *paramTypes READ paramTypes CONSTANT)
|
||||
Q_PROPERTY(Params *params READ params CONSTANT)
|
||||
|
||||
public:
|
||||
explicit Plugin(QObject *parent = 0);
|
||||
|
|
@ -57,14 +56,10 @@ public:
|
|||
ParamTypes *paramTypes();
|
||||
void setParamTypes(ParamTypes *paramTypes);
|
||||
|
||||
Params *params();
|
||||
void setParams(Params *params);
|
||||
|
||||
private:
|
||||
QString m_name;
|
||||
QUuid m_pluginId;
|
||||
ParamTypes *m_paramTypes = nullptr;
|
||||
Params *m_params = nullptr;
|
||||
};
|
||||
|
||||
#endif // PLUGIN_H
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ SettingsPageBase {
|
|||
HeaderButton {
|
||||
imageSource: "../images/tick.svg"
|
||||
onClicked: {
|
||||
engine.thingManager.savePluginConfig(root.plugin.pluginId)
|
||||
pluginConfigManager.savePluginConfig()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -66,17 +66,23 @@ SettingsPageBase {
|
|||
}
|
||||
}
|
||||
|
||||
PluginConfigManager {
|
||||
id: pluginConfigManager
|
||||
engine: _engine
|
||||
plugin: root.plugin
|
||||
}
|
||||
|
||||
SettingsPageSectionHeader {
|
||||
text: qsTr("Settings")
|
||||
}
|
||||
|
||||
Repeater {
|
||||
model: plugin.paramTypes
|
||||
model: pluginConfigManager.params
|
||||
|
||||
delegate: ParamDelegate {
|
||||
Layout.fillWidth: true
|
||||
paramType: root.plugin.paramTypes.get(index)
|
||||
param: root.plugin.params.getParam(model.id)
|
||||
paramType: root.plugin.paramTypes.getParamType(model.id)
|
||||
param: pluginConfigManager.params.getParam(model.id)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,6 +51,22 @@ SettingsPageBase {
|
|||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
Layout.fillWidth: true
|
||||
Layout.margins: Style.margins
|
||||
text: qsTr("Install more plugins")
|
||||
visible: packagesFilterModel.count > 0
|
||||
onClicked: {
|
||||
pageStack.push(Qt.resolvedUrl("PackageListPage.qml"), {filter: "nymea-plugin"})
|
||||
}
|
||||
PackagesFilterModel {
|
||||
id: packagesFilterModel
|
||||
packages: engine.systemController.packages
|
||||
nameFilter: "nymea-plugin"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SettingsPageSectionHeader {
|
||||
text: qsTr("Installed integration plugins")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue