Merge branch 'release-0.3.3' 0.3.3
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 12 Dec 2010 16:11:32 +0000 (17:11 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 12 Dec 2010 16:11:32 +0000 (17:11 +0100)
pom.xml
src/main/java/net/pterodactylus/sone/main/SonePlugin.java
src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/resources/i18n/sone.en.properties
src/main/resources/templates/notify/configNotReadNotification.html [new file with mode: 0644]
src/main/resources/templates/notify/firstStartNotification.html [new file with mode: 0644]

diff --git a/pom.xml b/pom.xml
index a93599b..ba13bd4 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -2,12 +2,12 @@
        <modelVersion>4.0.0</modelVersion>
        <groupId>net.pterodactylus</groupId>
        <artifactId>sone</artifactId>
-       <version>0.3.2</version>
+       <version>0.3.3</version>
        <dependencies>
                <dependency>
                        <groupId>net.pterodactylus</groupId>
                        <artifactId>utils</artifactId>
-                       <version>0.7.1</version>
+                       <version>0.7.2</version>
                </dependency>
                <dependency>
                        <groupId>junit</groupId>
index fbf8b1a..130ce11 100644 (file)
@@ -79,7 +79,7 @@ public class SonePlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL10
        }
 
        /** The version. */
-       public static final Version VERSION = new Version(0, 3, 2);
+       public static final Version VERSION = new Version(0, 3, 3);
 
        /** The logger. */
        private static final Logger logger = Logging.getLogger(SonePlugin.class);
@@ -147,10 +147,13 @@ public class SonePlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL10
                /* create a configuration. */
                Configuration oldConfiguration;
                Configuration newConfiguration = null;
+               boolean firstStart = !new File("sone.properties").exists();
+               boolean newConfig = false;
                try {
                        oldConfiguration = new Configuration(new MapConfigurationBackend(new File("sone.properties"), false));
                        newConfiguration = oldConfiguration;
                } catch (ConfigurationException ce1) {
+                       newConfig = true;
                        logger.log(Level.INFO, "Could not load configuration file, trying plugin store…", ce1);
                        try {
                                newConfiguration = new Configuration(new MapConfigurationBackend(new File("sone.properties"), true));
@@ -195,6 +198,8 @@ public class SonePlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL10
                                core.setConfiguration(newConfiguration);
                        }
                        webInterface.start();
+                       webInterface.setFirstStart(firstStart);
+                       webInterface.setNewConfig(newConfig);
                        identityManager.start();
                        startupFailed = false;
                } finally {
index 496fb60..9a8bd9b 100644 (file)
@@ -19,7 +19,6 @@ package net.pterodactylus.sone.web;
 
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.UUID;
 
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.web.page.Page;
@@ -93,7 +92,7 @@ public class SoneTemplatePage extends TemplatePage {
         *         session
         */
        protected Session getCurrentSession(ToadletContext toadletContenxt) {
-               return getCurrentSession(toadletContenxt, true);
+               return webInterface.getCurrentSession(toadletContenxt);
        }
 
        /**
@@ -109,11 +108,7 @@ public class SoneTemplatePage extends TemplatePage {
         *         session
         */
        protected Session getCurrentSession(ToadletContext toadletContenxt, boolean create) {
-               Session session = webInterface.getSessionManager().useSession(toadletContenxt);
-               if (create && (session == null)) {
-                       session = webInterface.getSessionManager().createSession(UUID.randomUUID().toString(), toadletContenxt);
-               }
-               return session;
+               return webInterface.getCurrentSession(toadletContenxt, create);
        }
 
        /**
@@ -125,15 +120,7 @@ public class SoneTemplatePage extends TemplatePage {
         *         currently logged in
         */
        protected Sone getCurrentSone(ToadletContext toadletContext) {
-               Session session = getCurrentSession(toadletContext);
-               if (session == null) {
-                       return null;
-               }
-               String soneId = (String) session.getAttribute("Sone.CurrentSone");
-               if (soneId == null) {
-                       return null;
-               }
-               return webInterface.getCore().getLocalSone(soneId, false);
+               return webInterface.getCurrentSone(toadletContext);
        }
 
        /**
@@ -145,12 +132,7 @@ public class SoneTemplatePage extends TemplatePage {
         *            The Sone to set as currently logged in
         */
        protected void setCurrentSone(ToadletContext toadletContext, Sone sone) {
-               Session session = getCurrentSession(toadletContext);
-               if (sone == null) {
-                       session.removeAttribute("Sone.CurrentSone");
-               } else {
-                       session.setAttribute("Sone.CurrentSone", sone.getId());
-               }
+               webInterface.setCurrentSone(toadletContext, sone);
        }
 
        //
index dc09d78..95978ce 100644 (file)
@@ -26,6 +26,7 @@ import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.UUID;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -70,6 +71,7 @@ import net.pterodactylus.sone.web.page.PageToadlet;
 import net.pterodactylus.sone.web.page.PageToadletFactory;
 import net.pterodactylus.sone.web.page.StaticPage;
 import net.pterodactylus.util.logging.Logging;
+import net.pterodactylus.util.notify.Notification;
 import net.pterodactylus.util.notify.NotificationManager;
 import net.pterodactylus.util.notify.TemplateNotification;
 import net.pterodactylus.util.template.DateFilter;
@@ -84,7 +86,9 @@ import net.pterodactylus.util.template.TemplateProvider;
 import net.pterodactylus.util.template.XmlFilter;
 import net.pterodactylus.util.thread.Ticker;
 import freenet.clients.http.SessionManager;
+import freenet.clients.http.SessionManager.Session;
 import freenet.clients.http.ToadletContainer;
+import freenet.clients.http.ToadletContext;
 import freenet.l10n.BaseL10n;
 
 /**
@@ -189,6 +193,87 @@ public class WebInterface implements CoreListener {
        }
 
        /**
+        * Returns the current session, creating a new session if there is no
+        * current session.
+        *
+        * @param toadletContenxt
+        *            The toadlet context
+        * @return The current session, or {@code null} if there is no current
+        *         session
+        */
+       public Session getCurrentSession(ToadletContext toadletContenxt) {
+               return getCurrentSession(toadletContenxt, true);
+       }
+
+       /**
+        * Returns the current session, creating a new session if there is no
+        * current session and {@code create} is {@code true}.
+        *
+        * @param toadletContenxt
+        *            The toadlet context
+        * @param create
+        *            {@code true} to create a new session if there is no current
+        *            session, {@code false} otherwise
+        * @return The current session, or {@code null} if there is no current
+        *         session
+        */
+       public Session getCurrentSession(ToadletContext toadletContenxt, boolean create) {
+               Session session = getSessionManager().useSession(toadletContenxt);
+               if (create && (session == null)) {
+                       session = getSessionManager().createSession(UUID.randomUUID().toString(), toadletContenxt);
+               }
+               return session;
+       }
+
+       /**
+        * Returns the currently logged in Sone.
+        *
+        * @param toadletContext
+        *            The toadlet context
+        * @return The currently logged in Sone, or {@code null} if no Sone is
+        *         currently logged in
+        */
+       public Sone getCurrentSone(ToadletContext toadletContext) {
+               return getCurrentSone(getCurrentSession(toadletContext));
+       }
+
+       /**
+        * Returns the currently logged in Sone.
+        *
+        * @param session
+        *            The session
+        * @return The currently logged in Sone, or {@code null} if no Sone is
+        *         currently logged in
+        */
+       public Sone getCurrentSone(Session session) {
+               if (session == null) {
+                       return null;
+               }
+               String soneId = (String) session.getAttribute("Sone.CurrentSone");
+               if (soneId == null) {
+                       return null;
+               }
+               return getCore().getLocalSone(soneId, false);
+       }
+
+       /**
+        * Sets the currently logged in Sone.
+        *
+        * @param toadletContext
+        *            The toadlet context
+        * @param sone
+        *            The Sone to set as currently logged in
+        */
+       public void setCurrentSone(ToadletContext toadletContext, Sone sone) {
+               Session session = getCurrentSession(toadletContext);
+               if (sone == null) {
+                       session.removeAttribute("Sone.CurrentSone");
+               } else {
+                       session.setAttribute("Sone.CurrentSone", sone.getId());
+               }
+       }
+
+       /**
         * Returns the notification manager.
         *
         * @return The notification manager
@@ -244,6 +329,51 @@ public class WebInterface implements CoreListener {
                return new HashSet<Reply>(newReplyNotification.getElements());
        }
 
+       /**
+        * Sets whether the current start of the plugin is the first start. It is
+        * considered a first start if the configuration file does not exist.
+        *
+        * @param firstStart
+        *            {@code true} if no configuration file existed when Sone was
+        *            loaded, {@code false} otherwise
+        */
+       public void setFirstStart(boolean firstStart) {
+               if (firstStart) {
+                       Template firstStartNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/firstStartNotification.html"));
+                       Notification firstStartNotification = new TemplateNotification("first-start-notification", firstStartNotificationTemplate);
+                       notificationManager.addNotification(firstStartNotification);
+               }
+       }
+
+       /**
+        * Sets whether Sone was started with a fresh configuration file.
+        *
+        * @param newConfig
+        *            {@code true} if Sone was started with a fresh configuration,
+        *            {@code false} if the existing configuration could be read
+        */
+       public void setNewConfig(boolean newConfig) {
+               if (newConfig && !hasFirstStartNotification()) {
+                       Template configNotReadNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/configNotReadNotification.html"));
+                       Notification configNotReadNotification = new TemplateNotification("config-not-read-notification", configNotReadNotificationTemplate);
+                       notificationManager.addNotification(configNotReadNotification);
+               }
+       }
+
+       //
+       // PRIVATE ACCESSORS
+       //
+
+       /**
+        * Returns whether the first start notification is currently displayed.
+        *
+        * @return {@code true} if the first-start notification is currently
+        *         displayed, {@code false} otherwise
+        */
+       private boolean hasFirstStartNotification() {
+               return notificationManager.getNotification("first-start-notification") != null;
+       }
+
        //
        // ACTIONS
        //
@@ -442,7 +572,9 @@ public class WebInterface implements CoreListener {
        @Override
        public void newSoneFound(Sone sone) {
                newSoneNotification.add(sone);
-               notificationManager.addNotification(newSoneNotification);
+               if (!hasFirstStartNotification()) {
+                       notificationManager.addNotification(newSoneNotification);
+               }
        }
 
        /**
@@ -451,7 +583,9 @@ public class WebInterface implements CoreListener {
        @Override
        public void newPostFound(Post post) {
                newPostNotification.add(post);
-               notificationManager.addNotification(newPostNotification);
+               if (!hasFirstStartNotification()) {
+                       notificationManager.addNotification(newPostNotification);
+               }
        }
 
        /**
@@ -463,7 +597,9 @@ public class WebInterface implements CoreListener {
                        return;
                }
                newReplyNotification.add(reply);
-               notificationManager.addNotification(newReplyNotification);
+               if (!hasFirstStartNotification()) {
+                       notificationManager.addNotification(newReplyNotification);
+               }
        }
 
        /**
index d0c44f5..89af2d1 100644 (file)
@@ -176,7 +176,9 @@ WebInterface.SelectBox.Yes=Yes
 WebInterface.SelectBox.No=No
 WebInterface.ClickToShow.Replies=Click here to show hidden replies.
 
+Notification.FirstStart.Text=This seems to be the first time you start Sone. To start, create a new Sone from a web of trust identity and start following other Sones.
 Notification.Startup.Text=Sone is currently starting up. It may take a while to retrieve all identities and Sones from the web of trust. If you are missing some elements, please be patient, they will probably reappear very soon.
+Notification.ConfigNotRead.Text=The configuration file “sone.properties” could not be read, probably because it was not saved correctly. This can happen on versions prior to Sone 0.3.3 and there is nothing you can do about it.
 Notification.Button.Dismiss=Dismiss
 Notification.NewSone.Text=New Sones have been discovered:
 Notification.NewPost.Text=New posts have been discovered by the following Sones:
diff --git a/src/main/resources/templates/notify/configNotReadNotification.html b/src/main/resources/templates/notify/configNotReadNotification.html
new file mode 100644 (file)
index 0000000..3de81a4
--- /dev/null
@@ -0,0 +1 @@
+<div class="text"><%= Notification.ConfigNotRead.Text|l10n|html></div>
diff --git a/src/main/resources/templates/notify/firstStartNotification.html b/src/main/resources/templates/notify/firstStartNotification.html
new file mode 100644 (file)
index 0000000..b4ce468
--- /dev/null
@@ -0,0 +1 @@
+<div class="text"><%= Notification.FirstStart.Text|l10n|html></div>