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 org.xnap.XNap;
23  import org.xnap.search.AbstractSearch;
24  import org.xnap.search.SearchFilter;
25  import org.xnap.search.SearchHandler;
26  
27  import com.limegroup.gnutella.GUID;
28  import com.limegroup.gnutella.RouterService;
29  
30  /***
31   * Implements a limewire search session.
32   */
33  public class DefaultLimeWireSearch extends AbstractSearch 
34  	implements LimeWireSearch {
35  
36      // --- Constants(s) ---
37  
38      //--- Data Field(s) ---
39  
40      private SearchHandler handler;
41  	private boolean done = false;
42  	private GUID guid;
43  
44      //--- Constructor(s) ---
45  
46      public DefaultLimeWireSearch(SearchFilter filter, GUID guid)
47      {
48  		super(filter);
49  		
50  		this.guid = guid;
51      }
52  
53      // --- Method(s) ---
54  
55      /***
56       * Returns a string that describes the current status. 
57       */
58      public String getStatus()
59      {
60  		return done 
61  			? XNap.tr("LimeWire done")
62  			: XNap.tr("Receiving LimeWire results");
63      }
64  
65      /***
66       * Returns true, if this search can not be canceled.
67       */
68      public boolean isDone()
69      {
70  		return done;
71      }
72  
73  	public void received(LimeWireSearchResult result)
74  	{
75  		handler.resultReceived(result);
76  	}
77  	
78      /***
79       * Starts this search.
80       *
81       * @param handler the object that handles the results
82       */
83      public void start(SearchHandler handler)
84      {
85      	this.handler = handler;
86  		this.done = false;
87  
88  		//MediaType mt = LimeWireSearchManager.getMediaType(getFilter().getMediaType());
89  		RouterService.query(guid.bytes(), getFilter().getText());
90      }
91  
92      /***
93       * Cancels this search.
94       */
95      public void stop()
96      {
97      	RouterService.stopQuery(guid);
98  		done = true;
99      }
100 
101 	/***
102 	 *  @see xnap.plugin.limewire.LimeWireSearch#failed()
103 	 */
104 	public void failed() 
105 	{
106 		// is never called
107 	}
108 
109     // --- Inner Class(es) ---
110 
111 }
112