|
@@ -22,26 +22,29 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.ui.messages;
|
24
|
24
|
|
|
25
|
+import com.dmdirc.ClientModule;
|
25
|
26
|
import com.dmdirc.DMDircMBassador;
|
26
|
27
|
import com.dmdirc.events.ServerDisconnectedEvent;
|
27
|
28
|
import com.dmdirc.events.ServerNumericEvent;
|
28
|
29
|
import com.dmdirc.interfaces.Connection;
|
|
30
|
+import com.dmdirc.interfaces.SystemLifecycleComponent;
|
29
|
31
|
import com.dmdirc.interfaces.config.ConfigProvider;
|
30
|
32
|
|
31
|
33
|
import java.util.HashMap;
|
32
|
34
|
import java.util.Map;
|
33
|
35
|
|
|
36
|
+import javax.inject.Inject;
|
|
37
|
+import javax.inject.Singleton;
|
|
38
|
+
|
34
|
39
|
import net.engio.mbassy.listener.Handler;
|
35
|
|
-import net.engio.mbassy.listener.Listener;
|
36
|
|
-import net.engio.mbassy.listener.References;
|
37
|
40
|
|
38
|
41
|
/**
|
39
|
42
|
* Listens for whois-like numeric events and automatically formats them.
|
40
|
43
|
*
|
41
|
44
|
* @since 0.6.3
|
42
|
45
|
*/
|
43
|
|
-@Listener(references = References.Strong)
|
44
|
|
-public class WhoisNumericFormatter {
|
|
46
|
+@Singleton
|
|
47
|
+public class WhoisNumericFormatter implements SystemLifecycleComponent {
|
45
|
48
|
|
46
|
49
|
/** The name of the target of any current whois requests. */
|
47
|
50
|
private final Map<Connection, String> targets = new HashMap<>();
|
|
@@ -57,19 +60,14 @@ public class WhoisNumericFormatter {
|
57
|
60
|
* @param identity The identity to write formatters to
|
58
|
61
|
* @param eventBus The event bus to subscribe to events on
|
59
|
62
|
*/
|
60
|
|
- public WhoisNumericFormatter(final ConfigProvider identity,
|
|
63
|
+ @Inject
|
|
64
|
+ public WhoisNumericFormatter(
|
|
65
|
+ @ClientModule.AddonConfig final ConfigProvider identity,
|
61
|
66
|
final DMDircMBassador eventBus) {
|
62
|
67
|
this.identity = identity;
|
63
|
68
|
this.eventBus = eventBus;
|
64
|
69
|
}
|
65
|
70
|
|
66
|
|
- /**
|
67
|
|
- * Registers this this whois numeric formatter with the global actions manager.
|
68
|
|
- */
|
69
|
|
- public void register() {
|
70
|
|
- eventBus.subscribe(this);
|
71
|
|
- }
|
72
|
|
-
|
73
|
71
|
/**
|
74
|
72
|
* Handles a server disconnected event. This clears any entry for that server in the
|
75
|
73
|
* {@link #targets} map.
|
|
@@ -107,17 +105,17 @@ public class WhoisNumericFormatter {
|
107
|
105
|
&& arguments[3].equals(targets.get(server))) {
|
108
|
106
|
// This numeric should be automatically formatted.
|
109
|
107
|
|
110
|
|
- if (!event.getDisplayFormat().isEmpty()) {
|
111
|
|
- // There's a custom format. We'll see if we need to
|
112
|
|
- // add a formatter or notification settings for it
|
113
|
|
- // anyway.
|
114
|
|
- ensureExists(event.getDisplayFormat(), arguments.length);
|
115
|
|
- } else {
|
|
108
|
+ if (event.getDisplayFormat().isEmpty()) {
|
116
|
109
|
// No custom formatter, switch it to an auto whois
|
117
|
110
|
// format and target.
|
118
|
111
|
final String target = "numeric_autowhois_" + (arguments.length - 4);
|
119
|
112
|
ensureExists(target, arguments.length);
|
120
|
113
|
event.setDisplayFormat(target);
|
|
114
|
+ } else {
|
|
115
|
+ // There's a custom format. We'll see if we need to
|
|
116
|
+ // add a formatter or notification settings for it
|
|
117
|
+ // anyway.
|
|
118
|
+ ensureExists(event.getDisplayFormat(), arguments.length);
|
121
|
119
|
}
|
122
|
120
|
}
|
123
|
121
|
break;
|
|
@@ -147,4 +145,13 @@ public class WhoisNumericFormatter {
|
147
|
145
|
}
|
148
|
146
|
}
|
149
|
147
|
|
|
148
|
+ @Override
|
|
149
|
+ public void startUp() {
|
|
150
|
+ eventBus.subscribe(this);
|
|
151
|
+ }
|
|
152
|
+
|
|
153
|
+ @Override
|
|
154
|
+ public void shutDown() {
|
|
155
|
+ eventBus.unsubscribe(this);
|
|
156
|
+ }
|
150
|
157
|
}
|