Add a “Sone rescue mode.”
[Sone.git] / src / main / java / net / pterodactylus / sone / core / Core.java
index 7872c94..ccf2cd3 100644 (file)
@@ -95,6 +95,9 @@ public class Core implements IdentityListener {
        /** The Sone downloader. */
        private final SoneDownloader soneDownloader;
 
+       /** Whether the core has been stopped. */
+       private volatile boolean stopped;
+
        /** The Sones’ statuses. */
        /* synchronize access on itself. */
        private final Map<Sone, SoneStatus> soneStatuses = new HashMap<Sone, SoneStatus>();
@@ -192,6 +195,16 @@ public class Core implements IdentityListener {
        }
 
        /**
+        * Returns whether the “Sone rescue mode” is currently activated.
+        *
+        * @return {@code true} if the “Sone rescue mode” is currently activated,
+        *         {@code false} if it is not
+        */
+       public boolean isSoneRescueMode() {
+               return options.getBooleanOption("SoneRescueMode").get();
+       }
+
+       /**
         * Returns the identity manager used by the core.
         *
         * @return The identity manager
@@ -734,6 +747,7 @@ public class Core implements IdentityListener {
                                        for (Post post : sone.getPosts()) {
                                                if (!storedSone.getPosts().contains(post) && !knownPosts.contains(post.getId())) {
                                                        newPosts.add(post.getId());
+                                                       coreListenerManager.fireNewPostFound(post);
                                                }
                                                posts.put(post.getId(), post);
                                        }
@@ -747,6 +761,7 @@ public class Core implements IdentityListener {
                                        for (Reply reply : sone.getReplies()) {
                                                if (!storedSone.getReplies().contains(reply) && !knownReplies.contains(reply.getId())) {
                                                        newReplies.add(reply.getId());
+                                                       coreListenerManager.fireNewReplyFound(reply);
                                                }
                                                replies.put(reply.getId(), reply);
                                        }
@@ -1138,6 +1153,7 @@ public class Core implements IdentityListener {
                        }
                }
                saveConfiguration();
+               stopped = true;
        }
 
        //
@@ -1158,6 +1174,7 @@ public class Core implements IdentityListener {
                        }
 
                }));
+               options.addBooleanOption("SoneRescueMode", new DefaultOption<Boolean>(false));
                options.addBooleanOption("ClearOnNextRestart", new DefaultOption<Boolean>(false));
                options.addBooleanOption("ReallyClearOnNextRestart", new DefaultOption<Boolean>(false));
 
@@ -1173,6 +1190,7 @@ public class Core implements IdentityListener {
                }
 
                options.getIntegerOption("InsertionDelay").set(configuration.getIntValue("Option/InsertionDelay").getValue(null));
+               options.getBooleanOption("SoneRescueMode").set(configuration.getBooleanValue("Option/SoneRescueMode").getValue(null));
 
                /* load known Sones. */
                int soneCounter = 0;
@@ -1219,6 +1237,7 @@ public class Core implements IdentityListener {
                /* store the options first. */
                try {
                        configuration.getIntValue("Option/InsertionDelay").setValue(options.getIntegerOption("InsertionDelay").getReal());
+                       configuration.getBooleanValue("Option/SoneRescueMode").setValue(options.getBooleanOption("SoneRescueMode").getReal());
                        configuration.getBooleanValue("Option/ClearOnNextRestart").setValue(options.getBooleanOption("ClearOnNextRestart").getReal());
                        configuration.getBooleanValue("Option/ReallyClearOnNextRestart").setValue(options.getBooleanOption("ReallyClearOnNextRestart").getReal());