Quellcode durchsuchen

Use events for showconfig in all remaining plugins.

pull/292/head
Greg Holmes vor 9 Jahren
Ursprung
Commit
3db884418a

+ 308
- 0
mediasource_vlc/src/com/dmdirc/addons/mediasource_vlc/VlcManager.java Datei anzeigen

@@ -0,0 +1,308 @@
1
+package com.dmdirc.addons.mediasource_vlc;
2
+
3
+import com.dmdirc.addons.nowplaying.MediaSource;
4
+import com.dmdirc.addons.nowplaying.MediaSourceState;
5
+import com.dmdirc.config.prefs.PluginPreferencesCategory;
6
+import com.dmdirc.config.prefs.PreferencesCategory;
7
+import com.dmdirc.config.prefs.PreferencesDialogModel;
8
+import com.dmdirc.config.prefs.PreferencesSetting;
9
+import com.dmdirc.config.prefs.PreferencesType;
10
+import com.dmdirc.events.ClientPrefsOpenedEvent;
11
+import com.dmdirc.interfaces.config.IdentityController;
12
+import com.dmdirc.plugins.PluginDomain;
13
+import com.dmdirc.plugins.PluginInfo;
14
+import com.dmdirc.util.io.Downloader;
15
+
16
+import java.io.File;
17
+import java.io.IOException;
18
+import java.util.HashMap;
19
+import java.util.List;
20
+import java.util.Map;
21
+
22
+import javax.inject.Inject;
23
+
24
+import net.engio.mbassy.listener.Handler;
25
+
26
+/**
27
+ * Retrieves information from VLC using its HTTP interface.
28
+ */
29
+public class VlcManager implements MediaSource {
30
+
31
+    /** The information obtained from VLC. */
32
+    private final Map<String, String> information = new HashMap<>();
33
+    /** This plugin's plugin info. */
34
+    private final PluginInfo pluginInfo;
35
+    /** The identity controller to read settings from. */
36
+    private final IdentityController identityController;
37
+    /** Downloader to download files. */
38
+    private final Downloader downloader;
39
+
40
+    @Inject
41
+    public VlcManager(
42
+            @PluginDomain(VlcMediaSourcePlugin.class) final PluginInfo pluginInfo,
43
+            final IdentityController identityController) {
44
+        this.pluginInfo = pluginInfo;
45
+        this.identityController = identityController;
46
+        this.downloader = new Downloader();
47
+    }
48
+
49
+    @Override
50
+    public MediaSourceState getState() {
51
+        if (fetchInformation()) {
52
+            final String output = information.get("state");
53
+            if (output.equalsIgnoreCase("stop")) {
54
+                return MediaSourceState.STOPPED;
55
+            } else if (output.equalsIgnoreCase("playing")) {
56
+                return MediaSourceState.PLAYING;
57
+            } else if (output.equalsIgnoreCase("paused")) {
58
+                return MediaSourceState.PAUSED;
59
+            } else {
60
+                return MediaSourceState.NOTKNOWN;
61
+            }
62
+        } else {
63
+            return MediaSourceState.CLOSED;
64
+        }
65
+    }
66
+
67
+    @Override
68
+    public String getAppName() {
69
+        return "VLC";
70
+    }
71
+
72
+    @Override
73
+    public String getArtist() {
74
+        return information.containsKey("artist") ? information.get("artist") : getFallbackArtist();
75
+    }
76
+
77
+    /**
78
+     * Retrieves the fallback artist (parsed from the file name).
79
+     *
80
+     * @return The fallback artist
81
+     */
82
+    private String getFallbackArtist() {
83
+        String result = "unknown";
84
+
85
+        if (information.containsKey("playlist_current")) {
86
+            try {
87
+                final int item = Integer.parseInt(information.get(
88
+                        "playlist_current"));
89
+                String[] bits = information.get("playlist_item_" + item).split(
90
+                        (File.separatorChar == '\\' ? "\\\\" : File.separator));
91
+                result = bits[bits.length - 1];
92
+                bits = result.split("-");
93
+                if (bits.length > 1) {
94
+                    result = bits[0];
95
+                } else {
96
+                    // Whole filename is the title, so no artist is known.
97
+                    result = "unknown";
98
+                }
99
+            } catch (NumberFormatException nfe) {
100
+                // DO nothing
101
+            }
102
+        }
103
+
104
+        return result;
105
+    }
106
+
107
+    @Override
108
+    public String getTitle() {
109
+        return information.containsKey("title") ? information.get("title")
110
+                : getFallbackTitle();
111
+    }
112
+
113
+    /**
114
+     * Retrieves the fallback title (parsed from the file name).
115
+     *
116
+     * @return The fallback title
117
+     */
118
+    private String getFallbackTitle() {
119
+        String result = "unknown";
120
+
121
+        // Title is unknown, lets guess using the filename
122
+        if (information.containsKey("playlist_current")) {
123
+            try {
124
+                final int item = Integer.parseInt(information.get(
125
+                        "playlist_current"));
126
+                result = information.get("playlist_item_" + item);
127
+
128
+                final int sepIndex = result.lastIndexOf(File.separatorChar);
129
+                final int extIndex = result.lastIndexOf('.');
130
+                result = result.substring(sepIndex,
131
+                        extIndex > sepIndex ? extIndex : result.length());
132
+
133
+                final int offset = result.indexOf('-');
134
+                if (offset > -1) {
135
+                    result = result.substring(offset + 1).trim();
136
+                }
137
+            } catch (NumberFormatException nfe) {
138
+                // Do nothing
139
+            }
140
+        }
141
+
142
+        return result;
143
+    }
144
+
145
+    @Override
146
+    public String getAlbum() {
147
+        return information.containsKey("album/movie/show title")
148
+                ? information.get("album/movie/show title") : "unknown";
149
+    }
150
+
151
+    @Override
152
+    public String getLength() {
153
+        // This is just seconds, could do with formatting.
154
+        return information.containsKey("length") ? information.get("length")
155
+                : "unknown";
156
+    }
157
+
158
+    @Override
159
+    public String getTime() {
160
+        // This is just seconds, could do with formatting.
161
+        return information.containsKey("time") ? information.get("time")
162
+                : "unknown";
163
+    }
164
+
165
+    @Override
166
+    public String getFormat() {
167
+        return information.containsKey("codec") ? information.get("codec")
168
+                : "unknown";
169
+    }
170
+
171
+    @Override
172
+    public String getBitrate() {
173
+        return information.containsKey("bitrate") ? information.get("bitrate")
174
+                : "unknown";
175
+    }
176
+
177
+    @Handler
178
+    public void showConfig(final ClientPrefsOpenedEvent event) {
179
+        final PreferencesDialogModel manager = event.getModel();
180
+        final PreferencesCategory general = new PluginPreferencesCategory(
181
+                pluginInfo, "VLC Media Source",
182
+                "", "category-vlc");
183
+
184
+        final PreferencesSetting setting = new PreferencesSetting(
185
+                PreferencesType.LABEL, pluginInfo.getDomain(), "", "Instructions",
186
+                "Instructions", manager.getConfigManager(), manager.getIdentity());
187
+        setting.setValue("<html><p>"
188
+                + "The VLC media source requires that VLC's web interface is"
189
+                + " enabled. To do this, follow the steps below:</p>"
190
+                + "<ol style='margin-left: 20px; padding-left: 0px;'>"
191
+                + "<li>Open VLC's preferences dialog (found in the 'Tools' "
192
+                + "menu)"
193
+                + "<li>Set the 'Show settings' option to 'All'"
194
+                + "<li>Expand the 'Interface' category by clicking on the plus "
195
+                + "sign next to it"
196
+                + "<li>Select the 'Main interfaces' category"
197
+                + "<li>Check the box next to 'HTTP remote control interface'"
198
+                + "<li>Expand the 'Main interfaces' category"
199
+                + "<li>Select the 'HTTP' category"
200
+                + "<li>In the 'Host address' field, enter 'localhost:8082'"
201
+                + "<li>In the 'Source directory' field enter the path to VLC's"
202
+                + " http directory<ul style='margin-left: 5px; padding-left: "
203
+                + "0px; list-style-type: none;'>"
204
+                + "<li style='padding-bottom: 5px'>For Linux users this may be "
205
+                + "/usr/share/vlc/http/"
206
+                + "<li>For Windows users this will be under the main VLC "
207
+                + "directory, e.g. C:\\Program Files\\VLC\\http</ul><li>Click "
208
+                + "'Save'<li>Restart VLC</ol></html>");
209
+        general.addSetting(setting);
210
+        general.addSetting(new PreferencesSetting(PreferencesType.TEXT,
211
+                pluginInfo.getDomain(), "host", "Hostname and port",
212
+                "The host and port that VLC listens on for web connections",
213
+                manager.getConfigManager(), manager.getIdentity()));
214
+
215
+        manager.getCategory("Plugins").addSubCategory(general);
216
+    }
217
+
218
+    /**
219
+     * Attempts to fetch information from VLC's web interface.
220
+     *
221
+     * @return True on success, false otherwise
222
+     */
223
+    private boolean fetchInformation() {
224
+        information.clear();
225
+        final List<String> res;
226
+        final List<String> res2;
227
+
228
+        try {
229
+            final String host = identityController.getGlobalConfiguration()
230
+                    .getOption(pluginInfo.getDomain(), "host");
231
+            res = downloader.getPage("http://" + host + "/old/info.html");
232
+            res2 = downloader.getPage("http://" + host + "/old/");
233
+            parseInformation(res, res2);
234
+            return true;
235
+        } catch (IOException ex) {
236
+            return false;
237
+        }
238
+    }
239
+
240
+    /**
241
+     * Parses the information from the two pages obtained from VLC's web interface.
242
+     *
243
+     * @param res  The first page of VLC info (/old/info.html)
244
+     * @param res2 The second page of VLC info (/old/)
245
+     */
246
+    protected void parseInformation(final List<String> res,
247
+            final List<String> res2) {
248
+        for (String line : res) {
249
+            final String tline = line.trim();
250
+
251
+            if (tline.startsWith("<li>")) {
252
+                final int colon = tline.indexOf(':');
253
+                final String key = tline.substring(5, colon).trim()
254
+                        .toLowerCase();
255
+                final String value = tline.substring(colon + 1, tline.length()
256
+                        - 5).trim();
257
+
258
+                information.put(key, value);
259
+            }
260
+        }
261
+
262
+        boolean isPlaylist = false;
263
+        boolean isCurrent = false;
264
+        boolean isItem = false;
265
+        int playlistItem = 0;
266
+        for (String line : res2) {
267
+            final String tline = line.trim();
268
+
269
+            if (isPlaylist) {
270
+                if (tline.startsWith("</ul>")) {
271
+                    isPlaylist = false;
272
+                    information.put("playlist_items", Integer.toString(
273
+                            playlistItem));
274
+                } else if (tline.equalsIgnoreCase("<strong>")) {
275
+                    isCurrent = true;
276
+                } else if (tline.equalsIgnoreCase("</strong>")) {
277
+                    isCurrent = false;
278
+                } else if (tline.startsWith("<a href=\"?control=play&amp")) {
279
+                    isItem = true;
280
+                } else if (isItem) {
281
+                    String itemname = tline;
282
+                    if (itemname.endsWith("</a>")) {
283
+                        itemname = itemname.substring(0, itemname.length() - 4);
284
+                    }
285
+                    if (!itemname.isEmpty()) {
286
+                        if (isCurrent) {
287
+                            information.put("playlist_current", Integer
288
+                                    .toString(playlistItem));
289
+                        }
290
+                        information.put("playlist_item_" + Integer.toString(
291
+                                playlistItem++), itemname);
292
+                    }
293
+                    isItem = false;
294
+                }
295
+            } else if (tline.equalsIgnoreCase("<!-- Playlist -->")) {
296
+                isPlaylist = true;
297
+            } else if (tline.startsWith("State:")) {
298
+                information.put("state", tline.substring(6, tline.indexOf('<'))
299
+                        .trim());
300
+            } else if (tline.startsWith("got_")) {
301
+                final int equals = tline.indexOf('=');
302
+
303
+                information.put(tline.substring(4, equals).trim(),
304
+                        tline.substring(equals + 1, tline.length() - 1).trim());
305
+            }
306
+        }
307
+    }
308
+}

+ 7
- 286
mediasource_vlc/src/com/dmdirc/addons/mediasource_vlc/VlcMediaSourcePlugin.java Datei anzeigen

@@ -22,302 +22,23 @@
22 22
 
23 23
 package com.dmdirc.addons.mediasource_vlc;
24 24
 
25
-import com.dmdirc.addons.nowplaying.MediaSource;
26
-import com.dmdirc.addons.nowplaying.MediaSourceState;
27
-import com.dmdirc.config.prefs.PluginPreferencesCategory;
28
-import com.dmdirc.config.prefs.PreferencesCategory;
29
-import com.dmdirc.config.prefs.PreferencesDialogModel;
30
-import com.dmdirc.config.prefs.PreferencesSetting;
31
-import com.dmdirc.config.prefs.PreferencesType;
32
-import com.dmdirc.interfaces.config.IdentityController;
33 25
 import com.dmdirc.plugins.PluginInfo;
34 26
 import com.dmdirc.plugins.implementations.BasePlugin;
35
-import com.dmdirc.util.io.Downloader;
36 27
 
37
-import java.io.File;
38
-import java.io.IOException;
39
-import java.util.HashMap;
40
-import java.util.List;
41
-import java.util.Map;
28
+import dagger.ObjectGraph;
42 29
 
43 30
 /**
44 31
  * Retrieves information from VLC using its HTTP interface.
45 32
  */
46
-public class VlcMediaSourcePlugin extends BasePlugin implements MediaSource {
33
+public class VlcMediaSourcePlugin extends BasePlugin {
47 34
 
48
-    /** The information obtained from VLC. */
49
-    private final Map<String, String> information = new HashMap<>();
50
-    /** This plugin's plugin info. */
51
-    private final PluginInfo pluginInfo;
52
-    /** The identity controller to read settings from. */
53
-    private final IdentityController identityController;
54
-    /** Downloader to download files. */
55
-    private final Downloader downloader;
56
-
57
-    public VlcMediaSourcePlugin(final PluginInfo pluginInfo,
58
-            final IdentityController identityController) {
59
-        this.pluginInfo = pluginInfo;
60
-        this.identityController = identityController;
61
-        this.downloader = new Downloader();
62
-    }
63
-
64
-    @Override
65
-    public MediaSourceState getState() {
66
-        if (fetchInformation()) {
67
-            final String output = information.get("state");
68
-            if (output.equalsIgnoreCase("stop")) {
69
-                return MediaSourceState.STOPPED;
70
-            } else if (output.equalsIgnoreCase("playing")) {
71
-                return MediaSourceState.PLAYING;
72
-            } else if (output.equalsIgnoreCase("paused")) {
73
-                return MediaSourceState.PAUSED;
74
-            } else {
75
-                return MediaSourceState.NOTKNOWN;
76
-            }
77
-        } else {
78
-            return MediaSourceState.CLOSED;
79
-        }
80
-    }
81
-
82
-    @Override
83
-    public String getAppName() {
84
-        return "VLC";
85
-    }
86
-
87
-    @Override
88
-    public String getArtist() {
89
-        return information.containsKey("artist") ? information.get("artist") : getFallbackArtist();
90
-    }
91
-
92
-    /**
93
-     * Retrieves the fallback artist (parsed from the file name).
94
-     *
95
-     * @return The fallback artist
96
-     */
97
-    private String getFallbackArtist() {
98
-        String result = "unknown";
99
-
100
-        if (information.containsKey("playlist_current")) {
101
-            try {
102
-                final int item = Integer.parseInt(information.get(
103
-                        "playlist_current"));
104
-                String[] bits = information.get("playlist_item_" + item).split(
105
-                        (File.separatorChar == '\\' ? "\\\\" : File.separator));
106
-                result = bits[bits.length - 1];
107
-                bits = result.split("-");
108
-                if (bits.length > 1) {
109
-                    result = bits[0];
110
-                } else {
111
-                    // Whole filename is the title, so no artist is known.
112
-                    result = "unknown";
113
-                }
114
-            } catch (NumberFormatException nfe) {
115
-                // DO nothing
116
-            }
117
-        }
118
-
119
-        return result;
120
-    }
35
+    private VlcManager vlcManager;
121 36
 
122 37
     @Override
123
-    public String getTitle() {
124
-        return information.containsKey("title") ? information.get("title")
125
-                : getFallbackTitle();
126
-    }
127
-
128
-    /**
129
-     * Retrieves the fallback title (parsed from the file name).
130
-     *
131
-     * @return The fallback title
132
-     */
133
-    private String getFallbackTitle() {
134
-        String result = "unknown";
135
-
136
-        // Title is unknown, lets guess using the filename
137
-        if (information.containsKey("playlist_current")) {
138
-            try {
139
-                final int item = Integer.parseInt(information.get(
140
-                        "playlist_current"));
141
-                result = information.get("playlist_item_" + item);
142
-
143
-                final int sepIndex = result.lastIndexOf(File.separatorChar);
144
-                final int extIndex = result.lastIndexOf('.');
145
-                result = result.substring(sepIndex,
146
-                        extIndex > sepIndex ? extIndex : result.length());
147
-
148
-                final int offset = result.indexOf('-');
149
-                if (offset > -1) {
150
-                    result = result.substring(offset + 1).trim();
151
-                }
152
-            } catch (NumberFormatException nfe) {
153
-                // Do nothing
154
-            }
155
-        }
38
+    public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
39
+        super.load(pluginInfo, graph);
156 40
 
157
-        return result;
158
-    }
159
-
160
-    @Override
161
-    public String getAlbum() {
162
-        return information.containsKey("album/movie/show title")
163
-                ? information.get("album/movie/show title") : "unknown";
164
-    }
165
-
166
-    @Override
167
-    public String getLength() {
168
-        // This is just seconds, could do with formatting.
169
-        return information.containsKey("length") ? information.get("length")
170
-                : "unknown";
41
+        setObjectGraph(graph.plus(new VlcModule(pluginInfo)));
42
+        vlcManager = getObjectGraph().get(VlcManager.class);
171 43
     }
172
-
173
-    @Override
174
-    public String getTime() {
175
-        // This is just seconds, could do with formatting.
176
-        return information.containsKey("time") ? information.get("time")
177
-                : "unknown";
178
-    }
179
-
180
-    @Override
181
-    public String getFormat() {
182
-        return information.containsKey("codec") ? information.get("codec")
183
-                : "unknown";
184
-    }
185
-
186
-    @Override
187
-    public String getBitrate() {
188
-        return information.containsKey("bitrate") ? information.get("bitrate")
189
-                : "unknown";
190
-    }
191
-
192
-    @Override
193
-    public void showConfig(final PreferencesDialogModel manager) {
194
-        final PreferencesCategory general = new PluginPreferencesCategory(
195
-                pluginInfo, "VLC Media Source",
196
-                "", "category-vlc");
197
-
198
-        final PreferencesSetting setting = new PreferencesSetting(
199
-                PreferencesType.LABEL, pluginInfo.getDomain(), "", "Instructions",
200
-                "Instructions", manager.getConfigManager(), manager.getIdentity());
201
-        setting.setValue("<html><p>"
202
-                + "The VLC media source requires that VLC's web interface is"
203
-                + " enabled. To do this, follow the steps below:</p>"
204
-                + "<ol style='margin-left: 20px; padding-left: 0px;'>"
205
-                + "<li>Open VLC's preferences dialog (found in the 'Tools' "
206
-                + "menu)"
207
-                + "<li>Set the 'Show settings' option to 'All'"
208
-                + "<li>Expand the 'Interface' category by clicking on the plus "
209
-                + "sign next to it"
210
-                + "<li>Select the 'Main interfaces' category"
211
-                + "<li>Check the box next to 'HTTP remote control interface'"
212
-                + "<li>Expand the 'Main interfaces' category"
213
-                + "<li>Select the 'HTTP' category"
214
-                + "<li>In the 'Host address' field, enter 'localhost:8082'"
215
-                + "<li>In the 'Source directory' field enter the path to VLC's"
216
-                + " http directory<ul style='margin-left: 5px; padding-left: "
217
-                + "0px; list-style-type: none;'>"
218
-                + "<li style='padding-bottom: 5px'>For Linux users this may be "
219
-                + "/usr/share/vlc/http/"
220
-                + "<li>For Windows users this will be under the main VLC "
221
-                + "directory, e.g. C:\\Program Files\\VLC\\http</ul><li>Click "
222
-                + "'Save'<li>Restart VLC</ol></html>");
223
-        general.addSetting(setting);
224
-        general.addSetting(new PreferencesSetting(PreferencesType.TEXT,
225
-                pluginInfo.getDomain(), "host", "Hostname and port",
226
-                "The host and port that VLC listens on for web connections",
227
-                manager.getConfigManager(), manager.getIdentity()));
228
-
229
-        manager.getCategory("Plugins").addSubCategory(general);
230
-    }
231
-
232
-    /**
233
-     * Attempts to fetch information from VLC's web interface.
234
-     *
235
-     * @return True on success, false otherwise
236
-     */
237
-    private boolean fetchInformation() {
238
-        information.clear();
239
-        final List<String> res;
240
-        final List<String> res2;
241
-
242
-        try {
243
-            final String host = identityController.getGlobalConfiguration()
244
-                    .getOption(pluginInfo.getDomain(), "host");
245
-            res = downloader.getPage("http://" + host + "/old/info.html");
246
-            res2 = downloader.getPage("http://" + host + "/old/");
247
-            parseInformation(res, res2);
248
-            return true;
249
-        } catch (IOException ex) {
250
-            return false;
251
-        }
252
-    }
253
-
254
-    /**
255
-     * Parses the information from the two pages obtained from VLC's web interface.
256
-     *
257
-     * @param res  The first page of VLC info (/old/info.html)
258
-     * @param res2 The second page of VLC info (/old/)
259
-     */
260
-    protected void parseInformation(final List<String> res,
261
-            final List<String> res2) {
262
-        for (String line : res) {
263
-            final String tline = line.trim();
264
-
265
-            if (tline.startsWith("<li>")) {
266
-                final int colon = tline.indexOf(':');
267
-                final String key = tline.substring(5, colon).trim()
268
-                        .toLowerCase();
269
-                final String value = tline.substring(colon + 1, tline.length()
270
-                        - 5).trim();
271
-
272
-                information.put(key, value);
273
-            }
274
-        }
275
-
276
-        boolean isPlaylist = false;
277
-        boolean isCurrent = false;
278
-        boolean isItem = false;
279
-        int playlistItem = 0;
280
-        for (String line : res2) {
281
-            final String tline = line.trim();
282
-
283
-            if (isPlaylist) {
284
-                if (tline.startsWith("</ul>")) {
285
-                    isPlaylist = false;
286
-                    information.put("playlist_items", Integer.toString(
287
-                            playlistItem));
288
-                } else if (tline.equalsIgnoreCase("<strong>")) {
289
-                    isCurrent = true;
290
-                } else if (tline.equalsIgnoreCase("</strong>")) {
291
-                    isCurrent = false;
292
-                } else if (tline.startsWith("<a href=\"?control=play&amp")) {
293
-                    isItem = true;
294
-                } else if (isItem) {
295
-                    String itemname = tline;
296
-                    if (itemname.endsWith("</a>")) {
297
-                        itemname = itemname.substring(0, itemname.length() - 4);
298
-                    }
299
-                    if (!itemname.isEmpty()) {
300
-                        if (isCurrent) {
301
-                            information.put("playlist_current", Integer
302
-                                    .toString(playlistItem));
303
-                        }
304
-                        information.put("playlist_item_" + Integer.toString(
305
-                                playlistItem++), itemname);
306
-                    }
307
-                    isItem = false;
308
-                }
309
-            } else if (tline.equalsIgnoreCase("<!-- Playlist -->")) {
310
-                isPlaylist = true;
311
-            } else if (tline.startsWith("State:")) {
312
-                information.put("state", tline.substring(6, tline.indexOf('<'))
313
-                        .trim());
314
-            } else if (tline.startsWith("got_")) {
315
-                final int equals = tline.indexOf('=');
316
-
317
-                information.put(tline.substring(4, equals).trim(),
318
-                        tline.substring(equals + 1, tline.length() - 1).trim());
319
-            }
320
-        }
321
-    }
322
-
323 44
 }

+ 46
- 0
mediasource_vlc/src/com/dmdirc/addons/mediasource_vlc/VlcModule.java Datei anzeigen

@@ -0,0 +1,46 @@
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.mediasource_vlc;
24
+
25
+import com.dmdirc.ClientModule;
26
+import com.dmdirc.plugins.PluginDomain;
27
+import com.dmdirc.plugins.PluginInfo;
28
+
29
+import dagger.Module;
30
+import dagger.Provides;
31
+
32
+@Module(injects = VlcManager.class, addsTo = ClientModule.class)
33
+public class VlcModule {
34
+
35
+    private final PluginInfo pluginInfo;
36
+
37
+    public VlcModule(final PluginInfo pluginInfo) {
38
+        this.pluginInfo = pluginInfo;
39
+    }
40
+
41
+    @Provides
42
+    @PluginDomain(VlcMediaSourcePlugin.class)
43
+    public PluginInfo getPluginInfo() {
44
+        return pluginInfo;
45
+    }
46
+}

+ 68
- 0
nma/src/com/dmdirc/addons/nma/NotifyMyAndroidManager.java Datei anzeigen

@@ -0,0 +1,68 @@
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.nma;
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.events.ClientPrefsOpenedEvent;
31
+import com.dmdirc.plugins.PluginDomain;
32
+import com.dmdirc.plugins.PluginInfo;
33
+
34
+import javax.inject.Inject;
35
+
36
+import net.engio.mbassy.listener.Handler;
37
+
38
+public class NotifyMyAndroidManager {
39
+
40
+    private final PluginInfo pluginInfo;
41
+
42
+    @Inject
43
+    public NotifyMyAndroidManager(
44
+            @PluginDomain(NotifyMyAndroidPlugin.class)final PluginInfo pluginInfo) {
45
+        this.pluginInfo = pluginInfo;
46
+    }
47
+
48
+    @Handler
49
+    public void showConfig(final ClientPrefsOpenedEvent event) {
50
+        final PreferencesDialogModel manager = event.getModel();
51
+        final PreferencesCategory category = new PluginPreferencesCategory(
52
+                pluginInfo, "Notify My Android",
53
+                "General configuration for Notify My Android plugin.");
54
+
55
+        category.addSetting(new PreferencesSetting(
56
+                PreferencesType.TEXT, pluginInfo.getDomain(), "apikey",
57
+                "API Key", "Comma-separated list of NotifyMyAndroid API keys"
58
+                + " to be notified when the command is used.",
59
+                manager.getConfigManager(), manager.getIdentity()));
60
+        category.addSetting(new PreferencesSetting(
61
+                PreferencesType.TEXT, pluginInfo.getDomain(), "application",
62
+                "Application", "Name of the application to report to "
63
+                + "NotifyMyAndroid",
64
+                manager.getConfigManager(), manager.getIdentity()));
65
+
66
+        manager.getCategory("Plugins").addSubCategory(category);
67
+    }
68
+}

+ 8
- 1
nma/src/com/dmdirc/addons/nma/NotifyMyAndroidModule.java Datei anzeigen

@@ -29,7 +29,8 @@ import com.dmdirc.plugins.PluginInfo;
29 29
 import dagger.Module;
30 30
 import dagger.Provides;
31 31
 
32
-@Module(injects = NotifyMyAndroidCommand.class, addsTo = ClientModule.class)
32
+@Module(injects = {NotifyMyAndroidManager.class, NotifyMyAndroidCommand.class},
33
+        addsTo = ClientModule.class)
33 34
 public class NotifyMyAndroidModule {
34 35
 
35 36
     private final PluginInfo pluginInfo;
@@ -44,4 +45,10 @@ public class NotifyMyAndroidModule {
44 45
         return pluginInfo.getDomain();
45 46
     }
46 47
 
48
+    @Provides
49
+    @PluginDomain(NotifyMyAndroidPlugin.class)
50
+    public PluginInfo getPluginInfo() {
51
+        return pluginInfo;
52
+    }
53
+
47 54
 }

+ 2
- 36
nma/src/com/dmdirc/addons/nma/NotifyMyAndroidPlugin.java Datei anzeigen

@@ -22,11 +22,6 @@
22 22
 
23 23
 package com.dmdirc.addons.nma;
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 25
 import com.dmdirc.plugins.PluginInfo;
31 26
 import com.dmdirc.plugins.implementations.BaseCommandPlugin;
32 27
 
@@ -37,42 +32,13 @@ import dagger.ObjectGraph;
37 32
  */
38 33
 public class NotifyMyAndroidPlugin extends BaseCommandPlugin {
39 34
 
40
-    /** Our info object. */
41
-    private final PluginInfo pluginInfo;
42
-
43
-    /**
44
-     * Creates a new instance of the {@link NotifyMyAndroidPlugin}.
45
-     *
46
-     * @param pluginInfo The plugin info object for this plugin.
47
-     */
48
-    public NotifyMyAndroidPlugin(final PluginInfo pluginInfo) {
49
-        this.pluginInfo = pluginInfo;
50
-    }
35
+    private NotifyMyAndroidManager notifyMyAndroidManager;
51 36
 
52 37
     @Override
53 38
     public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
54 39
         super.load(pluginInfo, graph);
55 40
         setObjectGraph(graph.plus(new NotifyMyAndroidModule(pluginInfo)));
56
-    }
57
-
58
-    @Override
59
-    public void showConfig(final PreferencesDialogModel manager) {
60
-        final PreferencesCategory category = new PluginPreferencesCategory(
61
-                pluginInfo, "Notify My Android",
62
-                "General configuration for Notify My Android plugin.");
63
-
64
-        category.addSetting(new PreferencesSetting(
65
-                PreferencesType.TEXT, pluginInfo.getDomain(), "apikey",
66
-                "API Key", "Comma-separated list of NotifyMyAndroid API keys"
67
-                + " to be notified when the command is used.",
68
-                manager.getConfigManager(), manager.getIdentity()));
69
-        category.addSetting(new PreferencesSetting(
70
-                PreferencesType.TEXT, pluginInfo.getDomain(), "application",
71
-                "Application", "Name of the application to report to "
72
-                + "NotifyMyAndroid",
73
-                manager.getConfigManager(), manager.getIdentity()));
74
-
75
-        manager.getCategory("Plugins").addSubCategory(category);
41
+        notifyMyAndroidManager = getObjectGraph().get(NotifyMyAndroidManager.class);
76 42
     }
77 43
 
78 44
 }

+ 22
- 0
notifications/src/com/dmdirc/addons/notifications/NotificationsManager.java Datei anzeigen

@@ -24,6 +24,11 @@ package com.dmdirc.addons.notifications;
24 24
 
25 25
 import com.dmdirc.ClientModule.GlobalConfig;
26 26
 import com.dmdirc.DMDircMBassador;
27
+import com.dmdirc.addons.ui_swing.UIUtilities;
28
+import com.dmdirc.config.prefs.PluginPreferencesCategory;
29
+import com.dmdirc.config.prefs.PreferencesCategory;
30
+import com.dmdirc.config.prefs.PreferencesDialogModel;
31
+import com.dmdirc.events.ClientPrefsOpenedEvent;
27 32
 import com.dmdirc.events.PluginLoadedEvent;
28 33
 import com.dmdirc.events.PluginUnloadedEvent;
29 34
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
@@ -47,6 +52,7 @@ public class NotificationsManager {
47 52
     private List<String> order;
48 53
     /** This plugin's settings domain. */
49 54
     private final String domain;
55
+    private final PluginInfo pluginInfo;
50 56
     /** Global config to read settings from. */
51 57
     private final AggregateConfigProvider globalConfig;
52 58
     /** Plugin manager. */
@@ -56,9 +62,11 @@ public class NotificationsManager {
56 62
 
57 63
     @Inject
58 64
     public NotificationsManager(@PluginDomain(NotificationsPlugin.class) final String domain,
65
+            @PluginDomain(NotificationsPlugin.class) final PluginInfo pluginInfo,
59 66
             @GlobalConfig final AggregateConfigProvider globalConfig, final DMDircMBassador eventBus,
60 67
             final PluginManager pluginManager) {
61 68
         this.domain = domain;
69
+        this.pluginInfo = pluginInfo;
62 70
         this.globalConfig = globalConfig;
63 71
         this.pluginManager = pluginManager;
64 72
         this.eventBus = eventBus;
@@ -182,4 +190,18 @@ public class NotificationsManager {
182 190
         return null;
183 191
     }
184 192
 
193
+    @Handler
194
+    public void showConfig(final ClientPrefsOpenedEvent event) {
195
+        final PreferencesDialogModel manager = event.getModel();
196
+        final NotificationConfig configPanel = UIUtilities.invokeAndWait(
197
+                () -> new NotificationConfig(manager.getIdentity(), pluginInfo.getDomain(),
198
+                        manager.getConfigManager()
199
+                                .getOptionList(pluginInfo.getDomain(), "methodOrder")));
200
+
201
+        final PreferencesCategory category = new PluginPreferencesCategory(
202
+                pluginInfo, "Notifications", "", "category-notifications",
203
+                configPanel);
204
+        manager.getCategory("Plugins").addSubCategory(category);
205
+    }
206
+
185 207
 }

+ 6
- 0
notifications/src/com/dmdirc/addons/notifications/NotificationsModule.java Datei anzeigen

@@ -45,4 +45,10 @@ public class NotificationsModule {
45 45
         return pluginInfo.getDomain();
46 46
     }
47 47
 
48
+    @Provides
49
+    @PluginDomain(NotificationsPlugin.class)
50
+    public PluginInfo getPluginInfo() {
51
+        return pluginInfo;
52
+    }
53
+
48 54
 }

+ 0
- 29
notifications/src/com/dmdirc/addons/notifications/NotificationsPlugin.java Datei anzeigen

@@ -22,10 +22,6 @@
22 22
 
23 23
 package com.dmdirc.addons.notifications;
24 24
 
25
-import com.dmdirc.addons.ui_swing.UIUtilities;
26
-import com.dmdirc.config.prefs.PluginPreferencesCategory;
27
-import com.dmdirc.config.prefs.PreferencesCategory;
28
-import com.dmdirc.config.prefs.PreferencesDialogModel;
29 25
 import com.dmdirc.plugins.PluginInfo;
30 26
 import com.dmdirc.plugins.implementations.BaseCommandPlugin;
31 27
 
@@ -36,21 +32,9 @@ import dagger.ObjectGraph;
36 32
  */
37 33
 public class NotificationsPlugin extends BaseCommandPlugin {
38 34
 
39
-    /** This plugin's plugin info. */
40
-    private final PluginInfo pluginInfo;
41 35
     /** Notifications manager. */
42 36
     private NotificationsManager manager;
43 37
 
44
-    /**
45
-     * Creates a new instance of this plugin.
46
-     *
47
-     * @param pluginInfo This plugin's plugin info
48
-     */
49
-    public NotificationsPlugin(final PluginInfo pluginInfo) {
50
-        this.pluginInfo = pluginInfo;
51
-
52
-    }
53
-
54 38
     @Override
55 39
     public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
56 40
         super.load(pluginInfo, graph);
@@ -71,17 +55,4 @@ public class NotificationsPlugin extends BaseCommandPlugin {
71 55
         super.onUnload();
72 56
     }
73 57
 
74
-    @Override
75
-    public void showConfig(final PreferencesDialogModel manager) {
76
-        final NotificationConfig configPanel = UIUtilities.invokeAndWait(
77
-                () -> new NotificationConfig(manager.getIdentity(), pluginInfo.getDomain(),
78
-                        manager.getConfigManager().getOptionList(pluginInfo.getDomain(),
79
-                                "methodOrder")));
80
-
81
-        final PreferencesCategory category = new PluginPreferencesCategory(
82
-                pluginInfo, "Notifications", "", "category-notifications",
83
-                configPanel);
84
-        manager.getCategory("Plugins").addSubCategory(category);
85
-    }
86
-
87 58
 }

+ 22
- 1
nowplaying/src/com/dmdirc/addons/nowplaying/NowPlayingManager.java Datei anzeigen

@@ -24,6 +24,11 @@ package com.dmdirc.addons.nowplaying;
24 24
 
25 25
 import com.dmdirc.ClientModule.GlobalConfig;
26 26
 import com.dmdirc.DMDircMBassador;
27
+import com.dmdirc.addons.ui_swing.UIUtilities;
28
+import com.dmdirc.config.prefs.PluginPreferencesCategory;
29
+import com.dmdirc.config.prefs.PreferencesCategory;
30
+import com.dmdirc.config.prefs.PreferencesDialogModel;
31
+import com.dmdirc.events.ClientPrefsOpenedEvent;
27 32
 import com.dmdirc.events.PluginLoadedEvent;
28 33
 import com.dmdirc.events.PluginUnloadedEvent;
29 34
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
@@ -49,6 +54,7 @@ public class NowPlayingManager {
49 54
     private final AggregateConfigProvider globalConfig;
50 55
     /** Event bus to subscribe to events on. */
51 56
     private final DMDircMBassador eventBus;
57
+    private final PluginInfo pluginInfo;
52 58
     /** This plugin's settings domain. */
53 59
     private final String domain;
54 60
     /** The sources that we know of. */
@@ -61,11 +67,13 @@ public class NowPlayingManager {
61 67
     @Inject
62 68
     public NowPlayingManager(final PluginManager pluginManager, final DMDircMBassador eventBus,
63 69
             @GlobalConfig final AggregateConfigProvider globalConfig,
64
-            @PluginDomain(NowPlayingPlugin.class) final String domain) {
70
+            @PluginDomain(NowPlayingPlugin.class) final String domain,
71
+            @PluginDomain(NowPlayingPlugin.class) final PluginInfo pluginInfo) {
65 72
         this.pluginManager = pluginManager;
66 73
         this.globalConfig = globalConfig;
67 74
         this.domain = domain;
68 75
         this.eventBus = eventBus;
76
+        this.pluginInfo = pluginInfo;
69 77
     }
70 78
 
71 79
     /**
@@ -284,4 +292,17 @@ public class NowPlayingManager {
284 292
         return res;
285 293
     }
286 294
 
295
+    @Handler
296
+    public void showConfig(final ClientPrefsOpenedEvent event) {
297
+        final PreferencesDialogModel manager = event.getModel();
298
+        final ConfigPanel configPanel = UIUtilities.invokeAndWait(
299
+                () -> new ConfigPanel(this, manager.getConfigManager(),
300
+                        manager.getIdentity(), domain, getSettings()));
301
+
302
+        final PreferencesCategory category = new PluginPreferencesCategory(
303
+                pluginInfo, "Now Playing",
304
+                "", "category-nowplaying", configPanel);
305
+        manager.getCategory("Plugins").addSubCategory(category);
306
+    }
307
+
287 308
 }

+ 6
- 0
nowplaying/src/com/dmdirc/addons/nowplaying/NowPlayingModule.java Datei anzeigen

@@ -44,4 +44,10 @@ public class NowPlayingModule {
44 44
         return pluginInfo.getDomain();
45 45
     }
46 46
 
47
+    @Provides
48
+    @PluginDomain(NowPlayingPlugin.class)
49
+    public PluginInfo getPluginInfo() {
50
+        return pluginInfo;
51
+    }
52
+
47 53
 }

+ 0
- 31
nowplaying/src/com/dmdirc/addons/nowplaying/NowPlayingPlugin.java Datei anzeigen

@@ -22,10 +22,6 @@
22 22
 
23 23
 package com.dmdirc.addons.nowplaying;
24 24
 
25
-import com.dmdirc.addons.ui_swing.UIUtilities;
26
-import com.dmdirc.config.prefs.PluginPreferencesCategory;
27
-import com.dmdirc.config.prefs.PreferencesCategory;
28
-import com.dmdirc.config.prefs.PreferencesDialogModel;
29 25
 import com.dmdirc.plugins.PluginInfo;
30 26
 import com.dmdirc.plugins.implementations.BaseCommandPlugin;
31 27
 
@@ -36,23 +32,9 @@ import dagger.ObjectGraph;
36 32
  */
37 33
 public class NowPlayingPlugin extends BaseCommandPlugin {
38 34
 
39
-    /** This plugin's plugin info. */
40
-    private final PluginInfo pluginInfo;
41
-    /** This plugin's settings domain. */
42
-    private final String domain;
43 35
     /** Now playing manager. */
44 36
     private NowPlayingManager nowplayingmanager;
45 37
 
46
-    /**
47
-     * Creates a new instance of this plugin.
48
-     *
49
-     * @param pluginInfo This plugin's plugin info
50
-     */
51
-    public NowPlayingPlugin(final PluginInfo pluginInfo) {
52
-        this.pluginInfo = pluginInfo;
53
-        this.domain = pluginInfo.getDomain();
54
-    }
55
-
56 38
     @Override
57 39
     public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
58 40
         super.load(pluginInfo, graph);
@@ -73,17 +55,4 @@ public class NowPlayingPlugin extends BaseCommandPlugin {
73 55
         nowplayingmanager.onUnload();
74 56
     }
75 57
 
76
-    @Override
77
-    public void showConfig(final PreferencesDialogModel manager) {
78
-        final ConfigPanel configPanel = UIUtilities.invokeAndWait(
79
-                () -> new ConfigPanel(nowplayingmanager, manager.getConfigManager(),
80
-                        manager.getIdentity(), domain,
81
-                        nowplayingmanager.getSettings()));
82
-
83
-        final PreferencesCategory category = new PluginPreferencesCategory(
84
-                pluginInfo, "Now Playing",
85
-                "", "category-nowplaying", configPanel);
86
-        manager.getCategory("Plugins").addSubCategory(category);
87
-    }
88
-
89 58
 }

Laden…
Abbrechen
Speichern