|
@@ -24,16 +24,16 @@ package com.dmdirc.addons.windowflashing;
|
24
|
24
|
|
25
|
25
|
import com.dmdirc.addons.ui_swing.MainFrame;
|
26
|
26
|
import com.dmdirc.addons.ui_swing.SwingController;
|
|
27
|
+import com.dmdirc.config.ConfigBinder;
|
|
28
|
+import com.dmdirc.config.ConfigBinding;
|
27
|
29
|
import com.dmdirc.config.IdentityManager;
|
28
|
30
|
import com.dmdirc.config.prefs.PluginPreferencesCategory;
|
29
|
31
|
import com.dmdirc.config.prefs.PreferencesCategory;
|
30
|
32
|
import com.dmdirc.config.prefs.PreferencesDialogModel;
|
31
|
33
|
import com.dmdirc.config.prefs.PreferencesSetting;
|
32
|
34
|
import com.dmdirc.config.prefs.PreferencesType;
|
33
|
|
-import com.dmdirc.interfaces.ConfigChangeListener;
|
34
|
35
|
import com.dmdirc.plugins.BasePlugin;
|
35
|
36
|
import com.dmdirc.plugins.PluginInfo;
|
36
|
|
-import com.dmdirc.plugins.PluginManager;
|
37
|
37
|
|
38
|
38
|
import com.sun.jna.Native;
|
39
|
39
|
import com.sun.jna.NativeLibrary;
|
|
@@ -46,8 +46,14 @@ import com.sun.jna.platform.win32.WinUser.FLASHWINFO;
|
46
|
46
|
/**
|
47
|
47
|
* Native notification plugin to make DMDirc support windows task bar flashing.
|
48
|
48
|
*/
|
49
|
|
-public class WindowFlashing extends BasePlugin implements ConfigChangeListener {
|
|
49
|
+public class WindowFlashing extends BasePlugin {
|
50
|
50
|
|
|
51
|
+ /** This plugin's plugin info. */
|
|
52
|
+ private final PluginInfo pluginInfo;
|
|
53
|
+ /** Config binder. */
|
|
54
|
+ private final ConfigBinder binder;
|
|
55
|
+ /** Parent swing controller. */
|
|
56
|
+ private final SwingController controller;
|
51
|
57
|
/** Library instance. */
|
52
|
58
|
private User32 user32;
|
53
|
59
|
/** Flash info object. */
|
|
@@ -55,22 +61,34 @@ public class WindowFlashing extends BasePlugin implements ConfigChangeListener {
|
55
|
61
|
/** Swing main frame. */
|
56
|
62
|
private MainFrame mainFrame;
|
57
|
63
|
/** Cached blink rate setting. */
|
58
|
|
- private int blinkrate = 0;
|
|
64
|
+ @ConfigBinding(domain="plugin-windowflashing", key="blinkrate",
|
|
65
|
+ fallbacks={"plugin-windowflashing", "blinkratefallback"})
|
|
66
|
+ private int blinkrate;
|
59
|
67
|
/** Cached count setting. */
|
60
|
|
- private int flashcount = Integer.MAX_VALUE;
|
61
|
|
- /** Cached flags setting. */
|
62
|
|
- private int flags = 0;
|
63
|
|
- /** This plugin's plugin info. */
|
64
|
|
- private final PluginInfo pluginInfo;
|
|
68
|
+ @ConfigBinding(domain="plugin-windowflashing", key="flashcount",
|
|
69
|
+ fallbacks={"plugin-windowflashing", "flashcountfallback"})
|
|
70
|
+ private int flashcount;
|
|
71
|
+ /** Cached flash taskbar setting. */
|
|
72
|
+ @ConfigBinding(domain="plugin-windowflashing", key="flashtaskbar")
|
|
73
|
+ private boolean flashtaskbar;
|
|
74
|
+ /** Cached flash caption setting. */
|
|
75
|
+ @ConfigBinding(domain="plugin-windowflashing", key="flashcaption")
|
|
76
|
+ private boolean flashcaption;
|
65
|
77
|
|
66
|
78
|
/**
|
67
|
79
|
* Creates a new instance of this plugin.
|
68
|
80
|
*
|
69
|
81
|
* @param pluginInfo This plugin's plugin info
|
|
82
|
+ * @param identityManager Identity Manager
|
|
83
|
+ * @param controller Parent swing controller
|
70
|
84
|
*/
|
71
|
|
- public WindowFlashing(final PluginInfo pluginInfo) {
|
|
85
|
+ public WindowFlashing(final PluginInfo pluginInfo,
|
|
86
|
+ final IdentityManager identityManager,
|
|
87
|
+ final SwingController controller) {
|
72
|
88
|
super();
|
73
|
89
|
this.pluginInfo = pluginInfo;
|
|
90
|
+ this.controller = controller;
|
|
91
|
+ binder = identityManager.getGlobalConfiguration().getBinder();
|
74
|
92
|
registerCommand(new FlashWindow(this), FlashWindow.INFO);
|
75
|
93
|
}
|
76
|
94
|
|
|
@@ -98,19 +116,16 @@ public class WindowFlashing extends BasePlugin implements ConfigChangeListener {
|
98
|
116
|
/** {@inheritDoc} */
|
99
|
117
|
@Override
|
100
|
118
|
public void onLoad() {
|
101
|
|
- mainFrame = ((SwingController) PluginManager
|
102
|
|
- .getPluginManager().getPluginInfoByName("ui_swing")
|
103
|
|
- .getPlugin()).getMainFrame();
|
|
119
|
+ mainFrame = controller.getMainFrame();
|
104
|
120
|
user32 = (User32) Native.loadLibrary("user32", User32.class);
|
105
|
|
- setupFlashObject();
|
106
|
|
- IdentityManager.getIdentityManager().getGlobalConfiguration()
|
107
|
|
- .addChangeListener(getDomain(), this);
|
|
121
|
+ binder.bind(this, WindowFlashing.class);
|
108
|
122
|
super.onLoad();
|
109
|
123
|
}
|
110
|
124
|
|
111
|
125
|
/** {@inheritDoc} */
|
112
|
126
|
@Override
|
113
|
127
|
public void onUnload() {
|
|
128
|
+ binder.unbind(this);
|
114
|
129
|
mainFrame = null;
|
115
|
130
|
user32 = null;
|
116
|
131
|
flashInfo = null;
|
|
@@ -145,15 +160,7 @@ public class WindowFlashing extends BasePlugin implements ConfigChangeListener {
|
145
|
160
|
"Should the window caption flash?",
|
146
|
161
|
manager.getConfigManager(), manager.getIdentity()));
|
147
|
162
|
|
148
|
|
- manager.addCategory(category);
|
149
|
|
- }
|
150
|
|
-
|
151
|
|
- /** {@inheritDoc} */
|
152
|
|
- @Override
|
153
|
|
- public void configChanged(final String domain, final String key) {
|
154
|
|
- blinkrate = getTimeout();
|
155
|
|
- flashcount = getCount();
|
156
|
|
- flags = getFlags();
|
|
163
|
+ manager.getCategory("Plugins").addSubCategory(category);
|
157
|
164
|
}
|
158
|
165
|
|
159
|
166
|
/**
|
|
@@ -161,7 +168,7 @@ public class WindowFlashing extends BasePlugin implements ConfigChangeListener {
|
161
|
168
|
*/
|
162
|
169
|
private void setupFlashObject() {
|
163
|
170
|
flashInfo = new FLASHWINFO();
|
164
|
|
- flashInfo.dwFlags = flags;
|
|
171
|
+ flashInfo.dwFlags = getFlags();
|
165
|
172
|
flashInfo.dwTimeout = blinkrate;
|
166
|
173
|
flashInfo.uCount = flashcount;
|
167
|
174
|
flashInfo.hWnd = getHWND();
|
|
@@ -186,53 +193,17 @@ public class WindowFlashing extends BasePlugin implements ConfigChangeListener {
|
186
|
193
|
*/
|
187
|
194
|
private int getFlags() {
|
188
|
195
|
int returnValue = 0;
|
189
|
|
- if (IdentityManager.getIdentityManager().getGlobalConfiguration()
|
190
|
|
- .getOptionBool(getDomain(), "flashtaskbar")) {
|
|
196
|
+ if (flashtaskbar) {
|
191
|
197
|
returnValue |= WinUser.FLASHW_TRAY;
|
192
|
198
|
}
|
193
|
|
-
|
194
|
|
- if (IdentityManager.getIdentityManager().getGlobalConfiguration()
|
195
|
|
- .getOptionBool(getDomain(), "flashcaption")) {
|
|
199
|
+ if (flashcaption) {
|
196
|
200
|
returnValue |= WinUser.FLASHW_CAPTION;
|
197
|
201
|
}
|
198
|
|
-
|
199
|
|
- if (IdentityManager.getIdentityManager().getGlobalConfiguration()
|
200
|
|
- .getOptionBool(getDomain(), "flashcount")) {
|
|
202
|
+ if (flashcount >= 0) {
|
201
|
203
|
returnValue |= WinUser.FLASHW_TIMER;
|
202
|
204
|
} else {
|
203
|
205
|
returnValue |= WinUser.FLASHW_TIMERNOFG;
|
204
|
206
|
}
|
205
|
|
-
|
206
|
207
|
return returnValue;
|
207
|
208
|
}
|
208
|
|
-
|
209
|
|
- /**
|
210
|
|
- * Returns the blink rate value from the config.
|
211
|
|
- *
|
212
|
|
- * @return Blink rate
|
213
|
|
- */
|
214
|
|
- private int getTimeout() {
|
215
|
|
- if (IdentityManager.getIdentityManager().getGlobalConfiguration()
|
216
|
|
- .hasOptionInt(getDomain(), "blinkrate")) {
|
217
|
|
- return IdentityManager.getIdentityManager().getGlobalConfiguration()
|
218
|
|
- .getOptionInt(getDomain(), "blinkrate");
|
219
|
|
- } else {
|
220
|
|
- return 0;
|
221
|
|
- }
|
222
|
|
- }
|
223
|
|
-
|
224
|
|
- /**
|
225
|
|
- * Returns the flash count value from the config.
|
226
|
|
- *
|
227
|
|
- * @return Number of flashes before stopping
|
228
|
|
- */
|
229
|
|
- private int getCount() {
|
230
|
|
- if (IdentityManager.getIdentityManager().getGlobalConfiguration()
|
231
|
|
- .hasOptionInt(getDomain(), "flashcount")) {
|
232
|
|
- return IdentityManager.getIdentityManager().getGlobalConfiguration()
|
233
|
|
- .getOptionInt(getDomain(), "flashcount");
|
234
|
|
- } else {
|
235
|
|
- return Integer.MAX_VALUE;
|
236
|
|
- }
|
237
|
|
- }
|
238
|
209
|
}
|