Browse Source

Fixes issue 3605: Transfer speed for DCC plugin has lots of decimal places

Fixes issue 1879: open folder/open file buttons in dcc window after completion

Change-Id: I41dbf25c5089130c0f6e28f7a9c7a1ad1fa978a9
Reviewed-on: http://gerrit.dmdirc.com/587
Automatic-Compile: Gregory Holmes <greg@dmdirc.com>
Reviewed-by: Gregory Holmes <greg@dmdirc.com>
tags/0.6.3
Simon Mott 14 years ago
parent
commit
2b5e8b0d34
1 changed files with 48 additions and 4 deletions
  1. 48
    4
      src/com/dmdirc/addons/dcc/DCCSendWindow.java

+ 48
- 4
src/com/dmdirc/addons/dcc/DCCSendWindow.java View File

@@ -27,12 +27,16 @@ import com.dmdirc.ServerState;
27 27
 import com.dmdirc.actions.ActionManager;
28 28
 import com.dmdirc.addons.dcc.actions.DCCActions;
29 29
 import com.dmdirc.config.IdentityManager;
30
+import com.dmdirc.logger.ErrorLevel;
31
+import com.dmdirc.logger.Logger;
30 32
 import com.dmdirc.parser.interfaces.Parser;
31 33
 import com.dmdirc.parser.interfaces.callbacks.SocketCloseListener;
32 34
 
35
+import java.awt.Desktop;
33 36
 import java.awt.event.ActionEvent;
34 37
 import java.awt.event.ActionListener;
35 38
 import java.io.File;
39
+import java.io.IOException;
36 40
 
37 41
 import javax.swing.JButton;
38 42
 import javax.swing.JLabel;
@@ -78,6 +82,9 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
78 82
     /** Button */
79 83
     private final JButton button = new JButton("Cancel");
80 84
 
85
+    /** Open Button */
86
+    private final JButton openButton = new JButton("Open");
87
+
81 88
     /** Plugin that this send belongs to. */
82 89
     private final DCCPlugin myPlugin;
83 90
 
@@ -87,6 +94,10 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
87 94
     /** Server that caused this send */
88 95
     private Server server = null;
89 96
 
97
+    /** Show open button. */
98
+    private boolean showOpen = Desktop.isDesktopSupported() &&
99
+            Desktop.getDesktop().isSupported(Desktop.Action.OPEN);
100
+
90 101
     /**
91 102
      * Creates a new instance of DCCSendWindow with a given DCCSend object.
92 103
      *
@@ -110,7 +121,7 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
110 121
 
111 122
         otherNickname = targetNick;
112 123
 
113
-        getContentPane().setLayout(new MigLayout());
124
+        getContentPane().setLayout(new MigLayout("hidemode 0"));
114 125
 
115 126
         progress.setMinimum(0);
116 127
         progress.setMaximum(100);
@@ -131,7 +142,11 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
131 142
         getContentPane().add(progress, "growx, wrap");
132 143
 
133 144
         button.addActionListener(this);
134
-        getContentPane().add(button, "wrap, align right");
145
+        openButton.addActionListener(this);
146
+        openButton.setVisible(false);
147
+
148
+        getContentPane().add(openButton, "split 2, align right");
149
+        getContentPane().add(button, "align right");
135 150
 
136 151
         plugin.addWindow(this);
137 152
     }
@@ -157,7 +172,11 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
157 172
         return dcc;
158 173
     }
159 174
 
160
-    /** {@inheritDoc} */
175
+    /**
176
+     * {@inheritDoc}
177
+     *
178
+     * @param e Action event
179
+     */
161 180
     @Override
162 181
     public void actionPerformed(final ActionEvent e) {
163 182
         if (e.getActionCommand().equals("Cancel")) {
@@ -206,6 +225,27 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
206 225
             }
207 226
         } else if (e.getActionCommand().equals("Close Window")) {
208 227
             close();
228
+        } else if (e.getSource() == openButton) {
229
+            final File file = new File(dcc.getFileName());
230
+            try {
231
+                Desktop.getDesktop().open(file);
232
+            } catch (IllegalArgumentException ex) {
233
+                    Logger.userError(ErrorLevel.LOW, "Unable to open file: " +
234
+                            file + ex);
235
+                    openButton.setEnabled(false);
236
+            } catch (IOException ex) {
237
+                try {
238
+                    Desktop.getDesktop().open(file.getParentFile());
239
+                } catch (IllegalArgumentException ex1) {
240
+                    Logger.userError(ErrorLevel.LOW, "Unable to open folder: " +
241
+                            file.getParentFile() + ex1);
242
+                    openButton.setEnabled(false);
243
+                } catch (IOException ex1) {
244
+                    Logger.userError(ErrorLevel.LOW, "No associated handler " +
245
+                            "to open file or directory." + ex1);
246
+                    openButton.setEnabled(false);
247
+                }
248
+            }
209 249
         }
210 250
     }
211 251
 
@@ -251,7 +291,7 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
251 291
         } else if (bytesPerSecond > 1024) {
252 292
             speed.setText(String.format("Speed: %.2f KB/s", (bytesPerSecond / 1024)));
253 293
         } else {
254
-            speed.setText(String.format("Speed: %f B/s", bytesPerSecond));
294
+            speed.setText(String.format("Speed: %.2f B/s", bytesPerSecond));
255 295
         }
256 296
 
257 297
         final long remaningBytes;
@@ -296,6 +336,10 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
296 336
             synchronized (this) {
297 337
                 if (transferCount == dcc.getFileSize()) {
298 338
                     status.setText("Status: Transfer Compelete.");
339
+
340
+                    if (showOpen && dcc.getType() == DCCSend.TransferType.RECEIVE) {
341
+                        openButton.setVisible(true);
342
+                    }
299 343
                     progress.setValue(100);
300 344
                     setIcon(dcc.getType() == DCCSend.TransferType.SEND ? "dcc-send-done" : "dcc-receive-done");
301 345
                     button.setText("Close Window");

Loading…
Cancel
Save