You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FreeDesktopNotificationsPlugin.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright (c) 2006-2014 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. package com.dmdirc.addons.freedesktop_notifications;
  23. import com.dmdirc.config.prefs.PluginPreferencesCategory;
  24. import com.dmdirc.config.prefs.PreferencesCategory;
  25. import com.dmdirc.config.prefs.PreferencesDialogModel;
  26. import com.dmdirc.config.prefs.PreferencesSetting;
  27. import com.dmdirc.config.prefs.PreferencesType;
  28. import com.dmdirc.plugins.Exported;
  29. import com.dmdirc.plugins.PluginInfo;
  30. import com.dmdirc.plugins.implementations.BaseCommandPlugin;
  31. import dagger.ObjectGraph;
  32. /**
  33. * This plugin adds freedesktop Style Notifications to dmdirc.
  34. */
  35. public class FreeDesktopNotificationsPlugin extends BaseCommandPlugin {
  36. /** This plugin's plugin info. */
  37. private final PluginInfo pluginInfo;
  38. /** Manager to show notifications. */
  39. private FDManager manager;
  40. public FreeDesktopNotificationsPlugin(final PluginInfo pluginInfo) {
  41. this.pluginInfo = pluginInfo;
  42. }
  43. @Override
  44. public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
  45. super.load(pluginInfo, graph);
  46. setObjectGraph(graph.plus(new FDModule(pluginInfo)));
  47. registerCommand(FDNotifyCommand.class, FDNotifyCommand.INFO);
  48. manager = getObjectGraph().get(FDManager.class);
  49. }
  50. /**
  51. * Used to show a notification using this plugin.
  52. *
  53. * @param title Title of dialog if applicable
  54. * @param message Message to show
  55. *
  56. * @return True if the notification was shown.
  57. */
  58. @Exported
  59. public boolean showNotification(final String title, final String message) {
  60. return manager.showNotification(title, message);
  61. }
  62. /**
  63. * Called when the plugin is loaded.
  64. */
  65. @Override
  66. public void onLoad() {
  67. manager.onLoad();
  68. super.onLoad();
  69. }
  70. /**
  71. * Called when this plugin is Unloaded.
  72. */
  73. @Override
  74. public synchronized void onUnload() {
  75. manager.onUnLoad();
  76. super.onUnload();
  77. }
  78. @Override
  79. public void showConfig(final PreferencesDialogModel manager) {
  80. final PreferencesCategory general = new PluginPreferencesCategory(
  81. pluginInfo, "FreeDesktop Notifications",
  82. "General configuration for FreeDesktop Notifications plugin.");
  83. general.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
  84. pluginInfo.getDomain(), "general.timeout", "Timeout",
  85. "Length of time in seconds before the notification popup closes.",
  86. manager.getConfigManager(), manager.getIdentity()));
  87. general.addSetting(new PreferencesSetting(PreferencesType.FILE,
  88. pluginInfo.getDomain(), "general.icon", "icon",
  89. "Path to icon to use on the notification.",
  90. manager.getConfigManager(), manager.getIdentity()));
  91. general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  92. pluginInfo.getDomain(), "advanced.escapehtml", "Escape HTML",
  93. "Some Implementations randomly parse HTML, escape it before showing?",
  94. manager.getConfigManager(), manager.getIdentity()));
  95. general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  96. pluginInfo.getDomain(), "advanced.strictescape", "Strict Escape HTML",
  97. "Strictly escape HTML or just the basic characters? (&, < and >)",
  98. manager.getConfigManager(), manager.getIdentity()));
  99. general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  100. pluginInfo.getDomain(), "advanced.stripcodes", "Strip Control Codes",
  101. "Strip IRC Control codes from messages?",
  102. manager.getConfigManager(), manager.getIdentity()));
  103. manager.getCategory("Plugins").addSubCategory(general);
  104. }
  105. }