|
@@ -8,15 +8,22 @@
|
|
|
******************************************************************************/
|
|
|
package org.cryptomator.ui.controllers;
|
|
|
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
+import java.nio.file.Paths;
|
|
|
import java.util.Optional;
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
import javax.inject.Named;
|
|
|
import javax.inject.Singleton;
|
|
|
|
|
|
+import javafx.beans.Observable;
|
|
|
+import javafx.beans.value.ObservableValue;
|
|
|
+import javafx.scene.layout.GridPane;
|
|
|
import org.apache.commons.lang3.SystemUtils;
|
|
|
import org.cryptomator.common.settings.Settings;
|
|
|
import org.cryptomator.ui.l10n.Localization;
|
|
|
+import org.cryptomator.ui.model.NioAdapterImpl;
|
|
|
|
|
|
import com.google.common.base.CharMatcher;
|
|
|
import com.google.common.base.Strings;
|
|
@@ -52,6 +59,15 @@ public class SettingsController implements ViewController {
|
|
|
@FXML
|
|
|
private CheckBox checkForUpdatesCheckbox;
|
|
|
|
|
|
+ @FXML
|
|
|
+ private GridPane webdavNioAdapter;
|
|
|
+
|
|
|
+ @FXML
|
|
|
+ private GridPane fuseNioAdapter;
|
|
|
+
|
|
|
+ @FXML
|
|
|
+ private Label portFieldLabel;
|
|
|
+
|
|
|
@FXML
|
|
|
private TextField portField;
|
|
|
|
|
@@ -64,9 +80,24 @@ public class SettingsController implements ViewController {
|
|
|
@FXML
|
|
|
private Label prefGvfsSchemeLabel;
|
|
|
|
|
|
+ @FXML
|
|
|
+ private Label defaultMountDirLabel;
|
|
|
+
|
|
|
+ @FXML
|
|
|
+ private TextField defaultMountDir;
|
|
|
+
|
|
|
+ @FXML
|
|
|
+ private Button changeDefaultMountDirButton;
|
|
|
+
|
|
|
@FXML
|
|
|
private ChoiceBox<String> prefGvfsScheme;
|
|
|
|
|
|
+ @FXML
|
|
|
+ private Label nioAdapterLabel;
|
|
|
+
|
|
|
+ @FXML
|
|
|
+ private ChoiceBox<String> nioAdapter;
|
|
|
+
|
|
|
@FXML
|
|
|
private CheckBox debugModeCheckbox;
|
|
|
|
|
@@ -75,25 +106,69 @@ public class SettingsController implements ViewController {
|
|
|
|
|
|
@Override
|
|
|
public void initialize() {
|
|
|
+ versionLabel.setText(String.format(localization.getString("settings.version.label"), applicationVersion.orElse("SNAPSHOT")));
|
|
|
checkForUpdatesCheckbox.setDisable(areUpdatesManagedExternally());
|
|
|
checkForUpdatesCheckbox.setSelected(settings.checkForUpdates().get() && !areUpdatesManagedExternally());
|
|
|
+
|
|
|
+ //NIOADAPTER
|
|
|
+ nioAdapter.getItems().addAll(getSupportedAdapters());
|
|
|
+ nioAdapter.setValue(settings.usedNioAdapterImpl().get());
|
|
|
+ nioAdapter.setVisible(true);
|
|
|
+ nioAdapter.getSelectionModel().selectedItemProperty().addListener( (ObservableValue<? extends String> observable, String oldVal, String newVal) -> changeNioView(newVal) );
|
|
|
+
|
|
|
+
|
|
|
+ //WEBDAV
|
|
|
+ webdavNioAdapter.managedProperty().bind(webdavNioAdapter.visibleProperty());
|
|
|
+ prefGvfsScheme.managedProperty().bind(webdavNioAdapter.visibleProperty());
|
|
|
+ prefGvfsSchemeLabel.managedProperty().bind(webdavNioAdapter.visibleProperty());
|
|
|
+ portFieldLabel.managedProperty().bind(webdavNioAdapter.visibleProperty());
|
|
|
+ changePortButton.managedProperty().bind(webdavNioAdapter.visibleProperty());
|
|
|
+ portField.managedProperty().bind(webdavNioAdapter.visibleProperty());
|
|
|
portField.setText(String.valueOf(settings.port().intValue()));
|
|
|
portField.addEventFilter(KeyEvent.KEY_TYPED, this::filterNumericKeyEvents);
|
|
|
changePortButton.visibleProperty().bind(settings.port().asString().isNotEqualTo(portField.textProperty()));
|
|
|
changePortButton.disableProperty().bind(Bindings.createBooleanBinding(this::isPortValid, portField.textProperty()).not());
|
|
|
- versionLabel.setText(String.format(localization.getString("settings.version.label"), applicationVersion.orElse("SNAPSHOT")));
|
|
|
- prefGvfsSchemeLabel.setVisible(SystemUtils.IS_OS_LINUX);
|
|
|
- prefGvfsScheme.setVisible(SystemUtils.IS_OS_LINUX);
|
|
|
prefGvfsScheme.getItems().add("dav");
|
|
|
prefGvfsScheme.getItems().add("webdav");
|
|
|
prefGvfsScheme.setValue(settings.preferredGvfsScheme().get());
|
|
|
+ prefGvfsSchemeLabel.setVisible(SystemUtils.IS_OS_LINUX);
|
|
|
+ prefGvfsScheme.setVisible(SystemUtils.IS_OS_LINUX);
|
|
|
+
|
|
|
+ //FUSE
|
|
|
+ fuseNioAdapter.managedProperty().bind(fuseNioAdapter.visibleProperty());
|
|
|
+ defaultMountDirLabel.managedProperty().bind(fuseNioAdapter.visibleProperty());
|
|
|
+ defaultMountDir.managedProperty().bind(fuseNioAdapter.visibleProperty());
|
|
|
+ defaultMountDirLabel.setVisible(SystemUtils.IS_OS_LINUX);
|
|
|
+ defaultMountDir.setVisible(SystemUtils.IS_OS_LINUX);
|
|
|
+ defaultMountDir.setText(String.valueOf(settings.defaultMountDir().get()));
|
|
|
+ changeDefaultMountDirButton.setVisible(false);
|
|
|
+ changeDefaultMountDirButton.visibleProperty().bind(
|
|
|
+ Bindings.createBooleanBinding(
|
|
|
+ () -> fuseNioAdapter.visibleProperty().get() && settings.defaultMountDir().isNotEqualTo(Strings.nullToEmpty(defaultMountDir.getText())).get() ,
|
|
|
+ fuseNioAdapter.visibleProperty(),
|
|
|
+ settings.defaultMountDir().isNotEqualTo(defaultMountDir.textProperty())
|
|
|
+ )
|
|
|
+ );
|
|
|
+ changeDefaultMountDirButton.disableProperty().bind(Bindings.createBooleanBinding(this::isDirValid, defaultMountDir.textProperty()).not());
|
|
|
+
|
|
|
debugModeCheckbox.setSelected(settings.debugMode().get());
|
|
|
|
|
|
settings.checkForUpdates().bind(checkForUpdatesCheckbox.selectedProperty());
|
|
|
settings.preferredGvfsScheme().bind(prefGvfsScheme.valueProperty());
|
|
|
+ settings.usedNioAdapterImpl().bind(nioAdapter.valueProperty());
|
|
|
settings.debugMode().bind(debugModeCheckbox.selectedProperty());
|
|
|
}
|
|
|
|
|
|
+ //TODO: how to implement this?
|
|
|
+ private String [] getSupportedAdapters() {
|
|
|
+ return new String[]{NioAdapterImpl.FUSE.name(), NioAdapterImpl.WEBDAV.name()};
|
|
|
+ }
|
|
|
+
|
|
|
+ private void changeNioView(String newVal) {
|
|
|
+ fuseNioAdapter.setVisible(newVal.equalsIgnoreCase("FUSE"));
|
|
|
+ webdavNioAdapter.setVisible(newVal.equalsIgnoreCase("WEBDAV"));
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Parent getRoot() {
|
|
|
return root;
|
|
@@ -110,6 +185,23 @@ public class SettingsController implements ViewController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @FXML
|
|
|
+ private void changeDefaultMountDir(ActionEvent event){
|
|
|
+ assert isDirValid() : "Error. Not a valid Directory. Does and exist and do you have the needed Rights?";
|
|
|
+ settings.defaultMountDir().set(defaultMountDir.getText());
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isDirValid(){
|
|
|
+ if(SystemUtils.IS_OS_WINDOWS){
|
|
|
+ //this should never ever happen!
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ Path path = Paths.get(defaultMountDir.getText());
|
|
|
+ return Files.isDirectory(path) && Files.isReadable(path) && Files.isWritable(path) && Files.isExecutable(path);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private boolean isPortValid() {
|
|
|
try {
|
|
|
int port = Integer.parseInt(portField.getText());
|