|
@@ -22,93 +22,39 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.addons.windowflashing;
|
24
|
24
|
|
25
|
|
-import com.dmdirc.actions.ActionManager;
|
26
|
|
-import com.dmdirc.actions.CoreActionType;
|
27
|
|
-import com.dmdirc.addons.ui_swing.MainFrame;
|
28
|
|
-import com.dmdirc.addons.ui_swing.SwingController;
|
29
|
|
-import com.dmdirc.config.ConfigBinder;
|
30
|
|
-import com.dmdirc.config.ConfigBinding;
|
31
|
25
|
import com.dmdirc.config.prefs.PluginPreferencesCategory;
|
32
|
26
|
import com.dmdirc.config.prefs.PreferencesCategory;
|
33
|
27
|
import com.dmdirc.config.prefs.PreferencesDialogModel;
|
34
|
28
|
import com.dmdirc.config.prefs.PreferencesSetting;
|
35
|
29
|
import com.dmdirc.config.prefs.PreferencesType;
|
36
|
|
-import com.dmdirc.interfaces.ActionListener;
|
37
|
|
-import com.dmdirc.interfaces.CommandController;
|
38
|
|
-import com.dmdirc.interfaces.actions.ActionType;
|
39
|
|
-import com.dmdirc.interfaces.config.IdentityController;
|
40
|
30
|
import com.dmdirc.plugins.Exported;
|
41
|
31
|
import com.dmdirc.plugins.PluginInfo;
|
42
|
32
|
import com.dmdirc.plugins.implementations.BaseCommandPlugin;
|
43
|
33
|
|
44
|
|
-import com.sun.jna.Native;
|
45
|
|
-import com.sun.jna.NativeLibrary;
|
46
|
|
-import com.sun.jna.Pointer;
|
47
|
|
-import com.sun.jna.platform.win32.User32;
|
48
|
|
-import com.sun.jna.platform.win32.WinDef.HWND;
|
49
|
|
-import com.sun.jna.platform.win32.WinUser;
|
50
|
|
-import com.sun.jna.platform.win32.WinUser.FLASHWINFO;
|
|
34
|
+import dagger.ObjectGraph;
|
51
|
35
|
|
52
|
36
|
/**
|
53
|
37
|
* Native notification plugin to make DMDirc support windows task bar flashing.
|
54
|
38
|
*/
|
55
|
|
-public class WindowFlashing extends BaseCommandPlugin implements ActionListener {
|
|
39
|
+public class WindowFlashing extends BaseCommandPlugin {
|
56
|
40
|
|
|
41
|
+ /** Window flashing manager. */
|
|
42
|
+ private WindowFlashingManager manager;
|
57
|
43
|
/** This plugin's plugin info. */
|
58
|
|
- private final PluginInfo pluginInfo;
|
59
|
|
- /** Config binder. */
|
60
|
|
- private final ConfigBinder binder;
|
61
|
|
- /** Parent swing controller. */
|
62
|
|
- private final SwingController controller;
|
63
|
|
- /** Action manager used for getting client events. */
|
64
|
|
- private final ActionManager actionManager;
|
65
|
|
- /** Library instance. */
|
66
|
|
- private User32 user32;
|
67
|
|
- /** Swing main frame. */
|
68
|
|
- private MainFrame mainFrame;
|
69
|
|
- /** Cached blink rate setting. */
|
70
|
|
- @ConfigBinding(domain="plugin-windowflashing", key="blinkrate",
|
71
|
|
- fallbacks={"plugin-windowflashing", "blinkratefallback"})
|
72
|
|
- private int blinkrate;
|
73
|
|
- /** Cached count setting. */
|
74
|
|
- @ConfigBinding(domain="plugin-windowflashing", key="flashcount",
|
75
|
|
- fallbacks={"plugin-windowflashing", "flashcountfallback"})
|
76
|
|
- private int flashcount;
|
77
|
|
- /** Cached flash taskbar setting. */
|
78
|
|
- @ConfigBinding(domain="plugin-windowflashing", key="flashtaskbar")
|
79
|
|
- private boolean flashtaskbar;
|
80
|
|
- /** Cached flash caption setting. */
|
81
|
|
- @ConfigBinding(domain="plugin-windowflashing", key="flashcaption")
|
82
|
|
- private boolean flashcaption;
|
|
44
|
+ private PluginInfo pluginInfo;
|
83
|
45
|
|
84
|
|
- /**
|
85
|
|
- * Creates a new instance of this plugin.
|
86
|
|
- *
|
87
|
|
- * @param pluginInfo This plugin's plugin info
|
88
|
|
- * @param identityController Identity Manager
|
89
|
|
- * @param controller Parent swing controller
|
90
|
|
- * @param actionManager Action manager
|
91
|
|
- * @param commandController command controller to register commands
|
92
|
|
- */
|
93
|
|
- public WindowFlashing(final PluginInfo pluginInfo,
|
94
|
|
- final IdentityController identityController,
|
95
|
|
- final SwingController controller,
|
96
|
|
- final ActionManager actionManager,
|
97
|
|
- final CommandController commandController) {
|
|
46
|
+ public WindowFlashing(final PluginInfo pluginInfo) {
|
98
|
47
|
this.pluginInfo = pluginInfo;
|
99
|
|
- this.controller = controller;
|
100
|
|
- this.actionManager = actionManager;
|
101
|
|
- binder = identityController.getGlobalConfiguration().getBinder();
|
102
|
|
- registerCommand(new FlashWindow(this, commandController), FlashWindow.INFO);
|
103
|
48
|
}
|
104
|
49
|
|
105
|
|
- /**
|
106
|
|
- * Flashes an inactive window under windows.
|
107
|
|
- */
|
108
|
|
- public void flashWindow() {
|
109
|
|
- if (!mainFrame.isFocused()) {
|
110
|
|
- user32.FlashWindowEx(setupFlashObject());
|
111
|
|
- }
|
|
50
|
+ @Override
|
|
51
|
+ public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
|
|
52
|
+ super.load(pluginInfo, graph);
|
|
53
|
+ this.pluginInfo = pluginInfo;
|
|
54
|
+
|
|
55
|
+ setObjectGraph(graph.plus(new WindowFlashingModule()));
|
|
56
|
+ registerCommand(FlashWindow.class, FlashWindow.INFO);
|
|
57
|
+ manager = getObjectGraph().get(WindowFlashingManager.class);
|
112
|
58
|
}
|
113
|
59
|
|
114
|
60
|
/**
|
|
@@ -120,31 +66,21 @@ public class WindowFlashing extends BaseCommandPlugin implements ActionListener
|
120
|
66
|
*/
|
121
|
67
|
@Exported
|
122
|
68
|
public void flashNotification(final String title, final String message) {
|
123
|
|
- flashWindow();
|
|
69
|
+ manager.flashWindow();
|
124
|
70
|
}
|
125
|
71
|
|
126
|
|
- /** {@inheritDoc} */
|
127
|
72
|
@Override
|
128
|
73
|
public void onLoad() {
|
129
|
|
- mainFrame = controller.getMainFrame();
|
130
|
|
- user32 = (User32) Native.loadLibrary("user32", User32.class);
|
131
|
|
- binder.bind(this, WindowFlashing.class);
|
132
|
|
- actionManager.registerListener(this, CoreActionType.CLIENT_FOCUS_GAINED);
|
133
|
74
|
super.onLoad();
|
|
75
|
+ manager.onLoad();
|
134
|
76
|
}
|
135
|
77
|
|
136
|
|
- /** {@inheritDoc} */
|
137
|
78
|
@Override
|
138
|
79
|
public void onUnload() {
|
139
|
80
|
super.onUnload();
|
140
|
|
- actionManager.unregisterListener(this);
|
141
|
|
- binder.unbind(this);
|
142
|
|
- mainFrame = null;
|
143
|
|
- user32 = null;
|
144
|
|
- NativeLibrary.getInstance("user32").dispose();
|
|
81
|
+ manager.onUnload();
|
145
|
82
|
}
|
146
|
83
|
|
147
|
|
- /** {@inheritDoc} */
|
148
|
84
|
@Override
|
149
|
85
|
public void showConfig(final PreferencesDialogModel manager) {
|
150
|
86
|
final PreferencesCategory category = new PluginPreferencesCategory(
|
|
@@ -152,93 +88,25 @@ public class WindowFlashing extends BaseCommandPlugin implements ActionListener
|
152
|
88
|
"General configuration for window flashing plugin.");
|
153
|
89
|
|
154
|
90
|
category.addSetting(new PreferencesSetting(
|
155
|
|
- PreferencesType.OPTIONALINTEGER, getDomain(), "blinkrate",
|
|
91
|
+ PreferencesType.OPTIONALINTEGER, pluginInfo.getDomain(), "blinkrate",
|
156
|
92
|
"Blink rate", "Specifies the rate at which the taskbar and or "
|
157
|
93
|
+ "caption will blink, if unspecified this will be your cursor "
|
158
|
94
|
+ "blink rate.",
|
159
|
95
|
manager.getConfigManager(), manager.getIdentity()));
|
160
|
96
|
category.addSetting(new PreferencesSetting(
|
161
|
|
- PreferencesType.OPTIONALINTEGER, getDomain(), "flashcount",
|
|
97
|
+ PreferencesType.OPTIONALINTEGER, pluginInfo.getDomain(), "flashcount",
|
162
|
98
|
"Flash count", "Specifies the number of times to blink, if "
|
163
|
99
|
+ "unspecified this will blink indefinitely",
|
164
|
100
|
manager.getConfigManager(), manager.getIdentity()));
|
165
|
101
|
category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
|
166
|
|
- getDomain(), "flashtaskbar", "Flash taskbar",
|
|
102
|
+ pluginInfo.getDomain(), "flashtaskbar", "Flash taskbar",
|
167
|
103
|
"Should the taskbar entry flash?",
|
168
|
104
|
manager.getConfigManager(), manager.getIdentity()));
|
169
|
105
|
category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
|
170
|
|
- getDomain(), "flashcaption", "Flash caption",
|
|
106
|
+ pluginInfo.getDomain(), "flashcaption", "Flash caption",
|
171
|
107
|
"Should the window caption flash?",
|
172
|
108
|
manager.getConfigManager(), manager.getIdentity()));
|
173
|
109
|
|
174
|
110
|
manager.getCategory("Plugins").addSubCategory(category);
|
175
|
111
|
}
|
176
|
|
-
|
177
|
|
- /**
|
178
|
|
- * Creates a new flash info object that starts flashing with the configured
|
179
|
|
- * settings.
|
180
|
|
- */
|
181
|
|
- private FLASHWINFO setupFlashObject() {
|
182
|
|
- final FLASHWINFO flashInfo = new FLASHWINFO();
|
183
|
|
- flashInfo.dwFlags = getFlags();
|
184
|
|
- flashInfo.dwTimeout = blinkrate;
|
185
|
|
- flashInfo.uCount = flashcount;
|
186
|
|
- flashInfo.hWnd = getHWND();
|
187
|
|
- flashInfo.cbSize = flashInfo.size();
|
188
|
|
- return flashInfo;
|
189
|
|
- }
|
190
|
|
-
|
191
|
|
- /**
|
192
|
|
- * Creates a new flash object that stops the flashing.
|
193
|
|
- */
|
194
|
|
- private FLASHWINFO stopFlashObject() {
|
195
|
|
- final FLASHWINFO flashInfo = new FLASHWINFO();
|
196
|
|
- flashInfo.dwFlags = WinUser.FLASHW_STOP;
|
197
|
|
- flashInfo.dwTimeout = 0;
|
198
|
|
- flashInfo.uCount = 0;
|
199
|
|
- flashInfo.hWnd = getHWND();
|
200
|
|
- flashInfo.cbSize = flashInfo.size();
|
201
|
|
- return flashInfo;
|
202
|
|
- }
|
203
|
|
-
|
204
|
|
- /**
|
205
|
|
- * Returns the native handle object for the main frame.
|
206
|
|
- * @return
|
207
|
|
- */
|
208
|
|
- private HWND getHWND() {
|
209
|
|
- final HWND hwnd = new HWND();
|
210
|
|
- final Pointer pointer = Native.getWindowPointer(mainFrame);
|
211
|
|
- hwnd.setPointer(pointer);
|
212
|
|
- return hwnd;
|
213
|
|
- }
|
214
|
|
-
|
215
|
|
- /**
|
216
|
|
- * Calculates the flags for the flash object based on config settings.
|
217
|
|
- *
|
218
|
|
- * @return Flash info flags
|
219
|
|
- */
|
220
|
|
- private int getFlags() {
|
221
|
|
- int returnValue = 0;
|
222
|
|
- if (flashtaskbar) {
|
223
|
|
- returnValue |= WinUser.FLASHW_TRAY;
|
224
|
|
- }
|
225
|
|
- if (flashcaption) {
|
226
|
|
- returnValue |= WinUser.FLASHW_CAPTION;
|
227
|
|
- }
|
228
|
|
- if (flashcount >= 0) {
|
229
|
|
- returnValue |= WinUser.FLASHW_TIMER;
|
230
|
|
- } else {
|
231
|
|
- returnValue |= WinUser.FLASHW_TIMERNOFG;
|
232
|
|
- }
|
233
|
|
- return returnValue;
|
234
|
|
- }
|
235
|
|
-
|
236
|
|
- /** {@inheritDoc} */
|
237
|
|
- @Override
|
238
|
|
- public void processEvent(final ActionType type, final StringBuffer format,
|
239
|
|
- final Object... arguments) {
|
240
|
|
- if (mainFrame != null) {
|
241
|
|
- user32.FlashWindowEx(stopFlashObject());
|
242
|
|
- }
|
243
|
|
- }
|
244
|
112
|
}
|