Author: toad
Date: 2008-09-03 17:15:50 +0000 (Wed, 03 Sep 2008)
New Revision: 22374

Modified:
   trunk/freenet/src/freenet/clients/http/ConfigToadlet.java
   trunk/freenet/src/freenet/node/SecurityLevels.java
Log:
Fix a minor bug in the friends=high confirm form.
Only write the config file once, not once per change.


Modified: trunk/freenet/src/freenet/clients/http/ConfigToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/ConfigToadlet.java   2008-09-03 
17:08:59 UTC (rev 22373)
+++ trunk/freenet/src/freenet/clients/http/ConfigToadlet.java   2008-09-03 
17:15:50 UTC (rev 22374)
@@ -123,7 +123,7 @@
                        HTMLNode content = null;
                        HTMLNode ul = null;
                        HTMLNode formNode = null;
-                       boolean addedWarning = false;
+                       boolean changedAnything = false;
                        String configName = 
"security-levels.networkThreatLevel";
                        String confirm = 
"security-levels.networkThreatLevel.confirm";
                        String tryConfirm = 
"security-levels.networkThreatLevel.tryConfirm";
@@ -148,14 +148,15 @@
                                                        HTMLNode infoboxContent 
= infobox.addChild("div", "class", "infobox-content");
                                                        
infoboxContent.addChild(warning);
                                                        
infoboxContent.addChild("input", new String[] { "type", "name", "value" }, new 
String[] { "hidden", tryConfirm, "on" });
-                                                       addedWarning = true;
                                                } else {
                                                        // Apply immediately, 
no confirm needed.
                                                        
node.securityLevels.setThreatLevel(newThreatLevel);
+                                                       changedAnything = true;
                                                }
                                        } else if(request.isPartSet(confirm)) {
                                                // Apply immediately, user 
confirmed it.
                                                
node.securityLevels.setThreatLevel(newThreatLevel);
+                                               changedAnything = true;
                                        }
                                }
                        }
@@ -180,18 +181,19 @@

                                                        
seclevelGroup.addChild("input", new String[] { "type", "name", "value" }, new 
String[] { "hidden", configName, friendsThreatLevel });
                                                        HTMLNode infobox = 
seclevelGroup.addChild("div", "class", "infobox infobox-information");
-                                                       infobox.addChild("div", 
"class", "infobox-header", l10nSec("friendsThreatLevelConfirmTitle", "mode", 
SecurityLevels.localisedName(newThreatLevel)));
+                                                       infobox.addChild("div", 
"class", "infobox-header", l10nSec("friendsThreatLevelConfirmTitle", "mode", 
SecurityLevels.localisedName(newFriendsLevel)));
                                                        HTMLNode infoboxContent 
= infobox.addChild("div", "class", "infobox-content");
                                                        
infoboxContent.addChild(warning);
                                                        
infoboxContent.addChild("input", new String[] { "type", "name", "value" }, new 
String[] { "hidden", tryConfirm, "on" });
-                                                       addedWarning = true;
                                                } else {
                                                        // Apply immediately, 
no confirm needed.
                                                        
node.securityLevels.setThreatLevel(newFriendsLevel);
+                                                       changedAnything = true;
                                                }
                                        } else if(request.isPartSet(confirm)) {
                                                // Apply immediately, user 
confirmed it.
                                                
node.securityLevels.setThreatLevel(newFriendsLevel);
+                                               changedAnything = true;
                                        }
                                }
                        }
@@ -205,9 +207,13 @@
                                if(newPhysicalLevel != 
node.securityLevels.getPhysicalThreatLevel()) {
                                        // No confirmation for changes to 
physical threat level.
                                        
node.securityLevels.setThreatLevel(newPhysicalLevel);
+                                       changedAnything = true;
                                }
                        }

+                       if(changedAnything)
+                               core.storeConfig();
+                       
                        if(pageNode != null) {
                                formNode.addChild("input", new String[] { 
"type", "name", "value" }, new String[] { "hidden", "seclevels", "on" });
                                formNode.addChild("input", new String[] { 
"type", "value" }, new String[] { "submit", l10n("apply")});

Modified: trunk/freenet/src/freenet/node/SecurityLevels.java
===================================================================
--- trunk/freenet/src/freenet/node/SecurityLevels.java  2008-09-03 17:08:59 UTC 
(rev 22373)
+++ trunk/freenet/src/freenet/node/SecurityLevels.java  2008-09-03 17:15:50 UTC 
(rev 22374)
@@ -328,7 +328,6 @@
                synchronized(this) {
                        networkThreatLevel = newThreatLevel;
                }
-               node.config.store();
        }

        public void setThreatLevel(FRIENDS_THREAT_LEVEL newThreatLevel) {
@@ -336,7 +335,6 @@
                synchronized(this) {
                        friendsThreatLevel = newThreatLevel;
                }
-               node.config.store();
        }

        public void setThreatLevel(PHYSICAL_THREAT_LEVEL newThreatLevel) {
@@ -344,11 +342,14 @@
                synchronized(this) {
                        physicalThreatLevel = newThreatLevel;
                }
-               node.config.store();
        }

        public static String localisedName(NETWORK_THREAT_LEVEL newThreatLevel) 
{
                return 
L10n.getString("SecurityLevels.networkThreatLevel.name."+newThreatLevel.name());
        }
+       
+       public static String localisedName(FRIENDS_THREAT_LEVEL 
newFriendsLevel) {
+               return 
L10n.getString("SecurityLevels.friendsThreatLevel.name."+newFriendsLevel.name());
+       }

 }


Reply via email to