Cleanup RoomSecurityPage

This commit is contained in:
Tobias Fella
2025-08-17 21:35:58 +02:00
parent 5aeefea5c0
commit 5fc59b0d66

View File

@@ -2,6 +2,8 @@
// SPDX-FileCopyrightText: 2021 Carl Schwan <carl@carlschwan.eu> // SPDX-FileCopyrightText: 2021 Carl Schwan <carl@carlschwan.eu>
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
pragma ComponentBehavior: Bound
import QtQuick import QtQuick
import QtQuick.Controls as QQC2 import QtQuick.Controls as QQC2
import QtQuick.Layouts import QtQuick.Layouts
@@ -9,31 +11,29 @@ import QtQuick.Layouts
import org.kde.kirigami as Kirigami import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.formcard as FormCard import org.kde.kirigamiaddons.formcard as FormCard
import Quotient
import org.kde.neochat import org.kde.neochat
import Quotient
FormCard.FormCardPage { FormCard.FormCardPage {
id: root id: root
property NeoChatRoom room property NeoChatRoom room
property string needUpgradeRoom: i18n("You need to upgrade this room to a newer version to enable this setting.") property string needUpgradeRoom: i18nc("@info", "You need to upgrade this room to a newer version to enable this setting.")
title: i18n("Security") title: i18nc("@title", "Security")
FormCard.FormHeader { FormCard.FormHeader {
title: i18nc("@option:check", "Encryption") title: i18nc("@option:check", "Encryption")
} }
FormCard.FormCard { FormCard.FormCard {
FormCard.AbstractFormDelegate { FormCard.AbstractFormDelegate {
visible: room.usesEncryption visible: root.room.usesEncryption
contentItem: RowLayout { contentItem: RowLayout {
spacing: Kirigami.Units.largeSpacing spacing: Kirigami.Units.largeSpacing
Kirigami.Icon { Kirigami.Icon {
source: "lock" source: "lock"
width: Kirigami.Units.iconSizes.sizeForLabels
height: Kirigami.Units.iconSizes.sizeForLabels
} }
QQC2.Label { QQC2.Label {
text: i18nc("@info", "This room uses encryption.") text: i18nc("@info", "This room uses encryption.")
@@ -49,15 +49,12 @@ FormCard.FormCardPage {
icon.name: "lock-symbolic" icon.name: "lock-symbolic"
text: i18nc("@action:button Enable encryption in this room", "Enable Encryption…") text: i18nc("@action:button Enable encryption in this room", "Enable Encryption…")
description: i18nc("@info:description", "Once enabled, encryption cannot be disabled.") description: i18nc("@info:description", "Once enabled, encryption cannot be disabled.")
enabled: room.canEncryptRoom enabled: root.room.canEncryptRoom
visible: !room.usesEncryption visible: !root.room.usesEncryption
onClicked: { onClicked: (confirmEncryptionDialog.createObject(QQC2.Overlay.overlay, {
let dialog = confirmEncryptionDialog.createObject(QQC2.Overlay.overlay, { room: root.room
room: room }) as ConfirmEncryptionDialog).open()
});
dialog.open();
}
} }
} }
@@ -67,28 +64,28 @@ FormCard.FormCardPage {
FormCard.FormCard { FormCard.FormCard {
FormCard.FormRadioDelegate { FormCard.FormRadioDelegate {
text: i18nc("@option:check", "Private (invite only)") text: i18nc("@option:check", "Private (invite only)")
description: i18n("Only invited people can join.") description: i18nc("@info", "Only invited people can join.")
checked: room.joinRule === JoinRule.Invite checked: root.room.joinRule === JoinRule.Invite
enabled: room.canSendState("m.room.join_rules") enabled: root.room.canSendState("m.room.join_rules")
onCheckedChanged: if (checked && room.joinRule != JoinRule.Invite) { onCheckedChanged: if (checked && root.room.joinRule != JoinRule.Invite) {
root.room.joinRule = JoinRule.Invite; root.room.joinRule = JoinRule.Invite;
} }
} }
FormCard.FormRadioDelegate { FormCard.FormRadioDelegate {
text: i18nc("@option:check", "Space members") text: i18nc("@option:check", "Space members")
description: i18n("Anyone in the selected spaces can find and join.") + (!["8", "9", "10", "11", "12"].includes(room.version) ? `\n${needUpgradeRoom}` : "") description: i18nc("@info", "Anyone in the selected spaces can find and join.") + (!["8", "9", "10", "11", "12"].includes(root.room.version) ? `\n${root.needUpgradeRoom}` : "")
checked: room.joinRule === JoinRule.Restricted checked: root.room.joinRule === JoinRule.Restricted
enabled: room.canSendState("m.room.join_rules") && ["8", "9", "10", "11", "12"].includes(room.version) enabled: root.room.canSendState("m.room.join_rules") && ["8", "9", "10", "11", "12"].includes(root.room.version)
onCheckedChanged: if (checked && room.joinRule != JoinRule.Restricted) { onCheckedChanged: if (checked && root.room.joinRule != JoinRule.Restricted) {
selectSpacesDialog.createObject(QQC2.Overlay.overlay).open(); (selectSpacesDialog.createObject(QQC2.Overlay.overlay) as SelectSpacesDialog).open();
} }
contentItem.children: QQC2.Button { contentItem.children: QQC2.Button {
visible: root.room.joinRule === JoinRule.Restricted visible: root.room.joinRule === JoinRule.Restricted
text: i18n("Select spaces") text: i18nc("@action:button", "Select spaces")
icon.name: "list-add" icon.name: "list-add"
onClicked: selectSpacesDialog.createObject(QQC2.Overlay.overlay).open() onClicked: (selectSpacesDialog.createObject(QQC2.Overlay.overlay) as SelectSpacesDialog).open()
QQC2.ToolTip.text: text QQC2.ToolTip.text: text
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
@@ -104,19 +101,19 @@ FormCard.FormCardPage {
} }
FormCard.FormRadioDelegate { FormCard.FormRadioDelegate {
text: i18nc("@option:check", "Knock") text: i18nc("@option:check", "Knock")
description: i18n("People not in the room need to request an invite to join the room.") + (!["7", "8", "9", "10", "11", "12"].includes(room.version) ? `\n${needUpgradeRoom}` : "") description: i18nc("@info", "People not in the room need to request an invite to join the room.") + (!["7", "8", "9", "10", "11", "12"].includes(root.room.version) ? `\n${root.needUpgradeRoom}` : "")
checked: room.joinRule === JoinRule.Knock checked: root.room.joinRule === JoinRule.Knock
// https://spec.matrix.org/v1.4/rooms/#feature-matrix // https://spec.matrix.org/v1.4/rooms/#feature-matrix
enabled: room.canSendState("m.room.join_rules") && ["7", "8", "9", "10", "11", "12"].includes(room.version) enabled: root.room.canSendState("m.room.join_rules") && ["7", "8", "9", "10", "11", "12"].includes(root.room.version)
onCheckedChanged: if (checked && room.joinRule != JoinRule.Knock) { onCheckedChanged: if (checked && root.room.joinRule != JoinRule.Knock) {
root.room.joinRule = JoinRule.Knock; root.room.joinRule = JoinRule.Knock;
} }
} }
FormCard.FormRadioDelegate { FormCard.FormRadioDelegate {
text: i18nc("@option:check", "Public") text: i18nc("@option:check", "Public")
description: i18nc("@option:check", "Anyone can find and join.") description: i18nc("@option:check", "Anyone can find and join.")
checked: room.joinRule === JoinRule.Public checked: root.room.joinRule === JoinRule.Public
enabled: room.canSendState("m.room.join_rules") enabled: root.room.canSendState("m.room.join_rules")
onCheckedChanged: if (checked && root.room.joinRule != JoinRule.Public) { onCheckedChanged: if (checked && root.room.joinRule != JoinRule.Public) {
root.room.joinRule = JoinRule.Public; root.room.joinRule = JoinRule.Public;
} }
@@ -130,37 +127,37 @@ FormCard.FormCardPage {
FormCard.FormRadioDelegate { FormCard.FormRadioDelegate {
text: i18nc("@option:check", "Anyone") text: i18nc("@option:check", "Anyone")
description: i18nc("@option:check", "Anyone, regardless of whether they have joined, can view history.") description: i18nc("@option:check", "Anyone, regardless of whether they have joined, can view history.")
checked: room.historyVisibility === "world_readable" checked: root.room.historyVisibility === "world_readable"
enabled: room.canSendState("m.room.history_visibility") enabled: root.room.canSendState("m.room.history_visibility")
onCheckedChanged: if (checked) { onCheckedChanged: if (checked) {
room.historyVisibility = "world_readable"; root.room.historyVisibility = "world_readable";
} }
} }
FormCard.FormRadioDelegate { FormCard.FormRadioDelegate {
text: i18nc("@option:check", "Members only") text: i18nc("@option:check", "Members only")
description: i18nc("@option:check", "All members can view the entire message history, even before they joined.") description: i18nc("@option:check", "All members can view the entire message history, even before they joined.")
checked: room.historyVisibility === "shared" checked: root.room.historyVisibility === "shared"
enabled: room.canSendState("m.room.history_visibility") enabled: root.room.canSendState("m.room.history_visibility")
onCheckedChanged: if (checked) { onCheckedChanged: if (checked) {
room.historyVisibility = "shared"; root.room.historyVisibility = "shared";
} }
} }
FormCard.FormRadioDelegate { FormCard.FormRadioDelegate {
text: i18nc("@option:check", "Members only (since invite)") text: i18nc("@option:check", "Members only (since invite)")
description: i18nc("@option:check", "New members can view the message history from the point they were invited to the room.") description: i18nc("@option:check", "New members can view the message history from the point they were invited to the room.")
checked: room.historyVisibility === "invited" checked: root.room.historyVisibility === "invited"
enabled: room.canSendState("m.room.history_visibility") enabled: root.room.canSendState("m.room.history_visibility")
onCheckedChanged: if (checked) { onCheckedChanged: if (checked) {
room.historyVisibility = "invited"; root.room.historyVisibility = "invited";
} }
} }
FormCard.FormRadioDelegate { FormCard.FormRadioDelegate {
text: i18nc("@option:check", "Members only (since joining)") text: i18nc("@option:check", "Members only (since joining)")
description: i18nc("@option:check", "New members can view the message history from the point they joined the room.") description: i18nc("@option:check", "New members can view the message history from the point they joined the room.")
checked: room.historyVisibility === "joined" checked: root.room.historyVisibility === "joined"
enabled: room.canSendState("m.room.history_visibility") enabled: root.room.canSendState("m.room.history_visibility")
onCheckedChanged: if (checked) { onCheckedChanged: if (checked) {
room.historyVisibility = "joined"; root.room.historyVisibility = "joined";
} }
} }
} }
@@ -179,9 +176,9 @@ FormCard.FormCardPage {
} }
property Connections connections: Connections { property Connections connections: Connections {
target: room target: root.room
onEncryption: { function onEncryption() {
enableEncryptionSwitch.checked = room.usesEncryption; enableEncryptionSwitch.checked = root.room.usesEncryption;
} }
} }
} }