moment/src/gui/Pages/AccountSettings/Notifications.qml

112 lines
2.8 KiB
QML
Raw Normal View History

// 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
// {model.id: {notify, highlight, bubble, sound, urgency_hint}}
2020-11-01 00:55:29 -04:00
property var pendingEdits: ({})
property string saveFutureId: ""
function takeFocus() {
2020-11-01 00:55:29 -04:00
// deviceList.headerItem.exportButton.forceActiveFocus() TODO
}
function save() {
const args = []
for (const [modelId, kwargs] of Object.entries(pendingEdits)) {
if (! model.find(modelId)) continue // pushrule was deleted
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,
"mass_tweak_pushrules",
args,
() => {
if (! root) return
saveFutureId = ""
pendingEdits = {}
}
)
}
clip: true
model: ModelStore.get(userId, "pushrules")
implicitHeight: Math.min(window.height, contentHeight + bottomMargin)
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
}
}
section.property: "kind"
section.delegate: HLabel {
width: root.width
padding: theme.spacing
font.pixelSize: theme.fontSize.big
text:
2021-02-22 11:32:34 -04:00
section === "override" ? qsTr("High priority general rules") :
section === "content" ? qsTr("Message content rules") :
section === "room" ? qsTr("Room rules") :
section === "sender" ? qsTr("Sender rules") :
2021-02-22 11:32:34 -04:00
qsTr("Low priority general rules")
}
delegate: NotificationRuleDelegate {
2020-11-01 00:55:29 -04:00
page: root
width: root.width
}
2020-11-01 00:55:29 -04:00
footer: AutoDirectionLayout {
z: 100
width: root.width
enabled: Object.keys(root.pendingEdits).length !== 0
ApplyButton {
onClicked: root.save()
loading: root.saveFutureId !== ""
Layout.topMargin: theme.spacing
2020-11-01 00:55:29 -04:00
}
CancelButton {
onClicked: pendingEdits = {}
Layout.topMargin: theme.spacing
2020-11-01 00:55:29 -04:00
}
}
FlickShortcuts {
flickable: root
active: ! mainUI.debugConsole.visible && root.enableFlickShortcuts
}
}