diff --git a/client/src/main/java/ctbrec/ui/settings/SettingsTab.java b/client/src/main/java/ctbrec/ui/settings/SettingsTab.java index 1914afd5..7d3a3c52 100644 --- a/client/src/main/java/ctbrec/ui/settings/SettingsTab.java +++ b/client/src/main/java/ctbrec/ui/settings/SettingsTab.java @@ -32,6 +32,7 @@ import ctbrec.ui.settings.api.SimpleFileProperty; import ctbrec.ui.settings.api.SimpleRangeProperty; import ctbrec.ui.settings.api.ValueConverter; import ctbrec.ui.tabs.TabSelectionListener; +import javafx.beans.binding.BooleanExpression; import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleListProperty; @@ -162,6 +163,7 @@ public class SettingsTab extends Tab implements TabSelectionListener { Setting.of("Update overview interval (seconds)", overviewUpdateIntervalInSecs, "Update the thumbnail overviews every x seconds"), Setting.of("Update thumbnails", updateThumbnails, "The overviews will still be updated, but the thumbnails won't be changed. This is useful for less powerful systems."), Setting.of("Display stream resolution in overview", determineResolution), + Setting.of("Manually select stream quality", chooseStreamQuality, "Opens a dialog to select the video resolution before recording"), Setting.of("Enable live previews (experimental)", livePreviews), Setting.of("Start Tab", startTab), Setting.of("Colors (Base / Accent)", new ColorSettingsPane(Config.getInstance())) @@ -179,7 +181,6 @@ public class SettingsTab extends Tab implements TabSelectionListener { Setting.of("Recordings Directory", recordingsDir), Setting.of("Directory Structure", directoryStructure), Setting.of("Split recordings after (minutes)", splitAfter).converter(SplitAfterOption.converter()), - Setting.of("Manually select stream quality", chooseStreamQuality, "Opens a dialog to select the video resolution before recording"), Setting.of("Restrict Resolution", resolutionRange, "Only record streams with resolution within the given range"), Setting.of("Concurrent Recordings (0 = unlimited)", concurrentRecordings), Setting.of("Check online state every (seconds)", onlineCheckIntervalInSecs, "Check every x seconds, if a model came online"), @@ -219,6 +220,32 @@ public class SettingsTab extends Tab implements TabSelectionListener { ); setContent(prefs.getView()); prefs.expandTree(); + + + prefs.getSetting("httpServer").ifPresent(s -> bindEnabledProperty(s, recordLocal)); + prefs.getSetting("httpPort").ifPresent(s -> bindEnabledProperty(s, recordLocal)); + prefs.getSetting("servletContext").ifPresent(s -> bindEnabledProperty(s, recordLocal)); + prefs.getSetting("requireAuthentication").ifPresent(s -> bindEnabledProperty(s, recordLocal)); + prefs.getSetting("transportLayerSecurity").ifPresent(s -> bindEnabledProperty(s, recordLocal)); + prefs.getSetting("recordingsDir").ifPresent(s -> bindEnabledProperty(s, recordLocal.not())); + prefs.getSetting("splitRecordings").ifPresent(s -> bindEnabledProperty(s, recordLocal.not())); + prefs.getSetting("minimumResolution").ifPresent(s -> bindEnabledProperty(s, recordLocal.not())); + prefs.getSetting("recordingsDirStructure").ifPresent(s -> bindEnabledProperty(s, recordLocal.not())); + prefs.getSetting("onlineCheckIntervalInSecs").ifPresent(s -> bindEnabledProperty(s, recordLocal.not())); + prefs.getSetting("minimumSpaceLeftInBytes").ifPresent(s -> bindEnabledProperty(s, recordLocal.not())); + prefs.getSetting("postProcessing").ifPresent(s -> bindEnabledProperty(s, recordLocal.not())); + prefs.getSetting("postProcessingThreads").ifPresent(s -> bindEnabledProperty(s, recordLocal.not())); + prefs.getSetting("removeRecordingAfterPostProcessing").ifPresent(s -> bindEnabledProperty(s, recordLocal.not())); + prefs.getSetting("minimumLengthInSeconds").ifPresent(s -> bindEnabledProperty(s, recordLocal.not())); + prefs.getSetting("concurrentRecordings").ifPresent(s -> bindEnabledProperty(s, recordLocal.not())); + } + + private void bindEnabledProperty(Setting s, BooleanExpression bindTo) { + try { + s.getGui().disableProperty().bind(bindTo); + } catch (Exception e) { + LOG.error("Couldn't bind disableProperty of {}", s.getName(), e); + } } private List getTabNames() { diff --git a/client/src/main/java/ctbrec/ui/settings/api/Preferences.java b/client/src/main/java/ctbrec/ui/settings/api/Preferences.java index 75903187..9b096406 100644 --- a/client/src/main/java/ctbrec/ui/settings/api/Preferences.java +++ b/client/src/main/java/ctbrec/ui/settings/api/Preferences.java @@ -2,6 +2,10 @@ package ctbrec.ui.settings.api; import static java.util.Optional.*; +import java.util.Objects; +import java.util.Optional; +import java.util.function.Consumer; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -186,4 +190,51 @@ public class Preferences { public void expandTree() { expandAll(categoryTree.getRoot()); } + + public void traverse(Consumer visitor) { + for (Category category : categories) { + visit(category, visitor); + } + } + + private void visit(Category cat, Consumer visitor) { + if (cat.hasGroups()) { + for (Group group : cat.getGroups()) { + for (Setting setting : group.getSettings()) { + visitor.accept(setting); + } + } + } + if (cat.hasSubCategories()) { + for (Category subcat : cat.getSubCategories()) { + visit(subcat, visitor); + } + } + } + + public Optional getSetting(String key) { + SettingSearchVisitor search = new SettingSearchVisitor(key); + traverse(search); + return search.getResult(); + } + + private class SettingSearchVisitor implements Consumer { + Optional result = Optional.empty(); + private String key; + + public SettingSearchVisitor(String key) { + this.key = key; + } + + @Override + public void accept(Setting s) { + if (Objects.equals(key, ofNullable(s.getKey()).orElse(""))) { + result = Optional.of(s); + } + } + + public Optional getResult() { + return result; + } + } } diff --git a/client/src/main/java/ctbrec/ui/settings/api/Setting.java b/client/src/main/java/ctbrec/ui/settings/api/Setting.java index 89f90298..98acb0a6 100644 --- a/client/src/main/java/ctbrec/ui/settings/api/Setting.java +++ b/client/src/main/java/ctbrec/ui/settings/api/Setting.java @@ -77,7 +77,7 @@ public class Setting { return property; } - Node getGui() throws Exception { + public Node getGui() throws Exception { if (gui == null) { gui = preferencesStorage.createGui(this); if (gui instanceof Control && StringUtil.isNotBlank(tooltip)) { diff --git a/client/src/main/java/ctbrec/ui/settings/api/SimpleRangeProperty.java b/client/src/main/java/ctbrec/ui/settings/api/SimpleRangeProperty.java index 4f99c929..238243eb 100644 --- a/client/src/main/java/ctbrec/ui/settings/api/SimpleRangeProperty.java +++ b/client/src/main/java/ctbrec/ui/settings/api/SimpleRangeProperty.java @@ -13,6 +13,7 @@ public class SimpleRangeProperty extends SimpleObjectProperty { private String highKey; public SimpleRangeProperty(Range range, String lowKey, String highKey, T low, T high) { + super(null, lowKey); this.range = range; this.lowKey = lowKey; this.highKey = highKey;