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 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      // --- Constants(s) ---
45  
46      //--- Data Field(s) ---
47  
48      //--- Constructor(s) ---
49  
50      public LimeWireSearchResultContainer()
51      {
52      }
53  
54      // --- Method(s) ---
55  
56      public Action[] getActions()
57      {
58  		return new Action[] { new DownloadAction() };
59      }
60  
61      //--- Inner classes(s) ---
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