Procházet zdrojové kódy

Adds --timeout parameter to /osd command

Fixes issue CLIENT-49

Change-Id: If8c57a5270e08a7c7eaa330b836f34c5361454c7
Reviewed-on: http://gerrit.dmdirc.com/1620
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.6.5
Simon Mott před 13 roky
rodič
revize
a6a808177e

+ 25
- 4
src/com/dmdirc/addons/osd/OsdCommand.java Zobrazit soubor

@@ -56,12 +56,14 @@ public final class OsdCommand extends Command implements
56 56
     /**
57 57
      * Used to show a notification using this plugin.
58 58
      *
59
+     * @param timeout Timeout for the OSD window. If negative then the value
60
+     * from the config will be used
59 61
      * @param title Title of dialog if applicable
60 62
      * @param message Message to show
61 63
      * @return True if the notification was shown.
62 64
      */
63
-    public boolean showOSD(final String title, final String message) {
64
-        osdManager.showWindow(Styliser.stipControlCodes(message));
65
+    public boolean showOSD(final int timeout, final String title, final String message) {
66
+        osdManager.showWindow(timeout, Styliser.stipControlCodes(message));
65 67
         return true;
66 68
     }
67 69
 
@@ -72,8 +74,26 @@ public final class OsdCommand extends Command implements
72 74
         if (args.getArguments().length > 0
73 75
                 && "--close".equalsIgnoreCase(args.getArguments()[0])) {
74 76
             osdManager.closeAll();
77
+        } else if (args.getArguments().length > 0
78
+                && "--timeout".equalsIgnoreCase(args.getArguments()[0])) {
79
+            if (args.getArguments().length < 2) {
80
+                sendLine(origin, args.isSilent(), FORMAT_ERROR, "You " +
81
+                        "must specify a valid number for the OSD timeout.");
82
+                return;
83
+            }
84
+
85
+            int timeout = 0;
86
+            try {
87
+                timeout = Integer.parseInt(args.getArguments()[1]);
88
+            } catch (NumberFormatException ex) {
89
+                sendLine(origin, args.isSilent(), FORMAT_ERROR, "You " +
90
+                        "must specify a valid number for the OSD timeout.");
91
+                return;
92
+            }
93
+
94
+            showOSD(timeout, null, args.getArgumentsAsString(2));
75 95
         } else {
76
-            showOSD(null, args.getArgumentsAsString());
96
+            showOSD(-1 , null, args.getArgumentsAsString());
77 97
         }
78 98
     }
79 99
     
@@ -99,7 +119,8 @@ public final class OsdCommand extends Command implements
99 119
     @Override
100 120
     public String getHelp() {
101 121
         return "osd --close - closes all OSD windows\n" +
102
-                "osd <message> - show the specified message in an OSD window";
122
+                "osd [--timer <delay in seconds>] <message> - show the specified" +
123
+                " message in an OSD window";
103 124
     }
104 125
 
105 126
     /** {@inheritDoc} */

+ 7
- 7
src/com/dmdirc/addons/osd/OsdManager.java Zobrazit soubor

@@ -43,7 +43,7 @@ public class OsdManager {
43 43
     /** List of OSD Windows. */
44 44
     private final List<OsdWindow> windowList = new ArrayList<OsdWindow>();
45 45
     /** List of messages to be queued. */
46
-    private final Queue<String> windowQueue = new LinkedList<String>();
46
+    private final Queue<QueuedMessage> windowQueue = new LinkedList<QueuedMessage>();
47 47
 
48 48
     /**
49 49
      * Create a new OSD Manager.
@@ -59,8 +59,8 @@ public class OsdManager {
59 59
      *
60 60
      * @param message Message to be displayed.
61 61
      */
62
-    public void showWindow(final String message) {
63
-        windowQueue.add(message);
62
+    public void showWindow(final int timeout, final String message) {
63
+        windowQueue.add(new QueuedMessage(timeout, message));
64 64
         displayWindows();
65 65
     }
66 66
 
@@ -71,11 +71,11 @@ public class OsdManager {
71 71
         final Integer maxWindows = IdentityManager.getGlobalConfig().
72 72
                 getOptionInt(plugin.getDomain(), "maxWindows", false);
73 73
 
74
-        String nextItem;
74
+        QueuedMessage nextItem;
75 75
 
76 76
         while ((maxWindows == null || getWindowCount() < maxWindows)
77 77
                 && (nextItem = windowQueue.poll()) != null) {
78
-            displayWindow(nextItem);
78
+            displayWindow(nextItem.getTimeout(), nextItem.getMessage());
79 79
         }
80 80
     }
81 81
 
@@ -90,7 +90,7 @@ public class OsdManager {
90 90
      * @see OsdPolicy#getYPosition(com.dmdirc.addons.osd.OsdManager, int)
91 91
      * @param message Text to display in the OSD window.
92 92
      */
93
-    private synchronized void displayWindow(final String message) {
93
+    private synchronized void displayWindow(final int timeout, final String message) {
94 94
         final OsdPolicy policy = OsdPolicy.valueOf(IdentityManager.
95 95
                 getGlobalConfig().getOption(plugin.getDomain(), "newbehaviour").
96 96
                 toUpperCase());
@@ -103,7 +103,7 @@ public class OsdManager {
103 103
             /** {@inheritDoc} */
104 104
             @Override
105 105
             public void run() {
106
-                setObject(new OsdWindow(message, false,
106
+                setObject(new OsdWindow(timeout, message, false,
107 107
                         IdentityManager.getGlobalConfig().getOptionInt(
108 108
                         plugin.getDomain(), "locationX"), policy.getYPosition(
109 109
                         OsdManager.this, startY), plugin, OsdManager.this));

+ 2
- 2
src/com/dmdirc/addons/osd/OsdPlugin.java Zobrazit soubor

@@ -146,7 +146,7 @@ public final class OsdPlugin extends Plugin implements CategoryChangeListener,
146 146
     /** {@inheritDoc} */
147 147
     @Override
148 148
     public void categorySelected(final PreferencesCategory category) {
149
-        osdWindow = new OsdWindow("Please drag this OSD to position", true, x, y, this, osdManager);
149
+        osdWindow = new OsdWindow(-1, "Please drag this OSD to position", true, x, y, this, osdManager);
150 150
         osdWindow.setBackgroundColour(backgroundSetting.getValue());
151 151
         osdWindow.setForegroundColour(foregroundSetting.getValue());
152 152
         osdWindow.setFontSize(Integer.parseInt(fontSizeSetting.getValue()));
@@ -203,7 +203,7 @@ public final class OsdPlugin extends Plugin implements CategoryChangeListener,
203 203
      * @param message Message to show
204 204
      */
205 205
     public void showOSD(final String title, final String message) {
206
-        osdManager.showWindow(message);
206
+        osdManager.showWindow(-1, message);
207 207
     }
208 208
 
209 209
 }

+ 13
- 6
src/com/dmdirc/addons/osd/OsdWindow.java Zobrazit soubor

@@ -84,23 +84,30 @@ public class OsdWindow extends JDialog implements MouseListener,
84 84
     /**
85 85
      * Creates a new instance of OsdWindow.
86 86
      *
87
+     * @param timeout Timeout period for the window. Set to -1 to use value from
88
+     *        config
87 89
      * @param text The text to be displayed in the OSD window
88 90
      * @param config Is the window being configured (should it timeout and
89
-     * allow itself to be moved)
91
+     *        allow itself to be moved)
90 92
      * @param x The x-axis position for the OSD Window
91 93
      * @param y The y-axis position for the OSD window
92 94
      * @param plugin Parent OSD Plugin
93 95
      * @param osdManager The manager that owns this OSD Window
94 96
      */
95
-    public OsdWindow(final String text, final boolean config, final int x,
97
+    public OsdWindow(final int timeout, final String text, final boolean config, final int x,
96 98
             final int y, final OsdPlugin plugin, final OsdManager osdManager) {
97 99
         super(((SwingController) PluginManager.getPluginManager()
98 100
                 .getPluginInfoByName("ui_swing").getPlugin()).getMainFrame(), false);
99 101
 
100 102
         this.config = config;
101 103
         this.osdManager = osdManager;
102
-        this.timeout = IdentityManager.getGlobalConfig()
103
-            .getOptionInt(osdManager.getPlugin().getDomain(), "timeout", false);
104
+
105
+        if (timeout < 0) {
106
+            this.timeout = IdentityManager.getGlobalConfig().getOptionInt(
107
+                    osdManager.getPlugin().getDomain(), "timeout", false);
108
+        } else {
109
+            this.timeout = timeout;
110
+        }
104 111
 
105 112
         setFocusableWindowState(false);
106 113
         setAlwaysOnTop(true);
@@ -141,7 +148,7 @@ public class OsdWindow extends JDialog implements MouseListener,
141 148
             addMouseListener(this);
142 149
         } else {
143 150
             addMouseListener(this);
144
-            if (timeout != null) {
151
+            if (this.timeout != null && this.timeout > 0) {
145 152
                 new Timer("OSD Display Timer").schedule(new TimerTask() {
146 153
 
147 154
                     /** {@inheritDoc} */
@@ -149,7 +156,7 @@ public class OsdWindow extends JDialog implements MouseListener,
149 156
                     public void run() {
150 157
                         osdManager.closeWindow(OsdWindow.this);
151 158
                     }
152
-                }, Math.max(timeout, 1) * 1000);
159
+                }, this.timeout * 1000);
153 160
             }
154 161
         }
155 162
     }

+ 66
- 0
src/com/dmdirc/addons/osd/QueuedMessage.java Zobrazit soubor

@@ -0,0 +1,66 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes,
3
+ * Simon Mott
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+
24
+package com.dmdirc.addons.osd;
25
+
26
+/**
27
+ * Class for storing OSD Window timeout values and messages for the window queue.
28
+ *
29
+ * @since 0.6.5
30
+ */
31
+public class QueuedMessage  {
32
+    /** Timeout delay in seconds. */
33
+    private final int timeout;
34
+
35
+    /** Message to display on the OSD. */
36
+    private final String message;
37
+
38
+    /**
39
+     * Creates a new instance of QueuedMessage.
40
+     *
41
+     * @param timeout Timeout for the OSD window in seconds
42
+     * @param message Message to display in the OSD
43
+     */
44
+    public QueuedMessage(final int timeout, final String message) {
45
+        this.timeout = timeout;
46
+        this.message = message;
47
+    }
48
+
49
+    /**
50
+     * Returns the timeout for this OSD window.
51
+     *
52
+     * @return Timeout in seconds
53
+     */
54
+    public int getTimeout() {
55
+        return timeout;
56
+    }
57
+
58
+    /**
59
+     * Returns the message for the OSD window.
60
+     *
61
+     * @return Message for the OSD window
62
+     */
63
+    public String getMessage() {
64
+        return message;
65
+    }
66
+}

Načítá se…
Zrušit
Uložit