2019-12-19 22:46:16 +11:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-07-13 19:39:01 +10:00
|
|
|
import QtQuick 2.12
|
2019-06-27 16:31:03 +10:00
|
|
|
import io.thp.pyotherside 1.5
|
2019-12-27 23:58:24 +11:00
|
|
|
import CppUtils 0.1
|
2019-12-03 07:29:29 +11:00
|
|
|
import "Privates"
|
2019-06-27 16:31:03 +10:00
|
|
|
|
|
|
|
Python {
|
|
|
|
id: py
|
2019-12-08 09:33:33 +11:00
|
|
|
|
|
|
|
|
2019-12-18 21:16:24 +11:00
|
|
|
readonly property QtObject privates: QtObject {
|
|
|
|
function makeFuture(callback) {
|
|
|
|
return Qt.createComponent("Future.qml")
|
2019-12-03 07:29:29 +11:00
|
|
|
.createObject(py, { bridge: py })
|
2019-12-08 09:33:33 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-18 21:16:24 +11:00
|
|
|
|
2019-12-06 23:44:45 +11:00
|
|
|
function setattr(obj, attr, value, callback=null) {
|
|
|
|
py.call(py.getattr(obj, "__setattr__"), [attr, value], callback)
|
|
|
|
}
|
|
|
|
|
2019-10-28 21:26:02 +11:00
|
|
|
function callCoro(name, args=[], onSuccess=null, onError=null) {
|
2020-03-08 19:27:43 +11:00
|
|
|
const uuid = name + "." + CppUtils.uuid()
|
|
|
|
const future = privates.makeFuture()
|
2019-12-08 09:33:33 +11:00
|
|
|
|
2020-03-08 19:27:43 +11:00
|
|
|
Globals.pendingCoroutines[uuid] = {future, onSuccess, onError}
|
2019-12-08 09:33:33 +11:00
|
|
|
|
2019-12-18 21:44:18 +11:00
|
|
|
call("BRIDGE.call_backend_coro", [name, uuid, args], pyFuture => {
|
2019-12-18 21:16:24 +11:00
|
|
|
future.privates.pythonFuture = pyFuture
|
2019-12-08 09:33:33 +11:00
|
|
|
})
|
|
|
|
|
2019-12-18 21:16:24 +11:00
|
|
|
return future
|
2019-06-27 16:31:03 +10:00
|
|
|
}
|
|
|
|
|
2019-10-28 21:26:02 +11:00
|
|
|
function callClientCoro(
|
|
|
|
accountId, name, args=[], onSuccess=null, onError=null
|
|
|
|
) {
|
2020-03-08 19:27:43 +11:00
|
|
|
const future = privates.makeFuture()
|
2019-12-08 09:33:33 +11:00
|
|
|
|
2019-12-18 23:14:35 +11:00
|
|
|
callCoro("get_client", [accountId], () => {
|
2020-03-08 19:27:43 +11:00
|
|
|
const uuid = accountId + "." + name + "." + CppUtils.uuid()
|
2019-06-29 08:12:45 +10:00
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
Globals.pendingCoroutines[uuid] = {onSuccess, onError}
|
2019-12-08 09:33:33 +11:00
|
|
|
|
2020-03-08 19:27:43 +11:00
|
|
|
const call_args = [accountId, name, uuid, args]
|
2019-12-08 09:33:33 +11:00
|
|
|
|
2019-12-18 21:44:18 +11:00
|
|
|
call("BRIDGE.call_client_coro", call_args, pyFuture => {
|
2019-12-18 21:16:24 +11:00
|
|
|
future.privates.pythonFuture = pyFuture
|
2019-12-08 09:33:33 +11:00
|
|
|
})
|
2019-07-21 22:38:49 +10:00
|
|
|
})
|
2019-12-08 09:33:33 +11:00
|
|
|
|
2019-12-18 21:16:24 +11:00
|
|
|
return future
|
2019-06-29 08:12:45 +10:00
|
|
|
}
|
|
|
|
|
2019-07-21 21:14:16 +10:00
|
|
|
function saveConfig(backend_attribute, data, callback=null) {
|
2019-07-19 11:58:21 +10:00
|
|
|
if (! py.ready) { return } // config not loaded yet
|
2019-12-08 09:33:33 +11:00
|
|
|
return callCoro(backend_attribute + ".write", [data], callback)
|
2019-07-19 11:58:21 +10:00
|
|
|
}
|
|
|
|
|
2019-07-25 07:26:40 +10:00
|
|
|
function loadSettings(callback=null) {
|
2020-03-08 19:27:43 +11:00
|
|
|
const func = "load_settings"
|
2019-12-10 04:21:12 +11:00
|
|
|
|
|
|
|
return callCoro(func, [], ([settings, uiState, history, theme]) => {
|
2019-07-25 07:26:40 +10:00
|
|
|
window.settings = settings
|
|
|
|
window.uiState = uiState
|
2019-12-10 04:21:12 +11:00
|
|
|
window.history = history
|
2019-07-25 07:26:40 +10:00
|
|
|
window.theme = Qt.createQmlObject(theme, window, "theme")
|
|
|
|
|
|
|
|
if (callback) { callback(settings, uiState, theme) }
|
|
|
|
})
|
|
|
|
}
|
2019-06-27 16:31:03 +10:00
|
|
|
}
|