|
@@ -35,12 +35,10 @@ import com.dmdirc.interfaces.ConfigChangeListener;
|
35
|
35
|
import com.dmdirc.logger.ErrorLevel;
|
36
|
36
|
import com.dmdirc.logger.Logger;
|
37
|
37
|
import com.dmdirc.plugins.PluginInfo;
|
38
|
|
-import com.dmdirc.plugins.PluginManager;
|
39
|
38
|
import com.dmdirc.plugins.implementations.BaseCommandPlugin;
|
40
|
39
|
import com.dmdirc.plugins.implementations.PluginFilesHelper;
|
41
|
40
|
import com.dmdirc.ui.messages.Styliser;
|
42
|
41
|
import com.dmdirc.util.io.StreamReader;
|
43
|
|
-import com.dmdirc.util.resourcemanager.ResourceManager;
|
44
|
42
|
|
45
|
43
|
import java.io.IOException;
|
46
|
44
|
import java.util.ArrayList;
|
|
@@ -69,8 +67,6 @@ public final class FreeDesktopNotificationsPlugin
|
69
|
67
|
private final ConfigManager config;
|
70
|
68
|
/** Addon identity. */
|
71
|
69
|
private final Identity identity;
|
72
|
|
- /** Plugin manager instance. */
|
73
|
|
- private final PluginManager pluginManager;
|
74
|
70
|
/** Plugin files helper. */
|
75
|
71
|
private final PluginFilesHelper filesHelper;
|
76
|
72
|
|
|
@@ -79,17 +75,14 @@ public final class FreeDesktopNotificationsPlugin
|
79
|
75
|
*
|
80
|
76
|
* @param pluginInfo This plugin's plugin info
|
81
|
77
|
* @param identityManager Identity Manager instance
|
82
|
|
- * @param pluginManager Plugin manager
|
83
|
78
|
* @param commandController Command controller to register commands
|
84
|
79
|
*/
|
85
|
80
|
public FreeDesktopNotificationsPlugin(final PluginInfo pluginInfo,
|
86
|
81
|
final IdentityManager identityManager,
|
87
|
|
- final PluginManager pluginManager,
|
88
|
82
|
final CommandController commandController) {
|
89
|
83
|
super(commandController);
|
90
|
84
|
this.pluginInfo = pluginInfo;
|
91
|
|
- this.pluginManager = pluginManager;
|
92
|
|
- this.filesHelper = new PluginFilesHelper(pluginInfo.getMetaData());
|
|
85
|
+ this.filesHelper = new PluginFilesHelper(pluginInfo);
|
93
|
86
|
config = identityManager.getGlobalConfiguration();
|
94
|
87
|
identity = identityManager.getGlobalAddonIdentity();
|
95
|
88
|
registerCommand(new FDNotifyCommand(this), FDNotifyCommand.INFO);
|
|
@@ -103,7 +96,9 @@ public final class FreeDesktopNotificationsPlugin
|
103
|
96
|
* @return True if the notification was shown.
|
104
|
97
|
*/
|
105
|
98
|
public boolean showNotification(final String title, final String message) {
|
106
|
|
- if (filesHelper.getFilesDir() == null) { return false; }
|
|
99
|
+ if (filesHelper.getFilesDir() == null) {
|
|
100
|
+ return false;
|
|
101
|
+ }
|
107
|
102
|
|
108
|
103
|
final ArrayList<String> args = new ArrayList<String>();
|
109
|
104
|
|
|
@@ -130,7 +125,10 @@ public final class FreeDesktopNotificationsPlugin
|
130
|
125
|
final StringBuffer data = new StringBuffer();
|
131
|
126
|
new StreamReader(myProcess.getErrorStream()).start();
|
132
|
127
|
new StreamReader(myProcess.getInputStream(), data).start();
|
133
|
|
- try { myProcess.waitFor(); } catch (InterruptedException e) { }
|
|
128
|
+ try {
|
|
129
|
+ myProcess.waitFor();
|
|
130
|
+ } catch (InterruptedException e) {
|
|
131
|
+ }
|
134
|
132
|
return true;
|
135
|
133
|
} catch (SecurityException e) {
|
136
|
134
|
} catch (IOException e) {
|
|
@@ -147,7 +145,9 @@ public final class FreeDesktopNotificationsPlugin
|
147
|
145
|
*/
|
148
|
146
|
public String prepareString(final String input) {
|
149
|
147
|
String output = input;
|
150
|
|
- if (stripcodes) { output = Styliser.stipControlCodes(output); }
|
|
148
|
+ if (stripcodes) {
|
|
149
|
+ output = Styliser.stipControlCodes(output);
|
|
150
|
+ }
|
151
|
151
|
if (escapehtml) {
|
152
|
152
|
if (strictescape) {
|
153
|
153
|
output = StringEscapeUtils.escapeHtml(output);
|
|
@@ -168,26 +168,12 @@ public final class FreeDesktopNotificationsPlugin
|
168
|
168
|
public void onLoad() {
|
169
|
169
|
config.addChangeListener(getDomain(), this);
|
170
|
170
|
setCachedSettings();
|
171
|
|
-
|
172
|
|
- // Extract required Files
|
173
|
|
- final PluginInfo pi = pluginManager.getPluginInfoByName("freedesktop_notifications");
|
174
|
|
-
|
175
|
|
- // This shouldn't actually happen, but check to make sure.
|
176
|
|
- if (pi != null) {
|
177
|
|
- // Now get the RM
|
178
|
|
- try {
|
179
|
|
- final ResourceManager res = pi.getResourceManager();
|
180
|
|
-
|
181
|
|
- // Extract the files needed
|
182
|
|
- try {
|
183
|
|
- res.extractResoucesEndingWith(filesHelper.getFilesDir(), ".py");
|
184
|
|
- res.extractResoucesEndingWith(filesHelper.getFilesDir(), ".png");
|
185
|
|
- } catch (IOException ex) {
|
186
|
|
- Logger.userError(ErrorLevel.MEDIUM, "Unable to extract files for Free desktop notifications: " + ex.getMessage(), ex);
|
187
|
|
- }
|
188
|
|
- } catch (IOException ioe) {
|
189
|
|
- Logger.userError(ErrorLevel.LOW, "Unable to open ResourceManager for freedesktop_notifications: "+ioe.getMessage(), ioe);
|
190
|
|
- }
|
|
171
|
+ // Extract the files needed
|
|
172
|
+ try {
|
|
173
|
+ filesHelper.extractResoucesEndingWith(".py");
|
|
174
|
+ filesHelper.extractResoucesEndingWith(".png");
|
|
175
|
+ } catch (IOException ex) {
|
|
176
|
+ Logger.userError(ErrorLevel.MEDIUM, "Unable to extract files for Free desktop notifications: " + ex.getMessage(), ex);
|
191
|
177
|
}
|
192
|
178
|
super.onLoad();
|
193
|
179
|
}
|
|
@@ -242,7 +228,7 @@ public final class FreeDesktopNotificationsPlugin
|
242
|
228
|
private void setCachedSettings() {
|
243
|
229
|
timeout = config.getOptionInt(getDomain(), "general.timeout");
|
244
|
230
|
icon = config.getOption(getDomain(), "general.icon");
|
245
|
|
- escapehtml = config.getOptionBool( getDomain(), "advanced.escapehtml");
|
|
231
|
+ escapehtml = config.getOptionBool(getDomain(), "advanced.escapehtml");
|
246
|
232
|
strictescape = config.getOptionBool(getDomain(), "advanced.strictescape");
|
247
|
233
|
stripcodes = config.getOptionBool(getDomain(), "advanced.stripcodes");
|
248
|
234
|
}
|
|
@@ -253,4 +239,3 @@ public final class FreeDesktopNotificationsPlugin
|
253
|
239
|
setCachedSettings();
|
254
|
240
|
}
|
255
|
241
|
}
|
256
|
|
-
|