2016-08-21 18:38:15 +01:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2016 Aleix Pol Gonzalez <aleixpol@kde.org>
|
2024-06-30 23:03:57 +01:00
|
|
|
* SPDX-FileCopyrightText: 2024 ivan tkachenko <me@ratijas.tk>
|
2016-08-21 18:38:15 +01:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2016-08-21 18:38:15 +01:00
|
|
|
*/
|
|
|
|
|
2024-06-30 23:03:57 +01:00
|
|
|
pragma ComponentBehavior: Bound
|
|
|
|
|
|
|
|
import QtQml
|
|
|
|
|
|
|
|
import org.kde.kdeconnect as KDEConnect
|
2016-08-21 18:38:15 +01:00
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: prop
|
2024-06-30 23:03:57 +01:00
|
|
|
|
|
|
|
property QtObject object
|
2016-08-21 18:38:15 +01:00
|
|
|
property string read
|
2024-06-30 23:03:57 +01:00
|
|
|
property string change: read + "Changed"
|
2016-08-21 18:38:15 +01:00
|
|
|
|
2024-06-30 23:03:57 +01:00
|
|
|
Component.onCompleted: {
|
|
|
|
get();
|
|
|
|
}
|
2016-08-21 18:38:15 +01:00
|
|
|
|
|
|
|
onChangeChanged: {
|
|
|
|
if (object) {
|
2024-06-30 23:03:57 +01:00
|
|
|
const signal = object[change];
|
|
|
|
if (signal) {
|
|
|
|
signal.connect(valueReceived);
|
2016-08-21 18:38:15 +01:00
|
|
|
} else {
|
2024-06-30 23:03:57 +01:00
|
|
|
console.warn(`couldn't find signal ${change} for ${object}`);
|
2016-08-21 18:38:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-30 23:03:57 +01:00
|
|
|
function valueReceived(value: var): void {
|
|
|
|
if (!value) {
|
2016-08-21 18:38:15 +01:00
|
|
|
get();
|
|
|
|
} else {
|
2024-06-30 23:03:57 +01:00
|
|
|
_value = value;
|
2016-08-21 18:38:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
property var defaultValue
|
|
|
|
property var _value: defaultValue
|
|
|
|
readonly property var value: _value
|
|
|
|
|
2024-06-30 23:03:57 +01:00
|
|
|
readonly property KDEConnect.DBusAsyncResponse __response: KDEConnect.DBusAsyncResponse {
|
2016-08-21 18:38:15 +01:00
|
|
|
id: response
|
2024-06-30 23:03:57 +01:00
|
|
|
|
2016-08-21 18:38:15 +01:00
|
|
|
autoDelete: false
|
2024-06-30 23:03:57 +01:00
|
|
|
|
2023-04-29 14:54:38 +01:00
|
|
|
onSuccess: result => {
|
2016-08-21 18:38:15 +01:00
|
|
|
prop._value = result;
|
|
|
|
}
|
2024-06-30 23:03:57 +01:00
|
|
|
|
2023-04-29 14:54:38 +01:00
|
|
|
onError: message => {
|
2024-06-30 23:03:57 +01:00
|
|
|
console.warn("failed call", prop.object, prop.read, prop.change, message);
|
2016-08-21 18:38:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-30 23:03:57 +01:00
|
|
|
function get(): void {
|
|
|
|
if (object) {
|
|
|
|
const method = object[read];
|
|
|
|
if (method) {
|
|
|
|
response.setPendingCall(method());
|
|
|
|
}
|
|
|
|
}
|
2016-08-21 18:38:15 +01:00
|
|
|
}
|
|
|
|
}
|