2019-07-13 19:34:58 +10:00
|
|
|
// Copyright 2019 miruka
|
|
|
|
// This file is part of harmonyqml, licensed under LGPLv3.
|
|
|
|
|
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Controls 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
|
|
|
import "../../Base"
|
|
|
|
import "../../utils.js" as Utils
|
|
|
|
|
2019-07-14 10:15:20 +10:00
|
|
|
HGridLayout {
|
|
|
|
function applyChanges() {
|
2019-07-16 06:14:08 +10:00
|
|
|
if (nameField.changed) {
|
|
|
|
saveButton.nameChangeRunning = true
|
2019-07-14 10:15:20 +10:00
|
|
|
|
2019-07-16 06:14:08 +10:00
|
|
|
py.callClientCoro(
|
|
|
|
userId, "set_displayname", [nameField.field.text], () => {
|
|
|
|
saveButton.nameChangeRunning = false
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-07-19 11:58:21 +10:00
|
|
|
if (aliasField.changed) {
|
|
|
|
window.settings.write_aliases[userId] = aliasField.field.text
|
|
|
|
window.settingsChanged()
|
|
|
|
}
|
|
|
|
|
2019-07-16 06:14:08 +10:00
|
|
|
if (avatar.changed) {
|
|
|
|
saveButton.avatarChangeRunning = true
|
2019-07-18 19:18:13 +10:00
|
|
|
let path = Qt.resolvedUrl(avatar.imageUrl).replace(/^file:/, "")
|
2019-07-16 06:14:08 +10:00
|
|
|
|
|
|
|
py.callClientCoro(
|
|
|
|
userId, "set_avatar_from_file", [path], response => {
|
|
|
|
saveButton.avatarChangeRunning = false
|
|
|
|
if (response != true) { print(response) }
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
2019-07-14 10:15:20 +10:00
|
|
|
}
|
|
|
|
|
2019-07-19 11:58:21 +10:00
|
|
|
function cancelChanges() {
|
|
|
|
nameField.field.text = userInfo.displayName
|
|
|
|
aliasField.field.text = aliasField.currentAlias
|
|
|
|
fileDialog.selectedFile = ""
|
|
|
|
fileDialog.file = ""
|
|
|
|
}
|
|
|
|
|
2019-07-14 10:15:20 +10:00
|
|
|
columns: 2
|
2019-07-18 15:18:06 +10:00
|
|
|
flow: window.isWide ? GridLayout.LeftToRight : GridLayout.TopToBottom
|
2019-07-14 10:15:20 +10:00
|
|
|
rowSpacing: currentSpacing
|
|
|
|
|
|
|
|
Component.onCompleted: nameField.field.forceActiveFocus()
|
|
|
|
|
|
|
|
HUserAvatar {
|
2019-07-16 06:14:08 +10:00
|
|
|
property bool changed: avatar.imageUrl != avatar.defaultImageUrl
|
|
|
|
|
2019-07-14 10:15:20 +10:00
|
|
|
id: avatar
|
|
|
|
userId: editAccount.userId
|
2019-07-16 18:37:39 +10:00
|
|
|
imageUrl: fileDialog.selectedFile || fileDialog.file || defaultImageUrl
|
|
|
|
toolTipImageUrl: ""
|
2019-07-14 10:15:20 +10:00
|
|
|
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
|
2019-07-16 08:54:21 +10:00
|
|
|
Layout.preferredWidth: Math.min(flickable.height, avatarPreferredSize)
|
2019-07-14 10:15:20 +10:00
|
|
|
Layout.preferredHeight: Layout.preferredWidth
|
2019-07-16 06:14:08 +10:00
|
|
|
|
2019-07-16 10:10:43 +10:00
|
|
|
HRectangle {
|
|
|
|
z: 10
|
|
|
|
visible: opacity > 0
|
2019-07-16 18:37:39 +10:00
|
|
|
opacity: ! fileDialog.dialog.visible &&
|
|
|
|
(! avatar.imageUrl || avatar.hovered) ? 1 : 0
|
2019-07-16 10:10:43 +10:00
|
|
|
Behavior on opacity { HNumberAnimation {} }
|
|
|
|
|
|
|
|
anchors.fill: parent
|
2019-07-18 15:31:51 +10:00
|
|
|
color: Utils.hsla(0, 0, 0, avatar.imageUrl ? 0.7 : 1)
|
2019-07-16 10:10:43 +10:00
|
|
|
|
|
|
|
HColumnLayout {
|
|
|
|
anchors.centerIn: parent
|
|
|
|
spacing: currentSpacing
|
2019-07-17 01:48:57 +10:00
|
|
|
width: parent.width
|
2019-07-16 10:10:43 +10:00
|
|
|
|
|
|
|
HIcon {
|
2019-07-18 03:40:28 +10:00
|
|
|
svgName: "upload-avatar"
|
2019-07-16 10:10:43 +10:00
|
|
|
dimension: 64
|
|
|
|
Layout.alignment: Qt.AlignCenter
|
|
|
|
}
|
|
|
|
|
2019-07-16 19:29:47 +10:00
|
|
|
Item { Layout.preferredHeight: theme.spacing }
|
2019-07-16 10:10:43 +10:00
|
|
|
|
|
|
|
HLabel {
|
|
|
|
text: qsTr("Upload profile picture")
|
2019-07-18 15:31:51 +10:00
|
|
|
color: Utils.hsla(0, 0, 90, 1)
|
2019-07-17 01:48:57 +10:00
|
|
|
font.pixelSize: theme.fontSize.big *
|
|
|
|
avatar.height / avatarPreferredSize
|
2019-07-16 10:10:43 +10:00
|
|
|
wrapMode: Text.WordWrap
|
2019-07-17 01:48:57 +10:00
|
|
|
horizontalAlignment: Qt.AlignHCenter
|
2019-07-16 19:08:27 +10:00
|
|
|
|
2019-07-16 10:10:43 +10:00
|
|
|
Layout.fillWidth: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-16 06:14:08 +10:00
|
|
|
HFileDialogOpener {
|
|
|
|
id: fileDialog
|
|
|
|
fileType: HFileDialogOpener.FileType.Images
|
|
|
|
dialog.title: qsTr("Select profile picture for %1")
|
|
|
|
.arg(userInfo.displayName)
|
|
|
|
}
|
2019-07-14 10:15:20 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
HColumnLayout {
|
|
|
|
id: profileInfo
|
2019-07-16 19:29:47 +10:00
|
|
|
spacing: theme.spacing
|
2019-07-14 10:15:20 +10:00
|
|
|
|
|
|
|
HColumnLayout {
|
2019-07-16 19:29:47 +10:00
|
|
|
spacing: theme.spacing
|
2019-07-14 10:15:20 +10:00
|
|
|
Layout.margins: currentSpacing
|
|
|
|
|
|
|
|
HLabel {
|
|
|
|
text: qsTr("User ID:<br>%1")
|
2019-07-16 10:10:43 +10:00
|
|
|
.arg(Utils.coloredNameHtml(userId, userId, userId))
|
2019-07-14 10:15:20 +10:00
|
|
|
textFormat: Text.StyledText
|
|
|
|
wrapMode: Text.Wrap
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
}
|
|
|
|
|
|
|
|
HLabeledTextField {
|
2019-07-16 06:14:08 +10:00
|
|
|
property bool changed: field.text != userInfo.displayName
|
|
|
|
|
2019-07-14 10:15:20 +10:00
|
|
|
id: nameField
|
|
|
|
label.text: qsTr("Display name:")
|
|
|
|
field.text: userInfo.displayName
|
|
|
|
field.onAccepted: applyChanges()
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.maximumWidth: 480
|
|
|
|
}
|
2019-07-19 11:58:21 +10:00
|
|
|
|
|
|
|
HLabeledTextField {
|
|
|
|
property string currentAlias:
|
|
|
|
window.settings.write_aliases[userId] || ""
|
|
|
|
|
|
|
|
property bool changed: field.text != currentAlias
|
|
|
|
|
|
|
|
id: aliasField
|
|
|
|
label.text: qsTr("Write alias:")
|
|
|
|
field.text: currentAlias
|
|
|
|
field.onAccepted: applyChanges()
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.maximumWidth: 480
|
|
|
|
}
|
2019-07-14 10:15:20 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
HSpacer {}
|
|
|
|
|
|
|
|
HRowLayout {
|
|
|
|
Layout.alignment: Qt.AlignBottom
|
|
|
|
|
|
|
|
HUIButton {
|
2019-07-16 06:14:08 +10:00
|
|
|
property bool nameChangeRunning: false
|
|
|
|
property bool avatarChangeRunning: false
|
|
|
|
|
2019-07-14 10:15:20 +10:00
|
|
|
id: saveButton
|
2019-07-19 10:58:38 +10:00
|
|
|
iconName: "apply"
|
|
|
|
text: qsTr("Apply")
|
2019-07-16 06:14:08 +10:00
|
|
|
loading: nameChangeRunning || avatarChangeRunning
|
2019-07-19 11:58:21 +10:00
|
|
|
enabled:
|
|
|
|
nameField.changed || aliasField.changed || avatar.changed
|
2019-07-14 10:15:20 +10:00
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.alignment: Qt.AlignBottom
|
|
|
|
|
|
|
|
onClicked: applyChanges()
|
|
|
|
}
|
|
|
|
|
|
|
|
HUIButton {
|
|
|
|
iconName: "cancel"
|
|
|
|
text: qsTr("Cancel")
|
2019-07-19 11:58:21 +10:00
|
|
|
enabled: saveButton.enabled && ! saveButton.loading
|
2019-07-14 10:15:20 +10:00
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.alignment: Qt.AlignBottom
|
|
|
|
|
2019-07-19 11:58:21 +10:00
|
|
|
onClicked: cancelChanges()
|
2019-07-14 10:15:20 +10:00
|
|
|
}
|
|
|
|
}
|
2019-07-13 19:34:58 +10:00
|
|
|
}
|
|
|
|
}
|