|
@@ -38,7 +38,9 @@ import com.dmdirc.plugins.PluginManager;
|
38
|
38
|
|
39
|
39
|
import java.util.ArrayList;
|
40
|
40
|
import java.util.Collection;
|
|
41
|
+import java.util.HashMap;
|
41
|
42
|
import java.util.List;
|
|
43
|
+import java.util.Map;
|
42
|
44
|
|
43
|
45
|
import javax.inject.Inject;
|
44
|
46
|
|
|
@@ -46,8 +48,8 @@ import net.engio.mbassy.listener.Handler;
|
46
|
48
|
|
47
|
49
|
public class NotificationsManager {
|
48
|
50
|
|
49
|
|
- /** The notification methods that we know of. */
|
50
|
|
- private final Collection<String> methods = new ArrayList<>();
|
|
51
|
+ /** The notification handlers that we know of. */
|
|
52
|
+ private final Map<String, NotificationHandler> handlers = new HashMap<>();
|
51
|
53
|
/** The user's preferred order for method usage. */
|
52
|
54
|
private List<String> order;
|
53
|
55
|
/** This plugin's settings domain. */
|
|
@@ -73,7 +75,7 @@ public class NotificationsManager {
|
73
|
75
|
}
|
74
|
76
|
|
75
|
77
|
public void onLoad() {
|
76
|
|
- methods.clear();
|
|
78
|
+ handlers.clear();
|
77
|
79
|
loadSettings();
|
78
|
80
|
eventBus.subscribe(this);
|
79
|
81
|
pluginManager.getPluginInfos().stream()
|
|
@@ -82,7 +84,7 @@ public class NotificationsManager {
|
82
|
84
|
}
|
83
|
85
|
|
84
|
86
|
public void onUnload() {
|
85
|
|
- methods.clear();
|
|
87
|
+ handlers.clear();
|
86
|
88
|
eventBus.unsubscribe(this);
|
87
|
89
|
}
|
88
|
90
|
|
|
@@ -113,8 +115,8 @@ public class NotificationsManager {
|
113
|
115
|
*/
|
114
|
116
|
private void addPlugin(final PluginInfo target) {
|
115
|
117
|
if (target.hasExportedService("showNotification")) {
|
116
|
|
- methods.add(target.getMetaData().getName());
|
117
|
|
- addMethodToOrder(target);
|
|
118
|
+ handlers.put(target.getMetaData().getName(), new LegacyNotificationHandler(pluginInfo));
|
|
119
|
+ addHandlerToOrder(target);
|
118
|
120
|
}
|
119
|
121
|
}
|
120
|
122
|
|
|
@@ -124,7 +126,7 @@ public class NotificationsManager {
|
124
|
126
|
*
|
125
|
127
|
* @param source The notification method to be tested
|
126
|
128
|
*/
|
127
|
|
- private void addMethodToOrder(final PluginInfo source) {
|
|
129
|
+ private void addHandlerToOrder(final PluginInfo source) {
|
128
|
130
|
if (!order.contains(source.getMetaData().getName())) {
|
129
|
131
|
order.add(source.getMetaData().getName());
|
130
|
132
|
}
|
|
@@ -137,54 +139,50 @@ public class NotificationsManager {
|
137
|
139
|
* @param target The plugin to be tested
|
138
|
140
|
*/
|
139
|
141
|
private void removePlugin(final PluginInfo target) {
|
140
|
|
- methods.remove(target.getMetaData().getName());
|
|
142
|
+ handlers.remove(target.getMetaData().getName());
|
141
|
143
|
}
|
142
|
144
|
|
143
|
145
|
/**
|
144
|
|
- * Retrieves a method based on its name.
|
|
146
|
+ * Retrieves a handler based on its name.
|
145
|
147
|
*
|
146
|
148
|
* @param name The name to search for
|
147
|
149
|
*
|
148
|
|
- * @return The method with the specified name or null if none were found.
|
|
150
|
+ * @return The handler with the specified name or null if none were found.
|
149
|
151
|
*/
|
150
|
|
- public PluginInfo getMethod(final String name) {
|
151
|
|
- return pluginManager.getPluginInfoByName(name);
|
|
152
|
+ public NotificationHandler getHandler(final String name) {
|
|
153
|
+ return handlers.get(name);
|
152
|
154
|
}
|
153
|
155
|
|
154
|
156
|
/**
|
155
|
|
- * Retrieves all the methods registered with this plugin.
|
|
157
|
+ * Retrieves the names of all the handlers registered with this plugin.
|
156
|
158
|
*
|
157
|
|
- * @return All known notification sources
|
|
159
|
+ * @return All known notification handler names
|
158
|
160
|
*/
|
159
|
|
- public List<PluginInfo> getMethods() {
|
160
|
|
- final List<PluginInfo> plugins = new ArrayList<>();
|
161
|
|
- for (String method : methods) {
|
162
|
|
- plugins.add(pluginManager.getPluginInfoByName(method));
|
163
|
|
- }
|
164
|
|
- return plugins;
|
|
161
|
+ public Collection<String> getHandlerNames() {
|
|
162
|
+ return handlers.keySet();
|
165
|
163
|
}
|
166
|
164
|
|
167
|
165
|
/**
|
168
|
|
- * Does this plugin have any active notification methods?
|
|
166
|
+ * Does this plugin have any active notification handler?
|
169
|
167
|
*
|
170
|
|
- * @return true iif active notification methods are registered
|
|
168
|
+ * @return true iif active notification handlers are registered
|
171
|
169
|
*/
|
172
|
|
- public boolean hasActiveMethod() {
|
173
|
|
- return !methods.isEmpty();
|
|
170
|
+ public boolean hasActiveHandler() {
|
|
171
|
+ return !handlers.isEmpty();
|
174
|
172
|
}
|
175
|
173
|
|
176
|
174
|
/**
|
177
|
|
- * Returns the user's preferred method if loaded, or null if none loaded.
|
|
175
|
+ * Returns the user's preferred handler if loaded, or null if none loaded.
|
178
|
176
|
*
|
179
|
|
- * @return Preferred notification method
|
|
177
|
+ * @return Preferred notification handler
|
180
|
178
|
*/
|
181
|
|
- public PluginInfo getPreferredMethod() {
|
182
|
|
- if (methods.isEmpty()) {
|
|
179
|
+ public NotificationHandler getPreferredHandler() {
|
|
180
|
+ if (handlers.isEmpty()) {
|
183
|
181
|
return null;
|
184
|
182
|
}
|
185
|
183
|
for (String method : order) {
|
186
|
|
- if (methods.contains(method)) {
|
187
|
|
- return pluginManager.getPluginInfoByName(method);
|
|
184
|
+ if (handlers.containsKey(method)) {
|
|
185
|
+ return handlers.get(method);
|
188
|
186
|
}
|
189
|
187
|
}
|
190
|
188
|
return null;
|