Parcourir la source

Merge branch 'master' of https://github.com/DMDirc/Plugins into qauth

pull/300/head
Greg Holmes il y a 9 ans
Parent
révision
5aa3f150e6

+ 0
- 20
identd/src/com/dmdirc/addons/identd/IdentdPlugin.java Voir le fichier

22
 
22
 
23
 package com.dmdirc.addons.identd;
23
 package com.dmdirc.addons.identd;
24
 
24
 
25
-import com.dmdirc.config.prefs.PluginPreferencesCategory;
26
-import com.dmdirc.config.prefs.PreferencesCategory;
27
-import com.dmdirc.config.prefs.PreferencesDialogModel;
28
-import com.dmdirc.config.prefs.PreferencesSetting;
29
-import com.dmdirc.config.prefs.PreferencesType;
30
 import com.dmdirc.plugins.PluginInfo;
25
 import com.dmdirc.plugins.PluginInfo;
31
 import com.dmdirc.plugins.implementations.BasePlugin;
26
 import com.dmdirc.plugins.implementations.BasePlugin;
32
-import com.dmdirc.util.validators.PortValidator;
33
 
27
 
34
 import dagger.ObjectGraph;
28
 import dagger.ObjectGraph;
35
 
29
 
38
  */
32
  */
39
 public class IdentdPlugin extends BasePlugin {
33
 public class IdentdPlugin extends BasePlugin {
40
 
34
 
41
-    /** This plugin's plugin info. */
42
-    private final PluginInfo pluginInfo;
43
-    /** This plugin's settings domain. */
44
-    private final String domain;
45
     /** Identd Manager. */
35
     /** Identd Manager. */
46
     private IdentdManager identdManager;
36
     private IdentdManager identdManager;
47
 
37
 
48
-    /**
49
-     * Creates a new instance of this plugin.
50
-     *
51
-     * @param pluginInfo This plugin's plugin info
52
-     */
53
-    public IdentdPlugin(final PluginInfo pluginInfo) {
54
-        this.pluginInfo = pluginInfo;
55
-        domain = pluginInfo.getDomain();
56
-    }
57
-
58
     @Override
38
     @Override
59
     public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
39
     public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
60
         super.load(pluginInfo, graph);
40
         super.load(pluginInfo, graph);

+ 47
- 0
notifications/src/com/dmdirc/addons/notifications/LegacyNotificationHandler.java Voir le fichier

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.notifications;
24
+
25
+import com.dmdirc.plugins.ExportedService;
26
+import com.dmdirc.plugins.PluginInfo;
27
+
28
+/**
29
+ * A notification handler that works using exported services.
30
+ */
31
+public class LegacyNotificationHandler implements NotificationHandler {
32
+
33
+    private final PluginInfo pluginInfo;
34
+
35
+    public LegacyNotificationHandler(final PluginInfo pluginInfo) {
36
+        this.pluginInfo = pluginInfo;
37
+    }
38
+
39
+    @Override
40
+    public void showNotification(final String title, final String message) {
41
+        final ExportedService source = pluginInfo.getExportedService("showNotification");
42
+        if (source != null) {
43
+            source.execute(title, message);
44
+        }
45
+    }
46
+
47
+}

+ 12
- 19
notifications/src/com/dmdirc/addons/notifications/NotificationCommand.java Voir le fichier

30
 import com.dmdirc.commandparser.commands.IntelligentCommand;
30
 import com.dmdirc.commandparser.commands.IntelligentCommand;
31
 import com.dmdirc.commandparser.commands.context.CommandContext;
31
 import com.dmdirc.commandparser.commands.context.CommandContext;
32
 import com.dmdirc.interfaces.CommandController;
32
 import com.dmdirc.interfaces.CommandController;
33
-import com.dmdirc.plugins.ExportedService;
34
-import com.dmdirc.plugins.PluginInfo;
35
 import com.dmdirc.ui.input.AdditionalTabTargets;
33
 import com.dmdirc.ui.input.AdditionalTabTargets;
36
 
34
 
37
-import java.util.List;
38
-import java.util.stream.Collectors;
35
+import java.util.Collection;
39
 
36
 
40
 import javax.annotation.Nonnull;
37
 import javax.annotation.Nonnull;
41
 
38
 
78
                 "--method".equalsIgnoreCase(args.getArguments()[0])) {
75
                 "--method".equalsIgnoreCase(args.getArguments()[0])) {
79
             if (args.getArguments().length > 1) {
76
             if (args.getArguments().length > 1) {
80
                 final String sourceName = args.getArguments()[1];
77
                 final String sourceName = args.getArguments()[1];
81
-                final ExportedService source = manager.getMethod(sourceName)
82
-                        .getExportedService("showNotification");
78
+                final NotificationHandler handler = manager.getHandler(sourceName);
83
 
79
 
84
-                if (source == null) {
80
+                if (handler == null) {
85
                     sendLine(origin, args.isSilent(), FORMAT_ERROR,
81
                     sendLine(origin, args.isSilent(), FORMAT_ERROR,
86
                             "Method not found.");
82
                             "Method not found.");
87
                 } else {
83
                 } else {
88
-                    source.execute("DMDirc", args.getArgumentsAsString(2));
84
+                    handler.showNotification("DMDirc", args.getArgumentsAsString(2));
89
                 }
85
                 }
90
             } else {
86
             } else {
91
                 sendLine(origin, args.isSilent(), FORMAT_ERROR,
87
                 sendLine(origin, args.isSilent(), FORMAT_ERROR,
92
                         "You must specify a method when using --method.");
88
                         "You must specify a method when using --method.");
93
             }
89
             }
94
-        } else if (manager.hasActiveMethod()) {
95
-            manager.getPreferredMethod().getExportedService("showNotification")
96
-                    .execute("DMDirc", args.getArgumentsAsString(0));
90
+        } else if (manager.hasActiveHandler()) {
91
+            manager.getPreferredHandler().showNotification("DMDirc", args.getArgumentsAsString(0));
97
         } else {
92
         } else {
98
             sendLine(origin, args.isSilent(), FORMAT_ERROR,
93
             sendLine(origin, args.isSilent(), FORMAT_ERROR,
99
                     "No active notification methods available.");
94
                     "No active notification methods available.");
108
      */
103
      */
109
     private void doMethodList(final FrameContainer origin,
104
     private void doMethodList(final FrameContainer origin,
110
             final boolean isSilent) {
105
             final boolean isSilent) {
111
-        final List<PluginInfo> methods = manager.getMethods();
106
+        final Collection<String> handlers = manager.getHandlerNames();
112
 
107
 
113
-        if (methods.isEmpty()) {
108
+        if (handlers.isEmpty()) {
114
             sendLine(origin, isSilent, FORMAT_ERROR, "No notification "
109
             sendLine(origin, isSilent, FORMAT_ERROR, "No notification "
115
                     + "methods available.");
110
                     + "methods available.");
116
         } else {
111
         } else {
117
             final String[] headers = {"Method"};
112
             final String[] headers = {"Method"};
118
-            final String[][] data = new String[methods.size()][1];
113
+            final String[][] data = new String[handlers.size()][1];
119
             int i = 0;
114
             int i = 0;
120
-            for (PluginInfo method : methods) {
121
-                data[i][0] = method.getMetaData().getName();
115
+            for (String handler : handlers) {
116
+                data[i][0] = handler;
122
                 i++;
117
                 i++;
123
             }
118
             }
124
 
119
 
136
             res.add("--method");
131
             res.add("--method");
137
             return res;
132
             return res;
138
         } else if (arg == 1 && "--method".equalsIgnoreCase(context.getPreviousArgs().get(0))) {
133
         } else if (arg == 1 && "--method".equalsIgnoreCase(context.getPreviousArgs().get(0))) {
139
-            res.addAll(manager.getMethods().stream()
140
-                    .map(source -> source.getMetaData().getName())
141
-                    .collect(Collectors.toList()));
134
+            res.addAll(manager.getHandlerNames());
142
             return res;
135
             return res;
143
         }
136
         }
144
         return res;
137
         return res;

+ 38
- 0
notifications/src/com/dmdirc/addons/notifications/NotificationHandler.java Voir le fichier

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.notifications;
24
+
25
+/**
26
+ * Handler of notifications.
27
+ */
28
+public interface NotificationHandler {
29
+
30
+    /**
31
+     * Displays a notification to the user.
32
+     *
33
+     * @param title The title of the notification.
34
+     * @param message The notification content.
35
+     */
36
+    void showNotification(String title, String message);
37
+
38
+}

+ 28
- 30
notifications/src/com/dmdirc/addons/notifications/NotificationsManager.java Voir le fichier

38
 
38
 
39
 import java.util.ArrayList;
39
 import java.util.ArrayList;
40
 import java.util.Collection;
40
 import java.util.Collection;
41
+import java.util.HashMap;
41
 import java.util.List;
42
 import java.util.List;
43
+import java.util.Map;
42
 
44
 
43
 import javax.inject.Inject;
45
 import javax.inject.Inject;
44
 
46
 
46
 
48
 
47
 public class NotificationsManager {
49
 public class NotificationsManager {
48
 
50
 
49
-    /** The notification methods that we know of. */
50
-    private final Collection<String> methods = new ArrayList<>();
51
+    /** The notification handlers that we know of. */
52
+    private final Map<String, NotificationHandler> handlers = new HashMap<>();
51
     /** The user's preferred order for method usage. */
53
     /** The user's preferred order for method usage. */
52
     private List<String> order;
54
     private List<String> order;
53
     /** This plugin's settings domain. */
55
     /** This plugin's settings domain. */
73
     }
75
     }
74
 
76
 
75
     public void onLoad() {
77
     public void onLoad() {
76
-        methods.clear();
78
+        handlers.clear();
77
         loadSettings();
79
         loadSettings();
78
         eventBus.subscribe(this);
80
         eventBus.subscribe(this);
79
         pluginManager.getPluginInfos().stream()
81
         pluginManager.getPluginInfos().stream()
82
     }
84
     }
83
 
85
 
84
     public void onUnload() {
86
     public void onUnload() {
85
-        methods.clear();
87
+        handlers.clear();
86
         eventBus.unsubscribe(this);
88
         eventBus.unsubscribe(this);
87
     }
89
     }
88
 
90
 
113
      */
115
      */
114
     private void addPlugin(final PluginInfo target) {
116
     private void addPlugin(final PluginInfo target) {
115
         if (target.hasExportedService("showNotification")) {
117
         if (target.hasExportedService("showNotification")) {
116
-            methods.add(target.getMetaData().getName());
117
-            addMethodToOrder(target);
118
+            handlers.put(target.getMetaData().getName(), new LegacyNotificationHandler(pluginInfo));
119
+            addHandlerToOrder(target);
118
         }
120
         }
119
     }
121
     }
120
 
122
 
124
      *
126
      *
125
      * @param source The notification method to be tested
127
      * @param source The notification method to be tested
126
      */
128
      */
127
-    private void addMethodToOrder(final PluginInfo source) {
129
+    private void addHandlerToOrder(final PluginInfo source) {
128
         if (!order.contains(source.getMetaData().getName())) {
130
         if (!order.contains(source.getMetaData().getName())) {
129
             order.add(source.getMetaData().getName());
131
             order.add(source.getMetaData().getName());
130
         }
132
         }
137
      * @param target The plugin to be tested
139
      * @param target The plugin to be tested
138
      */
140
      */
139
     private void removePlugin(final PluginInfo target) {
141
     private void removePlugin(final PluginInfo target) {
140
-        methods.remove(target.getMetaData().getName());
142
+        handlers.remove(target.getMetaData().getName());
141
     }
143
     }
142
 
144
 
143
     /**
145
     /**
144
-     * Retrieves a method based on its name.
146
+     * Retrieves a handler based on its name.
145
      *
147
      *
146
      * @param name The name to search for
148
      * @param name The name to search for
147
      *
149
      *
148
-     * @return The method with the specified name or null if none were found.
150
+     * @return The handler with the specified name or null if none were found.
149
      */
151
      */
150
-    public PluginInfo getMethod(final String name) {
151
-        return pluginManager.getPluginInfoByName(name);
152
+    public NotificationHandler getHandler(final String name) {
153
+        return handlers.get(name);
152
     }
154
     }
153
 
155
 
154
     /**
156
     /**
155
-     * Retrieves all the methods registered with this plugin.
157
+     * Retrieves the names of all the handlers registered with this plugin.
156
      *
158
      *
157
-     * @return All known notification sources
159
+     * @return All known notification handler names
158
      */
160
      */
159
-    public List<PluginInfo> getMethods() {
160
-        final List<PluginInfo> plugins = new ArrayList<>();
161
-        for (String method : methods) {
162
-            plugins.add(pluginManager.getPluginInfoByName(method));
163
-        }
164
-        return plugins;
161
+    public Collection<String> getHandlerNames() {
162
+        return handlers.keySet();
165
     }
163
     }
166
 
164
 
167
     /**
165
     /**
168
-     * Does this plugin have any active notification methods?
166
+     * Does this plugin have any active notification handler?
169
      *
167
      *
170
-     * @return true iif active notification methods are registered
168
+     * @return true iif active notification handlers are registered
171
      */
169
      */
172
-    public boolean hasActiveMethod() {
173
-        return !methods.isEmpty();
170
+    public boolean hasActiveHandler() {
171
+        return !handlers.isEmpty();
174
     }
172
     }
175
 
173
 
176
     /**
174
     /**
177
-     * Returns the user's preferred method if loaded, or null if none loaded.
175
+     * Returns the user's preferred handler if loaded, or null if none loaded.
178
      *
176
      *
179
-     * @return Preferred notification method
177
+     * @return Preferred notification handler
180
      */
178
      */
181
-    public PluginInfo getPreferredMethod() {
182
-        if (methods.isEmpty()) {
179
+    public NotificationHandler getPreferredHandler() {
180
+        if (handlers.isEmpty()) {
183
             return null;
181
             return null;
184
         }
182
         }
185
         for (String method : order) {
183
         for (String method : order) {
186
-            if (methods.contains(method)) {
187
-                return pluginManager.getPluginInfoByName(method);
184
+            if (handlers.containsKey(method)) {
185
+                return handlers.get(method);
188
             }
186
             }
189
         }
187
         }
190
         return null;
188
         return null;

+ 0
- 1
osd/src/com/dmdirc/addons/osd/OsdPlugin.java Voir le fichier

33
  */
33
  */
34
 public class OsdPlugin extends BaseCommandPlugin {
34
 public class OsdPlugin extends BaseCommandPlugin {
35
 
35
 
36
-
37
     /** The OSD Manager that this plugin is using. */
36
     /** The OSD Manager that this plugin is using. */
38
     private OsdManager osdManager;
37
     private OsdManager osdManager;
39
 
38
 

+ 3
- 10
ui_swing/src/com/dmdirc/addons/ui_swing/SwingController.java Voir le fichier

47
 public class SwingController extends BaseCommandPlugin implements UIController {
47
 public class SwingController extends BaseCommandPlugin implements UIController {
48
 
48
 
49
     /** This plugin's plugin info object. */
49
     /** This plugin's plugin info object. */
50
-    private final PluginInfo pluginInfo;
50
+    private PluginInfo pluginInfo;
51
     /** The manager we're using for dependencies. */
51
     /** The manager we're using for dependencies. */
52
     private SwingManager swingManager;
52
     private SwingManager swingManager;
53
 
53
 
54
-    /**
55
-     * Instantiates a new SwingController.
56
-     *
57
-     * @param pluginInfo      Plugin info
58
-     */
59
-    public SwingController(final PluginInfo pluginInfo) {
60
-        this.pluginInfo = pluginInfo;
61
-    }
62
-
63
     @Override
54
     @Override
64
     public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
55
     public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
65
         super.load(pluginInfo, graph);
56
         super.load(pluginInfo, graph);
66
 
57
 
58
+        this.pluginInfo = pluginInfo;
59
+
67
         setObjectGraph(graph.plus(new SwingModule(this, pluginInfo, pluginInfo.getDomain())));
60
         setObjectGraph(graph.plus(new SwingModule(this, pluginInfo, pluginInfo.getDomain())));
68
         getObjectGraph().validate();
61
         getObjectGraph().validate();
69
         swingManager = getObjectGraph().get(SwingManager.class);
62
         swingManager = getObjectGraph().get(SwingManager.class);

+ 15
- 2
ui_swing/src/com/dmdirc/addons/ui_swing/components/addonpanel/PluginPanel.java Voir le fichier

38
 import java.util.ArrayList;
38
 import java.util.ArrayList;
39
 import java.util.Collection;
39
 import java.util.Collection;
40
 import java.util.Collections;
40
 import java.util.Collections;
41
+import java.util.Comparator;
41
 import java.util.List;
42
 import java.util.List;
42
 
43
 
43
 import javax.inject.Inject;
44
 import javax.inject.Inject;
53
 
54
 
54
     /** A version number for this class. */
55
     /** A version number for this class. */
55
     private static final long serialVersionUID = 1;
56
     private static final long serialVersionUID = 1;
57
+
58
+    /** Comparator to use to sort plugins in the panel. */
59
+    private static final Comparator<? super PluginInfo> COMPARATOR = new PluginInfoComparator();
60
+
56
     /** Manager to retrieve plugin information from. */
61
     /** Manager to retrieve plugin information from. */
57
     private final PluginManager pluginManager;
62
     private final PluginManager pluginManager;
58
     /** Manager to use to retrieve addon-related icons. */
63
     /** Manager to use to retrieve addon-related icons. */
97
         final List<PluginInfo> list = new ArrayList<>();
102
         final List<PluginInfo> list = new ArrayList<>();
98
         final Collection<PluginInfo> sortedList = new ArrayList<>();
103
         final Collection<PluginInfo> sortedList = new ArrayList<>();
99
         list.addAll(pluginManager.getPluginInfos());
104
         list.addAll(pluginManager.getPluginInfos());
100
-        Collections.sort(list);
105
+        Collections.sort(list, COMPARATOR);
101
         list.stream().filter(plugin -> plugin.getMetaData().getParent() == null).forEach(plugin -> {
106
         list.stream().filter(plugin -> plugin.getMetaData().getParent() == null).forEach(plugin -> {
102
             final List<PluginInfo> childList = new ArrayList<>();
107
             final List<PluginInfo> childList = new ArrayList<>();
103
             sortedList.add(plugin);
108
             sortedList.add(plugin);
104
             plugin.getChildren().stream()
109
             plugin.getChildren().stream()
105
                     .filter(child -> !childList.contains(child))
110
                     .filter(child -> !childList.contains(child))
106
                     .forEach(childList::add);
111
                     .forEach(childList::add);
107
-            Collections.sort(childList);
112
+            Collections.sort(childList, COMPARATOR);
108
             sortedList.addAll(childList);
113
             sortedList.addAll(childList);
109
         });
114
         });
110
 
115
 
136
         return "plugins";
141
         return "plugins";
137
     }
142
     }
138
 
143
 
144
+    private static class PluginInfoComparator implements Comparator<PluginInfo> {
145
+
146
+        @Override
147
+        public int compare(final PluginInfo o1, final PluginInfo o2) {
148
+            return o1.getMetaData().getName().compareTo(o2.getMetaData().getName());
149
+        }
150
+    }
151
+
139
 }
152
 }

Chargement…
Annuler
Enregistrer