Author: toad
Date: 2006-12-15 21:39:13 +0000 (Fri, 15 Dec 2006)
New Revision: 11424
Modified:
trunk/freenet/src/freenet/clients/http/Bookmark.java
trunk/freenet/src/freenet/clients/http/BookmarkManager.java
trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java
Log:
Notify user via UserAlert when a bookmarked site is updated.
Modified: trunk/freenet/src/freenet/clients/http/Bookmark.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/Bookmark.java 2006-12-15
20:56:28 UTC (rev 11423)
+++ trunk/freenet/src/freenet/clients/http/Bookmark.java 2006-12-15
21:39:13 UTC (rev 11424)
@@ -4,19 +4,92 @@
package freenet.clients.http;
import freenet.keys.FreenetURI;
+import freenet.keys.USK;
+import freenet.node.NodeClientCore;
+import freenet.node.useralerts.UserAlert;
+import freenet.node.useralerts.UserAlertManager;
+import freenet.support.HTMLNode;
+
import java.net.MalformedURLException;
public class Bookmark {
- FreenetURI key;
+
+ private FreenetURI key;
+ private String desc;
+ private boolean updated;
+ private final BookmarkUpdatedUserAlert alert;
+ private UserAlertManager alerts;
- String desc;
+ private class BookmarkUpdatedUserAlert implements UserAlert {
- Bookmark(String k, String d) throws MalformedURLException {
+ public boolean userCanDismiss() {
+ return true;
+ }
+
+ public String getTitle() {
+ return "Bookmark updated: "+desc;
+ }
+
+ public String getText() {
+ return "The bookmarked site "+desc+" has been updated
to edition "+key.getSuggestedEdition();
+ }
+
+ public HTMLNode getHTMLText() {
+ HTMLNode n = new HTMLNode("div");
+ n.addChild("#", "The bookmarked site ");
+ n.addChild("a", "href",
'/'+key.toString()).addChild("#", desc);
+ n.addChild("#", " has been updated to edition
"+key.getSuggestedEdition()+".");
+ return n;
+ }
+
+ public short getPriorityClass() {
+ return UserAlert.MINOR;
+ }
+
+ public boolean isValid() {
+ synchronized(Bookmark.this) {
+ return updated;
+ }
+ }
+
+ public void isValid(boolean validity) {
+ if(validity) return;
+ disableBookmark();
+ }
+
+ public String dismissButtonText() {
+ return "Delete notification";
+ }
+
+ public boolean shouldUnregisterOnDismiss() {
+ return true;
+ }
+
+ public void onDismiss() {
+ disableBookmark();
+ }
+
+ }
+
+ private synchronized void disableBookmark() {
+ updated = false;
+ alerts.unregister(alert);
+ }
+
+ private synchronized void enableBookmark() {
+ if(updated) return;
+ updated = true;
+ alerts.register(alert);
+ }
+
+ Bookmark(String k, String d, UserAlertManager uam) throws
MalformedURLException {
this.key = new FreenetURI(k);
this.desc = d;
+ alert = new BookmarkUpdatedUserAlert();
+ this.alerts = uam;
}
- Bookmark(String from) throws MalformedURLException {
+ Bookmark(String from, UserAlertManager uam) throws
MalformedURLException {
int eqpos = from.indexOf("=");
if (eqpos < 0) {
@@ -26,17 +99,23 @@
this.key = new FreenetURI(from.substring(0, eqpos));
this.desc = from.substring(eqpos + 1);
}
+ alert = new BookmarkUpdatedUserAlert();
+ this.alerts = uam;
}
public String getKey() {
return key.toString();
}
- public void setKey(FreenetURI uri) {
+ public synchronized FreenetURI getURI() {
+ return key;
+ }
+
+ public synchronized void setKey(FreenetURI uri) {
key = uri;
}
- public String getKeyType() {
+ public synchronized String getKeyType() {
return key.getKeyType();
}
@@ -51,4 +130,14 @@
public String toString() {
return this.key.toString() + '=' + this.desc;
}
+
+ public synchronized void setEdition(long ed, NodeClientCore node) {
+ if(key.getSuggestedEdition() >= ed) return;
+ key = key.setSuggestedEdition(ed);
+ enableBookmark();
+ }
+
+ public USK getUSK() throws MalformedURLException {
+ return USK.create(key);
+ }
}
\ No newline at end of file
Modified: trunk/freenet/src/freenet/clients/http/BookmarkManager.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/BookmarkManager.java 2006-12-15
20:56:28 UTC (rev 11423)
+++ trunk/freenet/src/freenet/clients/http/BookmarkManager.java 2006-12-15
21:39:13 UTC (rev 11424)
@@ -10,6 +10,8 @@
import freenet.keys.USK;
import freenet.keys.FreenetURI;
import freenet.node.NodeClientCore;
+import freenet.node.useralerts.UserAlert;
+import freenet.support.HTMLNode;
import freenet.config.StringArrCallback;
import freenet.config.StringArrOption;
import freenet.config.InvalidConfigValueException;
@@ -51,7 +53,7 @@
bookmarks.clear();
for (int i = 0; i < newvals.length; i++) {
try {
- bookmarks.add(new Bookmark(newvals[i]));
+ bookmarks.add(new Bookmark(newvals[i],
node.alerts));
} catch (MalformedURLException mue) {
throw new
InvalidConfigValueException(mue.getMessage());
}
@@ -63,18 +65,17 @@
public void onFoundEdition(long edition, USK key) {
for (Enumeration e = bookmarks.elements();
e.hasMoreElements(); ) {
- Bookmark i = (Bookmark) e.nextElement();
+ Bookmark b = (Bookmark) e.nextElement();
- if (!i.getKeyType().equals("USK")) continue;
+ if (!b.getKeyType().equals("USK")) continue;
try {
- FreenetURI furi = new
FreenetURI(i.getKey());
+ FreenetURI furi = new
FreenetURI(b.getKey());
USK usk = USK.create(furi);
if (usk.equals(key, false)) {
- i.setKey(key.getURI());
- i.key =
i.key.setMetaString(furi.getAllMetaStrings());
- } else {
+
b.setEdition(key.suggestedEdition, node);
+ break;
}
} catch (MalformedURLException mue) {
}
@@ -92,7 +93,7 @@
String[] initialbookmarks = sc.getStringArr("bookmarks");
for (int i = 0; i < initialbookmarks.length; i++) {
try {
- addBookmark(new Bookmark(initialbookmarks[i]),
false);
+ addBookmark(new Bookmark(initialbookmarks[i],
n.alerts), false);
} catch (MalformedURLException mue) {
// just ignore that one
}
@@ -114,7 +115,7 @@
Bookmark[] b = (Bookmark[]) bookmarks.toArray(new
Bookmark[bookmarks.size()]);
FreenetURI[] uris = new FreenetURI[b.length];
for(int i=0;i<uris.length;i++) {
- uris[i] = b[i].key;
+ uris[i] = b[i].getURI();
}
return uris;
}
@@ -126,7 +127,7 @@
if (!i.getKeyType().equals("USK")) continue;
try {
- USK u = USK.create(i.key);
+ USK u = i.getUSK();
this.node.uskManager.unsubscribe(u, this.uskcb,
true);
} catch (MalformedURLException mue) {
@@ -139,7 +140,7 @@
this.bookmarks.add(b);
if (b.getKeyType().equals("USK")) {
try {
- USK u = USK.create(b.key);
+ USK u = b.getUSK();
this.node.uskManager.subscribe(u, this.uskcb,
true, this);
} catch (MalformedURLException mue) {
@@ -151,7 +152,7 @@
public void removeBookmark(Bookmark b, boolean store) {
if (b.getKeyType().equals("USK")) {
try {
- USK u = USK.create(b.key);
+ USK u = b.getUSK();
this.node.uskManager.unsubscribe(u, this.uskcb,
true);
} catch (MalformedURLException mue) {
Modified: trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java 2006-12-15
20:56:28 UTC (rev 11423)
+++ trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java 2006-12-15
21:39:13 UTC (rev 11424)
@@ -136,7 +136,7 @@
String key = request.getPartAsString("key",
MAX_KEY_LENGTH);
String name = request.getPartAsString("name",
MAX_NAME_LENGTH);
try {
- bookmarks.addBookmark(new Bookmark(key, name),
true);
+ bookmarks.addBookmark(new Bookmark(key, name,
core.alerts), true);
} catch (MalformedURLException mue) {
this.sendBookmarkEditPage(ctx, MODE_ADD, null,
key, name, "Given key does not appear to be a valid Freenet key.");
return;
@@ -166,7 +166,7 @@
String key =
request.getPartAsString("key", MAX_KEY_LENGTH);
String name =
request.getPartAsString("name", MAX_NAME_LENGTH);
try {
- Bookmark newbkmk = new
Bookmark(key, name);
+ Bookmark newbkmk = new
Bookmark(key, name, core.alerts);
bookmarks.removeBookmark(b,
false);
bookmarks.addBookmark(newbkmk,
true);
} catch (MalformedURLException mue) {