View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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      // --- Constants(s) ---
38  
39      //--- Data Field(s) ---
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      //--- Constructor(s) ---
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      // --- Method(s) ---
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     // --- Inner Class(es) ---
156 
157 }
158