diff --git a/nymea-app/resources.qrc b/nymea-app/resources.qrc
index 5de82b1e..8978990b 100644
--- a/nymea-app/resources.qrc
+++ b/nymea-app/resources.qrc
@@ -212,5 +212,6 @@
ui/mainviews/DevicesPageDelegate.qml
ui/components/AutoSizeMenu.qml
ui/components/EmptyViewPlaceholder.qml
+ ui/components/RemoveDeviceMethodDialog.qml
diff --git a/nymea-app/ui/EditDevicesPage.qml b/nymea-app/ui/EditDevicesPage.qml
index d430a5d3..d5a6efa9 100644
--- a/nymea-app/ui/EditDevicesPage.qml
+++ b/nymea-app/ui/EditDevicesPage.qml
@@ -17,6 +17,34 @@ Page {
}
}
+ QtObject {
+ id: d
+ property var deviceToRemove: null
+ }
+
+ Connections {
+ target: Engine.deviceManager
+ onRemoveDeviceReply: {
+ if (!d.deviceToRemove) {
+ return;
+ }
+
+ switch (params.deviceError) {
+ case "DeviceErrorNoError":
+ d.deviceToRemove = null;
+ return;
+ case "DeviceErrorDeviceInRule":
+ var removeMethodComponent = Qt.createComponent(Qt.resolvedUrl("components/RemoveDeviceMethodDialog.qml"))
+ var popup = removeMethodComponent.createObject(root, {device: d.deviceToRemove, rulesList: params["ruleIds"]});
+ popup.open();
+ return;
+ default:
+ var popup = errorDialog.createObject(root, {errorCode: params.deviceError})
+ popup.open();
+ }
+ }
+ }
+
ListView {
anchors.fill: parent
model: Engine.deviceManager.devices
@@ -28,7 +56,8 @@ Page {
pageStack.push(Qt.resolvedUrl("devicepages/ConfigureThingPage.qml"), {device: Engine.deviceManager.devices.get(index)})
}
onDeleteClicked: {
- Engine.deviceManager.removeDevice(Engine.deviceManager.devices.get(index).id)
+ d.deviceToRemove = Engine.deviceManager.devices.get(index);
+ Engine.deviceManager.removeDevice(d.deviceToRemove.id)
}
}
}
diff --git a/nymea-app/ui/components/RemoveDeviceMethodDialog.qml b/nymea-app/ui/components/RemoveDeviceMethodDialog.qml
new file mode 100644
index 00000000..58b370df
--- /dev/null
+++ b/nymea-app/ui/components/RemoveDeviceMethodDialog.qml
@@ -0,0 +1,68 @@
+import QtQuick 2.9
+import QtQuick.Controls 2.2
+import QtQuick.Layouts 1.3
+import Nymea 1.0
+
+Dialog {
+ id: root
+ width: Math.min(parent.width * .8, contentLabel.implicitWidth + app.margins * 2)
+ x: (parent.width - width) / 2
+ y: (parent.height - height) / 2
+ modal: true
+
+ property var device: null
+ property var rulesList: null
+
+ ColumnLayout {
+ width: parent.width
+ Label {
+ id: contentLabel
+ text: qsTr("This thing is currently used in one or more rules:")
+ Layout.fillWidth: true
+ wrapMode: Text.WordWrap
+ }
+
+ ThinDivider {}
+ ListView {
+ Layout.fillWidth: true
+ Layout.preferredHeight: app.iconSize * Math.min(count, 5)
+ model: rulesList
+ interactive: contentHeight > height
+ delegate: Label {
+ height: app.iconSize
+ width: parent.width
+ elide: Text.ElideRight
+ text: Engine.ruleManager.rules.getRule(modelData).name
+ verticalAlignment: Text.AlignVCenter
+ }
+ }
+ ThinDivider {}
+
+ Button {
+ text: qsTr("Remove all those rules")
+ Layout.fillWidth: true
+ onClicked: {
+ Engine.deviceManager.removeDevice(root.device.id, DeviceManager.RemovePolicyCascade)
+ root.close()
+ root.destroy();
+ }
+ }
+ Button {
+ text: qsTr("Update rules, removing this thing")
+ Layout.fillWidth: true
+ onClicked: {
+ Engine.deviceManager.removeDevice(root.device.id, DeviceManager.RemovePolicyUpdate)
+ root.close()
+ root.destroy();
+ }
+ }
+ Button {
+ text: qsTr("Don't remove this thing")
+ Layout.fillWidth: true
+ onClicked: {
+ root.close()
+ root.destroy();
+ }
+ }
+ }
+}
diff --git a/nymea-app/ui/devicepages/ConfigureThingPage.qml b/nymea-app/ui/devicepages/ConfigureThingPage.qml
index 57dacc6b..b3ad8a8e 100644
--- a/nymea-app/ui/devicepages/ConfigureThingPage.qml
+++ b/nymea-app/ui/devicepages/ConfigureThingPage.qml
@@ -47,7 +47,7 @@ Page {
pageStack.pop();
return;
case "DeviceErrorDeviceInRule":
- var popup = removeMethodComponent.createObject(root, {rulesList: params["ruleIds"]});
+ var popup = removeMethodComponent.createObject(root, {device: root.device, rulesList: params["ruleIds"]});
popup.open();
return;
default:
@@ -117,67 +117,8 @@ Page {
Component {
id: removeMethodComponent
- Dialog {
- id: removeMethodDialog
- width: Math.min(parent.width * .8, contentLabel.implicitWidth + app.margins * 2)
- x: (parent.width - width) / 2
- y: (parent.height - height) / 2
- modal: true
+ RemoveDeviceMethodDialog {
- property var rulesList: null
-
- ColumnLayout {
- width: parent.width
- Label {
- id: contentLabel
- text: qsTr("This thing is currently used in one or more rules:")
- Layout.fillWidth: true
- wrapMode: Text.WordWrap
- }
-
- ThinDivider {}
- ListView {
- Layout.fillWidth: true
- Layout.preferredHeight: app.iconSize * Math.min(count, 5)
- model: rulesList
- interactive: contentHeight > height
- delegate: Label {
- height: app.iconSize
- width: parent.width
- elide: Text.ElideRight
- text: Engine.ruleManager.rules.getRule(modelData).name
- verticalAlignment: Text.AlignVCenter
- }
- }
- ThinDivider {}
-
- Button {
- text: qsTr("Remove all those rules")
- Layout.fillWidth: true
- onClicked: {
- Engine.deviceManager.removeDevice(root.device.id, DeviceManager.RemovePolicyCascade)
- removeMethodDialog.close()
- removeMethodDialog.destroy();
- }
- }
- Button {
- text: qsTr("Update rules, removing this thing")
- Layout.fillWidth: true
- onClicked: {
- Engine.deviceManager.removeDevice(root.device.id, DeviceManager.RemovePolicyUpdate)
- removeMethodDialog.close()
- removeMethodDialog.destroy();
- }
- }
- Button {
- text: qsTr("Don't remove this thing")
- Layout.fillWidth: true
- onClicked: {
- removeMethodDialog.close()
- removeMethodDialog.destroy();
- }
- }
- }
}
}
}