|
@@ -22,115 +22,46 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.addons.systray;
|
24
|
24
|
|
25
|
|
-import com.dmdirc.actions.CoreActionType;
|
26
|
|
-import com.dmdirc.addons.ui_swing.MainFrame;
|
27
|
|
-import com.dmdirc.addons.ui_swing.SwingController;
|
28
|
25
|
import com.dmdirc.config.prefs.PluginPreferencesCategory;
|
29
|
26
|
import com.dmdirc.config.prefs.PreferencesCategory;
|
30
|
27
|
import com.dmdirc.config.prefs.PreferencesDialogModel;
|
31
|
28
|
import com.dmdirc.config.prefs.PreferencesSetting;
|
32
|
29
|
import com.dmdirc.config.prefs.PreferencesType;
|
33
|
|
-import com.dmdirc.interfaces.ActionController;
|
34
|
|
-import com.dmdirc.interfaces.CommandController;
|
35
|
|
-import com.dmdirc.interfaces.actions.ActionType;
|
36
|
|
-import com.dmdirc.interfaces.config.IdentityController;
|
37
|
30
|
import com.dmdirc.plugins.Exported;
|
38
|
31
|
import com.dmdirc.plugins.PluginInfo;
|
39
|
32
|
import com.dmdirc.plugins.implementations.BaseCommandPlugin;
|
40
|
|
-import com.dmdirc.ui.IconManager;
|
41
|
|
-import com.dmdirc.ui.messages.Styliser;
|
42
|
|
-import com.dmdirc.util.URLBuilder;
|
43
|
33
|
import com.dmdirc.util.validators.ValidationResponse;
|
44
|
34
|
|
45
|
|
-import java.awt.AWTException;
|
46
|
|
-import java.awt.Frame;
|
47
|
|
-import java.awt.MenuItem;
|
48
|
|
-import java.awt.PopupMenu;
|
49
|
35
|
import java.awt.SystemTray;
|
50
|
|
-import java.awt.TrayIcon;
|
51
|
|
-import java.awt.event.ActionEvent;
|
52
|
|
-import java.awt.event.ActionListener;
|
53
|
|
-import java.awt.event.MouseEvent;
|
54
|
|
-import java.awt.event.MouseListener;
|
|
36
|
+
|
|
37
|
+import dagger.ObjectGraph;
|
55
|
38
|
|
56
|
39
|
/**
|
57
|
40
|
* The Systray plugin shows DMDirc in the user's system tray, and allows notifications to be
|
58
|
41
|
* disabled.
|
59
|
42
|
*/
|
60
|
|
-public class SystrayPlugin extends BaseCommandPlugin implements
|
61
|
|
- ActionListener, MouseListener, com.dmdirc.interfaces.ActionListener {
|
|
43
|
+public class SystrayPlugin extends BaseCommandPlugin {
|
62
|
44
|
|
63
|
|
- /** The tray icon we're currently using. */
|
64
|
|
- private final TrayIcon icon;
|
65
|
|
- /** Main frame instance. */
|
66
|
|
- private final MainFrame mainFrame;
|
67
|
45
|
/** This plugin's plugin info. */
|
68
|
46
|
private final PluginInfo pluginInfo;
|
69
|
|
- /** The action controller to use. */
|
70
|
|
- private final ActionController actionController;
|
71
|
|
- /** The controller to read/write settings with. */
|
72
|
|
- private final IdentityController identityController;
|
|
47
|
+ /** Systray manager. */
|
|
48
|
+ private SystrayManager manager;
|
73
|
49
|
|
74
|
50
|
/**
|
75
|
51
|
* Creates a new system tray plugin.
|
76
|
52
|
*
|
77
|
|
- * @param swingController The controller that owns this plugin.
|
78
|
53
|
* @param pluginInfo This plugin's plugin info.
|
79
|
|
- * @param actionController The action controller to use.
|
80
|
|
- * @param identityController The identity manager to read settings from.
|
81
|
|
- * @param commandController The controller to use for command information.
|
82
|
|
- * @param urlBuilder URL builder to use to resolve icon paths.
|
83
|
54
|
*/
|
84
|
|
- public SystrayPlugin(
|
85
|
|
- final SwingController swingController,
|
86
|
|
- final PluginInfo pluginInfo,
|
87
|
|
- final ActionController actionController,
|
88
|
|
- final IdentityController identityController,
|
89
|
|
- final CommandController commandController,
|
90
|
|
- final URLBuilder urlBuilder) {
|
|
55
|
+ public SystrayPlugin(final PluginInfo pluginInfo) {
|
91
|
56
|
this.pluginInfo = pluginInfo;
|
92
|
|
- this.actionController = actionController;
|
93
|
|
- this.identityController = identityController;
|
94
|
|
- this.mainFrame = swingController.getMainFrame();
|
95
|
|
-
|
96
|
|
- final MenuItem show = new MenuItem("Show/hide");
|
97
|
|
- final MenuItem quit = new MenuItem("Quit");
|
98
|
|
-
|
99
|
|
- final PopupMenu menu = new PopupMenu();
|
100
|
|
- menu.add(show);
|
101
|
|
- menu.add(quit);
|
102
|
|
-
|
103
|
|
- show.addActionListener(this);
|
104
|
|
- quit.addActionListener(this);
|
105
|
|
-
|
106
|
|
- icon = new TrayIcon(
|
107
|
|
- new IconManager(identityController.getGlobalConfiguration(), urlBuilder)
|
108
|
|
- .getImage("logo"), "DMDirc", menu);
|
109
|
|
- icon.setImageAutoSize(true);
|
110
|
|
- icon.addMouseListener(this);
|
111
|
|
- registerCommand(new PopupCommand(this, commandController), PopupCommand.INFO);
|
112
|
57
|
}
|
113
|
58
|
|
114
|
|
- /**
|
115
|
|
- * Sends a notification via the system tray icon.
|
116
|
|
- *
|
117
|
|
- * @param title The title of the notification
|
118
|
|
- * @param message The contents of the notification
|
119
|
|
- * @param type The type of notification
|
120
|
|
- */
|
121
|
|
- public void notify(final String title, final String message,
|
122
|
|
- final TrayIcon.MessageType type) {
|
123
|
|
- icon.displayMessage(title, Styliser.stipControlCodes(message), type);
|
124
|
|
- }
|
125
|
|
-
|
126
|
|
- /**
|
127
|
|
- * Sends a notification via the system tray icon.
|
128
|
|
- *
|
129
|
|
- * @param title The title of the notification
|
130
|
|
- * @param message The contents of the notification
|
131
|
|
- */
|
132
|
|
- public void notify(final String title, final String message) {
|
133
|
|
- notify(title, message, TrayIcon.MessageType.NONE);
|
|
59
|
+ @Override
|
|
60
|
+ public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
|
|
61
|
+ super.load(pluginInfo, graph);
|
|
62
|
+ setObjectGraph(graph.plus(new SystrayModule(pluginInfo)));
|
|
63
|
+ registerCommand(PopupCommand.class, PopupCommand.INFO);
|
|
64
|
+ manager = getObjectGraph().get(SystrayManager.class);
|
134
|
65
|
}
|
135
|
66
|
|
136
|
67
|
/**
|
|
@@ -142,27 +73,9 @@ public class SystrayPlugin extends BaseCommandPlugin implements
|
142
|
73
|
*/
|
143
|
74
|
@Exported
|
144
|
75
|
public void showPopup(final String title, final String message) {
|
145
|
|
- notify(title, message);
|
|
76
|
+ manager.notify(title, message);
|
146
|
77
|
}
|
147
|
78
|
|
148
|
|
- /**
|
149
|
|
- * {@inheritDoc}
|
150
|
|
- *
|
151
|
|
- * @param e Action event
|
152
|
|
- */
|
153
|
|
- @Override
|
154
|
|
- public void actionPerformed(final ActionEvent e) {
|
155
|
|
- switch (e.getActionCommand()) {
|
156
|
|
- case "Show/hide":
|
157
|
|
- mainFrame.setVisible(!mainFrame.isVisible());
|
158
|
|
- break;
|
159
|
|
- case "Quit":
|
160
|
|
- mainFrame.quit();
|
161
|
|
- break;
|
162
|
|
- }
|
163
|
|
- }
|
164
|
|
-
|
165
|
|
- /** {@inheritDoc} */
|
166
|
79
|
@Override
|
167
|
80
|
public ValidationResponse checkPrerequisites() {
|
168
|
81
|
if (SystemTray.isSupported()) {
|
|
@@ -173,31 +86,18 @@ public class SystrayPlugin extends BaseCommandPlugin implements
|
173
|
86
|
}
|
174
|
87
|
}
|
175
|
88
|
|
176
|
|
- /** {@inheritDoc} */
|
177
|
89
|
@Override
|
178
|
90
|
public void onLoad() {
|
179
|
|
- boolean continueLoading = true;
|
180
|
|
- try {
|
181
|
|
- SystemTray.getSystemTray().add(icon);
|
182
|
|
- actionController.registerListener(this, CoreActionType.CLIENT_MINIMISED);
|
183
|
|
- } catch (AWTException ex) {
|
184
|
|
- continueLoading = false;
|
185
|
|
- }
|
186
|
|
- if (!continueLoading || mainFrame == null) {
|
187
|
|
- pluginInfo.unloadPlugin();
|
188
|
|
- }
|
|
91
|
+ manager.load();
|
189
|
92
|
super.onLoad();
|
190
|
93
|
}
|
191
|
94
|
|
192
|
|
- /** {@inheritDoc} */
|
193
|
95
|
@Override
|
194
|
96
|
public void onUnload() {
|
195
|
|
- SystemTray.getSystemTray().remove(icon);
|
196
|
|
- actionController.unregisterListener(this);
|
|
97
|
+ manager.unload();
|
197
|
98
|
super.onUnload();
|
198
|
99
|
}
|
199
|
100
|
|
200
|
|
- /** {@inheritDoc} */
|
201
|
101
|
@Override
|
202
|
102
|
public void showConfig(final PreferencesDialogModel manager) {
|
203
|
103
|
final PreferencesCategory category = new PluginPreferencesCategory(
|
|
@@ -205,7 +105,7 @@ public class SystrayPlugin extends BaseCommandPlugin implements
|
205
|
105
|
"General configuration settings");
|
206
|
106
|
|
207
|
107
|
category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
|
208
|
|
- getDomain(), "autominimise", "Auto-hide DMDirc when minimised",
|
|
108
|
+ pluginInfo.getDomain(), "autominimise", "Auto-hide DMDirc when minimised",
|
209
|
109
|
"If this option is enabled, the systray plugin will hide DMDirc"
|
210
|
110
|
+ " to the system tray whenever DMDirc is minimised",
|
211
|
111
|
manager.getConfigManager(), manager.getIdentity()));
|
|
@@ -213,73 +113,4 @@ public class SystrayPlugin extends BaseCommandPlugin implements
|
213
|
113
|
manager.getCategory("Plugins").addSubCategory(category);
|
214
|
114
|
}
|
215
|
115
|
|
216
|
|
- /**
|
217
|
|
- * {@inheritDoc}
|
218
|
|
- *
|
219
|
|
- * @param e Mouse event
|
220
|
|
- */
|
221
|
|
- @Override
|
222
|
|
- public void mouseClicked(final MouseEvent e) {
|
223
|
|
- if (e.getButton() == MouseEvent.BUTTON1) {
|
224
|
|
- if (mainFrame.isVisible()) {
|
225
|
|
- mainFrame.setVisible(false);
|
226
|
|
- } else {
|
227
|
|
- mainFrame.setVisible(true);
|
228
|
|
- mainFrame.setState(Frame.NORMAL);
|
229
|
|
- mainFrame.toFront();
|
230
|
|
- }
|
231
|
|
- }
|
232
|
|
- }
|
233
|
|
-
|
234
|
|
- /**
|
235
|
|
- * {@inheritDoc}
|
236
|
|
- *
|
237
|
|
- * @param e Mouse event
|
238
|
|
- */
|
239
|
|
- @Override
|
240
|
|
- public void mousePressed(final MouseEvent e) {
|
241
|
|
- //Ignore
|
242
|
|
- }
|
243
|
|
-
|
244
|
|
- /**
|
245
|
|
- * {@inheritDoc}
|
246
|
|
- *
|
247
|
|
- * @param e Mouse event
|
248
|
|
- */
|
249
|
|
- @Override
|
250
|
|
- public void mouseReleased(final MouseEvent e) {
|
251
|
|
- //Ignore
|
252
|
|
- }
|
253
|
|
-
|
254
|
|
- /**
|
255
|
|
- * {@inheritDoc}
|
256
|
|
- *
|
257
|
|
- * @param e Mouse event
|
258
|
|
- */
|
259
|
|
- @Override
|
260
|
|
- public void mouseEntered(final MouseEvent e) {
|
261
|
|
- //Ignore
|
262
|
|
- }
|
263
|
|
-
|
264
|
|
- /**
|
265
|
|
- * {@inheritDoc}
|
266
|
|
- *
|
267
|
|
- * @param e Mouse event
|
268
|
|
- */
|
269
|
|
- @Override
|
270
|
|
- public void mouseExited(final MouseEvent e) {
|
271
|
|
- //Ignore
|
272
|
|
- }
|
273
|
|
-
|
274
|
|
- /** {@inheritDoc} */
|
275
|
|
- @Override
|
276
|
|
- public void processEvent(final ActionType type, final StringBuffer format,
|
277
|
|
- final Object... arguments) {
|
278
|
|
- if (type == CoreActionType.CLIENT_MINIMISED
|
279
|
|
- && identityController.getGlobalConfiguration()
|
280
|
|
- .getOptionBool(getDomain(), "autominimise")) {
|
281
|
|
- mainFrame.setVisible(false);
|
282
|
|
- }
|
283
|
|
- }
|
284
|
|
-
|
285
|
116
|
}
|