diff --git a/libnymea-app-core/devices.cpp b/libnymea-app-core/devices.cpp index f69a5f94..356f1375 100644 --- a/libnymea-app-core/devices.cpp +++ b/libnymea-app-core/devices.cpp @@ -72,6 +72,8 @@ QVariant Devices::data(const QModelIndex &index, int role) const return device->id().toString(); case RoleDeviceClass: return device->deviceClassId().toString(); + case RoleParentDeviceId: + return device->parentDeviceId().toString(); case RoleSetupComplete: return device->setupComplete(); case RoleInterfaces: @@ -133,6 +135,7 @@ QHash Devices::roleNames() const roles[RoleName] = "name"; roles[RoleId] = "id"; roles[RoleDeviceClass] = "deviceClassId"; + roles[RoleParentDeviceId] = "parentDeviceId"; roles[RoleSetupComplete] = "setupComplete"; roles[RoleInterfaces] = "interfaces"; roles[RoleBaseInterface] = "baseInterface"; diff --git a/libnymea-app-core/devices.h b/libnymea-app-core/devices.h index d0f350d2..50d959de 100644 --- a/libnymea-app-core/devices.h +++ b/libnymea-app-core/devices.h @@ -36,6 +36,7 @@ public: enum Roles { RoleName, RoleId, + RoleParentDeviceId, RoleDeviceClass, RoleSetupComplete, RoleInterfaces, diff --git a/libnymea-app-core/jsonrpc/jsontypes.cpp b/libnymea-app-core/jsonrpc/jsontypes.cpp index 42e5c65d..a35f72d2 100644 --- a/libnymea-app-core/jsonrpc/jsontypes.cpp +++ b/libnymea-app-core/jsonrpc/jsontypes.cpp @@ -221,11 +221,12 @@ Device* JsonTypes::unpackDevice(const QVariantMap &deviceMap, DeviceClasses *dev return nullptr; } + QUuid parentDeviceId = deviceMap.value("parentId").toUuid(); Device *device = nullptr; if (oldDevice) { device = oldDevice; } else { - device = new Device(deviceClass); + device = new Device(deviceClass, parentDeviceId); } device->setName(deviceMap.value("name").toString()); device->setId(deviceMap.value("id").toUuid()); diff --git a/libnymea-common/types/device.cpp b/libnymea-common/types/device.cpp index 29f400e1..4ecef5eb 100644 --- a/libnymea-common/types/device.cpp +++ b/libnymea-common/types/device.cpp @@ -25,8 +25,9 @@ #include -Device::Device(DeviceClass *deviceClass, QObject *parent) : +Device::Device(DeviceClass *deviceClass, const QUuid &parentDeviceId, QObject *parent) : QObject(parent), + m_parentDeviceId(parentDeviceId), m_deviceClass(deviceClass) { } @@ -57,6 +58,16 @@ QUuid Device::deviceClassId() const return m_deviceClass->id(); } +QUuid Device::parentDeviceId() const +{ + return m_parentDeviceId; +} + +bool Device::isChild() const +{ + return !m_parentDeviceId.isNull(); +} + bool Device::setupComplete() { return m_setupComplete; diff --git a/libnymea-common/types/device.h b/libnymea-common/types/device.h index 99a4388e..c6cdcc4f 100644 --- a/libnymea-common/types/device.h +++ b/libnymea-common/types/device.h @@ -37,6 +37,8 @@ class Device : public QObject Q_OBJECT Q_PROPERTY(QUuid id READ id CONSTANT) Q_PROPERTY(QUuid deviceClassId READ deviceClassId CONSTANT) + Q_PROPERTY(QUuid parentDeviceId READ parentDeviceId CONSTANT) + Q_PROPERTY(bool isChild READ isChild CONSTANT) Q_PROPERTY(QString name READ name NOTIFY nameChanged) Q_PROPERTY(bool setupComplete READ setupComplete NOTIFY setupCompleteChanged) Q_PROPERTY(Params *params READ params NOTIFY paramsChanged) @@ -45,7 +47,7 @@ class Device : public QObject Q_PROPERTY(DeviceClass *deviceClass READ deviceClass CONSTANT) public: - explicit Device(DeviceClass *deviceClass, QObject *parent = nullptr); + explicit Device(DeviceClass *deviceClass, const QUuid &parentDeviceId = QUuid(), QObject *parent = nullptr); QString name() const; void setName(const QString &name); @@ -54,6 +56,8 @@ public: void setId(const QUuid &id); QUuid deviceClassId() const; + QUuid parentDeviceId() const; + bool isChild() const; bool setupComplete(); void setSetupComplete(const bool &setupComplete); @@ -77,6 +81,7 @@ public: private: QString m_name; QUuid m_id; + QUuid m_parentDeviceId; bool m_setupComplete; Params *m_params = nullptr; Params *m_settings = nullptr; diff --git a/libnymea-common/types/params.cpp b/libnymea-common/types/params.cpp index 339afdc8..0997b8fc 100644 --- a/libnymea-common/types/params.cpp +++ b/libnymea-common/types/params.cpp @@ -89,6 +89,7 @@ void Params::addParam(Param *param) //qDebug() << "Params: loaded param" << param->name(); m_params.append(param); endInsertRows(); + emit countChanged(); } void Params::clearModel() @@ -96,6 +97,7 @@ void Params::clearModel() beginResetModel(); m_params.clear(); endResetModel(); + emit countChanged(); } QHash Params::roleNames() const diff --git a/libnymea-common/types/params.h b/libnymea-common/types/params.h index 27da733f..05dc86ac 100644 --- a/libnymea-common/types/params.h +++ b/libnymea-common/types/params.h @@ -30,13 +30,14 @@ class Params : public QAbstractListModel { Q_OBJECT + Q_PROPERTY(int count READ count NOTIFY countChanged) public: enum RoleId { RoleId, RoleValue }; - explicit Params(QObject *parent = 0); + explicit Params(QObject *parent = nullptr); QList params(); @@ -53,6 +54,9 @@ public: void clearModel(); +signals: + void countChanged(); + protected: QHash roleNames() const; diff --git a/nymea-app/translations/nymea-app-de.ts b/nymea-app/translations/nymea-app-de.ts index 00a2cd0d..1c499199 100644 --- a/nymea-app/translations/nymea-app-de.ts +++ b/nymea-app/translations/nymea-app-de.ts @@ -791,11 +791,11 @@ ConfigureThingPage Delete Thing - "Thing" löschen + "Thing" löschen Rename Thing - "Thing" umbenennen + "Thing" umbenennen Remove device error: %1 @@ -803,7 +803,7 @@ Thing parameters - "Thing" Parameter + "Thing" Parameter This thing is currently used in one or more rules: @@ -823,11 +823,11 @@ Reconfigure Thing - "Thing" neu einrichten + "Thing" neu einrichten Thing information - "Thing" Informationen + "Thing" Informationen Vendor: @@ -839,12 +839,36 @@ Thing settings - "Thing" einstellungen + "Thing" einstellungen Apply Anwenden + + Rename + Umbenennen + + + Delete + Löschen + + + Reconfigure + Neu einrichten + + + Information + Informationen + + + Parameters + Parameter + + + Settings + Einstellungen + ConnectPage @@ -1289,7 +1313,7 @@ Thing details - Details + Details Mark as favorite @@ -1301,7 +1325,19 @@ Thing logs - "Thing" Protokoll + "Thing" Protokoll + + + Details + Details + + + Settings + Einstellungen + + + Logs + Protokoll diff --git a/nymea-app/translations/nymea-app-en.ts b/nymea-app/translations/nymea-app-en.ts index 5711de6a..c5704b10 100644 --- a/nymea-app/translations/nymea-app-en.ts +++ b/nymea-app/translations/nymea-app-en.ts @@ -569,22 +569,6 @@ ConfigureThingPage - - Delete Thing - - - - Rename Thing - - - - Reconfigure Thing - - - - Thing information - - Vendor: @@ -593,18 +577,34 @@ Type - - Thing parameters - - - - Thing settings - - Apply + + Rename + + + + Delete + + + + Reconfigure + + + + Information + + + + Parameters + + + + Settings + + ConnectPage @@ -875,14 +875,6 @@ Magic - - Thing details - - - - Thing logs - - Mark as favorite @@ -899,6 +891,18 @@ Thing runs out of battery! + + Details + + + + Settings + + + + Logs + + DeviceRulesPage diff --git a/nymea-app/translations/nymea-app-en_US.ts b/nymea-app/translations/nymea-app-en_US.ts index 5711de6a..c5704b10 100644 --- a/nymea-app/translations/nymea-app-en_US.ts +++ b/nymea-app/translations/nymea-app-en_US.ts @@ -569,22 +569,6 @@ ConfigureThingPage - - Delete Thing - - - - Rename Thing - - - - Reconfigure Thing - - - - Thing information - - Vendor: @@ -593,18 +577,34 @@ Type - - Thing parameters - - - - Thing settings - - Apply + + Rename + + + + Delete + + + + Reconfigure + + + + Information + + + + Parameters + + + + Settings + + ConnectPage @@ -875,14 +875,6 @@ Magic - - Thing details - - - - Thing logs - - Mark as favorite @@ -899,6 +891,18 @@ Thing runs out of battery! + + Details + + + + Settings + + + + Logs + + DeviceRulesPage diff --git a/nymea-app/translations/nymea-app-ko.ts b/nymea-app/translations/nymea-app-ko.ts index f97d9a3a..11500825 100644 --- a/nymea-app/translations/nymea-app-ko.ts +++ b/nymea-app/translations/nymea-app-ko.ts @@ -568,19 +568,19 @@ ConfigureThingPage Delete Thing - 삭제하기 + 삭제하기 Rename Thing - 이름 바꾸기 + 이름 바꾸기 Reconfigure Thing - 재설정 + 재설정 Thing information - 사물(장치) 정보 + 사물(장치) 정보 Vendor: @@ -592,16 +592,40 @@ Thing parameters - 사물(장치) 매개변수 + 사물(장치) 매개변수 Thing settings - 사물(장치) 설정 + 사물(장치) 설정 Apply 적용 + + Rename + + + + Delete + + + + Reconfigure + + + + Information + + + + Parameters + + + + Settings + 설정 + ConnectPage @@ -874,11 +898,11 @@ Thing details - 세부 정보 + 세부 정보 Thing logs - 사물 기록 + 사물 기록 Mark as favorite @@ -896,6 +920,18 @@ Thing runs out of battery! 배터리가 다 됐네요! + + Details + + + + Settings + 설정 + + + Logs + + DeviceRulesPage diff --git a/nymea-app/ui/customviews/GenericTypeLogView.qml b/nymea-app/ui/customviews/GenericTypeLogView.qml index 98364481..1706a509 100644 --- a/nymea-app/ui/customviews/GenericTypeLogView.qml +++ b/nymea-app/ui/customviews/GenericTypeLogView.qml @@ -53,7 +53,7 @@ Item { } Label { Layout.fillWidth: true - text: "%1: %2".arg(deviceClass.eventTypes.getEventType(model.typeId).displayName).arg(model.value.trim()) + text: deviceClass.eventTypes.getEventType(model.typeId).displayName + (model.value.length > 0 ? (": " + model.value.trim()) : "") elide: Text.ElideRight font.pixelSize: app.smallFont } diff --git a/nymea-app/ui/devicepages/DevicePageBase.qml b/nymea-app/ui/devicepages/DevicePageBase.qml index 478e609a..016c8360 100644 --- a/nymea-app/ui/devicepages/DevicePageBase.qml +++ b/nymea-app/ui/devicepages/DevicePageBase.qml @@ -56,10 +56,11 @@ Page { thingMenu.addItem(menuEntryComponent.createObject(thingMenu, {text: qsTr("Magic"), iconSource: "../images/magic.svg", functionName: "openDeviceMagicPage"})) if (root.showDetailsButton) { - thingMenu.addItem(menuEntryComponent.createObject(thingMenu, {text: qsTr("Thing details"), iconSource: "../images/configure.svg", functionName: "openGenericDevicePage"})) + thingMenu.addItem(menuEntryComponent.createObject(thingMenu, {text: qsTr("Details"), iconSource: "../images/info.svg", functionName: "openGenericDevicePage"})) } + thingMenu.addItem(menuEntryComponent.createObject(thingMenu, {text: qsTr("Settings"), iconSource: "../images/configure.svg", functionName: "openThingSettingsPage"})) if (root.showLogsButton) { - thingMenu.addItem(menuEntryComponent.createObject(thingMenu, {text: qsTr("Thing logs"), iconSource: "../images/logs.svg", functionName: "openDeviceLogPage"})) + thingMenu.addItem(menuEntryComponent.createObject(thingMenu, {text: qsTr("Logs"), iconSource: "../images/logs.svg", functionName: "openDeviceLogPage"})) } if (engine.jsonRpcClient.ensureServerVersion(1.6)) { @@ -84,6 +85,10 @@ Page { engine.tagsManager.untagDevice(root.device.id, "favorites") } } + function openThingSettingsPage() { + pageStack.push(Qt.resolvedUrl("../thingconfiguration/ConfigureThingPage.qml"), {device: root.device}) + } + function openDeviceLogPage() { pageStack.push(Qt.resolvedUrl("DeviceLogPage.qml"), {device: root.device }); } diff --git a/nymea-app/ui/thingconfiguration/ConfigureThingPage.qml b/nymea-app/ui/thingconfiguration/ConfigureThingPage.qml index 72f6b0af..56167421 100644 --- a/nymea-app/ui/thingconfiguration/ConfigureThingPage.qml +++ b/nymea-app/ui/thingconfiguration/ConfigureThingPage.qml @@ -24,26 +24,36 @@ Page { id: deviceMenu width: implicitWidth + app.margins x: parent.width - width - IconMenuItem { - iconSource: "../images/delete.svg" - text: qsTr("Delete Thing") - onTriggered: engine.deviceManager.removeDevice(root.device.id) - } - IconMenuItem { - iconSource: "../images/edit.svg" - text: qsTr("Rename Thing") - onTriggered: { - var popup = renameDialog.createObject(root); - popup.open(); + + Component.onCompleted: { + deviceMenu.addItem(menuEntryComponent.createObject(deviceMenu, {text: qsTr("Rename"), iconSource: "../images/edit.svg", functionName: "renameThing"})) + if (!root.device.isChild) { + deviceMenu.addItem(menuEntryComponent.createObject(deviceMenu, {text: qsTr("Delete"), iconSource: "../images/delete.svg", functionName: "deleteThing"})) + } + if (!root.device.isChild) { + deviceMenu.addItem(menuEntryComponent.createObject(deviceMenu, {text: qsTr("Reconfigure"), iconSource: "../images/configure.svg", functionName: "reconfigureThing"})) } } - IconMenuItem { - iconSource: "../images/configure.svg" - text: qsTr("Reconfigure Thing") - visible: root.device.deviceClass.paramTypes.count > 0 - onTriggered: { - var configPage = pageStack.push(Qt.resolvedUrl("SetupWizard.qml"), {device: root.device}) - configPage.done.connect(function() {pageStack.pop(root)}) + + function renameThing() { + var popup = renameDialog.createObject(root); + popup.open(); + } + + function deleteThing() { + engine.deviceManager.removeDevice(root.device.id) + } + + function reconfigureThing() { + var configPage = pageStack.push(Qt.resolvedUrl("SetupWizard.qml"), {device: root.device}) + configPage.done.connect(function() {pageStack.pop(root)}) + } + + Component { + id: menuEntryComponent + IconMenuItem { + property string functionName: "" + onTriggered: deviceMenu[functionName]() } } } @@ -77,7 +87,7 @@ Page { Label { Layout.fillWidth: true Layout.margins: app.margins - text: qsTr("Thing information") + text: qsTr("Information") color: app.accentColor } RowLayout { @@ -106,7 +116,7 @@ Page { Layout.leftMargin: app.margins Layout.rightMargin: app.margins Layout.topMargin: app.margins - text: qsTr("Thing parameters") + text: qsTr("Parameters") color: app.accentColor visible: root.deviceClass.paramTypes.count > 0 } @@ -126,7 +136,7 @@ Page { Layout.leftMargin: app.margins Layout.rightMargin: app.margins Layout.topMargin: app.margins - text: qsTr("Thing settings") + text: qsTr("Settings") color: app.accentColor visible: root.deviceClass.settingsTypes.count > 0 }