Skip to content
Snippets Groups Projects
RoomSettings.qml 10.2 KiB
Newer Older
  • Learn to ignore specific revisions
  • Nicolas Werner's avatar
    Nicolas Werner committed
    // SPDX-FileCopyrightText: 2021 Nheko Contributors
    
    // SPDX-FileCopyrightText: 2022 Nheko Contributors
    
    Nicolas Werner's avatar
    Nicolas Werner committed
    // SPDX-License-Identifier: GPL-3.0-or-later
    
    
    import ".."
    import "../ui"
    
    Nicolas Werner's avatar
    Nicolas Werner committed
    import Qt.labs.platform 1.1 as Platform
    
    Jedi18's avatar
    Jedi18 committed
    import QtQuick.Controls 2.3
    import QtQuick.Layouts 1.2
    
    import QtQuick.Window 2.13
    
    Jedi18's avatar
    Jedi18 committed
    import im.nheko 1.0
    
    ApplicationWindow {
    
        id: roomSettingsDialog
    
    Jedi18's avatar
    Jedi18 committed
    
        property var roomSettings
    
    
        minimumWidth: 340
        minimumHeight: 340
    
        width: 450
        height: 680
    
        palette: Nheko.colors
        color: Nheko.colors.window
    
        flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint
    
        title: qsTr("Room Settings")
    
    Jedi18's avatar
    Jedi18 committed
    
        Shortcut {
            sequence: StandardKey.Cancel
            onActivated: roomSettingsDialog.close()
        }
    
        ScrollHelper {
            flickable: flickable
            anchors.fill: flickable
        }
        Flickable {
            id: flickable
            boundsBehavior: Flickable.StopAtBounds
            anchors.fill: parent
            clip: true
            flickableDirection: Flickable.VerticalFlick
            contentWidth: contentLayout1.width
            contentHeight: contentLayout1.height
    
    Malte E's avatar
    Malte E committed
            ColumnLayout {
                id: contentLayout1
                width: flickable.width
                spacing: Nheko.paddingMedium
    
                Avatar {
                    Layout.topMargin: Nheko.paddingMedium
                    url: roomSettings.roomAvatarUrl.replace("mxc://", "image://MxcImage/")
                    roomid: roomSettings.roomId
                    displayName: roomSettings.roomName
                    height: 130
                    width: 130
                    Layout.alignment: Qt.AlignHCenter
                    onClicked: {
                        if (roomSettings.canChangeAvatar)
                            roomSettings.updateAvatar();
    
    Malte E's avatar
    Malte E committed
                    }
    
    Malte E's avatar
    Malte E committed
                Spinner {
                    Layout.alignment: Qt.AlignHCenter
                    visible: roomSettings.isLoading
                    foreground: Nheko.colors.mid
                    running: roomSettings.isLoading
                }
    
    Malte E's avatar
    Malte E committed
                Text {
                    id: errorText
    
    Malte E's avatar
    Malte E committed
                    color: "red"
                    visible: opacity > 0
                    opacity: 0
                    Layout.alignment: Qt.AlignHCenter
                    wrapMode: Text.Wrap // somehow still doesn't wrap
                }
    
    Malte E's avatar
    Malte E committed
                SequentialAnimation {
                    id: hideErrorAnimation
    
    Malte E's avatar
    Malte E committed
                    running: false
    
    Malte E's avatar
    Malte E committed
                    PauseAnimation {
                        duration: 4000
                    }
    
    Malte E's avatar
    Malte E committed
                    NumberAnimation {
                        target: errorText
                        property: 'opacity'
                        to: 0
                        duration: 1000
                    }
    
    Malte E's avatar
    Malte E committed
    
                Connections {
                    target: roomSettings
                    function onDisplayError(errorMessage) {
                        errorText.text = errorMessage;
                        errorText.opacity = 1;
                        hideErrorAnimation.restart();
                    }
    
    Jedi18's avatar
    Jedi18 committed
                }
    
    Malte E's avatar
    Malte E committed
                    Label {
                        text: roomSettings.roomName
                        Layout.alignment: Qt.AlignHCenter
                        font.pixelSize: fontMetrics.font.pixelSize * 2
                        Layout.fillWidth: true
                        horizontalAlignment: TextEdit.AlignHCenter
                    }
    
    Jedi18's avatar
    Jedi18 committed
    
    
    Malte E's avatar
    Malte E committed
                    Label {
                        text: qsTr("%n member(s)", "", roomSettings.memberCount)
                        Layout.alignment: Qt.AlignHCenter
    
    Malte E's avatar
    Malte E committed
                        TapHandler {
                            onSingleTapped: TimelineManager.openRoomMembers(Rooms.getRoomById(roomSettings.roomId))
                        }
    
                        CursorShape {
                            cursorShape: Qt.PointingHandCursor
                            anchors.fill: parent
                        }
    
    Malte E's avatar
    Malte E committed
                ImageButton {
                    Layout.alignment: Qt.AlignHCenter
                    image: ":/icons/icons/ui/edit.svg"
                    visible: roomSettings.canChangeNameAndTopic
                    onClicked: roomSettings.openEditModal()
    
    Jedi18's avatar
    Jedi18 committed
                }
    
    Malte E's avatar
    Malte E committed
                TextArea {
                    Layout.fillHeight: true
                    Layout.alignment: Qt.AlignHCenter
                    Layout.fillWidth: true
                    Layout.leftMargin: Nheko.paddingLarge
                    Layout.rightMargin: Nheko.paddingLarge
    
    Jedi18's avatar
    Jedi18 committed
    
    
                    text: TimelineManager.escapeEmoji(roomSettings.roomTopic)
    
    Nicolas Werner's avatar
    Nicolas Werner committed
                    wrapMode: TextEdit.WordWrap
                    textFormat: TextEdit.RichText
    
    Jedi18's avatar
    Jedi18 committed
                    readOnly: true
                    background: null
    
                    color: Nheko.colors.text
    
    Nicolas Werner's avatar
    Nicolas Werner committed
                    horizontalAlignment: TextEdit.AlignHCenter
    
                    onLinkActivated: Nheko.openLink(link)
    
    Nicolas Werner's avatar
    Nicolas Werner committed
                    CursorShape {
                        anchors.fill: parent
                        cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor
                    }
    
    Malte E's avatar
    Malte E committed
                }
    
    Jedi18's avatar
    Jedi18 committed
    
    
    Malte E's avatar
    Malte E committed
                GridLayout {
                    columns: 2
                    rowSpacing: Nheko.paddingMedium
                    Layout.margins: Nheko.paddingMedium
    
    Jedi18's avatar
    Jedi18 committed
    
    
    Malte E's avatar
    Malte E committed
                    Label {
                        text: qsTr("SETTINGS")
                        font.bold: true
                    }
    
    Jedi18's avatar
    Jedi18 committed
    
    
    Malte E's avatar
    Malte E committed
                    Item {
                        Layout.fillWidth: true
                    }
    
    Jedi18's avatar
    Jedi18 committed
    
    
    Malte E's avatar
    Malte E committed
                    Label {
                        text: qsTr("Notifications")
                        Layout.fillWidth: true
                    }
    
    Malte E's avatar
    Malte E committed
                    ComboBox {
                        model: [qsTr("Muted"), qsTr("Mentions only"), qsTr("All messages")]
                        currentIndex: roomSettings.notifications
                        onActivated: {
                            roomSettings.changeNotifications(index);
                        }
                        Layout.fillWidth: true
    
    Jedi18's avatar
    Jedi18 committed
    
    
    Malte E's avatar
    Malte E committed
                    Label {
                        text: qsTr("Room access")
                        Layout.fillWidth: true
                    }
    
    Jedi18's avatar
    Jedi18 committed
    
    
    Malte E's avatar
    Malte E committed
                    ComboBox {
                        enabled: roomSettings.canChangeJoinRules
                        model: {
                            let opts = [qsTr("Anyone and guests"), qsTr("Anyone"), qsTr("Invited users")];
                            if (roomSettings.supportsKnocking)
                                opts.push(qsTr("By knocking"));
    
    Malte E's avatar
    Malte E committed
                            if (roomSettings.supportsRestricted)
                                opts.push(qsTr("Restricted by membership in other rooms"));
    
    Malte E's avatar
    Malte E committed
                            return opts;
                        }
                        currentIndex: roomSettings.accessJoinRules
                        onActivated: {
                            roomSettings.changeAccessRules(index);
                        }
                        Layout.fillWidth: true
    
    Jedi18's avatar
    Jedi18 committed
    
    
    Malte E's avatar
    Malte E committed
                    Label {
                        text: qsTr("Encryption")
                    }
    
    Jedi18's avatar
    Jedi18 committed
    
    
    Malte E's avatar
    Malte E committed
                    ToggleButton {
                        id: encryptionToggle
    
    Malte E's avatar
    Malte E committed
                        checked: roomSettings.isEncryptionEnabled
                        onCheckedChanged: {
                            if (roomSettings.isEncryptionEnabled) {
                                checked = true;
                                return ;
                            }
                            confirmEncryptionDialog.open();
    
    Malte E's avatar
    Malte E committed
                        Layout.alignment: Qt.AlignRight
    
    Malte E's avatar
    Malte E committed
                    Platform.MessageDialog {
                        id: confirmEncryptionDialog
    
    Malte E's avatar
    Malte E committed
                        title: qsTr("End-to-End Encryption")
                        text: qsTr("Encryption is currently experimental and things might break unexpectedly. <br>
                                    Please take note that it can't be disabled afterwards.")
                        modality: Qt.NonModal
                        onAccepted: {
                            if (roomSettings.isEncryptionEnabled)
                                return ;
    
    Malte E's avatar
    Malte E committed
                            roomSettings.enableEncryption();
                        }
                        onRejected: {
                            encryptionToggle.checked = false;
                        }
                        buttons: Platform.MessageDialog.Ok | Platform.MessageDialog.Cancel
    
    Malte E's avatar
    Malte E committed
    
                    Label {
                        text: qsTr("Sticker & Emote Settings")
    
    Malte E's avatar
    Malte E committed
                    Button {
                        text: qsTr("Change")
                        ToolTip.text: qsTr("Change what packs are enabled, remove packs or create new ones")
                        onClicked: TimelineManager.openImagePackSettings(roomSettings.roomId)
                        Layout.alignment: Qt.AlignRight
                    }
    
    Malte E's avatar
    Malte E committed
                    Label {
                        text: qsTr("Hidden events")
                    }
    
    Malte E's avatar
    Malte E committed
                    HiddenEventsDialog {
                        id: hiddenEventsDialog
                        roomid: roomSettings.roomId
                        roomName: roomSettings.roomName
                    }
    
    Malte E's avatar
    Malte E committed
                    Button {
                        text: qsTr("Configure")
                        ToolTip.text: qsTr("Select events to hide in this room")
                        onClicked: hiddenEventsDialog.show()
                        Layout.alignment: Qt.AlignRight
                    }
    
    Malte E's avatar
    Malte E committed
                    Item {
                        // for adding extra space between sections
                        Layout.fillWidth: true
                    }
    
    Malte E's avatar
    Malte E committed
                    Item {
                        // for adding extra space between sections
                        Layout.fillWidth: true
                    }
    
    Malte E's avatar
    Malte E committed
                    Label {
                        text: qsTr("INFO")
                        font.bold: true
                    }
    
    Malte E's avatar
    Malte E committed
                    Item {
                        Layout.fillWidth: true
                    }
    
    Jedi18's avatar
    Jedi18 committed
    
    
    Malte E's avatar
    Malte E committed
                    Label {
                        text: qsTr("Internal ID")
                    }
    
    Jedi18's avatar
    Jedi18 committed
    
    
    Malte E's avatar
    Malte E committed
                    Label {
                        text: roomSettings.roomId
                        font.pixelSize: Math.floor(fontMetrics.font.pixelSize * 0.8)
                        Layout.alignment: Qt.AlignRight
                    }
    
    Malte E's avatar
    Malte E committed
                    Label {
                        text: qsTr("Room Version")
                    }
    
    Jedi18's avatar
    Jedi18 committed
    
    
    Malte E's avatar
    Malte E committed
                    Label {
                        text: roomSettings.roomVersion
                        font.pixelSize: fontMetrics.font.pixelSize
                        Layout.alignment: Qt.AlignRight
                    }
    
        }
        footer: DialogButtonBox {
            standardButtons: DialogButtonBox.Ok
            onAccepted: close()
    
    Jedi18's avatar
    Jedi18 committed
        }