소스 검색

Tidy up Logging plugin.

Change-Id: I3b08c6e8316f03d2636802eb43d00350d5be01a0
Reviewed-on: http://gerrit.dmdirc.com/2262
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.7rc1
Greg Holmes 12 년 전
부모
커밋
256c07d0fc

+ 1
- 2
src/com/dmdirc/addons/logging/HistoryWindow.java 파일 보기

@@ -24,7 +24,6 @@ package com.dmdirc.addons.logging;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.Server;
27
-import com.dmdirc.config.IdentityManager;
28 27
 import com.dmdirc.ui.WindowManager;
29 28
 import com.dmdirc.ui.core.components.WindowComponent;
30 29
 
@@ -50,7 +49,7 @@ public class HistoryWindow extends FrameContainer {
50 49
 
51 50
         WindowManager.getWindowManager().addWindow(parent, this);
52 51
 
53
-        final int frameBufferSize = IdentityManager.getGlobalConfig().getOptionInt(
52
+        final int frameBufferSize = parent.getConfigManager().getOptionInt(
54 53
                 "ui", "frameBufferSize");
55 54
         addLine(reader.getLinesAsString(Math.min(frameBufferSize, numLines)), false);
56 55
     }

+ 6
- 24
src/com/dmdirc/addons/logging/LoggingCommand.java 파일 보기

@@ -29,14 +29,14 @@ import com.dmdirc.commandparser.CommandType;
29 29
 import com.dmdirc.commandparser.commands.Command;
30 30
 import com.dmdirc.commandparser.commands.IntelligentCommand;
31 31
 import com.dmdirc.commandparser.commands.context.CommandContext;
32
-import com.dmdirc.plugins.Plugin;
33
-import com.dmdirc.plugins.PluginInfo;
34
-import com.dmdirc.plugins.PluginManager;
35 32
 import com.dmdirc.ui.input.AdditionalTabTargets;
36 33
 
34
+import lombok.AllArgsConstructor;
35
+
37 36
 /**
38 37
  * The dcop command retrieves information from a dcop application.
39 38
  */
39
+@AllArgsConstructor
40 40
 public final class LoggingCommand extends Command implements
41 41
         IntelligentCommand {
42 42
 
@@ -46,33 +46,15 @@ public final class LoggingCommand extends Command implements
46 46
     public static final BaseCommandInfo INFO = new BaseCommandInfo(LOGGING,
47 47
             "logging - <set|help> [parameters]",
48 48
             CommandType.TYPE_SERVER);
49
+    /** Logging plugin. */
50
+    private final LoggingPlugin plugin;
49 51
 
50 52
     /** {@inheritDoc} */
51 53
     @Override
52 54
     public void execute(final FrameContainer origin,
53 55
             final CommandArguments args, final CommandContext context) {
54
-        final PluginInfo pluginInfo = PluginManager.getPluginManager().getPluginInfoByName("logging");
55
-        if (pluginInfo == null) {
56
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Logging Plugin is not loaded.");
57
-            return;
58
-        }
59
-        final Plugin gotPlugin = pluginInfo.getPlugin();
60
-
61
-        if (!(gotPlugin instanceof LoggingPlugin)) {
62
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Logging Plugin is not loaded.");
63
-            return;
64
-        }
65
-
66
-        final LoggingPlugin plugin = (LoggingPlugin) gotPlugin;
67
-
68 56
         if (args.getArguments().length > 0) {
69
-            if (args.getArguments()[0].equalsIgnoreCase("reload")) {
70
-                if (PluginManager.getPluginManager().reloadPlugin(pluginInfo.getFilename())) {
71
-                    sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Plugin reloaded.");
72
-                } else {
73
-                    sendLine(origin, args.isSilent(), FORMAT_ERROR, "Plugin failed to reload.");
74
-                }
75
-            } else if (args.getArguments()[0].equalsIgnoreCase("history")) {
57
+            if (args.getArguments()[0].equalsIgnoreCase("history")) {
76 58
                 if (!plugin.showHistory(origin)) {
77 59
                     sendLine(origin, args.isSilent(), FORMAT_ERROR, "Unable to open history for this window.");
78 60
                 }

+ 30
- 21
src/com/dmdirc/addons/logging/LoggingPlugin.java 파일 보기

@@ -29,6 +29,8 @@ import com.dmdirc.Query;
29 29
 import com.dmdirc.Server;
30 30
 import com.dmdirc.actions.CoreActionType;
31 31
 import com.dmdirc.interfaces.actions.ActionType;
32
+import com.dmdirc.config.ConfigManager;
33
+import com.dmdirc.config.Identity;
32 34
 import com.dmdirc.config.IdentityManager;
33 35
 import com.dmdirc.config.prefs.PluginPreferencesCategory;
34 36
 import com.dmdirc.config.prefs.PreferencesCategory;
@@ -87,6 +89,10 @@ public class LoggingPlugin extends BasePlugin implements ActionListener,
87 89
     private final PluginInfo pluginInfo;
88 90
     /** The action controller to use. */
89 91
     private final ActionController actionController;
92
+    /** Global config. */
93
+    private final ConfigManager config;
94
+    /** Addon identity. */
95
+    private final Identity identity;
90 96
 
91 97
     /** Timer used to close idle files. */
92 98
     protected Timer idleFileTimer;
@@ -105,20 +111,23 @@ public class LoggingPlugin extends BasePlugin implements ActionListener,
105 111
      * @param actionController The action controller to register listeners with
106 112
      */
107 113
     public LoggingPlugin(final PluginInfo pluginInfo,
108
-            final ActionController actionController) {
114
+            final ActionController actionController,
115
+            final IdentityManager identityManager) {
109 116
         super();
110 117
 
111 118
         this.pluginInfo = pluginInfo;
112 119
         this.actionController = actionController;
120
+        config = identityManager.getGlobalConfiguration();
121
+        identity = identityManager.getGlobalAddonIdentity();
113 122
 
114
-        registerCommand(new LoggingCommand(), LoggingCommand.INFO);
123
+        registerCommand(new LoggingCommand(this), LoggingCommand.INFO);
115 124
     }
116 125
 
117 126
     /** {@inheritDoc} */
118 127
     @Override
119 128
     public void domainUpdated() {
120
-        IdentityManager.getAddonIdentity().setOption(getDomain(),
121
-                "general.directory", Main.getConfigDir() + "logs" + System.getProperty("file.separator"));
129
+        identity.setOption(getDomain(), "general.directory",
130
+                Main.getConfigDir() + "logs" + System.getProperty("file.separator"));
122 131
     }
123 132
 
124 133
     /**
@@ -139,7 +148,7 @@ public class LoggingPlugin extends BasePlugin implements ActionListener,
139 148
             }
140 149
         }
141 150
 
142
-        IdentityManager.getGlobalConfig().addChangeListener(getDomain(), this);
151
+        config.addChangeListener(getDomain(), this);
143 152
 
144 153
         actionController.registerListener(this,
145 154
                 CoreActionType.CHANNEL_OPENED,
@@ -350,9 +359,9 @@ public class LoggingPlugin extends BasePlugin implements ActionListener,
350 359
                 final String overrideNick = isME ? getDisplayName(parser.getLocalClient()) : "";
351 360
 
352 361
                 if (type == CoreActionType.QUERY_MESSAGE || type == CoreActionType.QUERY_SELF_MESSAGE) {
353
-                    appendLine(filename, "<%s> %s", getDisplayName(client, overrideNick), (String) arguments[2]);
362
+                    appendLine(filename, "<%s> %s", getDisplayName(client, overrideNick), arguments[2]);
354 363
                 } else {
355
-                    appendLine(filename, "* %s %s", getDisplayName(client, overrideNick), (String) arguments[2]);
364
+                    appendLine(filename, "* %s %s", getDisplayName(client, overrideNick), arguments[2]);
356 365
                 }
357 366
                 break;
358 367
         }
@@ -865,20 +874,20 @@ public class LoggingPlugin extends BasePlugin implements ActionListener,
865 874
 
866 875
     /** Updates cached settings. */
867 876
     public void setCachedSettings() {
868
-        networkfolders = IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "general.networkfolders");
869
-        filenamehash = IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "advanced.filenamehash");
870
-        addtime = IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "general.addtime");
871
-        stripcodes = IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "general.stripcodes");
872
-        channelmodeprefix = IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "general.channelmodeprefix");
873
-        autobackbuffer = IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "backbuffer.autobackbuffer");
874
-        backbufferTimestamp = IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "backbuffer.timestamp");
875
-        usedate = IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "advanced.usedate");
876
-        timestamp = IdentityManager.getGlobalConfig().getOption(getDomain(), "general.timestamp");
877
-        usedateformat = IdentityManager.getGlobalConfig().getOption(getDomain(), "advanced.usedateformat");
878
-        historyLines = IdentityManager.getGlobalConfig().getOptionInt(getDomain(), "history.lines");
879
-        colour = IdentityManager.getGlobalConfig().getOption(getDomain(), "backbuffer.colour");
880
-        backbufferLines = IdentityManager.getGlobalConfig().getOptionInt(getDomain(), "backbuffer.lines");
881
-        logDirectory = IdentityManager.getGlobalConfig().getOption(getDomain(), "general.directory");
877
+        networkfolders = config.getOptionBool(getDomain(), "general.networkfolders");
878
+        filenamehash = config.getOptionBool(getDomain(), "advanced.filenamehash");
879
+        addtime = config.getOptionBool(getDomain(), "general.addtime");
880
+        stripcodes = config.getOptionBool(getDomain(), "general.stripcodes");
881
+        channelmodeprefix = config.getOptionBool(getDomain(), "general.channelmodeprefix");
882
+        autobackbuffer = config.getOptionBool(getDomain(), "backbuffer.autobackbuffer");
883
+        backbufferTimestamp = config.getOptionBool(getDomain(), "backbuffer.timestamp");
884
+        usedate = config.getOptionBool(getDomain(), "advanced.usedate");
885
+        timestamp = config.getOption(getDomain(), "general.timestamp");
886
+        usedateformat = config.getOption(getDomain(), "advanced.usedateformat");
887
+        historyLines = config.getOptionInt(getDomain(), "history.lines");
888
+        colour = config.getOption(getDomain(), "backbuffer.colour");
889
+        backbufferLines = config.getOptionInt(getDomain(), "backbuffer.lines");
890
+        logDirectory = config.getOption(getDomain(), "general.directory");
882 891
     }
883 892
 
884 893
     /** Open File. */

+ 2
- 1
test/com/dmdirc/addons/logging/TestLoggingPlugin.java 파일 보기

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.addons.logging;
24 24
 
25
+import com.dmdirc.config.IdentityManager;
25 26
 import com.dmdirc.interfaces.ActionController;
26 27
 import com.dmdirc.plugins.PluginInfo;
27 28
 import com.dmdirc.util.collections.MapList;
@@ -32,7 +33,7 @@ public class TestLoggingPlugin extends LoggingPlugin {
32 33
     public final MapList<Object, String> lines = new MapList<Object, String>();
33 34
 
34 35
     public TestLoggingPlugin() {
35
-        super(mock(PluginInfo.class), mock(ActionController.class));
36
+        super(mock(PluginInfo.class), mock(ActionController.class), IdentityManager.getIdentityManager());
36 37
     }
37 38
 
38 39
     @Override

Loading…
취소
저장