Browse Source

Tidy up (and fix horribly broken) window flashing plugin.

Change-Id: I893a0b659f57e9244e258a838b3252e8455e8be4
Fixes-Issue: CLIENT-331
Reviewed-on: http://gerrit.dmdirc.com/2316
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.7rc1
Greg Holmes 12 years ago
parent
commit
ea9e6c0a66

+ 36
- 65
src/com/dmdirc/addons/windowflashing/WindowFlashing.java View File

24
 
24
 
25
 import com.dmdirc.addons.ui_swing.MainFrame;
25
 import com.dmdirc.addons.ui_swing.MainFrame;
26
 import com.dmdirc.addons.ui_swing.SwingController;
26
 import com.dmdirc.addons.ui_swing.SwingController;
27
+import com.dmdirc.config.ConfigBinder;
28
+import com.dmdirc.config.ConfigBinding;
27
 import com.dmdirc.config.IdentityManager;
29
 import com.dmdirc.config.IdentityManager;
28
 import com.dmdirc.config.prefs.PluginPreferencesCategory;
30
 import com.dmdirc.config.prefs.PluginPreferencesCategory;
29
 import com.dmdirc.config.prefs.PreferencesCategory;
31
 import com.dmdirc.config.prefs.PreferencesCategory;
30
 import com.dmdirc.config.prefs.PreferencesDialogModel;
32
 import com.dmdirc.config.prefs.PreferencesDialogModel;
31
 import com.dmdirc.config.prefs.PreferencesSetting;
33
 import com.dmdirc.config.prefs.PreferencesSetting;
32
 import com.dmdirc.config.prefs.PreferencesType;
34
 import com.dmdirc.config.prefs.PreferencesType;
33
-import com.dmdirc.interfaces.ConfigChangeListener;
34
 import com.dmdirc.plugins.BasePlugin;
35
 import com.dmdirc.plugins.BasePlugin;
35
 import com.dmdirc.plugins.PluginInfo;
36
 import com.dmdirc.plugins.PluginInfo;
36
-import com.dmdirc.plugins.PluginManager;
37
 
37
 
38
 import com.sun.jna.Native;
38
 import com.sun.jna.Native;
39
 import com.sun.jna.NativeLibrary;
39
 import com.sun.jna.NativeLibrary;
46
 /**
46
 /**
47
  * Native notification plugin to make DMDirc support windows task bar flashing.
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
     /** Library instance. */
57
     /** Library instance. */
52
     private User32 user32;
58
     private User32 user32;
53
     /** Flash info object. */
59
     /** Flash info object. */
55
     /** Swing main frame. */
61
     /** Swing main frame. */
56
     private MainFrame mainFrame;
62
     private MainFrame mainFrame;
57
     /** Cached blink rate setting. */
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
     /** Cached count setting. */
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
      * Creates a new instance of this plugin.
79
      * Creates a new instance of this plugin.
68
      *
80
      *
69
      * @param pluginInfo This plugin's plugin info
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
         super();
88
         super();
73
         this.pluginInfo = pluginInfo;
89
         this.pluginInfo = pluginInfo;
90
+        this.controller = controller;
91
+        binder = identityManager.getGlobalConfiguration().getBinder();
74
         registerCommand(new FlashWindow(this), FlashWindow.INFO);
92
         registerCommand(new FlashWindow(this), FlashWindow.INFO);
75
     }
93
     }
76
 
94
 
98
     /** {@inheritDoc} */
116
     /** {@inheritDoc} */
99
     @Override
117
     @Override
100
     public void onLoad() {
118
     public void onLoad() {
101
-        mainFrame = ((SwingController) PluginManager
102
-                .getPluginManager().getPluginInfoByName("ui_swing")
103
-                .getPlugin()).getMainFrame();
119
+        mainFrame = controller.getMainFrame();
104
         user32 = (User32) Native.loadLibrary("user32", User32.class);
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
         super.onLoad();
122
         super.onLoad();
109
     }
123
     }
110
 
124
 
111
     /** {@inheritDoc} */
125
     /** {@inheritDoc} */
112
     @Override
126
     @Override
113
     public void onUnload() {
127
     public void onUnload() {
128
+        binder.unbind(this);
114
         mainFrame = null;
129
         mainFrame = null;
115
         user32 = null;
130
         user32 = null;
116
         flashInfo = null;
131
         flashInfo = null;
145
                 "Should the window caption flash?",
160
                 "Should the window caption flash?",
146
                 manager.getConfigManager(), manager.getIdentity()));
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
      */
168
      */
162
     private void setupFlashObject() {
169
     private void setupFlashObject() {
163
         flashInfo = new FLASHWINFO();
170
         flashInfo = new FLASHWINFO();
164
-        flashInfo.dwFlags = flags;
171
+        flashInfo.dwFlags = getFlags();
165
         flashInfo.dwTimeout = blinkrate;
172
         flashInfo.dwTimeout = blinkrate;
166
         flashInfo.uCount = flashcount;
173
         flashInfo.uCount = flashcount;
167
         flashInfo.hWnd = getHWND();
174
         flashInfo.hWnd = getHWND();
186
      */
193
      */
187
     private int getFlags() {
194
     private int getFlags() {
188
         int returnValue = 0;
195
         int returnValue = 0;
189
-        if (IdentityManager.getIdentityManager().getGlobalConfiguration()
190
-                .getOptionBool(getDomain(), "flashtaskbar")) {
196
+        if (flashtaskbar) {
191
             returnValue |= WinUser.FLASHW_TRAY;
197
             returnValue |= WinUser.FLASHW_TRAY;
192
         }
198
         }
193
-
194
-        if (IdentityManager.getIdentityManager().getGlobalConfiguration()
195
-                .getOptionBool(getDomain(), "flashcaption")) {
199
+        if (flashcaption) {
196
             returnValue |= WinUser.FLASHW_CAPTION;
200
             returnValue |= WinUser.FLASHW_CAPTION;
197
         }
201
         }
198
-
199
-        if (IdentityManager.getIdentityManager().getGlobalConfiguration()
200
-                .getOptionBool(getDomain(), "flashcount")) {
202
+        if (flashcount >= 0) {
201
             returnValue |= WinUser.FLASHW_TIMER;
203
             returnValue |= WinUser.FLASHW_TIMER;
202
         } else {
204
         } else {
203
             returnValue |= WinUser.FLASHW_TIMERNOFG;
205
             returnValue |= WinUser.FLASHW_TIMERNOFG;
204
         }
206
         }
205
-
206
         return returnValue;
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
 }

+ 2
- 0
src/com/dmdirc/addons/windowflashing/plugin.config View File

35
 
35
 
36
 defaults:
36
 defaults:
37
   blinkrate=false:0
37
   blinkrate=false:0
38
+  blinkratefallback=0
38
   flashcount=false:5
39
   flashcount=false:5
40
+  flashcountfallback=-1
39
   flashtaskbar=true
41
   flashtaskbar=true
40
   flashcaption=true
42
   flashcaption=true
41
 
43
 

Loading…
Cancel
Save