aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/entities
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-11-13 21:04:05 +0100
committeriNPUTmice <daniel@gultsch.de>2014-11-15 15:34:11 +0100
commit7a90ca429bb46fae4cbd600bd4c2274f4a731a16 (patch)
tree0ec0d753e32f0c361e43bf2bac627bda39a7899d /src/main/java/eu/siacs/conversations/entities
parent4c504dea7ac7b0413df89ec630408b91f4abddb4 (diff)
basic arbitrary file transfer
Diffstat (limited to 'src/main/java/eu/siacs/conversations/entities')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Downloadable.java6
-rw-r--r--src/main/java/eu/siacs/conversations/entities/DownloadableFile.java12
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Message.java25
3 files changed, 36 insertions, 7 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Downloadable.java b/src/main/java/eu/siacs/conversations/entities/Downloadable.java
index e4c85336..cc0dc157 100644
--- a/src/main/java/eu/siacs/conversations/entities/Downloadable.java
+++ b/src/main/java/eu/siacs/conversations/entities/Downloadable.java
@@ -2,7 +2,7 @@ package eu.siacs.conversations.entities;
public interface Downloadable {
- public final String[] VALID_EXTENSIONS = {"webp", "jpeg", "jpg", "png", "jpe"};
+ public final String[] VALID_IMAGE_EXTENSIONS = {"webp", "jpeg", "jpg", "png", "jpe"};
public final String[] VALID_CRYPTO_EXTENSIONS = {"pgp", "gpg", "otr"};
public static final int STATUS_UNKNOWN = 0x200;
@@ -18,4 +18,8 @@ public interface Downloadable {
public int getStatus();
public long getFileSize();
+
+ public int getProgress();
+
+ public String getMimeType();
}
diff --git a/src/main/java/eu/siacs/conversations/entities/DownloadableFile.java b/src/main/java/eu/siacs/conversations/entities/DownloadableFile.java
index 1605c75b..6aff643a 100644
--- a/src/main/java/eu/siacs/conversations/entities/DownloadableFile.java
+++ b/src/main/java/eu/siacs/conversations/entities/DownloadableFile.java
@@ -6,6 +6,7 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
+import java.net.URLConnection;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
@@ -28,6 +29,7 @@ public class DownloadableFile extends File {
private long expectedSize = 0;
private String sha1sum;
private Key aeskey;
+ private String mime;
private byte[] iv = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0xf };
@@ -52,6 +54,16 @@ public class DownloadableFile extends File {
}
}
+ public String getMimeType() {
+ if (mime==null) {
+ mime = URLConnection.guessContentTypeFromName(this.getAbsolutePath());
+ if (mime == null) {
+ mime = "";
+ }
+ }
+ return mime;
+ }
+
public void setExpectedSize(long size) {
this.expectedSize = size;
}
diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java
index 5b44435e..33f3443b 100644
--- a/src/main/java/eu/siacs/conversations/entities/Message.java
+++ b/src/main/java/eu/siacs/conversations/entities/Message.java
@@ -32,7 +32,7 @@ public class Message extends AbstractEntity {
public static final int TYPE_TEXT = 0;
public static final int TYPE_IMAGE = 1;
- public static final int TYPE_AUDIO = 2;
+ public static final int TYPE_FILE = 2;
public static final int TYPE_STATUS = 3;
public static final int TYPE_PRIVATE = 4;
@@ -45,6 +45,7 @@ public class Message extends AbstractEntity {
public static String STATUS = "status";
public static String TYPE = "type";
public static String REMOTE_MSG_ID = "remoteMsgId";
+ public static String RELATIVE_FILE_PATH = "relativeFilePath";
public boolean markable = false;
protected String conversationUuid;
protected Jid counterpart;
@@ -55,6 +56,7 @@ public class Message extends AbstractEntity {
protected int encryption;
protected int status;
protected int type;
+ protected String relativeFilePath;
protected boolean read = true;
protected String remoteMsgId = null;
protected Conversation conversation = null;
@@ -74,13 +76,13 @@ public class Message extends AbstractEntity {
this(java.util.UUID.randomUUID().toString(), conversation.getUuid(),
conversation.getContactJid().toBareJid(), null, body, System
.currentTimeMillis(), encryption,
- status, TYPE_TEXT, null);
+ status, TYPE_TEXT, null,null);
this.conversation = conversation;
}
public Message(final String uuid, final String conversationUUid, final Jid counterpart,
final String trueCounterpart, final String body, final long timeSent,
- final int encryption, final int status, final int type, final String remoteMsgId) {
+ final int encryption, final int status, final int type, final String remoteMsgId, final String relativeFilePath) {
this.uuid = uuid;
this.conversationUuid = conversationUUid;
this.counterpart = counterpart;
@@ -91,6 +93,7 @@ public class Message extends AbstractEntity {
this.status = status;
this.type = type;
this.remoteMsgId = remoteMsgId;
+ this.relativeFilePath = relativeFilePath;
}
public static Message fromCursor(Cursor cursor) {
@@ -114,7 +117,8 @@ public class Message extends AbstractEntity {
cursor.getInt(cursor.getColumnIndex(ENCRYPTION)),
cursor.getInt(cursor.getColumnIndex(STATUS)),
cursor.getInt(cursor.getColumnIndex(TYPE)),
- cursor.getString(cursor.getColumnIndex(REMOTE_MSG_ID)));
+ cursor.getString(cursor.getColumnIndex(REMOTE_MSG_ID)),
+ cursor.getString(cursor.getColumnIndex(RELATIVE_FILE_PATH)));
}
public static Message createStatusMessage(Conversation conversation) {
@@ -141,6 +145,7 @@ public class Message extends AbstractEntity {
values.put(STATUS, status);
values.put(TYPE, type);
values.put(REMOTE_MSG_ID, remoteMsgId);
+ values.put(RELATIVE_FILE_PATH, relativeFilePath);
return values;
}
@@ -205,6 +210,14 @@ public class Message extends AbstractEntity {
this.status = status;
}
+ public void setRelativeFilePath(String path) {
+ this.relativeFilePath = path;
+ }
+
+ public String getRelativeFilePath() {
+ return this.relativeFilePath;
+ }
+
public String getRemoteMsgId() {
return this.remoteMsgId;
}
@@ -376,14 +389,14 @@ public class Message extends AbstractEntity {
}
String[] extensionParts = filename.split("\\.");
if (extensionParts.length == 2
- && Arrays.asList(Downloadable.VALID_EXTENSIONS).contains(
+ && Arrays.asList(Downloadable.VALID_IMAGE_EXTENSIONS).contains(
extensionParts[extensionParts.length - 1])) {
return true;
} else if (extensionParts.length == 3
&& Arrays
.asList(Downloadable.VALID_CRYPTO_EXTENSIONS)
.contains(extensionParts[extensionParts.length - 1])
- && Arrays.asList(Downloadable.VALID_EXTENSIONS).contains(
+ && Arrays.asList(Downloadable.VALID_IMAGE_EXTENSIONS).contains(
extensionParts[extensionParts.length - 2])) {
return true;
} else {