Fire a “new Sone found” event when a new Sone is found.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / Core.java
index 5a80f31..2894945 100644 (file)
@@ -44,7 +44,6 @@ import net.pterodactylus.sone.main.SonePlugin;
 import net.pterodactylus.util.config.Configuration;
 import net.pterodactylus.util.config.ConfigurationException;
 import net.pterodactylus.util.logging.Logging;
-import net.pterodactylus.util.notify.NotificationManager;
 import net.pterodactylus.util.number.Numbers;
 import freenet.keys.FreenetURI;
 
@@ -81,6 +80,9 @@ public class Core implements IdentityListener {
        /** The options. */
        private final Options options = new Options();
 
+       /** The core listener manager. */
+       private final CoreListenerManager coreListenerManager = new CoreListenerManager(this);
+
        /** The configuration. */
        private final Configuration configuration;
 
@@ -90,9 +92,6 @@ public class Core implements IdentityListener {
        /** Interface to freenet. */
        private final FreenetInterface freenetInterface;
 
-       /** The notification manager. */
-       private final NotificationManager notificationManager = new NotificationManager();
-
        /** The Sone downloader. */
        private final SoneDownloader soneDownloader;
 
@@ -156,6 +155,30 @@ public class Core implements IdentityListener {
        }
 
        //
+       // LISTENER MANAGEMENT
+       //
+
+       /**
+        * Adds a new core listener.
+        *
+        * @param coreListener
+        *            The listener to add
+        */
+       public void addCoreListener(CoreListener coreListener) {
+               coreListenerManager.addListener(coreListener);
+       }
+
+       /**
+        * Removes a core listener.
+        *
+        * @param coreListener
+        *            The listener to remove
+        */
+       public void removeCoreListener(CoreListener coreListener) {
+               coreListenerManager.removeListener(coreListener);
+       }
+
+       //
        // ACCESSORS
        //
 
@@ -178,15 +201,6 @@ public class Core implements IdentityListener {
        }
 
        /**
-        * Returns the notification manager.
-        *
-        * @return The notification manager
-        */
-       public NotificationManager getNotifications() {
-               return notificationManager;
-       }
-
-       /**
         * Returns the status of the given Sone.
         *
         * @param sone
@@ -665,7 +679,13 @@ public class Core implements IdentityListener {
                        sone.setLatestEdition(Numbers.safeParseLong(identity.getProperty("Sone.LatestEdition"), (long) 0));
                        if (newSone) {
                                synchronized (newSones) {
-                                       newSones.add(sone.getId());
+                                       newSone = !knownSones.contains(sone.getId());
+                                       if (newSone) {
+                                               newSones.add(sone.getId());
+                                       }
+                               }
+                               if (newSone) {
+                                       coreListenerManager.fireNewSoneFound(sone);
                                }
                        }
                        remoteSones.put(identity.getId(), sone);