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
 import com.dmdirc.actions.ActionManager;
27
 import com.dmdirc.actions.ActionManager;
28
 import com.dmdirc.addons.dcc.actions.DCCActions;
28
 import com.dmdirc.addons.dcc.actions.DCCActions;
29
 import com.dmdirc.config.IdentityManager;
29
 import com.dmdirc.config.IdentityManager;
30
+import com.dmdirc.logger.ErrorLevel;
31
+import com.dmdirc.logger.Logger;
30
 import com.dmdirc.parser.interfaces.Parser;
32
 import com.dmdirc.parser.interfaces.Parser;
31
 import com.dmdirc.parser.interfaces.callbacks.SocketCloseListener;
33
 import com.dmdirc.parser.interfaces.callbacks.SocketCloseListener;
32
 
34
 
35
+import java.awt.Desktop;
33
 import java.awt.event.ActionEvent;
36
 import java.awt.event.ActionEvent;
34
 import java.awt.event.ActionListener;
37
 import java.awt.event.ActionListener;
35
 import java.io.File;
38
 import java.io.File;
39
+import java.io.IOException;
36
 
40
 
37
 import javax.swing.JButton;
41
 import javax.swing.JButton;
38
 import javax.swing.JLabel;
42
 import javax.swing.JLabel;
78
     /** Button */
82
     /** Button */
79
     private final JButton button = new JButton("Cancel");
83
     private final JButton button = new JButton("Cancel");
80
 
84
 
85
+    /** Open Button */
86
+    private final JButton openButton = new JButton("Open");
87
+
81
     /** Plugin that this send belongs to. */
88
     /** Plugin that this send belongs to. */
82
     private final DCCPlugin myPlugin;
89
     private final DCCPlugin myPlugin;
83
 
90
 
87
     /** Server that caused this send */
94
     /** Server that caused this send */
88
     private Server server = null;
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
      * Creates a new instance of DCCSendWindow with a given DCCSend object.
102
      * Creates a new instance of DCCSendWindow with a given DCCSend object.
92
      *
103
      *
110
 
121
 
111
         otherNickname = targetNick;
122
         otherNickname = targetNick;
112
 
123
 
113
-        getContentPane().setLayout(new MigLayout());
124
+        getContentPane().setLayout(new MigLayout("hidemode 0"));
114
 
125
 
115
         progress.setMinimum(0);
126
         progress.setMinimum(0);
116
         progress.setMaximum(100);
127
         progress.setMaximum(100);
131
         getContentPane().add(progress, "growx, wrap");
142
         getContentPane().add(progress, "growx, wrap");
132
 
143
 
133
         button.addActionListener(this);
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
         plugin.addWindow(this);
151
         plugin.addWindow(this);
137
     }
152
     }
157
         return dcc;
172
         return dcc;
158
     }
173
     }
159
 
174
 
160
-    /** {@inheritDoc} */
175
+    /**
176
+     * {@inheritDoc}
177
+     *
178
+     * @param e Action event
179
+     */
161
     @Override
180
     @Override
162
     public void actionPerformed(final ActionEvent e) {
181
     public void actionPerformed(final ActionEvent e) {
163
         if (e.getActionCommand().equals("Cancel")) {
182
         if (e.getActionCommand().equals("Cancel")) {
206
             }
225
             }
207
         } else if (e.getActionCommand().equals("Close Window")) {
226
         } else if (e.getActionCommand().equals("Close Window")) {
208
             close();
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
         } else if (bytesPerSecond > 1024) {
291
         } else if (bytesPerSecond > 1024) {
252
             speed.setText(String.format("Speed: %.2f KB/s", (bytesPerSecond / 1024)));
292
             speed.setText(String.format("Speed: %.2f KB/s", (bytesPerSecond / 1024)));
253
         } else {
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
         final long remaningBytes;
297
         final long remaningBytes;
296
             synchronized (this) {
336
             synchronized (this) {
297
                 if (transferCount == dcc.getFileSize()) {
337
                 if (transferCount == dcc.getFileSize()) {
298
                     status.setText("Status: Transfer Compelete.");
338
                     status.setText("Status: Transfer Compelete.");
339
+
340
+                    if (showOpen && dcc.getType() == DCCSend.TransferType.RECEIVE) {
341
+                        openButton.setVisible(true);
342
+                    }
299
                     progress.setValue(100);
343
                     progress.setValue(100);
300
                     setIcon(dcc.getType() == DCCSend.TransferType.SEND ? "dcc-send-done" : "dcc-receive-done");
344
                     setIcon(dcc.getType() == DCCSend.TransferType.SEND ? "dcc-send-done" : "dcc-receive-done");
301
                     button.setText("Close Window");
345
                     button.setText("Close Window");

Loading…
Cancel
Save