Debian Codegraph @

resources/qml/dialogs/UserProfile.qml

raw
1 // SPDX-FileCopyrightText: Nheko Contributors
2 //
3 // SPDX-License-Identifier: GPL-3.0-or-later
4
5 import ".."
6 import "../ui"
7 import "../components"
8 import QtQuick 2.15
9 import QtQuick.Controls 2.15
10 import QtQuick.Layouts 1.2
11 import QtQuick.Window 2.13
12 import QtQml.Models 2.2
13 import im.nheko 1.0
14
15 ApplicationWindow {
16 id: userProfileDialog
17
18 property var profile
19
20 height: 650
21 width: 420
22 minimumWidth: 150
23 minimumHeight: 150
24 color: palette.window
25 title: profile.isGlobalUserProfile ? qsTr("Global User Profile") : qsTr("Room User Profile")
26 modality: Qt.NonModal
27 flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint
28
29 Shortcut {
30 sequence: StandardKey.Cancel
31 onActivated: userProfileDialog.close()
32 }
33
34 ListView {
35 id: devicelist
36
37 property int selectedTab: 0
38
39 Layout.fillHeight: true
40 Layout.fillWidth: true
41 clip: true
42 spacing: 8
43 boundsBehavior: Flickable.StopAtBounds
44 anchors.fill: parent
45 anchors.margins: 10
46 footerPositioning: ListView.OverlayFooter
47
48 header: ColumnLayout {
49 id: contentL
50
51 width: devicelist.width
52 spacing: Nheko.paddingMedium
53
54 Avatar {
55 id: displayAvatar
56
57 url: profile.avatarUrl.replace("mxc://", "image://MxcImage/")
58 Layout.preferredHeight: 130
59 Layout.preferredWidth: 130
60 displayName: profile.displayName
61 userid: profile.userid
62 Layout.alignment: Qt.AlignHCenter
63 onClicked: TimelineManager.openImageOverlay(null, profile.avatarUrl, "", 0, 0)
64
65 ImageButton {
66 hoverEnabled: true
67 ToolTip.visible: hovered
68 ToolTip.text: profile.isGlobalUserProfile ? qsTr("Change avatar globally.") : qsTr("Change avatar. Will only apply to this room.")
69 anchors.left: displayAvatar.left
70 anchors.top: displayAvatar.top
71 anchors.leftMargin: Nheko.paddingMedium
72 anchors.topMargin: Nheko.paddingMedium
73 visible: profile.isSelf
74 image: ":/icons/icons/ui/edit.svg"
75 onClicked: profile.changeAvatar()
76 }
77
78 }
79
80 Spinner {
81 Layout.alignment: Qt.AlignHCenter
82 running: profile.isLoading
83 visible: profile.isLoading
84 foreground: palette.mid
85 }
86
87 Text {
88 id: errorText
89
90 color: "red"
91 visible: opacity > 0
92 opacity: 0
93 Layout.alignment: Qt.AlignHCenter
94 }
95
96 SequentialAnimation {
97 id: hideErrorAnimation
98
99 running: false
100
101 PauseAnimation {
102 duration: 4000
103 }
104
105 NumberAnimation {
106 target: errorText
107 property: 'opacity'
108 to: 0
109 duration: 1000
110 }
111
112 }
113
114 Connections {
115 function onDisplayError(errorMessage) {
116 errorText.text = errorMessage;
117 errorText.opacity = 1;
118 hideErrorAnimation.restart();
119 }
120
121 target: profile
122 }
123
124 TextInput {
125 id: displayUsername
126
127 property bool isUsernameEditingAllowed
128
129 readOnly: !isUsernameEditingAllowed
130 text: profile.displayName
131 font.pixelSize: 20
132 color: TimelineManager.userColor(profile.userid, palette.window)
133 font.bold: true
134 Layout.alignment: Qt.AlignHCenter
135 Layout.maximumWidth: parent.width - (Nheko.paddingSmall * 2) - usernameChangeButton.anchors.leftMargin - (usernameChangeButton.width * 2)
136 horizontalAlignment: TextInput.AlignHCenter
137 wrapMode: TextInput.Wrap
138 selectByMouse: true
139 onAccepted: {
140 profile.changeUsername(displayUsername.text);
141 displayUsername.isUsernameEditingAllowed = false;
142 }
143
144 ImageButton {
145 id: usernameChangeButton
146 visible: profile.isSelf
147 anchors.leftMargin: Nheko.paddingSmall
148 anchors.left: displayUsername.right
149 anchors.verticalCenter: displayUsername.verticalCenter
150 hoverEnabled: true
151 ToolTip.visible: hovered
152 ToolTip.text: profile.isGlobalUserProfile ? qsTr("Change display name globally.") : qsTr("Change display name. Will only apply to this room.")
153 image: displayUsername.isUsernameEditingAllowed ? ":/icons/icons/ui/checkmark.svg" : ":/icons/icons/ui/edit.svg"
154 onClicked: {
155 if (displayUsername.isUsernameEditingAllowed) {
156 profile.changeUsername(displayUsername.text);
157 displayUsername.isUsernameEditingAllowed = false;
158 } else {
159 displayUsername.isUsernameEditingAllowed = true;
160 displayUsername.focus = true;
161 displayUsername.selectAll();
162 }
163 }
164 }
165
166 }
167
168 MatrixText {
169 text: profile.userid
170 Layout.alignment: Qt.AlignHCenter
171 }
172
173 MatrixText {
174 id: statusMsg
175 text: qsTr("<i><b>Status:</b> %1</i>").arg(userStatus)
176 visible: userStatus != ""
177 Layout.fillWidth: true
178 horizontalAlignment: TextEdit.AlignHCenter
179 Layout.leftMargin: Nheko.paddingMedium
180 Layout.rightMargin: Nheko.paddingMedium
181 font.pointSize: Math.floor(fontMetrics.font.pointSize * 0.9)
182
183 property string userStatus: Presence.userStatus(profile.userid)
184 Connections {
185 target: Presence
186 function onPresenceChanged(id) {
187 if (id == profile.userid) statusMsg.userStatus = Presence.userStatus(profile.userid);
188 }
189 }
190 }
191
192 RowLayout {
193 visible: !profile.isGlobalUserProfile
194 Layout.alignment: Qt.AlignHCenter
195 spacing: Nheko.paddingSmall
196
197 MatrixText {
198 id: displayRoomname
199
200 text: qsTr("Room: %1").arg(profile.room ? profile.room.roomName : "")
201 ToolTip.text: qsTr("This is a room-specific profile. The user's name and avatar may be different from their global versions.")
202 ToolTip.visible: ma.hovered
203 Layout.maximumWidth: parent.parent.width - (parent.spacing * 3) - 16
204 horizontalAlignment: TextEdit.AlignHCenter
205
206 HoverHandler {
207 id: ma
208 }
209
210 }
211
212 ImageButton {
213 image: ":/icons/icons/ui/world.svg"
214 hoverEnabled: true
215 ToolTip.visible: hovered
216 ToolTip.text: qsTr("Open the global profile for this user.")
217 onClicked: profile.openGlobalProfile()
218 }
219
220 }
221
222 Button {
223 id: verifyUserButton
224
225 text: qsTr("Verify")
226 Layout.alignment: Qt.AlignHCenter
227 enabled: profile.userVerified != Crypto.Verified
228 visible: profile.userVerified != Crypto.Verified && !profile.isSelf && profile.userVerificationEnabled
229 onClicked: profile.verify()
230 }
231
232 EncryptionIndicator {
233 Layout.preferredHeight: 32
234 Layout.preferredWidth: 32
235 sourceSize.width: width
236 sourceSize.height: height
237 encrypted: profile.userVerificationEnabled
238 trust: profile.userVerified
239 Layout.alignment: Qt.AlignHCenter
240 ToolTip.visible: false
241 }
242
243 RowLayout {
244 // ImageButton{
245 // image:":/icons/icons/ui/volume-off-indicator.svg"
246 // Layout.margins: {
247 // left: 5
248 // right: 5
249 // }
250 // ToolTip.visible: hovered
251 // ToolTip.text: qsTr("Ignore messages from this user.")
252 // onClicked : {
253 // profile.ignoreUser()
254 // }
255 // }
256
257 Layout.alignment: Qt.AlignHCenter
258 Layout.bottomMargin: 10
259 spacing: Nheko.paddingSmall
260
261 ImageButton {
262 Layout.preferredHeight: 24
263 Layout.preferredWidth: 24
264 image: ":/icons/icons/ui/chat.svg"
265 hoverEnabled: true
266 ToolTip.visible: hovered
267 ToolTip.text: qsTr("Start a private chat.")
268 onClicked: profile.startChat()
269 }
270
271 ImageButton {
272 Layout.preferredHeight: 24
273 Layout.preferredWidth: 24
274 image: ":/icons/icons/ui/round-remove-button.svg"
275 hoverEnabled: true
276 ToolTip.visible: hovered
277 ToolTip.text: qsTr("Kick the user.")
278 onClicked: profile.kickUser()
279 visible: !profile.isGlobalUserProfile && profile.room.permissions.canKick()
280 }
281
282 ImageButton {
283 Layout.preferredHeight: 24
284 Layout.preferredWidth: 24
285 image: ":/icons/icons/ui/ban.svg"
286 hoverEnabled: true
287 ToolTip.visible: hovered
288 ToolTip.text: qsTr("Ban the user.")
289 onClicked: profile.banUser()
290 visible: !profile.isGlobalUserProfile && profile.room.permissions.canBan()
291 }
292
293 ImageButton {
294 Layout.preferredHeight: 24
295 Layout.preferredWidth: 24
296 image: ":/icons/icons/ui/volume-off-indicator.svg"
297 hoverEnabled: true
298 ToolTip.visible: hovered
299 ToolTip.text: profile.ignored ? qsTr("Unignore the user.") : qsTr("Ignore the user.")
300 buttonTextColor: profile.ignored ? Nheko.theme.red : palette.buttonText
301 onClicked: profile.ignored = !profile.ignored
302 visible: !profile.isSelf
303 }
304
305 ImageButton {
306 Layout.preferredHeight: 24
307 Layout.preferredWidth: 24
308 image: ":/icons/icons/ui/refresh.svg"
309 hoverEnabled: true
310 ToolTip.visible: hovered
311 ToolTip.text: qsTr("Refresh device list.")
312 onClicked: profile.refreshDevices()
313 }
314 }
315
316 TabBar {
317 id: tabbar
318 visible: !profile.isSelf
319 Layout.fillWidth: true
320
321 onCurrentIndexChanged: devicelist.selectedTab = currentIndex
322
323
324 NhekoTabButton {
325 text: qsTr("Devices")
326 }
327 NhekoTabButton {
328 text: qsTr("Shared Rooms")
329 }
330
331 Layout.bottomMargin: Nheko.paddingMedium
332 }
333 }
334
335 model: (selectedTab == 0) ? devicesModel : sharedRoomsModel
336
337 DelegateModel {
338 id: devicesModel
339 model: profile.deviceList
340 delegate: RowLayout {
341 required property int verificationStatus
342 required property string deviceId
343 required property string deviceName
344 required property string lastIp
345 required property var lastTs
346
347 width: devicelist.width
348 spacing: 4
349
350 ColumnLayout {
351 spacing: 0
352
353 Layout.leftMargin: Nheko.paddingMedium
354 Layout.rightMargin: Nheko.paddingMedium
355 RowLayout {
356 Text {
357 Layout.fillWidth: true
358 Layout.alignment: Qt.AlignLeft
359 elide: Text.ElideRight
360 font.bold: true
361 color: palette.text
362 text: deviceId
363 }
364
365 Image {
366 Layout.preferredHeight: 16
367 Layout.preferredWidth: 16
368 visible: profile.isSelf && verificationStatus != VerificationStatus.NOT_APPLICABLE
369 sourceSize.height: height
370 sourceSize.width: width
371 source: {
372 switch (verificationStatus) {
373 case VerificationStatus.VERIFIED:
374 return "image://colorimage/:/icons/icons/ui/shield-filled-checkmark.svg?" + Nheko.theme.green;
375 case VerificationStatus.UNVERIFIED:
376 return "image://colorimage/:/icons/icons/ui/shield-filled-exclamation-mark.svg?" + Nheko.theme.orange;
377 case VerificationStatus.SELF:
378 return "image://colorimage/:/icons/icons/ui/checkmark.svg?" + Nheko.theme.green;
379 default:
380 return "image://colorimage/:/icons/icons/ui/shield-filled-cross.svg?" + Nheko.theme.orange;
381 }
382 }
383 }
384
385 ImageButton {
386 Layout.alignment: Qt.AlignTop
387 image: ":/icons/icons/ui/power-off.svg"
388 hoverEnabled: true
389 ToolTip.visible: hovered
390 ToolTip.text: qsTr("Sign out this device.")
391 onClicked: profile.signOutDevice(deviceId)
392 visible: profile.isSelf
393 }
394
395 }
396
397 RowLayout {
398 id: deviceNameRow
399
400 property bool isEditingAllowed
401
402 TextInput {
403 id: deviceNameField
404
405 readOnly: !deviceNameRow.isEditingAllowed
406 text: deviceName
407 color: palette.text
408 Layout.alignment: Qt.AlignLeft
409 Layout.fillWidth: true
410 selectByMouse: true
411 onAccepted: {
412 profile.changeDeviceName(deviceId, deviceNameField.text);
413 deviceNameRow.isEditingAllowed = false;
414 }
415 }
416
417 ImageButton {
418 visible: profile.isSelf
419 hoverEnabled: true
420 ToolTip.visible: hovered
421 ToolTip.text: qsTr("Change device name.")
422 image: deviceNameRow.isEditingAllowed ? ":/icons/icons/ui/checkmark.svg" : ":/icons/icons/ui/edit.svg"
423 onClicked: {
424 if (deviceNameRow.isEditingAllowed) {
425 profile.changeDeviceName(deviceId, deviceNameField.text);
426 deviceNameRow.isEditingAllowed = false;
427 } else {
428 deviceNameRow.isEditingAllowed = true;
429 deviceNameField.focus = true;
430 deviceNameField.selectAll();
431 }
432 }
433 }
434
435 }
436
437 Text {
438 visible: profile.isSelf
439 Layout.fillWidth: true
440 Layout.alignment: Qt.AlignLeft
441 elide: Text.ElideRight
442 color: palette.text
443 text: qsTr("Last seen %1 from %2").arg(new Date(lastTs).toLocaleString(Locale.ShortFormat)).arg(lastIp ? lastIp : "???")
444 }
445
446 }
447
448 Image {
449 Layout.preferredHeight: 16
450 Layout.preferredWidth: 16
451 sourceSize.height: height
452 sourceSize.width: width
453 visible: !profile.isSelf && verificationStatus != VerificationStatus.NOT_APPLICABLE
454 source: {
455 switch (verificationStatus) {
456 case VerificationStatus.VERIFIED:
457 return "image://colorimage/:/icons/icons/ui/shield-filled-checkmark.svg?" + Nheko.theme.green;
458 case VerificationStatus.UNVERIFIED:
459 return "image://colorimage/:/icons/icons/ui/shield-filled-exclamation-mark.svg?" + Nheko.theme.orange;
460 case VerificationStatus.SELF:
461 return "image://colorimage/:/icons/icons/ui/checkmark.svg?" + Nheko.theme.green;
462 default:
463 return "image://colorimage/:/icons/icons/ui/shield-filled.svg?" + Nheko.theme.red;
464 }
465 }
466 }
467
468 Button {
469 id: verifyButton
470
471 visible: verificationStatus == VerificationStatus.UNVERIFIED && (profile.isSelf || !profile.userVerificationEnabled)
472 text: (verificationStatus != VerificationStatus.VERIFIED) ? qsTr("Verify") : qsTr("Unverify")
473 onClicked: {
474 if (verificationStatus == VerificationStatus.VERIFIED)
475 profile.unverify(deviceId);
476 else
477 profile.verify(deviceId);
478 }
479 }
480
481 }
482 }
483
484 DelegateModel {
485 id: sharedRoomsModel
486 model: profile.sharedRooms
487 delegate: RowLayout {
488 required property string roomId
489 required property string roomName
490 required property string avatarUrl
491
492 width: devicelist.width
493 spacing: 4
494
495
496 Avatar {
497 id: avatar
498
499 enabled: false
500 Layout.alignment: Qt.AlignVCenter
501 Layout.leftMargin: Nheko.paddingMedium
502
503 property int avatarSize: Math.ceil(fontMetrics.lineSpacing * 1.6)
504 Layout.preferredHeight: avatarSize
505 Layout.preferredWidth: avatarSize
506 url: avatarUrl.replace("mxc://", "image://MxcImage/")
507 roomid: roomId
508 displayName: roomName
509 }
510
511 ElidedLabel {
512 Layout.alignment: Qt.AlignVCenter
513 color: palette.text
514 Layout.fillWidth: true
515 elideWidth: width
516 fullText: roomName
517 textFormat: Text.PlainText
518 Layout.rightMargin: Nheko.paddingMedium
519 }
520
521 Item {
522 Layout.fillWidth: true
523 }
524 }
525 }
526
527 footer: DialogButtonBox {
528 z: 2
529 width: devicelist.width
530 alignment: Qt.AlignRight
531 standardButtons: DialogButtonBox.Ok
532 onAccepted: userProfileDialog.close()
533
534 background: Rectangle {
535 anchors.fill: parent
536 color: palette.window
537 }
538
539 }
540
541 }
542
543 }