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 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      
37  
38      
39  
40      private SearchHandler handler;
41  	private boolean done = false;
42  	private GUID guid;
43  
44      
45  
46      public DefaultLimeWireSearch(SearchFilter filter, GUID guid)
47      {
48  		super(filter);
49  		
50  		this.guid = guid;
51      }
52  
53      
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  		
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 		
107 	}
108 
109     
110 
111 }
112