matrixion/qml/dialogs/UserProfile.qml

400 lines
16 KiB
QML
Raw Normal View History

2021-03-05 02:35:15 +03:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
// SPDX-FileCopyrightText: 2022 Nheko Contributors
2021-03-05 02:35:15 +03:00
// SPDX-License-Identifier: GPL-3.0-or-later
2022-04-16 03:13:01 +03:00
import "../"
import "../device-verification"
import "../ui"
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.2
import QtQuick.Window 2.13
import im.nheko
import im.nheko
2020-05-22 08:47:02 +03:00
2020-10-08 22:11:21 +03:00
ApplicationWindow {
id: userProfileDialog
property var profile
2022-04-16 03:13:01 +03:00
color: timelineRoot.palette.window
flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint
2020-10-08 22:11:21 +03:00
height: 650
minimumHeight: 150
2022-04-16 03:13:01 +03:00
minimumWidth: 150
modality: Qt.NonModal
2022-04-11 05:18:16 +03:00
palette: timelineRoot.palette
2021-04-01 00:07:07 +03:00
title: profile.isGlobalUserProfile ? qsTr("Global User Profile") : qsTr("Room User Profile")
2022-04-16 03:13:01 +03:00
width: 420
2020-10-08 22:11:21 +03:00
2021-01-30 02:18:39 +03:00
Shortcut {
sequence: StandardKey.Cancel
2022-04-16 03:13:01 +03:00
2021-01-30 02:18:39 +03:00
onActivated: userProfileDialog.close()
}
ListView {
id: devicelist
Layout.fillHeight: true
Layout.fillWidth: true
anchors.fill: parent
anchors.margins: 10
2022-04-16 03:13:01 +03:00
boundsBehavior: Flickable.StopAtBounds
clip: true
footerPositioning: ListView.OverlayFooter
2022-04-16 03:13:01 +03:00
model: profile.deviceList
spacing: 8
2020-10-08 22:11:21 +03:00
2022-04-16 03:13:01 +03:00
delegate: RowLayout {
required property string deviceId
required property string deviceName
required property string lastIp
required property var lastTs
required property int verificationStatus
2021-02-02 14:54:08 +03:00
2022-04-16 03:13:01 +03:00
spacing: 4
width: devicelist.width
ColumnLayout {
spacing: 0
RowLayout {
Text {
Layout.alignment: Qt.AlignLeft
Layout.fillWidth: true
color: timelineRoot.palette.text
elide: Text.ElideRight
font.bold: true
text: deviceId
}
Image {
Layout.preferredHeight: 16
Layout.preferredWidth: 16
source: {
switch (verificationStatus) {
case VerificationStatus.VERIFIED:
return "image://colorimage/:/icons/icons/ui/shield-filled-checkmark.svg?green";
case VerificationStatus.UNVERIFIED:
return "image://colorimage/:/icons/icons/ui/shield-filled-exclamation-mark.svg?#d6c020";
case VerificationStatus.SELF:
return "image://colorimage/:/icons/icons/ui/checkmark.svg?green";
default:
return "image://colorimage/:/icons/icons/ui/shield-filled-cross.svg?#d6c020";
}
}
sourceSize.height: 16 * Screen.devicePixelRatio
sourceSize.width: 16 * Screen.devicePixelRatio
visible: profile.isSelf && verificationStatus != VerificationStatus.NOT_APPLICABLE
}
ImageButton {
Layout.alignment: Qt.AlignTop
ToolTip.text: qsTr("Sign out this device.")
ToolTip.visible: hovered
hoverEnabled: true
image: ":/icons/icons/ui/power-off.svg"
visible: profile.isSelf
2022-04-16 03:13:01 +03:00
onClicked: profile.signOutDevice(deviceId)
}
}
RowLayout {
id: deviceNameRow
property bool isEditingAllowed
TextInput {
id: deviceNameField
Layout.alignment: Qt.AlignLeft
Layout.fillWidth: true
color: timelineRoot.palette.text
readOnly: !deviceNameRow.isEditingAllowed
selectByMouse: true
text: deviceName
onAccepted: {
profile.changeDeviceName(deviceId, deviceNameField.text);
deviceNameRow.isEditingAllowed = false;
}
}
ImageButton {
ToolTip.text: qsTr("Change device name.")
ToolTip.visible: hovered
hoverEnabled: true
image: deviceNameRow.isEditingAllowed ? ":/icons/icons/ui/checkmark.svg" : ":/icons/icons/ui/edit.svg"
visible: profile.isSelf
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
Layout.fillWidth: true
color: timelineRoot.palette.text
elide: Text.ElideRight
text: qsTr("Last seen %1 from %2").arg(new Date(lastTs).toLocaleString(Locale.ShortFormat)).arg(lastIp ? lastIp : "???")
visible: profile.isSelf
}
}
Image {
Layout.preferredHeight: 16
Layout.preferredWidth: 16
source: {
switch (verificationStatus) {
case VerificationStatus.VERIFIED:
return "image://colorimage/:/icons/icons/ui/shield-filled-checkmark.svg?green";
case VerificationStatus.UNVERIFIED:
return "image://colorimage/:/icons/icons/ui/shield-filled-exclamation-mark.svg?#d6c020";
case VerificationStatus.SELF:
return "image://colorimage/:/icons/icons/ui/checkmark.svg?green";
default:
return "image://colorimage/:/icons/icons/ui/shield-filled.svg?red";
}
}
visible: !profile.isSelf && verificationStatus != VerificationStatus.NOT_APPLICABLE
}
Button {
id: verifyButton
text: (verificationStatus != VerificationStatus.VERIFIED) ? qsTr("Verify") : qsTr("Unverify")
visible: verificationStatus == VerificationStatus.UNVERIFIED && (profile.isSelf || !profile.userVerificationEnabled)
onClicked: {
if (verificationStatus == VerificationStatus.VERIFIED)
profile.unverify(deviceId);
else
profile.verify(deviceId);
}
}
}
footer: DialogButtonBox {
alignment: Qt.AlignRight
standardButtons: DialogButtonBox.Ok
width: devicelist.width
2022-04-16 03:13:01 +03:00
z: 2
background: Rectangle {
anchors.fill: parent
color: timelineRoot.palette.window
}
onAccepted: userProfileDialog.close()
}
header: ColumnLayout {
id: contentL
spacing: 10
2022-04-16 03:13:01 +03:00
width: devicelist.width
Avatar {
id: displayAvatar
2022-04-16 03:13:01 +03:00
Layout.alignment: Qt.AlignHCenter
displayName: profile.displayName
2022-04-16 03:13:01 +03:00
height: 130
url: profile.avatarUrl.replace("mxc://", "image://MxcImage/")
userid: profile.userid
2022-04-16 03:13:01 +03:00
width: 130
onClicked: TimelineManager.openImageOverlay(null, profile.avatarUrl, "")
ImageButton {
ToolTip.text: profile.isGlobalUserProfile ? qsTr("Change avatar globally.") : qsTr("Change avatar. Will only apply to this room.")
2022-04-16 03:13:01 +03:00
ToolTip.visible: hovered
anchors.left: displayAvatar.left
anchors.leftMargin: Nheko.paddingMedium
2022-04-16 03:13:01 +03:00
anchors.top: displayAvatar.top
anchors.topMargin: Nheko.paddingMedium
2022-04-16 03:13:01 +03:00
hoverEnabled: true
2021-11-14 04:23:10 +03:00
image: ":/icons/icons/ui/edit.svg"
2022-04-16 03:13:01 +03:00
visible: profile.isSelf
onClicked: profile.changeAvatar()
}
}
Spinner {
Layout.alignment: Qt.AlignHCenter
2022-04-16 03:13:01 +03:00
foreground: timelineRoot.palette.mid
running: profile.isLoading
visible: profile.isLoading
}
Text {
id: errorText
2022-04-16 03:13:01 +03:00
Layout.alignment: Qt.AlignHCenter
color: "red"
opacity: 0
2022-04-16 03:13:01 +03:00
visible: opacity > 0
}
SequentialAnimation {
id: hideErrorAnimation
running: false
PauseAnimation {
duration: 4000
}
NumberAnimation {
2022-04-16 03:13:01 +03:00
duration: 1000
property: 'opacity'
2022-04-16 03:13:01 +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)
2022-04-16 03:13:01 +03:00
color: TimelineManager.userColor(profile.userid, timelineRoot.palette.window)
font.bold: true
font.pixelSize: 20
horizontalAlignment: TextInput.AlignHCenter
2022-04-16 03:13:01 +03:00
readOnly: !isUsernameEditingAllowed
selectByMouse: true
2022-04-16 03:13:01 +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
2022-04-16 03:13:01 +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
2022-04-16 03:13:01 +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"
2022-04-16 03:13:01 +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
2022-04-16 03:13:01 +03:00
text: profile.userid
}
RowLayout {
Layout.alignment: Qt.AlignHCenter
spacing: Nheko.paddingSmall
2022-04-16 03:13:01 +03:00
visible: !profile.isGlobalUserProfile
MatrixText {
id: displayRoomname
2022-04-16 03:13:01 +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
2022-04-16 03:13:01 +03:00
text: qsTr("Room: %1").arg(profile.room ? profile.room.roomName : "")
HoverHandler {
id: ma
}
}
ImageButton {
ToolTip.text: qsTr("Open the global profile for this user.")
2022-04-16 03:13:01 +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
2022-04-16 03:13:01 +03:00
text: qsTr("Verify")
visible: profile.userVerified != Crypto.Verified && !profile.isSelf && profile.userVerificationEnabled
2022-04-16 03:13:01 +03:00
onClicked: profile.verify()
}
EncryptionIndicator {
2022-04-16 03:13:01 +03:00
Layout.alignment: Qt.AlignHCenter
Layout.preferredHeight: 16
Layout.preferredWidth: 16
2022-04-16 03:13:01 +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 {
ToolTip.text: qsTr("Start a private chat.")
2022-04-16 03:13:01 +03:00
ToolTip.visible: hovered
hoverEnabled: true
image: ":/icons/icons/ui/chat.svg"
onClicked: profile.startChat()
}
ImageButton {
ToolTip.text: qsTr("Kick the user.")
2022-04-16 03:13:01 +03:00
ToolTip.visible: hovered
hoverEnabled: true
image: ":/icons/icons/ui/round-remove-button.svg"
visible: !profile.isGlobalUserProfile && profile.room.permissions.canKick()
2022-04-16 03:13:01 +03:00
onClicked: profile.kickUser()
}
ImageButton {
ToolTip.text: qsTr("Ban the user.")
2022-04-16 03:13:01 +03:00
ToolTip.visible: hovered
hoverEnabled: true
image: ":/icons/icons/ui/ban.svg"
visible: !profile.isGlobalUserProfile && profile.room.permissions.canBan()
2022-04-16 03:13:01 +03:00
onClicked: profile.banUser()
}
ImageButton {
ToolTip.text: qsTr("Refresh device list.")
2022-04-16 03:13:01 +03:00
ToolTip.visible: hovered
hoverEnabled: true
image: ":/icons/icons/ui/refresh.svg"
2022-04-16 03:13:01 +03:00
onClicked: profile.refreshDevices()
}
2020-10-08 22:11:21 +03:00
}
}
2020-10-08 22:11:21 +03:00
}
2020-05-17 16:34:47 +03:00
}