add device remove policy support
This commit is contained in:
parent
38d3a59409
commit
e79e89d946
@ -343,11 +343,15 @@ void DeviceManager::confirmPairing(const QUuid &pairingTransactionId, const QStr
|
||||
m_jsonClient->sendCommand("Devices.ConfirmPairing", params, this, "confirmPairingResponse");
|
||||
}
|
||||
|
||||
void DeviceManager::removeDevice(const QUuid &deviceId)
|
||||
void DeviceManager::removeDevice(const QUuid &deviceId, RemovePolicy removePolicy)
|
||||
{
|
||||
qDebug() << "JsonRpc: delete device" << deviceId.toString();
|
||||
QVariantMap params;
|
||||
params.insert("deviceId", deviceId.toString());
|
||||
if (removePolicy != RemovePolicyNone) {
|
||||
QMetaEnum policyEnum = QMetaEnum::fromType<DeviceManager::RemovePolicy>();
|
||||
params.insert("removePolicy", policyEnum.valueToKey(removePolicy));
|
||||
}
|
||||
m_jsonClient->sendCommand("Devices.RemoveConfiguredDevice", params, this, "removeDeviceResponse");
|
||||
}
|
||||
|
||||
|
||||
@ -41,6 +41,13 @@ class DeviceManager : public JsonHandler
|
||||
Q_PROPERTY(bool fetchingData READ fetchingData NOTIFY fetchingDataChanged)
|
||||
|
||||
public:
|
||||
enum RemovePolicy {
|
||||
RemovePolicyNone,
|
||||
RemovePolicyCascade,
|
||||
RemovePolicyUpdate
|
||||
};
|
||||
Q_ENUM(RemovePolicy)
|
||||
|
||||
explicit DeviceManager(JsonRpcClient *jsonclient, QObject *parent = 0);
|
||||
|
||||
void clear();
|
||||
@ -59,7 +66,7 @@ public:
|
||||
Q_INVOKABLE void addDiscoveredDevice(const QUuid &deviceClassId, const QUuid &deviceDescriptorId, const QString &name);
|
||||
Q_INVOKABLE void pairDevice(const QUuid &deviceClassId, const QUuid &deviceDescriptorId, const QString &name);
|
||||
Q_INVOKABLE void confirmPairing(const QUuid &pairingTransactionId, const QString &secret = QString());
|
||||
Q_INVOKABLE void removeDevice(const QUuid &deviceId);
|
||||
Q_INVOKABLE void removeDevice(const QUuid &deviceId, RemovePolicy policy = RemovePolicyNone);
|
||||
Q_INVOKABLE void editDevice(const QUuid &deviceId, const QString &name);
|
||||
Q_INVOKABLE void executeAction(const QUuid &deviceId, const QUuid &actionTypeId, const QVariantList ¶ms = QVariantList());
|
||||
|
||||
|
||||
@ -254,7 +254,7 @@ void JsonRpcClient::dataReceived(const QByteArray &data)
|
||||
// qWarning() << "Could not parse json data from mea" << data << error.errorString();
|
||||
return;
|
||||
}
|
||||
// qDebug() << "received response" << m_receiveBuffer.left(splitIndex);
|
||||
qDebug() << "received response" << m_receiveBuffer.left(splitIndex);
|
||||
m_receiveBuffer = m_receiveBuffer.right(m_receiveBuffer.length() - splitIndex - 1);
|
||||
if (!m_receiveBuffer.isEmpty()) {
|
||||
staticMetaObject.invokeMethod(this, "dataReceived", Qt::QueuedConnection, Q_ARG(QByteArray, QByteArray()));
|
||||
|
||||
@ -140,7 +140,7 @@ void RuleManager::getRuleDetailsReply(const QVariantMap ¶ms)
|
||||
qDebug() << "Got rule details for a rule we don't know";
|
||||
return;
|
||||
}
|
||||
// qDebug() << "got rule details for rule" << ruleMap;
|
||||
qDebug() << "got rule details for rule" << ruleMap;
|
||||
parseEventDescriptors(ruleMap.value("eventDescriptors").toList(), rule);
|
||||
parseRuleActions(ruleMap.value("actions").toList(), rule);
|
||||
parseRuleExitActions(ruleMap.value("exitActions").toList(), rule);
|
||||
@ -157,6 +157,7 @@ void RuleManager::onAddRuleReply(const QVariantMap ¶ms)
|
||||
void RuleManager::removeRuleReply(const QVariantMap ¶ms)
|
||||
{
|
||||
qDebug() << "Have remove rule reply" << params;
|
||||
|
||||
}
|
||||
|
||||
void RuleManager::onEditRuleReply(const QVariantMap ¶ms)
|
||||
|
||||
@ -42,12 +42,18 @@ Page {
|
||||
Connections {
|
||||
target: Engine.deviceManager
|
||||
onRemoveDeviceReply: {
|
||||
if (params.deviceError === "DeviceErrorNoError") {
|
||||
switch (params.deviceError) {
|
||||
case "DeviceErrorNoError":
|
||||
pageStack.pop();
|
||||
return;
|
||||
case "DeviceErrorDeviceInRule":
|
||||
var popup = removeMethodComponent.createObject(root, {rulesList: params["ruleIds"]});
|
||||
popup.open();
|
||||
return;
|
||||
default:
|
||||
var popup = errorDialog.createObject(root, {text: "Remove device error: " + JSON.stringify(params.deviceError) })
|
||||
popup.open();
|
||||
}
|
||||
var popup = errorDialog.createObject(root, {text: "Remove device error: " + JSON.stringify(params.deviceError) })
|
||||
popup.open();
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,4 +114,70 @@ 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
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user