Ver código fonte

Away state listeners and formatters

git-svn-id: http://svn.dmdirc.com/trunk@2667 00569f92-eb28-0410-84fd-f71c24880f
tags/0.5.5
Chris Smith 16 anos atrás
pai
commit
c9179365d6

+ 41
- 20
src/com/dmdirc/Server.java Ver arquivo

@@ -28,6 +28,7 @@ import com.dmdirc.actions.wrappers.AliasWrapper;
28 28
 import com.dmdirc.commandparser.CommandManager;
29 29
 import com.dmdirc.config.ConfigManager;
30 30
 import com.dmdirc.config.Identity;
31
+import com.dmdirc.interfaces.AwayStateListener;
31 32
 import com.dmdirc.interfaces.InviteListener;
32 33
 import com.dmdirc.logger.ErrorLevel;
33 34
 import com.dmdirc.logger.Logger;
@@ -1054,26 +1055,6 @@ public final class Server extends WritableFrameContainer implements Serializable
1054 1055
                 Integer.valueOf(numeric), tokens);
1055 1056
     }
1056 1057
 
1057
-    /**
1058
-     * Called when our away state changes.
1059
-     *
1060
-     * @param currentState The new aray state
1061
-     * @param reason Our away reason, if applicable
1062
-     */
1063
-    public void onAwayState(final boolean currentState, final String reason) {
1064
-        if (currentState) {
1065
-            awayMessage = reason;
1066
-
1067
-            ActionManager.processEvent(CoreActionType.SERVER_AWAY, null, this, awayMessage);
1068
-        } else {
1069
-            awayMessage = "";
1070
-
1071
-            ActionManager.processEvent(CoreActionType.SERVER_BACK, null, this);
1072
-        }
1073
-
1074
-        window.setAwayIndicator(isAway());
1075
-    }
1076
-
1077 1058
     /**
1078 1059
      * Called when the socket has been closed.
1079 1060
      */
@@ -1254,5 +1235,45 @@ public final class Server extends WritableFrameContainer implements Serializable
1254 1235
             listener.inviteExpired(this, invite);
1255 1236
         }
1256 1237
     }
1238
+    
1239
+    // ----------------------------------------------- AWAY STATE HANDLING -----
1240
+    
1241
+    /**
1242
+     * Adds an away state lisener to this server.
1243
+     * 
1244
+     * @param listener The listener to be added
1245
+     */
1246
+    public void addAwayStateListener(final AwayStateListener listener) {
1247
+        listeners.add(AwayStateListener.class, listener);
1248
+    }
1249
+    
1250
+    /**
1251
+     * Removes an away state lisener from this server.
1252
+     * 
1253
+     * @param listener The listener to be removed
1254
+     */
1255
+    public void removeAwayStateListener(final AwayStateListener listener) {
1256
+        listeners.remove(AwayStateListener.class, listener);
1257
+    }
1258
+    
1259
+    /**
1260
+     * Updates our away state and fires the relevant listeners.
1261
+     * 
1262
+     * @param message The away message to use, or an empty string if we're not
1263
+     * away
1264
+     */
1265
+    public void updateAwayState(final String message) {
1266
+        awayMessage = message;
1267
+        
1268
+        if (message.isEmpty()) {
1269
+            for (AwayStateListener listener : listeners.get(AwayStateListener.class)) {
1270
+                listener.onBack();
1271
+            }
1272
+        } else {
1273
+            for (AwayStateListener listener : listeners.get(AwayStateListener.class)) {
1274
+                listener.onAway(message);
1275
+            }            
1276
+        }
1277
+    }
1257 1278
 
1258 1279
 }

+ 8
- 1
src/com/dmdirc/ServerEventHandler.java Ver arquivo

@@ -205,7 +205,14 @@ public final class ServerEventHandler extends EventHandler
205 205
     public void onAwayState(final IRCParser tParser, final boolean currentState,
206 206
             final String reason) {
207 207
         checkParser(tParser);
208
-        owner.onAwayState(currentState, reason);
208
+        
209
+        owner.updateAwayState(currentState ? reason : "");
210
+        
211
+        if (currentState) {
212
+            owner.doNotification("away", CoreActionType.SERVER_AWAY, reason);
213
+        } else {
214
+            owner.doNotification("back", CoreActionType.SERVER_BACK);
215
+        }
209 216
     }
210 217
     
211 218
     /** {@inheritDoc} */

+ 2
- 0
src/com/dmdirc/config/defaults/default/defaults Ver arquivo

@@ -32,6 +32,8 @@ general.port=7000
32 32
 general.password=
33 33
 
34 34
 notifications.authNotice=server
35
+notifications.away=server
36
+notifications.back=server
35 37
 notifications.unknownNotice=server
36 38
 notifications.connectError=server
37 39
 notifications.connectRetry=server

+ 4
- 0
src/com/dmdirc/config/defaults/default/formatter Ver arquivo

@@ -148,9 +148,13 @@ formatter.connectError = \u00032Error connecting: %2$s
148 148
 formatter.connectRetry = \u00032Reconnecting in %2$s seconds...
149 149
 formatter.serverConnecting = Connecting to %1$s:%2$s...
150 150
 
151
+# Type: Argless
152
+formatter.back = \u000314You are no longer marked as away.
153
+
151 154
 # Type: Miscellaneous
152 155
 #    1: Miscellaneous data
153 156
 formatter.authNotice = \u00035-AUTH- %1$s
157
+formatter.away = \u000314You are now marked as away (%1$s\u000F\u000314).
154 158
 formatter.channelNoTopic = \u00033* There is no topic set for %1$s\u000F.
155 159
 formatter.rawCommand = \u000310>>> %1$s
156 160
 formatter.unknownCommand = \u000314Unknown command %1$s\u000F.

+ 44
- 0
src/com/dmdirc/interfaces/AwayStateListener.java Ver arquivo

@@ -0,0 +1,44 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.interfaces;
24
+
25
+/**
26
+ * AwayStateListeners are informed of changes to our away state.
27
+ * 
28
+ * @author chris
29
+ */
30
+public interface AwayStateListener {
31
+    
32
+    /**
33
+     * Called when we're marked as away.
34
+     * 
35
+     * @param reason The reason that we're away
36
+     */
37
+    void onAway(String reason);
38
+    
39
+    /**
40
+     * Called when we're marked as back.
41
+     */
42
+    void onBack();
43
+
44
+}

Carregando…
Cancelar
Salvar