1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.plugin.limewire;
21
22 import java.awt.event.ActionEvent;
23 import java.io.IOException;
24 import java.util.Iterator;
25
26 import javax.swing.Action;
27
28 import org.xnap.XNap;
29 import org.xnap.gui.StatusBar;
30 import org.xnap.gui.action.AbstractDownloadAction;
31 import org.xnap.search.AbstractSearchResultContainer;
32
33 import com.limegroup.gnutella.GUID;
34 import com.limegroup.gnutella.RemoteFileDesc;
35 import com.limegroup.gnutella.RouterService;
36 import com.limegroup.gnutella.downloader.AlreadyDownloadingException;
37
38 /***
39 * This class provides a container for {@link LimeWireSearchResult} objects.
40 */
41 public class LimeWireSearchResultContainer
42 extends AbstractSearchResultContainer {
43
44
45
46
47
48
49
50 public LimeWireSearchResultContainer()
51 {
52 }
53
54
55
56 public Action[] getActions()
57 {
58 return new Action[] { new DownloadAction() };
59 }
60
61
62
63 public class DownloadAction extends AbstractDownloadAction {
64
65 public void actionPerformed(ActionEvent event)
66 {
67 if (getChildCount() > 0) {
68 RemoteFileDesc[] desc = new RemoteFileDesc[getChildCount()];
69 int count = 0;
70 GUID guid = null;
71 for (Iterator i = iterator(); i.hasNext();) {
72 LimeWireSearchResult result = (LimeWireSearchResult)i.next();
73 if (count == 0) {
74 guid = new GUID(result.getData().getMessageGUID());
75 }
76
77 desc[count] = result.getRemoteDesc();
78 count++;
79 }
80
81 try {
82 RouterService.download(desc, true, guid);
83 }
84 catch (IOException e) {
85 StatusBar.setText(XNap.tr("Error: {0}",
86 e.getLocalizedMessage()));
87 }
88 catch (AlreadyDownloadingException e) {
89 StatusBar.setText(XNap.tr("Already downloading file!"));
90 }
91 }
92 }
93 }
94
95 }
96