diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2022-09-19 21:39:37 +0200 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2022-09-19 21:39:37 +0200 |
commit | fe403ddc709801262d0848b991691ae6c1d7123d (patch) | |
tree | 44aa5518f6d8a9ce9e5048848c4cabca47df6614 /resources | |
parent | Fix copypasto in cmake bundle option descriptions. (diff) | |
download | nheko-fe403ddc709801262d0848b991691ae6c1d7123d.tar.xz |
Rework how access rules for rooms are modified completely
Diffstat (limited to 'resources')
-rw-r--r-- | resources/qml/Root.qml | 16 | ||||
-rw-r--r-- | resources/qml/dialogs/AllowedRoomsSettingsDialog.qml | 178 | ||||
-rw-r--r-- | resources/qml/dialogs/RoomSettings.qml | 96 | ||||
-rw-r--r-- | resources/res.qrc | 1 |
4 files changed, 276 insertions, 15 deletions
diff --git a/resources/qml/Root.qml b/resources/qml/Root.qml index fc321136..063284c1 100644 --- a/resources/qml/Root.qml +++ b/resources/qml/Root.qml @@ -95,6 +95,22 @@ Pane { } Component { + id: allowedRoomSettingsComponent + + AllowedRoomsSettingsDialog { + } + + } + + function showAllowedRoomsEditor(settings) { + var dialog = allowedRoomSettingsComponent.createObject(timelineRoot, { + "roomSettings": settings + }); + dialog.show(); + destroyOnClose(dialog); + } + + Component { id: roomMembersComponent RoomMembers { diff --git a/resources/qml/dialogs/AllowedRoomsSettingsDialog.qml b/resources/qml/dialogs/AllowedRoomsSettingsDialog.qml new file mode 100644 index 00000000..60ac06de --- /dev/null +++ b/resources/qml/dialogs/AllowedRoomsSettingsDialog.qml @@ -0,0 +1,178 @@ +// SPDX-FileCopyrightText: 2022 Nheko Contributors +// +// SPDX-License-Identifier: GPL-3.0-or-later + +import ".." +import "../ui" +import Qt.labs.platform 1.1 as Platform +import QtQuick 2.15 +import QtQuick.Controls 2.3 +import QtQuick.Layouts 1.2 +import QtQuick.Window 2.13 +import im.nheko 1.0 + +ApplicationWindow { + id: allowedDialog + + property var roomSettings + + minimumWidth: 340 + minimumHeight: 450 + width: 450 + height: 680 + palette: Nheko.colors + color: Nheko.colors.window + modality: Qt.NonModal + flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint + title: qsTr("Allowed rooms settings") + + Shortcut { + sequence: StandardKey.Cancel + onActivated: roomSettingsDialog.close() + } + + ColumnLayout { + anchors.margins: Nheko.paddingMedium + anchors.fill: parent + spacing: 0 + + + MatrixText { + text: qsTr("List of rooms that allow access to this room. Anyone who is in any of those rooms can join this room.") + font.pixelSize: Math.floor(fontMetrics.font.pixelSize * 1.1) + Layout.fillWidth: true + Layout.fillHeight: false + color: Nheko.colors.text + Layout.bottomMargin: Nheko.paddingMedium + } + + ListView { + Layout.fillWidth: true + Layout.fillHeight: true + + id: view + + clip: true + + ScrollHelper { + flickable: parent + anchors.fill: parent + } + + model: roomSettings.allowedRoomsModel + spacing: 4 + cacheBuffer: 50 + + delegate: RowLayout { + anchors.left: parent.left + anchors.right: parent.right + + ColumnLayout { + Layout.fillWidth: true + Text { + Layout.fillWidth: true + text: model.name + color: Nheko.colors.text + textFormat: Text.PlainText + } + + Text { + Layout.fillWidth: true + text: model.isParent ? qsTr("Parent community") : qsTr("Other room") + color: Nheko.colors.buttonText + textFormat: Text.PlainText + } + } + + ToggleButton { + checked: model.allowed + Layout.alignment: Qt.AlignRight + onCheckedChanged: model.allowed = checked + } + } + } + + Column{ + id: roomEntryCompleter + Layout.fillWidth: true + + spacing: 1 + z: 5 + + Completer { + id: roomCompleter + + visible: roomEntry.text.length > 0 + width: parent.width + roomId: allowedDialog.roomSettings.roomId + completerName: "room" + bottomToTop: true + fullWidth: true + avatarHeight: Nheko.avatarSize / 2 + avatarWidth: Nheko.avatarSize / 2 + centerRowContent: false + rowMargin: 2 + rowSpacing: 2 + } + + MatrixTextField { + id: roomEntry + + width: parent.width + + placeholderText: qsTr("Enter additional rooms not in the list yet...") + + //font.pixelSize: Math.ceil(quickSwitcher.textHeight * 0.6) + color: Nheko.colors.text + onTextEdited: { + roomCompleter.completer.searchString = text; + } + Keys.onPressed: { + if (event.key == Qt.Key_Up || event.key == Qt.Key_Backtab) { + event.accepted = true; + roomCompleter.up(); + } else if (event.key == Qt.Key_Down || event.key == Qt.Key_Tab) { + event.accepted = true; + if (event.key == Qt.Key_Tab && (event.modifiers & Qt.ShiftModifier)) + roomCompleter.up(); + else + roomCompleter.down(); + } else if (event.matches(StandardKey.InsertParagraphSeparator)) { + roomCompleter.finishCompletion(); + event.accepted = true; + } + } + } + + } + + Connections { + function onCompletionSelected(id) { + console.log("selected: " + id); + roomSettings.allowedRoomsModel.addRoom(id); + roomEntry.clear(); + } + + function onCountChanged() { + if (roomCompleter.count > 0 && (roomCompleter.currentIndex < 0 || roomCompleter.currentIndex >= roomCompleter.count)) + roomCompleter.currentIndex = 0; + + } + + target: roomCompleter + } + + } + + footer: DialogButtonBox { + id: dbb + + standardButtons: DialogButtonBox.Ok | DialogButtonBox.Cancel + onAccepted: { + roomSettings.applyAllowedFromModel(); + allowedDialog.close(); + } + onRejected: allowedDialog.close() + } + +} diff --git a/resources/qml/dialogs/RoomSettings.qml b/resources/qml/dialogs/RoomSettings.qml index 137df6c4..33a6f6fa 100644 --- a/resources/qml/dialogs/RoomSettings.qml +++ b/resources/qml/dialogs/RoomSettings.qml @@ -288,32 +288,98 @@ ApplicationWindow { } Label { - text: qsTr("Room access") + text: qsTr("Anyone can join") Layout.fillWidth: true color: Nheko.colors.text } - ComboBox { + ToggleButton { + id: publicRoomButton + enabled: roomSettings.canChangeJoinRules - model: { - let opts = [qsTr("Anyone and guests"), qsTr("Anyone"), qsTr("Invited users")]; - if (roomSettings.supportsKnocking) - opts.push(qsTr("By knocking")); + checked: !roomSettings.privateAccess + Layout.alignment: Qt.AlignRight + } - if (roomSettings.supportsRestricted) - opts.push(qsTr("Restricted by membership in other rooms")); + Label { + text: qsTr("Allow knocking") + Layout.fillWidth: true + color: Nheko.colors.text + visible: knockingButton.visible + } - if (roomSettings.supportsKnockRestricted) - opts.push(qsTr("Restricted by membership in other rooms or by knocking")); + ToggleButton { + id: knockingButton - return opts; + visible: !publicRoomButton.checked + enabled: roomSettings.canChangeJoinRules && roomSettings.supportsKnocking + checked: roomSettings.knockingEnabled + onCheckedChanged: { + if (checked && !roomSettings.supportsKnockRestricted) restrictedButton.checked = false; } - currentIndex: roomSettings.accessJoinRules - onActivated: { - roomSettings.changeAccessRules(index); + Layout.alignment: Qt.AlignRight + } + + Label { + text: qsTr("Allow joining via other rooms") + Layout.fillWidth: true + color: Nheko.colors.text + visible: restrictedButton.visible + } + + ToggleButton { + id: restrictedButton + + visible: !publicRoomButton.checked + enabled: roomSettings.canChangeJoinRules && roomSettings.supportsRestricted + checked: roomSettings.restrictedEnabled + onCheckedChanged: { + if (checked && !roomSettings.supportsKnockRestricted) knockingButton.checked = false; } + Layout.alignment: Qt.AlignRight + } + + Label { + text: qsTr("Rooms to join via") + Layout.fillWidth: true + color: Nheko.colors.text + visible: allowedRoomsButton.visible + } + + Button { + id: allowedRoomsButton + + visible: restrictedButton.checked && restrictedButton.visible + enabled: roomSettings.canChangeJoinRules && roomSettings.supportsRestricted + + text: qsTr("Change") + ToolTip.text: qsTr("Change the list of rooms users can join this room via. Usually this is the official community of this room.") + onClicked: timelineRoot.showAllowedRoomsEditor(roomSettings) + Layout.alignment: Qt.AlignRight + } + + Label { + text: qsTr("Allow guests to join") + Layout.fillWidth: true + color: Nheko.colors.text + } + + ToggleButton { + id: guestAccessButton + + enabled: roomSettings.canChangeJoinRules + checked: roomSettings.guestAccess + Layout.alignment: Qt.AlignRight + } + + Button { + visible: publicRoomButton.checked == roomSettings.privateAccess || knockingButton.checked != roomSettings.knockingEnabled || restrictedButton.checked != roomSettings.restrictedEnabled || guestAccessButton.checked != roomSettings.guestAccess || roomSettings.allowedRoomsModified + enabled: roomSettings.canChangeJoinRules + + text: qsTr("Apply access rules") + onClicked: roomSettings.changeAccessRules(!publicRoomButton.checked, guestAccessButton.checked, knockingButton.checked, restrictedButton.checked) + Layout.columnSpan: 2 Layout.fillWidth: true - WheelHandler{} // suppress scrolling changing values } Label { diff --git a/resources/res.qrc b/resources/res.qrc index c14ebd5f..27d9c081 100644 --- a/resources/res.qrc +++ b/resources/res.qrc @@ -166,6 +166,7 @@ <file>qml/dialogs/ReadReceipts.qml</file> <file>qml/dialogs/RoomDirectory.qml</file> <file>qml/dialogs/RoomMembers.qml</file> + <file>qml/dialogs/AllowedRoomsSettingsDialog.qml</file> <file>qml/dialogs/RoomSettings.qml</file> <file>qml/dialogs/UserProfile.qml</file> <file>qml/emoji/EmojiPicker.qml</file> |