|
@@ -22,91 +22,69 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.addons.notifications;
|
24
|
24
|
|
25
|
|
-import com.dmdirc.actions.ActionManager;
|
26
|
|
-import com.dmdirc.actions.CoreActionType;
|
27
|
25
|
import com.dmdirc.addons.ui_swing.UIUtilities;
|
28
|
26
|
import com.dmdirc.config.prefs.PluginPreferencesCategory;
|
29
|
27
|
import com.dmdirc.config.prefs.PreferencesCategory;
|
30
|
28
|
import com.dmdirc.config.prefs.PreferencesDialogModel;
|
31
|
|
-import com.dmdirc.interfaces.ActionListener;
|
32
|
|
-import com.dmdirc.interfaces.CommandController;
|
33
|
|
-import com.dmdirc.interfaces.actions.ActionType;
|
34
|
|
-import com.dmdirc.interfaces.config.IdentityController;
|
35
|
29
|
import com.dmdirc.plugins.PluginInfo;
|
36
|
30
|
import com.dmdirc.plugins.implementations.BaseCommandPlugin;
|
37
|
31
|
|
38
|
|
-import java.util.ArrayList;
|
39
|
|
-import java.util.List;
|
40
|
32
|
import java.util.concurrent.Callable;
|
41
|
33
|
|
|
34
|
+import dagger.ObjectGraph;
|
|
35
|
+
|
42
|
36
|
/**
|
43
|
37
|
* Notification Manager plugin, aggregates notification sources exposing them via a single command.
|
44
|
38
|
*/
|
45
|
|
-public class NotificationsPlugin extends BaseCommandPlugin implements ActionListener {
|
|
39
|
+public class NotificationsPlugin extends BaseCommandPlugin {
|
46
|
40
|
|
47
|
|
- /** The notification methods that we know of. */
|
48
|
|
- private final List<String> methods = new ArrayList<>();
|
49
|
|
- /** The user's preferred order for method usage. */
|
50
|
|
- private List<String> order;
|
51
|
41
|
/** This plugin's plugin info. */
|
52
|
42
|
private final PluginInfo pluginInfo;
|
53
|
|
- /** The controller to read and write settings with. */
|
54
|
|
- private final IdentityController identityController;
|
|
43
|
+ /** Notifications manager. */
|
|
44
|
+ private NotificationsManager manager;
|
55
|
45
|
|
56
|
46
|
/**
|
57
|
47
|
* Creates a new instance of this plugin.
|
58
|
48
|
*
|
59
|
|
- * @param pluginInfo This plugin's plugin info
|
60
|
|
- * @param commandController Command controller to register commands
|
61
|
|
- * @param identityController The controller to read and write settings with.
|
|
49
|
+ * @param pluginInfo This plugin's plugin info
|
62
|
50
|
*/
|
63
|
|
- public NotificationsPlugin(
|
64
|
|
- final PluginInfo pluginInfo,
|
65
|
|
- final CommandController commandController,
|
66
|
|
- final IdentityController identityController) {
|
67
|
|
- super(commandController);
|
|
51
|
+ public NotificationsPlugin(final PluginInfo pluginInfo) {
|
68
|
52
|
this.pluginInfo = pluginInfo;
|
69
|
|
- this.identityController = identityController;
|
70
|
|
- registerCommand(new NotificationCommand(commandController, this),
|
71
|
|
- NotificationCommand.INFO);
|
|
53
|
+
|
|
54
|
+ }
|
|
55
|
+
|
|
56
|
+ @Override
|
|
57
|
+ public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
|
|
58
|
+ super.load(pluginInfo, graph);
|
|
59
|
+ setObjectGraph(graph.plus(new NotificationsModule(pluginInfo)));
|
|
60
|
+ registerCommand(NotificationCommand.class, NotificationCommand.INFO);
|
|
61
|
+ manager = getObjectGraph().get(NotificationsManager.class);
|
72
|
62
|
}
|
73
|
63
|
|
74
|
|
- /** {@inheritDoc} */
|
75
|
64
|
@Override
|
76
|
65
|
public void onLoad() {
|
77
|
|
- methods.clear();
|
78
|
|
- loadSettings();
|
79
|
|
- ActionManager.getActionManager().registerListener(this,
|
80
|
|
- CoreActionType.PLUGIN_LOADED, CoreActionType.PLUGIN_UNLOADED);
|
81
|
|
- for (PluginInfo target : pluginInfo.getMetaData().getManager()
|
82
|
|
- .getPluginInfos()) {
|
83
|
|
- if (target.isLoaded()) {
|
84
|
|
- addPlugin(target);
|
85
|
|
- }
|
86
|
|
- }
|
|
66
|
+ manager.onLoad();
|
87
|
67
|
super.onLoad();
|
88
|
68
|
}
|
89
|
69
|
|
90
|
|
- /** {@inheritDoc} */
|
91
|
70
|
@Override
|
92
|
71
|
public void onUnload() {
|
93
|
|
- methods.clear();
|
94
|
|
- ActionManager.getActionManager().unregisterListener(this);
|
|
72
|
+ manager.onUnload();
|
95
|
73
|
super.onUnload();
|
96
|
74
|
}
|
97
|
75
|
|
98
|
|
- /** {@inheritDoc} */
|
99
|
76
|
@Override
|
100
|
77
|
public void showConfig(final PreferencesDialogModel manager) {
|
101
|
78
|
final NotificationConfig configPanel = UIUtilities.invokeAndWait(
|
102
|
79
|
new Callable<NotificationConfig>() {
|
103
|
|
- /** {@inheritDoc} */
|
104
|
|
- @Override
|
105
|
|
- public NotificationConfig call() {
|
106
|
|
- return new NotificationConfig(NotificationsPlugin.this,
|
107
|
|
- order);
|
108
|
|
- }
|
109
|
|
- });
|
|
80
|
+ /** {@inheritDoc} */
|
|
81
|
+ @Override
|
|
82
|
+ public NotificationConfig call() {
|
|
83
|
+ return new NotificationConfig(manager.getIdentity(), pluginInfo.getDomain(),
|
|
84
|
+ manager.getConfigManager().getOptionList(pluginInfo.getDomain(),
|
|
85
|
+ "methodOrder"));
|
|
86
|
+ }
|
|
87
|
+ });
|
110
|
88
|
|
111
|
89
|
final PreferencesCategory category = new PluginPreferencesCategory(
|
112
|
90
|
pluginInfo, "Notifications", "", "category-notifications",
|
|
@@ -114,124 +92,4 @@ public class NotificationsPlugin extends BaseCommandPlugin implements ActionList
|
114
|
92
|
manager.getCategory("Plugins").addSubCategory(category);
|
115
|
93
|
}
|
116
|
94
|
|
117
|
|
- /** Loads the plugins settings. */
|
118
|
|
- private void loadSettings() {
|
119
|
|
- if (identityController.getGlobalConfiguration()
|
120
|
|
- .hasOptionString(pluginInfo.getDomain(), "methodOrder")) {
|
121
|
|
- order = identityController.getGlobalConfiguration().
|
122
|
|
- getOptionList(pluginInfo.getDomain(), "methodOrder");
|
123
|
|
- } else {
|
124
|
|
- order = new ArrayList<>();
|
125
|
|
- }
|
126
|
|
- }
|
127
|
|
-
|
128
|
|
- /** {@inheritDoc} */
|
129
|
|
- @Override
|
130
|
|
- public void processEvent(final ActionType type, final StringBuffer format,
|
131
|
|
- final Object... arguments) {
|
132
|
|
- if (type == CoreActionType.PLUGIN_LOADED) {
|
133
|
|
- addPlugin((PluginInfo) arguments[0]);
|
134
|
|
- } else if (type == CoreActionType.PLUGIN_UNLOADED) {
|
135
|
|
- removePlugin((PluginInfo) arguments[0]);
|
136
|
|
- }
|
137
|
|
- }
|
138
|
|
-
|
139
|
|
- /**
|
140
|
|
- * Checks to see if a plugin implements the notification method interface and if it does, adds
|
141
|
|
- * the method to our list.
|
142
|
|
- *
|
143
|
|
- * @param target The plugin to be tested
|
144
|
|
- */
|
145
|
|
- private void addPlugin(final PluginInfo target) {
|
146
|
|
- if (target.hasExportedService("showNotification")) {
|
147
|
|
- methods.add(target.getMetaData().getName());
|
148
|
|
- addMethodToOrder(target);
|
149
|
|
- }
|
150
|
|
- }
|
151
|
|
-
|
152
|
|
- /**
|
153
|
|
- * Checks to see if the specified notification method needs to be added to our order list, and
|
154
|
|
- * adds it if neccessary.
|
155
|
|
- *
|
156
|
|
- * @param source The notification method to be tested
|
157
|
|
- */
|
158
|
|
- private void addMethodToOrder(final PluginInfo source) {
|
159
|
|
- if (!order.contains(source.getMetaData().getName())) {
|
160
|
|
- order.add(source.getMetaData().getName());
|
161
|
|
- }
|
162
|
|
- }
|
163
|
|
-
|
164
|
|
- /**
|
165
|
|
- * Checks to see if a plugin implements the notification method interface and if it does,
|
166
|
|
- * removes the method from our list.
|
167
|
|
- *
|
168
|
|
- * @param target The plugin to be tested
|
169
|
|
- */
|
170
|
|
- private void removePlugin(final PluginInfo target) {
|
171
|
|
- methods.remove(target.getMetaData().getName());
|
172
|
|
- }
|
173
|
|
-
|
174
|
|
- /**
|
175
|
|
- * Retrieves a method based on its name.
|
176
|
|
- *
|
177
|
|
- * @param name The name to search for
|
178
|
|
- *
|
179
|
|
- * @return The method with the specified name or null if none were found.
|
180
|
|
- */
|
181
|
|
- public PluginInfo getMethod(final String name) {
|
182
|
|
- return pluginInfo.getMetaData().getManager().getPluginInfoByName(name);
|
183
|
|
- }
|
184
|
|
-
|
185
|
|
- /**
|
186
|
|
- * Retrieves all the methods registered with this plugin.
|
187
|
|
- *
|
188
|
|
- * @return All known notification sources
|
189
|
|
- */
|
190
|
|
- public List<PluginInfo> getMethods() {
|
191
|
|
- final List<PluginInfo> plugins = new ArrayList<>();
|
192
|
|
- for (String method : methods) {
|
193
|
|
- plugins.add(pluginInfo.getMetaData().getManager()
|
194
|
|
- .getPluginInfoByName(method));
|
195
|
|
- }
|
196
|
|
- return plugins;
|
197
|
|
- }
|
198
|
|
-
|
199
|
|
- /**
|
200
|
|
- * Does this plugin have any active notification methods?
|
201
|
|
- *
|
202
|
|
- * @return true iif active notification methods are registered
|
203
|
|
- */
|
204
|
|
- public boolean hasActiveMethod() {
|
205
|
|
- return !methods.isEmpty();
|
206
|
|
- }
|
207
|
|
-
|
208
|
|
- /**
|
209
|
|
- * Returns the user's preferred method if loaded, or null if none loaded.
|
210
|
|
- *
|
211
|
|
- * @return Preferred notification method
|
212
|
|
- */
|
213
|
|
- public PluginInfo getPreferredMethod() {
|
214
|
|
- if (methods.isEmpty()) {
|
215
|
|
- return null;
|
216
|
|
- }
|
217
|
|
- for (String method : order) {
|
218
|
|
- if (methods.contains(method)) {
|
219
|
|
- return pluginInfo.getMetaData().getManager().getPluginInfoByName(
|
220
|
|
- method);
|
221
|
|
- }
|
222
|
|
- }
|
223
|
|
- return null;
|
224
|
|
- }
|
225
|
|
-
|
226
|
|
- /**
|
227
|
|
- * Saves the plugins settings.
|
228
|
|
- *
|
229
|
|
- * @param newOrder The new order for methods
|
230
|
|
- */
|
231
|
|
- protected void saveSettings(final List<String> newOrder) {
|
232
|
|
- order = newOrder;
|
233
|
|
- identityController.getUserSettings()
|
234
|
|
- .setOption(pluginInfo.getDomain(), "methodOrder", order);
|
235
|
|
- }
|
236
|
|
-
|
237
|
95
|
}
|