Przeglądaj źródła

Add window flashing config options.

Change-Id: Ib5e2fe93f4000d801c92be2f7fa9ce706a6ca998
Reviewed-on: http://gerrit.dmdirc.com/1879
Reviewed-by: Chris Smith <chris@dmdirc.com>
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
tags/0.7rc1
Greg Holmes 13 lat temu
rodzic
commit
839cfacd95

+ 130
- 23
src/com/dmdirc/addons/windowflashing/WindowFlashing.java Wyświetl plik

@@ -25,6 +25,13 @@ package com.dmdirc.addons.windowflashing;
25 25
 import com.dmdirc.addons.ui_swing.MainFrame;
26 26
 import com.dmdirc.addons.ui_swing.SwingController;
27 27
 import com.dmdirc.commandparser.CommandManager;
28
+import com.dmdirc.config.IdentityManager;
29
+import com.dmdirc.config.prefs.PluginPreferencesCategory;
30
+import com.dmdirc.config.prefs.PreferencesCategory;
31
+import com.dmdirc.config.prefs.PreferencesDialogModel;
32
+import com.dmdirc.config.prefs.PreferencesSetting;
33
+import com.dmdirc.config.prefs.PreferencesType;
34
+import com.dmdirc.interfaces.ConfigChangeListener;
28 35
 import com.dmdirc.plugins.Plugin;
29 36
 import com.dmdirc.plugins.PluginManager;
30 37
 
@@ -33,25 +40,14 @@ import com.sun.jna.NativeLibrary;
33 40
 import com.sun.jna.Pointer;
34 41
 import com.sun.jna.platform.win32.User32;
35 42
 import com.sun.jna.platform.win32.WinDef.HWND;
43
+import com.sun.jna.platform.win32.WinUser;
36 44
 import com.sun.jna.platform.win32.WinUser.FLASHWINFO;
37 45
 
38 46
 /**
39 47
  * Native notification plugin to make DMDirc support windows task bar flashing.
40 48
  */
41
-public class WindowFlashing extends Plugin {
42
-
43
-    /** Stops the window flashing. */
44
-    private static final int FLASHW_STOP = 0; //NOPMD
45
-    /** Flashes the window caption. */
46
-    private static final int FLASHW_CAPTION = 1; //NOPMD
47
-    /** Flashes the window's taskbar entry. */
48
-    private static final int FLASHW_TRAY = 2; //NOPMD
49
-    /** Flash both the window's caption and taskbar entry. */
50
-    private static final int FLASHW_ALL = 3;
51
-    /** Flash until FLASHW_STOP is set. */
52
-    private static final int FLASHW_TIMER = 4; //NOPMD
53
-    /** Flash until the window gains focus. */
54
-    private static final int FLASHW_TIMERNOFG = 12;
49
+public class WindowFlashing extends Plugin implements ConfigChangeListener {
50
+
55 51
     /** Library instance. */
56 52
     private User32 user32;
57 53
     /** Flash info object. */
@@ -60,12 +56,19 @@ public class WindowFlashing extends Plugin {
60 56
     private MainFrame mainFrame;
61 57
     /** Flash window command. */
62 58
     private FlashWindow flashCommand;
59
+    /** Cached blink rate setting. */
60
+    private int blinkrate = 0;
61
+    /** Cached count setting. */
62
+    private int flashcount = Integer.MAX_VALUE;
63
+    /** Cached flags setting. */
64
+    private int flags = 0;
63 65
 
64 66
     /**
65 67
      * Flashes an inactive window under windows.
66 68
      */
67 69
     public void flashWindow() {
68 70
         if (!mainFrame.isFocused()) {
71
+            setupFlashObject();
69 72
             user32.FlashWindowEx(flashInfo);
70 73
         }
71 74
     }
@@ -90,15 +93,8 @@ public class WindowFlashing extends Plugin {
90 93
                 .getPluginManager().getPluginInfoByName("ui_swing")
91 94
                 .getPlugin()).getMainFrame();
92 95
         user32 = (User32) Native.loadLibrary("user32", User32.class);
93
-        final HWND hwnd = new HWND();
94
-        final Pointer pointer = Native.getWindowPointer(mainFrame);
95
-        hwnd.setPointer(pointer);
96
-        flashInfo = new FLASHWINFO();
97
-        flashInfo.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG;
98
-        flashInfo.dwTimeout = 0;
99
-        flashInfo.uCount = Integer.MAX_VALUE;
100
-        flashInfo.hWnd = hwnd;
101
-        flashInfo.cbSize = flashInfo.size();
96
+        setupFlashObject();
97
+        IdentityManager.getGlobalConfig().addChangeListener(getDomain(), this);
102 98
     }
103 99
 
104 100
     /** {@inheritDoc} */
@@ -111,4 +107,115 @@ public class WindowFlashing extends Plugin {
111 107
         flashInfo = null;
112 108
         NativeLibrary.getInstance("user32").dispose();
113 109
     }
110
+
111
+    /** {@inheritDoc} */
112
+    @Override
113
+    public void showConfig(final PreferencesDialogModel manager) {
114
+        final PreferencesCategory category = new PluginPreferencesCategory(
115
+                getPluginInfo(), "Window Flashing",
116
+                "General configuration for window flashing plugin.");
117
+
118
+        category.addSetting(new PreferencesSetting(
119
+                PreferencesType.OPTIONALINTEGER, getDomain(), "blinkrate",
120
+                "Blink rate", "Specifies the rate at which the taskbar and or "
121
+                + "caption will blink, if unspecified this will be your cursor "
122
+                + "blink rate."));
123
+        category.addSetting(new PreferencesSetting(
124
+                PreferencesType.OPTIONALINTEGER, getDomain(), "flashcount",
125
+                "Flash count", "Specifies the number of times to blink, if "
126
+                + "unspecified this will blink indefinitely"));
127
+        category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
128
+                getDomain(), "flashtaskbar", "Flash taskbar",
129
+                "Should the taskbar entry flash?"));
130
+        category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
131
+                getDomain(), "flashcaption", "Flash caption",
132
+                "Should the window caption flash?"));
133
+
134
+        manager.addCategory(category);
135
+    }
136
+
137
+    /** {@inheritDoc} */
138
+    @Override
139
+    public void configChanged(final String domain, final String key) {
140
+        blinkrate = getTimeout();
141
+        flashcount = getCount();
142
+        flags = getFlags();
143
+    }
144
+
145
+    /**
146
+     * Creates a new flash info object with the cached settings.
147
+     */
148
+    private void setupFlashObject() {
149
+        flashInfo = new FLASHWINFO();
150
+        flashInfo.dwFlags = flags;
151
+        flashInfo.dwTimeout = blinkrate;
152
+        flashInfo.uCount = flashcount;
153
+        flashInfo.hWnd = getHWND();
154
+        flashInfo.cbSize = flashInfo.size();
155
+    }
156
+
157
+    /**
158
+     * Returns the native handle object for the main frame.
159
+     * @return
160
+     */
161
+    private HWND getHWND() {
162
+        final HWND hwnd = new HWND();
163
+        final Pointer pointer = Native.getWindowPointer(mainFrame);
164
+        hwnd.setPointer(pointer);
165
+        return hwnd;
166
+    }
167
+
168
+    /**
169
+     * Calculates the flags for the flash object based on config settings.
170
+     *
171
+     * @return Flash info flags
172
+     */
173
+    private int getFlags() {
174
+        int returnValue = 0;
175
+        if (IdentityManager.getGlobalConfig().getOptionBool(getDomain(),
176
+                "flashtaskbar")) {
177
+            returnValue |= WinUser.FLASHW_TRAY;
178
+        }
179
+        if (IdentityManager.getGlobalConfig().getOptionBool(getDomain(),
180
+                "flashcaption")) {
181
+            returnValue |= WinUser.FLASHW_CAPTION;
182
+        }
183
+        if (IdentityManager.getGlobalConfig().getOptionBool(getDomain(),
184
+                "flashcount")) {
185
+            returnValue |= WinUser.FLASHW_TIMER;
186
+        } else {
187
+            returnValue |= WinUser.FLASHW_TIMERNOFG;
188
+        }
189
+        return returnValue;
190
+    }
191
+
192
+    /**
193
+     * Returns the blink rate value from the config.
194
+     *
195
+     * @return Blink rate
196
+     */
197
+    private int getTimeout() {
198
+        if (IdentityManager.getGlobalConfig().hasOptionInt(getDomain(),
199
+                "blinkrate")) {
200
+            return IdentityManager.getGlobalConfig().getOptionInt(
201
+                    getDomain(), "blinkrate");
202
+        } else {
203
+            return 0;
204
+        }
205
+    }
206
+
207
+    /**
208
+     * Returns the flash count value from the config.
209
+     *
210
+     * @return Number of flashes before stopping
211
+     */
212
+    private int getCount() {
213
+        if (IdentityManager.getGlobalConfig().hasOptionInt(getDomain(),
214
+                "flashcount")) {
215
+            return IdentityManager.getGlobalConfig().getOptionInt(
216
+                    getDomain(), "flashcount");
217
+        } else {
218
+            return Integer.MAX_VALUE;
219
+        }
220
+    }
114 221
 }

+ 7
- 0
src/com/dmdirc/addons/windowflashing/plugin.config Wyświetl plik

@@ -8,6 +8,7 @@ keysections:
8 8
   updates
9 9
   requires
10 10
   version
11
+  defaults
11 12
 
12 13
 metadata:
13 14
   author=Greg <greg@dmdirc.com>
@@ -32,5 +33,11 @@ required-services:
32 33
 provides:
33 34
   windowflash command
34 35
 
36
+defaults:
37
+  blinkrate=false:0
38
+  flashcount=false:5
39
+  flashtaskbar=true
40
+  flashcaption=true
41
+
35 42
 exports:
36 43
   flashNotification in com.dmdirc.addons.windowflashing.WindowFlashing as showNotification

Ładowanie…
Anuluj
Zapisz