Port account editor to formcard

This commit is contained in:
Tobias Fella
2023-08-30 19:03:03 +02:00
parent a9965acdd3
commit 94c1b67ec9

View File

@@ -9,268 +9,211 @@ import Qt.labs.platform 1.1
import QtQuick.Window 2.15 import QtQuick.Window 2.15
import org.kde.kirigami 2.15 as Kirigami import org.kde.kirigami 2.15 as Kirigami
import org.kde.kirigamiaddons.labs.mobileform 0.1 as MobileForm import org.kde.kirigamiaddons.formcard 1.0 as FormCard
import org.kde.kirigamiaddons.labs.components 1.0 as KirigamiComponents import org.kde.kirigamiaddons.labs.components 1.0 as KirigamiComponents
import org.kde.neochat 1.0 import org.kde.neochat 1.0
Kirigami.ScrollablePage { FormCard.FormCardPage {
id: root id: root
title: i18n("Edit Account") title: i18n("Edit Account")
property NeoChatConnection connection property NeoChatConnection connection
readonly property bool compact: width > Kirigami.Units.gridUnit * 30 ? 2 : 1 QQC2.RoundButton {
property var fileDialog: null;
topPadding: 0 Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
leftPadding: 0 Layout.topMargin: Kirigami.Units.largeSpacing
rightPadding: 0
ColumnLayout {
spacing: 0
QQC2.RoundButton { // Square button
property var fileDialog: null; implicitWidth: Kirigami.Units.gridUnit * 5
implicitHeight: implicitWidth
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter padding: 0
Layout.topMargin: Kirigami.Units.largeSpacing
// Square button contentItem: KirigamiComponents.Avatar {
implicitWidth: Kirigami.Units.gridUnit * 5 id: avatar
implicitHeight: implicitWidth source: root.connection && root.connection.localUser.avatarMediaId ? ("image://mxc/" + root.connection.localUser.avatarMediaId) : ""
name: root.connection.localUser.displayName
}
padding: 0 onClicked: {
if (fileDialog != null) {
contentItem: KirigamiComponents.Avatar { return;
id: avatar
source: root.connection && root.connection.localUser.avatarMediaId ? ("image://mxc/" + root.connection.localUser.avatarMediaId) : ""
name: root.connection.localUser.displayName
} }
onClicked: { fileDialog = openFileDialog.createObject(QQC2.ApplicationWindow.Overlay)
if (fileDialog != null) { fileDialog.chosen.connect(function(receivedSource) {
if (!receivedSource) {
return; return;
} }
avatar.source = receivedSource;
});
fileDialog.onRejected.connect(function() {
mouseArea.fileDialog = null;
});
fileDialog.open();
}
fileDialog = openFileDialog.createObject(QQC2.ApplicationWindow.Overlay) QQC2.Button {
fileDialog.chosen.connect(function(receivedSource) { anchors {
if (!receivedSource) { bottom: parent.bottom
return; right: parent.right
}
avatar.source = receivedSource;
});
fileDialog.onRejected.connect(function() {
mouseArea.fileDialog = null;
});
fileDialog.open();
} }
visible: avatar.source.toString().length === 0
icon.name: "cloud-upload"
text: i18n("Upload new avatar")
display: QQC2.AbstractButton.IconOnly
QQC2.Button { onClicked: parent.onClicked()
anchors {
bottom: parent.bottom
right: parent.right
}
visible: avatar.source.toString().length === 0
icon.name: "cloud-upload"
text: i18n("Upload new avatar")
display: QQC2.AbstractButton.IconOnly
onClicked: parent.onClicked() QQC2.ToolTip.text: text
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}
QQC2.ToolTip.text: text QQC2.Button {
QQC2.ToolTip.visible: hovered anchors {
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay bottom: parent.bottom
right: parent.right
} }
visible: avatar.source.toString().length !== 0
icon.name: "edit-clear"
text: i18n("Remove current avatar")
display: QQC2.AbstractButton.IconOnly
QQC2.Button { onClicked: avatar.source = ""
anchors {
bottom: parent.bottom
right: parent.right
}
visible: avatar.source.toString().length !== 0
icon.name: "edit-clear"
text: i18n("Remove current avatar")
display: QQC2.AbstractButton.IconOnly
onClicked: avatar.source = "" QQC2.ToolTip.text: text
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}
Component {
id: openFileDialog
QQC2.ToolTip.text: text OpenFileDialog {
QQC2.ToolTip.visible: hovered folder: StandardPaths.writableLocation(StandardPaths.PicturesLocation)
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay parentWindow: root.Window.window
} }
} }
}
MobileForm.FormHeader { FormCard.FormHeader {
Layout.fillWidth: true title: i18n("User information")
title: i18n("User information") }
FormCard.FormCard {
FormCard.FormTextFieldDelegate {
id: name
label: i18n("Name:")
text: root.connection ? root.connection.localUser.displayName : ""
} }
MobileForm.FormCard { FormCard.FormDelegateSeparator {}
Layout.fillWidth: true FormCard.FormTextFieldDelegate {
contentItem: ColumnLayout { id: accountLabel
spacing: 0 label: i18n("Label:")
MobileForm.FormTextFieldDelegate { text: root.connection ? root.connection.label : ""
id: name
label: i18n("Name:")
text: root.connection ? root.connection.localUser.displayName : ""
}
MobileForm.FormDelegateSeparator {}
MobileForm.FormTextFieldDelegate {
id: accountLabel
label: i18n("Label:")
text: root.connection ? root.connection.label : ""
}
MobileForm.FormDelegateSeparator {}
MobileForm.AbstractFormDelegate {
Layout.fillWidth: true
background: null
padding: Kirigami.Units.smallSpacing
contentItem: RowLayout {
Item {
Layout.fillWidth: true
}
QQC2.Button {
text: i18n("Save")
Layout.bottomMargin: Kirigami.Units.smallSpacing
Layout.topMargin: Kirigami.Units.smallSpacing
onClicked: {
if (!root.connection.setAvatar(avatar.source)) {
showPassiveNotification("The Avatar could not be set");
}
if (root.connection.localUser.displayName !== name.text) {
root.connection.localUser.rename(name.text);
}
if (root.connection.label !== accountLabel.text) {
root.connection.label = accountLabel.text;
}
}
}
}
}
}
} }
FormCard.FormDelegateSeparator {}
MobileForm.FormHeader { FormCard.FormButtonDelegate {
Layout.fillWidth: true text: i18n("Save")
title: i18n("Password") onClicked: {
} if (!root.connection.setAvatar(avatar.source)) {
MobileForm.FormCard { showPassiveNotification("The Avatar could not be set");
Layout.fillWidth: true
contentItem: ColumnLayout {
spacing: 0
MobileForm.FormTextDelegate {
visible: root.connection !== undefined && root.connection.canChangePassword === false
text: i18n("Your server doesn't support changing your password")
} }
MobileForm.FormDelegateSeparator { visible: root.connection !== undefined && root.connection.canChangePassword === false } if (root.connection.localUser.displayName !== name.text) {
MobileForm.FormTextFieldDelegate { root.connection.localUser.rename(name.text);
id: currentPassword
label: i18n("Current Password:")
enabled: root.connection !== undefined && root.connection.canChangePassword !== false
echoMode: TextInput.Password
} }
MobileForm.FormDelegateSeparator {} if (root.connection.label !== accountLabel.text) {
MobileForm.FormTextFieldDelegate { root.connection.label = accountLabel.text;
id: newPassword
label: i18n("New Password:")
enabled: root.connection !== undefined && root.connection.canChangePassword !== false
echoMode: TextInput.Password
}
MobileForm.FormDelegateSeparator {}
MobileForm.FormTextFieldDelegate {
id: confirmPassword
label: i18n("Confirm new Password:")
enabled: root.connection !== undefined && root.connection.canChangePassword !== false
echoMode: TextInput.Password
onTextChanged: if (newPassword.text !== confirmPassword.text && confirmPassword.text.length > 0) {
confirmPassword.status = MobileForm.AbstractFormDelegate.Status.Error;
confirmPassword.statusMessage = i18n("Passwords don't match");
} else {
confirmPassword.status = MobileForm.AbstractFormDelegate.Status.Default;
confirmPassword.statusMessage = '';
}
}
MobileForm.FormDelegateSeparator {}
MobileForm.AbstractFormDelegate {
Layout.fillWidth: true
background: null
contentItem: RowLayout {
Item {
Layout.fillWidth: true
}
QQC2.Button {
text: i18n("Save")
Layout.bottomMargin: Kirigami.Units.smallSpacing
Layout.topMargin: Kirigami.Units.smallSpacing
enabled: currentPassword.text.length > 0 && newPassword.text.length > 0 && confirmPassword.text.length > 0
onClicked: {
if (newPassword.text === confirmPassword.text) {
root.connection.changePassword(currentPassword.text, newPassword.text);
} else {
showPassiveNotification(i18n("Passwords do not match"));
}
}
}
QQC2.Button {
text: i18n("Cancel")
Layout.rightMargin: Kirigami.Units.smallSpacing
Layout.bottomMargin: Kirigami.Units.smallSpacing
Layout.topMargin: Kirigami.Units.smallSpacing
onClicked: root.closeDialog();
}
}
}
}
}
MobileForm.FormHeader {
Layout.fillWidth: true
title: i18n("Server Information")
}
MobileForm.FormCard {
Layout.fillWidth: true
contentItem: ColumnLayout {
spacing: 0
MobileForm.FormTextDelegate {
text: i18n("Homeserver url")
description: root.connection.homeserver
}
/** TODO but needs first some api in Quotient
MobileForm.FormTextDelegate {
text: i18n("Server file upload limit")
description: root.connection.homeserver
}
MobileForm.FormTextDelegate {
text: i18n("Server name")
description: root.connection.homeserver
}
MobileForm.FormTextDelegate {
text: i18n("Server version")
description: root.connection.homeserver
}*/
}
}
MobileForm.FormHeader {
Layout.fillWidth: true
title: i18nc("@title", "Account Management")
}
MobileForm.FormCard {
Layout.fillWidth: true
contentItem: ColumnLayout {
spacing: 0
MobileForm.FormButtonDelegate {
id: deactivateAccountButton
text: i18n("Deactivate Account")
onClicked: pageStack.pushDialogLayer("qrc:/ConfirmDeactivateAccountDialog.qml", {connection: root.connection}, {title: i18nc("@title", "Confirm Deactivating Account")})
} }
} }
} }
} }
Component {
id: openFileDialog
OpenFileDialog { FormCard.FormHeader {
folder: StandardPaths.writableLocation(StandardPaths.PicturesLocation) title: i18n("Password")
parentWindow: root.Window.window }
FormCard.FormCard {
FormCard.FormTextDelegate {
visible: root.connection !== undefined && root.connection.canChangePassword === false
text: i18n("Your server doesn't support changing your password")
}
FormCard.FormDelegateSeparator { visible: root.connection !== undefined && root.connection.canChangePassword === false }
FormCard.FormTextFieldDelegate {
id: currentPassword
label: i18n("Current Password:")
enabled: root.connection !== undefined && root.connection.canChangePassword !== false
echoMode: TextInput.Password
}
FormCard.FormDelegateSeparator {}
FormCard.FormTextFieldDelegate {
id: newPassword
label: i18n("New Password:")
enabled: root.connection !== undefined && root.connection.canChangePassword !== false
echoMode: TextInput.Password
}
FormCard.FormDelegateSeparator {}
FormCard.FormTextFieldDelegate {
id: confirmPassword
label: i18n("Confirm new Password:")
enabled: root.connection !== undefined && root.connection.canChangePassword !== false
echoMode: TextInput.Password
onTextChanged: if (newPassword.text !== confirmPassword.text && confirmPassword.text.length > 0) {
confirmPassword.status = FormCard.AbstractFormDelegate.Status.Error;
confirmPassword.statusMessage = i18n("Passwords don't match");
} else {
confirmPassword.status = FormCard.AbstractFormDelegate.Status.Default;
confirmPassword.statusMessage = '';
}
}
FormCard.FormDelegateSeparator {}
FormCard.FormButtonDelegate {
text: i18n("Save")
enabled: currentPassword.text.length > 0 && newPassword.text.length > 0 && confirmPassword.text.length > 0
onClicked: {
if (newPassword.text === confirmPassword.text) {
root.connection.changePassword(currentPassword.text, newPassword.text);
} else {
showPassiveNotification(i18n("Passwords do not match"));
}
}
}
}
FormCard.FormHeader {
Layout.fillWidth: true
title: i18n("Server Information")
}
FormCard.FormCard {
FormCard.FormTextDelegate {
text: i18n("Homeserver url")
description: root.connection.homeserver
}
/* TODO but needs first some api in Quotient
FormCard.FormTextDelegate {
text: i18n("Server file upload limit")
description: root.connection.homeserver
}
FormCard.FormTextDelegate {
text: i18n("Server name")
description: root.connection.homeserver
}
FormCard.FormTextDelegate {
text: i18n("Server version")
description: root.connection.homeserver
}*/
}
FormCard.FormHeader {
title: i18nc("@title", "Account Management")
}
FormCard.FormCard {
FormCard.FormButtonDelegate {
id: deactivateAccountButton
text: i18n("Deactivate Account")
onClicked: pageStack.pushDialogLayer("qrc:/ConfirmDeactivateAccountDialog.qml", {connection: root.connection}, {title: i18nc("@title", "Confirm Deactivating Account")})
} }
} }
} }