Browser Items in rules

This commit is contained in:
Michael Zanetti 2019-07-17 22:49:04 +02:00
parent 62b2a33145
commit f735c5edfb
15 changed files with 195 additions and 56 deletions

View File

@ -318,6 +318,9 @@ QVariantList JsonTypes::packRuleActions(RuleActions *ruleActions)
if (!ra->actionTypeId().isNull() && !ra->deviceId().isNull()) { if (!ra->actionTypeId().isNull() && !ra->deviceId().isNull()) {
ruleAction.insert("deviceId", ra->deviceId()); ruleAction.insert("deviceId", ra->deviceId());
ruleAction.insert("actionTypeId", ra->actionTypeId()); ruleAction.insert("actionTypeId", ra->actionTypeId());
} else if (!ra->deviceId().isNull() && !ra->browserItemId().isEmpty()) {
ruleAction.insert("deviceId", ra->deviceId());
ruleAction.insert("browserItemId", ra->browserItemId());
} else { } else {
ruleAction.insert("interface", ra->interfaceName()); ruleAction.insert("interface", ra->interfaceName());
ruleAction.insert("interfaceAction", ra->interfaceAction()); ruleAction.insert("interfaceAction", ra->interfaceAction());

View File

@ -286,6 +286,9 @@ RuleAction *RuleManager::parseRuleAction(const QVariantMap &ruleAction)
if (ruleAction.contains("deviceId") && ruleAction.contains("actionTypeId")) { if (ruleAction.contains("deviceId") && ruleAction.contains("actionTypeId")) {
ret->setDeviceId(ruleAction.value("deviceId").toUuid()); ret->setDeviceId(ruleAction.value("deviceId").toUuid());
ret->setActionTypeId(ruleAction.value("actionTypeId").toUuid()); ret->setActionTypeId(ruleAction.value("actionTypeId").toUuid());
} else if (ruleAction.contains("deviceId") && ruleAction.contains("browserItemId")) {
ret->setDeviceId(ruleAction.value("deviceId").toUuid());
ret->setBrowserItemId(ruleAction.value("browserItemId").toString());
} else { } else {
ret->setInterfaceName(ruleAction.value("interface").toString()); ret->setInterfaceName(ruleAction.value("interface").toString());
ret->setInterfaceAction(ruleAction.value("interfaceAction").toString()); ret->setInterfaceAction(ruleAction.value("interfaceAction").toString());

View File

@ -62,6 +62,19 @@ void RuleAction::setInterfaceAction(const QString &interfaceAction)
} }
} }
QString RuleAction::browserItemId() const
{
return m_browserItemId;
}
void RuleAction::setBrowserItemId(const QString &browserItemId)
{
if (m_browserItemId != browserItemId) {
m_browserItemId = browserItemId;
emit browserItemIdChanged();
}
}
RuleActionParams *RuleAction::ruleActionParams() const RuleActionParams *RuleAction::ruleActionParams() const
{ {
return m_ruleActionParams; return m_ruleActionParams;
@ -72,6 +85,7 @@ RuleAction *RuleAction::clone() const
RuleAction *ret = new RuleAction(); RuleAction *ret = new RuleAction();
ret->setDeviceId(deviceId()); ret->setDeviceId(deviceId());
ret->setActionTypeId(actionTypeId()); ret->setActionTypeId(actionTypeId());
ret->setBrowserItemId(browserItemId());
ret->setInterfaceName(interfaceName()); ret->setInterfaceName(interfaceName());
ret->setInterfaceAction(interfaceAction()); ret->setInterfaceAction(interfaceAction());
for (int i = 0; i < ruleActionParams()->rowCount(); i++) { for (int i = 0; i < ruleActionParams()->rowCount(); i++) {
@ -88,6 +102,7 @@ bool RuleAction::operator==(RuleAction *other) const
COMPARE(m_actionTypeId, other->actionTypeId()); COMPARE(m_actionTypeId, other->actionTypeId());
COMPARE(m_interfaceName, other->interfaceName()); COMPARE(m_interfaceName, other->interfaceName());
COMPARE(m_interfaceAction, other->interfaceAction()); COMPARE(m_interfaceAction, other->interfaceAction());
COMPARE(m_browserItemId, other->browserItemId());
COMPARE_PTR(m_ruleActionParams, other->ruleActionParams()); COMPARE_PTR(m_ruleActionParams, other->ruleActionParams());
return true; return true;
} }

View File

@ -13,6 +13,7 @@ class RuleAction : public QObject
Q_PROPERTY(QUuid actionTypeId READ actionTypeId WRITE setActionTypeId NOTIFY actionTypeIdChanged) Q_PROPERTY(QUuid actionTypeId READ actionTypeId WRITE setActionTypeId NOTIFY actionTypeIdChanged)
Q_PROPERTY(QString interfaceName READ interfaceName WRITE setInterfaceName NOTIFY interfaceNameChanged) Q_PROPERTY(QString interfaceName READ interfaceName WRITE setInterfaceName NOTIFY interfaceNameChanged)
Q_PROPERTY(QString interfaceAction READ interfaceAction WRITE setInterfaceAction NOTIFY interfaceActionChanged) Q_PROPERTY(QString interfaceAction READ interfaceAction WRITE setInterfaceAction NOTIFY interfaceActionChanged)
Q_PROPERTY(QString browserItemId READ browserItemId WRITE setBrowserItemId NOTIFY browserItemIdChanged)
Q_PROPERTY(RuleActionParams* ruleActionParams READ ruleActionParams CONSTANT) Q_PROPERTY(RuleActionParams* ruleActionParams READ ruleActionParams CONSTANT)
public: public:
@ -30,6 +31,9 @@ public:
QString interfaceAction() const; QString interfaceAction() const;
void setInterfaceAction(const QString &interfaceAction); void setInterfaceAction(const QString &interfaceAction);
QString browserItemId() const;
void setBrowserItemId(const QString &browserItemId);
RuleActionParams* ruleActionParams() const; RuleActionParams* ruleActionParams() const;
RuleAction *clone() const; RuleAction *clone() const;
@ -40,12 +44,14 @@ signals:
void actionTypeIdChanged(); void actionTypeIdChanged();
void interfaceNameChanged(); void interfaceNameChanged();
void interfaceActionChanged(); void interfaceActionChanged();
bool browserItemIdChanged();
private: private:
QUuid m_deviceId; QUuid m_deviceId;
QUuid m_actionTypeId; QUuid m_actionTypeId;
QString m_interfaceName; QString m_interfaceName;
QString m_interfaceAction; QString m_interfaceAction;
QString m_browserItemId;
RuleActionParams *m_ruleActionParams; RuleActionParams *m_ruleActionParams;
}; };

View File

@ -189,5 +189,7 @@
<file>ui/components/MediaControls.qml</file> <file>ui/components/MediaControls.qml</file>
<file>ui/components/MediaArtworkImage.qml</file> <file>ui/components/MediaArtworkImage.qml</file>
<file>ui/components/BrowserContextMenu.qml</file> <file>ui/components/BrowserContextMenu.qml</file>
<file>ui/magic/SelectBrowserItemActionPage.qml</file>
<file>ui/delegates/BrowserItemDelegate.qml</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -77,8 +77,8 @@ Page {
delegate: NymeaListItemDelegate { delegate: NymeaListItemDelegate {
id: ruleDelegate id: ruleDelegate
width: parent.width width: parent.width
iconName: "../images/" + (model.executable ? (iconTag ? iconTag.value : "slideshow") : "magic") + ".svg" iconName: "../images/" + (model.executable ? (iconTag.value.length > 0 ? iconTag.value : "slideshow") : "magic") + ".svg"
iconColor: model.executable ? (colorTag ? colorTag.value : app.accentColor) : !model.enabled ? "red" : (model.active ? app.accentColor : "grey") iconColor: model.executable ? (colorTag.value.length > 0 ? colorTag.value : app.accentColor) : !model.enabled ? "red" : (model.active ? app.accentColor : "grey")
text: model.name text: model.name
canDelete: true canDelete: true

View File

@ -22,15 +22,18 @@ SwipeDelegate {
property alias secondaryIconName: secondaryIcon.name property alias secondaryIconName: secondaryIcon.name
property alias secondaryIconColor: secondaryIcon.color property alias secondaryIconColor: secondaryIcon.color
property alias secondaryIconKeyColor: secondaryIcon.keyColor property alias secondaryIconKeyColor: secondaryIcon.keyColor
property alias secondaryIconClickable: secondaryIconMouseArea.enabled
property alias tertiaryIconName: tertiaryIcon.name property alias tertiaryIconName: tertiaryIcon.name
property alias tertiaryIconColor: tertiaryIcon.color property alias tertiaryIconColor: tertiaryIcon.color
property alias tertiaryIconKeyColor: tertiaryIcon.keyColor property alias tertiaryIconKeyColor: tertiaryIcon.keyColor
property alias tertiaryIconClickable: tertiaryIconMouseArea.enabled
property alias additionalItem: additionalItemContainer.children property alias additionalItem: additionalItemContainer.children
property alias busy: busyIndicator.running property alias busy: busyIndicator.running
signal deleteClicked() signal deleteClicked()
signal secondaryIconClicked()
contentItem: RowLayout { contentItem: RowLayout {
id: innerLayout id: innerLayout
@ -95,6 +98,13 @@ SwipeDelegate {
Layout.preferredHeight: app.iconSize * .5 Layout.preferredHeight: app.iconSize * .5
Layout.preferredWidth: height Layout.preferredWidth: height
visible: name.length > 0 visible: name.length > 0
MouseArea {
id: secondaryIconMouseArea
enabled: false
anchors.fill: parent
anchors.margins: -app.margins
onClicked: root.secondaryIconClicked();
}
} }
ColorIcon { ColorIcon {
@ -102,6 +112,13 @@ SwipeDelegate {
Layout.preferredHeight: app.iconSize * .5 Layout.preferredHeight: app.iconSize * .5
Layout.preferredWidth: height Layout.preferredWidth: height
visible: name.length > 0 visible: name.length > 0
MouseArea {
id: tertiaryIconMouseArea
enabled: false
anchors.fill: parent
anchors.margins: -app.margins
onClicked: root.tertiaryIconClicked();
}
} }
ColorIcon { ColorIcon {

View File

@ -0,0 +1,40 @@
import QtQuick 2.5
import QtQuick.Controls 2.1
import QtQuick.Controls.Material 2.1
import QtQuick.Layouts 1.1
import Nymea 1.0
import "../components"
NymeaListItemDelegate {
id: root
width: parent.width
text: model.displayName
progressive: model.browsable
subText: model.description
prominentSubText: false
iconName: model.thumbnail
fallbackIcon: "../images/browser/" + model.icon + ".svg"
enabled: model.browsable || model.executable
secondaryIconName: model.actionTypeIds.length > 0 ? "../images/navigation-menu.svg" : ""
secondaryIconClickable: true
property Device device: null
onPressAndHold: openContextMenu()
onSecondaryIconClicked: openContextMenu()
signal contextMenuActionTriggered(var actionTypeId, var params)
function openContextMenu() {
if (model.actionTypeIds.length === 0) {
return;
}
var actionDialogComponent = Qt.createComponent(Qt.resolvedUrl("../components/BrowserContextMenu.qml"));
var popup = actionDialogComponent.createObject(root, {device: root.device, title: model.displayName, itemId: model.id, actionTypeIds: model.actionTypeIds});
popup.activated.connect(function(actionTypeId, params) {
root.contextMenuActionTriggered(actionTypeId, params)
})
popup.open()
}
}

View File

@ -3,6 +3,7 @@ import QtQuick.Controls 2.1
import QtQuick.Layouts 1.1 import QtQuick.Layouts 1.1
import Nymea 1.0 import Nymea 1.0
import "../components" import "../components"
import "../delegates"
Page { Page {
id: root id: root
@ -59,16 +60,10 @@ Page {
model: d.model model: d.model
ScrollBar.vertical: ScrollBar {} ScrollBar.vertical: ScrollBar {}
delegate: NymeaListItemDelegate { delegate: BrowserItemDelegate {
width: parent.width id: delegate
text: model.displayName
progressive: model.browsable
subText: model.description
prominentSubText: false
iconName: model.thumbnail
fallbackIcon: "../images/browser/" + model.icon + ".svg"
enabled: !model.disabled
busy: d.pendingItemId === model.id busy: d.pendingItemId === model.id
device: root.device
onClicked: { onClicked: {
print("clicked:", model.id) print("clicked:", model.id)
@ -79,15 +74,8 @@ Page {
} }
} }
onContextMenuActionTriggered: {
onPressAndHold: { root.executeBrowserItemAction(model.id, actionTypeId, params)
print("show actions:", model.actionTypeIds)
var actionDialogComponent = Qt.createComponent(Qt.resolvedUrl("../components/BrowserContextMenu.qml"));
var popup = actionDialogComponent.createObject(this, {device: root.device, title: model.displayName, itemId: model.id, actionTypeIds: model.actionTypeIds});
popup.activated.connect(function(actionTypeId, params) {
root.executeBrowserItemAction(model.id, actionTypeId, params)
})
popup.open()
} }
} }

View File

@ -6,6 +6,7 @@ import QtGraphicalEffects 1.0
import Nymea 1.0 import Nymea 1.0
import "../components" import "../components"
import "../customviews" import "../customviews"
import "../delegates"
DevicePageBase { DevicePageBase {
id: root id: root
@ -161,17 +162,10 @@ DevicePageBase {
browserItems = engine.deviceManager.browseDevice(root.device.id, nodeId); browserItems = engine.deviceManager.browseDevice(root.device.id, nodeId);
} }
delegate: NymeaListItemDelegate { delegate: BrowserItemDelegate {
width: parent.width
text: model.displayName
progressive: model.browsable
subText: model.description
prominentSubText: false
iconName: model.thumbnail
fallbackIcon: "../images/browser/" + (model.mediaIcon && model.mediaIcon !== "MediaBrowserIconNone" ? model.mediaIcon : model.icon) + ".svg" fallbackIcon: "../images/browser/" + (model.mediaIcon && model.mediaIcon !== "MediaBrowserIconNone" ? model.mediaIcon : model.icon) + ".svg"
enabled: model.browsable || model.executable
busy: d.pendingItemId === model.id busy: d.pendingItemId === model.id
secondaryIconName: model.actionTypeIds.length > 0 ? "../images/navigation-menu.svg" : "" device: root.device
onClicked: { onClicked: {
print("clicked:", model.id) print("clicked:", model.id)
@ -181,15 +175,9 @@ DevicePageBase {
internalPageStack.push(internalBrowserPage, {device: root.device, nodeId: model.id}) internalPageStack.push(internalBrowserPage, {device: root.device, nodeId: model.id})
} }
} }
onPressAndHold: {
print("show actions:", model.actionTypeIds) onContextMenuActionTriggered: {
var actionDialogComponent = Qt.createComponent(Qt.resolvedUrl("../components/BrowserContextMenu.qml")); root.executeBrowserItemAction(model.id, actionTypeId, params)
var popup = actionDialogComponent.createObject(root, {device: root.device, title: model.displayName, itemId: model.id, actionTypeIds: model.actionTypeIds});
popup.activated.connect(function(actionTypeId, params) {
print("params:", JSON.stringify(params))
root.executeBrowserItemAction(model.id, actionTypeId, params)
})
popup.open()
} }
} }

View File

@ -317,7 +317,7 @@ Page {
Behavior on opacity { NumberAnimation {duration: 200; easing.type: Easing.InOutQuad } } Behavior on opacity { NumberAnimation {duration: 200; easing.type: Easing.InOutQuad } }
Label { Label {
Layout.fillWidth: true Layout.fillWidth: true
text: qsTr("This is a scene" + root.ruleColor, root.ruleIcon) text: qsTr("This is a scene")
} }
CheckBox { CheckBox {

View File

@ -17,13 +17,14 @@ NymeaListItemDelegate {
property var deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null property var deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null
property var actionType: deviceClass ? deviceClass.actionTypes.getActionType(ruleAction.actionTypeId) property var actionType: deviceClass ? deviceClass.actionTypes.getActionType(ruleAction.actionTypeId)
: iface ? iface.actionTypes.findByName(ruleAction.interfaceAction) : null : iface ? iface.actionTypes.findByName(ruleAction.interfaceAction) : null
property var browserItemId: ruleAction.browserItemId
signal removeRuleAction() signal removeRuleAction()
onDeleteClicked: root.removeRuleAction() onDeleteClicked: root.removeRuleAction()
iconName: root.device ? "../images/action.svg" : "../images/action-interface.svg" iconName: root.device ? (root.browserItemId ? "../images/browser/BrowserIconFolder.svg" : "../images/action.svg") : "../images/action-interface.svg"
text: qsTr("%1 - %2").arg(root.device ? root.device.name : root.iface.displayName).arg(root.actionType.displayName) text: qsTr("%1 - %2").arg(root.device ? root.device.name : root.iface.displayName).arg(root.actionType ? root.actionType.displayName : qsTr("Launch an item"))
subText: { subText: {
var ret = []; var ret = [];
for (var i = 0; i < root.ruleAction.ruleActionParams.count; i++) { for (var i = 0; i < root.ruleAction.ruleActionParams.count; i++) {

View File

@ -0,0 +1,48 @@
import QtQuick 2.4
import QtQuick.Controls 2.1
import Nymea 1.0
import "../components"
import "../delegates"
Page {
id: root
property Device device: null
property string itemId: ""
signal selected(string itemId)
header: NymeaHeader {
onBackPressed: pageStack.pop()
text: qsTr("Select item")
}
Component.onCompleted: {
listView.model = engine.deviceManager.browseDevice(root.device.id, root.itemId)
}
ListView {
id: listView
anchors.fill: parent
ScrollBar.vertical: ScrollBar {}
delegate: BrowserItemDelegate {
width: parent.width
device: root.device
secondaryIconName: "" // We don't support BrowserItemActions in rules yet
onClicked: {
if (model.browsable) {
var page = pageStack.push(Qt.resolvedUrl("SelectBrowserItemActionPage.qml"), {device: root.device, itemId: model.id});
page.selected.connect(function() {
pageStack.pop();
root.selected(model.id);
})
} else if (model.executable) {
pageStack.pop();
root.selected(model.id);
}
}
}
}
}

View File

@ -8,13 +8,13 @@ Page {
property alias text: header.text property alias text: header.text
// a ruleAction object needs to be set and prefilled with either deviceId or interfaceName // a ruleAction object needs to be set and prefilled with either deviceId or interfaceName
property var ruleAction: null property RuleAction ruleAction: null
// optionally, a rule which will be used when determining params for the actions // optionally, a rule which will be used when determining params for the actions
property var rule: null property Rule rule: null
readonly property var device: ruleAction && ruleAction.deviceId ? engine.deviceManager.devices.getDevice(ruleAction.deviceId) : null readonly property Device device: ruleAction && ruleAction.deviceId ? engine.deviceManager.devices.getDevice(ruleAction.deviceId) : null
readonly property var deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null readonly property DeviceClass deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null
signal backPressed(); signal backPressed();
signal done(); signal done();
@ -65,7 +65,20 @@ Page {
} }
} else { } else {
if (root.device) { if (root.device) {
listView.model = deviceClass.actionTypes generatedModel.clear();
for (var i = 0; i < deviceClass.actionTypes.count; i++) {
var actionType = deviceClass.actionTypes.get(i);
generatedModel.append({displayName: actionType.displayName, actionTypeId: actionType.id})
}
// Append an item for browse mode
if (root.deviceClass.browsable) {
generatedModel.append({displayName: qsTr("Open an item on this thing..."), actionTypeId: "browse"})
}
listView.model = generatedModel;
// listView.model = deviceClass.actionTypes
} }
} }
} }
@ -73,10 +86,16 @@ Page {
ListView { ListView {
id: listView id: listView
anchors.fill: parent anchors.fill: parent
ScrollBar.vertical: ScrollBar {}
delegate: ItemDelegate { delegate: NymeaListItemDelegate {
id: delegate
text: model.displayName text: model.displayName
width: parent.width width: parent.width
iconName: model.actionTypeId === "browse" ? "../images/browser/BrowserIconFolder.svg" : "../images/action.svg"
property ActionType actionType: root.deviceClass.actionTypes.getActionType(model.actionTypeId)
progressive: model.actionTypeId === "browse" || actionType.paramTypes.count > 0
onClicked: { onClicked: {
if (header.interfacesMode) { if (header.interfacesMode) {
if (root.device) { if (root.device) {
@ -109,18 +128,27 @@ Page {
} }
} else { } else {
if (root.device) { if (root.device) {
var actionType = root.deviceClass.actionTypes.getActionType(model.id); if (model.actionTypeId === "browse") {
console.log("ActionType", actionType.id, "selected. Has", actionType.paramTypes.count, "params"); var page = pageStack.push(Qt.resolvedUrl("SelectBrowserItemActionPage.qml"), {device: root.device});
root.ruleAction.actionTypeId = actionType.id; page.selected.connect(function(itemId) {
if (actionType.paramTypes.count > 0) { root.ruleAction.browserItemId = itemId;
var paramsPage = pageStack.push(Qt.resolvedUrl("SelectRuleActionParamsPage.qml"), {ruleAction: root.ruleAction, rule: root.rule})
paramsPage.onBackPressed.connect(function() { pageStack.pop(); });
paramsPage.onCompleted.connect(function() {
pageStack.pop(); pageStack.pop();
root.done(); root.done();
}) })
} else { } else {
root.done(); var actionType = root.deviceClass.actionTypes.getActionType(model.actiontypeId);
console.log("ActionType", actionType.id, "selected. Has", actionType.paramTypes.count, "params");
root.ruleAction.actionTypeId = actionType.id;
if (actionType.paramTypes.count > 0) {
var paramsPage = pageStack.push(Qt.resolvedUrl("SelectRuleActionParamsPage.qml"), {ruleAction: root.ruleAction, rule: root.rule})
paramsPage.onBackPressed.connect(function() { pageStack.pop(); });
paramsPage.onCompleted.connect(function() {
pageStack.pop();
root.done();
})
} else {
root.done();
}
} }
} }
} }

View File

@ -31,7 +31,7 @@ Item {
height: interfacesGridView.cellHeight height: interfacesGridView.cellHeight
iconName: iconTag ? "../images/" + iconTag.value + ".svg" : "../images/slideshow.svg"; iconName: iconTag ? "../images/" + iconTag.value + ".svg" : "../images/slideshow.svg";
fallbackIconName: "../images/slideshow.svg" fallbackIconName: "../images/slideshow.svg"
iconColor: colorTag ? colorTag.value : app.accentColor; iconColor: colorTag.value.length > 0 ? colorTag.value : app.accentColor;
text: model.name.toUpperCase() text: model.name.toUpperCase()
property var colorTag: engine.tagsManager.tags.findRuleTag(model.id, "color") property var colorTag: engine.tagsManager.tags.findRuleTag(model.id, "color")