Add disabling of settings, if the don't make sense

This commit is contained in:
0xboobface 2020-07-05 20:33:47 +02:00
parent 9395431a6f
commit 716c75c3d2
4 changed files with 81 additions and 2 deletions

View File

@ -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<String> getTabNames() {

View File

@ -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<Setting> visitor) {
for (Category category : categories) {
visit(category, visitor);
}
}
private void visit(Category cat, Consumer<Setting> 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<Setting> getSetting(String key) {
SettingSearchVisitor search = new SettingSearchVisitor(key);
traverse(search);
return search.getResult();
}
private class SettingSearchVisitor implements Consumer<Setting> {
Optional<Setting> 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<Setting> getResult() {
return result;
}
}
}

View File

@ -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)) {

View File

@ -13,6 +13,7 @@ public class SimpleRangeProperty<T> extends SimpleObjectProperty<T> {
private String highKey;
public SimpleRangeProperty(Range<T> range, String lowKey, String highKey, T low, T high) {
super(null, lowKey);
this.range = range;
this.lowKey = lowKey;
this.highKey = highKey;