Port some things away from Controller::activeConnection

This commit is contained in:
Tobias Fella
2023-11-04 23:26:41 +01:00
parent ff4cf86ea5
commit 0e55c3b38f
29 changed files with 289 additions and 154 deletions

View File

@@ -14,17 +14,23 @@ import org.kde.neochat
FormCard.FormCardPage {
id: root
required property NeoChatConnection connection
title: i18nc("@title:window", "Notifications")
property PushRuleModel pushRuleModel: PushRuleModel {
connection: root.connection
}
FormCard.FormCard {
Layout.topMargin: Kirigami.Units.largeSpacing
FormCard.FormCheckDelegate {
text: i18n("Enable notifications for this account")
description: i18n("Whether push notifications are generated by your Matrix server")
checked: Controller.pushRuleModel.globalNotificationsEnabled
enabled: Controller.pushRuleModel.globalNotificationsSet
checked: root.pushRuleModel.globalNotificationsEnabled
enabled: root.pushRuleModel.globalNotificationsSet
onToggled: {
Controller.pushRuleModel.globalNotificationsEnabled = checked
root.pushRuleModel.globalNotificationsEnabled = checked
}
}
}
@@ -35,7 +41,7 @@ FormCard.FormCardPage {
FormCard.FormCard {
Repeater {
model: KSortFilterProxyModel {
sourceModel: Controller.pushRuleModel
sourceModel: root.pushRuleModel
filterRowCallback: function(source_row, source_parent) {
let sectionRole = sourceModel.data(sourceModel.index(source_row, 0, source_parent), PushRuleModel.SectionRole)
return sectionRole == PushNotificationSection.Room;
@@ -52,7 +58,7 @@ FormCard.FormCardPage {
FormCard.FormCard {
Repeater {
model: KSortFilterProxyModel {
sourceModel: Controller.pushRuleModel
sourceModel: root.pushRuleModel
filterRowCallback: function(source_row, source_parent) {
let sectionRole = sourceModel.data(sourceModel.index(source_row, 0, source_parent), PushRuleModel.SectionRole)
return sectionRole == PushNotificationSection.Mentions;
@@ -69,7 +75,7 @@ FormCard.FormCardPage {
FormCard.FormCard {
Repeater {
model: KSortFilterProxyModel {
sourceModel: Controller.pushRuleModel
sourceModel: root.pushRuleModel
filterRowCallback: function(source_row, source_parent) {
let sectionRole = sourceModel.data(sourceModel.index(source_row, 0, source_parent), PushRuleModel.SectionRole)
@@ -100,7 +106,7 @@ FormCard.FormCardPage {
}
onAccepted: {
Controller.pushRuleModel.addKeyword(keywordAddField.text)
root.pushRuleModel.addKeyword(keywordAddField.text)
keywordAddField.text = ""
}
}
@@ -114,7 +120,7 @@ FormCard.FormCardPage {
enabled: NotificationsManager.keywordNotificationAction !== PushNotificationAction.Unknown
onClicked: {
Controller.pushRuleModel.addKeyword(keywordAddField.text)
root.pushRuleModel.addKeyword(keywordAddField.text)
keywordAddField.text = ""
}
@@ -133,7 +139,7 @@ FormCard.FormCardPage {
FormCard.FormCard {
Repeater {
model: KSortFilterProxyModel {
sourceModel: Controller.pushRuleModel
sourceModel: root.pushRuleModel
filterRowCallback: function(source_row, source_parent) {
let sectionRole = sourceModel.data(sourceModel.index(source_row, 0, source_parent), PushRuleModel.SectionRole)
return sectionRole == PushNotificationSection.Invites;
@@ -154,7 +160,7 @@ FormCard.FormCardPage {
Repeater {
model: KSortFilterProxyModel {
id: unknownModel
sourceModel: Controller.pushRuleModel
sourceModel: root.pushRuleModel
filterRowCallback: function(source_row, source_parent) {
let sectionRole = sourceModel.data(sourceModel.index(source_row, 0, source_parent), PushRuleModel.SectionRole)
return sectionRole == PushNotificationSection.Unknown;
@@ -169,9 +175,9 @@ FormCard.FormCardPage {
id: ruleDelegate
NotificationRuleItem {
onDeleteRule: {
Controller.pushRuleModel.removeKeyword(id)
root.pushRuleModel.removeKeyword(id)
}
onActionChanged: (action) => Controller.pushRuleModel.setPushRuleAction(id, action)
onActionChanged: (action) => root.pushRuleModel.setPushRuleAction(id, action)
}
}
}

View File

@@ -69,6 +69,7 @@ Kirigami.ScrollablePage {
valueRole: "url"
model: ServerListModel {
id: serverListModel
connection: root.connection
}
delegate: Delegates.RoundedItemDelegate {

View File

@@ -16,6 +16,10 @@ FormCard.FormCardPage {
property NeoChatRoom room
property PushRuleModel pushRuleModel: PushRuleModel {
connection: root.room.connection
}
title: i18nc('@title:window', 'Notifications')
FormCard.FormHeader {
@@ -63,7 +67,7 @@ FormCard.FormCardPage {
FormCard.FormCard {
Repeater {
model: KSortFilterProxyModel {
sourceModel: Controller.pushRuleModel
sourceModel: root.pushRuleModel
filterRowCallback: function(source_row, source_parent) {
let sectionRole = sourceModel.data(sourceModel.index(source_row, 0, source_parent), PushRuleModel.SectionRole)
@@ -78,9 +82,9 @@ FormCard.FormCardPage {
id: ruleDelegate
NotificationRuleItem {
onDeleteRule: {
Controller.pushRuleModel.removeKeyword(id)
root.pushRuleModel.removeKeyword(id)
}
onActionChanged: (action) => Controller.pushRuleModel.setPushRuleAction(id, action)
onActionChanged: (action) => root.pushRuleModel.setPushRuleAction(id, action)
}
}
}
@@ -105,7 +109,7 @@ FormCard.FormCardPage {
}
onAccepted: {
Controller.pushRuleModel.addKeyword(keywordAddField.text, root.room.id)
root.pushRuleModel.addKeyword(keywordAddField.text, root.room.id)
keywordAddField.text = ""
}
}
@@ -119,7 +123,7 @@ FormCard.FormCardPage {
enabled: NotificationsManager.keywordNotificationAction !== PushNotificationAction.Unknown && keywordAddField.text.length > 0
onClicked: {
Controller.pushRuleModel.addKeyword(keywordAddField.text, root.room.id)
root.pushRuleModel.addKeyword(keywordAddField.text, root.room.id)
keywordAddField.text = ""
}

View File

@@ -39,6 +39,8 @@ Kirigami.Page {
sortFilterRoomListModel.filterText = "";
}
Component.onCompleted: Runner.roomListModel = root.roomListModel
Connections {
target: RoomManager
function onCurrentRoomChanged() {

View File

@@ -32,6 +32,11 @@ KirigamiSettings.CategorizedSettings {
text: i18n("Notifications")
icon.name: "preferences-desktop-notification"
page: Qt.resolvedUrl("GlobalNotificationsPage.qml")
initialProperties: {
return {
connection: root.connection
}
}
},
KirigamiSettings.SettingAction {
actionName: "security"

View File

@@ -40,6 +40,13 @@ Kirigami.ApplicationWindow {
}
}
onConnectionChanged: {
CustomEmojiModel.connection = root.connection
MatrixImageProvider.connection = root.connection
RoomManager.connection = root.connection
SpaceHierarchyCache.connection = root.connection
}
Connections {
target: root.quitAction
function onTriggered() {
@@ -190,6 +197,10 @@ Kirigami.ApplicationWindow {
}
Component.onCompleted: {
CustomEmojiModel.connection = root.connection
MatrixImageProvider.connection = root.connection
RoomManager.connection = root.connection
SpaceHierarchyCache.connection = root.connection
WindowController.setBlur(pageStack, Config.blur && !Config.compactLayout);
if (Config.minimizeToSystemTrayOnStartup && !Kirigami.Settings.isMobile && Controller.supportSystemTray && Config.systemTray) {
restoreWindowGeometryConnections.enabled = true; // To restore window size and position