2019-12-19 22:46:16 +11:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-12-18 09:07:38 +11:00
|
|
|
import QtQuick 2.12
|
2019-12-03 07:29:29 +11:00
|
|
|
import "../.."
|
2020-08-03 15:19:08 +10:00
|
|
|
import ".."
|
2019-12-18 09:07:38 +11:00
|
|
|
|
|
|
|
QtObject {
|
2020-07-09 07:26:52 +10:00
|
|
|
signal deviceUpdateSignal(string forAccount)
|
|
|
|
|
2019-12-18 09:07:38 +11:00
|
|
|
function onExitRequested(exitCode) {
|
|
|
|
Qt.exit(exitCode)
|
|
|
|
}
|
|
|
|
|
2020-06-03 11:42:16 +10:00
|
|
|
function onAlertRequested(highImportance) {
|
|
|
|
const msec =
|
|
|
|
highImportance ?
|
|
|
|
window.settings.alertOnMentionForMsec :
|
|
|
|
window.settings.alertOnMessageForMsec
|
2020-03-25 02:31:32 +11:00
|
|
|
|
|
|
|
if (Qt.application.state !== Qt.ApplicationActive && msec !== 0) {
|
|
|
|
window.alert(msec === -1 ? 0 : msec) // -1 → 0 = no time out
|
2019-12-18 09:07:38 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onCoroutineDone(uuid, result, error, traceback) {
|
2020-03-08 19:46:20 +11:00
|
|
|
const onSuccess = Globals.pendingCoroutines[uuid].onSuccess
|
|
|
|
const onError = Globals.pendingCoroutines[uuid].onError
|
2019-12-18 09:07:38 +11:00
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
delete Globals.pendingCoroutines[uuid]
|
2020-05-07 03:39:53 +10:00
|
|
|
Globals.pendingCoroutinesChanged()
|
2019-12-27 00:20:51 +11:00
|
|
|
|
2019-12-18 09:07:38 +11:00
|
|
|
if (error) {
|
2019-12-27 00:20:51 +11:00
|
|
|
const type = py.getattr(py.getattr(error, "__class__"), "__name__")
|
|
|
|
const args = py.getattr(error, "args")
|
2019-12-18 09:07:38 +11:00
|
|
|
|
2020-03-13 17:52:38 +11:00
|
|
|
if (type === "CancelledError") return
|
2019-12-18 09:07:38 +11:00
|
|
|
|
2020-03-16 06:40:53 +11:00
|
|
|
onError ?
|
|
|
|
onError(type, args, error, traceback, uuid) :
|
2020-08-03 15:19:08 +10:00
|
|
|
py.showError(type, traceback, "", uuid)
|
2020-03-16 06:40:53 +11:00
|
|
|
|
|
|
|
return
|
2019-12-27 00:20:51 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
if (onSuccess) onSuccess(result)
|
2019-12-18 09:07:38 +11:00
|
|
|
}
|
|
|
|
|
2019-12-27 01:05:01 +11:00
|
|
|
function onLoopException(message, error, traceback) {
|
|
|
|
// No need to log these here, the asyncio exception handler does it
|
|
|
|
const type = py.getattr(py.getattr(error, "__class__"), "__name__")
|
2020-08-03 15:19:08 +10:00
|
|
|
py.showError(type, traceback, message)
|
2019-12-27 01:05:01 +11:00
|
|
|
}
|
|
|
|
|
2020-09-03 03:38:11 +10:00
|
|
|
function onModelItemSet(syncId, indexThen, indexNow, changedFields) {
|
|
|
|
const model = ModelStore.get(syncId)
|
|
|
|
|
2020-04-08 01:58:26 +10:00
|
|
|
if (indexThen === undefined) {
|
2020-04-15 00:55:01 +10:00
|
|
|
// print("insert", syncId, indexThen, indexNow,
|
|
|
|
// JSON.stringify(changedFields))
|
2020-09-03 03:38:11 +10:00
|
|
|
model.insert(indexNow, changedFields)
|
|
|
|
model.idToItems[changedFields.id] = model.get(indexNow)
|
|
|
|
model.idToItemsChanged()
|
2020-04-08 01:58:26 +10:00
|
|
|
|
|
|
|
} else {
|
2020-04-15 00:55:01 +10:00
|
|
|
// print("set", syncId, indexThen, indexNow,
|
|
|
|
// JSON.stringify(changedFields))
|
2020-04-08 01:58:26 +10:00
|
|
|
model.set(indexThen, changedFields)
|
2020-05-01 14:30:26 +10:00
|
|
|
|
2020-04-08 01:58:26 +10:00
|
|
|
if (indexThen !== indexNow) model.move(indexThen, indexNow, 1)
|
2020-05-01 14:30:26 +10:00
|
|
|
|
|
|
|
model.fieldsChanged(indexNow, changedFields)
|
2020-04-08 01:58:26 +10:00
|
|
|
}
|
2019-12-03 07:29:29 +11:00
|
|
|
}
|
|
|
|
|
2020-09-03 03:38:11 +10:00
|
|
|
function onModelItemDeleted(syncId, index, count=1, ids=[]) {
|
|
|
|
// print("delete", syncId, index, count, ids)
|
|
|
|
const model = ModelStore.get(syncId)
|
|
|
|
model.remove(index, count)
|
|
|
|
|
|
|
|
for (let i = 0; i < ids.length; i++) {
|
|
|
|
delete model.idToItems[ids[i]]
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ids.length) model.idToItemsChanged()
|
2019-12-03 07:29:29 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
function onModelCleared(syncId) {
|
|
|
|
// print("clear", syncId)
|
2020-09-05 00:58:04 +10:00
|
|
|
const model = ModelStore.get(syncId)
|
|
|
|
model.clear()
|
2020-09-03 03:38:11 +10:00
|
|
|
model.idToItems = {}
|
2019-12-18 09:07:38 +11:00
|
|
|
}
|
2020-07-09 07:26:52 +10:00
|
|
|
|
|
|
|
function onDevicesUpdated(forAccount) {
|
|
|
|
deviceUpdateSignal(forAccount)
|
|
|
|
}
|
2019-12-18 09:07:38 +11:00
|
|
|
}
|