browseritemactions
This commit is contained in:
parent
41ebfb48f3
commit
62b2a33145
@ -521,13 +521,14 @@ void DeviceManager::executeBrowserItemResponse(const QVariantMap ¶ms)
|
|||||||
emit executeBrowserItemReply(params);
|
emit executeBrowserItemReply(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DeviceManager::executeBrowserItemAction(const QUuid &deviceId, const QString &itemId, const QUuid &actionTypeId, const QVariantMap ¶ms)
|
int DeviceManager::executeBrowserItemAction(const QUuid &deviceId, const QString &itemId, const QUuid &actionTypeId, const QVariantList ¶ms)
|
||||||
{
|
{
|
||||||
QVariantMap data;
|
QVariantMap data;
|
||||||
data.insert("deviceId", deviceId);
|
data.insert("deviceId", deviceId);
|
||||||
data.insert("itemId", itemId);
|
data.insert("itemId", itemId);
|
||||||
data.insert("actionTypeId", actionTypeId);
|
data.insert("actionTypeId", actionTypeId);
|
||||||
data.insert("params", params);
|
data.insert("params", params);
|
||||||
|
qDebug() << "params:" << params;
|
||||||
return m_jsonClient->sendCommand("Actions.ExecuteBrowserItemAction", data, this, "executeBrowserItemActionResponse");
|
return m_jsonClient->sendCommand("Actions.ExecuteBrowserItemAction", data, this, "executeBrowserItemActionResponse");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -77,7 +77,7 @@ public:
|
|||||||
Q_INVOKABLE BrowserItems* browseDevice(const QUuid &deviceId, const QString &itemId = QString());
|
Q_INVOKABLE BrowserItems* browseDevice(const QUuid &deviceId, const QString &itemId = QString());
|
||||||
Q_INVOKABLE void refreshBrowserItems(BrowserItems *browserItems);
|
Q_INVOKABLE void refreshBrowserItems(BrowserItems *browserItems);
|
||||||
Q_INVOKABLE int executeBrowserItem(const QUuid &deviceId, const QString &itemId);
|
Q_INVOKABLE int executeBrowserItem(const QUuid &deviceId, const QString &itemId);
|
||||||
Q_INVOKABLE int executeBrowserItemAction(const QUuid &deviceId, const QString &itemId, const QUuid &actionTypeId, const QVariantMap ¶ms = QVariantMap());
|
Q_INVOKABLE int executeBrowserItemAction(const QUuid &deviceId, const QString &itemId, const QUuid &actionTypeId, const QVariantList ¶ms = QVariantList());
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_INVOKABLE void notificationReceived(const QVariantMap &data);
|
Q_INVOKABLE void notificationReceived(const QVariantMap &data);
|
||||||
|
|||||||
@ -188,5 +188,6 @@
|
|||||||
<file>ui/devicelistpages/MediaDeviceListPage.qml</file>
|
<file>ui/devicelistpages/MediaDeviceListPage.qml</file>
|
||||||
<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>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|||||||
93
nymea-app/ui/components/BrowserContextMenu.qml
Normal file
93
nymea-app/ui/components/BrowserContextMenu.qml
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
import QtQuick 2.5
|
||||||
|
import QtQuick.Controls 2.1
|
||||||
|
import QtQuick.Layouts 1.1
|
||||||
|
import Nymea 1.0
|
||||||
|
import "../delegates"
|
||||||
|
|
||||||
|
MeaDialog {
|
||||||
|
id: root
|
||||||
|
|
||||||
|
property Device device
|
||||||
|
property string itemId
|
||||||
|
property alias actionTypeIds: actionListView.model
|
||||||
|
|
||||||
|
signal activated(var actionTypeId, var params)
|
||||||
|
|
||||||
|
standardButtons: Dialog.NoButton
|
||||||
|
|
||||||
|
StackView {
|
||||||
|
id: stackView
|
||||||
|
Layout.fillWidth: true
|
||||||
|
Layout.minimumHeight: actionListView.implicitHeight
|
||||||
|
|
||||||
|
property var actionTypeId
|
||||||
|
|
||||||
|
initialItem: ListView {
|
||||||
|
id: actionListView
|
||||||
|
width: parent.width
|
||||||
|
implicitHeight: contentHeight
|
||||||
|
|
||||||
|
interactive: contentHeight > height
|
||||||
|
clip: true
|
||||||
|
delegate: NymeaListItemDelegate {
|
||||||
|
width: parent.width
|
||||||
|
text: actionType.displayName
|
||||||
|
progressive: false
|
||||||
|
property ActionType actionType: root.device.deviceClass.browserItemActionTypes.getActionType(modelData)
|
||||||
|
onClicked: {
|
||||||
|
var hasParams = actionType.paramTypes.count > 0
|
||||||
|
if (hasParams) {
|
||||||
|
stackView.actionTypeId = actionType.id
|
||||||
|
stackView.push(paramComponent, {model: actionType.paramTypes})
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var params = []
|
||||||
|
root.activated(actionType.id, params)
|
||||||
|
root.accept()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: paramComponent
|
||||||
|
|
||||||
|
Repeater {
|
||||||
|
id: paramListView
|
||||||
|
|
||||||
|
delegate: ParamDelegate {
|
||||||
|
width: parent.width
|
||||||
|
paramType: paramListView.model.get(index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
|
||||||
|
Button {
|
||||||
|
text: qsTr("Cancel")
|
||||||
|
onClicked: root.reject()
|
||||||
|
}
|
||||||
|
Item { Layout.fillWidth: true }
|
||||||
|
Button {
|
||||||
|
text: qsTr("OK")
|
||||||
|
visible: stackView.depth > 1
|
||||||
|
onClicked: {
|
||||||
|
var params = []
|
||||||
|
print("k", stackView.currentItem.count)
|
||||||
|
for (var i = 0; i < stackView.currentItem.count; i++) {
|
||||||
|
print("juhu", i)
|
||||||
|
var param = {}
|
||||||
|
param["paramTypeId"] = stackView.currentItem.itemAt(i).paramType.id
|
||||||
|
param["value"] = stackView.currentItem.itemAt(i).value
|
||||||
|
params.push(param)
|
||||||
|
}
|
||||||
|
print("have params", params.length)
|
||||||
|
root.activated(stackView.actionTypeId, params)
|
||||||
|
root.accept();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -82,9 +82,12 @@ Page {
|
|||||||
|
|
||||||
onPressAndHold: {
|
onPressAndHold: {
|
||||||
print("show actions:", model.actionTypeIds)
|
print("show actions:", model.actionTypeIds)
|
||||||
var popup = actionDialogComponent.createObject(this, {title: model.displayName, itemId: model.id, actionTypeIds: 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()
|
popup.open()
|
||||||
// root.device.deviceClass.browserItemActionTypes.getActionType()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,32 +98,4 @@ Page {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Component {
|
|
||||||
id: actionDialogComponent
|
|
||||||
MeaDialog {
|
|
||||||
id: actionDialog
|
|
||||||
|
|
||||||
property string itemId
|
|
||||||
property alias actionTypeIds: actionListView.model
|
|
||||||
|
|
||||||
ListView {
|
|
||||||
id: actionListView
|
|
||||||
Layout.fillWidth: true
|
|
||||||
implicitHeight: count * 50
|
|
||||||
interactive: contentHeight > height
|
|
||||||
clip: true
|
|
||||||
delegate: NymeaListItemDelegate {
|
|
||||||
width: parent.width
|
|
||||||
text: actionType.displayName
|
|
||||||
progressive: false
|
|
||||||
property ActionType actionType: root.device.deviceClass.browserItemActionTypes.getActionType(modelData)
|
|
||||||
onClicked: {
|
|
||||||
var params = []
|
|
||||||
root.executeBrowserItemAction(actionDialog.itemId, actionType.id, params)
|
|
||||||
actionDialog.close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,6 +46,11 @@ DevicePageBase {
|
|||||||
d.pendingItemId = itemId
|
d.pendingItemId = itemId
|
||||||
d.pendingBrowserItemId = engine.deviceManager.executeBrowserItem(device.id, itemId);
|
d.pendingBrowserItemId = engine.deviceManager.executeBrowserItem(device.id, itemId);
|
||||||
}
|
}
|
||||||
|
function executeBrowserItemAction(itemId, actionTypeId, params) {
|
||||||
|
print("params2:", JSON.stringify(params))
|
||||||
|
d.pendingItemId = itemId
|
||||||
|
d.pendingBrowserItemId = engine.deviceManager.executeBrowserItemAction(device.id, itemId, actionTypeId, params);
|
||||||
|
}
|
||||||
|
|
||||||
readonly property State playbackState: device.states.getState(deviceClass.stateTypes.findByName("playbackStatus").id)
|
readonly property State playbackState: device.states.getState(deviceClass.stateTypes.findByName("playbackStatus").id)
|
||||||
|
|
||||||
@ -57,17 +62,19 @@ DevicePageBase {
|
|||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: engine.deviceManager
|
target: engine.deviceManager
|
||||||
onExecuteBrowserItemReply: {
|
onExecuteBrowserItemReply: executionFinished(params)
|
||||||
print("Execute reply:", params, params.id, params["id"], d.pendingBrowserItemId)
|
onExecuteBrowserItemActionReply: executionFinished(params)
|
||||||
if (params.id === d.pendingBrowserItemId) {
|
}
|
||||||
d.pendingBrowserItemId = -1;
|
function executionFinished(params) {
|
||||||
d.pendingItemId = ""
|
print("Execute reply:", params, params.id, params["id"], d.pendingBrowserItemId)
|
||||||
print("yep finished")
|
if (params.id === d.pendingBrowserItemId) {
|
||||||
if (params.params.deviceError === "DeviceErrorNoError") {
|
d.pendingBrowserItemId = -1;
|
||||||
swipeView.currentIndex = 0;
|
d.pendingItemId = ""
|
||||||
} else {
|
print("yep finished")
|
||||||
header.showInfo(qsTr("Error: %").arg(params.params.deviceError), true)
|
if (params.params.deviceError === "DeviceErrorNoError") {
|
||||||
}
|
swipeView.currentIndex = 0;
|
||||||
|
} else {
|
||||||
|
header.showInfo(qsTr("Error: %1").arg(params.params.deviceError), true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,6 +170,8 @@ DevicePageBase {
|
|||||||
iconName: model.thumbnail
|
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
|
enabled: model.browsable || model.executable
|
||||||
|
busy: d.pendingItemId === model.id
|
||||||
|
secondaryIconName: model.actionTypeIds.length > 0 ? "../images/navigation-menu.svg" : ""
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
print("clicked:", model.id)
|
print("clicked:", model.id)
|
||||||
@ -172,6 +181,16 @@ 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)
|
||||||
|
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) {
|
||||||
|
print("params:", JSON.stringify(params))
|
||||||
|
root.executeBrowserItemAction(model.id, actionTypeId, params)
|
||||||
|
})
|
||||||
|
popup.open()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BusyIndicator {
|
BusyIndicator {
|
||||||
|
|||||||
Reference in New Issue
Block a user