Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

SystrayPlugin.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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.systray;
  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 com.dmdirc.util.validators.ValidationResponse;
  32. import java.awt.SystemTray;
  33. import dagger.ObjectGraph;
  34. /**
  35. * The Systray plugin shows DMDirc in the user's system tray, and allows notifications to be
  36. * disabled.
  37. */
  38. public class SystrayPlugin extends BaseCommandPlugin {
  39. /** This plugin's plugin info. */
  40. private final PluginInfo pluginInfo;
  41. /** Systray manager. */
  42. private SystrayManager manager;
  43. /**
  44. * Creates a new system tray plugin.
  45. *
  46. * @param pluginInfo This plugin's plugin info.
  47. */
  48. public SystrayPlugin(final PluginInfo pluginInfo) {
  49. this.pluginInfo = pluginInfo;
  50. }
  51. @Override
  52. public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
  53. super.load(pluginInfo, graph);
  54. setObjectGraph(graph.plus(new SystrayModule(pluginInfo)));
  55. registerCommand(PopupCommand.class, PopupCommand.INFO);
  56. manager = getObjectGraph().get(SystrayManager.class);
  57. }
  58. /**
  59. * Proxy method for notify, this method is used for the exported command to avoid ambiguity when
  60. * performing reflection.
  61. *
  62. * @param title Title for the notification
  63. * @param message Text for the notification
  64. */
  65. @Exported
  66. public void showPopup(final String title, final String message) {
  67. manager.notify(title, message);
  68. }
  69. @Override
  70. public ValidationResponse checkPrerequisites() {
  71. if (SystemTray.isSupported()) {
  72. return new ValidationResponse();
  73. } else {
  74. return new ValidationResponse("System tray is not supported on "
  75. + "this platform.");
  76. }
  77. }
  78. @Override
  79. public void onLoad() {
  80. manager.load();
  81. super.onLoad();
  82. }
  83. @Override
  84. public void onUnload() {
  85. manager.unload();
  86. super.onUnload();
  87. }
  88. @Override
  89. public void showConfig(final PreferencesDialogModel manager) {
  90. final PreferencesCategory category = new PluginPreferencesCategory(
  91. pluginInfo, "System Tray",
  92. "General configuration settings");
  93. category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  94. pluginInfo.getDomain(), "autominimise", "Auto-hide DMDirc when minimised",
  95. "If this option is enabled, the systray plugin will hide DMDirc"
  96. + " to the system tray whenever DMDirc is minimised",
  97. manager.getConfigManager(), manager.getIdentity()));
  98. manager.getCategory("Plugins").addSubCategory(category);
  99. }
  100. }