mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-30 08:26:19 +00:00
added copy/print buttons to recovery key dialog
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
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.PrintQuality;
|
||||
import javafx.print.Printer;
|
||||
import javafx.print.PrinterJob;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.TextArea;
|
||||
@@ -33,6 +35,7 @@ public class CreateNewVaultRecoveryKeyController implements FxController {
|
||||
private final Lazy<Scene> successScene;
|
||||
private final StringProperty recoveryKeyProperty;
|
||||
private final StringProperty vaultName;
|
||||
private final ReadOnlyBooleanProperty printerSupported;
|
||||
public TextArea textarea;
|
||||
|
||||
@Inject
|
||||
@@ -41,11 +44,13 @@ public class CreateNewVaultRecoveryKeyController implements FxController {
|
||||
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();
|
||||
@@ -89,6 +94,14 @@ public class CreateNewVaultRecoveryKeyController implements FxController {
|
||||
|
||||
/* Getter/Setter */
|
||||
|
||||
public ReadOnlyBooleanProperty printerSupportedProperty() {
|
||||
return printerSupported;
|
||||
}
|
||||
|
||||
public boolean isPrinterSupported() {
|
||||
return printerSupported.get();
|
||||
}
|
||||
|
||||
public String getRecoveryKey() {
|
||||
return recoveryKeyProperty.get();
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ public enum FontAwesome5Icon {
|
||||
CHECK("\uF00C"), //
|
||||
COG("\uF013"), //
|
||||
COGS("\uF085"), //
|
||||
COPY("\uF0C5"), //
|
||||
EXCLAMATION("\uF12A"),
|
||||
EXCLAMATION_CIRCLE("\uF06A"), //
|
||||
EXCLAMATION_TRIANGLE("\uF071"), //
|
||||
@@ -24,6 +25,7 @@ public enum FontAwesome5Icon {
|
||||
LOCK_ALT("\uF30D"), //
|
||||
LOCK_OPEN_ALT("\uF3C2"), //
|
||||
PLUS("\uF067"), //
|
||||
PRINT("\uF02F"), //
|
||||
QUESTION("\uF128"), //
|
||||
SPARKLES("\uF890"), //
|
||||
SPINNER("\uF110"), //
|
||||
|
||||
@@ -1,26 +1,84 @@
|
||||
package org.cryptomator.ui.recoverykey;
|
||||
|
||||
import javafx.beans.property.ReadOnlyBooleanProperty;
|
||||
import javafx.beans.property.ReadOnlyStringProperty;
|
||||
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.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.common.vaults.Vault;
|
||||
import org.cryptomator.ui.common.FxController;
|
||||
import org.slf4j.Logger;
|
||||
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 ReadOnlyBooleanProperty printerSupported;
|
||||
|
||||
@Inject
|
||||
public RecoveryKeyDisplayController(@RecoveryKeyWindow Stage window, @RecoveryKeyWindow Vault vault, @RecoveryKeyWindow StringProperty recoveryKey) {
|
||||
this.window = window;
|
||||
this.vault = vault;
|
||||
this.recoveryKeyProperty = recoveryKey;
|
||||
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" + vault.getDisplayableName() + "\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
|
||||
@@ -34,6 +92,14 @@ public class RecoveryKeyDisplayController implements FxController {
|
||||
return vault;
|
||||
}
|
||||
|
||||
public ReadOnlyBooleanProperty printerSupportedProperty() {
|
||||
return printerSupported;
|
||||
}
|
||||
|
||||
public boolean isPrinterSupported() {
|
||||
return printerSupported.get();
|
||||
}
|
||||
|
||||
public ReadOnlyStringProperty recoveryKeyProperty() {
|
||||
return recoveryKeyProperty;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
<?import javafx.scene.control.TextArea?>
|
||||
<?import javafx.scene.layout.Region?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import org.cryptomator.ui.controls.FontAwesome5IconView?>
|
||||
<VBox xmlns="http://javafx.com/javafx"
|
||||
xmlns:fx="http://javafx.com/fxml"
|
||||
fx:controller="org.cryptomator.ui.addvaultwizard.CreateNewVaultRecoveryKeyController"
|
||||
@@ -23,11 +24,18 @@
|
||||
<Label text="%addvaultwizard.new.recoveryKeyInstruction" wrapText="true"/>
|
||||
|
||||
<TextArea editable="false" text="${controller.recoveryKey}" wrapText="true" prefRowCount="4" fx:id="textarea"/>
|
||||
|
||||
<ButtonBar buttonMinWidth="120" buttonOrder="+R">
|
||||
<buttons>
|
||||
<Button text="TODO Print" ButtonBar.buttonData="RIGHT" onAction="#printRecoveryKey"/>
|
||||
<Button text="TODO Copy" ButtonBar.buttonData="RIGHT" onAction="#copyRecoveryKey"/>
|
||||
<Button text="%generic.button.print" ButtonBar.buttonData="RIGHT" onAction="#printRecoveryKey" visible="${controller.printerSupported}">
|
||||
<graphic>
|
||||
<FontAwesome5IconView glyph="PRINT"/>
|
||||
</graphic>
|
||||
</Button>
|
||||
<Button text="%generic.button.copy" ButtonBar.buttonData="RIGHT" onAction="#copyRecoveryKey">
|
||||
<graphic>
|
||||
<FontAwesome5IconView glyph="COPY"/>
|
||||
</graphic>
|
||||
</Button>
|
||||
</buttons>
|
||||
</ButtonBar>
|
||||
|
||||
|
||||
@@ -31,14 +31,28 @@
|
||||
|
||||
<VBox spacing="6" HBox.hgrow="ALWAYS">
|
||||
<FormattedLabel format="%recoveryKey.display.message" arg1="${controller.vault.displayableName}" wrapText="true" VBox.vgrow="NEVER"/>
|
||||
<TextArea editable="false" text="${controller.recoveryKey}" wrapText="true" VBox.vgrow="ALWAYS"/>
|
||||
<TextArea editable="false" text="${controller.recoveryKey}" wrapText="true" VBox.vgrow="ALWAYS" prefRowCount="4"/>
|
||||
</VBox>
|
||||
</HBox>
|
||||
|
||||
<VBox alignment="BOTTOM_CENTER" VBox.vgrow="ALWAYS">
|
||||
<ButtonBar buttonMinWidth="120" buttonOrder="+C">
|
||||
<ButtonBar buttonMinWidth="100" buttonOrder="+UC">
|
||||
<buttons>
|
||||
<Button text="%generic.button.done" ButtonBar.buttonData="CANCEL_CLOSE" cancelButton="true" onAction="#close"/>
|
||||
<Button text="%generic.button.print" ButtonBar.buttonData="OTHER" onAction="#printRecoveryKey" visible="${controller.printerSupported}">
|
||||
<graphic>
|
||||
<FontAwesome5IconView glyph="PRINT"/>
|
||||
</graphic>
|
||||
</Button>
|
||||
<Button text="%generic.button.copy" ButtonBar.buttonData="OTHER" onAction="#copyRecoveryKey">
|
||||
<graphic>
|
||||
<FontAwesome5IconView glyph="COPY"/>
|
||||
</graphic>
|
||||
</Button>
|
||||
<Button text="%generic.button.done" ButtonBar.buttonData="CANCEL_CLOSE" cancelButton="true" onAction="#close">
|
||||
<graphic>
|
||||
<FontAwesome5IconView glyph="CHECK"/>
|
||||
</graphic>
|
||||
</Button>
|
||||
</buttons>
|
||||
</ButtonBar>
|
||||
</VBox>
|
||||
|
||||
@@ -7,8 +7,10 @@ generic.button.apply=Apply
|
||||
generic.button.back=Back
|
||||
generic.button.cancel=Cancel
|
||||
generic.button.change=Change
|
||||
generic.button.copy=Copy
|
||||
generic.button.done=Done
|
||||
generic.button.next=Next
|
||||
generic.button.print=Print
|
||||
|
||||
# Tray Menu
|
||||
traymenu.showMainWindow=Show
|
||||
|
||||
Reference in New Issue
Block a user