ImportKeys/ExportKeys separate dialog componants
This commit is contained in:
39
src/qml/Dialogs/ExportKeys.qml
Normal file
39
src/qml/Dialogs/ExportKeys.qml
Normal file
@@ -0,0 +1,39 @@
|
||||
import QtQuick 2.12
|
||||
import Qt.labs.platform 1.1
|
||||
import "../Popups"
|
||||
|
||||
HFileDialogOpener {
|
||||
fill: false
|
||||
dialog.title: qsTr("Save decryption keys file as...")
|
||||
dialog.fileMode: FileDialog.SaveFile
|
||||
onFileChanged: {
|
||||
exportPasswordPopup.file = file
|
||||
exportPasswordPopup.open()
|
||||
}
|
||||
|
||||
|
||||
property string userId: ""
|
||||
property bool exporting: false
|
||||
|
||||
|
||||
function exportKeys(file, passphrase) {
|
||||
exporting = true
|
||||
|
||||
let path = file.toString().replace(/^file:\/\//, "")
|
||||
|
||||
py.callClientCoro(userId, "export_keys", [path, passphrase], () => {
|
||||
exporting = false
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
PasswordPopup {
|
||||
id: exportPasswordPopup
|
||||
details.text: qsTr("Please enter a passphrase to protect this file:")
|
||||
okText: qsTr("Export")
|
||||
|
||||
onAcceptedPasswordChanged: exportKeys(file, acceptedPassword)
|
||||
|
||||
property url file: ""
|
||||
}
|
||||
}
|
49
src/qml/Dialogs/HFileDialogOpener.qml
Normal file
49
src/qml/Dialogs/HFileDialogOpener.qml
Normal file
@@ -0,0 +1,49 @@
|
||||
import QtQuick 2.12
|
||||
import Qt.labs.platform 1.1
|
||||
|
||||
Item {
|
||||
id: opener
|
||||
anchors.fill: fill ? parent : undefined
|
||||
|
||||
property bool fill: true
|
||||
|
||||
property alias dialog: fileDialog
|
||||
property string selectedFile: ""
|
||||
property string file: ""
|
||||
|
||||
enum FileType { All, Images }
|
||||
property int fileType: HFileDialogOpener.FileType.All
|
||||
|
||||
TapHandler { enabled: fill; onTapped: fileDialog.open() }
|
||||
|
||||
FileDialog {
|
||||
id: fileDialog
|
||||
|
||||
property var filters: ({
|
||||
all: qsTr("All files") + " (*)",
|
||||
images: qsTr("Image files") +
|
||||
" (*.jpg *.jpeg *.png *.gif *.bmp *.webp)"
|
||||
})
|
||||
|
||||
nameFilters:
|
||||
fileType == HFileDialogOpener.FileType.Images ?
|
||||
[filters.images, filters.all] :
|
||||
[filters.all]
|
||||
|
||||
folder: StandardPaths.writableLocation(
|
||||
fileType == HFileDialogOpener.FileType.Images ?
|
||||
StandardPaths.PicturesLocation :
|
||||
StandardPaths.HomeLocation
|
||||
)
|
||||
|
||||
title: "Select file"
|
||||
modality: Qt.NonModal
|
||||
|
||||
onVisibleChanged: if (visible) {
|
||||
opener.selectedFile = Qt.binding(() => Qt.resolvedUrl(currentFile))
|
||||
opener.file = Qt.binding(() => Qt.resolvedUrl(file))
|
||||
}
|
||||
onAccepted: { opener.selectedFile = currentFile, opener.file = file }
|
||||
onRejected: { selectedFile = ""; file = ""}
|
||||
}
|
||||
}
|
42
src/qml/Dialogs/ImportKeys.qml
Normal file
42
src/qml/Dialogs/ImportKeys.qml
Normal file
@@ -0,0 +1,42 @@
|
||||
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")
|
||||
onFileChanged: {
|
||||
importPasswordPopup.file = file
|
||||
importPasswordPopup.open()
|
||||
}
|
||||
|
||||
|
||||
property string userId: ""
|
||||
|
||||
|
||||
function importKeys(file, passphrase) {
|
||||
let path = file.toString().replace(/^file:\/\//, "")
|
||||
py.callClientCoro(userId, "import_keys", [path, passphrase])
|
||||
}
|
||||
|
||||
|
||||
PasswordPopup {
|
||||
id: importPasswordPopup
|
||||
details.text: qsTr(
|
||||
"Please enter the passphrase that was used to protect this file:"
|
||||
)
|
||||
okText: qsTr("Import")
|
||||
|
||||
onAcceptedPasswordChanged: importKeys(file, acceptedPassword)
|
||||
|
||||
property url file: ""
|
||||
|
||||
function verifyPassword(pass, callback) {
|
||||
py.callCoro(
|
||||
"check_exported_keys_passphrase",
|
||||
[file.toString().replace(/^file:\/\//, ""), pass],
|
||||
callback
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user