Add decryption keys import in account settings

This commit is contained in:
miruka
2019-07-25 02:43:52 -04:00
parent 93a6867735
commit 858c9f337d
12 changed files with 236 additions and 36 deletions

View File

@@ -13,7 +13,7 @@ Item {
property string file: ""
enum FileType { All, Images }
property int fileType: FileType.All
property int fileType: HFileDialogOpener.FileType.All
TapHandler { onTapped: fileDialog.open() }

View File

@@ -0,0 +1,55 @@
// Copyright 2019 miruka
// This file is part of harmonyqml, licensed under LGPLv3.
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import "../SidePane"
Popup {
id: popup
width: window.width
anchors.centerIn: Overlay.overlay
modal: true
onOpened: passwordField.forceActiveFocus()
property alias label: popupLabel
property alias field: passwordField
property string password: ""
background: HRectangle {
color: theme.controls.popup.background
}
HColumnLayout {
width: parent.width
spacing: theme.spacing
HLabel {
id: popupLabel
wrapMode: Text.Wrap
Layout.alignment: Qt.AlignCenter
Layout.minimumWidth: theme.minimumSupportedWidth
Layout.maximumWidth:
Math.min(480, window.width - theme.spacing * 2)
}
HTextField {
id: passwordField
echoMode: TextInput.Password
focus: true
onAccepted: {
popup.password = text
popup.close()
}
Layout.alignment: Qt.AlignCenter
Layout.fillWidth: true
Layout.preferredWidth: popupLabel.width
Layout.maximumWidth: popupLabel.width
}
}
}

View File

@@ -1,12 +0,0 @@
// Copyright 2019 miruka
// This file is part of harmonyqml, licensed under LGPLv3.
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import "../../Base"
import "../../utils.js" as Utils
HLabel {
text: "Client - TODO"
}

View File

@@ -1,12 +0,0 @@
// Copyright 2019 miruka
// This file is part of harmonyqml, licensed under LGPLv3.
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import "../../Base"
import "../../utils.js" as Utils
HLabel {
text: "Devices - TODO"
}

View File

@@ -24,21 +24,32 @@ HPage {
Utils.coloredNameHtml(headerName, userId)
)
HRectangle {
color: ready ? theme.controls.box.background : "transparent"
Behavior on color { HColorAnimation {} }
HSpacer {}
Layout.alignment: Qt.AlignCenter
Repeater {
model: ["Profile.qml", "Encryption.qml"]
Layout.maximumWidth: Math.min(parent.width, 640)
Layout.preferredWidth:
pageStack.isWide ? parent.width : avatarPreferredSize
HRectangle {
color: ready ? theme.controls.box.background : "transparent"
Behavior on color { HColorAnimation {} }
Layout.preferredHeight: childrenRect.height
Layout.alignment: Qt.AlignCenter
Loader {
width: parent.width
source: ready ? "Profile.qml" : "../../Base/HBusyIndicator.qml"
Layout.maximumWidth: Math.min(parent.width, 640)
Layout.preferredWidth:
pageStack.isWide ? parent.width : avatarPreferredSize
Layout.preferredHeight: childrenRect.height
Loader {
width: parent.width
source: ready ?
modelData :
(modelData == "Profile.qml" ?
"../../Base/HBusyIndicator.qml" : "")
}
}
}
HSpacer {}
}

View File

@@ -0,0 +1,79 @@
// Copyright 2019 miruka
// This file is part of harmonyqml, licensed under LGPLv3.
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import "../../Base"
import "../../utils.js" as Utils
HColumnLayout {
function importKeys(file, passphrase) {
importButton.loading = true
let path = Qt.resolvedUrl(file).replace(/^file:\/\//, "")
py.callClientCoro(
editAccount.userId, "import_keys", [path, passphrase], () => {
importButton.loading = false
}
)
}
HLabel {
wrapMode: Text.Wrap
text: qsTr(
"The decryption keys for the messages you received in " +
"encrypted rooms can be exported to a file.%1" +
"You will then be able to import this file in another " +
"Matrix client."
).arg(pageStack.isWide ? "\n" :"\n\n")
Layout.fillWidth: true
Layout.margins: currentSpacing
}
HRowLayout {
HUIButton {
id: exportButton
iconName: "export-keys"
text: qsTr("Export")
enabled: false
Layout.fillWidth: true
Layout.alignment: Qt.AlignBottom
}
HUIButton {
id: importButton
iconName: "import-keys"
text: qsTr("Import")
Layout.fillWidth: true
Layout.alignment: Qt.AlignBottom
HFileDialogOpener {
id: fileDialog
dialog.title: qsTr("Select a decryption key file to import")
onFileChanged: {
importPasswordPopup.file = file
importPasswordPopup.open()
}
}
}
}
HPasswordPopup {
property url file: ""
id: importPasswordPopup
label.text: qsTr(
"Please enter the passphrase that was used to protect this " +
"file.\n\n" +
"The import can take a few minutes. " +
"You can leave the account settings page while it is running. " +
"Messages may not be sent or received until the operation is done."
)
onPasswordChanged: importKeys(file, password)
}
}