| 1 |
// SPDX-FileCopyrightText: Nheko Contributors |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: GPL-3.0-or-later |
| 4 |
|
| 5 |
import ".." |
| 6 |
import QtQuick 2.15 |
| 7 |
import QtQuick.Window 2.13 |
| 8 |
import QtQuick.Layouts 1.3 |
| 9 |
import QtQuick.Controls 2.3 |
| 10 |
import im.nheko 1.0 |
| 11 |
|
| 12 |
ApplicationWindow { |
| 13 |
id: createRoomRoot |
| 14 |
|
| 15 |
property bool space: false |
| 16 |
|
| 17 |
title: space ? qsTr("New community") : qsTr("New Room") |
| 18 |
minimumWidth: Math.max(rootLayout.implicitWidth+2*rootLayout.anchors.margins, footer.implicitWidth + Nheko.paddingLarge) |
| 19 |
minimumHeight: rootLayout.implicitHeight+footer.implicitHeight+2*rootLayout.anchors.margins |
| 20 |
modality: Qt.NonModal |
| 21 |
flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint |
| 22 |
|
| 23 |
onVisibilityChanged: { |
| 24 |
newRoomName.forceActiveFocus(); |
| 25 |
} |
| 26 |
|
| 27 |
Shortcut { |
| 28 |
sequence: StandardKey.Cancel |
| 29 |
onActivated: createRoomRoot.close() |
| 30 |
} |
| 31 |
GridLayout { |
| 32 |
id: rootLayout |
| 33 |
anchors.fill: parent |
| 34 |
anchors.margins: Nheko.paddingLarge |
| 35 |
columns: 2 |
| 36 |
rowSpacing: Nheko.paddingMedium |
| 37 |
|
| 38 |
MatrixTextField { |
| 39 |
id: newRoomName |
| 40 |
Layout.columnSpan: 2 |
| 41 |
Layout.fillWidth: true |
| 42 |
|
| 43 |
focus: true |
| 44 |
label: qsTr("Name") |
| 45 |
placeholderText: qsTr("No name") |
| 46 |
} |
| 47 |
MatrixTextField { |
| 48 |
id: newRoomTopic |
| 49 |
Layout.columnSpan: 2 |
| 50 |
Layout.fillWidth: true |
| 51 |
|
| 52 |
focus: true |
| 53 |
label: qsTr("Topic") |
| 54 |
placeholderText: qsTr("No topic") |
| 55 |
} |
| 56 |
|
| 57 |
Item { |
| 58 |
Layout.preferredHeight: newRoomName.height / 2 |
| 59 |
} |
| 60 |
|
| 61 |
RowLayout { |
| 62 |
Layout.columnSpan: 2 |
| 63 |
Layout.fillWidth: true |
| 64 |
Label { |
| 65 |
Layout.preferredWidth: implicitWidth |
| 66 |
text: "#" |
| 67 |
color: palette.text |
| 68 |
} |
| 69 |
MatrixTextField { |
| 70 |
id: newRoomAlias |
| 71 |
focus: true |
| 72 |
placeholderText: qsTr("Alias") |
| 73 |
} |
| 74 |
Label { |
| 75 |
Layout.preferredWidth: implicitWidth |
| 76 |
property string userName: userInfoGrid.profile.userid |
| 77 |
text: userName.substring(userName.indexOf(":")) |
| 78 |
color: palette.text |
| 79 |
} |
| 80 |
} |
| 81 |
Label { |
| 82 |
Layout.preferredWidth: implicitWidth |
| 83 |
Layout.alignment: Qt.AlignLeft |
| 84 |
text: qsTr("Public") |
| 85 |
color: palette.text |
| 86 |
HoverHandler { |
| 87 |
id: privateHover |
| 88 |
} |
| 89 |
ToolTip.visible: privateHover.hovered |
| 90 |
ToolTip.text: qsTr("Public rooms can be joined by anyone; private rooms need explicit invites.") |
| 91 |
ToolTip.delay: Nheko.tooltipDelay |
| 92 |
} |
| 93 |
ToggleButton { |
| 94 |
Layout.alignment: Qt.AlignRight |
| 95 |
Layout.preferredWidth: implicitWidth |
| 96 |
id: isPublic |
| 97 |
checked: false |
| 98 |
} |
| 99 |
Label { |
| 100 |
visible: !space |
| 101 |
Layout.preferredWidth: implicitWidth |
| 102 |
Layout.alignment: Qt.AlignLeft |
| 103 |
text: qsTr("Trusted") |
| 104 |
color: palette.text |
| 105 |
HoverHandler { |
| 106 |
id: trustedHover |
| 107 |
} |
| 108 |
ToolTip.visible: trustedHover.hovered |
| 109 |
ToolTip.text: qsTr("All invitees are given the same power level as the creator") |
| 110 |
ToolTip.delay: Nheko.tooltipDelay |
| 111 |
} |
| 112 |
ToggleButton { |
| 113 |
visible: !space |
| 114 |
Layout.alignment: Qt.AlignRight |
| 115 |
Layout.preferredWidth: implicitWidth |
| 116 |
id: isTrusted |
| 117 |
checked: false |
| 118 |
enabled: !isPublic.checked |
| 119 |
} |
| 120 |
Label { |
| 121 |
visible: !space |
| 122 |
Layout.preferredWidth: implicitWidth |
| 123 |
Layout.alignment: Qt.AlignLeft |
| 124 |
text: qsTr("Encryption") |
| 125 |
color: palette.text |
| 126 |
HoverHandler { |
| 127 |
id: encryptionHover |
| 128 |
} |
| 129 |
ToolTip.visible: encryptionHover.hovered |
| 130 |
ToolTip.text: qsTr("Caution: Encryption cannot be disabled") |
| 131 |
ToolTip.delay: Nheko.tooltipDelay |
| 132 |
} |
| 133 |
ToggleButton { |
| 134 |
visible: !space |
| 135 |
Layout.alignment: Qt.AlignRight |
| 136 |
Layout.preferredWidth: implicitWidth |
| 137 |
id: isEncrypted |
| 138 |
checked: false |
| 139 |
} |
| 140 |
|
| 141 |
Item {Layout.fillHeight: true} |
| 142 |
} |
| 143 |
footer: DialogButtonBox { |
| 144 |
standardButtons: DialogButtonBox.Cancel |
| 145 |
Button { |
| 146 |
text: qsTr("Create Room") |
| 147 |
DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole |
| 148 |
} |
| 149 |
onRejected: createRoomRoot.close(); |
| 150 |
onAccepted: { |
| 151 |
var preset = 0; |
| 152 |
|
| 153 |
if (isPublic.checked) { |
| 154 |
preset = 1; |
| 155 |
} |
| 156 |
else { |
| 157 |
preset = isTrusted.checked ? 2 : 0; |
| 158 |
} |
| 159 |
Nheko.createRoom(space, newRoomName.text, newRoomTopic.text, newRoomAlias.text, isEncrypted.checked, preset) |
| 160 |
createRoomRoot.close(); |
| 161 |
} |
| 162 |
} |
| 163 |
} |