Author: toad
Date: 2008-04-22 18:44:20 +0000 (Tue, 22 Apr 2008)
New Revision: 19501

Modified:
   trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java
   trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties
   trunk/freenet/src/freenet/node/useralerts/UserAlert.java
   trunk/freenet/src/freenet/node/useralerts/UserAlertManager.java
Log:
"Remove trivial notifications" button removes all bookmark update and 
download/upload complete notices.

Modified: trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java  2008-04-22 
15:38:56 UTC (rev 19500)
+++ trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java  2008-04-22 
18:44:20 UTC (rev 19501)
@@ -7,6 +7,7 @@
 import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.util.HashSet;

 import org.tanukisoftware.wrapper.WrapperManager;

@@ -384,6 +385,13 @@
                         }
                     }, 1);
             return;
+        } else if(request.isPartSet("dismiss-events")) {
+               String alertsToDump = request.getPartAsString("events", 4096);
+               String[] alertAnchors = alertsToDump.split(",");
+               HashSet toDump = new HashSet();
+               for(int i=0;i<alertAnchors.length;i++) 
toDump.add(alertAnchors[i]);
+               core.alerts.dumpEvents(toDump);
+               redirectToRoot(ctx);
         } else {
             redirectToRoot(ctx);
         }
@@ -539,7 +547,7 @@

         // Alerts
         if (ctx.isAllowedFullAccess()) {
-            
contentNode.addChild(core.alerts.createAlertsShort(l10n("alertsSummary"), 
advancedModeOutputEnabled));
+            
contentNode.addChild(core.alerts.createAlertsShort(l10n("alertsSummary"), 
advancedModeOutputEnabled, true));
         }

         // Bookmarks

Modified: trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties
===================================================================
--- trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties   2008-04-22 
15:38:56 UTC (rev 19500)
+++ trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties   2008-04-22 
18:44:20 UTC (rev 19501)
@@ -1170,6 +1170,7 @@
 UserAlertManager.alertsTitle=Outstanding alerts
 UserAlertManager.clickForMore=Click on an item for more information or to get 
rid of it.
 UserAlertManager.criticalErrorCountLabel=Critical Errors:
+UserAlertManager.dumpEventsButton=Remove trivial notifications
 UserAlertManager.errorCountLabel=Errors:
 UserAlertManager.minorCountLabel=Minor:
 UserAlertManager.totalLabel=Total:

Modified: trunk/freenet/src/freenet/node/useralerts/UserAlert.java
===================================================================
--- trunk/freenet/src/freenet/node/useralerts/UserAlert.java    2008-04-22 
15:38:56 UTC (rev 19500)
+++ trunk/freenet/src/freenet/node/useralerts/UserAlert.java    2008-04-22 
18:44:20 UTC (rev 19501)
@@ -65,6 +65,7 @@

        /**
         * @return A unique, short name for the alert. Can be simply 
hashCode(), not visible to the user.
+        * MUST NOT contain spaces or commas.
         */
        public String anchor();


Modified: trunk/freenet/src/freenet/node/useralerts/UserAlertManager.java
===================================================================
--- trunk/freenet/src/freenet/node/useralerts/UserAlertManager.java     
2008-04-22 15:38:56 UTC (rev 19500)
+++ trunk/freenet/src/freenet/node/useralerts/UserAlertManager.java     
2008-04-22 18:44:20 UTC (rev 19501)
@@ -6,10 +6,13 @@
 import java.util.Arrays;
 import java.util.Comparator;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.LinkedHashSet;

+import freenet.support.Base64;
 import freenet.support.HTMLNode;
 import freenet.support.Logger;
+import freenet.support.StringArray;
 import freenet.l10n.L10n;
 import freenet.node.NodeClientCore;

@@ -80,6 +83,10 @@
                short prio0 = a0.getPriorityClass();
                short prio1 = a1.getPriorityClass();
                if(prio0 - prio1 == 0) {
+                       boolean isEvent0 = a0.isEventNotification();
+                       boolean isEvent1 = a1.isEventNotification();
+                       if(isEvent0 && !isEvent1) return 1;
+                       if((!isEvent0) && isEvent1) return -1;
                        // First go by class
                        int classHash0 = a0.getClass().hashCode();
                        int classHash1 = a1.getClass().hashCode();
@@ -122,13 +129,16 @@
         * Write each alert in uber-concise form as HTML, with a link to 
         * /alerts/[ anchor pointing to the real alert].
         */
-       public HTMLNode createAlertsShort(String title, boolean advancedMode) {
+       public HTMLNode createAlertsShort(String title, boolean advancedMode, 
boolean drawDumpEventsForm) {
                UserAlert[] alerts = getAlerts();
                short maxLevel = Short.MAX_VALUE;
+               int events = 0;
                for(int i=0;i<alerts.length;i++) {
                        short level = alerts[i].getPriorityClass();
                        if(level < maxLevel) maxLevel = level;
+                       if(alerts[i].isEventNotification()) events++;
                }
+               if(events < 2) drawDumpEventsForm = false;
                if(maxLevel == Short.MAX_VALUE) {
                        return new HTMLNode("#", "");
                }
@@ -150,6 +160,19 @@
                if (totalNumber == 0) {
                        return new HTMLNode("#", "");
                }
+               if(drawDumpEventsForm) {
+                       HTMLNode dumpFormNode = contentNode.addChild("form", 
new String[] { "action", "method" }, new String[] { "/", "post" 
}).addChild("div");
+                       dumpFormNode.addChild("input", new String[] { "type", 
"name", "value" }, new String[] { "hidden", "formPassword", core.formPassword 
});
+                       StringBuffer sb = new StringBuffer();
+                       for(int i=0;i<alerts.length;i++) {
+                               if(!alerts[i].isEventNotification()) continue;
+                               if(sb.length() != 0)
+                                       sb.append(",");
+                               sb.append(alerts[i].anchor());
+                       }
+                       dumpFormNode.addChild("input", new String[] { "type", 
"name", "value" }, new String[] { "hidden", "events", sb.toString() });
+                       dumpFormNode.addChild("input", new String[] { "type", 
"name", "value" }, new String[] { "submit", "dismiss-events", 
l10n("dumpEventsButton") });
+               }
                return boxNode;
        }

@@ -280,4 +303,15 @@
                return L10n.getString("UserAlertManager."+key);
        }

+       public void dumpEvents(HashSet toDump) {
+               // An iterator might be faster, but we don't want to call 
methods on the alert within the lock.
+               UserAlert[] alerts = getAlerts();
+               for(int i=0;i<alerts.length;i++) {
+                       if(!alerts[i].isEventNotification()) continue;
+                       if(!toDump.contains(alerts[i].anchor())) continue;
+                       unregister(alerts[i]);
+                       alerts[i].onDismiss();
+               }
+       }
+
 }


Reply via email to