Procházet zdrojové kódy

Add settings to the channel who plugin.

pull/377/head
Greg Holmes před 9 roky
rodič
revize
399748c3db

+ 6
- 1
channelwho/plugin.config Zobrazit soubor

7
   metadata
7
   metadata
8
   updates
8
   updates
9
   version
9
   version
10
+  defaults
10
 
11
 
11
 metadata:
12
 metadata:
12
   author=Greg <greg@dmdirc.com>
13
   author=Greg <greg@dmdirc.com>
19
   id=77
20
   id=77
20
 
21
 
21
 version:
22
 version:
22
-  friendly=0.1
23
+  friendly=0.1
24
+
25
+defaults:
26
+  sendwho=false
27
+  whointerval=60000

+ 29
- 0
channelwho/src/com/dmdirc/addons/channelwho/ChannelWhoManager.java Zobrazit soubor

23
 package com.dmdirc.addons.channelwho;
23
 package com.dmdirc.addons.channelwho;
24
 
24
 
25
 import com.dmdirc.DMDircMBassador;
25
 import com.dmdirc.DMDircMBassador;
26
+import com.dmdirc.config.prefs.PreferencesCategory;
27
+import com.dmdirc.config.prefs.PreferencesSetting;
28
+import com.dmdirc.config.prefs.PreferencesType;
29
+import com.dmdirc.events.ClientPrefsOpenedEvent;
30
+import com.dmdirc.events.GroupChatPrefsRequestedEvent;
26
 import com.dmdirc.events.ServerConnectingEvent;
31
 import com.dmdirc.events.ServerConnectingEvent;
27
 import com.dmdirc.events.ServerDisconnectedEvent;
32
 import com.dmdirc.events.ServerDisconnectedEvent;
28
 import com.dmdirc.interfaces.Connection;
33
 import com.dmdirc.interfaces.Connection;
29
 import com.dmdirc.interfaces.ConnectionManager;
34
 import com.dmdirc.interfaces.ConnectionManager;
35
+import com.dmdirc.plugins.PluginDomain;
36
+import com.dmdirc.util.validators.NumericalValidator;
30
 
37
 
31
 import com.google.common.annotations.VisibleForTesting;
38
 import com.google.common.annotations.VisibleForTesting;
32
 
39
 
42
  */
49
  */
43
 public class ChannelWhoManager {
50
 public class ChannelWhoManager {
44
 
51
 
52
+    private final String domain;
45
     private final ConnectionHandlerFactory connectionHandlerFactory;
53
     private final ConnectionHandlerFactory connectionHandlerFactory;
46
     private final ConnectionManager connectionManager;
54
     private final ConnectionManager connectionManager;
47
     private final DMDircMBassador eventBus;
55
     private final DMDircMBassador eventBus;
49
 
57
 
50
     @Inject
58
     @Inject
51
     public ChannelWhoManager(
59
     public ChannelWhoManager(
60
+            @PluginDomain(ChannelWhoPlugin.class) final String domain,
52
             final ConnectionHandlerFactory connectionHandlerFactory,
61
             final ConnectionHandlerFactory connectionHandlerFactory,
53
             final ConnectionManager connectionManager,
62
             final ConnectionManager connectionManager,
54
             final DMDircMBassador eventBus) {
63
             final DMDircMBassador eventBus) {
64
+        this.domain = domain;
55
         this.connectionHandlerFactory = connectionHandlerFactory;
65
         this.connectionHandlerFactory = connectionHandlerFactory;
56
         this.connectionManager = connectionManager;
66
         this.connectionManager = connectionManager;
57
         this.eventBus = eventBus;
67
         this.eventBus = eventBus;
79
         }
89
         }
80
     }
90
     }
81
 
91
 
92
+    @VisibleForTesting
93
+    @Handler
94
+    void handleGroupChatPrefsRequestedEvent(final GroupChatPrefsRequestedEvent event) {
95
+        event.getCategory().addSetting(new PreferencesSetting(PreferencesType.BOOLEAN, domain,
96
+                "sendWho", "Send Who Requests", "Should we send who requests to the channel?",
97
+                event.getConfig(), event.getIdentity()));
98
+    }
99
+
100
+    @VisibleForTesting
101
+    @Handler
102
+    void handlePrefsDialog(final ClientPrefsOpenedEvent event) {
103
+        final PreferencesCategory category = new PreferencesCategory("Channel Who", "Provides " +
104
+                "support for sendinw WHO requests to channels at regular intervals");
105
+        category.addSetting(new PreferencesSetting(PreferencesType.DURATION,
106
+                new NumericalValidator(0, Integer.MAX_VALUE), domain, "whointerval",
107
+                "Who Interval", "The interval WHO requests will be sent to channels",
108
+                event.getModel().getConfigManager(), event.getModel().getIdentity()));
109
+    }
110
+
82
     @VisibleForTesting
111
     @VisibleForTesting
83
     @Handler
112
     @Handler
84
     void handleServerConnectingEvent(final ServerConnectingEvent event) {
113
     void handleServerConnectingEvent(final ServerConnectingEvent event) {

+ 7
- 8
channelwho/src/com/dmdirc/addons/channelwho/ConnectionHandler.java Zobrazit soubor

81
         executorService.shutdown();
81
         executorService.shutdown();
82
         connection.getWindowModel().getEventBus().unsubscribe(this);
82
         connection.getWindowModel().getEventBus().unsubscribe(this);
83
         if (future != null) {
83
         if (future != null) {
84
-            future.cancel(true);
84
+            future.cancel(false);
85
         }
85
         }
86
     }
86
     }
87
 
87
 
89
     void checkWho() {
89
     void checkWho() {
90
         connectionManager.getConnections().forEach(connection ->
90
         connectionManager.getConnections().forEach(connection ->
91
                 connection.getGroupChatManager().getChannels().forEach(channel -> {
91
                 connection.getGroupChatManager().getChannels().forEach(channel -> {
92
-            if (channel.getWindowModel().getConfigManager().getOptionBool(domain, "sendWho")) {
93
-                channel.requestUsersInfo();
94
-            }
95
-        }));
92
+                    if (channel.getWindowModel().getConfigManager().getOptionBool(domain, "sendwho")) {
93
+                        channel.requestUsersInfo();}}));
96
     }
94
     }
97
 
95
 
98
     @VisibleForTesting
96
     @VisibleForTesting
99
-    @ConfigBinding(key="whoInterval")
97
+    @ConfigBinding(key="whointerval")
100
     void handleWhoInterval(final int value) {
98
     void handleWhoInterval(final int value) {
101
         if (future != null) {
99
         if (future != null) {
102
-            future.cancel(true);
100
+            future.cancel(false);
103
         }
101
         }
104
-        future = executorService.schedule(this::checkWho, value, TimeUnit.MILLISECONDS);
102
+        future = executorService.scheduleAtFixedRate(this::checkWho, value, value,
103
+                TimeUnit.MILLISECONDS);
105
     }
104
     }
106
 
105
 
107
     @VisibleForTesting
106
     @VisibleForTesting

Načítá se…
Zrušit
Uložit