2020-10-30 14:15:17 -04:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Controls 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
|
|
|
import "../.."
|
|
|
|
import "../../Base"
|
|
|
|
import "../../Base/Buttons"
|
|
|
|
import "../../ShortcutBundles"
|
|
|
|
|
|
|
|
HListView {
|
|
|
|
id: root
|
|
|
|
|
|
|
|
property string userId
|
|
|
|
|
|
|
|
property bool enableFlickShortcuts:
|
|
|
|
SwipeView ? SwipeView.isCurrentItem : true
|
|
|
|
|
2020-11-01 01:10:49 -04:00
|
|
|
// {model.id: {notify, highlight, bubble, sound, urgency_hint}}
|
2020-11-01 00:55:29 -04:00
|
|
|
property var pendingEdits: ({})
|
|
|
|
property string saveFutureId: ""
|
|
|
|
|
2020-10-30 14:15:17 -04:00
|
|
|
function takeFocus() {
|
2020-11-01 00:55:29 -04:00
|
|
|
// deviceList.headerItem.exportButton.forceActiveFocus() TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
function save() {
|
|
|
|
const args = []
|
|
|
|
|
2020-11-01 01:10:49 -04:00
|
|
|
for (const [modelId, kwargs] of Object.entries(pendingEdits)) {
|
2020-11-01 01:48:28 -04:00
|
|
|
if (! model.find(modelId)) continue // pushrule was deleted
|
|
|
|
|
2020-11-01 01:10:49 -04:00
|
|
|
const [kind, rule_id] = JSON.parse(modelId)
|
2020-11-01 00:55:29 -04:00
|
|
|
args.push(Object.assign({}, {kind, rule_id}, kwargs))
|
|
|
|
}
|
|
|
|
|
|
|
|
saveFutureId = py.callClientCoro(
|
|
|
|
userId,
|
2021-02-25 05:14:42 -04:00
|
|
|
"mass_tweak_pushrules_actions",
|
2020-11-01 00:55:29 -04:00
|
|
|
args,
|
|
|
|
() => {
|
|
|
|
if (! root) return
|
|
|
|
saveFutureId = ""
|
|
|
|
pendingEdits = {}
|
|
|
|
}
|
|
|
|
)
|
2020-10-30 14:15:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
clip: true
|
|
|
|
model: ModelStore.get(userId, "pushrules")
|
|
|
|
implicitHeight: Math.min(window.height, contentHeight + bottomMargin)
|
|
|
|
|
2020-11-04 09:01:44 -04:00
|
|
|
header: HColumnLayout {
|
|
|
|
width: root.width
|
|
|
|
|
|
|
|
HLoader {
|
|
|
|
source: "../../Base/HBusyIndicator.qml"
|
|
|
|
active: root.model.count === 0
|
|
|
|
opacity: active ? 1 : 0
|
|
|
|
visible: opacity > 0
|
|
|
|
|
|
|
|
Behavior on opacity { HNumberAnimation {} }
|
|
|
|
|
|
|
|
Layout.alignment: Qt.AlignCenter
|
|
|
|
Layout.topMargin: theme.spacing
|
2021-02-28 14:39:21 -04:00
|
|
|
Layout.bottomMargin: Layout.topMargin
|
2020-11-04 09:01:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-30 14:15:17 -04:00
|
|
|
section.property: "kind"
|
2021-02-23 08:12:38 -04:00
|
|
|
section.delegate: HRowLayout {
|
2020-10-30 14:15:17 -04:00
|
|
|
width: root.width
|
2021-02-23 08:12:38 -04:00
|
|
|
|
|
|
|
HLabel {
|
|
|
|
padding: theme.spacing
|
|
|
|
font.pixelSize: theme.fontSize.big
|
|
|
|
text:
|
|
|
|
section === "override" ? qsTr("High priority general rules") :
|
|
|
|
section === "content" ? qsTr("Message content rules") :
|
|
|
|
section === "room" ? qsTr("Room rules") :
|
|
|
|
section === "sender" ? qsTr("Sender rules") :
|
|
|
|
qsTr("Low priority general rules")
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
}
|
|
|
|
|
|
|
|
PositiveButton {
|
|
|
|
readonly property var newRule: ({
|
|
|
|
id: '[section, ""]',
|
|
|
|
kind: section,
|
|
|
|
rule_id: "",
|
|
|
|
order: 0,
|
|
|
|
default: false,
|
|
|
|
enabled: true,
|
|
|
|
conditions: "[]",
|
|
|
|
pattern: "",
|
|
|
|
actions: "[]",
|
|
|
|
notify: false,
|
|
|
|
highlight: false,
|
|
|
|
bubble: false,
|
|
|
|
sound: false,
|
|
|
|
urgency_hint: false,
|
|
|
|
})
|
|
|
|
|
|
|
|
backgroundColor: "transparent"
|
|
|
|
icon.name: "pushrule-add"
|
|
|
|
iconItem.small: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
Layout.fillWidth: false
|
|
|
|
onClicked: window.makePopup(
|
|
|
|
"Popups/PushRuleSettingsPopup/PushRuleSettingsPopup.qml",
|
|
|
|
{userId: root.userId, rule: newRule, ruleExists: false},
|
|
|
|
)
|
|
|
|
}
|
2020-10-30 14:15:17 -04:00
|
|
|
}
|
|
|
|
|
2021-02-28 12:06:34 -04:00
|
|
|
delegate: PushRuleDelegate {
|
2020-11-01 00:55:29 -04:00
|
|
|
page: root
|
2020-10-30 14:15:17 -04:00
|
|
|
width: root.width
|
|
|
|
}
|
|
|
|
|
2021-02-25 05:14:42 -04:00
|
|
|
onPendingEditsChanged:
|
|
|
|
utils.isEmptyObject(pendingEdits) ?
|
|
|
|
autoSaveTimer.stop() :
|
|
|
|
autoSaveTimer.restart()
|
2020-11-03 11:38:37 -04:00
|
|
|
|
2021-02-25 05:14:42 -04:00
|
|
|
Component.onDestruction: ! utils.isEmptyObject(pendingEdits) && save()
|
2020-11-01 00:55:29 -04:00
|
|
|
|
2021-02-25 05:14:42 -04:00
|
|
|
Timer {
|
|
|
|
id: autoSaveTimer
|
2022-01-16 16:48:55 +01:00
|
|
|
interval: 3000
|
2021-02-25 05:14:42 -04:00
|
|
|
onTriggered: root.save()
|
2020-11-01 00:55:29 -04:00
|
|
|
}
|
|
|
|
|
2020-10-30 14:15:17 -04:00
|
|
|
FlickShortcuts {
|
|
|
|
flickable: root
|
|
|
|
active: ! mainUI.debugConsole.visible && root.enableFlickShortcuts
|
|
|
|
}
|
|
|
|
}
|