Merge branch 'fix-start-with-broken-config' into next
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 12 Dec 2010 16:10:21 +0000 (17:10 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 12 Dec 2010 16:10:21 +0000 (17:10 +0100)
pom.xml
src/main/java/net/pterodactylus/sone/main/SonePlugin.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..447fad7 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
                <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..5a0e8ae 100644 (file)
@@ -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 ee8b9bf..95978ce 100644 (file)
@@ -71,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;
@@ -328,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
        //
@@ -526,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);
+               }
        }
 
        /**
@@ -535,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);
+               }
        }
 
        /**
@@ -547,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>