From 7c0bed79a9024221258a85fa9a721a9e90f40251 Mon Sep 17 00:00:00 2001 From: miruka Date: Mon, 9 Sep 2019 14:42:58 -0400 Subject: [PATCH] ImportKeys/ExportKeys separate dialog componants --- TODO.md | 1 + src/python/matrix_client.py | 4 +- src/qml/Dialogs/ExportKeys.qml | 39 ++++++++++ .../{Base => Dialogs}/HFileDialogOpener.qml | 0 src/qml/Dialogs/ImportKeys.qml | 42 ++++++++++ src/qml/Pages/EditAccount/Encryption.qml | 37 +-------- .../Pages/EditAccount/ImportExportKeys.qml | 78 ++++--------------- src/qml/Pages/EditAccount/ImportingKeys.qml | 5 +- src/qml/Pages/EditAccount/Profile.qml | 1 + 9 files changed, 109 insertions(+), 98 deletions(-) create mode 100644 src/qml/Dialogs/ExportKeys.qml rename src/qml/{Base => Dialogs}/HFileDialogOpener.qml (100%) create mode 100644 src/qml/Dialogs/ImportKeys.qml diff --git a/TODO.md b/TODO.md index cd3e78a5..a11910b5 100644 --- a/TODO.md +++ b/TODO.md @@ -33,6 +33,7 @@ - Show error if uploading avatar fails or file is corrupted - Way to open context menus without a right mouse button - Room header descriptions: styled text + - Indeterminate progress bar - Message selection - Copy to X11 selection diff --git a/src/python/matrix_client.py b/src/python/matrix_client.py index b2e1e3f1..31de70d9 100644 --- a/src/python/matrix_client.py +++ b/src/python/matrix_client.py @@ -324,13 +324,15 @@ class MatrixClient(nio.AsyncClient): account = self.models[Account][self.user_id] import_keys = partial(self.olm.import_keys_static, infile, passphrase) + account.importing_key = 0 + account.total_keys_to_import = -1 # preparing + try: sessions = await loop.run_in_executor(None, import_keys) except nio.EncryptionError as err: account.import_error = (infile, passphrase, str(err)) return - account.importing_key = 0 account.total_keys_to_import = len(sessions) for session in sessions: diff --git a/src/qml/Dialogs/ExportKeys.qml b/src/qml/Dialogs/ExportKeys.qml new file mode 100644 index 00000000..21b4194a --- /dev/null +++ b/src/qml/Dialogs/ExportKeys.qml @@ -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: "" + } +} diff --git a/src/qml/Base/HFileDialogOpener.qml b/src/qml/Dialogs/HFileDialogOpener.qml similarity index 100% rename from src/qml/Base/HFileDialogOpener.qml rename to src/qml/Dialogs/HFileDialogOpener.qml diff --git a/src/qml/Dialogs/ImportKeys.qml b/src/qml/Dialogs/ImportKeys.qml new file mode 100644 index 00000000..fe103b81 --- /dev/null +++ b/src/qml/Dialogs/ImportKeys.qml @@ -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 + ) + } + } +} diff --git a/src/qml/Pages/EditAccount/Encryption.qml b/src/qml/Pages/EditAccount/Encryption.qml index 47450ebf..11b02b8e 100644 --- a/src/qml/Pages/EditAccount/Encryption.qml +++ b/src/qml/Pages/EditAccount/Encryption.qml @@ -4,46 +4,13 @@ import "../../Base" HLoader { id: encryptionUI source: - accountInfo.import_error[0] ? "ImportError.qml" : - importing || accountInfo.total_keys_to_import ? "ImportingKeys.qml" : + accountInfo.import_error[0] ? "ImportError.qml" : + accountInfo.total_keys_to_import ? "ImportingKeys.qml" : "ImportExportKeys.qml" onSourceChanged: animation.running = true - property bool importing: false - - - function exportKeys(file, passphrase, button=null) { - if (button) button.loading = true - - let path = file.toString().replace(/^file:\/\//, "") - - py.callClientCoro( - editAccount.userId, "export_keys", [path, passphrase], () => { - // null: user is on another page - if (encryptionUI !== null && button) button.loading = false - } - ) - } - - function importKeys(file, passphrase, button=null) { - if (button) button.loading = true - encryptionUI.importing = true - - let path = file.toString().replace(/^file:\/\//, "") - - py.callClientCoro( - editAccount.userId, "import_keys", [path, passphrase], () => { - if (encryptionUI !== null) { - encryptionUI.importing = false - if (button) button.loading = false - } - } - ) - } - - SequentialAnimation { id: animation HNumberAnimation { diff --git a/src/qml/Pages/EditAccount/ImportExportKeys.qml b/src/qml/Pages/EditAccount/ImportExportKeys.qml index 5efc6af3..278ebeba 100644 --- a/src/qml/Pages/EditAccount/ImportExportKeys.qml +++ b/src/qml/Pages/EditAccount/ImportExportKeys.qml @@ -1,14 +1,9 @@ import QtQuick 2.12 -import QtQuick.Controls 2.12 import QtQuick.Layouts 1.12 -import Qt.labs.platform 1.1 import "../../Base" -import "../../Popups" import "../../utils.js" as Utils HBox { - property var exportButton: null - horizontalSpacing: currentSpacing verticalSpacing: currentSpacing @@ -19,10 +14,24 @@ HBox { buttonCallbacks: ({ export: button => { - exportButton = button - exportFileDialog.dialog.open() + Utils.makeObject( + "Dialogs/ExportKeys.qml", + editAccount, + { userId: editAccount.userId }, + obj => { + button.loading = Qt.binding(() => obj.exporting) + obj.dialog.open() + } + ) + }, + import: button => { + Utils.makeObject( + "Dialogs/ImportKeys.qml", + editAccount, + { userId: editAccount.userId }, + obj => { obj.dialog.open() } + ) }, - import: button => { importFileDialog.dialog.open() }, }) @@ -38,57 +47,4 @@ HBox { Layout.fillWidth: true } - - HFileDialogOpener { - id: exportFileDialog - fill: false - dialog.title: qsTr("Save decryption keys file as...") - dialog.fileMode: FileDialog.SaveFile - onFileChanged: { - exportPasswordPopup.file = file - exportPasswordPopup.open() - } - } - - HFileDialogOpener { - id: importFileDialog - fill: false - dialog.title: qsTr("Select a decryption keys file to import") - onFileChanged: { - importPasswordPopup.file = file - importPasswordPopup.open() - } - } - - PasswordPopup { - property url file: "" - - id: exportPasswordPopup - details.text: qsTr("Please enter a passphrase to protect this file:") - okText: qsTr("Export") - - onAcceptedPasswordChanged: - encryptionUI.exportKeys(file, acceptedPassword, exportButton) - } - - PasswordPopup { - property url file: "" - - function verifyPassword(pass, callback) { - py.callCoro( - "check_exported_keys_passphrase", - [file.toString().replace(/^file:\/\//, ""), pass], - callback - ) - } - - id: importPasswordPopup - details.text: qsTr( - "Please enter the passphrase that was used to protect this file:" - ) - okText: qsTr("Import") - - onAcceptedPasswordChanged: - encryptionUI.importKeys(file, acceptedPassword) - } } diff --git a/src/qml/Pages/EditAccount/ImportingKeys.qml b/src/qml/Pages/EditAccount/ImportingKeys.qml index 70b1e631..df6ca3e1 100644 --- a/src/qml/Pages/EditAccount/ImportingKeys.qml +++ b/src/qml/Pages/EditAccount/ImportingKeys.qml @@ -34,7 +34,9 @@ HColumnLayout { } HLabel { - text: qsTr("%1/%2") + text: progressBar.indeterminate ? + qsTr("Preparing...") : + qsTr("%1/%2") .arg(Math.ceil(progressBar.value)).arg(progressBar.to) Layout.margins: currentSpacing @@ -46,6 +48,7 @@ HColumnLayout { from: 0 value: progress to: accountInfo.total_keys_to_import + indeterminate: accountInfo.total_keys_to_import < 0 Behavior on value { HNumberAnimation { factor: 5 } } diff --git a/src/qml/Pages/EditAccount/Profile.qml b/src/qml/Pages/EditAccount/Profile.qml index 6760b6db..bcb29c63 100644 --- a/src/qml/Pages/EditAccount/Profile.qml +++ b/src/qml/Pages/EditAccount/Profile.qml @@ -2,6 +2,7 @@ import QtQuick 2.12 import QtQuick.Controls 2.12 import QtQuick.Layouts 1.12 import "../../Base" +import "../../Dialogs" import "../../utils.js" as Utils HGridLayout {