From 92e92557fade1ba3567764c0b9fb32a2aae3760c Mon Sep 17 00:00:00 2001 From: Johan Ouwerkerk Date: Tue, 6 Oct 2020 23:29:20 +0200 Subject: [PATCH] feat: add a page to recover when an account turns out to be already used while adding it This page is a bit of a bodge for the fact that the current Accounts model must be 'unlocked' before it can be used. In turn, this means that it is not straightforward to check that an account is still 'available' when presenting the user with the option to add an account received via URI from the commandline. The solution implemented here is to check and let the user recover after unlocking, if necessary. Issues: #7, #14 --- src/contents/ui/RenameAccount.qml | 65 +++++++++++++++++++++++++++++++++++++++ src/resources.qrc | 1 + 2 files changed, 66 insertions(+) create mode 100644 src/contents/ui/RenameAccount.qml diff --git a/src/contents/ui/RenameAccount.qml b/src/contents/ui/RenameAccount.qml new file mode 100644 index 0000000..fa116c8 --- /dev/null +++ b/src/contents/ui/RenameAccount.qml @@ -0,0 +1,65 @@ +/* + * SPDX-License-Identifier: GPL-3.0-or-later + * SPDX-FileCopyrightText: 2020 Johan Ouwerkerk + */ + +import QtQuick 2.1 +import QtQuick.Layouts 1.2 +import QtQuick.Controls 2.0 as Controls +import org.kde.kirigami 2.8 as Kirigami + +import Keysmith.Application 1.0 +import Keysmith.Models 1.0 as Models +import Keysmith.Validators 1.0 as Validators + +Kirigami.Page { + id: root + title: i18nc("@title:window", "Rename account to add") + signal cancelled + signal newAccount(var input) + property bool quitEnabled: false + property Models.AccountListModel accounts: Keysmith.accountListModel() + + property bool acceptable: accountName.acceptable + property Models.ValidatedAccountInput validatedInput: Models.ValidatedAccountInput {} + + Connections { + target: validatedInput + onTypeChanged: { + root.detailsEnabled = false; + } + } + + ColumnLayout { + anchors { + horizontalCenter: parent.horizontalCenter + } + Controls.Label { + text:i18nc("@info:label Keysmith received an account to add via URI on e.g. commandline which is already in use", "Another account with the same name already exists. Please correct the name or issuer for the new account.") + color: Kirigami.Theme.negativeTextColor + Layout.maximumWidth: root.width - 2 * Kirigami.Units.largeSpacing + wrapMode: Text.WordWrap + } + AccountNameForm { + id: accountName + validateAccountAvailability: true + validatedInput: root.validatedInput + } + } + + actions.left: Kirigami.Action { + text: i18nc("@action:button cancel and dismiss the rename account form", "Cancel") + iconName: "edit-undo" + onTriggered: { + root.cancelled(); + } + } + actions.main: Kirigami.Action { + text: i18n("Add") + iconName: "answer-correct" + enabled: acceptable + onTriggered: { + root.newAccount(root.validatedInput); + } + } +} diff --git a/src/resources.qrc b/src/resources.qrc index 7cfdaad..72e9629 100644 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -9,6 +9,7 @@ contents/ui/AccountsOverview.qml contents/ui/AddAccount.qml contents/ui/ErrorPage.qml + contents/ui/RenameAccount.qml contents/ui/AccountNameForm.qml contents/ui/HOTPDetailsForm.qml contents/ui/TOTPDetailsForm.qml