From 2d41671b2bd13aa555fea2330fd8fa3bd349beca Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Wed, 20 Jun 2018 22:30:58 +0200 Subject: [PATCH] hide features which aren't implemented in the core yet --- libmea-core/jsonrpc/jsonrpcclient.cpp | 33 +++- libmea-core/jsonrpc/jsonrpcclient.h | 12 ++ mea/resources.qrc | 3 + mea/ui/AppSettingsPage.qml | 21 +-- mea/ui/SettingsPage.qml | 42 ++--- mea/ui/components/MeaListItemDelegate.qml | 1 + mea/ui/images/logs.svg | 177 ++++++++++++++++++++++ mea/ui/images/plugin.svg | 164 ++++++++++++++++++++ mea/ui/magic/EditRulePage.qml | 15 +- mea/ui/system/AboutNymeaPage.qml | 39 +++++ mea/ui/system/PluginsPage.qml | 16 +- 11 files changed, 457 insertions(+), 66 deletions(-) create mode 100644 mea/ui/images/logs.svg create mode 100644 mea/ui/images/plugin.svg create mode 100644 mea/ui/system/AboutNymeaPage.qml diff --git a/libmea-core/jsonrpc/jsonrpcclient.cpp b/libmea-core/jsonrpc/jsonrpcclient.cpp index 7fa7bf4f..6a8938ae 100644 --- a/libmea-core/jsonrpc/jsonrpcclient.cpp +++ b/libmea-core/jsonrpc/jsonrpcclient.cpp @@ -134,6 +134,21 @@ bool JsonRpcClient::pushButtonAuthAvailable() const return m_pushButtonAuthAvailable; } +QString JsonRpcClient::serverVersion() const +{ + return m_serverVersion; +} + +QString JsonRpcClient::jsonRpcVersion() const +{ + return m_jsonRpcVersion.toString(); +} + +QString JsonRpcClient::serverUuid() const +{ + return m_serverUuid; +} + int JsonRpcClient::createUser(const QString &username, const QString &password) { QVariantMap params; @@ -168,6 +183,10 @@ int JsonRpcClient::requestPushButtonAuth(const QString &deviceName) return reply->commandId(); } +bool JsonRpcClient::ensureServerVersion(const QString &jsonRpcVersion) +{ + return QVersionNumber(m_jsonRpcVersion) >= QVersionNumber::fromString(jsonRpcVersion); +} void JsonRpcClient::processAuthenticate(const QVariantMap &data) { @@ -274,24 +293,28 @@ void JsonRpcClient::dataReceived(const QByteArray &data) m_initialSetupRequired = dataMap.value("initialSetupRequired").toBool(); m_authenticationRequired = dataMap.value("authenticationRequired").toBool(); m_pushButtonAuthAvailable = dataMap.value("pushButtonAuthAvailable").toBool(); + emit pushButtonAuthAvailableChanged(); + qDebug() << "Handshake received" << "initRequired:" << m_initialSetupRequired << "authRequired:" << m_authenticationRequired << "pushButtonAvailable:" << m_pushButtonAuthAvailable;; m_serverUuid = dataMap.value("uuid").toString(); - emit pushButtonAuthAvailableChanged(); + m_serverVersion = dataMap.value("version").toString(); QString protoVersionString = dataMap.value("protocol version").toString(); if (!protoVersionString.contains('.')) { protoVersionString.prepend("0."); } + m_jsonRpcVersion = QVersionNumber::fromString(protoVersionString); QVersionNumber minimumRequiredVersion = QVersionNumber(1, 0); - QVersionNumber protocolVersion = QVersionNumber::fromString(protoVersionString); - if (protocolVersion < minimumRequiredVersion) { - qWarning() << "Nymea box doesn't support minimum required version. Required:" << minimumRequiredVersion << "Found:" << protocolVersion; + if (m_jsonRpcVersion < minimumRequiredVersion) { + qWarning() << "Nymea box doesn't support minimum required version. Required:" << minimumRequiredVersion << "Found:" << m_jsonRpcVersion; m_connection->disconnect(); - emit invalidProtocolVersion(protocolVersion.toString(), minimumRequiredVersion.toString()); + emit invalidProtocolVersion(m_jsonRpcVersion.toString(), minimumRequiredVersion.toString()); return; } + emit handshakeReceived(); + if (m_initialSetupRequired) { emit initialSetupRequiredChanged(); return; diff --git a/libmea-core/jsonrpc/jsonrpcclient.h b/libmea-core/jsonrpc/jsonrpcclient.h index f8ced86b..8256dd19 100644 --- a/libmea-core/jsonrpc/jsonrpcclient.h +++ b/libmea-core/jsonrpc/jsonrpcclient.h @@ -24,6 +24,7 @@ #include #include #include +#include #include "nymeaconnection.h" #include "jsonhandler.h" @@ -39,6 +40,9 @@ class JsonRpcClient : public JsonHandler Q_PROPERTY(bool initialSetupRequired READ initialSetupRequired NOTIFY initialSetupRequiredChanged) Q_PROPERTY(bool authenticationRequired READ authenticationRequired NOTIFY authenticationRequiredChanged) Q_PROPERTY(bool pushButtonAuthAvailable READ pushButtonAuthAvailable NOTIFY pushButtonAuthAvailableChanged) + Q_PROPERTY(QString serverVersion READ serverVersion NOTIFY handshakeReceived) + Q_PROPERTY(QString jsonRpcVersion READ jsonRpcVersion NOTIFY handshakeReceived) + Q_PROPERTY(QString serverUuid READ serverUuid NOTIFY handshakeReceived) public: explicit JsonRpcClient(NymeaConnection *connection, QObject *parent = 0); @@ -56,13 +60,19 @@ public: bool authenticationRequired() const; bool pushButtonAuthAvailable() const; + QString serverVersion() const; + QString jsonRpcVersion() const; + QString serverUuid() const; + // ui methods Q_INVOKABLE int createUser(const QString &username, const QString &password); Q_INVOKABLE int authenticate(const QString &username, const QString &password, const QString &deviceName); Q_INVOKABLE int requestPushButtonAuth(const QString &deviceName); + Q_INVOKABLE bool ensureServerVersion(const QString &jsonRpcVersion); signals: + void handshakeReceived(); void initialSetupRequiredChanged(); void authenticationRequiredChanged(); void pushButtonAuthAvailableChanged(); @@ -94,6 +104,8 @@ private: bool m_pushButtonAuthAvailable = false; int m_pendingPushButtonTransaction = -1; QString m_serverUuid; + QVersionNumber m_jsonRpcVersion; + QString m_serverVersion; QByteArray m_token; QByteArray m_receiveBuffer; diff --git a/mea/resources.qrc b/mea/resources.qrc index 834fe50d..acdddf38 100644 --- a/mea/resources.qrc +++ b/mea/resources.qrc @@ -202,5 +202,8 @@ ui/components/MeaListItemDelegate.qml ui/images/state-interface.svg ui/images/action-interface.svg + ui/system/AboutNymeaPage.qml + ui/images/logs.svg + ui/images/plugin.svg diff --git a/mea/ui/AppSettingsPage.qml b/mea/ui/AppSettingsPage.qml index 9dec1e83..e44057f3 100644 --- a/mea/ui/AppSettingsPage.qml +++ b/mea/ui/AppSettingsPage.qml @@ -110,24 +110,11 @@ Page { } } ThinDivider {} - ItemDelegate { + MeaListItemDelegate { Layout.fillWidth: true - - contentItem: RowLayout { - Label { - Layout.fillWidth: true - text: qsTr("About %1").arg(app.appName) - } - Image { - source: "images/next.svg" - Layout.preferredHeight: parent.height - Layout.preferredWidth: height - } - } - - onClicked: { - pageStack.push(Qt.resolvedUrl("AboutPage.qml")) - } + text: qsTr("About %1").arg(app.appName) + iconName: "../images/info.svg" + onClicked: pageStack.push(Qt.resolvedUrl("AboutPage.qml")) } } diff --git a/mea/ui/SettingsPage.qml b/mea/ui/SettingsPage.qml index 4a928968..74462dac 100644 --- a/mea/ui/SettingsPage.qml +++ b/mea/ui/SettingsPage.qml @@ -89,41 +89,25 @@ Page { } - ItemDelegate { + MeaListItemDelegate { Layout.fillWidth: true - contentItem: RowLayout { - Label { - Layout.fillWidth: true - text: qsTr("Plugins") - } - Image { - source: "images/next.svg" - Layout.preferredHeight: parent.height - Layout.preferredWidth: height - } - } - onClicked: { - pageStack.push(Qt.resolvedUrl("system/PluginsPage.qml")) - } + iconName: "../images/plugin.svg" + text: qsTr("Plugins") + onClicked:pageStack.push(Qt.resolvedUrl("system/PluginsPage.qml")) } - ItemDelegate { + MeaListItemDelegate { Layout.fillWidth: true - contentItem: RowLayout { - Label { - text: qsTr("Log viewer") - Layout.fillWidth: true - } - Image { - source: "images/next.svg" - Layout.preferredHeight: parent.height - Layout.preferredWidth: height - } - } - + iconName: "../images/logs.svg" + text: qsTr("Log viewer") onClicked: pageStack.push(Qt.resolvedUrl("system/LogViewerPage.qml")) } - + MeaListItemDelegate { + Layout.fillWidth: true + iconName: "../images/info.svg" + text: qsTr("About nymea") + onClicked: pageStack.push(Qt.resolvedUrl("system/AboutNymeaPage.qml")) + } } Component { diff --git a/mea/ui/components/MeaListItemDelegate.qml b/mea/ui/components/MeaListItemDelegate.qml index c29f0b16..55131509 100644 --- a/mea/ui/components/MeaListItemDelegate.qml +++ b/mea/ui/components/MeaListItemDelegate.qml @@ -23,6 +23,7 @@ SwipeDelegate { Layout.preferredWidth: height name: root.iconName color: root.iconColor + visible: root.iconName } ColumnLayout { Layout.fillWidth: true diff --git a/mea/ui/images/logs.svg b/mea/ui/images/logs.svg new file mode 100644 index 00000000..4110f70e --- /dev/null +++ b/mea/ui/images/logs.svg @@ -0,0 +1,177 @@ + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + diff --git a/mea/ui/images/plugin.svg b/mea/ui/images/plugin.svg new file mode 100644 index 00000000..8a885ea0 --- /dev/null +++ b/mea/ui/images/plugin.svg @@ -0,0 +1,164 @@ + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + diff --git a/mea/ui/magic/EditRulePage.qml b/mea/ui/magic/EditRulePage.qml index f53ed139..9443da3c 100644 --- a/mea/ui/magic/EditRulePage.qml +++ b/mea/ui/magic/EditRulePage.qml @@ -521,16 +521,19 @@ Page { iconName: "../images/event.svg" text: qsTr("When one of my things triggers an event") method: "addEventDescriptor" + minimumJsonRpcVersion: "1.0" } ListElement { iconName: "../images/event-interface.svg" text: qsTr("When a thing of a given type triggers an event") method: "addInterfaceEventDescriptor" + minimumJsonRpcVersion: "1.5" } ListElement { iconName: "../images/alarm-clock.svg" text: qsTr("At a particular time or date") method: "addTimeEventItem" + minimumJsonRpcVersion: "1.0" } } delegate: MeaListItemDelegate { @@ -539,6 +542,7 @@ Page { text: model.text progressive: true iconSize: app.iconSize * 2 + visible: Engine.jsonRpcClient.ensureServerVersion(model.minimumJsonRpcVersion) onClicked: { root[model.method]() @@ -567,17 +571,19 @@ Page { iconName: "../images/state.svg" text: qsTr("When one of my things is in a certain state") method: "createStateEvaluator" - + minimumJsonRpcVersion: "1.0" } ListElement { iconName: "../images/state-interface.svg" text: qsTr("When a thing of a given type enters a state") method: "createInterfaceStateEvaluator" + minimumJsonRpcVersion: "1.5" } ListElement { iconName: "../images/clock-app-symbolic.svg" text: qsTr("During a given time") method: "addCalendarItem" + minimumJsonRpcVersion: "1.0" } } delegate: MeaListItemDelegate { @@ -586,6 +592,7 @@ Page { text: model.text progressive: true iconSize: app.iconSize * 2 + visible: Engine.jsonRpcClient.ensureServerVersion(model.minimumJsonRpcVersion) onClicked: { root[model.method]() @@ -618,24 +625,28 @@ Page { text: qsTr("Execute an action on of my things") method: "addRuleAction" isExitAction: false + minimumJsonRpcVersion: "1.0" } ListElement { iconName: "../images/action-interface.svg" text: qsTr("Execute an action on an entire kind of things") method: "addInterfaceRuleAction" isExitAction: false + minimumJsonRpcVersion: "1.5" } ListElement { iconName: "../images/action.svg" text: qsTr("Execute an action on of my things") method: "addRuleExitAction" isExitAction: true + minimumJsonRpcVersion: "1.0" } ListElement { iconName: "../images/action-interface.svg" text: qsTr("Execute an action on an entire kind of things") method: "addInterfaceRuleExitAction" isExitAction: true + minimumJsonRpcVersion: "1.5" } } delegate: MeaListItemDelegate { @@ -644,7 +655,7 @@ Page { text: model.text progressive: true iconSize: app.iconSize * 2 - visible: ruleActionQuestionPage.exitAction === model.isExitAction + visible: ruleActionQuestionPage.exitAction === model.isExitAction && Engine.jsonRpcClient.ensureServerVersion(model.minimumJsonRpcVersion) onClicked: { root[model.method]() diff --git a/mea/ui/system/AboutNymeaPage.qml b/mea/ui/system/AboutNymeaPage.qml new file mode 100644 index 00000000..d819cf3e --- /dev/null +++ b/mea/ui/system/AboutNymeaPage.qml @@ -0,0 +1,39 @@ +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Layouts 1.3 +import Mea 1.0 +import "../components" + +Page { + + id: root + header: GuhHeader { + text: qsTr("About %1").arg(app.systemName) + onBackPressed: pageStack.pop() + } + + ColumnLayout { + anchors { left: parent.left; top: parent.top; right: parent.right } + + MeaListItemDelegate { + Layout.fillWidth: true + text: qsTr("Server UUID:") + subText: Engine.jsonRpcClient.serverUuid + progressive: false + } + + MeaListItemDelegate { + Layout.fillWidth: true + text: qsTr("Server version:") + subText: Engine.jsonRpcClient.serverVersion + progressive: false + } + + MeaListItemDelegate { + Layout.fillWidth: true + text: qsTr("Protocol version:") + subText: Engine.jsonRpcClient.jsonRpcVersion + progressive: false + } + } +} diff --git a/mea/ui/system/PluginsPage.qml b/mea/ui/system/PluginsPage.qml index aa7c7f84..3dcaf7e4 100644 --- a/mea/ui/system/PluginsPage.qml +++ b/mea/ui/system/PluginsPage.qml @@ -18,21 +18,11 @@ Page { model: Engine.deviceManager.plugins clip: true - delegate: ItemDelegate { + delegate: MeaListItemDelegate { width: parent.width - contentItem: RowLayout { - Label { - Layout.fillWidth: true - text: model.name - } - Image { - source: "../images/next.svg" - Layout.preferredHeight: parent.height - Layout.preferredWidth: height - } - } + iconName: "../images/plugin.svg" + text: model.name onClicked: pageStack.push(Qt.resolvedUrl("PluginParamsPage.qml"), {plugin: Engine.deviceManager.plugins.get(index)}) } } - }