From: David ‘Bombe’ Roden Date: Sun, 12 Dec 2010 16:10:21 +0000 (+0100) Subject: Merge branch 'fix-start-with-broken-config' into next X-Git-Tag: beta-freefall-0.6.2-1~197 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=2528f9e7901cdbc39c38272b13a939665f00ab80;hp=0ac5c61faa54b62f29bf8c8e9903919315810c80 Merge branch 'fix-start-with-broken-config' into next --- diff --git a/pom.xml b/pom.xml index a93599b..447fad7 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ net.pterodactylus utils - 0.7.1 + 0.7.2 junit diff --git a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java index fbf8b1a..5a0e8ae 100644 --- a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java +++ b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java @@ -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 { diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index ee8b9bf..95978ce 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -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(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); + } } /** diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties index d0c44f5..89af2d1 100644 --- a/src/main/resources/i18n/sone.en.properties +++ b/src/main/resources/i18n/sone.en.properties @@ -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 index 0000000..3de81a4 --- /dev/null +++ b/src/main/resources/templates/notify/configNotReadNotification.html @@ -0,0 +1 @@ +
<%= Notification.ConfigNotRead.Text|l10n|html>
diff --git a/src/main/resources/templates/notify/firstStartNotification.html b/src/main/resources/templates/notify/firstStartNotification.html new file mode 100644 index 0000000..b4ce468 --- /dev/null +++ b/src/main/resources/templates/notify/firstStartNotification.html @@ -0,0 +1 @@ +
<%= Notification.FirstStart.Text|l10n|html>