Author: toad
Date: 2006-12-14 20:17:16 +0000 (Thu, 14 Dec 2006)
New Revision: 11400

Added:
   trunk/freenet/src/freenet/node/useralerts/ProxyUserAlert.java
Modified:
   trunk/freenet/src/freenet/node/IPDetectorPluginManager.java
Log:
Never show more than one connection status UserAlert at the same time.

Modified: trunk/freenet/src/freenet/node/IPDetectorPluginManager.java
===================================================================
--- trunk/freenet/src/freenet/node/IPDetectorPluginManager.java 2006-12-14 
19:45:37 UTC (rev 11399)
+++ trunk/freenet/src/freenet/node/IPDetectorPluginManager.java 2006-12-14 
20:17:16 UTC (rev 11400)
@@ -6,6 +6,7 @@
 import java.util.Vector;

 import freenet.io.comm.Peer;
+import freenet.node.useralerts.ProxyUserAlert;
 import freenet.node.useralerts.SimpleUserAlert;
 import freenet.node.useralerts.UserAlert;
 import freenet.pluginmanager.DetectedIP;
@@ -29,6 +30,7 @@
        private SimpleUserAlert portRestrictedAlert;
        private SimpleUserAlert restrictedAlert;
        private SimpleUserAlert connectedAlert;
+       private ProxyUserAlert proxyAlert;

        IPDetectorPluginManager(Node node, NodeIPDetector detector) {
                logMINOR = Logger.shouldLog(Logger.MINOR, getClass());
@@ -53,6 +55,7 @@
                connectedAlert = new SimpleUserAlert(true, "Direct internet 
connection detected",
                                "You appear to be directly connected to the 
internet. Congratulations, you should be able to connect "+
                                "to any other freenet node.", 
UserAlert.WARNING);
+               proxyAlert = new ProxyUserAlert(node.clientCore.alerts);
        }

        void start() {
@@ -446,15 +449,15 @@
                                }

                                if(countClosed > 0 && (countOpen + 
countRestricted + countPortRestricted + countSymmetric) == 0) {
-                                       
node.clientCore.alerts.register(noConnectionAlert);
+                                       proxyAlert.setAlert(noConnectionAlert);
                                } else if(countSymmetric > 0 && (countOpen + 
countRestricted + countPortRestricted == 0)) {
-                                       
node.clientCore.alerts.register(symmetricAlert);
+                                       proxyAlert.setAlert(symmetricAlert);
                                } else if(countPortRestricted > 0 && (countOpen 
+ countRestricted == 0)) {
-                                       
node.clientCore.alerts.register(portRestrictedAlert);
+                                       
proxyAlert.setAlert(portRestrictedAlert);
                                } else if(countRestricted > 0 && (countOpen == 
0)) {
-                                       
node.clientCore.alerts.register(restrictedAlert);
+                                       proxyAlert.setAlert(restrictedAlert);
                                } else if(countOpen > 0) {
-                                       
node.clientCore.alerts.register(connectedAlert);
+                                       proxyAlert.setAlert(connectedAlert);
                                }
                                detector.processDetectedIPs(list);
                        } finally {

Added: trunk/freenet/src/freenet/node/useralerts/ProxyUserAlert.java
===================================================================
--- trunk/freenet/src/freenet/node/useralerts/ProxyUserAlert.java               
                (rev 0)
+++ trunk/freenet/src/freenet/node/useralerts/ProxyUserAlert.java       
2006-12-14 20:17:16 UTC (rev 11400)
@@ -0,0 +1,69 @@
+package freenet.node.useralerts;
+
+import freenet.support.HTMLNode;
+
+/**
+ * ProxyUserAlert - a UserAlert implementation that has a pointer to another 
UA.
+ * It can be set to null, in which case it is disabled, or to another UA. Thus 
we can
+ * have a bunch of UAs and switch between them knowing that more than one will 
never
+ * be displayed at the same time.
+ */
+public class ProxyUserAlert implements UserAlert {
+
+       private UserAlert alert;
+       private final UserAlertManager uam;
+       
+       public ProxyUserAlert(UserAlertManager uam) {
+               this.uam = uam;
+       }
+       
+       public void setAlert(UserAlert a) {
+               if(alert == null && a != null)
+                       uam.register(this);
+               alert = a;
+               if(a == null)
+                       uam.unregister(this);
+       }
+       
+       public boolean userCanDismiss() {
+               return alert.userCanDismiss();
+       }
+
+       public String getTitle() {
+               return alert.getTitle();
+       }
+
+       public String getText() {
+               return alert.getText();
+       }
+
+       public HTMLNode getHTMLText() {
+               return alert.getHTMLText();
+       }
+
+       public short getPriorityClass() {
+               return alert.getPriorityClass();
+       }
+
+       public boolean isValid() {
+               return alert != null && alert.isValid();
+       }
+
+       public void isValid(boolean validity) {
+               if(alert != null)
+                       alert.isValid(validity);
+       }
+
+       public String dismissButtonText() {
+               return alert.dismissButtonText();
+       }
+
+       public boolean shouldUnregisterOnDismiss() {
+               return alert.shouldUnregisterOnDismiss();
+       }
+
+       public void onDismiss() {
+               if(alert != null) alert.onDismiss();
+       }
+
+}


Reply via email to