瀏覽代碼

Fixes issue 0003604: Ternary away states

Change-Id: Iad1585549ff0853ab20ab0f2e7ff0dfe98e2164b
Reviewed-on: http://gerrit.dmdirc.com/612
Automatic-Compile: Shane Mc Cormack <shane@dmdirc.com>
Automatic-Compile: Chris Smith <chris@dmdirc.com>
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.6.3
Shane Mc Cormack 14 年之前
父節點
當前提交
358c888c70

+ 38
- 0
src/com/dmdirc/parser/common/AwayState.java 查看文件

@@ -0,0 +1,38 @@
1
+/*
2
+ *  Copyright (c) 2006-2010 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.parser.common;
24
+
25
+/**
26
+ * Away states.
27
+ *
28
+ * @author Shane
29
+ * @since 0.6.3
30
+ */
31
+public enum AwayState {
32
+    /** State is unknown. */
33
+    UNKNOWN,
34
+    /** User is here. */
35
+    HERE,
36
+    /** User is away. */
37
+    AWAY;
38
+}

+ 4
- 2
src/com/dmdirc/parser/interfaces/callbacks/AwayStateListener.java 查看文件

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.parser.interfaces.callbacks;
24 24
 
25
+import com.dmdirc.parser.common.AwayState;
25 26
 import com.dmdirc.parser.interfaces.Parser;
26 27
 
27 28
 /**
@@ -33,9 +34,10 @@ public interface AwayStateListener extends CallbackInterface {
33 34
 	 * Called when we go away, or come back.
34 35
 	 *
35 36
 	 * @param tParser Reference to the parser object that made the callback.
36
-	 * @param currentState Set to true if we are now away, else false.
37
+         * @param oldState Old Away State
38
+	 * @param currentState Current Away State
37 39
 	 * @param reason Best guess at away reason
38 40
 	 * @see com.dmdirc.parser.irc.ProcessAway#callAwayState
39 41
 	 */
40
-	void onAwayState(Parser tParser, boolean currentState, String reason);
42
+	void onAwayState(Parser tParser, AwayState oldState, AwayState currentState, String reason);
41 43
 }

+ 4
- 2
src/com/dmdirc/parser/interfaces/callbacks/ChannelOtherAwayStateListener.java 查看文件

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.parser.interfaces.callbacks;
24 24
 
25
+import com.dmdirc.parser.common.AwayState;
25 26
 import com.dmdirc.parser.interfaces.ChannelClientInfo;
26 27
 import com.dmdirc.parser.interfaces.ChannelInfo;
27 28
 import com.dmdirc.parser.interfaces.Parser;
@@ -38,8 +39,9 @@ public interface ChannelOtherAwayStateListener extends CallbackInterface {
38 39
 	 * @param tParser Reference to the parser object that made the callback.
39 40
 	 * @param channel Channel this is for
40 41
 	 * @param channelClient Client this is for
41
-	 * @param state Away State (true if away, false if here)
42
+         * @param oldState Old Away State
43
+	 * @param state Current Away State
42 44
 	 * @see com.dmdirc.parser.irc.ProcessAway#callChannelAwayStateOther
43 45
 	 */
44
-	void onChannelAwayStateOther(Parser tParser, ChannelInfo channel, ChannelClientInfo channelClient, boolean state);
46
+	void onChannelAwayStateOther(Parser tParser, ChannelInfo channel, ChannelClientInfo channelClient, AwayState oldState, AwayState state);
45 47
 }

+ 4
- 2
src/com/dmdirc/parser/interfaces/callbacks/OtherAwayStateListener.java 查看文件

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.parser.interfaces.callbacks;
24 24
 
25
+import com.dmdirc.parser.common.AwayState;
25 26
 import com.dmdirc.parser.interfaces.ClientInfo;
26 27
 import com.dmdirc.parser.interfaces.Parser;
27 28
 import com.dmdirc.parser.interfaces.SpecificCallback;
@@ -36,8 +37,9 @@ public interface OtherAwayStateListener extends CallbackInterface {
36 37
 	 *
37 38
 	 * @param tParser Reference to the parser object that made the callback.
38 39
 	 * @param client Client this is for
39
-	 * @param state Away State (true if away, false if here)
40
+         * @param oldState Old Away State
41
+	 * @param state Current Away State
40 42
 	 * @see com.dmdirc.parser.irc.ProcessAway#callAwayStateOther
41 43
 	 */
42
-	void onAwayStateOther(Parser tParser, ClientInfo client, boolean state);
44
+	void onAwayStateOther(Parser tParser, ClientInfo client, AwayState oldState, AwayState state);
43 45
 }

+ 9
- 8
src/com/dmdirc/parser/irc/IRCClientInfo.java 查看文件

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.parser.irc;
24 24
 
25
+import com.dmdirc.parser.common.AwayState;
25 26
 import com.dmdirc.parser.interfaces.ClientInfo;
26 27
 import com.dmdirc.parser.interfaces.LocalClientInfo;
27 28
 import com.dmdirc.parser.interfaces.Parser;
@@ -53,7 +54,7 @@ public class IRCClientInfo implements LocalClientInfo {
53 54
     /** Known RealName of client. */
54 55
     private String sRealName = "";
55 56
     /** Known away state for client. */
56
-    private boolean bIsAway;
57
+    private AwayState away;
57 58
     /** Is this a fake client created just for a callback? */
58 59
     private boolean bIsFake;
59 60
     /** Reference to the parser object that owns this channel, Used for modes. */
@@ -205,21 +206,21 @@ public class IRCClientInfo implements LocalClientInfo {
205 206
     
206 207
     /**
207 208
      * Set the away state of a user.
208
-     * Automatically sets away reason to "" if set to false
209
+     * Automatically sets away reason to "" if not set to AwayState.AWAY
209 210
      *
210
-     * @param bNewState Boolean representing state. true = away, false = here
211
+     * @param bNewState AwayState representing new away state.
211 212
      */    
212
-    protected void setAwayState(final boolean bNewState) {
213
-        bIsAway = bNewState;
214
-        if (!bIsAway) { myAwayReason = ""; }
213
+    protected void setAwayState(final AwayState bNewState) {
214
+        away = bNewState;
215
+        if (away != AwayState.AWAY) { myAwayReason = ""; }
215 216
     }
216 217
     
217 218
     /**
218 219
      * Get the away state of a user.
219 220
      *
220
-     * @return Boolean representing state. true = away, false = here
221
+     * @return AwayState of the user.
221 222
      */    
222
-    public boolean getAwayState() { return bIsAway; }
223
+    public AwayState getAwayState() { return away; }
223 224
     
224 225
     /**
225 226
      * Get the Away Reason for this user.

+ 8
- 5
src/com/dmdirc/parser/irc/ProcessAway.java 查看文件

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.parser.irc;
24 24
 
25
+import com.dmdirc.parser.common.AwayState;
25 26
 import com.dmdirc.parser.interfaces.callbacks.AwayStateListener;
26 27
 
27 28
 /**
@@ -40,8 +41,9 @@ public class ProcessAway extends IRCProcessor {
40 41
             IRCClientInfo iClient = getClientInfo(token[3]);
41 42
             if (iClient != null) { iClient.setAwayReason(token[token.length-1]); }
42 43
         } else {
43
-            myParser.getLocalClient().setAwayState(sParam.equals("306"));
44
-            callAwayState(myParser.getLocalClient().getAwayState(), myParser.getLocalClient().getAwayReason());
44
+            final AwayState oldState = myParser.getLocalClient().getAwayState();
45
+            myParser.getLocalClient().setAwayState(sParam.equals("306") ? AwayState.AWAY : AwayState.HERE) ;
46
+            callAwayState(oldState, myParser.getLocalClient().getAwayState(), myParser.getLocalClient().getAwayReason());
45 47
         }
46 48
     }
47 49
     
@@ -49,12 +51,13 @@ public class ProcessAway extends IRCProcessor {
49 51
      * Callback to all objects implementing the onAwayState Callback.
50 52
      *
51 53
      * @see IAwayState
52
-     * @param currentState Set to true if we are now away, else false.
54
+     * @param oldState Old Away State
55
+     * @param currentState Current Away State
53 56
      * @param reason Best guess at away reason
54 57
      * @return true if a method was called, false otherwise
55 58
      */
56
-    protected boolean callAwayState(boolean currentState, String reason) {
57
-        return myParser.getCallbackManager().getCallbackType(AwayStateListener.class).call(currentState, reason);
59
+    protected boolean callAwayState(final AwayState oldState, final AwayState currentState, final String reason) {
60
+        return getCallbackManager().getCallbackType(AwayStateListener.class).call(oldState, currentState, reason);
58 61
     }
59 62
     
60 63
     /**

+ 18
- 14
src/com/dmdirc/parser/irc/ProcessWho.java 查看文件

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.parser.irc;
24 24
 
25
+import com.dmdirc.parser.common.AwayState;
25 26
 import com.dmdirc.parser.interfaces.ChannelClientInfo;
26 27
 import com.dmdirc.parser.interfaces.ChannelInfo;
27 28
 import com.dmdirc.parser.interfaces.ClientInfo;
@@ -61,20 +62,20 @@ public class ProcessWho extends IRCProcessor {
61 62
             }
62 63
             // Update away state
63 64
             final String mode = token[8];
64
-            final boolean isAway = mode.indexOf('G') != -1;
65
+            final AwayState isAway = (mode.indexOf('G') == -1) ? AwayState.HERE : AwayState.AWAY;
65 66
             if (client.getAwayState() != isAway) {
67
+                final AwayState oldState = client.getAwayState();
66 68
                 client.setAwayState(isAway);
67
-                if (!isAway) { client.setAwayReason(""); }
68 69
                 if (client == myParser.getLocalClient()) {
69
-                    callAwayState(client.getAwayState(), client.getAwayReason());
70
+                    callAwayState(oldState, client.getAwayState(), client.getAwayReason());
70 71
                 } else {
71
-                    callAwayStateOther(client, isAway);
72
+                    callAwayStateOther(client, oldState, isAway);
72 73
                     
73 74
                     ChannelClientInfo iChannelClient;
74 75
                     for (ChannelInfo iChannel : myParser.getChannels()) {
75 76
                         iChannelClient = iChannel.getChannelClient(client);
76 77
                         if (iChannelClient != null) {
77
-                            callChannelAwayStateOther(iChannel,iChannelClient,isAway);
78
+                            callChannelAwayStateOther(iChannel,iChannelClient,oldState,isAway);
78 79
                         }
79 80
                     }
80 81
                 }
@@ -86,12 +87,13 @@ public class ProcessWho extends IRCProcessor {
86 87
      * Callback to all objects implementing the onAwayState Callback.
87 88
      *
88 89
      * @see IAwayState
89
-     * @param currentState Set to true if we are now away, else false.
90
+     * @param oldState Old Away State
91
+     * @param currentState Current Away State
90 92
      * @param reason Best guess at away reason
91 93
      * @return true if a method was called, false otherwise
92 94
      */
93
-    protected boolean callAwayState(boolean currentState, String reason) {
94
-        return getCallbackManager().getCallbackType(AwayStateListener.class).call(currentState, reason);
95
+    protected boolean callAwayState(final AwayState oldState, final AwayState currentState, final String reason) {
96
+        return getCallbackManager().getCallbackType(AwayStateListener.class).call(oldState, currentState, reason);
95 97
     }
96 98
     
97 99
     /**
@@ -99,11 +101,12 @@ public class ProcessWho extends IRCProcessor {
99 101
      *
100 102
      * @see IAwayStateOther
101 103
      * @param client Client this is for
102
-     * @param state Away State (true if away, false if here)
104
+     * @param oldState Old Away State
105
+     * @param state Current Away State
103 106
      * @return true if a method was called, false otherwise
104 107
      */
105
-    protected boolean callAwayStateOther(final ClientInfo client, final boolean state) {
106
-        return getCallbackManager().getCallbackType(OtherAwayStateListener.class).call(client, state);
108
+    protected boolean callAwayStateOther(final ClientInfo client, final AwayState oldState, final AwayState state) {
109
+        return getCallbackManager().getCallbackType(OtherAwayStateListener.class).call(client, oldState, state);
107 110
     }
108 111
     
109 112
     /**
@@ -112,11 +115,12 @@ public class ProcessWho extends IRCProcessor {
112 115
      * @see IAwayStateOther
113 116
      * @param channel Channel this is for
114 117
      * @param channelClient ChannelClient this is for
115
-     * @param state Away State (true if away, false if here)
118
+     * @param oldState Old Away State
119
+     * @param state Current Away State
116 120
      * @return true if a method was called, false otherwise
117 121
      */
118
-    protected boolean callChannelAwayStateOther(final ChannelInfo channel, final ChannelClientInfo channelClient, final boolean state) {
119
-        return getCallbackManager().getCallbackType(ChannelOtherAwayStateListener.class).call(channel, channelClient, state);
122
+    protected boolean callChannelAwayStateOther(final ChannelInfo channel, final ChannelClientInfo channelClient, final AwayState oldState, final AwayState state) {
123
+        return getCallbackManager().getCallbackType(ChannelOtherAwayStateListener.class).call(channel, channelClient, oldState, state);
120 124
     }
121 125
     
122 126
     /**

Loading…
取消
儲存