matrixion/resources/qml/dialogs/UserProfile.qml

522 lines
20 KiB
QML
Raw Normal View History

// SPDX-FileCopyrightText: Nheko Contributors
//
2021-03-05 02:35:15 +03:00
// SPDX-License-Identifier: GPL-3.0-or-later
import ".."
import "../ui"
2023-02-24 04:40:14 +03:00
import "../components"
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.2
import QtQuick.Window 2.13
2023-02-24 04:40:14 +03:00
import QtQml.Models 2.2
2020-05-22 08:47:02 +03:00
import im.nheko 1.0
2020-10-08 22:11:21 +03:00
ApplicationWindow {
id: userProfileDialog
property var profile
2023-10-31 05:11:03 +03:00
color: palette.window
flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint
2020-10-08 22:11:21 +03:00
height: 650
minimumHeight: 150
2023-10-31 05:11:03 +03:00
minimumWidth: 150
modality: Qt.NonModal
2023-10-31 05:11:03 +03:00
title: profile.isGlobalUserProfile ? qsTr("Global User Profile") : qsTr("Room User Profile")
width: 420
2020-10-08 22:11:21 +03:00
2021-01-30 02:18:39 +03:00
Shortcut {
sequence: StandardKey.Cancel
2023-10-31 05:11:03 +03:00
2021-01-30 02:18:39 +03:00
onActivated: userProfileDialog.close()
}
ListView {
id: devicelist
2023-02-24 04:40:14 +03:00
property int selectedTab: 0
Layout.fillHeight: true
Layout.fillWidth: true
anchors.fill: parent
anchors.margins: 10
2023-10-31 05:11:03 +03:00
boundsBehavior: Flickable.StopAtBounds
clip: true
footerPositioning: ListView.OverlayFooter
2023-10-31 05:11:03 +03:00
model: (selectedTab == 0) ? devicesModel : sharedRoomsModel
spacing: 8
2020-10-08 22:11:21 +03:00
2023-10-31 05:11:03 +03:00
footer: DialogButtonBox {
alignment: Qt.AlignRight
standardButtons: DialogButtonBox.Ok
width: devicelist.width
z: 2
background: Rectangle {
anchors.fill: parent
color: palette.window
}
onAccepted: userProfileDialog.close()
}
header: ColumnLayout {
id: contentL
spacing: Nheko.paddingMedium
2023-10-31 05:11:03 +03:00
width: devicelist.width
Avatar {
id: displayAvatar
2023-10-31 05:11:03 +03:00
Layout.alignment: Qt.AlignHCenter
2023-10-26 17:43:09 +03:00
Layout.preferredHeight: 130
Layout.preferredWidth: 130
displayName: profile.displayName
2023-10-31 05:11:03 +03:00
url: profile.avatarUrl.replace("mxc://", "image://MxcImage/")
userid: profile.userid
2023-10-31 05:11:03 +03:00
2022-05-10 04:19:53 +03:00
onClicked: TimelineManager.openImageOverlay(null, profile.avatarUrl, "", 0, 0)
ImageButton {
ToolTip.text: profile.isGlobalUserProfile ? qsTr("Change avatar globally.") : qsTr("Change avatar. Will only apply to this room.")
2023-10-31 05:11:03 +03:00
ToolTip.visible: hovered
anchors.left: displayAvatar.left
anchors.leftMargin: Nheko.paddingMedium
2023-10-31 05:11:03 +03:00
anchors.top: displayAvatar.top
anchors.topMargin: Nheko.paddingMedium
2023-10-31 05:11:03 +03:00
hoverEnabled: true
2021-11-14 04:23:10 +03:00
image: ":/icons/icons/ui/edit.svg"
2023-10-31 05:11:03 +03:00
visible: profile.isSelf
onClicked: profile.changeAvatar()
}
}
Spinner {
Layout.alignment: Qt.AlignHCenter
2023-10-31 05:11:03 +03:00
foreground: palette.mid
running: profile.isLoading
visible: profile.isLoading
}
Text {
id: errorText
2021-02-07 21:58:32 +03:00
2023-10-31 05:11:03 +03:00
Layout.alignment: Qt.AlignHCenter
color: "red"
opacity: 0
2023-10-31 05:11:03 +03:00
visible: opacity > 0
}
SequentialAnimation {
id: hideErrorAnimation
2021-02-07 21:58:32 +03:00
running: false
PauseAnimation {
duration: 4000
}
NumberAnimation {
2023-10-31 05:11:03 +03:00
duration: 1000
property: 'opacity'
2023-10-31 05:11:03 +03:00
target: errorText
to: 0
}
}
Connections {
function onDisplayError(errorMessage) {
errorText.text = errorMessage;
errorText.opacity = 1;
hideErrorAnimation.restart();
}
target: profile
}
TextInput {
id: displayUsername
property bool isUsernameEditingAllowed
Layout.alignment: Qt.AlignHCenter
Layout.maximumWidth: parent.width - (Nheko.paddingSmall * 2) - usernameChangeButton.anchors.leftMargin - (usernameChangeButton.width * 2)
2023-10-31 05:11:03 +03:00
color: TimelineManager.userColor(profile.userid, palette.window)
font.bold: true
font.pixelSize: 20
horizontalAlignment: TextInput.AlignHCenter
2023-10-31 05:11:03 +03:00
readOnly: !isUsernameEditingAllowed
selectByMouse: true
2023-10-31 05:11:03 +03:00
text: profile.displayName
wrapMode: TextInput.Wrap
onAccepted: {
profile.changeUsername(displayUsername.text);
displayUsername.isUsernameEditingAllowed = false;
}
2020-10-08 22:11:21 +03:00
ImageButton {
id: usernameChangeButton
2023-10-31 05:11:03 +03:00
ToolTip.text: profile.isGlobalUserProfile ? qsTr("Change display name globally.") : qsTr("Change display name. Will only apply to this room.")
ToolTip.visible: hovered
anchors.left: displayUsername.right
2023-10-31 05:11:03 +03:00
anchors.leftMargin: Nheko.paddingSmall
anchors.verticalCenter: displayUsername.verticalCenter
hoverEnabled: true
2021-11-14 04:23:10 +03:00
image: displayUsername.isUsernameEditingAllowed ? ":/icons/icons/ui/checkmark.svg" : ":/icons/icons/ui/edit.svg"
2023-10-31 05:11:03 +03:00
visible: profile.isSelf
onClicked: {
if (displayUsername.isUsernameEditingAllowed) {
profile.changeUsername(displayUsername.text);
displayUsername.isUsernameEditingAllowed = false;
} else {
displayUsername.isUsernameEditingAllowed = true;
displayUsername.focus = true;
displayUsername.selectAll();
}
}
}
}
MatrixText {
Layout.alignment: Qt.AlignHCenter
2023-10-31 05:11:03 +03:00
text: profile.userid
}
MatrixText {
id: statusMsg
2023-10-31 05:11:03 +03:00
property string userStatus: Presence.userStatus(profile.userid)
Layout.fillWidth: true
Layout.leftMargin: Nheko.paddingMedium
Layout.rightMargin: Nheko.paddingMedium
font.pointSize: Math.floor(fontMetrics.font.pointSize * 0.9)
2023-10-31 05:11:03 +03:00
horizontalAlignment: TextEdit.AlignHCenter
text: qsTr("<i><b>Status:</b> %1</i>").arg(userStatus)
visible: userStatus != ""
Connections {
function onPresenceChanged(id) {
2023-10-31 05:11:03 +03:00
if (id == profile.userid)
statusMsg.userStatus = Presence.userStatus(profile.userid);
}
2023-10-31 05:11:03 +03:00
target: Presence
}
}
RowLayout {
Layout.alignment: Qt.AlignHCenter
spacing: Nheko.paddingSmall
2023-10-31 05:11:03 +03:00
visible: !profile.isGlobalUserProfile
MatrixText {
id: displayRoomname
2023-10-31 05:11:03 +03:00
Layout.maximumWidth: parent.parent.width - (parent.spacing * 3) - 16
ToolTip.text: qsTr("This is a room-specific profile. The user's name and avatar may be different from their global versions.")
ToolTip.visible: ma.hovered
horizontalAlignment: TextEdit.AlignHCenter
2023-10-31 05:11:03 +03:00
text: qsTr("Room: %1").arg(profile.room ? profile.room.roomName : "")
HoverHandler {
id: ma
2023-10-31 05:11:03 +03:00
}
}
ImageButton {
ToolTip.text: qsTr("Open the global profile for this user.")
2023-10-31 05:11:03 +03:00
ToolTip.visible: hovered
hoverEnabled: true
image: ":/icons/icons/ui/world.svg"
onClicked: profile.openGlobalProfile()
}
2020-10-08 22:11:21 +03:00
}
Button {
id: verifyUserButton
Layout.alignment: Qt.AlignHCenter
enabled: profile.userVerified != Crypto.Verified
2023-10-31 05:11:03 +03:00
text: qsTr("Verify")
visible: profile.userVerified != Crypto.Verified && !profile.isSelf && profile.userVerificationEnabled
2023-10-31 05:11:03 +03:00
onClicked: profile.verify()
}
EncryptionIndicator {
2023-10-31 05:11:03 +03:00
Layout.alignment: Qt.AlignHCenter
2023-04-04 20:29:08 +03:00
Layout.preferredHeight: 32
Layout.preferredWidth: 32
2023-10-31 05:11:03 +03:00
ToolTip.visible: false
encrypted: profile.userVerificationEnabled
trust: profile.userVerified
2020-10-08 22:11:21 +03:00
}
RowLayout {
// ImageButton{
2021-11-14 04:23:10 +03:00
// image:":/icons/icons/ui/volume-off-indicator.svg"
// Layout.margins: {
// left: 5
// right: 5
// }
// ToolTip.visible: hovered
// ToolTip.text: qsTr("Ignore messages from this user.")
// onClicked : {
// profile.ignoreUser()
// }
// }
Layout.alignment: Qt.AlignHCenter
Layout.bottomMargin: 10
spacing: Nheko.paddingSmall
ImageButton {
2023-04-04 20:29:08 +03:00
Layout.preferredHeight: 24
Layout.preferredWidth: 24
ToolTip.text: qsTr("Start a private chat.")
2023-10-31 05:11:03 +03:00
ToolTip.visible: hovered
hoverEnabled: true
image: ":/icons/icons/ui/chat.svg"
onClicked: profile.startChat()
}
ImageButton {
2023-04-04 20:29:08 +03:00
Layout.preferredHeight: 24
Layout.preferredWidth: 24
ToolTip.text: qsTr("Kick the user.")
2023-10-31 05:11:03 +03:00
ToolTip.visible: hovered
hoverEnabled: true
image: ":/icons/icons/ui/round-remove-button.svg"
visible: !profile.isGlobalUserProfile && profile.room.permissions.canKick()
2023-10-31 05:11:03 +03:00
onClicked: profile.kickUser()
}
ImageButton {
2023-04-04 20:29:08 +03:00
Layout.preferredHeight: 24
Layout.preferredWidth: 24
ToolTip.text: qsTr("Ban the user.")
2023-10-31 05:11:03 +03:00
ToolTip.visible: hovered
hoverEnabled: true
image: ":/icons/icons/ui/ban.svg"
visible: !profile.isGlobalUserProfile && profile.room.permissions.canBan()
2023-10-31 05:11:03 +03:00
onClicked: profile.banUser()
}
2023-07-28 04:04:34 +03:00
ImageButton {
Layout.preferredHeight: 24
Layout.preferredWidth: 24
ToolTip.text: profile.ignored ? qsTr("Unignore the user.") : qsTr("Ignore the user.")
2023-10-31 05:11:03 +03:00
ToolTip.visible: hovered
buttonTextColor: profile.ignored ? Nheko.theme.red : palette.buttonText
2023-10-31 05:11:03 +03:00
hoverEnabled: true
image: ":/icons/icons/ui/volume-off-indicator.svg"
visible: !profile.isSelf
2023-07-28 04:04:34 +03:00
2023-10-31 05:11:03 +03:00
onClicked: profile.ignored = !profile.ignored
}
ImageButton {
2023-04-04 20:29:08 +03:00
Layout.preferredHeight: 24
Layout.preferredWidth: 24
ToolTip.text: qsTr("Refresh device list.")
2023-10-31 05:11:03 +03:00
ToolTip.visible: hovered
hoverEnabled: true
image: ":/icons/icons/ui/refresh.svg"
onClicked: profile.refreshDevices()
}
}
2023-02-24 04:40:14 +03:00
TabBar {
id: tabbar
2023-10-31 05:11:03 +03:00
Layout.bottomMargin: Nheko.paddingMedium
2023-02-24 04:40:14 +03:00
Layout.fillWidth: true
2023-10-31 05:11:03 +03:00
visible: !profile.isSelf
2023-02-24 04:40:14 +03:00
onCurrentIndexChanged: devicelist.selectedTab = currentIndex
NhekoTabButton {
text: qsTr("Devices")
}
NhekoTabButton {
text: qsTr("Shared Rooms")
}
}
}
2020-10-08 22:11:21 +03:00
2023-02-24 04:40:14 +03:00
DelegateModel {
id: devicesModel
2023-10-31 05:11:03 +03:00
2023-02-24 04:40:14 +03:00
model: profile.deviceList
2023-10-31 05:11:03 +03:00
2023-02-24 04:40:14 +03:00
delegate: RowLayout {
required property string deviceId
required property string deviceName
required property string lastIp
required property var lastTs
2023-10-31 05:11:03 +03:00
required property int verificationStatus
2023-02-24 04:40:14 +03:00
spacing: 4
2023-10-31 05:11:03 +03:00
width: devicelist.width
2023-02-24 04:40:14 +03:00
ColumnLayout {
Layout.leftMargin: Nheko.paddingMedium
Layout.rightMargin: Nheko.paddingMedium
2023-10-31 05:11:03 +03:00
spacing: 0
2023-02-24 04:40:14 +03:00
RowLayout {
Text {
Layout.alignment: Qt.AlignLeft
2023-10-31 05:11:03 +03:00
Layout.fillWidth: true
color: palette.text
2023-02-24 04:40:14 +03:00
elide: Text.ElideRight
font.bold: true
text: deviceId
}
Image {
Layout.preferredHeight: 16
Layout.preferredWidth: 16
source: {
switch (verificationStatus) {
2023-10-31 05:11:03 +03:00
case VerificationStatus.VERIFIED:
2023-02-24 04:40:14 +03:00
return "image://colorimage/:/icons/icons/ui/shield-filled-checkmark.svg?" + Nheko.theme.green;
2023-10-31 05:11:03 +03:00
case VerificationStatus.UNVERIFIED:
2023-02-24 04:40:14 +03:00
return "image://colorimage/:/icons/icons/ui/shield-filled-exclamation-mark.svg?" + Nheko.theme.orange;
2023-10-31 05:11:03 +03:00
case VerificationStatus.SELF:
2023-02-24 04:40:14 +03:00
return "image://colorimage/:/icons/icons/ui/checkmark.svg?" + Nheko.theme.green;
2023-10-31 05:11:03 +03:00
default:
2023-02-24 04:40:14 +03:00
return "image://colorimage/:/icons/icons/ui/shield-filled-cross.svg?" + Nheko.theme.orange;
}
}
2023-10-31 05:11:03 +03:00
sourceSize.height: 16 * Screen.devicePixelRatio
sourceSize.width: 16 * Screen.devicePixelRatio
visible: profile.isSelf && verificationStatus != VerificationStatus.NOT_APPLICABLE
2023-02-24 04:40:14 +03:00
}
ImageButton {
Layout.alignment: Qt.AlignTop
ToolTip.text: qsTr("Sign out this device.")
2023-10-31 05:11:03 +03:00
ToolTip.visible: hovered
hoverEnabled: true
image: ":/icons/icons/ui/power-off.svg"
2023-02-24 04:40:14 +03:00
visible: profile.isSelf
2023-10-31 05:11:03 +03:00
onClicked: profile.signOutDevice(deviceId)
}
2023-02-24 04:40:14 +03:00
}
RowLayout {
id: deviceNameRow
property bool isEditingAllowed
TextInput {
id: deviceNameField
Layout.alignment: Qt.AlignLeft
Layout.fillWidth: true
2023-10-31 05:11:03 +03:00
color: palette.text
readOnly: !deviceNameRow.isEditingAllowed
2023-02-24 04:40:14 +03:00
selectByMouse: true
2023-10-31 05:11:03 +03:00
text: deviceName
2023-02-24 04:40:14 +03:00
onAccepted: {
profile.changeDeviceName(deviceId, deviceNameField.text);
deviceNameRow.isEditingAllowed = false;
}
}
ImageButton {
ToolTip.text: qsTr("Change device name.")
2023-10-31 05:11:03 +03:00
ToolTip.visible: hovered
hoverEnabled: true
2023-02-24 04:40:14 +03:00
image: deviceNameRow.isEditingAllowed ? ":/icons/icons/ui/checkmark.svg" : ":/icons/icons/ui/edit.svg"
2023-10-31 05:11:03 +03:00
visible: profile.isSelf
2023-02-24 04:40:14 +03:00
onClicked: {
if (deviceNameRow.isEditingAllowed) {
profile.changeDeviceName(deviceId, deviceNameField.text);
deviceNameRow.isEditingAllowed = false;
} else {
deviceNameRow.isEditingAllowed = true;
deviceNameField.focus = true;
deviceNameField.selectAll();
}
}
}
}
Text {
Layout.alignment: Qt.AlignLeft
2023-10-31 05:11:03 +03:00
Layout.fillWidth: true
color: palette.text
2023-10-31 05:11:03 +03:00
elide: Text.ElideRight
2023-02-24 04:40:14 +03:00
text: qsTr("Last seen %1 from %2").arg(new Date(lastTs).toLocaleString(Locale.ShortFormat)).arg(lastIp ? lastIp : "???")
2023-10-31 05:11:03 +03:00
visible: profile.isSelf
}
2023-02-24 04:40:14 +03:00
}
Image {
Layout.preferredHeight: 16
Layout.preferredWidth: 16
source: {
switch (verificationStatus) {
2023-10-31 05:11:03 +03:00
case VerificationStatus.VERIFIED:
2023-02-24 04:40:14 +03:00
return "image://colorimage/:/icons/icons/ui/shield-filled-checkmark.svg?" + Nheko.theme.green;
2023-10-31 05:11:03 +03:00
case VerificationStatus.UNVERIFIED:
2023-02-24 04:40:14 +03:00
return "image://colorimage/:/icons/icons/ui/shield-filled-exclamation-mark.svg?" + Nheko.theme.orange;
2023-10-31 05:11:03 +03:00
case VerificationStatus.SELF:
2023-02-24 04:40:14 +03:00
return "image://colorimage/:/icons/icons/ui/checkmark.svg?" + Nheko.theme.green;
2023-10-31 05:11:03 +03:00
default:
2023-02-24 04:40:14 +03:00
return "image://colorimage/:/icons/icons/ui/shield-filled.svg?" + Nheko.theme.red;
}
}
2023-10-31 05:11:03 +03:00
visible: !profile.isSelf && verificationStatus != VerificationStatus.NOT_APPLICABLE
2023-02-24 04:40:14 +03:00
}
Button {
id: verifyButton
2023-02-24 04:40:14 +03:00
text: (verificationStatus != VerificationStatus.VERIFIED) ? qsTr("Verify") : qsTr("Unverify")
2023-10-31 05:11:03 +03:00
visible: verificationStatus == VerificationStatus.UNVERIFIED && (profile.isSelf || !profile.userVerificationEnabled)
2023-02-24 04:40:14 +03:00
onClicked: {
if (verificationStatus == VerificationStatus.VERIFIED)
2023-10-31 05:11:03 +03:00
profile.unverify(deviceId);
2023-02-24 04:40:14 +03:00
else
2023-10-31 05:11:03 +03:00
profile.verify(deviceId);
2023-02-24 04:40:14 +03:00
}
}
2023-02-24 04:40:14 +03:00
}
}
DelegateModel {
id: sharedRoomsModel
2023-10-31 05:11:03 +03:00
2023-02-24 04:40:14 +03:00
model: profile.sharedRooms
2023-10-31 05:11:03 +03:00
2023-02-24 04:40:14 +03:00
delegate: RowLayout {
2023-10-31 05:11:03 +03:00
required property string avatarUrl
2023-02-24 04:40:14 +03:00
required property string roomId
required property string roomName
2023-02-24 04:40:14 +03:00
spacing: 4
2023-10-31 05:11:03 +03:00
width: devicelist.width
2023-02-24 04:40:14 +03:00
Avatar {
id: avatar
2023-10-31 05:11:03 +03:00
property int avatarSize: Math.ceil(fontMetrics.lineSpacing * 1.6)
2023-02-24 04:40:14 +03:00
Layout.alignment: Qt.AlignVCenter
Layout.leftMargin: Nheko.paddingMedium
2023-10-26 17:43:09 +03:00
Layout.preferredHeight: avatarSize
Layout.preferredWidth: avatarSize
2023-02-24 04:40:14 +03:00
displayName: roomName
2023-10-31 05:11:03 +03:00
enabled: false
roomid: roomId
url: avatarUrl.replace("mxc://", "image://MxcImage/")
2020-10-08 22:11:21 +03:00
}
2023-02-24 04:40:14 +03:00
ElidedLabel {
Layout.alignment: Qt.AlignVCenter
Layout.fillWidth: true
2023-10-31 05:11:03 +03:00
Layout.rightMargin: Nheko.paddingMedium
color: palette.text
2023-02-24 04:40:14 +03:00
elideWidth: width
fullText: roomName
textFormat: Text.PlainText
}
2023-02-24 04:40:14 +03:00
Item {
Layout.fillWidth: true
}
2020-10-08 22:11:21 +03:00
}
}
}
2020-05-17 16:34:47 +03:00
}