Procházet zdrojové kódy

Fixed bug in the dcop plugin (missing space)

Fixed bug in the action manager (array index)
Added menu to systray plugin
Switched to a new SVG-based icon
Abstracted quit functionality



git-svn-id: http://svn.dmdirc.com/trunk@984 00569f92-eb28-0410-84fd-f71c24880f
tags/0.4
Chris Smith před 17 roky
rodič
revize
9d72d8868e

+ 17
- 0
src/uk/org/ownage/dmdirc/Main.java Zobrazit soubor

@@ -58,4 +58,21 @@ public final class Main {
58 58
         MainFrame.getMainFrame();
59 59
     }
60 60
     
61
+    /**
62
+     * Quits the client nicely.
63
+     * @param reason The quit reason to send
64
+     */
65
+    public static void quit(final String reason) {
66
+        ServerManager.getServerManager().disconnectAll(reason);
67
+        Config.save();
68
+        System.exit(0);
69
+    }
70
+    
71
+    /**
72
+     * Quits the client nicely, with the default closing message.
73
+     */
74
+    public static void quit() {
75
+        quit(Config.getOption("general", "closemessage"));
76
+    }
77
+    
61 78
 }

+ 3
- 3
src/uk/org/ownage/dmdirc/actions/ActionManager.java Zobrazit soubor

@@ -196,14 +196,14 @@ public class ActionManager {
196 196
         Channel channel = null;
197 197
         ChannelClientInfo source = null;
198 198
         
199
-        if (arguments[0] instanceof Server) {
199
+        if (arguments.length > 0 && arguments[0] instanceof Server) {
200 200
             server = (Server) arguments[0];
201 201
         } else if (arguments[0] instanceof Channel) {
202 202
             channel = (Channel) arguments[0];
203 203
             server = channel.getServer();
204 204
         }
205 205
         
206
-        if (arguments[1] instanceof ChannelClientInfo) {
206
+        if (arguments.length > 1 && arguments[1] instanceof ChannelClientInfo) {
207 207
             source = (ChannelClientInfo) arguments[1];
208 208
         }
209 209
         
@@ -219,7 +219,7 @@ public class ActionManager {
219 219
             res = res.replaceAll("\\$source", source.getNickname());
220 220
         }
221 221
         
222
-        if (arguments[2] instanceof String) {
222
+        if (arguments.length > 2 && arguments[2] instanceof String) {
223 223
             res = res.replaceAll("\\$message", (String) arguments[2]);
224 224
         }
225 225
         

+ 2
- 3
src/uk/org/ownage/dmdirc/commandparser/commands/server/Quit.java Zobrazit soubor

@@ -23,6 +23,7 @@
23 23
 package uk.org.ownage.dmdirc.commandparser.commands.server;
24 24
 
25 25
 import uk.org.ownage.dmdirc.Config;
26
+import uk.org.ownage.dmdirc.Main;
26 27
 import uk.org.ownage.dmdirc.Server;
27 28
 import uk.org.ownage.dmdirc.ServerManager;
28 29
 import uk.org.ownage.dmdirc.commandparser.CommandManager;
@@ -54,9 +55,7 @@ public final class Quit extends ServerCommand {
54 55
      */
55 56
     public void execute(final CommandWindow origin, final Server server,
56 57
             final String... args) {
57
-        ServerManager.getServerManager().disconnectAll(implodeArgs(args));
58
-        Config.save();
59
-        System.exit(0);
58
+        Main.quit(implodeArgs(args));
60 59
     }
61 60
     
62 61
     

+ 1
- 1
src/uk/org/ownage/dmdirc/plugins/plugins/dcop/DcopCommand.java Zobrazit soubor

@@ -56,7 +56,7 @@ public final class DcopCommand extends ServerCommand {
56 56
     public void execute(final CommandWindow origin, final Server server,
57 57
             final String... args) {
58 58
         try {
59
-            final List<String> res = DcopPlugin.getDcopResult("dcop" + implodeArgs(args));
59
+            final List<String> res = DcopPlugin.getDcopResult("dcop " + implodeArgs(args));
60 60
             for (String line : res) {
61 61
                 origin.addLine(line);
62 62
             }

+ 85
- 22
src/uk/org/ownage/dmdirc/plugins/plugins/systray/SystrayPlugin.java Zobrazit soubor

@@ -23,11 +23,19 @@
23 23
 package uk.org.ownage.dmdirc.plugins.plugins.systray;
24 24
 
25 25
 import java.awt.AWTException;
26
+import java.awt.MenuItem;
27
+import java.awt.PopupMenu;
26 28
 import java.awt.SystemTray;
27 29
 import java.awt.TrayIcon;
30
+import java.awt.event.ActionEvent;
31
+import java.awt.event.ActionListener;
32
+import java.awt.event.MouseEvent;
33
+import java.awt.event.MouseListener;
34
+import java.net.URL;
28 35
 
29 36
 import javax.swing.ImageIcon;
30 37
 
38
+import uk.org.ownage.dmdirc.Main;
31 39
 import uk.org.ownage.dmdirc.plugins.Plugin;
32 40
 import uk.org.ownage.dmdirc.ui.MainFrame;
33 41
 
@@ -36,7 +44,7 @@ import uk.org.ownage.dmdirc.ui.MainFrame;
36 44
  * notifications to be disabled.
37 45
  * @author chris
38 46
  */
39
-public class SystrayPlugin implements Plugin {
47
+public class SystrayPlugin implements Plugin, ActionListener, MouseListener {
40 48
     
41 49
     /** Is this plugin active? */
42 50
     private boolean isActive = false;
@@ -44,6 +52,22 @@ public class SystrayPlugin implements Plugin {
44 52
     /** The tray icon we're currently using. */
45 53
     private TrayIcon icon;
46 54
     
55
+    /** The menu to use for the tray icon. */
56
+    private final PopupMenu menu;
57
+    
58
+    /** Creates a new system tray plugin. */
59
+    public SystrayPlugin() {
60
+        final MenuItem show = new MenuItem("Show/hide");
61
+        final MenuItem quit = new MenuItem("Quit");
62
+        
63
+        menu = new PopupMenu();
64
+        menu.add(show);
65
+        menu.add(quit);
66
+        
67
+        show.addActionListener(this);
68
+        quit.addActionListener(this);
69
+    }
70
+    
47 71
     /**
48 72
      * Sends a notification via the system tray icon.
49 73
      * @param title The title of the notification
@@ -61,21 +85,28 @@ public class SystrayPlugin implements Plugin {
61 85
      */
62 86
     public void notify(final String title, final String message) {
63 87
         notify(title, message, TrayIcon.MessageType.NONE);
64
-    }    
88
+    }
65 89
     
66
-    /** {@inheritDoc}. */
90
+    /** {@inheritDoc} */
91
+    public void actionPerformed(final ActionEvent e) {
92
+        if (e.getActionCommand().equals("Show/hide")) {
93
+            MainFrame.getMainFrame().setVisible(!MainFrame.getMainFrame().isVisible());
94
+        } else if (e.getActionCommand().equals("Quit")) {
95
+            Main.quit();
96
+        }
97
+    }
98
+    
99
+    /** {@inheritDoc} */
67 100
     public boolean onLoad() {
68 101
         if (SystemTray.isSupported()) {
69
-            final SystemTray tray = SystemTray.getSystemTray();
70
-            
71
-            final ImageIcon image = MainFrame.getMainFrame().getIcon();
72
-            
73
-            icon = new TrayIcon(image.getImage());
74
-            
75
-            icon.setImageAutoSize(false);
102
+            final ClassLoader cldr = this.getClass().getClassLoader();
103
+            final URL imageURL = cldr.getResource("uk/org/ownage/dmdirc/res/logo.png");
104
+            icon = new TrayIcon(new ImageIcon(imageURL).getImage(), "DMDirc", menu);
105
+            icon.setImageAutoSize(true);
106
+            icon.addMouseListener(this);
76 107
             
77 108
             try {
78
-                tray.add(icon);
109
+                SystemTray.getSystemTray().add(icon);
79 110
             } catch (AWTException ex) {
80 111
                 return false;
81 112
             }
@@ -88,50 +119,82 @@ public class SystrayPlugin implements Plugin {
88 119
         return true;
89 120
     }
90 121
     
91
-    /** {@inheritDoc}. */
122
+    /** {@inheritDoc} */
92 123
     public void onUnload() {
93 124
     }
94 125
     
95
-    /** {@inheritDoc}. */
126
+    /** {@inheritDoc} */
96 127
     public void onActivate() {
97 128
         isActive = true;
98 129
     }
99 130
     
100
-    /** {@inheritDoc}. */
131
+    /** {@inheritDoc} */
101 132
     public boolean isActive() {
102 133
         return isActive;
103 134
     }
104 135
     
105 136
     /** {@inheritDoc}. */
106 137
     public void onDeactivate() {
138
+        SystemTray.getSystemTray().remove(icon);
107 139
         isActive = false;
108
-        final SystemTray tray = SystemTray.getSystemTray();
109
-        
110
-        tray.remove(icon);
111 140
     }
112 141
     
113
-    /** {@inheritDoc}. */
142
+    /** {@inheritDoc} */
114 143
     public boolean isConfigurable() {
115 144
         return false;
116 145
     }
117 146
     
118
-    /** {@inheritDoc}. */
147
+    /** {@inheritDoc} */
119 148
     public void showConfig() {
120 149
     }
121 150
     
122
-    /** {@inheritDoc}. */
151
+    /** {@inheritDoc} */
123 152
     public int getVersion() {
124 153
         return 0;
125 154
     }
126 155
     
127
-    /** {@inheritDoc}. */
156
+    /** {@inheritDoc} */
128 157
     public String getAuthor() {
129 158
         return "Chris 'MD87' Smith - chris@dmdirc.com";
130 159
     }
131 160
     
132
-    /** {@inheritDoc}. */
161
+    /** {@inheritDoc} */
133 162
     public String getDescription() {
134 163
         return "Adds a system tray icon";
135 164
     }
136 165
     
166
+    /** {@inheritDoc} */
167
+    public void mouseClicked(final MouseEvent e) {
168
+        if (e.getButton() == MouseEvent.BUTTON1) {
169
+            if (MainFrame.getMainFrame().isVisible()) {
170
+                // TODO: Uncomment the code below, with an appropriate replacement
171
+                //       for requestFocus() that does something more than flash.
172
+                
173
+                //if (MainFrame.getMainFrame().isActive()) {
174
+                MainFrame.getMainFrame().setVisible(false);
175
+                //} else {
176
+                //    MainFrame.getMainFrame().requestFocus();
177
+                //}
178
+            } else {
179
+                MainFrame.getMainFrame().setVisible(true);
180
+            }
181
+        }
182
+    }
183
+    
184
+    /** {@inheritDoc} */
185
+    public void mousePressed(final MouseEvent e) {
186
+    }
187
+    
188
+    /** {@inheritDoc} */
189
+    public void mouseReleased(final MouseEvent e) {
190
+    }
191
+    
192
+    /** {@inheritDoc} */
193
+    public void mouseEntered(final MouseEvent e) {
194
+    }
195
+    
196
+    /** {@inheritDoc} */
197
+    public void mouseExited(final MouseEvent e) {
198
+    }
199
+    
137 200
 }

binární
src/uk/org/ownage/dmdirc/res/icon.png Zobrazit soubor


binární
src/uk/org/ownage/dmdirc/res/logo.png Zobrazit soubor


+ 93
- 0
src/uk/org/ownage/dmdirc/res/logo.svg Zobrazit soubor

@@ -0,0 +1,93 @@
1
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
3
+<svg
4
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
5
+   xmlns:cc="http://web.resource.org/cc/"
6
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
7
+   xmlns:svg="http://www.w3.org/2000/svg"
8
+   xmlns="http://www.w3.org/2000/svg"
9
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
10
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
11
+   width="64px"
12
+   height="64px"
13
+   id="svg2233"
14
+   sodipodi:version="0.32"
15
+   inkscape:version="0.45"
16
+   sodipodi:docname="logo.svg"
17
+   sodipodi:docbase="/home/chris/DMDirc/trunk/src/uk/org/ownage/dmdirc/res"
18
+   inkscape:output_extension="org.inkscape.output.svg.inkscape"
19
+   inkscape:export-filename="/home/chris/DMDirc/trunk/src/uk/org/ownage/dmdirc/res/icon.png"
20
+   inkscape:export-xdpi="22.5"
21
+   inkscape:export-ydpi="22.5"
22
+   sodipodi:modified="TRUE">
23
+  <defs
24
+     id="defs2235" />
25
+  <sodipodi:namedview
26
+     id="base"
27
+     pagecolor="#ffffff"
28
+     bordercolor="#666666"
29
+     borderopacity="1.0"
30
+     inkscape:pageopacity="0.0"
31
+     inkscape:pageshadow="2"
32
+     inkscape:zoom="7.7781746"
33
+     inkscape:cx="38.436654"
34
+     inkscape:cy="32.116009"
35
+     inkscape:current-layer="layer1"
36
+     showgrid="true"
37
+     inkscape:document-units="px"
38
+     inkscape:grid-bbox="true"
39
+     inkscape:window-width="1280"
40
+     inkscape:window-height="956"
41
+     inkscape:window-x="0"
42
+     inkscape:window-y="0" />
43
+  <metadata
44
+     id="metadata2238">
45
+    <rdf:RDF>
46
+      <cc:Work
47
+         rdf:about="">
48
+        <dc:format>image/svg+xml</dc:format>
49
+        <dc:type
50
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
51
+      </cc:Work>
52
+    </rdf:RDF>
53
+  </metadata>
54
+  <g
55
+     id="layer1"
56
+     inkscape:label="Layer 1"
57
+     inkscape:groupmode="layer">
58
+    <path
59
+       sodipodi:type="arc"
60
+       style="opacity:1;fill:#fff100;fill-opacity:1;stroke:#000000;stroke-width:2.88174772;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none"
61
+       id="path2221"
62
+       sodipodi:cx="390.08929"
63
+       sodipodi:cy="567.54077"
64
+       sodipodi:rx="37.767857"
65
+       sodipodi:ry="38.392857"
66
+       d="M 427.85715 567.54077 A 37.767857 38.392857 0 1 1  352.32144,567.54077 A 37.767857 38.392857 0 1 1  427.85715 567.54077 z"
67
+       transform="matrix(0.6995081,0,0,0.6885814,-240.49033,-359.17061)" />
68
+    <path
69
+       sodipodi:type="arc"
70
+       style="fill:#000000;stroke:#000000;stroke-width:0.46683663;stroke-miterlimit:4;stroke-dasharray:none"
71
+       id="path2223"
72
+       sodipodi:cx="357.76785"
73
+       sodipodi:cy="535.39789"
74
+       sodipodi:rx="2.5892856"
75
+       sodipodi:ry="2.6785715"
76
+       d="M 360.35714 535.39789 A 2.5892856 2.6785715 0 1 1  355.17857,535.39789 A 2.5892856 2.6785715 0 1 1  360.35714 535.39789 z"
77
+       transform="matrix(1.209758,0,0,1.1890018,-408.04011,-611.18464)" />
78
+    <path
79
+       style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2.7099998;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
80
+       d="M 23.368104,48.697059 L 47.455791,37.270576"
81
+       id="path2229" />
82
+    <path
83
+       sodipodi:type="arc"
84
+       style="fill:#000000;stroke:#000000;stroke-width:0.46683663;stroke-miterlimit:4;stroke-dasharray:none"
85
+       id="path3216"
86
+       sodipodi:cx="357.76785"
87
+       sodipodi:cy="535.39789"
88
+       sodipodi:rx="2.5892856"
89
+       sodipodi:ry="2.6785715"
90
+       d="M 360.35714 535.39789 A 2.5892856 2.6785715 0 1 1  355.17857,535.39789 A 2.5892856 2.6785715 0 1 1  360.35714 535.39789 z"
91
+       transform="matrix(1.209758,0,0,1.1890018,-393.06865,-611.1982)" />
92
+  </g>
93
+</svg>

+ 1
- 2
src/uk/org/ownage/dmdirc/ui/MainFrame.java Zobrazit soubor

@@ -543,8 +543,7 @@ public final class MainFrame extends JFrame implements WindowListener,
543 543
         } else if (e.getActionCommand().equals("Profile")) {
544 544
             new ProfileEditorDialog();
545 545
         } else if (e.getActionCommand().equals("Exit")) {
546
-            Config.save();
547
-            System.exit(1);
546
+            Main.quit();
548 547
         }
549 548
     }
550 549
     

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