| 1 |
// SPDX-FileCopyrightText: Nheko Contributors |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: GPL-3.0-or-later |
| 4 |
|
| 5 |
import ".." |
| 6 |
import "../components" |
| 7 |
import QtQuick 2.12 |
| 8 |
import QtQuick.Controls 2.5 |
| 9 |
import QtQuick.Layouts 1.3 |
| 10 |
import im.nheko 1.0 |
| 11 |
|
| 12 |
|
| 13 |
ApplicationWindow { |
| 14 |
id: plEditorW |
| 15 |
|
| 16 |
property var roomSettings |
| 17 |
property var editingModel: Nheko.editPowerlevels(roomSettings.roomId) |
| 18 |
|
| 19 |
modality: Qt.NonModal |
| 20 |
flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint |
| 21 |
minimumWidth: 300 |
| 22 |
minimumHeight: 400 |
| 23 |
height: 600 |
| 24 |
width: 300 |
| 25 |
|
| 26 |
title: qsTr("Permissions in %1").arg(roomSettings.roomName); |
| 27 |
|
| 28 |
// Shortcut { |
| 29 |
// sequence: StandardKey.Cancel |
| 30 |
// onActivated: dbb.rejected() |
| 31 |
// } |
| 32 |
|
| 33 |
ColumnLayout { |
| 34 |
anchors.margins: Nheko.paddingMedium |
| 35 |
anchors.fill: parent |
| 36 |
spacing: 0 |
| 37 |
|
| 38 |
|
| 39 |
MatrixText { |
| 40 |
text: qsTr("Be careful when editing permissions. You can't lower the permissions of people with a same or higher level than you. Be careful when promoting others.") |
| 41 |
font.pixelSize: Math.floor(fontMetrics.font.pixelSize * 1.1) |
| 42 |
Layout.fillWidth: true |
| 43 |
Layout.fillHeight: false |
| 44 |
color: palette.text |
| 45 |
Layout.bottomMargin: Nheko.paddingMedium |
| 46 |
} |
| 47 |
|
| 48 |
TabBar { |
| 49 |
id: bar |
| 50 |
Layout.preferredWidth: parent.width |
| 51 |
|
| 52 |
NhekoTabButton { |
| 53 |
text: qsTr("Roles") |
| 54 |
} |
| 55 |
NhekoTabButton { |
| 56 |
text: qsTr("Users") |
| 57 |
} |
| 58 |
} |
| 59 |
Rectangle { |
| 60 |
Layout.fillWidth: true |
| 61 |
Layout.fillHeight: true |
| 62 |
color: palette.alternateBase |
| 63 |
border.width: 1 |
| 64 |
border.color: Nheko.theme.separator |
| 65 |
|
| 66 |
StackLayout { |
| 67 |
anchors.fill: parent |
| 68 |
anchors.margins: Nheko.paddingMedium |
| 69 |
currentIndex: bar.currentIndex |
| 70 |
|
| 71 |
|
| 72 |
ColumnLayout { |
| 73 |
spacing: Nheko.paddingMedium |
| 74 |
|
| 75 |
MatrixText { |
| 76 |
text: qsTr("Move permissions between roles to change them") |
| 77 |
font.pixelSize: Math.floor(fontMetrics.font.pixelSize * 1.1) |
| 78 |
Layout.fillWidth: true |
| 79 |
Layout.fillHeight: false |
| 80 |
color: palette.text |
| 81 |
} |
| 82 |
|
| 83 |
ReorderableListview { |
| 84 |
Layout.fillWidth: true |
| 85 |
Layout.fillHeight: true |
| 86 |
|
| 87 |
model: editingModel.types |
| 88 |
|
| 89 |
delegate: RowLayout { |
| 90 |
Column { |
| 91 |
Layout.fillWidth: true |
| 92 |
|
| 93 |
Text { visible: model.isType; text: model.displayName; color: palette.text} |
| 94 |
Text { |
| 95 |
visible: !model.isType; |
| 96 |
text: { |
| 97 |
if (editingModel.adminLevel == model.powerlevel) |
| 98 |
return qsTr("Administrator (%1)").arg(model.powerlevel) |
| 99 |
else if (editingModel.moderatorLevel == model.powerlevel) |
| 100 |
return qsTr("Moderator (%1)").arg(model.powerlevel) |
| 101 |
else if (editingModel.defaultUserLevel == model.powerlevel) |
| 102 |
return qsTr("User (%1)").arg(model.powerlevel) |
| 103 |
else |
| 104 |
return qsTr("Custom (%1)").arg(model.powerlevel) |
| 105 |
} |
| 106 |
color: palette.text |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
ImageButton { |
| 111 |
Layout.alignment: Qt.AlignRight |
| 112 |
Layout.rightMargin: 2 |
| 113 |
image: model.isType ? ":/icons/icons/ui/dismiss.svg" : ":/icons/icons/ui/add-square-button.svg" |
| 114 |
visible: !model.isType || model.removeable |
| 115 |
hoverEnabled: true |
| 116 |
ToolTip.visible: hovered |
| 117 |
ToolTip.text: model.isType ? qsTr("Remove event type") : qsTr("Add event type") |
| 118 |
onClicked: { |
| 119 |
if (model.isType) { |
| 120 |
editingModel.types.remove(index); |
| 121 |
} else { |
| 122 |
typeEntry.y = offset |
| 123 |
typeEntry.visible = true |
| 124 |
typeEntry.index = index; |
| 125 |
typeEntry.forceActiveFocus() |
| 126 |
} |
| 127 |
} |
| 128 |
} |
| 129 |
} |
| 130 |
MatrixTextField { |
| 131 |
id: typeEntry |
| 132 |
|
| 133 |
property int index |
| 134 |
|
| 135 |
width: parent.width |
| 136 |
z: 5 |
| 137 |
visible: false |
| 138 |
|
| 139 |
color: palette.text |
| 140 |
|
| 141 |
Keys.onPressed: { |
| 142 |
if (typeEntry.text.includes('.') && event.matches(StandardKey.InsertParagraphSeparator)) { |
| 143 |
editingModel.types.add(typeEntry.index, typeEntry.text) |
| 144 |
typeEntry.visible = false; |
| 145 |
typeEntry.clear(); |
| 146 |
event.accepted = true; |
| 147 |
} |
| 148 |
else if (event.matches(StandardKey.Cancel)) { |
| 149 |
typeEntry.visible = false; |
| 150 |
typeEntry.clear(); |
| 151 |
event.accepted = true; |
| 152 |
} |
| 153 |
} |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
Button { |
| 158 |
Layout.fillWidth: true |
| 159 |
text: qsTr("Add new role") |
| 160 |
|
| 161 |
onClicked: newPLLay.visible = true |
| 162 |
|
| 163 |
Rectangle { |
| 164 |
id: newPLLay |
| 165 |
|
| 166 |
anchors.fill: parent |
| 167 |
visible: false |
| 168 |
color: palette.alternateBase |
| 169 |
|
| 170 |
RowLayout { |
| 171 |
spacing: Nheko.paddingMedium |
| 172 |
anchors.fill: parent |
| 173 |
|
| 174 |
SpinBox { |
| 175 |
id: newPLVal |
| 176 |
|
| 177 |
Layout.fillWidth: true |
| 178 |
Layout.fillHeight: true |
| 179 |
|
| 180 |
editable: true |
| 181 |
//from: -9007199254740991 |
| 182 |
//to: 9007199254740991 |
| 183 |
|
| 184 |
// max qml values |
| 185 |
from: -2000000000 |
| 186 |
to: 2000000000 |
| 187 |
|
| 188 |
Keys.onPressed: { |
| 189 |
if (event.matches(StandardKey.InsertParagraphSeparator)) { |
| 190 |
editingModel.addRole(newPLVal.value); |
| 191 |
newPLLay.visible = false; |
| 192 |
} |
| 193 |
} |
| 194 |
} |
| 195 |
|
| 196 |
Button { |
| 197 |
text: qsTr("Add") |
| 198 |
Layout.preferredWidth: 100 |
| 199 |
onClicked: { |
| 200 |
editingModel.addRole(newPLVal.value); |
| 201 |
newPLLay.visible = false; |
| 202 |
} |
| 203 |
} |
| 204 |
} |
| 205 |
} |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
ColumnLayout { |
| 210 |
spacing: Nheko.paddingMedium |
| 211 |
|
| 212 |
MatrixText { |
| 213 |
text: qsTr("Move users up or down to change their permissions") |
| 214 |
font.pixelSize: Math.floor(fontMetrics.font.pixelSize * 1.1) |
| 215 |
Layout.fillWidth: true |
| 216 |
Layout.fillHeight: false |
| 217 |
} |
| 218 |
|
| 219 |
ReorderableListview { |
| 220 |
Layout.fillWidth: true |
| 221 |
Layout.fillHeight: true |
| 222 |
|
| 223 |
model: editingModel.users |
| 224 |
|
| 225 |
Column{ |
| 226 |
id: userEntryCompleter |
| 227 |
|
| 228 |
property int index: 0 |
| 229 |
|
| 230 |
visible: false |
| 231 |
|
| 232 |
width: parent.width |
| 233 |
spacing: 1 |
| 234 |
z: 5 |
| 235 |
MatrixTextField { |
| 236 |
id: userEntry |
| 237 |
|
| 238 |
width: parent.width |
| 239 |
//font.pixelSize: Math.ceil(quickSwitcher.textHeight * 0.6) |
| 240 |
color: palette.text |
| 241 |
onTextEdited: { |
| 242 |
userCompleter.completer.searchString = text; |
| 243 |
} |
| 244 |
Keys.onPressed: { |
| 245 |
if (event.key == Qt.Key_Up || event.key == Qt.Key_Backtab) { |
| 246 |
event.accepted = true; |
| 247 |
userCompleter.up(); |
| 248 |
} else if (event.key == Qt.Key_Down || event.key == Qt.Key_Tab) { |
| 249 |
event.accepted = true; |
| 250 |
if (event.key == Qt.Key_Tab && (event.modifiers & Qt.ShiftModifier)) |
| 251 |
userCompleter.up(); |
| 252 |
else |
| 253 |
userCompleter.down(); |
| 254 |
} else if (event.matches(StandardKey.InsertParagraphSeparator)) { |
| 255 |
if (userCompleter.currentCompletion()) { |
| 256 |
userCompleter.finishCompletion(); |
| 257 |
} else if (userEntry.text.startsWith("@") && userEntry.text.includes(":")) { |
| 258 |
userCompletionConnections.onCompletionSelected(userEntry.text); |
| 259 |
} |
| 260 |
event.accepted = true; |
| 261 |
} else if (event.matches(StandardKey.Cancel)) { |
| 262 |
typeEntry.visible = false; |
| 263 |
typeEntry.clear(); |
| 264 |
event.accepted = true; |
| 265 |
} |
| 266 |
} |
| 267 |
} |
| 268 |
|
| 269 |
|
| 270 |
Completer { |
| 271 |
id: userCompleter |
| 272 |
|
| 273 |
visible: userEntry.text.length > 0 |
| 274 |
width: parent.width |
| 275 |
roomId: plEditorW.roomSettings.roomId |
| 276 |
completerName: "user" |
| 277 |
bottomToTop: false |
| 278 |
fullWidth: true |
| 279 |
avatarHeight: Nheko.avatarSize / 2 |
| 280 |
avatarWidth: Nheko.avatarSize / 2 |
| 281 |
centerRowContent: false |
| 282 |
rowMargin: 2 |
| 283 |
rowSpacing: 2 |
| 284 |
} |
| 285 |
} |
| 286 |
|
| 287 |
Connections { |
| 288 |
function onCompletionSelected(id) { |
| 289 |
console.log("selected: " + id); |
| 290 |
editingModel.users.add(userEntryCompleter.index, id); |
| 291 |
userEntry.clear(); |
| 292 |
userEntryCompleter.visible = false; |
| 293 |
} |
| 294 |
|
| 295 |
function onCountChanged() { |
| 296 |
if (userCompleter.count > 0 && (userCompleter.currentIndex < 0 || userCompleter.currentIndex >= userCompleter.count)) |
| 297 |
userCompleter.currentIndex = 0; |
| 298 |
|
| 299 |
} |
| 300 |
|
| 301 |
target: userCompleter |
| 302 |
id: userCompletionConnections |
| 303 |
} |
| 304 |
|
| 305 |
delegate: RowLayout { |
| 306 |
//anchors { fill: parent; margins: 2 } |
| 307 |
id: row |
| 308 |
|
| 309 |
Avatar { |
| 310 |
id: avatar |
| 311 |
|
| 312 |
Layout.preferredHeight: Nheko.avatarSize / 2 |
| 313 |
Layout.preferredWidth: Nheko.avatarSize / 2 |
| 314 |
Layout.leftMargin: 2 |
| 315 |
userid: model.mxid |
| 316 |
url: { |
| 317 |
if (model.isUser) |
| 318 |
return model.avatarUrl.replace("mxc://", "image://MxcImage/") |
| 319 |
else if (editingModel.adminLevel >= model.powerlevel) |
| 320 |
return "image://colorimage/:/icons/icons/ui/ribbon_star.svg?" + palette.buttonText; |
| 321 |
else if (editingModel.moderatorLevel >= model.powerlevel) |
| 322 |
return "image://colorimage/:/icons/icons/ui/ribbon.svg?" + palette.buttonText; |
| 323 |
else |
| 324 |
return "image://colorimage/:/icons/icons/ui/person.svg?" + palette.buttonText; |
| 325 |
} |
| 326 |
displayName: model.displayName |
| 327 |
enabled: false |
| 328 |
} |
| 329 |
Column { |
| 330 |
Layout.fillWidth: true |
| 331 |
|
| 332 |
Text { visible: model.isUser; text: model.displayName; color: palette.text} |
| 333 |
Text { visible: model.isUser; text: model.mxid; color: palette.text} |
| 334 |
Text { |
| 335 |
visible: !model.isUser; |
| 336 |
text: { |
| 337 |
if (editingModel.adminLevel == model.powerlevel) |
| 338 |
return qsTr("Administrator (%1)").arg(model.powerlevel) |
| 339 |
else if (editingModel.moderatorLevel == model.powerlevel) |
| 340 |
return qsTr("Moderator (%1)").arg(model.powerlevel) |
| 341 |
else |
| 342 |
return qsTr("Custom (%1)").arg(model.powerlevel) |
| 343 |
} |
| 344 |
color: palette.text |
| 345 |
} |
| 346 |
} |
| 347 |
|
| 348 |
ImageButton { |
| 349 |
Layout.alignment: Qt.AlignRight |
| 350 |
Layout.rightMargin: 2 |
| 351 |
image: model.isUser ? ":/icons/icons/ui/dismiss.svg" : ":/icons/icons/ui/add-square-button.svg" |
| 352 |
visible: !model.isUser || model.removeable |
| 353 |
hoverEnabled: true |
| 354 |
ToolTip.visible: hovered |
| 355 |
ToolTip.text: model.isUser ? qsTr("Remove user") : qsTr("Add user") |
| 356 |
onClicked: { |
| 357 |
if (model.isUser) { |
| 358 |
editingModel.users.remove(index); |
| 359 |
} else { |
| 360 |
userEntryCompleter.y = offset |
| 361 |
userEntryCompleter.visible = true |
| 362 |
userEntryCompleter.index = index; |
| 363 |
userEntry.forceActiveFocus() |
| 364 |
} |
| 365 |
} |
| 366 |
} |
| 367 |
} |
| 368 |
} |
| 369 |
|
| 370 |
} |
| 371 |
} |
| 372 |
} |
| 373 |
} |
| 374 |
|
| 375 |
footer: DialogButtonBox { |
| 376 |
id: dbb |
| 377 |
|
| 378 |
standardButtons: DialogButtonBox.Ok | DialogButtonBox.Cancel |
| 379 |
onAccepted: { |
| 380 |
if (editingModel.isSpace) { |
| 381 |
// TODO(Nico): Replace with showing a list of spaces to apply to |
| 382 |
editingModel.updateSpacesModel(); |
| 383 |
plEditorW.close(); |
| 384 |
timelineRoot.showSpacePLApplyPrompt(roomSettings, editingModel) |
| 385 |
} else { |
| 386 |
editingModel.commit(); |
| 387 |
plEditorW.close(); |
| 388 |
} |
| 389 |
} |
| 390 |
onRejected: plEditorW.close(); |
| 391 |
} |
| 392 |
|
| 393 |
} |