Convert update events to EventBus-based events.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / Core.java
index e278629..bd1bf37 100644 (file)
@@ -44,13 +44,9 @@ import net.pterodactylus.sone.core.event.NewPostReplyFoundEvent;
 import net.pterodactylus.sone.core.event.NewSoneFoundEvent;
 import net.pterodactylus.sone.core.event.PostRemovedEvent;
 import net.pterodactylus.sone.core.event.PostReplyRemovedEvent;
-import net.pterodactylus.sone.core.event.SoneInsertAbortedEvent;
-import net.pterodactylus.sone.core.event.SoneInsertedEvent;
-import net.pterodactylus.sone.core.event.SoneInsertingEvent;
 import net.pterodactylus.sone.core.event.SoneLockedEvent;
 import net.pterodactylus.sone.core.event.SoneRemovedEvent;
 import net.pterodactylus.sone.core.event.SoneUnlockedEvent;
-import net.pterodactylus.sone.core.event.UpdateFoundEvent;
 import net.pterodactylus.sone.data.Album;
 import net.pterodactylus.sone.data.Client;
 import net.pterodactylus.sone.data.Image;
@@ -82,7 +78,6 @@ import net.pterodactylus.util.validation.EqualityValidator;
 import net.pterodactylus.util.validation.IntegerRangeValidator;
 import net.pterodactylus.util.validation.OrValidator;
 import net.pterodactylus.util.validation.Validation;
-import net.pterodactylus.util.version.Version;
 
 import com.google.common.base.Predicate;
 import com.google.common.collect.Collections2;
@@ -97,7 +92,7 @@ import freenet.keys.FreenetURI;
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
-public class Core extends AbstractService implements IdentityListener, UpdateListener, SoneProvider, PostProvider, SoneInsertListener {
+public class Core extends AbstractService implements IdentityListener, SoneProvider, PostProvider {
 
        /** The logger. */
        private static final Logger logger = Logging.getLogger(Core.class);
@@ -222,7 +217,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                this.identityManager = identityManager;
                this.soneDownloader = new SoneDownloader(this, freenetInterface);
                this.imageInserter = new ImageInserter(freenetInterface);
-               this.updateChecker = new UpdateChecker(freenetInterface);
+               this.updateChecker = new UpdateChecker(eventBus, freenetInterface);
                this.webOfTrustUpdater = webOfTrustUpdater;
                this.eventBus = eventBus;
        }
@@ -824,8 +819,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                        sone.setKnown(true);
                        /* TODO - load posts ’n stuff */
                        sones.put(ownIdentity.getId(), sone);
-                       final SoneInserter soneInserter = new SoneInserter(this, freenetInterface, sone);
-                       soneInserter.addSoneInsertListener(this);
+                       final SoneInserter soneInserter = new SoneInserter(this, eventBus, freenetInterface, sone);
                        soneInserters.put(sone, soneInserter);
                        sone.setStatus(SoneStatus.idle);
                        loadSone(sone);
@@ -1205,7 +1199,6 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                        }
                        sones.remove(sone.getId());
                        SoneInserter soneInserter = soneInserters.remove(sone);
-                       soneInserter.removeSoneInsertListener(this);
                        soneInserter.stop();
                }
                webOfTrustUpdater.removeContext((OwnIdentity) sone.getIdentity(), "Sone");
@@ -1891,7 +1884,6 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
        @Override
        public void serviceStart() {
                loadConfiguration();
-               updateChecker.addUpdateListener(this);
                updateChecker.start();
                identityManager.addIdentityListener(this);
                identityManager.start();
@@ -1925,7 +1917,6 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
        public void serviceStop() {
                synchronized (sones) {
                        for (Entry<Sone, SoneInserter> soneInserter : soneInserters.entrySet()) {
-                               soneInserter.getValue().removeSoneInsertListener(this);
                                soneInserter.getValue().stop();
                                saveSone(soneInserter.getKey());
                        }
@@ -1933,7 +1924,6 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                saveConfiguration();
                webOfTrustUpdater.stop();
                updateChecker.stop();
-               updateChecker.removeUpdateListener(this);
                soneDownloader.stop();
                identityManager.removeIdentityListener(this);
                identityManager.stop();
@@ -2420,46 +2410,6 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                eventBus.post(new SoneRemovedEvent(sone));
        }
 
-       //
-       // INTERFACE UpdateListener
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       public void updateFound(Version version, long releaseTime, long latestEdition) {
-               eventBus.post(new UpdateFoundEvent(version, releaseTime, latestEdition));
-       }
-
-       //
-       // INTERFACE ImageInsertListener
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       public void insertStarted(Sone sone) {
-               eventBus.post(new SoneInsertingEvent(sone));
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       public void insertFinished(Sone sone, long insertDuration) {
-               eventBus.post(new SoneInsertedEvent(sone, insertDuration));
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       public void insertAborted(Sone sone, Throwable cause) {
-               eventBus.post(new SoneInsertAbortedEvent(sone, cause));
-       }
-
        /**
         * Deletes the temporary image.
         *