Преглед на файлове

Crazy caching!

Change-Id: Ibcb94ca616d3b6e9ed6a1b6c94698ab74cbd7872
Reviewed-on: http://gerrit.dmdirc.com/484
Tested-by: Gregory Holmes <greboid@dmdirc.com>
Reviewed-by: Shane Mc Cormack <shane@dmdirc.com>
Automatic-Compile: Shane Mc Cormack <shane@dmdirc.com>
tags/0.6.3
Gregory Holmes преди 14 години
родител
ревизия
fcdc626c2f

+ 0
- 3
src/com/dmdirc/addons/freedesktop_notifications/FDNotifyCommand.java Целия файл

@@ -22,14 +22,11 @@
22 22
 
23 23
 package com.dmdirc.addons.freedesktop_notifications;
24 24
 
25
-import com.dmdirc.Server;
26 25
 import com.dmdirc.commandparser.CommandArguments;
27 26
 import com.dmdirc.commandparser.CommandManager;
28 27
 import com.dmdirc.commandparser.commands.GlobalCommand;
29 28
 import com.dmdirc.ui.interfaces.InputWindow;
30 29
 
31
-import java.util.List;
32
-
33 30
 /**
34 31
  * The FDNotify Command shows a nice popup on using the FreeDesktop
35 32
  * VisualNotifications.

+ 45
- 24
src/com/dmdirc/addons/freedesktop_notifications/FreeDesktopNotificationsPlugin.java Целия файл

@@ -22,44 +22,58 @@
22 22
 
23 23
 package com.dmdirc.addons.freedesktop_notifications;
24 24
 
25
+import com.dmdirc.Main;
26
+import com.dmdirc.addons.freedesktop_notifications.commons.StringEscapeUtils;
27
+import com.dmdirc.commandparser.CommandManager;
28
+import com.dmdirc.config.IdentityManager;
29
+import com.dmdirc.config.prefs.PreferencesCategory;
30
+import com.dmdirc.config.prefs.PreferencesManager;
31
+import com.dmdirc.config.prefs.PreferencesSetting;
32
+import com.dmdirc.config.prefs.PreferencesType;
33
+import com.dmdirc.installer.StreamReader;
34
+import com.dmdirc.interfaces.ConfigChangeListener;
35
+import com.dmdirc.logger.ErrorLevel;
36
+import com.dmdirc.logger.Logger;
25 37
 import com.dmdirc.plugins.Plugin;
26 38
 import com.dmdirc.plugins.PluginInfo;
27 39
 import com.dmdirc.plugins.PluginManager;
40
+import com.dmdirc.ui.messages.Styliser;
28 41
 import com.dmdirc.util.resourcemanager.ResourceManager;
29
-import com.dmdirc.logger.ErrorLevel;
30
-import com.dmdirc.logger.Logger;
31
-import com.dmdirc.Main;
42
+
32 43
 import java.io.File;
33 44
 import java.io.IOException;
34 45
 import java.util.ArrayList;
35
-import com.dmdirc.commandparser.CommandManager;
36
-import com.dmdirc.installer.StreamReader;
37
-import com.dmdirc.ui.messages.Styliser;
38
-import com.dmdirc.config.IdentityManager;
39
-import com.dmdirc.config.Identity;
40
-import com.dmdirc.config.prefs.PreferencesManager;
41
-import com.dmdirc.config.prefs.PreferencesCategory;
42
-import com.dmdirc.config.prefs.PreferencesSetting;
43
-import com.dmdirc.config.prefs.PreferencesType;
44
-import com.dmdirc.addons.freedesktop_notifications.commons.StringEscapeUtils;;
45 46
 
46 47
 /**
47 48
  * This plugin adds freedesktop Style Notifications to dmdirc.
48 49
  *
49 50
  * @author Shane 'Dataforce' McCormack
50 51
  */
51
-public final class FreeDesktopNotificationsPlugin extends Plugin {
52
+public final class FreeDesktopNotificationsPlugin extends Plugin implements
53
+        ConfigChangeListener{
52 54
     /** The DcopCommand we created */
53 55
     private FDNotifyCommand command = null;
54
-    
55 56
     /** Files dir */
56 57
     private static final String filesDir  = Main.getConfigDir() + "plugins/freedesktop_notifications_files/";
58
+    /** notification timeout. */
59
+    private int timeout;
60
+    /** notification icon. */
61
+    private String icon;
62
+    /** Escape HTML. */
63
+    private boolean escapehtml;
64
+    /** Strict escape. */
65
+    private boolean strictescape;
66
+    /** Strip codes. */
67
+    private boolean stripcodes;
57 68
     
58 69
     /**
59 70
      * Creates a new instance of the FreeDesktopNotifications Plugin.
60 71
      */
61 72
     public FreeDesktopNotificationsPlugin() {
62 73
         super();
74
+
75
+        IdentityManager.getGlobalConfig().addChangeListener(getDomain(), this);
76
+        setCachedSettings();
63 77
     }
64 78
 
65 79
     /**
@@ -70,8 +84,6 @@ public final class FreeDesktopNotificationsPlugin extends Plugin {
70 84
      * @return True if the notification was shown.
71 85
      */
72 86
     public boolean showNotification(final String title, final String message) {
73
-        final int seconds = IdentityManager.getGlobalConfig().getOptionInt(getDomain(), "general.timeout");
74
-        final String icon = IdentityManager.getGlobalConfig().getOption(getDomain(), "general.icon");
75 87
         final ArrayList<String> args = new ArrayList<String>();
76 88
         
77 89
         args.add("/usr/bin/env");
@@ -82,7 +94,7 @@ public final class FreeDesktopNotificationsPlugin extends Plugin {
82 94
         args.add("-i");
83 95
         args.add(icon);
84 96
         args.add("-t");
85
-        args.add(Integer.toString(seconds * 1000));
97
+        args.add(Integer.toString(timeout * 1000));
86 98
         args.add("-s");
87 99
 
88 100
         if (title != null && !title.isEmpty()) {
@@ -113,10 +125,6 @@ public final class FreeDesktopNotificationsPlugin extends Plugin {
113 125
      * @return Input string after being processed according to config settings.
114 126
      */
115 127
     public final String prepareString(final String input) {
116
-        final boolean escapehtml = IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "advanced.escapehtml");
117
-	final boolean strictescape = IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "advanced.strictescape");
118
-        final boolean stripcodes = IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "advanced.stripcodes");
119
-
120 128
         String output = input;
121 129
         if (stripcodes) { output = Styliser.stipControlCodes(output); }
122 130
         if (escapehtml) {
@@ -178,8 +186,7 @@ public final class FreeDesktopNotificationsPlugin extends Plugin {
178 186
     /** {@inheritDoc} */
179 187
     @Override
180 188
     public void domainUpdated() {
181
-        final Identity defaults = IdentityManager.getAddonIdentity();
182
-        defaults.setOption(getDomain(), "general.icon", filesDir+"icon.png");
189
+        IdentityManager.getAddonIdentity().setOption(getDomain(), "general.icon", filesDir+"icon.png");
183 190
     }
184 191
     
185 192
     /** {@inheritDoc} */
@@ -195,5 +202,19 @@ public final class FreeDesktopNotificationsPlugin extends Plugin {
195 202
         
196 203
         manager.getCategory("Plugins").addSubCategory(general);
197 204
     }
205
+
206
+    private void setCachedSettings() {
207
+        timeout = IdentityManager.getGlobalConfig().getOptionInt(getDomain(), "general.timeout");
208
+        icon = IdentityManager.getGlobalConfig().getOption(getDomain(), "general.icon");
209
+        escapehtml = IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "advanced.escapehtml");
210
+	strictescape = IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "advanced.strictescape");
211
+        stripcodes = IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "advanced.stripcodes");
212
+    }
213
+
214
+    /** {@inheritDoc} */
215
+    @Override
216
+    public void configChanged(final String domain, final String key) {
217
+        setCachedSettings();
218
+    }
198 219
 }
199 220
 

+ 1
- 0
src/com/dmdirc/addons/nickcolours/ColourRenderer.java Целия файл

@@ -25,6 +25,7 @@ package com.dmdirc.addons.nickcolours;
25 25
 import com.dmdirc.ui.messages.ColourManager;
26 26
 
27 27
 import java.awt.Color;
28
+
28 29
 import java.awt.Component;
29 30
 import javax.swing.JTable;
30 31
 import javax.swing.border.LineBorder;

+ 4
- 10
src/com/dmdirc/addons/nickcolours/NickColourInputDialog.java Целия файл

@@ -49,15 +49,12 @@ public class NickColourInputDialog extends StandardDialog
49 49
      * objects being unserialized with the new class).
50 50
      */
51 51
     private static final long serialVersionUID = 1;
52
-    
53 52
     /** Whether or not this is a new entry (as opposed to editing an old one). */
54 53
     private boolean isnew;
55 54
     /** The row we're editing, if this isn't a new entry. */
56 55
     private int row;
57
-    
58 56
     /** The NickColourPanel we're reporting to. */
59 57
     private final NickColourPanel panel;
60
-    
61 58
     /** nickname textfield. */
62 59
     private JTextField nickname;
63 60
     /** network textfield. */
@@ -167,17 +164,14 @@ public class NickColourInputDialog extends StandardDialog
167 164
     }
168 165
     
169 166
     /** Saves settings. */
170
-    public void saveSettings() {
171
-        final String myNetwork = network.getText().toLowerCase();
172
-        final String myNickname = nickname.getText().toLowerCase();
173
-        final String myTextColour = textColour.getColour();
174
-        final String myNickColour = nicklistColour.getColour();
175
-        
167
+    public void saveSettings() {        
176 168
         if (!isnew) {
177 169
             panel.removeRow(row);
178 170
         }
179 171
         
180
-        panel.addRow(myNetwork, myNickname, myTextColour, myNickColour);
172
+        panel.addRow(network.getText().toLowerCase(),
173
+                nickname.getText().toLowerCase(),
174
+                nickname.getText().toLowerCase(), nicklistColour.getColour());
181 175
     }
182 176
     
183 177
 }

+ 31
- 14
src/com/dmdirc/addons/nickcolours/NickColourPlugin.java Целия файл

@@ -33,6 +33,7 @@ import com.dmdirc.config.prefs.PreferencesManager;
33 33
 import com.dmdirc.config.prefs.PreferencesSetting;
34 34
 import com.dmdirc.config.prefs.PreferencesType;
35 35
 import com.dmdirc.interfaces.ActionListener;
36
+import com.dmdirc.interfaces.ConfigChangeListener;
36 37
 import com.dmdirc.parser.interfaces.ChannelClientInfo;
37 38
 import com.dmdirc.parser.interfaces.ChannelInfo;
38 39
 import com.dmdirc.parser.interfaces.ClientInfo;
@@ -49,13 +50,19 @@ import java.util.Map;
49 50
  *
50 51
  * @author chris
51 52
  */
52
-public final class NickColourPlugin extends Plugin implements ActionListener {
53
+public final class NickColourPlugin extends Plugin implements ActionListener,
54
+        ConfigChangeListener {
53 55
     
54 56
     /** "Random" colours to use to colour nicknames. */
55 57
     private String[] randColours = new String[] {
56 58
         "E90E7F", "8E55E9", "B30E0E", "18B33C",
57 59
         "58ADB3", "9E54B3", "B39875", "3176B3",
58 60
     };
61
+    private boolean useowncolour;
62
+    private String owncolour;
63
+    private boolean userandomcolour;
64
+    private boolean settext;
65
+    private boolean setnicklist;
59 66
     
60 67
     /** Creates a new instance of NickColourPlugin. */
61 68
     public NickColourPlugin() {
@@ -94,12 +101,10 @@ public final class NickColourPlugin extends Plugin implements ActionListener {
94 101
         final String nickOption2 = "color:"
95 102
                 + client.getClient().getParser().getStringConverter().toLowerCase("*:" + client.getClient().getNickname());
96 103
         
97
-        if (IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "useowncolour")
98
-                && client.getClient().equals(myself)) {
99
-            final Color color = ColourManager.parseColour(
100
-                    IdentityManager.getGlobalConfig().getOption(getDomain(), "owncolour"));
104
+        if (useowncolour && client.getClient().equals(myself)) {
105
+            final Color color = ColourManager.parseColour(owncolour);
101 106
             putColour(map, color, color);
102
-        }  else if (IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "userandomcolour")) {
107
+        }  else if (userandomcolour) {
103 108
             putColour(map, getColour(client.getClient().getNickname()), getColour(client.getClient().getNickname()));
104 109
         }
105 110
         
@@ -136,13 +141,11 @@ public final class NickColourPlugin extends Plugin implements ActionListener {
136 141
      */
137 142
     @SuppressWarnings("unchecked")
138 143
     private void putColour(final Map map, final Color textColour, final Color nickColour) {
139
-        if (IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "settext")
140
-                && textColour != null) {
144
+        if (settext && textColour != null) {
141 145
             map.put(ChannelClientProperty.TEXT_FOREGROUND, textColour);
142 146
         }
143 147
         
144
-        if (IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "setnicklist")
145
-                && nickColour != null) {
148
+        if (setnicklist && nickColour != null) {
146 149
             map.put(ChannelClientProperty.NICKLIST_FOREGROUND, nickColour);
147 150
         }
148 151
     }
@@ -218,10 +221,7 @@ public final class NickColourPlugin extends Plugin implements ActionListener {
218 221
     /** {@inheritDoc} */
219 222
     @Override
220 223
     public void onLoad() {
221
-        if (IdentityManager.getGlobalConfig().hasOptionString(getDomain(), "randomcolours")) {
222
-            randColours = IdentityManager.getGlobalConfig().getOptionList(getDomain(), "randomcolours").toArray(new String[0]);
223
-        }
224
-        
224
+        setCachedSettings();
225 225
         ActionManager.addListener(this, CoreActionType.CHANNEL_GOTNAMES,
226 226
                 CoreActionType.CHANNEL_JOIN);
227 227
     }
@@ -265,5 +265,22 @@ public final class NickColourPlugin extends Plugin implements ActionListener {
265 265
         general.addSubCategory(colours);
266 266
         manager.getCategory("Plugins").addSubCategory(general);
267 267
     }
268
+
269
+    private void setCachedSettings() {
270
+        useowncolour = IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "useowncolour");
271
+        owncolour = IdentityManager.getGlobalConfig().getOption(getDomain(), "owncolour");
272
+        userandomcolour = IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "userandomcolour");
273
+        settext = IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "settext");
274
+        setnicklist = IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "setnicklist");
275
+        if (IdentityManager.getGlobalConfig().hasOptionString(getDomain(), "randomcolours")) {
276
+            randColours = IdentityManager.getGlobalConfig().getOptionList(getDomain(), "randomcolours").toArray(new String[0]);
277
+        }
278
+    }
279
+
280
+    /** {@inheritDoc} */
281
+    @Override
282
+    public void configChanged(final String domain, final String key) {
283
+        setCachedSettings();
284
+    }
268 285
     
269 286
 }

+ 57
- 51
src/com/dmdirc/addons/parser_twitter/Twitter.java Целия файл

@@ -24,9 +24,15 @@ package com.dmdirc.addons.parser_twitter;
24 24
 
25 25
 import com.dmdirc.addons.parser_twitter.api.TwitterAPI;
26 26
 import com.dmdirc.addons.parser_twitter.api.TwitterErrorHandler;
27
+import com.dmdirc.addons.parser_twitter.api.TwitterException;
27 28
 import com.dmdirc.addons.parser_twitter.api.TwitterMessage;
29
+import com.dmdirc.addons.parser_twitter.api.TwitterRawHandler;
28 30
 import com.dmdirc.addons.parser_twitter.api.TwitterStatus;
29 31
 import com.dmdirc.addons.parser_twitter.api.TwitterUser;
32
+import com.dmdirc.config.ConfigManager;
33
+import com.dmdirc.config.IdentityManager;
34
+import com.dmdirc.interfaces.ConfigChangeListener;
35
+import com.dmdirc.logger.ErrorManager;
30 36
 import com.dmdirc.parser.common.CallbackManager;
31 37
 import com.dmdirc.parser.common.DefaultStringConverter;
32 38
 import com.dmdirc.parser.common.IgnoreList;
@@ -37,13 +43,18 @@ import com.dmdirc.parser.interfaces.ChannelInfo;
37 43
 import com.dmdirc.parser.interfaces.ClientInfo;
38 44
 import com.dmdirc.parser.interfaces.LocalClientInfo;
39 45
 import com.dmdirc.parser.interfaces.Parser;
40
-import com.dmdirc.parser.interfaces.callbacks.ChannelMessageListener;
41 46
 import com.dmdirc.parser.interfaces.StringConverter;
42 47
 import com.dmdirc.parser.interfaces.callbacks.AuthNoticeListener;
48
+import com.dmdirc.parser.interfaces.callbacks.ChannelJoinListener;
49
+import com.dmdirc.parser.interfaces.callbacks.ChannelKickListener;
50
+import com.dmdirc.parser.interfaces.callbacks.ChannelMessageListener;
43 51
 import com.dmdirc.parser.interfaces.callbacks.ChannelModeChangeListener;
44 52
 import com.dmdirc.parser.interfaces.callbacks.ChannelNamesListener;
45 53
 import com.dmdirc.parser.interfaces.callbacks.ChannelSelfJoinListener;
46 54
 import com.dmdirc.parser.interfaces.callbacks.ChannelTopicListener;
55
+import com.dmdirc.parser.interfaces.callbacks.DataInListener;
56
+import com.dmdirc.parser.interfaces.callbacks.DataOutListener;
57
+import com.dmdirc.parser.interfaces.callbacks.DebugInfoListener;
47 58
 import com.dmdirc.parser.interfaces.callbacks.MotdEndListener;
48 59
 import com.dmdirc.parser.interfaces.callbacks.MotdLineListener;
49 60
 import com.dmdirc.parser.interfaces.callbacks.MotdStartListener;
@@ -52,34 +63,21 @@ import com.dmdirc.parser.interfaces.callbacks.NickChangeListener;
52 63
 import com.dmdirc.parser.interfaces.callbacks.NumericListener;
53 64
 import com.dmdirc.parser.interfaces.callbacks.Post005Listener;
54 65
 import com.dmdirc.parser.interfaces.callbacks.PrivateMessageListener;
55
-import com.dmdirc.parser.interfaces.callbacks.UnknownMessageListener;
56 66
 import com.dmdirc.parser.interfaces.callbacks.PrivateNoticeListener;
57 67
 import com.dmdirc.parser.interfaces.callbacks.ServerReadyListener;
58
-import com.dmdirc.parser.interfaces.callbacks.UserModeDiscoveryListener;
59 68
 import com.dmdirc.parser.interfaces.callbacks.SocketCloseListener;
69
+import com.dmdirc.parser.interfaces.callbacks.UnknownMessageListener;
70
+import com.dmdirc.parser.interfaces.callbacks.UserModeDiscoveryListener;
60 71
 import com.dmdirc.ui.messages.Styliser;
61
-import java.lang.reflect.InvocationTargetException;
72
+
73
+import java.net.URI;
62 74
 import java.util.ArrayList;
75
+import java.util.Calendar;
63 76
 import java.util.Collection;
64
-
65 77
 import java.util.Collections;
66 78
 import java.util.HashMap;
67 79
 import java.util.List;
68 80
 import java.util.Map;
69
-import com.dmdirc.interfaces.ConfigChangeListener;
70
-import com.dmdirc.addons.parser_twitter.api.TwitterException;
71
-import com.dmdirc.addons.parser_twitter.api.TwitterRawHandler;
72
-import com.dmdirc.config.ConfigManager;
73
-import com.dmdirc.config.IdentityManager;
74
-import com.dmdirc.logger.ErrorManager;
75
-import com.dmdirc.parser.interfaces.callbacks.ChannelJoinListener;
76
-import com.dmdirc.parser.interfaces.callbacks.ChannelKickListener;
77
-import com.dmdirc.parser.interfaces.callbacks.DataInListener;
78
-import com.dmdirc.parser.interfaces.callbacks.DataOutListener;
79
-import com.dmdirc.parser.interfaces.callbacks.DebugInfoListener;
80
-import java.lang.reflect.Method;
81
-import java.net.URI;
82
-import java.util.Calendar;
83 81
 
84 82
 /**
85 83
  * Twitter Parser for DMDirc.
@@ -155,6 +153,20 @@ public class Twitter implements Parser, TwitterErrorHandler, TwitterRawHandler,
155 153
 
156 154
     /** Debug enabled. */
157 155
     private boolean debugEnabled;
156
+    /** Save last IDs */
157
+    private boolean saveLastIDs;
158
+    /** Status count. */
159
+    private int statusCount;
160
+    /** Get sent messages. */
161
+    private boolean getSentMessage;
162
+    /** Number of api calls to use. */
163
+    private int apicalls;
164
+    /** Auto append @ to nicknames. */
165
+    private boolean autoAt;
166
+    /** Replace opening nickname. */
167
+    private boolean replaceOpeningNickname;
168
+    /** hide 500 errors. */
169
+    private boolean hide500Errors;
158 170
 
159 171
     /**
160 172
      * Create a new Twitter Parser!
@@ -174,8 +186,7 @@ public class Twitter implements Parser, TwitterErrorHandler, TwitterRawHandler,
174 186
         this.myAddress = address;
175 187
         
176 188
         resetState(true);
177
-
178
-        debugEnabled = getConfigManager().getOptionBool(myPlugin.getDomain(), "debugEnabled");
189
+        
179 190
         if (getConfigManager().hasOptionString(myPlugin.getDomain(), "api.address."+myServerName)) {
180 191
             this.apiAddress = getConfigManager().getOption(myPlugin.getDomain(), "api.address."+myServerName);
181 192
         } else {
@@ -948,7 +959,7 @@ public class Twitter implements Parser, TwitterErrorHandler, TwitterRawHandler,
948 959
         long lastTimelineId = -1;
949 960
         long lastDirectMessageId = -1;
950 961
 
951
-        if (getConfigManager().getOptionBool(myPlugin.getDomain(), "saveLastIDs")) {
962
+        if (saveLastIDs) {
952 963
             if (getConfigManager().hasOptionString(myPlugin.getDomain(), "lastReplyId-"+myServerName+"-"+myUsername)) {
953 964
                 lastReplyId = TwitterAPI.parseLong(getConfigManager().getOption(myPlugin.getDomain(), "lastReplyId-"+myServerName+"-"+myUsername), -1);
954 965
             }
@@ -972,7 +983,7 @@ public class Twitter implements Parser, TwitterErrorHandler, TwitterRawHandler,
972 983
             if (!wantAuth && api.isAllowed()) {
973 984
                 lastQueryTime = System.currentTimeMillis();
974 985
 
975
-                final int statusesPerAttempt = Math.min(200, getConfigManager().getOptionInt(myPlugin.getDomain(), "statuscount"));
986
+                final int statusesPerAttempt = Math.min(200, statusCount);
976 987
 
977 988
                 final List<TwitterStatus> statuses = new ArrayList<TwitterStatus>();
978 989
                 for (TwitterStatus status : api.getReplies(lastReplyId, statusesPerAttempt)) {
@@ -1017,7 +1028,7 @@ public class Twitter implements Parser, TwitterErrorHandler, TwitterRawHandler,
1017 1028
                     if (directMessage.getID() > lastDirectMessageId) { lastDirectMessageId = directMessage.getID(); }
1018 1029
                 }
1019 1030
 
1020
-                if (getConfigManager().getOptionBool(myPlugin.getDomain(), "getSentMessages")) {
1031
+                if (getSentMessage) {
1021 1032
                     for (TwitterMessage directMessage : api.getSentDirectMessages(lastDirectMessageId)) {
1022 1033
                         directMessages.add(directMessage);
1023 1034
                         if (directMessage.getID() > lastDirectMessageId) { lastDirectMessageId = directMessage.getID(); }
@@ -1045,7 +1056,6 @@ public class Twitter implements Parser, TwitterErrorHandler, TwitterRawHandler,
1045 1056
             IdentityManager.getConfigIdentity().setOption(myPlugin.getDomain(), "lastTimelineId-"+myServerName+"-"+myUsername, Long.toString(lastTimelineId));
1046 1057
             IdentityManager.getConfigIdentity().setOption(myPlugin.getDomain(), "lastDirectMessageId-"+myServerName+"-"+myUsername, Long.toString(lastDirectMessageId));
1047 1058
 
1048
-            final int apiLimit = getConfigManager().getOptionInt(myPlugin.getDomain(), "apicalls");
1049 1059
             final int endCalls = (wantAuth) ? 0 : api.getUsedCalls();
1050 1060
             final Long[] apiCalls = (wantAuth) ? new Long[]{0L, 0L, System.currentTimeMillis(), (long)api.getUsedCalls()} : api.getRemainingApiCalls();
1051 1061
             doDebug(Debug.apiCalls, "Twitter calls Remaining: "+apiCalls[0]);
@@ -1071,14 +1081,14 @@ public class Twitter implements Parser, TwitterErrorHandler, TwitterRawHandler,
1071 1081
                 sleepTime = 10 * 60 * 1000;
1072 1082
                 // Also alert the user.
1073 1083
                 twitterFail("Unable to communicate with twitter, or no API calls allowed at all, retrying in 10 minutes.");
1074
-            } else if (api.getUsedCalls() > apiLimit) {
1084
+            } else if (api.getUsedCalls() > apicalls) {
1075 1085
                 // Sleep for the rest of the hour, we have done too much!
1076 1086
                 sleepTime = timeLeft;
1077 1087
             } else {
1078 1088
                 // Else work out how many calls we have left.
1079 1089
                 // Whichever is less between the number of calls we want to make
1080 1090
                 // and the number of calls twitter is going to allow us to make.
1081
-                final long callsLeft = Math.min(apiLimit - api.getUsedCalls(), apiCalls[0]);
1091
+                final long callsLeft = Math.min(apicalls - api.getUsedCalls(), apiCalls[0]);
1082 1092
                 // How many calls do we make each time?
1083 1093
                 // If this is less than 0 (If there was a time reset between
1084 1094
                 // calculating the start and end calls used) then assume 3.
@@ -1129,11 +1139,12 @@ public class Twitter implements Parser, TwitterErrorHandler, TwitterRawHandler,
1129 1139
         }
1130 1140
         clients.clear();
1131 1141
 
1132
-        if (!simpleMyself && getConfigManager().getOptionBool(myPlugin.getDomain(), "autoAt")) {
1142
+        if (!simpleMyself && autoAt) {
1133 1143
             myself = new TwitterClientInfo("@" + myUsername, this);
1134 1144
         } else {
1135 1145
             myself = new TwitterClientInfo(myUsername, this);
1136 1146
         }
1147
+        setCachedSettings();
1137 1148
     }
1138 1149
 
1139 1150
     /**
@@ -1184,7 +1195,7 @@ public class Twitter implements Parser, TwitterErrorHandler, TwitterRawHandler,
1184 1195
         final StringBuffer newStatus = new StringBuffer(message);
1185 1196
         final TwitterChannelInfo channel = (TwitterChannelInfo) this.getChannel(mainChannelName);
1186 1197
         
1187
-        if (channel != null && getConfigManager().getOptionBool(myPlugin.getDomain(), "replaceOpeningNickname")) {
1198
+        if (channel != null && replaceOpeningNickname) {
1188 1199
             final String[] bits = message.split(" ");
1189 1200
             if (bits[0].charAt(bits[0].length() - 1) == ':') {
1190 1201
                 final String name = bits[0].substring(0, bits[0].length() - 1);
@@ -1289,8 +1300,8 @@ public class Twitter implements Parser, TwitterErrorHandler, TwitterRawHandler,
1289 1300
     /** {@inheritDoc} */
1290 1301
     @Override
1291 1302
     public void handleTwitterError(final TwitterAPI api, final Throwable t, final String source, final String twitterInput, final String twitterOutput, final String message) {
1292
-        final boolean hide500Errors = !debugEnabled && getConfigManager().getOptionBool(myPlugin.getDomain(), "hide500Errors");
1293
-        if (hide500Errors && message.matches("^\\(50[0-9]\\).*")) { return; }
1303
+        final boolean showError = !debugEnabled && hide500Errors;
1304
+        if (showError && message.matches("^\\(50[0-9]\\).*")) { return; }
1294 1305
         try {
1295 1306
             if (!message.isEmpty()) {
1296 1307
                 twitterFail("Recieved an error from twitter: " + message + (debugEnabled ? " [" + source + "]" : ""));
@@ -1311,25 +1322,9 @@ public class Twitter implements Parser, TwitterErrorHandler, TwitterRawHandler,
1311 1322
             doDebug(Debug.twitterErrorMore, "");
1312 1323
             doDebug(Debug.twitterErrorMore, "Exception:");
1313 1324
 
1314
-            // Hax the error manager to get a nice String[] representing the stack trace and output it.
1315
-            try {
1316
-                final Method gt = ErrorManager.class.getDeclaredMethod("getTrace", Throwable.class);
1317
-                gt.setAccessible(true);
1318
-                final String[] trace = (String[]) gt.invoke(ErrorManager.getErrorManager(), t);
1319
-
1320
-                for (String out : trace) {
1321
-                    doDebug(Debug.twitterErrorMore, "                "+out);
1322
-                }
1323
-            } catch (NoSuchMethodException ex) {
1324
-                doDebug(Debug.twitterErrorMore, "    ... Unable to get StackTrace (nsme: "+ex+")");
1325
-            } catch (SecurityException ex) {
1326
-                doDebug(Debug.twitterErrorMore, "    ... Unable to get StackTrace (se: "+ex+")");
1327
-            } catch (IllegalAccessException ex) {
1328
-                doDebug(Debug.twitterErrorMore, "    ... Unable to get StackTrace (iae: "+ex+")");
1329
-            } catch (IllegalArgumentException ex) {
1330
-                doDebug(Debug.twitterErrorMore, "    ... Unable to get StackTrace (iae2: "+ex+")");
1331
-            } catch (InvocationTargetException ex) {
1332
-                doDebug(Debug.twitterErrorMore, "    ... Unable to get StackTrace (ite: "+ex+")");
1325
+            final String[] trace = ErrorManager.getTrace(t);
1326
+            for (String out : trace) {
1327
+                doDebug(Debug.twitterErrorMore, "                "+out);
1333 1328
             }
1334 1329
 
1335 1330
             doDebug(Debug.twitterErrorMore, "==================================");
@@ -1400,9 +1395,9 @@ public class Twitter implements Parser, TwitterErrorHandler, TwitterRawHandler,
1400 1395
     /** {@inheritDoc} */
1401 1396
     @Override
1402 1397
     public void configChanged(final String domain, final String key) {
1398
+        setCachedSettings();
1403 1399
         if (domain.equalsIgnoreCase(myPlugin.getDomain())) {
1404 1400
             if (key.equalsIgnoreCase("debugEnabled")) {
1405
-                debugEnabled = getConfigManager().getOptionBool(myPlugin.getDomain(), "debugEnabled");
1406 1401
                 api.setDebug(debugEnabled);
1407 1402
             } else if (key.equalsIgnoreCase("autoAt")) {
1408 1403
                 sendPrivateNotice("'autoAt' setting was changed, reconnect needed.");
@@ -1423,4 +1418,15 @@ public class Twitter implements Parser, TwitterErrorHandler, TwitterRawHandler,
1423 1418
 
1424 1419
         return myConfigManager;
1425 1420
     }
1421
+
1422
+    private void setCachedSettings() {
1423
+        saveLastIDs = getConfigManager().getOptionBool(myPlugin.getDomain(), "saveLastIDs");
1424
+        statusCount = getConfigManager().getOptionInt(myPlugin.getDomain(), "statusCount");
1425
+        getSentMessage = getConfigManager().getOptionBool(myPlugin.getDomain(), "getSentMessage");
1426
+        apicalls = getConfigManager().getOptionInt(myPlugin.getDomain(), "apicalls");
1427
+        autoAt = getConfigManager().getOptionBool(myPlugin.getDomain(), "autoAt");
1428
+        replaceOpeningNickname = getConfigManager().getOptionBool(myPlugin.getDomain(), "replaceOpeningNickname");
1429
+        hide500Errors = getConfigManager().getOptionBool(myPlugin.getDomain(), "hide500Errors");
1430
+        debugEnabled = getConfigManager().getOptionBool(myPlugin.getDomain(), "debugEnabled");
1431
+    }
1426 1432
 }

+ 26
- 18
src/com/dmdirc/addons/ui_swing/components/frames/InputTextFrame.java Целия файл

@@ -57,8 +57,8 @@ import javax.swing.JPanel;
57 57
 import javax.swing.JPopupMenu;
58 58
 import javax.swing.JSeparator;
59 59
 import javax.swing.KeyStroke;
60
-
61 60
 import javax.swing.event.InternalFrameEvent;
61
+
62 62
 import net.miginfocom.layout.PlatformDefaults;
63 63
 
64 64
 /**
@@ -85,6 +85,8 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
85 85
     private JPopupMenu inputFieldPopup;
86 86
     /** Nick popup menu. */
87 87
     protected JPopupMenu nickPopup;
88
+    /** Away indicator. */
89
+    private boolean useAwayIndicator;
88 90
 
89 91
     /**
90 92
      * Creates a new instance of InputFrame.
@@ -108,9 +110,11 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
108 110
         getInputField().setCaretColor(config.getOptionColour(
109 111
                 "ui", "inputforegroundcolour",
110 112
                 "ui", "foregroundcolour"));
113
+        config.getOptionBool("ui", "awayindicator");
111 114
 
112 115
         config.addChangeListener("ui", "inputforegroundcolour", this);
113 116
         config.addChangeListener("ui", "inputbackgroundcolour", this);
117
+        config.addChangeListener("ui", "awayindicator", this);
114 118
         if (getContainer().getServer() != null) {
115 119
             getContainer().getServer().addAwayStateListener(this);
116 120
         }
@@ -125,7 +129,7 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
125 129
             @Override
126 130
             public void run() {
127 131
                 InputTextFrame.super.open();
128
-                if (getConfigManager().getOptionBool("ui", "awayindicator") && getContainer().
132
+                if (useAwayIndicator && getContainer().
129 133
                     getServer() != null) {
130 134
                     awayLabel.setVisible(getContainer().getServer().isAway());
131 135
                 }
@@ -385,22 +389,26 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
385 389
     public void configChanged(final String domain, final String key) {
386 390
         super.configChanged(domain, key);
387 391
 
388
-        if ("ui".equals(domain) && getInputField() != null &&
389
-                getConfigManager() != null) {
390
-            if ("inputbackgroundcolour".equals(key) ||
391
-                    "backgroundcolour".equals(key)) {
392
-                getInputField().setBackground(getConfigManager().getOptionColour(
393
-                        "ui", "inputbackgroundcolour",
394
-                        "ui", "backgroundcolour"));
395
-            } else if ("inputforegroundcolour".equals(key) ||
396
-                    "foregroundcolour".equals(key)) {
397
-                getInputField().setForeground(getConfigManager().getOptionColour(
398
-                        "ui", "inputforegroundcolour",
399
-                        "ui", "foregroundcolour"));
400
-                getInputField().setCaretColor(getConfigManager().getOptionColour(
401
-                        "ui", "inputforegroundcolour",
402
-                        "ui", "foregroundcolour"));
403
-
392
+        if ("ui".equals(domain) && getConfigManager() != null) {
393
+            if (getInputField() != null) {
394
+                if ("inputbackgroundcolour".equals(key) ||
395
+                        "backgroundcolour".equals(key)) {
396
+                    getInputField().setBackground(getConfigManager().getOptionColour(
397
+                            "ui", "inputbackgroundcolour",
398
+                            "ui", "backgroundcolour"));
399
+                } else if ("inputforegroundcolour".equals(key) ||
400
+                        "foregroundcolour".equals(key)) {
401
+                    getInputField().setForeground(getConfigManager().getOptionColour(
402
+                            "ui", "inputforegroundcolour",
403
+                            "ui", "foregroundcolour"));
404
+                    getInputField().setCaretColor(getConfigManager().getOptionColour(
405
+                            "ui", "inputforegroundcolour",
406
+                            "ui", "foregroundcolour"));
407
+                }
408
+            }
409
+            if ("awayindicator".equals(key)) {
410
+                useAwayIndicator = getConfigManager().getOptionBool("ui",
411
+                        "awayindicator");
404 412
             }
405 413
         }
406 414
     }

+ 58
- 4
src/com/dmdirc/addons/ui_swing/components/statusbar/MessageLabel.java Целия файл

@@ -24,6 +24,7 @@ package com.dmdirc.addons.ui_swing.components.statusbar;
24 24
 
25 25
 import com.dmdirc.addons.ui_swing.UIUtilities;
26 26
 import com.dmdirc.config.IdentityManager;
27
+import com.dmdirc.interfaces.ConfigChangeListener;
27 28
 import com.dmdirc.ui.IconManager;
28 29
 import com.dmdirc.ui.interfaces.StatusBarComponent;
29 30
 import com.dmdirc.ui.interfaces.StatusMessageNotifier;
@@ -43,7 +44,7 @@ import javax.swing.SwingUtilities;
43 44
  * Message label handles showing messages in the status bar.
44 45
  */
45 46
 public class MessageLabel extends JLabel implements StatusBarComponent, 
46
-        MouseListener {
47
+        MouseListener, ConfigChangeListener {
47 48
 
48 49
     /**
49 50
      * A version number for this class. It should be changed whenever the class
@@ -57,6 +58,8 @@ public class MessageLabel extends JLabel implements StatusBarComponent,
57 58
     private transient StatusMessageNotifier messageNotifier;
58 59
     /** Timer to clear the message. */
59 60
     private transient TimerTask messageTimer;
61
+    /** Message timeout. */
62
+    private int timeout;
60 63
 
61 64
     /**
62 65
      * Instantiates a new message label.
@@ -66,34 +69,73 @@ public class MessageLabel extends JLabel implements StatusBarComponent,
66 69
         setText(DEFAULT_MESSAGE);
67 70
         setBorder(BorderFactory.createEtchedBorder());
68 71
         addMouseListener(this);
72
+        setCachedSettings();
73
+        IdentityManager.getGlobalConfig().addChangeListener("ui",
74
+                "awayindicator", this);
69 75
     }
70 76
 
77
+    /**
78
+     * Sets the message for this message label.
79
+     *
80
+     * @param newMessage New message
81
+     */
71 82
     public void setMessage(final String newMessage) {
72 83
         setMessage(newMessage, (StatusMessageNotifier) null);
73 84
     }
74 85
 
86
+    /**
87
+     * Sets the message for this message label.
88
+     *
89
+     * @param newMessage New message
90
+     * @param newNotifier New notifier
91
+     */
75 92
     public void setMessage(final String newMessage,
76 93
             final StatusMessageNotifier newNotifier) {
77 94
         setMessage(null, newMessage, newNotifier);
78 95
     }
79 96
 
97
+    /**
98
+     * Sets the message for this message label.
99
+     *
100
+     * @param iconType Icon type
101
+     * @param newMessage New message
102
+     */
80 103
     public void setMessage(final String iconType, final String newMessage) {
81 104
         setMessage(iconType, newMessage, null);
82 105
     }
83 106
 
107
+    /**
108
+     * Sets the message for this message label.
109
+     *
110
+     * @param iconType Icon type
111
+     * @param newMessage New message
112
+     * @param newNotifier New notifier
113
+     */
84 114
     public void setMessage(final String iconType, final String newMessage,
85 115
             final StatusMessageNotifier newNotifier) {
86
-        final int timeout =
87
-                IdentityManager.getGlobalConfig().
88
-                getOptionInt("statusBar", "messageDisplayLength");
89 116
         setMessage(iconType, newMessage, newNotifier, timeout);
90 117
     }
91 118
 
119
+    /**
120
+     * Sets the message for this message label.
121
+     *
122
+     * @param newMessage New message
123
+     * @param newNotifier New notifier
124
+     * @param timeout New timeout
125
+     */
92 126
     public void setMessage(final String newMessage,
93 127
             final StatusMessageNotifier newNotifier, final int timeout) {
94 128
         setMessage(null, newMessage, newNotifier, timeout);
95 129
     }
96 130
 
131
+    /**
132
+     * Sets the message for this message label.
133
+     *
134
+     * @param iconType Icon type
135
+     * @param newMessage New message
136
+     * @param newNotifier New notifier
137
+     * @param timeout New timeout
138
+     */
97 139
     public synchronized void setMessage(final String iconType, final String newMessage,
98 140
             final StatusMessageNotifier newNotifier, final int timeout) {
99 141
         final Icon icon;
@@ -195,4 +237,16 @@ public class MessageLabel extends JLabel implements StatusBarComponent,
195 237
     public void mouseExited(final MouseEvent e) {
196 238
         //Ignore
197 239
     }
240
+
241
+    /** Set cached options. */
242
+    private void setCachedSettings() {
243
+        timeout = IdentityManager.getGlobalConfig().getOptionInt("statusBar",
244
+                "messageDisplayLength");
245
+    }
246
+
247
+    /** {@inheritDoc} */
248
+    @Override
249
+    public void configChanged(final String domain, final String key) {
250
+        setCachedSettings();
251
+    }
198 252
 }

Loading…
Отказ
Запис