Show import keys error in the UI

This commit is contained in:
miruka
2019-08-28 11:42:52 -04:00
parent 7d2cbae26f
commit ce3404a516
8 changed files with 84 additions and 35 deletions

View File

@@ -2,18 +2,39 @@ import QtQuick 2.12
import "../../Base"
HLoader {
id: loader
source: accountInfo.total_keys_to_import ?
"ImportingKeys.qml" : "ImportExportKeys.qml"
property bool importing: false
function importKeys(file, passphrase, button=null) {
if (button) button.loading = true
importing = true
let path = file.toString().replace(/^file:\/\//, "")
py.callClientCoro(
editAccount.userId, "import_keys", [path, passphrase], () => {
importing = false
if (button) button.loading = false
}
)
}
id: encryptionUI
source:
accountInfo.import_error[0] ? "ImportError.qml" :
importing || accountInfo.total_keys_to_import ? "ImportingKeys.qml" :
"ImportExportKeys.qml"
onSourceChanged: animation.running = true
HNumberAnimation {
SequentialAnimation {
id: animation
target: loader.item
property: "scale"
from: 0
to: 1
overshoot: 3
HNumberAnimation {
target: encryptionUI; property: "scale"; to: 0;
}
HNumberAnimation {
target: encryptionUI; property: "scale"; to: 1; overshoot: 3;
}
}
}

View File

@@ -0,0 +1,33 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import "../../Base"
import "../../utils.js" as Utils
HInterfaceBox {
buttonModel: [
{ name: "retry", text: qsTr("Retry"), iconName: "retry" },
{ name: "cancel", text: qsTr("Cancel"), iconName: "cancel" },
]
buttonCallbacks: ({
retry: button => {
encryptionUI.importKeys(
accountInfo.import_error[0],
accountInfo.import_error[1],
button,
)
},
cancel: button => { py.callClientCoro(userId, "clear_import_error") },
})
HLabel {
color: theme.colors.errorText
wrapMode: Text.Wrap
text: qsTr("Couldn't import decryption keys file: %1")
.arg(qsTr(accountInfo.import_error[2]))
Layout.fillWidth: true
}
}

View File

@@ -5,18 +5,6 @@ import "../../Base"
import "../../utils.js" as Utils
HColumnLayout {
function importKeys(file, passphrase) {
importButton.loading = true
let path = file.toString().replace(/^file:\/\//, "")
py.callClientCoro(
editAccount.userId, "import_keys", [path, passphrase], () => {
if (importButton) importButton.loading = false
}
)
}
HLabel {
wrapMode: Text.Wrap
text: qsTr(
@@ -75,6 +63,7 @@ HColumnLayout {
label.text: qsTr(
"Please enter the passphrase that was used to protect this file:"
)
onAcceptedPasswordChanged: importKeys(file, acceptedPassword)
onAcceptedPasswordChanged:
encryptionUI.importKeys(file, acceptedPassword, importButton)
}
}