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 javax.swing.Action;
23
24 import org.xnap.XNap;
25 import org.xnap.search.SearchFilter;
26 import org.xnap.search.SearchHandler;
27
28 import com.limegroup.gnutella.GUID;
29 import com.limegroup.gnutella.RouterService;
30 import com.sun.java.util.collections.Set;
31
32 /***
33 * Implements a limewire search session.
34 */
35 public class LimeWireBrowse implements LimeWireSearch {
36
37
38
39
40
41 private GUID clientGUID;
42 private int port;
43 private String host;
44 private SearchHandler handler;
45 private boolean done = false;
46 private GUID guid;
47 private Set proxies;
48
49
50
51 public LimeWireBrowse(String host, int port, GUID guid,
52 GUID clientGUID, Set proxies)
53 {
54 this.host = host;
55 this.port = port;
56 this.guid = guid;
57 this.clientGUID = clientGUID;
58 this.proxies = proxies;
59 }
60
61
62
63 /***
64 * Returns <code>null</code>.
65 */
66 public Action[] getActions()
67 {
68 return null;
69 }
70
71 /***
72 * Returns a string that describes the current status.
73 */
74 public String getStatus()
75 {
76 return done ? XNap.tr("Done") : XNap.tr("receiving results") + "...";
77 }
78
79 /***
80 * Returns true, if this search can not be canceled.
81 */
82 public boolean isDone()
83 {
84 return done;
85 }
86
87 public void received(LimeWireSearchResult result)
88 {
89 handler.resultReceived(result);
90 }
91
92 /***
93 * Starts this search.
94 *
95 * @param handler the object that handles the results
96 */
97 public void start(SearchHandler handler)
98 {
99 this.handler = handler;
100 this.done = false;
101
102 Runnable runner = new Runnable()
103 {
104 public void run()
105 {
106 RouterService.doAsynchronousBrowseHost(host, port, guid, clientGUID,
107 proxies);
108 }
109 };
110 Thread t = new Thread(runner, "LimeWireBrowse:" + host);
111 t.start();
112 }
113
114 /***
115 * Cancels this search.
116 */
117 public void stop()
118 {
119 RouterService.stopQuery(guid);
120 done = true;
121 }
122
123 /***
124 * @see xnap.plugin.limewire.LimeWireSearch#failed()
125 */
126 public void failed()
127 {
128 done = true;
129 handler.stateChanged(this);
130 }
131
132 /***
133 * @see xnap.search.Search#getFilter()
134 */
135 public SearchFilter getFilter() {
136 return null;
137 }
138
139 /***
140 * @see xnap.search.Search#getName()
141 */
142 public String getName()
143 {
144 return host;
145 }
146
147 /***
148 * @see xnap.search.Search#showTree()
149 */
150 public boolean showTree()
151 {
152 return true;
153 }
154
155
156
157 }
158