From 6229d7abbe9bd7edcb3e917f2e75229102c4b3af Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Fri, 22 Nov 2019 13:10:50 +0100 Subject: [PATCH] Updated password and recovery key instructions --- .../CreateNewVaultRecoveryKeyController.java | 59 ++++++++++++++++++- .../resources/fxml/addvault_new_password.fxml | 6 +- .../fxml/addvault_new_recoverykey.fxml | 16 +++-- .../main/resources/i18n/strings.properties | 7 ++- 4 files changed, 78 insertions(+), 10 deletions(-) diff --git a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultRecoveryKeyController.java b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultRecoveryKeyController.java index 4c38f1250..6249a9a81 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultRecoveryKeyController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultRecoveryKeyController.java @@ -3,26 +3,83 @@ package org.cryptomator.ui.addvaultwizard; import dagger.Lazy; import javafx.beans.property.StringProperty; import javafx.fxml.FXML; +import javafx.print.PageLayout; +import javafx.print.PrintQuality; +import javafx.print.PrinterJob; import javafx.scene.Scene; +import javafx.scene.control.TextArea; +import javafx.scene.input.Clipboard; +import javafx.scene.input.ClipboardContent; +import javafx.scene.text.Font; +import javafx.scene.text.FontSmoothingType; +import javafx.scene.text.FontWeight; +import javafx.scene.text.Text; +import javafx.scene.text.TextFlow; import javafx.stage.Stage; import org.cryptomator.ui.common.FxController; import org.cryptomator.ui.common.FxmlFile; import org.cryptomator.ui.common.FxmlScene; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.inject.Inject; import javax.inject.Named; public class CreateNewVaultRecoveryKeyController implements FxController { + private static final Logger LOG = LoggerFactory.getLogger(CreateNewVaultRecoveryKeyController.class); + private final Stage window; private final Lazy successScene; private final StringProperty recoveryKeyProperty; + private final StringProperty vaultName; + public TextArea textarea; @Inject - CreateNewVaultRecoveryKeyController(@AddVaultWizardWindow Stage window, @FxmlScene(FxmlFile.ADDVAULT_SUCCESS) Lazy successScene, @Named("recoveryKey")StringProperty recoveryKey) { + CreateNewVaultRecoveryKeyController(@AddVaultWizardWindow Stage window, @FxmlScene(FxmlFile.ADDVAULT_SUCCESS) Lazy successScene, @Named("recoveryKey") StringProperty recoveryKey, @Named("vaultName") StringProperty vaultName) { this.window = window; this.successScene = successScene; this.recoveryKeyProperty = recoveryKey; + this.vaultName = vaultName; + } + + @FXML + public void printRecoveryKey() { + // TODO localize + PrinterJob job = PrinterJob.createPrinterJob(); + if (job != null && job.showPrintDialog(window)) { + PageLayout pageLayout = job.getJobSettings().getPageLayout(); + + Text heading = new Text("Cryptomator Recovery Key\n" + vaultName.get() + "\n"); + heading.setFont(Font.font("serif", FontWeight.BOLD, 20)); + heading.setFontSmoothingType(FontSmoothingType.LCD); + + Text key = new Text(recoveryKeyProperty.get()); + key.setFont(Font.font("serif", FontWeight.NORMAL, 16)); + key.setFontSmoothingType(FontSmoothingType.GRAY); + + TextFlow textFlow = new TextFlow(); + textFlow.setPrefSize(pageLayout.getPrintableWidth(), pageLayout.getPrintableHeight()); + textFlow.getChildren().addAll(heading, key); + textFlow.setLineSpacing(6); + + if (job.printPage(textFlow)) { + LOG.info("Recovery key printed."); + job.endJob(); + } else { + LOG.warn("Printing recovery key failed."); + } + } else { + LOG.info("Printing recovery key canceled by user."); + } + } + + @FXML + public void copyRecoveryKey() { + ClipboardContent clipboardContent = new ClipboardContent(); + clipboardContent.putString(recoveryKeyProperty.get()); + Clipboard.getSystemClipboard().setContent(clipboardContent); + LOG.info("Recovery key copied to clipboard."); } @FXML diff --git a/main/ui/src/main/resources/fxml/addvault_new_password.fxml b/main/ui/src/main/resources/fxml/addvault_new_password.fxml index 131e072f7..807d56bf4 100644 --- a/main/ui/src/main/resources/fxml/addvault_new_password.fxml +++ b/main/ui/src/main/resources/fxml/addvault_new_password.fxml @@ -46,9 +46,9 @@ - diff --git a/main/ui/src/main/resources/fxml/addvault_new_recoverykey.fxml b/main/ui/src/main/resources/fxml/addvault_new_recoverykey.fxml index 5485e2f91..af7d3a9d8 100644 --- a/main/ui/src/main/resources/fxml/addvault_new_recoverykey.fxml +++ b/main/ui/src/main/resources/fxml/addvault_new_recoverykey.fxml @@ -3,7 +3,6 @@ - @@ -23,15 +22,24 @@