Convert “Sone is being inserted” into EventBus-based event.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / CoreListenerManager.java
1 /*
2  * Sone - CoreListenerManager.java - Copyright © 2010–2012 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.sone.core;
19
20 import net.pterodactylus.sone.data.Image;
21 import net.pterodactylus.sone.data.Sone;
22 import net.pterodactylus.util.event.AbstractListenerManager;
23 import net.pterodactylus.util.version.Version;
24
25 /**
26  * Manager for {@link CoreListener}s.
27  *
28  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
29  */
30 public class CoreListenerManager extends AbstractListenerManager<Core, CoreListener> {
31
32         /**
33          * Creates a new core listener manager.
34          *
35          * @param source
36          *            The Core
37          */
38         public CoreListenerManager(Core source) {
39                 super(source);
40         }
41
42         //
43         // ACTIONS
44         //
45
46         /**
47          * Notifies all listeners that the insert of the given Sone has finished
48          * successfully.
49          *
50          * @see SoneInsertListener#insertFinished(Sone, long)
51          * @param sone
52          *            The Sone that was inserted
53          * @param insertDuration
54          *            The insert duration (in milliseconds)
55          */
56         void fireSoneInserted(Sone sone, long insertDuration) {
57                 for (CoreListener coreListener : getListeners()) {
58                         coreListener.soneInserted(sone, insertDuration);
59                 }
60         }
61
62         /**
63          * Notifies all listeners that the insert of the given Sone was aborted.
64          *
65          * @see SoneInsertListener#insertStarted(Sone)
66          * @param sone
67          *            The Sone being inserted
68          * @param cause
69          *            The cause for the abortion (may be {@code null}
70          */
71         void fireSoneInsertAborted(Sone sone, Throwable cause) {
72                 for (CoreListener coreListener : getListeners()) {
73                         coreListener.soneInsertAborted(sone, cause);
74                 }
75         }
76
77         /**
78          * Notifies all listeners that a new version was found.
79          *
80          * @see CoreListener#updateFound(Version, long, long)
81          * @param version
82          *            The new version
83          * @param releaseTime
84          *            The release time of the new version
85          * @param latestEdition
86          *            The latest edition of the Sone homepage
87          */
88         void fireUpdateFound(Version version, long releaseTime, long latestEdition) {
89                 for (CoreListener coreListener : getListeners()) {
90                         coreListener.updateFound(version, releaseTime, latestEdition);
91                 }
92         }
93
94         /**
95          * Notifies all listeners that an image has started being inserted.
96          *
97          * @see CoreListener#imageInsertStarted(Image)
98          * @param image
99          *            The image that is now inserted
100          */
101         void fireImageInsertStarted(Image image) {
102                 for (CoreListener coreListener : getListeners()) {
103                         coreListener.imageInsertStarted(image);
104                 }
105         }
106
107         /**
108          * Notifies all listeners that an image insert was aborted by the user.
109          *
110          * @see CoreListener#imageInsertAborted(Image)
111          * @param image
112          *            The image that is not inserted anymore
113          */
114         void fireImageInsertAborted(Image image) {
115                 for (CoreListener coreListener : getListeners()) {
116                         coreListener.imageInsertAborted(image);
117                 }
118         }
119
120         /**
121          * Notifies all listeners that an image was successfully inserted.
122          *
123          * @see CoreListener#imageInsertFinished(Image)
124          * @param image
125          *            The image that was inserted
126          */
127         void fireImageInsertFinished(Image image) {
128                 for (CoreListener coreListener : getListeners()) {
129                         coreListener.imageInsertFinished(image);
130                 }
131         }
132
133         /**
134          * Notifies all listeners that an image failed to be inserted.
135          *
136          * @see CoreListener#imageInsertFailed(Image, Throwable)
137          * @param image
138          *            The image that could not be inserted
139          * @param cause
140          *            The cause of the failure
141          */
142         void fireImageInsertFailed(Image image, Throwable cause) {
143                 for (CoreListener coreListener : getListeners()) {
144                         coreListener.imageInsertFailed(image, cause);
145                 }
146         }
147
148 }