From d679c9cab83d96c2a452543474b1fa14d231a047 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 11 Apr 2011 09:16:12 +0200 Subject: [PATCH] Add option to activate and deactivate the FCP interface. --- .../java/net/pterodactylus/sone/core/Core.java | 37 ++++++++++++++++++++++ .../net/pterodactylus/sone/web/OptionsPage.java | 3 ++ src/main/resources/i18n/sone.en.properties | 2 ++ src/main/resources/templates/options.html | 4 +++ 4 files changed, 46 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index c5f5564..1aba559 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -1706,6 +1706,7 @@ public class Core implements IdentityListener, UpdateListener { configuration.getIntValue("Option/PositiveTrust").setValue(options.getIntegerOption("PositiveTrust").getReal()); configuration.getIntValue("Option/NegativeTrust").setValue(options.getIntegerOption("NegativeTrust").getReal()); configuration.getStringValue("Option/TrustComment").setValue(options.getStringOption("TrustComment").getReal()); + configuration.getBooleanValue("Option/ActivateFcpInterface").setValue(options.getBooleanOption("ActivateFcpInterface").getReal()); configuration.getBooleanValue("Option/SoneRescueMode").setValue(options.getBooleanOption("SoneRescueMode").getReal()); configuration.getBooleanValue("Option/ClearOnNextRestart").setValue(options.getBooleanOption("ClearOnNextRestart").getReal()); configuration.getBooleanValue("Option/ReallyClearOnNextRestart").setValue(options.getBooleanOption("ReallyClearOnNextRestart").getReal()); @@ -1780,6 +1781,14 @@ public class Core implements IdentityListener, UpdateListener { options.addIntegerOption("PositiveTrust", new DefaultOption(75)); options.addIntegerOption("NegativeTrust", new DefaultOption(-25)); options.addStringOption("TrustComment", new DefaultOption("Set from Sone Web Interface")); + options.addBooleanOption("ActivateFcpInterface", new DefaultOption(false, new OptionWatcher() { + + @Override + @SuppressWarnings("synthetic-access") + public void optionChanged(Option option, Boolean oldValue, Boolean newValue) { + fcpInterface.setActive(newValue); + } + })); options.addBooleanOption("SoneRescueMode", new DefaultOption(false)); options.addBooleanOption("ClearOnNextRestart", new DefaultOption(false)); options.addBooleanOption("ReallyClearOnNextRestart", new DefaultOption(false)); @@ -1800,6 +1809,7 @@ public class Core implements IdentityListener, UpdateListener { options.getIntegerOption("PositiveTrust").set(configuration.getIntValue("Option/PositiveTrust").getValue(null)); options.getIntegerOption("NegativeTrust").set(configuration.getIntValue("Option/NegativeTrust").getValue(null)); options.getStringOption("TrustComment").set(configuration.getStringValue("Option/TrustComment").getValue(null)); + options.getBooleanOption("ActivateFcpInterface").set(configuration.getBooleanValue("Option/ActivateFcpInterface").getValue(null)); options.getBooleanOption("SoneRescueMode").set(configuration.getBooleanValue("Option/SoneRescueMode").getValue(null)); /* load known Sones. */ @@ -2074,6 +2084,33 @@ public class Core implements IdentityListener, UpdateListener { } /** + * Returns whether the {@link FcpInterface FCP interface} is currently + * active. + * + * @see FcpInterface#setActive(boolean) + * @return {@code true} if the FCP interface is currently active, + * {@code false} otherwise + */ + public boolean isFcpInterfaceActive() { + return options.getBooleanOption("ActivateFcpInterface").get(); + } + + /** + * Sets whether the {@link FcpInterface FCP interface} is currently + * active. + * + * @see FcpInterface#setActive(boolean) + * @param fcpInterfaceActive + * {@code true} to activate the FCP interface, {@code false} + * to deactivate the FCP interface + * @return This preferences object + */ + public Preferences setFcpInterfaceActive(boolean fcpInterfaceActive) { + options.getBooleanOption("ActivateFcpInterface").set(fcpInterfaceActive); + return this; + } + + /** * Returns whether the rescue mode is active. * * @return {@code true} if the rescue mode is active, {@code false} diff --git a/src/main/java/net/pterodactylus/sone/web/OptionsPage.java b/src/main/java/net/pterodactylus/sone/web/OptionsPage.java index 39cacc6..d603b1a 100644 --- a/src/main/java/net/pterodactylus/sone/web/OptionsPage.java +++ b/src/main/java/net/pterodactylus/sone/web/OptionsPage.java @@ -74,6 +74,8 @@ public class OptionsPage extends SoneTemplatePage { trustComment = null; } preferences.setTrustComment(trustComment); + boolean fcpInterfaceActive = Boolean.parseBoolean(request.getHttpRequest().getPartAsStringFailsafe("fcp-interface-active", 5)); + preferences.setFcpInterfaceActive(fcpInterfaceActive); boolean soneRescueMode = Boolean.parseBoolean(request.getHttpRequest().getPartAsStringFailsafe("sone-rescue-mode", 5)); preferences.setSoneRescueMode(soneRescueMode); boolean clearOnNextRestart = Boolean.parseBoolean(request.getHttpRequest().getPartAsStringFailsafe("clear-on-next-restart", 5)); @@ -91,6 +93,7 @@ public class OptionsPage extends SoneTemplatePage { templateContext.set("positive-trust", preferences.getPositiveTrust()); templateContext.set("negative-trust", preferences.getNegativeTrust()); templateContext.set("trust-comment", preferences.getTrustComment()); + templateContext.set("fcp-interface-active", preferences.isFcpInterfaceActive()); templateContext.set("sone-rescue-mode", preferences.isSoneRescueMode()); templateContext.set("clear-on-next-restart", preferences.isClearOnNextRestart()); templateContext.set("really-clear-on-next-restart", preferences.isReallyClearOnNextRestart()); diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties index cfdb100..b46318c 100644 --- a/src/main/resources/i18n/sone.en.properties +++ b/src/main/resources/i18n/sone.en.properties @@ -41,6 +41,8 @@ Page.Options.Section.TrustOptions.Title=Trust Settings Page.Options.Option.PositiveTrust.Description=The amount of positive trust you want to assign to other Sones by clicking the checkmark below a post or reply. Page.Options.Option.NegativeTrust.Description=The amount of trust you want to assign to other Sones by clicking the red X below a post or reply. This value should be negative. Page.Options.Option.TrustComment.Description=The comment that will be set in the web of trust for any trust you assign from Sone. +Page.Options.Section.FcpOptions.Title=FCP Interface Settings +Page.Options.Option.FcpInterfaceActive.Description=Activate the FCP interface to allow other plugins and remote clients to access your Sone plugin. Page.Options.Section.RescueOptions.Title=Rescue Settings Page.Options.Option.SoneRescueMode.Description=Try to rescue your Sones at the next start of the Sone plugin. This will read your all your old Sones from Freenet and ignore any disappearing postings and replies. You have to unlock your local Sones after they have been restored and you have to manually disable the rescue mode once you are satisfied with what has been restored! Page.Options.Section.Cleaning.Title=Clean Up diff --git a/src/main/resources/templates/options.html b/src/main/resources/templates/options.html index 7e71d32..bd9de95 100644 --- a/src/main/resources/templates/options.html +++ b/src/main/resources/templates/options.html @@ -57,6 +57,10 @@

<%= Page.Options.Option.TrustComment.Description|l10n|html>

+

<%= Page.Options.Section.FcpOptions.Title|l10n|html>

+ +

checked="checked"<%/if> /> <%= Page.Options.Option.FcpInterfaceActive.Description|l10n|html>

+

<%= Page.Options.Section.RescueOptions.Title|l10n|html>

<%= Page.Options.Option.SoneRescueMode.Description|l10n|html>

-- 2.7.4