Convert “Sone marked as known” 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.Post;
22 import net.pterodactylus.sone.data.PostReply;
23 import net.pterodactylus.sone.data.Sone;
24 import net.pterodactylus.util.event.AbstractListenerManager;
25 import net.pterodactylus.util.version.Version;
26
27 /**
28  * Manager for {@link CoreListener}s.
29  *
30  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
31  */
32 public class CoreListenerManager extends AbstractListenerManager<Core, CoreListener> {
33
34         /**
35          * Creates a new core listener manager.
36          *
37          * @param source
38          *            The Core
39          */
40         public CoreListenerManager(Core source) {
41                 super(source);
42         }
43
44         //
45         // ACTIONS
46         //
47
48         /**
49          * Notifies all listeners that the given post is now marked as known.
50          *
51          * @param post
52          *            The known post
53          */
54         void fireMarkPostKnown(Post post) {
55                 for (CoreListener coreListener : getListeners()) {
56                         coreListener.markPostKnown(post);
57                 }
58         }
59
60         /**
61          * Notifies all listeners that the given reply is now marked as known.
62          *
63          * @param reply
64          *            The known reply
65          */
66         void fireMarkReplyKnown(PostReply reply) {
67                 for (CoreListener coreListener : getListeners()) {
68                         coreListener.markReplyKnown(reply);
69                 }
70         }
71
72         /**
73          * Notifies all listener that the given Sone was removed.
74          *
75          * @see CoreListener#soneRemoved(Sone)
76          * @param sone
77          *            The removed Sone
78          */
79         void fireSoneRemoved(Sone sone) {
80                 for (CoreListener coreListener : getListeners()) {
81                         coreListener.soneRemoved(sone);
82                 }
83         }
84
85         /**
86          * Notifies all listener that the given post was removed.
87          *
88          * @see CoreListener#postRemoved(Post)
89          * @param post
90          *            The removed post
91          */
92         void firePostRemoved(Post post) {
93                 for (CoreListener coreListener : getListeners()) {
94                         coreListener.postRemoved(post);
95                 }
96         }
97
98         /**
99          * Notifies all listener that the given reply was removed.
100          *
101          * @see CoreListener#replyRemoved(PostReply)
102          * @param reply
103          *            The removed reply
104          */
105         void fireReplyRemoved(PostReply reply) {
106                 for (CoreListener coreListener : getListeners()) {
107                         coreListener.replyRemoved(reply);
108                 }
109         }
110
111         /**
112          * Notifies all listeners that the given Sone was locked.
113          *
114          * @see CoreListener#soneLocked(Sone)
115          * @param sone
116          *            The Sone that was locked
117          */
118         void fireSoneLocked(Sone sone) {
119                 for (CoreListener coreListener : getListeners()) {
120                         coreListener.soneLocked(sone);
121                 }
122         }
123
124         /**
125          * Notifies all listeners that the given Sone was unlocked.
126          *
127          * @see CoreListener#soneUnlocked(Sone)
128          * @param sone
129          *            The Sone that was unlocked
130          */
131         void fireSoneUnlocked(Sone sone) {
132                 for (CoreListener coreListener : getListeners()) {
133                         coreListener.soneUnlocked(sone);
134                 }
135         }
136
137         /**
138          * Notifies all listeners that the insert of the given Sone has started.
139          *
140          * @see SoneInsertListener#insertStarted(Sone)
141          * @param sone
142          *            The Sone being inserted
143          */
144         void fireSoneInserting(Sone sone) {
145                 for (CoreListener coreListener : getListeners()) {
146                         coreListener.soneInserting(sone);
147                 }
148         }
149
150         /**
151          * Notifies all listeners that the insert of the given Sone has finished
152          * successfully.
153          *
154          * @see SoneInsertListener#insertFinished(Sone, long)
155          * @param sone
156          *            The Sone that was inserted
157          * @param insertDuration
158          *            The insert duration (in milliseconds)
159          */
160         void fireSoneInserted(Sone sone, long insertDuration) {
161                 for (CoreListener coreListener : getListeners()) {
162                         coreListener.soneInserted(sone, insertDuration);
163                 }
164         }
165
166         /**
167          * Notifies all listeners that the insert of the given Sone was aborted.
168          *
169          * @see SoneInsertListener#insertStarted(Sone)
170          * @param sone
171          *            The Sone being inserted
172          * @param cause
173          *            The cause for the abortion (may be {@code null}
174          */
175         void fireSoneInsertAborted(Sone sone, Throwable cause) {
176                 for (CoreListener coreListener : getListeners()) {
177                         coreListener.soneInsertAborted(sone, cause);
178                 }
179         }
180
181         /**
182          * Notifies all listeners that a new version was found.
183          *
184          * @see CoreListener#updateFound(Version, long, long)
185          * @param version
186          *            The new version
187          * @param releaseTime
188          *            The release time of the new version
189          * @param latestEdition
190          *            The latest edition of the Sone homepage
191          */
192         void fireUpdateFound(Version version, long releaseTime, long latestEdition) {
193                 for (CoreListener coreListener : getListeners()) {
194                         coreListener.updateFound(version, releaseTime, latestEdition);
195                 }
196         }
197
198         /**
199          * Notifies all listeners that an image has started being inserted.
200          *
201          * @see CoreListener#imageInsertStarted(Image)
202          * @param image
203          *            The image that is now inserted
204          */
205         void fireImageInsertStarted(Image image) {
206                 for (CoreListener coreListener : getListeners()) {
207                         coreListener.imageInsertStarted(image);
208                 }
209         }
210
211         /**
212          * Notifies all listeners that an image insert was aborted by the user.
213          *
214          * @see CoreListener#imageInsertAborted(Image)
215          * @param image
216          *            The image that is not inserted anymore
217          */
218         void fireImageInsertAborted(Image image) {
219                 for (CoreListener coreListener : getListeners()) {
220                         coreListener.imageInsertAborted(image);
221                 }
222         }
223
224         /**
225          * Notifies all listeners that an image was successfully inserted.
226          *
227          * @see CoreListener#imageInsertFinished(Image)
228          * @param image
229          *            The image that was inserted
230          */
231         void fireImageInsertFinished(Image image) {
232                 for (CoreListener coreListener : getListeners()) {
233                         coreListener.imageInsertFinished(image);
234                 }
235         }
236
237         /**
238          * Notifies all listeners that an image failed to be inserted.
239          *
240          * @see CoreListener#imageInsertFailed(Image, Throwable)
241          * @param image
242          *            The image that could not be inserted
243          * @param cause
244          *            The cause of the failure
245          */
246         void fireImageInsertFailed(Image image, Throwable cause) {
247                 for (CoreListener coreListener : getListeners()) {
248                         coreListener.imageInsertFailed(image, cause);
249                 }
250         }
251
252 }