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 
0044             fileDialog = openFileDialog.createObject(this);
0045             fileDialog.chosen.connect((receivedSource) => {
0046                 if (!receivedSource) {
0047                     return;
0048                 }
0049                 source = receivedSource;
0050             });
0051             fileDialog.open();
0052         }
0053 
0054         QQC2.Button {
0055             anchors {
0056                 bottom: parent.bottom
0057                 right: parent.right
0058             }
0059             visible: avatar.source.toString().length === 0
0060             icon.name: "cloud-upload"
0061             text: i18n("Upload new avatar")
0062             display: QQC2.AbstractButton.IconOnly
0063 
0064             onClicked: parent.clicked()
0065 
0066             QQC2.ToolTip.text: text
0067             QQC2.ToolTip.visible: hovered
0068             QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0069         }
0070 
0071         QQC2.Button {
0072             anchors {
0073                 bottom: parent.bottom
0074                 right: parent.right
0075             }
0076             visible: avatar.source.toString().length !== 0
0077             icon.name: "edit-clear"
0078             text: i18n("Remove current avatar")
0079             display: QQC2.AbstractButton.IconOnly
0080 
0081             onClicked: avatar.source = ""
0082 
0083             QQC2.ToolTip.text: text
0084             QQC2.ToolTip.visible: hovered
0085             QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0086         }
0087         Component {
0088             id: openFileDialog
0089 
0090             OpenFileDialog {
0091                 currentFolder: StandardPaths.standardLocations(StandardPaths.PicturesLocation)[0]
0092                 parentWindow: root.Window.window
0093 
0094                 onAccepted: destroy()
0095                 onRejected: destroy()
0096             }
0097         }
0098     }
0099 
0100     FormCard.FormHeader {
0101         title: i18n("User information")
0102     }
0103     FormCard.FormCard {
0104         FormCard.FormTextFieldDelegate {
0105             id: name
0106             label: i18n("Name:")
0107             text: root.connection ? root.connection.localUser.displayName : ""
0108         }
0109         FormCard.FormDelegateSeparator {}
0110         FormCard.FormTextFieldDelegate {
0111             id: accountLabel
0112             label: i18n("Label:")
0113             text: root.connection ? root.connection.label : ""
0114         }
0115         FormCard.FormDelegateSeparator {}
0116         FormCard.FormButtonDelegate {
0117             text: i18n("Save")
0118             onClicked: {
0119                 if (!root.connection.setAvatar(avatar.source)) {
0120                     showPassiveNotification("The Avatar could not be set");
0121                 }
0122                 if (root.connection.localUser.displayName !== name.text) {
0123                     root.connection.localUser.rename(name.text);
0124                 }
0125                 if (root.connection.label !== accountLabel.text) {
0126                     root.connection.label = accountLabel.text;
0127                 }
0128             }
0129         }
0130     }
0131 
0132     FormCard.FormHeader {
0133         title: i18n("Password")
0134     }
0135     FormCard.FormCard {
0136         FormCard.FormTextDelegate {
0137             visible: root.connection !== undefined && root.connection.canChangePassword === false
0138             text: i18n("Your server doesn't support changing your password")
0139         }
0140         FormCard.FormDelegateSeparator { visible: root.connection !== undefined && root.connection.canChangePassword === false }
0141         FormCard.FormTextFieldDelegate {
0142             id: currentPassword
0143             label: i18n("Current Password:")
0144             enabled: root.connection !== undefined && root.connection.canChangePassword !== false
0145             echoMode: TextInput.Password
0146         }
0147         FormCard.FormDelegateSeparator {}
0148         FormCard.FormTextFieldDelegate {
0149             id: newPassword
0150             label: i18n("New Password:")
0151             enabled: root.connection !== undefined && root.connection.canChangePassword !== false
0152             echoMode: TextInput.Password
0153         }
0154         FormCard.FormDelegateSeparator {}
0155         FormCard.FormTextFieldDelegate {
0156             id: confirmPassword
0157             label: i18n("Confirm new Password:")
0158             enabled: root.connection !== undefined && root.connection.canChangePassword !== false
0159             echoMode: TextInput.Password
0160             onTextChanged: if (newPassword.text !== confirmPassword.text && confirmPassword.text.length > 0) {
0161                 confirmPassword.status = FormCard.AbstractFormDelegate.Status.Error;
0162                 confirmPassword.statusMessage = i18n("Passwords don't match");
0163             } else {
0164                 confirmPassword.status = FormCard.AbstractFormDelegate.Status.Default;
0165                 confirmPassword.statusMessage = '';
0166             }
0167         }
0168         FormCard.FormDelegateSeparator {}
0169         FormCard.FormButtonDelegate {
0170             text: i18n("Save")
0171             enabled: currentPassword.text.length > 0 && newPassword.text.length > 0 && confirmPassword.text.length > 0
0172             onClicked: {
0173                 if (newPassword.text === confirmPassword.text) {
0174                     root.connection.changePassword(currentPassword.text, newPassword.text);
0175                 } else {
0176                     showPassiveNotification(i18n("Passwords do not match"));
0177                 }
0178             }
0179         }
0180     }
0181 
0182     FormCard.FormHeader {
0183         Layout.fillWidth: true
0184         title: i18n("Server Information")
0185     }
0186     FormCard.FormCard {
0187         FormCard.FormTextDelegate {
0188             text: i18n("Homeserver url")
0189             description: root.connection.homeserver
0190         }
0191 
0192         /* TODO but needs first some api in Quotient
0193         FormCard.FormTextDelegate {
0194             text: i18n("Server file upload limit")
0195             description: root.connection.homeserver
0196         }
0197 
0198         FormCard.FormTextDelegate {
0199             text: i18n("Server name")
0200             description: root.connection.homeserver
0201         }
0202 
0203         FormCard.FormTextDelegate {
0204             text: i18n("Server version")
0205             description: root.connection.homeserver
0206         }*/
0207     }
0208     FormCard.FormHeader {
0209         title: i18nc("@title", "Account Management")
0210     }
0211     FormCard.FormCard {
0212         FormCard.FormButtonDelegate {
0213             id: deactivateAccountButton
0214             text: i18n("Deactivate Account")
0215             onClicked: pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/ConfirmDeactivateAccountDialog.qml", {connection: root.connection}, {title: i18nc("@title", "Confirm Deactivating Account")})
0216         }
0217     }
0218 
0219     data: Connections {
0220         target: root.connection
0221         function onPasswordStatus(status) {
0222             if (status === NeoChatConnection.Success) {
0223                 showPassiveNotification(i18n("Password changed successfully"));
0224             } else if (status === NeoChatConnection.Wrong) {
0225                 showPassiveNotification(i18n("Wrong password entered"));
0226             } else {
0227                 showPassiveNotification(i18n("Unknown problem while trying to change password"));
0228             }
0229         }
0230     }
0231 }