Port PushNotification settings page to FormCard

This commit is contained in:
Tobias Fella
2023-08-30 18:46:54 +02:00
parent a3423e5724
commit 0c19052f32

View File

@@ -6,144 +6,129 @@ import QtQuick.Controls 2.15 as QQC2
import QtQuick.Layouts 1.15 import QtQuick.Layouts 1.15
import org.kde.kirigami 2.15 as Kirigami import org.kde.kirigami 2.15 as Kirigami
import org.kde.kirigamiaddons.labs.mobileform 0.1 as MobileForm import org.kde.kirigamiaddons.formcard 1.0 as FormCard
import org.kde.kitemmodels 1.0 import org.kde.kitemmodels 1.0
import org.kde.neochat 1.0 import org.kde.neochat 1.0
Kirigami.ScrollablePage { FormCard.FormCardPage {
id: root id: root
property NeoChatRoom room property NeoChatRoom room
title: i18nc('@title:window', 'Notifications') title: i18nc('@title:window', 'Notifications')
topPadding: 0
leftPadding: 0 FormCard.FormHeader {
rightPadding: 0 title: i18n("Room notifications setting")
ColumnLayout { }
spacing: 0
MobileForm.FormHeader { FormCard.FormCard {
Layout.fillWidth: true FormCard.FormRadioDelegate {
title: i18n("Room notifications setting") text: i18n("Follow global setting")
} checked: room.pushNotificationState === PushNotificationState.Default
MobileForm.FormCard { enabled: room.pushNotificationState !== PushNotificationState.Unknown
Layout.fillWidth: true onToggled: {
contentItem: ColumnLayout { room.pushNotificationState = PushNotificationState.Default
spacing: 0
MobileForm.FormRadioDelegate {
text: i18n("Follow global setting")
checked: room.pushNotificationState === PushNotificationState.Default
enabled: room.pushNotificationState !== PushNotificationState.Unknown
onToggled: {
room.pushNotificationState = PushNotificationState.Default
}
}
MobileForm.FormRadioDelegate {
text: i18nc("As in 'notify for all messages'","All")
checked: room.pushNotificationState === PushNotificationState.All
enabled: room.pushNotificationState !== PushNotificationState.Unknown
onToggled: {
room.pushNotificationState = PushNotificationState.All
}
}
MobileForm.FormRadioDelegate {
text: i18nc("As in 'notify when the user is mentioned or the message contains a set keyword'","@Mentions and Keywords")
checked: room.pushNotificationState === PushNotificationState.MentionKeyword
enabled: room.pushNotificationState !== PushNotificationState.Unknown
onToggled: {
room.pushNotificationState = PushNotificationState.MentionKeyword
}
}
MobileForm.FormRadioDelegate {
text: i18nc("As in 'do not notify for any messages'","Off")
checked: room.pushNotificationState === PushNotificationState.Mute
enabled: room.pushNotificationState !== PushNotificationState.Unknown
onToggled: {
room.pushNotificationState = PushNotificationState.Mute
}
}
} }
} }
FormCard.FormRadioDelegate {
MobileForm.FormCard { text: i18nc("As in 'notify for all messages'","All")
Layout.fillWidth: true checked: room.pushNotificationState === PushNotificationState.All
enabled: room.pushNotificationState !== PushNotificationState.Unknown
contentItem: ColumnLayout { onToggled: {
spacing: 0 room.pushNotificationState = PushNotificationState.All
}
MobileForm.FormCardHeader { }
title: i18n("Keywords") FormCard.FormRadioDelegate {
} text: i18nc("As in 'notify when the user is mentioned or the message contains a set keyword'","@Mentions and Keywords")
Repeater { checked: room.pushNotificationState === PushNotificationState.MentionKeyword
model: KSortFilterProxyModel { enabled: room.pushNotificationState !== PushNotificationState.Unknown
sourceModel: Controller.pushRuleModel onToggled: {
room.pushNotificationState = PushNotificationState.MentionKeyword
filterRowCallback: function(source_row, source_parent) { }
let sectionRole = sourceModel.data(sourceModel.index(source_row, 0, source_parent), PushRuleModel.SectionRole) }
let roomIdRole = sourceModel.data(sourceModel.index(source_row, 0, source_parent), PushRuleModel.RoomIdRole) FormCard.FormRadioDelegate {
return sectionRole == PushNotificationSection.RoomKeywords && roomIdRole == root.room.id; text: i18nc("As in 'do not notify for any messages'","Off")
} checked: room.pushNotificationState === PushNotificationState.Mute
} enabled: room.pushNotificationState !== PushNotificationState.Unknown
onToggled: {
delegate: ruleDelegate room.pushNotificationState = PushNotificationState.Mute
}
MobileForm.AbstractFormDelegate {
Layout.fillWidth: true
contentItem : RowLayout {
Kirigami.ActionTextField {
id: keywordAddField
Layout.fillWidth: true
placeholderText: i18n("Keyword…")
enabled: NotificationsManager.keywordNotificationAction !== PushNotificationAction.Unknown
rightActions: Kirigami.Action {
icon.name: "edit-clear"
visible: keywordAddField.text.length > 0
onTriggered: {
keywordAddField.text = ""
}
}
onAccepted: {
Controller.pushRuleModel.addKeyword(keywordAddField.text, root.room.id)
keywordAddField.text = ""
}
}
QQC2.Button {
id: addButton
text: i18n("Add keyword")
Accessible.name: text
icon.name: "list-add"
display: QQC2.AbstractButton.IconOnly
enabled: NotificationsManager.keywordNotificationAction !== PushNotificationAction.Unknown
onClicked: {
Controller.pushRuleModel.addKeyword(keywordAddField.text, root.room.id)
keywordAddField.text = ""
}
QQC2.ToolTip {
text: addButton.text
delay: Kirigami.Units.toolTipDelay
}
}
}
}
} }
} }
} }
Component { FormCard.FormHeader {
id: ruleDelegate title: i18n("Keywords")
NotificationRuleItem { }
onDeleteRule: { FormCard.FormCard {
Controller.pushRuleModel.removeKeyword(id) Repeater {
model: KSortFilterProxyModel {
sourceModel: Controller.pushRuleModel
filterRowCallback: function(source_row, source_parent) {
let sectionRole = sourceModel.data(sourceModel.index(source_row, 0, source_parent), PushRuleModel.SectionRole)
let roomIdRole = sourceModel.data(sourceModel.index(source_row, 0, source_parent), PushRuleModel.RoomIdRole)
return sectionRole == PushNotificationSection.RoomKeywords && roomIdRole == root.room.id;
}
}
delegate: ruleDelegate
Component {
id: ruleDelegate
NotificationRuleItem {
onDeleteRule: {
Controller.pushRuleModel.removeKeyword(id)
}
onActionChanged: (action) => Controller.pushRuleModel.setPushRuleAction(id, action)
}
}
}
FormCard.AbstractFormDelegate {
Layout.fillWidth: true
contentItem : RowLayout {
Kirigami.ActionTextField {
id: keywordAddField
Layout.fillWidth: true
placeholderText: i18n("Keyword…")
enabled: NotificationsManager.keywordNotificationAction !== PushNotificationAction.Unknown
rightActions: Kirigami.Action {
icon.name: "edit-clear"
visible: keywordAddField.text.length > 0
onTriggered: {
keywordAddField.text = ""
}
}
onAccepted: {
Controller.pushRuleModel.addKeyword(keywordAddField.text, root.room.id)
keywordAddField.text = ""
}
}
QQC2.Button {
id: addButton
text: i18n("Add keyword")
Accessible.name: text
icon.name: "list-add"
display: QQC2.AbstractButton.IconOnly
enabled: NotificationsManager.keywordNotificationAction !== PushNotificationAction.Unknown
onClicked: {
Controller.pushRuleModel.addKeyword(keywordAddField.text, root.room.id)
keywordAddField.text = ""
}
QQC2.ToolTip {
text: addButton.text
delay: Kirigami.Units.toolTipDelay
}
}
} }
onActionChanged: (action) => Controller.pushRuleModel.setPushRuleAction(id, action)
} }
} }
} }