Warning, /network/neochat/src/qml/AccountEditorPage.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2020 Tobias Fella <tobias.fella@kde.org> 0002 // SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu> 0003 // SPDX-License-Identifier: GPL-2.0-or-later 0004 0005 import QtQuick 0006 import QtQuick.Controls as QQC2 0007 import QtQuick.Layouts 0008 import Qt.labs.platform 0009 import QtQuick.Window 0010 0011 import org.kde.kirigami as Kirigami 0012 import org.kde.kirigamiaddons.formcard as FormCard 0013 import org.kde.kirigamiaddons.components as KirigamiComponents 0014 import org.kde.neochat 0015 0016 FormCard.FormCardPage { 0017 id: root 0018 0019 title: i18n("Edit Account") 0020 property NeoChatConnection connection 0021 0022 KirigamiComponents.AvatarButton { 0023 id: avatar 0024 0025 property OpenFileDialog fileDialog: null 0026 0027 Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter 0028 Layout.topMargin: Kirigami.Units.largeSpacing 0029 0030 // Square button 0031 implicitWidth: Kirigami.Units.gridUnit * 5 0032 implicitHeight: implicitWidth 0033 0034 padding: 0 0035 0036 source: root.connection && root.connection.localUser.avatarMediaId ? ("image://mxc/" + root.connection.localUser.avatarMediaId) : "" 0037 name: root.connection.localUser.displayName 0038 0039 onClicked: { 0040 if (fileDialog) { 0041 return; 0042 } 0043 fileDialog = openFileDialog.createObject(this); 0044 fileDialog.chosen.connect(receivedSource => { 0045 if (!receivedSource) { 0046 return; 0047 } 0048 source = receivedSource; 0049 }); 0050 fileDialog.open(); 0051 } 0052 0053 QQC2.Button { 0054 anchors { 0055 bottom: parent.bottom 0056 right: parent.right 0057 } 0058 visible: avatar.source.toString().length === 0 0059 icon.name: "cloud-upload" 0060 text: i18n("Upload new avatar") 0061 display: QQC2.AbstractButton.IconOnly 0062 0063 onClicked: parent.clicked() 0064 0065 QQC2.ToolTip.text: text 0066 QQC2.ToolTip.visible: hovered 0067 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay 0068 } 0069 0070 QQC2.Button { 0071 anchors { 0072 bottom: parent.bottom 0073 right: parent.right 0074 } 0075 visible: avatar.source.toString().length !== 0 0076 icon.name: "edit-clear" 0077 text: i18n("Remove current avatar") 0078 display: QQC2.AbstractButton.IconOnly 0079 0080 onClicked: avatar.source = "" 0081 0082 QQC2.ToolTip.text: text 0083 QQC2.ToolTip.visible: hovered 0084 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay 0085 } 0086 Component { 0087 id: openFileDialog 0088 0089 OpenFileDialog { 0090 currentFolder: StandardPaths.standardLocations(StandardPaths.PicturesLocation)[0] 0091 parentWindow: root.Window.window 0092 0093 onAccepted: destroy() 0094 onRejected: destroy() 0095 } 0096 } 0097 } 0098 0099 FormCard.FormHeader { 0100 title: i18n("User information") 0101 } 0102 FormCard.FormCard { 0103 FormCard.FormTextFieldDelegate { 0104 id: name 0105 label: i18n("Name:") 0106 text: root.connection ? root.connection.localUser.displayName : "" 0107 } 0108 FormCard.FormDelegateSeparator {} 0109 FormCard.FormTextFieldDelegate { 0110 id: accountLabel 0111 label: i18n("Label:") 0112 text: root.connection ? root.connection.label : "" 0113 } 0114 FormCard.FormDelegateSeparator {} 0115 FormCard.FormButtonDelegate { 0116 text: i18n("Save") 0117 onClicked: { 0118 if (!root.connection.setAvatar(avatar.source)) { 0119 showPassiveNotification("The Avatar could not be set"); 0120 } 0121 if (root.connection.localUser.displayName !== name.text) { 0122 root.connection.localUser.rename(name.text); 0123 } 0124 if (root.connection.label !== accountLabel.text) { 0125 root.connection.label = accountLabel.text; 0126 } 0127 } 0128 } 0129 } 0130 0131 FormCard.FormHeader { 0132 title: i18n("Password") 0133 } 0134 FormCard.FormCard { 0135 FormCard.FormTextDelegate { 0136 visible: root.connection !== undefined && root.connection.canChangePassword === false 0137 text: i18n("Your server doesn't support changing your password") 0138 } 0139 FormCard.FormDelegateSeparator { 0140 visible: root.connection !== undefined && root.connection.canChangePassword === false 0141 } 0142 FormCard.FormTextFieldDelegate { 0143 id: currentPassword 0144 label: i18n("Current Password:") 0145 enabled: root.connection !== undefined && root.connection.canChangePassword !== false 0146 echoMode: TextInput.Password 0147 } 0148 FormCard.FormDelegateSeparator {} 0149 FormCard.FormTextFieldDelegate { 0150 id: newPassword 0151 label: i18n("New Password:") 0152 enabled: root.connection !== undefined && root.connection.canChangePassword !== false 0153 echoMode: TextInput.Password 0154 } 0155 FormCard.FormDelegateSeparator {} 0156 FormCard.FormTextFieldDelegate { 0157 id: confirmPassword 0158 label: i18n("Confirm new Password:") 0159 enabled: root.connection !== undefined && root.connection.canChangePassword !== false 0160 echoMode: TextInput.Password 0161 onTextChanged: if (newPassword.text !== confirmPassword.text && confirmPassword.text.length > 0) { 0162 confirmPassword.status = FormCard.AbstractFormDelegate.Status.Error; 0163 confirmPassword.statusMessage = i18n("Passwords don't match"); 0164 } else { 0165 confirmPassword.status = FormCard.AbstractFormDelegate.Status.Default; 0166 confirmPassword.statusMessage = ''; 0167 } 0168 } 0169 FormCard.FormDelegateSeparator {} 0170 FormCard.FormButtonDelegate { 0171 text: i18n("Save") 0172 enabled: currentPassword.text.length > 0 && newPassword.text.length > 0 && confirmPassword.text.length > 0 0173 onClicked: { 0174 if (newPassword.text === confirmPassword.text) { 0175 root.connection.changePassword(currentPassword.text, newPassword.text); 0176 } else { 0177 showPassiveNotification(i18n("Passwords do not match")); 0178 } 0179 } 0180 } 0181 } 0182 0183 FormCard.FormHeader { 0184 Layout.fillWidth: true 0185 title: i18n("Server Information") 0186 } 0187 FormCard.FormCard { 0188 FormCard.FormTextDelegate { 0189 text: i18n("Homeserver url") 0190 description: root.connection.homeserver 0191 } 0192 0193 /* TODO but needs first some api in Quotient 0194 FormCard.FormTextDelegate { 0195 text: i18n("Server file upload limit") 0196 description: root.connection.homeserver 0197 } 0198 0199 FormCard.FormTextDelegate { 0200 text: i18n("Server name") 0201 description: root.connection.homeserver 0202 } 0203 0204 FormCard.FormTextDelegate { 0205 text: i18n("Server version") 0206 description: root.connection.homeserver 0207 }*/ 0208 } 0209 FormCard.FormHeader { 0210 title: i18nc("@title", "Account Management") 0211 } 0212 FormCard.FormCard { 0213 FormCard.FormButtonDelegate { 0214 id: deactivateAccountButton 0215 text: i18n("Deactivate Account") 0216 onClicked: pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/ConfirmDeactivateAccountDialog.qml", { 0217 connection: root.connection 0218 }, { 0219 title: i18nc("@title", "Confirm Deactivating Account") 0220 }) 0221 } 0222 } 0223 0224 data: Connections { 0225 target: root.connection 0226 function onPasswordStatus(status) { 0227 if (status === NeoChatConnection.Success) { 0228 showPassiveNotification(i18n("Password changed successfully")); 0229 } else if (status === NeoChatConnection.Wrong) { 0230 showPassiveNotification(i18n("Wrong password entered")); 0231 } else { 0232 showPassiveNotification(i18n("Unknown problem while trying to change password")); 0233 } 0234 } 0235 } 0236 }