1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.plugin.azureus;
21
22 import java.io.File;
23
24 import javax.swing.Action;
25
26 import org.apache.log4j.Logger;
27 import org.gudy.azureus2.core3.peer.PEPeer;
28 import org.xnap.XNap;
29 import org.xnap.peer.Peer;
30 import org.xnap.plugin.Plugin;
31 import org.xnap.transfer.AbstractTransfer;
32 import org.xnap.transfer.Download;
33
34 /***
35 * Downloads a file.
36 */
37 public class AzureusPeerDownload extends AbstractTransfer implements Download {
38
39
40
41
42
43 private static Logger logger = Logger.getLogger(AzureusPeerDownload.class);
44
45 private AzureusDownloadContainer parent;
46 private PEPeer peer;
47
48
49
50 public AzureusPeerDownload(AzureusDownloadContainer parent, PEPeer peer)
51 {
52 this.parent = parent;
53 this.peer = peer;
54 }
55
56
57
58 public long getBytesTransferred()
59 {
60 return peer.getStats().getTotalReceived();
61 }
62
63 public Action[] getActions()
64 {
65 return null;
66 }
67
68 public File getFile()
69 {
70 return parent.getFile();
71 }
72
73 public String getFilename()
74 {
75 return parent.getFilename();
76 }
77
78 public long getFilesize()
79 {
80 return parent.getFilesize();
81 }
82
83 public Peer getPeer()
84 {
85 return null;
86 }
87
88 public Plugin getPlugin()
89 {
90 return AzureusPlugin.getInstance();
91 }
92
93 public String getStatus()
94 {
95 switch (peer.getState()) {
96 case PEPeer.CONNECTING :
97 return XNap.tr("Connecting");
98 case PEPeer.DISCONNECTED :
99 return XNap.tr("Disconnected");
100 case PEPeer.HANDSHAKING :
101 return XNap.tr("Handshaking");
102 case PEPeer.TRANSFERING :
103 return XNap.tr("Downloading");
104 default:
105 return XNap.tr("Unknown State {0}", peer.getState());
106 }
107 }
108
109 public long getTotalBytesTransferred()
110 {
111 return getBytesTransferred();
112 }
113
114 public boolean isDone()
115 {
116 int s = peer.getState();
117 return s == PEPeer.DISCONNECTED;
118 }
119
120 public boolean isRunning()
121 {
122 int s = peer.getState();
123 return s == PEPeer.TRANSFERING;
124 }
125
126
127
128 }