2024-02-14 12:52:54 +00:00
|
|
|
|
import QtQuick 2.15
|
|
|
|
|
import QtQuick.Layouts 1.15
|
|
|
|
|
import QtQml.Models 2.15
|
2021-10-19 09:17:20 +00:00
|
|
|
|
|
2023-02-06 13:37:25 +00:00
|
|
|
|
import StatusQ 0.1
|
2021-10-19 09:17:20 +00:00
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
|
import StatusQ.Controls 0.1
|
2022-03-10 19:41:59 +00:00
|
|
|
|
import StatusQ.Controls.Validators 0.1
|
2024-02-14 12:52:54 +00:00
|
|
|
|
import StatusQ.Popups.Dialog 0.1
|
2022-07-20 10:48:44 +00:00
|
|
|
|
|
2024-02-14 12:52:54 +00:00
|
|
|
|
import shared.controls 1.0
|
2024-03-11 23:15:19 +00:00
|
|
|
|
import utils 1.0
|
2022-09-27 21:26:26 +00:00
|
|
|
|
|
2024-02-14 12:52:54 +00:00
|
|
|
|
CommonContactDialog {
|
|
|
|
|
id: root
|
2020-09-16 16:00:21 +00:00
|
|
|
|
|
2024-02-14 12:52:54 +00:00
|
|
|
|
readonly property string nickname: contactDetails.localNickname
|
2022-07-20 10:48:44 +00:00
|
|
|
|
|
2022-03-08 11:01:57 +00:00
|
|
|
|
signal editDone(string newNickname)
|
2024-02-14 12:52:54 +00:00
|
|
|
|
signal removeNicknameRequested()
|
|
|
|
|
|
|
|
|
|
title: d.editMode ? qsTr("Edit nickname") : qsTr("Add nickname")
|
2021-10-22 20:49:47 +00:00
|
|
|
|
|
|
|
|
|
onOpened: {
|
2022-09-27 21:26:26 +00:00
|
|
|
|
nicknameInput.input.edit.forceActiveFocus()
|
2021-10-22 20:49:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-14 12:52:54 +00:00
|
|
|
|
readonly property var d: QtObject {
|
|
|
|
|
id: d
|
|
|
|
|
readonly property bool editMode: root.nickname !== ""
|
|
|
|
|
}
|
2021-01-12 20:51:00 +00:00
|
|
|
|
|
2024-02-14 12:52:54 +00:00
|
|
|
|
StatusInput {
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
id: nicknameInput
|
|
|
|
|
label: qsTr("Nickname")
|
|
|
|
|
input.clearable: true
|
|
|
|
|
text: root.nickname
|
2024-03-11 23:15:19 +00:00
|
|
|
|
charLimit: Constants.keypair.nameLengthMax
|
2024-02-14 12:52:54 +00:00
|
|
|
|
validators: [
|
|
|
|
|
StatusValidator {
|
2024-03-11 23:15:19 +00:00
|
|
|
|
validatorObj: RXValidator { regularExpression: /^[\w\d_ -\.]*$/u }
|
2024-02-14 12:52:54 +00:00
|
|
|
|
validate: (value) => validatorObj.test(value)
|
2024-03-11 23:15:19 +00:00
|
|
|
|
errorMessage: qsTr("Invalid characters (use A-Z and 0-9, hyphens and underscores only)")
|
|
|
|
|
},
|
|
|
|
|
StatusMinLengthValidator {
|
|
|
|
|
minLength: Constants.keypair.nameLengthMin
|
|
|
|
|
errorMessage: qsTr("Nicknames must be at least %n character(s) long", "", minLength)
|
|
|
|
|
},
|
|
|
|
|
StatusValidator {
|
|
|
|
|
name: "startsWithSpaceValidator"
|
|
|
|
|
validate: function (t) { return !(t.startsWith(" ") || t.endsWith(" "))}
|
|
|
|
|
errorMessage: qsTr("Nicknames can’t start or end with a space")
|
|
|
|
|
},
|
|
|
|
|
StatusValidator {
|
|
|
|
|
name: "endsWith-ethValidator"
|
|
|
|
|
validate: function (t) { return !(t.endsWith("-eth") || t.endsWith("_eth") || t.endsWith(".eth")) }
|
|
|
|
|
errorMessage: qsTr("Nicknames can’t end in “.eth”, “_eth” or “-eth”")
|
|
|
|
|
},
|
|
|
|
|
StatusValidator {
|
|
|
|
|
name: "isAliasValidator"
|
|
|
|
|
validate: function (t) { return !Utils.isAlias(t) }
|
|
|
|
|
errorMessage: qsTr("Adjective-animal nickname formats are not allowed")
|
2021-10-19 09:17:20 +00:00
|
|
|
|
}
|
2024-02-14 12:52:54 +00:00
|
|
|
|
]
|
2024-03-11 23:15:19 +00:00
|
|
|
|
onKeyPressed: {
|
2024-02-14 12:52:54 +00:00
|
|
|
|
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
|
2024-03-11 23:15:19 +00:00
|
|
|
|
if (root.nickname !== nicknameInput.text && nicknameInput.valid)
|
|
|
|
|
root.editDone(nicknameInput.text)
|
2021-01-13 00:31:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-16 16:00:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-14 12:52:54 +00:00
|
|
|
|
StatusBaseText {
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
text: qsTr("Nicknames help you identify others and are only visible to you")
|
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
|
font.pixelSize: Theme.tertiaryTextFontSize
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-16 11:56:29 +00:00
|
|
|
|
rightButtons: ObjectModel {
|
|
|
|
|
StatusFlatButton {
|
|
|
|
|
visible: !d.editMode
|
|
|
|
|
text: qsTr("Cancel")
|
|
|
|
|
onClicked: root.close()
|
|
|
|
|
}
|
|
|
|
|
StatusFlatButton {
|
|
|
|
|
visible: d.editMode
|
|
|
|
|
borderColor: "transparent"
|
|
|
|
|
type: StatusBaseButton.Type.Danger
|
|
|
|
|
text: qsTr("Remove nickname")
|
|
|
|
|
onClicked: root.removeNicknameRequested()
|
|
|
|
|
}
|
|
|
|
|
StatusButton {
|
|
|
|
|
enabled: root.nickname !== nicknameInput.text && nicknameInput.valid
|
|
|
|
|
text: d.editMode ? qsTr("Change nickname") : qsTr("Add nickname")
|
|
|
|
|
onClicked: root.editDone(nicknameInput.text)
|
2020-09-16 16:00:21 +00:00
|
|
|
|
}
|
2024-02-14 12:52:54 +00:00
|
|
|
|
}
|
2020-09-16 16:00:21 +00:00
|
|
|
|
}
|