Jelajahi Sumber

added new AdvancedSettings scene in AddVaultWizard

Jan-Peter Klein 2 tahun lalu
induk
melakukan
386bdd3490

+ 19 - 0
src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java

@@ -65,6 +65,13 @@ public abstract class AddVaultModule {
 		return new SimpleStringProperty("");
 	}
 
+	@Provides
+	@Named("shorteningThreshold")
+	@AddVaultWizardScoped
+	static StringProperty provideShorteningThreshold() {
+		return new SimpleStringProperty();
+	}
+
 	@Provides
 	@AddVaultWizardWindow
 	@AddVaultWizardScoped
@@ -130,6 +137,13 @@ public abstract class AddVaultModule {
 		return fxmlLoaders.createScene(FxmlFile.ADDVAULT_SUCCESS);
 	}
 
+	@Provides
+	@FxmlScene(FxmlFile.ADDVAULT_NEW_ADVANCED_SETTINGS)
+	@AddVaultWizardScoped
+	static Scene provideCreateNewVaultAdvancedSettingsScene(@AddVaultWizardWindow FxmlLoaderFactory fxmlLoaders) {
+		return fxmlLoaders.createScene(FxmlFile.ADDVAULT_NEW_ADVANCED_SETTINGS);
+	}
+
 	// ------------------
 
 	@Binds
@@ -181,4 +195,9 @@ public abstract class AddVaultModule {
 	@FxControllerKey(AddVaultSuccessController.class)
 	abstract FxController bindAddVaultSuccessController(AddVaultSuccessController controller);
 
+	@Binds
+	@IntoMap
+	@FxControllerKey(CreateNewVaultAdvancedSettingsController.class)
+	abstract FxController bindCreateNewVaultAdvancedSettingsController(CreateNewVaultAdvancedSettingsController controller);
+
 }

+ 96 - 0
src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultAdvancedSettingsController.java

@@ -0,0 +1,96 @@
+package org.cryptomator.ui.addvaultwizard;
+
+import dagger.Lazy;
+import org.cryptomator.ui.common.FxController;
+import org.cryptomator.ui.common.FxmlFile;
+import org.cryptomator.ui.common.FxmlScene;
+import org.cryptomator.ui.controls.NumericTextField;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javafx.application.Application;
+import javafx.beans.binding.Bindings;
+import javafx.beans.binding.BooleanBinding;
+import javafx.beans.property.ObjectProperty;
+import javafx.beans.property.StringProperty;
+import javafx.fxml.FXML;
+import javafx.scene.Scene;
+import javafx.stage.Stage;
+import java.nio.file.Path;
+import java.util.ResourceBundle;
+
+@AddVaultWizardScoped
+public class CreateNewVaultAdvancedSettingsController implements FxController {
+
+	private static final String DOCS_MOUNTING_URL = "https://docs.cryptomator.org/en/1.7/security/architecture/#name-shortening";
+	private final Stage window;
+	private final Lazy<Scene> chooseLocationScene;
+	private final Lazy<Scene> choosePasswordScene;
+	private final ObjectProperty<Path> vaultPath;
+	private final StringProperty vaultName;
+	private final ResourceBundle resourceBundle;
+	private final StringProperty shorteningThreshold;
+	public NumericTextField shorteningThresholdTextField;
+	private final BooleanBinding validShorteningThreshold;
+	private final Lazy<Application> application;
+
+	@Inject
+	CreateNewVaultAdvancedSettingsController(@AddVaultWizardWindow Stage window, //
+											 Lazy<Application> application, //
+											 @FxmlScene(FxmlFile.ADDVAULT_NEW_LOCATION) Lazy<Scene> chooseLocationScene, //
+											 @FxmlScene(FxmlFile.ADDVAULT_NEW_PASSWORD) Lazy<Scene> choosePasswordScene, //
+											 ObjectProperty<Path> vaultPath, //
+											 @Named("vaultName") StringProperty vaultName, //
+											 ResourceBundle resourceBundle, //
+											 @Named("shorteningThreshold") StringProperty shorteningThreshold) {
+		this.window = window;
+		this.application = application;
+		this.chooseLocationScene = chooseLocationScene;
+		this.choosePasswordScene = choosePasswordScene;
+		this.vaultPath = vaultPath;
+		this.vaultName = vaultName;
+		this.resourceBundle = resourceBundle;
+		this.shorteningThreshold = shorteningThreshold;
+		this.validShorteningThreshold = Bindings.createBooleanBinding(this::isValidShorteningThreshold, shorteningThreshold);
+	}
+
+	@FXML
+	public void initialize() {
+		shorteningThreshold.bindBidirectional(shorteningThresholdTextField.textProperty());
+	}
+
+	@FXML
+	public void back() {
+		window.setScene(chooseLocationScene.get());
+	}
+
+	@FXML
+	public void next() { window.setScene(choosePasswordScene.get()); }
+
+	public BooleanBinding validShorteningThresholdProperty() {
+		return validShorteningThreshold;
+	}
+
+	public boolean isValidShorteningThreshold() {
+		if(shorteningThresholdTextField != null){
+			try {
+				var value = Integer.parseInt(shorteningThresholdTextField.getText());
+				if (value < 36 || value > 220) {
+					return false;
+				}
+				else{
+					return true;
+				}
+			} catch (NumberFormatException e) {
+				return false;
+			}
+		}
+		else {
+			return false;
+		}
+	}
+
+	public void openDocs() {
+		application.get().getHostServices().showDocument(DOCS_MOUNTING_URL);
+	}
+}

+ 20 - 2
src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultLocationController.java

@@ -8,11 +8,14 @@ import org.cryptomator.ui.common.FxController;
 import org.cryptomator.ui.common.FxmlFile;
 import org.cryptomator.ui.common.FxmlScene;
 import org.cryptomator.ui.controls.FontAwesome5IconView;
+import org.cryptomator.ui.controls.NumericTextField;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.inject.Inject;
 import javax.inject.Named;
+import javafx.beans.Observable;
+import javafx.beans.binding.Bindings;
 import javafx.beans.binding.BooleanBinding;
 import javafx.beans.property.BooleanProperty;
 import javafx.beans.property.ObjectProperty;
@@ -21,6 +24,7 @@ import javafx.beans.property.StringProperty;
 import javafx.beans.value.ObservableValue;
 import javafx.fxml.FXML;
 import javafx.scene.Scene;
+import javafx.scene.control.CheckBox;
 import javafx.scene.control.Label;
 import javafx.scene.control.RadioButton;
 import javafx.scene.control.Toggle;
@@ -49,6 +53,7 @@ public class CreateNewVaultLocationController implements FxController {
 	private final Stage window;
 	private final Lazy<Scene> chooseNameScene;
 	private final Lazy<Scene> choosePasswordScene;
+	private final Lazy<Scene> chooseAdvancedSettingsScene;
 	private final List<RadioButton> locationPresetBtns;
 	private final ObjectProperty<Path> vaultPath;
 	private final StringProperty vaultName;
@@ -66,12 +71,20 @@ public class CreateNewVaultLocationController implements FxController {
 	public Label locationStatusLabel;
 	public FontAwesome5IconView goodLocation;
 	public FontAwesome5IconView badLocation;
+	public CheckBox advancedSettingsCheckBox;
 
 	@Inject
-	CreateNewVaultLocationController(@AddVaultWizardWindow Stage window, @FxmlScene(FxmlFile.ADDVAULT_NEW_NAME) Lazy<Scene> chooseNameScene, @FxmlScene(FxmlFile.ADDVAULT_NEW_PASSWORD) Lazy<Scene> choosePasswordScene, ObjectProperty<Path> vaultPath, @Named("vaultName") StringProperty vaultName, ResourceBundle resourceBundle) {
+	CreateNewVaultLocationController(@AddVaultWizardWindow Stage window, //
+									 @FxmlScene(FxmlFile.ADDVAULT_NEW_NAME) Lazy<Scene> chooseNameScene, //
+									 @FxmlScene(FxmlFile.ADDVAULT_NEW_PASSWORD) Lazy<Scene> choosePasswordScene, //
+									 @FxmlScene(FxmlFile.ADDVAULT_NEW_ADVANCED_SETTINGS) Lazy<Scene> chooseAdvancedSettingsScene, //
+									 ObjectProperty<Path> vaultPath, //
+									 @Named("vaultName") StringProperty vaultName, //
+									 ResourceBundle resourceBundle) {
 		this.window = window;
 		this.chooseNameScene = chooseNameScene;
 		this.choosePasswordScene = choosePasswordScene;
+		this.chooseAdvancedSettingsScene = chooseAdvancedSettingsScene;
 		this.vaultPath = vaultPath;
 		this.vaultName = vaultName;
 		this.resourceBundle = resourceBundle;
@@ -151,7 +164,12 @@ public class CreateNewVaultLocationController implements FxController {
 	@FXML
 	public void next() {
 		if (validVaultPath.getValue()) {
-			window.setScene(choosePasswordScene.get());
+			if(advancedSettingsCheckBox.isSelected()){
+				window.setScene(chooseAdvancedSettingsScene.get());
+			}
+			else {
+				window.setScene(choosePasswordScene.get());
+			}
 		}
 	}
 

File diff ditekan karena terlalu besar
+ 29 - 4
src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultPasswordController.java


+ 1 - 0
src/main/java/org/cryptomator/ui/common/FxmlFile.java

@@ -4,6 +4,7 @@ public enum FxmlFile {
 	ADDVAULT_EXISTING("/fxml/addvault_existing.fxml"), //
 	ADDVAULT_NEW_NAME("/fxml/addvault_new_name.fxml"), //
 	ADDVAULT_NEW_LOCATION("/fxml/addvault_new_location.fxml"), //
+	ADDVAULT_NEW_ADVANCED_SETTINGS("/fxml/addvault_new_advanced_settings.fxml"), //
 	ADDVAULT_NEW_PASSWORD("/fxml/addvault_new_password.fxml"), //
 	ADDVAULT_NEW_RECOVERYKEY("/fxml/addvault_new_recoverykey.fxml"), //
 	ADDVAULT_SUCCESS("/fxml/addvault_success.fxml"), //

+ 69 - 0
src/main/resources/fxml/addvault_new_advanced_settings.fxml

@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<?import org.cryptomator.ui.controls.FontAwesome5IconView?>
+<?import org.cryptomator.ui.controls.NumericTextField?>
+<?import javafx.geometry.Insets?>
+<?import javafx.scene.control.Button?>
+<?import javafx.scene.control.ButtonBar?>
+<?import javafx.scene.control.Hyperlink?>
+<?import javafx.scene.control.Label?>
+<?import javafx.scene.control.Tooltip?>
+<?import javafx.scene.layout.HBox?>
+<?import javafx.scene.layout.Region?>
+<?import javafx.scene.layout.StackPane?>
+<?import javafx.scene.layout.VBox?>
+<VBox xmlns:fx="http://javafx.com/fxml"
+	  xmlns="http://javafx.com/javafx"
+	  fx:controller="org.cryptomator.ui.addvaultwizard.CreateNewVaultAdvancedSettingsController"
+	  prefWidth="450"
+	  prefHeight="450"
+	  spacing="12"
+	  alignment="CENTER_LEFT">
+	<padding>
+		<Insets topRightBottomLeft="24"/>
+	</padding>
+	<children>
+
+		<Region prefHeight="12" VBox.vgrow="NEVER"/>
+
+		<VBox spacing="6">
+			<HBox spacing="2" HBox.hgrow="NEVER">
+				<Label text="%addvaultwizard.new.shorteningThreshold.title"/>
+				<Region prefWidth="2"/>
+				<Hyperlink contentDisplay="GRAPHIC_ONLY" onAction="#openDocs">
+					<graphic>
+						<FontAwesome5IconView glyph="QUESTION_CIRCLE" styleClass="glyph-icon-muted"/>
+					</graphic>
+					<tooltip>
+						<Tooltip text="%addvaultwizard.new.shorteningThreshold.tooltip" showDelay="10ms" />
+					</tooltip>
+				</Hyperlink>
+			</HBox>
+			<HBox>
+				<NumericTextField fx:id="shorteningThresholdTextField" promptText="%addvaultwizard.new.shorteningThreshold.namePrompt" text="220"/>
+				<Region prefWidth="4" HBox.hgrow="NEVER"/>
+				<StackPane>
+					<Label styleClass="label-muted" text="%addvaultwizard.new.shorteningThreshold.invalid" textAlignment="RIGHT" alignment="CENTER_RIGHT" visible="${!controller.validShorteningThreshold}" graphicTextGap="6">
+						<graphic>
+							<FontAwesome5IconView styleClass="glyph-icon-red" glyph="TIMES"/>
+						</graphic>
+					</Label>
+					<Label styleClass="label-muted" text="%addvaultwizard.new.shorteningThreshold.valid" textAlignment="RIGHT" alignment="CENTER_RIGHT" visible="${controller.validShorteningThreshold}" graphicTextGap="6">
+						<graphic>
+							<FontAwesome5IconView styleClass="glyph-icon-primary" glyph="CHECK"/>
+						</graphic>
+					</Label>
+				</StackPane>
+			</HBox>
+		</VBox>
+
+		<Region VBox.vgrow="ALWAYS"/>
+
+		<ButtonBar buttonMinWidth="120" buttonOrder="B+X">
+			<buttons>
+				<Button text="%generic.button.back" ButtonBar.buttonData="BACK_PREVIOUS" onAction="#back"/>
+				<Button text="%generic.button.next" ButtonBar.buttonData="NEXT_FORWARD" onAction="#next" defaultButton="true" disable="${!controller.validShorteningThreshold}"/>
+			</buttons>
+		</ButtonBar>
+	</children>
+</VBox>

+ 5 - 0
src/main/resources/fxml/addvault_new_location.fxml

@@ -11,6 +11,7 @@
 <?import javafx.scene.layout.HBox?>
 <?import javafx.scene.layout.Region?>
 <?import javafx.scene.layout.VBox?>
+<?import javafx.scene.control.CheckBox?>
 <VBox xmlns:fx="http://javafx.com/fxml"
 	  xmlns="http://javafx.com/javafx"
 	  fx:controller="org.cryptomator.ui.addvaultwizard.CreateNewVaultLocationController"
@@ -50,6 +51,10 @@
 			<Label fx:id="locationStatusLabel" alignment="CENTER_RIGHT" wrapText="true" visible="${controller.anyRadioButtonSelected}" maxWidth="Infinity" graphicTextGap="6" />
 		</VBox>
 
+		<Region prefHeight="12" VBox.vgrow="NEVER"/>
+
+		<CheckBox fx:id="advancedSettingsCheckBox" text="%addvaultwizard.new.showAdvancedSettings.checkbox"/>
+
 		<Region VBox.vgrow="ALWAYS"/>
 
 		<ButtonBar buttonMinWidth="120" buttonOrder="B+X">

+ 6 - 0
src/main/resources/i18n/strings.properties

@@ -63,6 +63,12 @@ addvaultwizard.new.validCharacters.message=The vault name may contain the follow
 addvaultwizard.new.validCharacters.chars=Word characters (e.g. a, ж or 수)
 addvaultwizard.new.validCharacters.numbers=Numbers
 addvaultwizard.new.validCharacters.dashes=Hyphen (%s) or underscore (%s)
+addvaultwizard.new.showAdvancedSettings.checkbox=Show advanced settings in next step
+addvaultwizard.new.shorteningThreshold.title=Limit the length of encrypted file names.
+addvaultwizard.new.shorteningThreshold.tooltip=Open the documentation to learn more.
+addvaultwizard.new.shorteningThreshold.namePrompt=36-220
+addvaultwizard.new.shorteningThreshold.invalid=Invalid
+addvaultwizard.new.shorteningThreshold.valid=Valid
 ### Password
 addvaultwizard.new.createVaultBtn=Create Vault
 addvaultwizard.new.generateRecoveryKeyChoice=You won't be able to access your data without your password. Do you want a recovery key for the case you lose your password?