2019-12-19 22:46:16 +11:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-09-10 04:42:58 +10:00
|
|
|
import QtQuick 2.12
|
|
|
|
import Qt.labs.platform 1.1
|
|
|
|
import "../Popups"
|
|
|
|
|
|
|
|
HFileDialogOpener {
|
|
|
|
fill: false
|
|
|
|
dialog.title: qsTr("Select a decryption keys file to import")
|
2019-11-06 23:55:47 +11:00
|
|
|
onFilePicked: {
|
2019-09-10 04:42:58 +10:00
|
|
|
importPasswordPopup.file = file
|
|
|
|
importPasswordPopup.open()
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
property string userId: ""
|
2019-11-24 02:14:14 +11:00
|
|
|
property bool importing: false
|
2019-09-10 04:42:58 +10:00
|
|
|
|
|
|
|
|
|
|
|
PasswordPopup {
|
|
|
|
id: importPasswordPopup
|
2020-03-18 04:40:58 +11:00
|
|
|
details.text: qsTr("Passphrase used to protect this file:")
|
2019-09-10 04:42:58 +10:00
|
|
|
okText: qsTr("Import")
|
|
|
|
|
|
|
|
|
|
|
|
property url file: ""
|
|
|
|
|
2019-11-30 20:50:56 +11:00
|
|
|
|
2019-09-10 04:42:58 +10:00
|
|
|
function verifyPassword(pass, callback) {
|
2020-03-08 19:46:20 +11:00
|
|
|
importing = true
|
|
|
|
const path = file.toString().replace(/^file:\/\//, "")
|
2019-11-30 20:50:56 +11:00
|
|
|
|
|
|
|
py.callClientCoro(userId, "import_keys", [path, pass], () => {
|
|
|
|
importing = false
|
|
|
|
callback(true)
|
|
|
|
|
2020-03-16 07:00:29 +11:00
|
|
|
}, (type, args, error, traceback, uuid) => {
|
|
|
|
let unknown = false
|
|
|
|
|
2019-11-30 20:50:56 +11:00
|
|
|
callback(
|
|
|
|
type === "EncryptionError" ?
|
|
|
|
false :
|
|
|
|
|
|
|
|
type === "ValueError" ?
|
|
|
|
qsTr("Invalid file format") :
|
|
|
|
|
|
|
|
type === "FileNotFoundError" ?
|
|
|
|
qsTr("This file doesn't exist") :
|
|
|
|
|
|
|
|
type === "IsADirectoryError" ?
|
|
|
|
qsTr("A folder was given, expecting a file") :
|
|
|
|
|
|
|
|
type === "PermissionError" ?
|
|
|
|
qsTr("No permission to read this file") :
|
|
|
|
|
2020-03-16 07:00:29 +11:00
|
|
|
(
|
|
|
|
unknown = true,
|
|
|
|
qsTr("Unknown error: %1 - %2").arg(type).arg(args)
|
|
|
|
)
|
2019-11-30 20:50:56 +11:00
|
|
|
)
|
2020-03-16 07:00:29 +11:00
|
|
|
|
|
|
|
if (unknown) utils.showError(type, traceback, uuid)
|
2019-11-30 20:50:56 +11:00
|
|
|
})
|
2019-09-10 04:42:58 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|