Переглянути джерело

Migrate DCC plugin to use events.

pull/453/head
Chris Smith 8 роки тому
джерело
коміт
d95097c3ea

+ 0
- 9
dcc/plugin.config Переглянути файл

8
   requires
8
   requires
9
   updates
9
   updates
10
   defaults
10
   defaults
11
-  formatters
12
   icons
11
   icons
13
   version
12
   version
14
 
13
 
52
   firewall.ports.startPort=11000
51
   firewall.ports.startPort=11000
53
   firewall.ports.endPort=11019
52
   firewall.ports.endPort=11019
54
 
53
 
55
-formatters:
56
-  DCCChatStarting=Starting DCC Chat with: %1$s on %2$s:%3$s
57
-  DCCChatInfo=%1$s
58
-  DCCChatError=Error: %1$s
59
-  DCCSendError=Error: %1$s
60
-  DCCChatSelfMessage=<%1$s> %2$s
61
-  DCCChatMessage=<%1$s> %2$s
62
-
63
 icons:
54
 icons:
64
   category-dcc=plugin://dcc:com/dmdirc/addons/dcc/res/transfers.png
55
   category-dcc=plugin://dcc:com/dmdirc/addons/dcc/res/transfers.png
65
   dcc=plugin://dcc:com/dmdirc/addons/dcc/res/transfers.png
56
   dcc=plugin://dcc:com/dmdirc/addons/dcc/res/transfers.png

+ 11
- 0
dcc/res/META-INF/format.yml Переглянути файл

1
+---
2
+DccChatStartingEvent:
3
+  format: "Starting DCC Chat with: {{target}} on {{host}}:{{port}}..."
4
+DccChatSocketClosedEvent:
5
+  format: "Socket closed."
6
+DccChatSocketOpenedEvent:
7
+  format: "Socket opened."
8
+DccChatMessageEvent:
9
+  format: "<{{nickname}}> {{message}}"
10
+DccChatSelfMessageEvent:
11
+  format: "<{{nickname}}> {{message}}"

+ 9
- 17
dcc/src/com/dmdirc/addons/dcc/ChatContainer.java Переглянути файл

24
 
24
 
25
 import com.dmdirc.DMDircMBassador;
25
 import com.dmdirc.DMDircMBassador;
26
 import com.dmdirc.addons.dcc.events.DccChatMessageEvent;
26
 import com.dmdirc.addons.dcc.events.DccChatMessageEvent;
27
-import com.dmdirc.addons.dcc.events.DccChatSelfmessageEvent;
28
-import com.dmdirc.addons.dcc.events.DccChatSocketclosedEvent;
29
-import com.dmdirc.addons.dcc.events.DccChatSocketopenedEvent;
27
+import com.dmdirc.addons.dcc.events.DccChatSelfMessageEvent;
28
+import com.dmdirc.addons.dcc.events.DccChatSocketClosedEvent;
29
+import com.dmdirc.addons.dcc.events.DccChatSocketOpenedEvent;
30
 import com.dmdirc.addons.dcc.io.DCCChat;
30
 import com.dmdirc.addons.dcc.io.DCCChat;
31
+import com.dmdirc.events.CommandErrorEvent;
31
 import com.dmdirc.interfaces.CommandController;
32
 import com.dmdirc.interfaces.CommandController;
32
 import com.dmdirc.interfaces.WindowModel;
33
 import com.dmdirc.interfaces.WindowModel;
33
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
34
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
34
 import com.dmdirc.ui.core.components.WindowComponent;
35
 import com.dmdirc.ui.core.components.WindowComponent;
35
 import com.dmdirc.ui.input.TabCompleterFactory;
36
 import com.dmdirc.ui.input.TabCompleterFactory;
36
 import com.dmdirc.ui.messages.BackBufferFactory;
37
 import com.dmdirc.ui.messages.BackBufferFactory;
37
-import com.dmdirc.util.EventUtils;
38
 
38
 
39
 import java.util.Arrays;
39
 import java.util.Arrays;
40
 
40
 
105
     @Override
105
     @Override
106
     public void sendLine(final String line) {
106
     public void sendLine(final String line) {
107
         if (dccChat.isWriteable()) {
107
         if (dccChat.isWriteable()) {
108
-            final DccChatSelfmessageEvent event = new DccChatSelfmessageEvent(this, line);
109
-            final String format = EventUtils.postDisplayable(eventBus, event, "DCCChatSelfMessage");
110
-            addLine(format, nickname, line);
108
+            eventBus.publishAsync(new DccChatSelfMessageEvent(this, nickname, line));
111
             dccChat.sendLine(line);
109
             dccChat.sendLine(line);
112
         } else {
110
         } else {
113
-            addLine("DCCChatError", "Socket is closed.", line);
111
+            eventBus.publishAsync(new CommandErrorEvent(this, "Socket is closed."));
114
         }
112
         }
115
     }
113
     }
116
 
114
 
117
     @Override
115
     @Override
118
     public void handleChatMessage(final DCCChat dcc, final String message) {
116
     public void handleChatMessage(final DCCChat dcc, final String message) {
119
-        final DccChatMessageEvent event = new DccChatMessageEvent(this, otherNickname, message);
120
-        final String format = EventUtils.postDisplayable(eventBus, event, "DCCChatMessage");
121
-        addLine(format, otherNickname, message);
117
+        eventBus.publishAsync(new DccChatMessageEvent(this, otherNickname, message));
122
     }
118
     }
123
 
119
 
124
     @Override
120
     @Override
125
     public void socketClosed(final DCCChat dcc) {
121
     public void socketClosed(final DCCChat dcc) {
126
-        final DccChatSocketclosedEvent event = new DccChatSocketclosedEvent(this);
127
-        final String format = EventUtils.postDisplayable(eventBus, event, "DCCChatInfo");
128
-        addLine(format, "Socket closed");
122
+        eventBus.publishAsync(new DccChatSocketClosedEvent(this));
129
         if (!isWindowClosing()) {
123
         if (!isWindowClosing()) {
130
             setIcon("dcc-chat-inactive");
124
             setIcon("dcc-chat-inactive");
131
         }
125
         }
133
 
127
 
134
     @Override
128
     @Override
135
     public void socketOpened(final DCCChat dcc) {
129
     public void socketOpened(final DCCChat dcc) {
136
-        final DccChatSocketopenedEvent event = new DccChatSocketopenedEvent(this);
137
-        final String format = EventUtils.postDisplayable(eventBus, event, "DCCChatInfo");
138
-        addLine(format, "Socket opened");
130
+        eventBus.publishAsync(new DccChatSocketOpenedEvent(this));
139
         setIcon("dcc-chat-active");
131
         setIcon("dcc-chat-active");
140
     }
132
     }
141
 
133
 

+ 10
- 7
dcc/src/com/dmdirc/addons/dcc/DCCCommand.java Переглянути файл

24
 
24
 
25
 import com.dmdirc.DMDircMBassador;
25
 import com.dmdirc.DMDircMBassador;
26
 import com.dmdirc.addons.dcc.events.DccChatRequestSentEvent;
26
 import com.dmdirc.addons.dcc.events.DccChatRequestSentEvent;
27
+import com.dmdirc.addons.dcc.events.DccChatStartingEvent;
27
 import com.dmdirc.addons.dcc.events.DccSendRequestEvent;
28
 import com.dmdirc.addons.dcc.events.DccSendRequestEvent;
28
 import com.dmdirc.addons.dcc.io.DCC;
29
 import com.dmdirc.addons.dcc.io.DCC;
29
 import com.dmdirc.addons.dcc.io.DCCChat;
30
 import com.dmdirc.addons.dcc.io.DCCChat;
170
             parser.sendCTCP(target, "DCC", "CHAT chat " + DCC.ipToLong(
171
             parser.sendCTCP(target, "DCC", "CHAT chat " + DCC.ipToLong(
171
                     myPlugin.getListenIP(parser)) + ' ' + chat.getPort());
172
                     myPlugin.getListenIP(parser)) + ' ' + chat.getPort());
172
             eventBus.publish(new DccChatRequestSentEvent(connection, target));
173
             eventBus.publish(new DccChatRequestSentEvent(connection, target));
173
-            sendLine(origin, isSilent, "DCCChatStarting", target, chat.getHost(), chat.getPort());
174
-            window.addLine("DCCChatStarting", target, chat.getHost(), chat.getPort());
174
+
175
+            // Send the starting event to both the source window, and the new DCC window.
176
+            window.getEventBus().publishAsync(new DccChatStartingEvent(
177
+                    window, target, chat.getHost(), chat.getPort()));
178
+            origin.getEventBus().publishAsync(new DccChatStartingEvent(
179
+                    origin, target, chat.getHost(), chat.getPort()));
175
         } else {
180
         } else {
176
-            sendLine(origin, isSilent, "DCCChatError",
177
-                    "Unable to start chat with " + target
178
-                    + " - unable to create listen socket");
181
+            showError(origin, isSilent,
182
+                    "Unable to start chat with " + target + " - unable to create listen socket");
179
         }
183
         }
180
     }
184
     }
181
 
185
 
253
                             + " " + send.getPort() + " " + send.getFileSize()
257
                             + " " + send.getPort() + " " + send.getFileSize()
254
                             + (send.isTurbo() ? " T" : ""));
258
                             + (send.isTurbo() ? " T" : ""));
255
                 } else {
259
                 } else {
256
-                    sendLine(origin, isSilent, "DCCSendError",
257
-                            "Unable to start dcc send with " + target
260
+                    showError(origin, isSilent, "Unable to start dcc send with " + target
258
                             + " - unable to create listen socket");
261
                             + " - unable to create listen socket");
259
                 }
262
                 }
260
             }
263
             }

+ 5
- 3
dcc/src/com/dmdirc/addons/dcc/DCCManager.java Переглянути файл

25
 import com.dmdirc.ClientModule.GlobalConfig;
25
 import com.dmdirc.ClientModule.GlobalConfig;
26
 import com.dmdirc.DMDircMBassador;
26
 import com.dmdirc.DMDircMBassador;
27
 import com.dmdirc.addons.dcc.events.DccChatRequestEvent;
27
 import com.dmdirc.addons.dcc.events.DccChatRequestEvent;
28
+import com.dmdirc.addons.dcc.events.DccChatStartingEvent;
28
 import com.dmdirc.addons.dcc.events.DccSendRequestEvent;
29
 import com.dmdirc.addons.dcc.events.DccSendRequestEvent;
29
 import com.dmdirc.addons.dcc.io.DCC;
30
 import com.dmdirc.addons.dcc.io.DCC;
30
 import com.dmdirc.addons.dcc.io.DCCChat;
31
 import com.dmdirc.addons.dcc.io.DCCChat;
461
         final DCCChat chat = new DCCChat();
462
         final DCCChat chat = new DCCChat();
462
         chat.setAddress(ipAddress, port);
463
         chat.setAddress(ipAddress, port);
463
         final String myNickname = parser.getLocalClient().getNickname();
464
         final String myNickname = parser.getLocalClient().getNickname();
464
-        final DCCFrameContainer f = new ChatContainer(
465
+        final DCCFrameContainer container = new ChatContainer(
465
                 getContainer(),
466
                 getContainer(),
466
                 chat,
467
                 chat,
467
                 config,
468
                 config,
472
                 nickname,
473
                 nickname,
473
                 tabCompleterFactory,
474
                 tabCompleterFactory,
474
                 eventBus);
475
                 eventBus);
475
-        windowManager.addWindow(getContainer(), f);
476
-        f.addLine("DCCChatStarting", nickname, chat.getHost(), chat.getPort());
476
+        windowManager.addWindow(getContainer(), container);
477
+        container.getEventBus().publishAsync(new DccChatStartingEvent(
478
+                container, nickname, chat.getHost(), chat.getPort()));
477
         chat.connect();
479
         chat.connect();
478
     }
480
     }
479
 
481
 

dcc/src/com/dmdirc/addons/dcc/events/DccChatSelfmessageEvent.java → dcc/src/com/dmdirc/addons/dcc/events/DccChatSelfMessageEvent.java Переглянути файл

28
 /**
28
 /**
29
  * Fired on a DCC chat self message.
29
  * Fired on a DCC chat self message.
30
  */
30
  */
31
-public class DccChatSelfmessageEvent extends DccDisplayableEvent {
31
+public class DccChatSelfMessageEvent extends DccDisplayableEvent {
32
 
32
 
33
     private final ChatContainer chatWindow;
33
     private final ChatContainer chatWindow;
34
+    private final String nickname;
34
     private final String message;
35
     private final String message;
35
 
36
 
36
-    public DccChatSelfmessageEvent(final ChatContainer chatWindow, final String message) {
37
+    public DccChatSelfMessageEvent(final ChatContainer chatWindow, final String nickname,
38
+            final String message) {
37
         this.chatWindow = chatWindow;
39
         this.chatWindow = chatWindow;
40
+        this.nickname = nickname;
38
         this.message = message;
41
         this.message = message;
39
     }
42
     }
40
 
43
 
42
         return chatWindow;
45
         return chatWindow;
43
     }
46
     }
44
 
47
 
48
+    public String getNickname() {
49
+        return nickname;
50
+    }
51
+
45
     public String getMessage() {
52
     public String getMessage() {
46
         return message;
53
         return message;
47
     }
54
     }

dcc/src/com/dmdirc/addons/dcc/events/DccChatSocketclosedEvent.java → dcc/src/com/dmdirc/addons/dcc/events/DccChatSocketClosedEvent.java Переглянути файл

28
 /**
28
 /**
29
  * Fired when a chat socket is closed.
29
  * Fired when a chat socket is closed.
30
  */
30
  */
31
-public class DccChatSocketclosedEvent extends DccDisplayableEvent {
31
+public class DccChatSocketClosedEvent extends DccDisplayableEvent {
32
 
32
 
33
     private final ChatContainer chatWindow;
33
     private final ChatContainer chatWindow;
34
 
34
 
35
-    public DccChatSocketclosedEvent(final ChatContainer chatWindow) {
35
+    public DccChatSocketClosedEvent(final ChatContainer chatWindow) {
36
         this.chatWindow = chatWindow;
36
         this.chatWindow = chatWindow;
37
     }
37
     }
38
 
38
 

dcc/src/com/dmdirc/addons/dcc/events/DccChatSocketopenedEvent.java → dcc/src/com/dmdirc/addons/dcc/events/DccChatSocketOpenedEvent.java Переглянути файл

28
 /**
28
 /**
29
  * Fired when a chat socket is opened.
29
  * Fired when a chat socket is opened.
30
  */
30
  */
31
-public class DccChatSocketopenedEvent extends DccDisplayableEvent {
31
+public class DccChatSocketOpenedEvent extends DccDisplayableEvent {
32
 
32
 
33
     private final ChatContainer chatWindow;
33
     private final ChatContainer chatWindow;
34
 
34
 
35
-    public DccChatSocketopenedEvent(final ChatContainer chatWindow) {
35
+    public DccChatSocketOpenedEvent(final ChatContainer chatWindow) {
36
         this.chatWindow = chatWindow;
36
         this.chatWindow = chatWindow;
37
     }
37
     }
38
 
38
 

+ 62
- 0
dcc/src/com/dmdirc/addons/dcc/events/DccChatStartingEvent.java Переглянути файл

1
+/*
2
+ * Copyright (c) 2006-2015 DMDirc Developers
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.addons.dcc.events;
24
+
25
+import com.dmdirc.interfaces.WindowModel;
26
+
27
+/**
28
+ * Event raised when a DCC chat is starting.
29
+ */
30
+public class DccChatStartingEvent extends DccDisplayableEvent {
31
+
32
+    private final WindowModel source;
33
+    private final String target;
34
+    private final String host;
35
+    private final int port;
36
+
37
+    public DccChatStartingEvent(final WindowModel source, final String target, final String host,
38
+            final int port) {
39
+        this.source = source;
40
+        this.target = target;
41
+        this.host = host;
42
+        this.port = port;
43
+    }
44
+
45
+    @Override
46
+    public WindowModel getSource() {
47
+        return source;
48
+    }
49
+
50
+    public String getTarget() {
51
+        return target;
52
+    }
53
+
54
+    public String getHost() {
55
+        return host;
56
+    }
57
+
58
+    public int getPort() {
59
+        return port;
60
+    }
61
+
62
+}

Завантаження…
Відмінити
Зберегти