aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/xmpp
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-10-15 19:32:12 +0200
committeriNPUTmice <daniel@gultsch.de>2014-10-15 19:32:12 +0200
commitcb4069f0f213ed1a38ce074d981b0c367dc2cdfd (patch)
tree9004af99e6da679e640fe97bdcdbf469832b8ab5 /src/eu/siacs/conversations/xmpp
parent1927a3d99c3a8e23535680ceb29e7dbb78bda185 (diff)
refactored file download status. make image http download available for carbon copied (sent) messages as well
Diffstat (limited to 'src/eu/siacs/conversations/xmpp')
-rw-r--r--src/eu/siacs/conversations/xmpp/XmppConnection.java2
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java85
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java2
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java3
4 files changed, 57 insertions, 35 deletions
diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java
index 54409be4..43614f50 100644
--- a/src/eu/siacs/conversations/xmpp/XmppConnection.java
+++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java
@@ -910,7 +910,7 @@ public class XmppConnection implements Runnable {
}
public void disconnect(boolean force) {
- Log.d(Config.LOGTAG, account.getJid()+": disconnecting");
+ Log.d(Config.LOGTAG, account.getJid() + ": disconnecting");
try {
if (force) {
socket.close();
diff --git a/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
index 4853d75c..8e4714f4 100644
--- a/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
@@ -34,17 +34,18 @@ public class JingleConnection implements Downloadable {
private JingleConnectionManager mJingleConnectionManager;
private XmppConnectionService mXmppConnectionService;
- public static final int STATUS_INITIATED = 0;
- public static final int STATUS_ACCEPTED = 1;
- public static final int STATUS_TERMINATED = 2;
- public static final int STATUS_CANCELED = 3;
- public static final int STATUS_FINISHED = 4;
- public static final int STATUS_TRANSMITTING = 5;
- public static final int STATUS_FAILED = 99;
+ protected static final int JINGLE_STATUS_INITIATED = 0;
+ protected static final int JINGLE_STATUS_ACCEPTED = 1;
+ protected static final int JINGLE_STATUS_TERMINATED = 2;
+ protected static final int JINGLE_STATUS_CANCELED = 3;
+ protected static final int JINGLE_STATUS_FINISHED = 4;
+ protected static final int JINGLE_STATUS_TRANSMITTING = 5;
+ protected static final int JINGLE_STATUS_FAILED = 99;
private int ibbBlockSize = 4096;
- private int status = -1;
+ private int mJingleStatus = -1;
+ private int mStatus = -1;
private Message message;
private String sessionId;
private Account account;
@@ -76,7 +77,7 @@ public class JingleConnection implements Downloadable {
mXmppConnectionService.markMessage(message,
Message.STATUS_SEND_FAILED);
}
- status = STATUS_FAILED;
+ mJingleStatus = JINGLE_STATUS_FAILED;
}
}
};
@@ -254,13 +255,14 @@ public class JingleConnection implements Downloadable {
}
public void init(Account account, JinglePacket packet) {
- this.status = STATUS_INITIATED;
+ this.mJingleStatus = JINGLE_STATUS_INITIATED;
Conversation conversation = this.mXmppConnectionService
.findOrCreateConversation(account,
packet.getFrom().split("/", 2)[0], false);
this.message = new Message(conversation, "", Message.ENCRYPTION_NONE);
+ this.message.setStatus(Message.STATUS_RECEIVED);
this.message.setType(Message.TYPE_IMAGE);
- this.message.setStatus(Message.STATUS_RECEIVED_OFFER);
+ this.mStatus = Downloadable.STATUS_OFFER;
this.message.setDownloadable(this);
String[] fromParts = packet.getFrom().split("/", 2);
this.message.setPresence(fromParts[1]);
@@ -306,6 +308,7 @@ public class JingleConnection implements Downloadable {
long size = Long.parseLong(fileSize.getContent());
message.setBody(Long.toString(size));
conversation.getMessages().add(message);
+ mXmppConnectionService.updateConversationUi();
if (size <= this.mJingleConnectionManager
.getAutoAcceptFileSize()) {
Log.d(Config.LOGTAG, "auto accepting file from "
@@ -370,7 +373,7 @@ public class JingleConnection implements Downloadable {
content.socks5transport().setChildren(getCandidatesAsElements());
packet.setContent(content);
this.sendJinglePacket(packet);
- this.status = STATUS_INITIATED;
+ this.mJingleStatus = JINGLE_STATUS_INITIATED;
}
}
@@ -383,8 +386,9 @@ public class JingleConnection implements Downloadable {
}
private void sendAccept() {
- status = STATUS_ACCEPTED;
- mXmppConnectionService.markMessage(message, Message.STATUS_RECEIVING);
+ mJingleStatus = JINGLE_STATUS_ACCEPTED;
+ this.mStatus = Downloadable.STATUS_DOWNLOADING;
+ mXmppConnectionService.updateConversationUi();
this.mJingleConnectionManager.getPrimaryCandidate(this.account,
new OnPrimaryCandidateFound() {
@@ -458,7 +462,7 @@ public class JingleConnection implements Downloadable {
Content content = packet.getJingleContent();
mergeCandidates(JingleCandidate.parse(content.socks5transport()
.getChildren()));
- this.status = STATUS_ACCEPTED;
+ this.mJingleStatus = JINGLE_STATUS_ACCEPTED;
mXmppConnectionService.markMessage(message, Message.STATUS_UNSEND);
this.connectNextCandidate();
return true;
@@ -493,7 +497,8 @@ public class JingleConnection implements Downloadable {
} else if (content.socks5transport().hasChild("candidate-error")) {
Log.d(Config.LOGTAG, "received candidate error");
this.receivedCandidate = true;
- if ((status == STATUS_ACCEPTED) && (this.sentCandidate)) {
+ if ((mJingleStatus == JINGLE_STATUS_ACCEPTED)
+ && (this.sentCandidate)) {
this.connect();
}
return true;
@@ -505,7 +510,8 @@ public class JingleConnection implements Downloadable {
JingleCandidate candidate = getCandidate(cid);
candidate.flagAsUsedByCounterpart();
this.receivedCandidate = true;
- if ((status == STATUS_ACCEPTED) && (this.sentCandidate)) {
+ if ((mJingleStatus == JINGLE_STATUS_ACCEPTED)
+ && (this.sentCandidate)) {
this.connect();
} else {
Log.d(Config.LOGTAG,
@@ -533,7 +539,7 @@ public class JingleConnection implements Downloadable {
this.sendFallbackToIbb();
}
} else {
- this.status = STATUS_TRANSMITTING;
+ this.mJingleStatus = JINGLE_STATUS_TRANSMITTING;
if (connection.needsActivation()) {
if (connection.getCandidate().isOurs()) {
Log.d(Config.LOGTAG, "candidate "
@@ -620,9 +626,10 @@ public class JingleConnection implements Downloadable {
packet.setReason(reason);
this.sendJinglePacket(packet);
this.disconnect();
- this.status = STATUS_FINISHED;
- this.mXmppConnectionService.markMessage(this.message,
- Message.STATUS_RECEIVED);
+ this.mJingleStatus = JINGLE_STATUS_FINISHED;
+ this.message.setStatus(Message.STATUS_RECEIVED);
+ this.message.setDownloadable(null);
+ this.mXmppConnectionService.updateMessage(message);
this.mJingleConnectionManager.finishConnection(this);
}
@@ -692,7 +699,7 @@ public class JingleConnection implements Downloadable {
}
private void receiveSuccess() {
- this.status = STATUS_FINISHED;
+ this.mJingleStatus = JINGLE_STATUS_FINISHED;
this.mXmppConnectionService.markMessage(this.message,
Message.STATUS_SEND);
this.disconnect();
@@ -700,14 +707,14 @@ public class JingleConnection implements Downloadable {
}
public void cancel() {
- this.status = STATUS_CANCELED;
+ this.mJingleStatus = JINGLE_STATUS_CANCELED;
this.disconnect();
if (this.message != null) {
if (this.responder.equals(account.getFullJid())) {
- this.mXmppConnectionService.markMessage(this.message,
- Message.STATUS_RECEPTION_FAILED);
+ this.mStatus = Downloadable.STATUS_FAILED;
+ this.mXmppConnectionService.updateConversationUi();
} else {
- if (this.status == STATUS_INITIATED) {
+ if (this.mJingleStatus == JINGLE_STATUS_INITIATED) {
this.mXmppConnectionService.markMessage(this.message,
Message.STATUS_SEND_REJECTED);
} else {
@@ -790,7 +797,7 @@ public class JingleConnection implements Downloadable {
.setAttribute("cid", cid);
packet.setContent(content);
this.sentCandidate = true;
- if ((receivedCandidate) && (status == STATUS_ACCEPTED)) {
+ if ((receivedCandidate) && (mJingleStatus == JINGLE_STATUS_ACCEPTED)) {
connect();
}
this.sendJinglePacket(packet);
@@ -803,7 +810,7 @@ public class JingleConnection implements Downloadable {
content.socks5transport().addChild("candidate-error");
packet.setContent(content);
this.sentCandidate = true;
- if ((receivedCandidate) && (status == STATUS_ACCEPTED)) {
+ if ((receivedCandidate) && (mJingleStatus == JINGLE_STATUS_ACCEPTED)) {
connect();
}
this.sendJinglePacket(packet);
@@ -817,8 +824,8 @@ public class JingleConnection implements Downloadable {
return this.responder;
}
- public int getStatus() {
- return this.status;
+ public int getJingleStatus() {
+ return this.mJingleStatus;
}
private boolean equalCandidateExists(JingleCandidate candidate) {
@@ -869,7 +876,7 @@ public class JingleConnection implements Downloadable {
}
public void start() {
- if (status == STATUS_INITIATED) {
+ if (mJingleStatus == JINGLE_STATUS_INITIATED) {
new Thread(new Runnable() {
@Override
@@ -878,7 +885,21 @@ public class JingleConnection implements Downloadable {
}
}).start();
} else {
- Log.d(Config.LOGTAG, "status (" + status + ") was not ok");
+ Log.d(Config.LOGTAG, "status (" + mJingleStatus + ") was not ok");
+ }
+ }
+
+ @Override
+ public int getStatus() {
+ return this.mStatus;
+ }
+
+ @Override
+ public long getFileSize() {
+ if (this.file != null) {
+ return this.file.getExpectedSize();
+ } else {
+ return 0;
}
}
}
diff --git a/src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java b/src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java
index bb360204..40ccbfe3 100644
--- a/src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java
@@ -154,7 +154,7 @@ public class JingleConnectionManager extends AbstractConnectionManager {
public void cancelInTransmission() {
for (JingleConnection connection : this.connections) {
- if (connection.getStatus() == JingleConnection.STATUS_TRANSMITTING) {
+ if (connection.getJingleStatus() == JingleConnection.JINGLE_STATUS_TRANSMITTING) {
connection.cancel();
}
}
diff --git a/src/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java b/src/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java
index e5016935..cc1e92f6 100644
--- a/src/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java
@@ -100,7 +100,8 @@ public class JingleInbandTransport extends JingleTransport {
}
@Override
- public void send(DownloadableFile file, OnFileTransmissionStatusChanged callback) {
+ public void send(DownloadableFile file,
+ OnFileTransmissionStatusChanged callback) {
this.onFileTransmissionStatusChanged = callback;
this.file = file;
try {