Add notification if the config file can not be read.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 12 Dec 2010 13:33:13 +0000 (14:33 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 12 Dec 2010 13:33:13 +0000 (14:33 +0100)
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]

index ca629fa..a24802b 100644 (file)
@@ -148,10 +148,12 @@ public class SonePlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL10
                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));
@@ -183,6 +185,7 @@ public class SonePlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL10
                /* create the web interface. */
                webInterface = new WebInterface(this);
                webInterface.setFirstStart(firstStart);
+               webInterface.setNewConfig(newConfig);
                core.addCoreListener(webInterface);
 
                /* create the identity manager. */
index 0e7905d..5865f1d 100644 (file)
@@ -261,6 +261,21 @@ public class WebInterface implements CoreListener {
                }
        }
 
+       /**
+        * 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 && (notificationManager.getNotification("first-start-notification") == null)) {
+                       Template configNotReadNotificationTemplate = new Template(createReader("/templates/notify/configNotReadNotification.html"));
+                       Notification configNotReadNotification = new TemplateNotification("config-not-read-notification", configNotReadNotificationTemplate);
+                       notificationManager.addNotification(configNotReadNotification);
+               }
+       }
+
        //
        // ACTIONS
        //
index 1a69477..89af2d1 100644 (file)
@@ -178,6 +178,7 @@ 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>