Convert “image insert failed” into EventBus-based event.
[Sone.git] / src / main / java / net / pterodactylus / sone / web / WebInterface.java
index 7c16c09..0863fee 100644 (file)
@@ -36,7 +36,10 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import net.pterodactylus.sone.core.Core;
-import net.pterodactylus.sone.core.CoreListener;
+import net.pterodactylus.sone.core.event.ImageInsertAbortedEvent;
+import net.pterodactylus.sone.core.event.ImageInsertFailedEvent;
+import net.pterodactylus.sone.core.event.ImageInsertFinishedEvent;
+import net.pterodactylus.sone.core.event.ImageInsertStartedEvent;
 import net.pterodactylus.sone.core.event.MarkPostKnownEvent;
 import net.pterodactylus.sone.core.event.MarkPostReplyKnownEvent;
 import net.pterodactylus.sone.core.event.MarkSoneKnownEvent;
@@ -51,6 +54,7 @@ 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.Image;
 import net.pterodactylus.sone.data.Post;
@@ -139,7 +143,6 @@ import net.pterodactylus.util.template.TemplateParser;
 import net.pterodactylus.util.template.TemplateProvider;
 import net.pterodactylus.util.template.XmlFilter;
 import net.pterodactylus.util.thread.Ticker;
-import net.pterodactylus.util.version.Version;
 import net.pterodactylus.util.web.RedirectPage;
 import net.pterodactylus.util.web.StaticPage;
 import net.pterodactylus.util.web.TemplatePage;
@@ -162,7 +165,7 @@ import freenet.support.api.HTTPRequest;
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
-public class WebInterface implements CoreListener {
+public class WebInterface {
 
        /** The logger. */
        private static final Logger logger = Logging.getLogger(WebInterface.class);
@@ -1022,55 +1025,66 @@ public class WebInterface implements CoreListener {
                }
        }
 
-       //
-       // CORELISTENER METHODS
-       //
-
        /**
-        * {@inheritDoc}
+        * Notifies the web interface that a new Sone version was found.
+        *
+        * @param updateFoundEvent
+        *            The event
         */
-       @Override
-       public void updateFound(Version version, long releaseTime, long latestEdition) {
-               newVersionNotification.getTemplateContext().set("latestVersion", version);
-               newVersionNotification.getTemplateContext().set("latestEdition", latestEdition);
-               newVersionNotification.getTemplateContext().set("releaseTime", releaseTime);
+       @Subscribe
+       public void updateFound(UpdateFoundEvent updateFoundEvent) {
+               newVersionNotification.getTemplateContext().set("latestVersion", updateFoundEvent.version());
+               newVersionNotification.getTemplateContext().set("latestEdition", updateFoundEvent.latestEdition());
+               newVersionNotification.getTemplateContext().set("releaseTime", updateFoundEvent.releaseTime());
                notificationManager.addNotification(newVersionNotification);
        }
 
        /**
-        * {@inheritDoc}
+        * Notifies the web interface that an image insert was started
+        *
+        * @param imageInsertStartedEvent
+        *            The event
         */
-       @Override
-       public void imageInsertStarted(Image image) {
-               insertingImagesNotification.add(image);
+       @Subscribe
+       public void imageInsertStarted(ImageInsertStartedEvent imageInsertStartedEvent) {
+               insertingImagesNotification.add(imageInsertStartedEvent.image());
                notificationManager.addNotification(insertingImagesNotification);
        }
 
        /**
-        * {@inheritDoc}
+        * Notifies the web interface that an {@link Image} insert was aborted.
+        *
+        * @param imageInsertAbortedEvent
+        *            The event
         */
-       @Override
-       public void imageInsertAborted(Image image) {
-               insertingImagesNotification.remove(image);
+       @Subscribe
+       public void imageInsertAborted(ImageInsertAbortedEvent imageInsertAbortedEvent) {
+               insertingImagesNotification.remove(imageInsertAbortedEvent.image());
        }
 
        /**
-        * {@inheritDoc}
+        * Notifies the web interface that an {@link Image} insert is finished.
+        *
+        * @param imageInsertFinishedEvent
+        *            The event
         */
-       @Override
-       public void imageInsertFinished(Image image) {
-               insertingImagesNotification.remove(image);
-               insertedImagesNotification.add(image);
+       @Subscribe
+       public void imageInsertFinished(ImageInsertFinishedEvent imageInsertFinishedEvent) {
+               insertingImagesNotification.remove(imageInsertFinishedEvent.image());
+               insertedImagesNotification.add(imageInsertFinishedEvent.image());
                notificationManager.addNotification(insertedImagesNotification);
        }
 
        /**
-        * {@inheritDoc}
+        * Notifies the web interface that an {@link Image} insert has failed.
+        *
+        * @param imageInsertFailedEvent
+        *            The event
         */
-       @Override
-       public void imageInsertFailed(Image image, Throwable cause) {
-               insertingImagesNotification.remove(image);
-               imageInsertFailedNotification.add(image);
+       @Subscribe
+       public void imageInsertFailed(ImageInsertFailedEvent imageInsertFailedEvent) {
+               insertingImagesNotification.remove(imageInsertFailedEvent.image());
+               imageInsertFailedNotification.add(imageInsertFailedEvent.image());
                notificationManager.addNotification(imageInsertFailedNotification);
        }