nheko/resources/qml/dialogs/RoomSettings.qml

391 lines
13 KiB
QML
Raw Normal View History

2021-03-05 00:35:15 +01:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
// SPDX-FileCopyrightText: 2022 Nheko Contributors
//
2021-03-05 00:35:15 +01:00
// SPDX-License-Identifier: GPL-3.0-or-later
import ".."
import "../ui"
2021-02-23 05:24:34 +01:00
import Qt.labs.platform 1.1 as Platform
import QtQuick 2.15
2021-02-09 18:41:39 +01:00
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.2
import QtQuick.Window 2.13
2021-02-09 18:41:39 +01:00
import im.nheko 1.0
ApplicationWindow {
id: roomSettingsDialog
2021-02-09 18:41:39 +01:00
property var roomSettings
minimumWidth: 340
2022-03-02 10:02:01 +01:00
minimumHeight: 450
2022-02-25 22:05:35 +01:00
width: 450
height: 680
2021-05-13 08:23:56 +02:00
palette: Nheko.colors
color: Nheko.colors.window
modality: Qt.NonModal
2021-08-19 16:55:54 +02:00
flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint
2021-04-17 20:40:31 +02:00
title: qsTr("Room Settings")
2021-02-09 18:41:39 +01:00
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
2022-03-02 10:02:01 +01:00
contentWidth: roomSettingsDialog.width
contentHeight: contentLayout1.height
2022-02-25 21:59:01 +01:00
ColumnLayout {
id: contentLayout1
2022-03-02 10:02:01 +01:00
width: parent.width
2022-02-25 21:59:01 +01:00
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();
2022-02-25 21:59:01 +01:00
}
2021-02-11 19:09:11 +01:00
}
2022-02-25 21:59:01 +01:00
Spinner {
Layout.alignment: Qt.AlignHCenter
visible: roomSettings.isLoading
foreground: Nheko.colors.mid
running: roomSettings.isLoading
}
2022-02-25 21:59:01 +01:00
Text {
id: errorText
2021-02-11 19:09:11 +01:00
2022-02-25 21:59:01 +01:00
color: "red"
visible: opacity > 0
opacity: 0
Layout.alignment: Qt.AlignHCenter
wrapMode: Text.Wrap // somehow still doesn't wrap
2022-03-02 10:02:01 +01:00
Layout.fillWidth: true
2022-02-25 21:59:01 +01:00
}
2022-02-25 21:59:01 +01:00
SequentialAnimation {
id: hideErrorAnimation
2022-02-25 21:59:01 +01:00
running: false
2022-02-25 21:59:01 +01:00
PauseAnimation {
duration: 4000
}
2022-02-25 21:59:01 +01:00
NumberAnimation {
target: errorText
property: 'opacity'
to: 0
duration: 1000
}
2021-02-11 19:09:11 +01:00
}
2022-02-25 21:59:01 +01:00
Connections {
target: roomSettings
function onDisplayError(errorMessage) {
errorText.text = errorMessage;
errorText.opacity = 1;
hideErrorAnimation.restart();
}
2021-02-09 18:41:39 +01:00
}
2022-02-25 21:59:01 +01:00
Label {
text: roomSettings.roomName
Layout.alignment: Qt.AlignHCenter
font.pixelSize: fontMetrics.font.pixelSize * 2
Layout.fillWidth: true
horizontalAlignment: TextEdit.AlignHCenter
color: Nheko.colors.text
2022-03-04 23:08:00 +01:00
wrapMode: Text.Wrap
2022-03-04 23:11:47 +01:00
textFormat: Text.RichText
2022-02-25 21:59:01 +01:00
}
2021-02-09 18:41:39 +01:00
2022-02-25 21:59:01 +01:00
Label {
text: qsTr("%n member(s)", "", roomSettings.memberCount)
Layout.alignment: Qt.AlignHCenter
color: Nheko.colors.text
2022-02-25 21:59:01 +01:00
TapHandler {
onSingleTapped: TimelineManager.openRoomMembers(Rooms.getRoomById(roomSettings.roomId))
}
CursorShape {
cursorShape: Qt.PointingHandCursor
anchors.fill: parent
}
}
2022-02-25 21:59:01 +01:00
ImageButton {
Layout.alignment: Qt.AlignHCenter
image: ":/icons/icons/ui/edit.svg"
visible: roomSettings.canChangeNameAndTopic
onClicked: roomSettings.openEditModal()
2021-02-09 18:41:39 +01:00
}
2022-02-25 21:59:01 +01:00
TextArea {
2022-03-02 10:02:01 +01:00
id: roomTopic
property bool cut: implicitHeight > 100
property bool showMore
clip: true
2022-03-04 11:19:58 +01:00
Layout.maximumHeight: showMore? Number.POSITIVE_INFINITY : 100
Layout.preferredHeight: implicitHeight
2022-02-25 21:59:01 +01:00
Layout.alignment: Qt.AlignHCenter
Layout.fillWidth: true
Layout.leftMargin: Nheko.paddingLarge
Layout.rightMargin: Nheko.paddingLarge
2021-02-13 14:38:52 +01:00
text: TimelineManager.escapeEmoji(roomSettings.roomTopic)
2021-02-23 05:24:34 +01:00
wrapMode: TextEdit.WordWrap
textFormat: TextEdit.RichText
2021-02-13 16:16:40 +01:00
readOnly: true
background: null
2022-03-02 10:02:01 +01:00
selectByMouse: !Settings.mobileMode
2021-05-13 08:23:56 +02:00
color: Nheko.colors.text
2021-02-23 05:24:34 +01:00
horizontalAlignment: TextEdit.AlignHCenter
2021-05-13 08:52:02 +02:00
onLinkActivated: Nheko.openLink(link)
2021-02-23 05:24:34 +01:00
CursorShape {
anchors.fill: parent
cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor
}
2022-02-25 21:59:01 +01:00
}
2022-03-02 10:02:01 +01:00
Item {
Layout.alignment: Qt.AlignHCenter
id: showMorePlaceholder
Layout.preferredHeight: showMoreButton.height
Layout.preferredWidth: showMoreButton.width
visible: roomTopic.cut
}
2021-02-09 18:41:39 +01:00
2022-02-25 21:59:01 +01:00
GridLayout {
columns: 2
rowSpacing: Nheko.paddingMedium
Layout.margins: Nheko.paddingMedium
2022-03-02 10:02:01 +01:00
Layout.fillWidth: true
2021-02-09 18:41:39 +01:00
2022-02-25 21:59:01 +01:00
Label {
text: qsTr("SETTINGS")
font.bold: true
color: Nheko.colors.text
2022-02-25 21:59:01 +01:00
}
2021-02-09 18:41:39 +01:00
2022-02-25 21:59:01 +01:00
Item {
Layout.fillWidth: true
}
2021-02-09 18:41:39 +01:00
2022-02-25 21:59:01 +01:00
Label {
text: qsTr("Notifications")
Layout.fillWidth: true
color: Nheko.colors.text
2022-02-25 21:59:01 +01:00
}
2022-02-25 21:59:01 +01:00
ComboBox {
model: [qsTr("Muted"), qsTr("Mentions only"), qsTr("All messages")]
currentIndex: roomSettings.notifications
onActivated: {
roomSettings.changeNotifications(index);
}
Layout.fillWidth: true
2022-03-02 10:02:01 +01:00
WheelHandler{} // suppress scrolling changing values
}
2021-02-09 18:41:39 +01:00
2022-02-25 21:59:01 +01:00
Label {
text: qsTr("Room access")
Layout.fillWidth: true
color: Nheko.colors.text
2022-02-25 21:59:01 +01:00
}
2021-02-09 18:41:39 +01:00
2022-02-25 21:59:01 +01:00
ComboBox {
enabled: roomSettings.canChangeJoinRules
model: {
let opts = [qsTr("Anyone and guests"), qsTr("Anyone"), qsTr("Invited users")];
if (roomSettings.supportsKnocking)
opts.push(qsTr("By knocking"));
2022-02-25 21:59:01 +01:00
if (roomSettings.supportsRestricted)
opts.push(qsTr("Restricted by membership in other rooms"));
2022-02-25 21:59:01 +01:00
return opts;
}
currentIndex: roomSettings.accessJoinRules
onActivated: {
roomSettings.changeAccessRules(index);
}
Layout.fillWidth: true
2022-03-02 10:02:01 +01:00
WheelHandler{} // suppress scrolling changing values
}
2021-02-09 18:41:39 +01:00
2022-02-25 21:59:01 +01:00
Label {
text: qsTr("Encryption")
color: Nheko.colors.text
2022-02-25 21:59:01 +01:00
}
2021-02-09 18:41:39 +01:00
2022-02-25 21:59:01 +01:00
ToggleButton {
id: encryptionToggle
2022-02-25 21:59:01 +01:00
checked: roomSettings.isEncryptionEnabled
onCheckedChanged: {
if (roomSettings.isEncryptionEnabled) {
checked = true;
return ;
}
confirmEncryptionDialog.open();
}
2022-02-25 21:59:01 +01:00
Layout.alignment: Qt.AlignRight
}
2022-02-25 21:59:01 +01:00
Platform.MessageDialog {
id: confirmEncryptionDialog
2022-02-25 21:59:01 +01:00
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 ;
2022-02-25 21:59:01 +01:00
roomSettings.enableEncryption();
}
onRejected: {
encryptionToggle.checked = false;
}
buttons: Platform.MessageDialog.Ok | Platform.MessageDialog.Cancel
}
2022-02-25 21:59:01 +01:00
Label {
text: qsTr("Sticker & Emote Settings")
color: Nheko.colors.text
}
2022-02-25 21:59:01 +01:00
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
}
2022-02-25 21:59:01 +01:00
Label {
text: qsTr("Hidden events")
color: Nheko.colors.text
2022-02-25 21:59:01 +01:00
}
2022-02-25 21:59:01 +01:00
HiddenEventsDialog {
id: hiddenEventsDialog
roomid: roomSettings.roomId
roomName: roomSettings.roomName
}
2022-02-25 21:59:01 +01:00
Button {
text: qsTr("Configure")
ToolTip.text: qsTr("Select events to hide in this room")
onClicked: hiddenEventsDialog.show()
Layout.alignment: Qt.AlignRight
}
2022-02-25 21:59:01 +01:00
Item {
// for adding extra space between sections
Layout.fillWidth: true
}
2022-02-25 21:59:01 +01:00
Item {
// for adding extra space between sections
Layout.fillWidth: true
}
2022-02-25 21:59:01 +01:00
Label {
text: qsTr("INFO")
font.bold: true
color: Nheko.colors.text
2022-02-25 21:59:01 +01:00
}
2022-02-25 21:59:01 +01:00
Item {
Layout.fillWidth: true
}
2021-02-09 18:41:39 +01:00
2022-02-25 21:59:01 +01:00
Label {
text: qsTr("Internal ID")
color: Nheko.colors.text
2022-02-25 21:59:01 +01:00
}
2021-02-09 18:41:39 +01:00
AbstractButton { // AbstractButton does not allow setting text color
2022-02-25 21:59:01 +01:00
Layout.alignment: Qt.AlignRight
2022-03-02 10:02:01 +01:00
Layout.fillWidth: true
Layout.preferredHeight: idLabel.height
Label { // TextEdit does not trigger onClicked
id: idLabel
text: roomSettings.roomId
font.pixelSize: Math.floor(fontMetrics.font.pixelSize * 0.8)
color: Nheko.colors.text
width: parent.width
2022-03-04 13:40:44 +01:00
horizontalAlignment: Text.AlignRight
wrapMode: Text.WrapAnywhere
ToolTip.text: qsTr("Copied to clipboard")
ToolTip.visible: toolTipTimer.running
}
TextEdit{ // label does not allow selection
id: textEdit
visible: false
text: roomSettings.roomId
}
onClicked: {
textEdit.selectAll()
textEdit.copy()
toolTipTimer.start()
}
Timer {
id: toolTipTimer
}
2022-02-25 21:59:01 +01:00
}
2022-02-25 21:59:01 +01:00
Label {
text: qsTr("Room Version")
color: Nheko.colors.text
2022-02-25 21:59:01 +01:00
}
2021-02-09 18:41:39 +01:00
2022-02-25 21:59:01 +01:00
Label {
text: roomSettings.roomVersion
font.pixelSize: fontMetrics.font.pixelSize
Layout.alignment: Qt.AlignRight
color: Nheko.colors.text
2022-02-25 21:59:01 +01:00
}
2021-02-09 18:41:39 +01:00
}
}
}
2022-03-02 10:02:01 +01:00
Button {
id: showMoreButton
2022-03-04 11:19:58 +01:00
anchors.horizontalCenter: flickable.horizontalCenter
y: Math.min(showMorePlaceholder.y+contentLayout1.y-flickable.contentY,flickable.height-height)
2022-03-02 10:02:01 +01:00
visible: roomTopic.cut
text: roomTopic.showMore? qsTr("show less") : qsTr("show more")
2022-03-02 10:02:01 +01:00
onClicked: {roomTopic.showMore = !roomTopic.showMore
console.log(flickable.visibleArea)
}
}
footer: DialogButtonBox {
standardButtons: DialogButtonBox.Ok
onAccepted: close()
2021-02-09 18:41:39 +01:00
}
}