diff --git a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java index 4eaa1c207..289376dca 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java +++ b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java @@ -20,6 +20,7 @@ import org.cryptomator.ui.common.FxControllerKey; import org.cryptomator.ui.common.FxmlFile; import org.cryptomator.ui.common.FxmlScene; import org.cryptomator.ui.mainwindow.MainWindow; +import org.cryptomator.ui.recoverykey.RecoveryKeyDisplayController; import javax.inject.Named; import javax.inject.Provider; @@ -170,11 +171,18 @@ public abstract class AddVaultModule { @Binds @IntoMap - @FxControllerKey(AddVaultSuccessController.class) - abstract FxController bindAddVaultSuccessController(AddVaultSuccessController controller); + @FxControllerKey(CreateNewVaultRecoveryKeyController.class) + abstract FxController bindCreateNewVaultRecoveryKeyController(CreateNewVaultRecoveryKeyController controller); + + @Provides + @IntoMap + @FxControllerKey(RecoveryKeyDisplayController.class) + static FxController provideRecoveryKeyDisplayController(@AddVaultWizardWindow Stage window, @Named("vaultName") StringProperty vaultName, @Named("recoveryKey") StringProperty recoveryKey) { + return new RecoveryKeyDisplayController(window, vaultName.get(), recoveryKey.get()); + } @Binds @IntoMap - @FxControllerKey(CreateNewVaultRecoveryKeyController.class) - abstract FxController bindCreateNewVaultRecoveryKeyController(CreateNewVaultRecoveryKeyController controller); + @FxControllerKey(AddVaultSuccessController.class) + abstract FxController bindAddVaultSuccessController(AddVaultSuccessController controller); } 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 5d2c31558..44f186774 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 @@ -1,112 +1,28 @@ package org.cryptomator.ui.addvaultwizard; import dagger.Lazy; -import javafx.beans.property.ReadOnlyBooleanProperty; -import javafx.beans.property.SimpleBooleanProperty; -import javafx.beans.property.StringProperty; import javafx.fxml.FXML; -import javafx.print.PageLayout; -import javafx.print.Printer; -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; - private final ReadOnlyBooleanProperty printerSupported; - public TextArea textarea; @Inject - CreateNewVaultRecoveryKeyController(@AddVaultWizardWindow Stage window, @FxmlScene(FxmlFile.ADDVAULT_SUCCESS) Lazy successScene, @Named("recoveryKey") StringProperty recoveryKey, @Named("vaultName") StringProperty vaultName) { + CreateNewVaultRecoveryKeyController(@AddVaultWizardWindow Stage window, @FxmlScene(FxmlFile.ADDVAULT_SUCCESS) Lazy successScene) { this.window = window; this.successScene = successScene; - this.recoveryKeyProperty = recoveryKey; - this.vaultName = vaultName; - this.printerSupported = new SimpleBooleanProperty(Printer.getDefaultPrinter() != null); - } - - @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 public void next() { window.setScene(successScene.get()); } - - /* Getter/Setter */ - - public ReadOnlyBooleanProperty printerSupportedProperty() { - return printerSupported; - } - - public boolean isPrinterSupported() { - return printerSupported.get(); - } - - public String getRecoveryKey() { - return recoveryKeyProperty.get(); - } - - public StringProperty recoveryKeyProperty() { - return recoveryKeyProperty; - } } diff --git a/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java b/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java index 553e70bef..944af9e28 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java +++ b/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java @@ -18,7 +18,7 @@ public enum FxmlFile { PREFERENCES("/fxml/preferences.fxml"), // QUIT("/fxml/quit.fxml"), // RECOVERYKEY_CREATE("/fxml/recoverykey_create.fxml"), // - RECOVERYKEY_DISPLAY("/fxml/recoverykey_display.fxml"), // + RECOVERYKEY_SUCCESS("/fxml/recoverykey_success.fxml"), // REMOVE_VAULT("/fxml/remove_vault.fxml"), // UNLOCK("/fxml/unlock.fxml"), UNLOCK_SUCCESS("/fxml/unlock_success.fxml"), // diff --git a/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java b/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java index 2ca6ebb69..945256f9e 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java @@ -40,7 +40,7 @@ public class RecoveryKeyCreationController implements FxController { public NiceSecurePasswordField passwordField; @Inject - public RecoveryKeyCreationController(@RecoveryKeyWindow Stage window, @FxmlScene(FxmlFile.RECOVERYKEY_DISPLAY) Lazy successScene, @RecoveryKeyWindow Vault vault, RecoveryKeyFactory recoveryKeyFactory, ExecutorService executor, @RecoveryKeyWindow StringProperty recoveryKey) { + public RecoveryKeyCreationController(@RecoveryKeyWindow Stage window, @FxmlScene(FxmlFile.RECOVERYKEY_SUCCESS) Lazy successScene, @RecoveryKeyWindow Vault vault, RecoveryKeyFactory recoveryKeyFactory, ExecutorService executor, @RecoveryKeyWindow StringProperty recoveryKey) { this.window = window; this.successScene = successScene; this.vault = vault; diff --git a/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyDisplayController.java b/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyDisplayController.java index 06b5c8a6a..8272ffa23 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyDisplayController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyDisplayController.java @@ -23,21 +23,19 @@ import org.slf4j.LoggerFactory; import javax.inject.Inject; -@RecoveryKeyScoped public class RecoveryKeyDisplayController implements FxController { private static final Logger LOG = LoggerFactory.getLogger(RecoveryKeyDisplayController.class); private final Stage window; - private final Vault vault; - private final StringProperty recoveryKeyProperty; + private final String vaultName; + private final String recoveryKey; private final ReadOnlyBooleanProperty printerSupported; - - @Inject - public RecoveryKeyDisplayController(@RecoveryKeyWindow Stage window, @RecoveryKeyWindow Vault vault, @RecoveryKeyWindow StringProperty recoveryKey) { + + public RecoveryKeyDisplayController(Stage window, String vaultName, String recoveryKey) { this.window = window; - this.vault = vault; - this.recoveryKeyProperty = recoveryKey; + this.vaultName = vaultName; + this.recoveryKey = recoveryKey; this.printerSupported = new SimpleBooleanProperty(Printer.getDefaultPrinter() != null); } @@ -49,11 +47,11 @@ public class RecoveryKeyDisplayController implements FxController { if (job != null && job.showPrintDialog(window)) { PageLayout pageLayout = job.getJobSettings().getPageLayout(); - Text heading = new Text("Cryptomator Recovery Key\n" + vault.getDisplayableName() + "\n"); + Text heading = new Text("Cryptomator Recovery Key\n" + vaultName + "\n"); heading.setFont(Font.font("serif", FontWeight.BOLD, 20)); heading.setFontSmoothingType(FontSmoothingType.LCD); - Text key = new Text(recoveryKeyProperty.get()); + Text key = new Text(recoveryKey); key.setFont(Font.font("serif", FontWeight.NORMAL, 16)); key.setFontSmoothingType(FontSmoothingType.GRAY); @@ -76,7 +74,7 @@ public class RecoveryKeyDisplayController implements FxController { @FXML public void copyRecoveryKey() { ClipboardContent clipboardContent = new ClipboardContent(); - clipboardContent.putString(recoveryKeyProperty.get()); + clipboardContent.putString(recoveryKey); Clipboard.getSystemClipboard().setContent(clipboardContent); LOG.info("Recovery key copied to clipboard."); } @@ -88,10 +86,6 @@ public class RecoveryKeyDisplayController implements FxController { /* Getter/Setter */ - public Vault getVault() { - return vault; - } - public ReadOnlyBooleanProperty printerSupportedProperty() { return printerSupported; } @@ -100,11 +94,11 @@ public class RecoveryKeyDisplayController implements FxController { return printerSupported.get(); } - public ReadOnlyStringProperty recoveryKeyProperty() { - return recoveryKeyProperty; + public String getRecoveryKey() { + return recoveryKey; } - public String getRecoveryKey() { - return recoveryKeyProperty.get(); + public String getVaultName() { + return vaultName; } } diff --git a/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyModule.java b/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyModule.java index 261b50682..80f89c749 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyModule.java +++ b/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyModule.java @@ -10,6 +10,7 @@ import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.stage.Modality; import javafx.stage.Stage; +import org.cryptomator.common.vaults.Vault; import org.cryptomator.ui.common.DefaultSceneFactory; import org.cryptomator.ui.common.FXMLLoaderFactory; import org.cryptomator.ui.common.FxController; @@ -63,10 +64,10 @@ abstract class RecoveryKeyModule { } @Provides - @FxmlScene(FxmlFile.RECOVERYKEY_DISPLAY) + @FxmlScene(FxmlFile.RECOVERYKEY_SUCCESS) @RecoveryKeyScoped - static Scene provideRecoveryKeyDisplayScene(@RecoveryKeyWindow FXMLLoaderFactory fxmlLoaders) { - return fxmlLoaders.createScene("/fxml/recoverykey_display.fxml"); + static Scene provideRecoveryKeySuccessScene(@RecoveryKeyWindow FXMLLoaderFactory fxmlLoaders) { + return fxmlLoaders.createScene("/fxml/recoverykey_success.fxml"); } // ------------------ @@ -76,9 +77,16 @@ abstract class RecoveryKeyModule { @FxControllerKey(RecoveryKeyCreationController.class) abstract FxController bindRecoveryKeyCreationController(RecoveryKeyCreationController controller); - @Binds + @Provides @IntoMap @FxControllerKey(RecoveryKeyDisplayController.class) - abstract FxController bindRecoveryKeyDisplayController(RecoveryKeyDisplayController controller); + static FxController provideRecoveryKeyDisplayController(@RecoveryKeyWindow Stage window, @RecoveryKeyWindow Vault vault, @RecoveryKeyWindow StringProperty recoveryKey) { + return new RecoveryKeyDisplayController(window, vault.getDisplayableName(), recoveryKey.get()); + } + + @Binds + @IntoMap + @FxControllerKey(RecoveryKeySuccessController.class) + abstract FxController bindRecoveryKeySuccessController(RecoveryKeySuccessController controller); } diff --git a/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeySuccessController.java b/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeySuccessController.java new file mode 100644 index 000000000..ae9e2e70f --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeySuccessController.java @@ -0,0 +1,24 @@ +package org.cryptomator.ui.recoverykey; + +import javafx.fxml.FXML; +import javafx.stage.Stage; +import org.cryptomator.ui.common.FxController; + +import javax.inject.Inject; + +@RecoveryKeyScoped +public class RecoveryKeySuccessController implements FxController { + + private final Stage window; + + @Inject + public RecoveryKeySuccessController(@RecoveryKeyWindow Stage window) { + this.window = window; + } + + @FXML + public void close() { + window.close(); + } + +} 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 9c2a2622e..ecfc1441a 100644 --- a/main/ui/src/main/resources/fxml/addvault_new_recoverykey.fxml +++ b/main/ui/src/main/resources/fxml/addvault_new_recoverykey.fxml @@ -3,11 +3,8 @@ - - - -