aboutsummaryrefslogtreecommitdiff
path: root/plugins/http-files/src
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-11-24 00:38:09 +0100
committerfiaxh <git@mx.ax.lt>2017-11-27 22:17:36 +0100
commit1e011852e00efa9d4d3547d2ca37e395da1070c6 (patch)
treea1d2fc5d26fc987d0a99279ebef3a458db828dab /plugins/http-files/src
parent2f6878a523ebf563e6fb11a5745905e07dc4a355 (diff)
downloaddino-1e011852e00efa9d4d3547d2ca37e395da1070c6.tar.gz
dino-1e011852e00efa9d4d3547d2ca37e395da1070c6.zip
http-files: async file download
Diffstat (limited to 'plugins/http-files/src')
-rw-r--r--plugins/http-files/src/file_provider.vala61
1 files changed, 32 insertions, 29 deletions
diff --git a/plugins/http-files/src/file_provider.vala b/plugins/http-files/src/file_provider.vala
index 58ff6445..aa8a6357 100644
--- a/plugins/http-files/src/file_provider.vala
+++ b/plugins/http-files/src/file_provider.vala
@@ -39,37 +39,40 @@ public class FileProvider : Dino.FileProvider, Object {
var session = new Soup.Session();
var head_message = new Soup.Message("HEAD", message.body);
if (head_message != null) {
- session.send_message(head_message);
- string? content_type = null, content_length = null;
- print(message.body + ":\n");
- head_message.response_headers.foreach((name, val) => {
- print(name + " " + val + "\n");
- if (name == "Content-Type") content_type = val;
- if (name == "Content-Length") content_length = val;
- });
- if (/*content_type != null && content_type.has_prefix("image") &&*/ content_length != null && int.parse(content_length) < 5000000) {
- FileTransfer file_transfer = new FileTransfer();
- try {
+ session.send_async.begin(head_message, null, (obj, res) => {
+ string? content_type = null, content_length = null;
+ print(message.body + ":\n");
+ head_message.response_headers.foreach((name, val) => {
+ print(name + " " + val + "\n");
+ if (name == "Content-Type") content_type = val;
+ if (name == "Content-Length") content_length = val;
+ });
+ if (/*content_type != null && content_type.has_prefix("image") &&*/ content_length != null && int.parse(content_length) < 5000000) {
+ FileTransfer file_transfer = new FileTransfer();
Soup.Request request = session.request(message.body);
- file_transfer.input_stream = request.send();
- } catch (Error e) {
- return;
+ request.send_async.begin(null, (obj, res) => {
+ try {
+ file_transfer.input_stream = request.send_async.end(res);
+ } catch (Error e) {
+ return;
+ }
+ file_transfer.account = conversation.account;
+ file_transfer.counterpart = message.counterpart;
+ file_transfer.ourpart = message.ourpart;
+ file_transfer.encryption = Encryption.NONE;
+ file_transfer.time = message.time;
+ file_transfer.local_time = message.local_time;
+ file_transfer.direction = message.direction;
+ file_transfer.file_name = message.body.substring(message.body.last_index_of("/") + 1);
+ file_transfer.mime_type = content_type;
+ file_transfer.size = int.parse(content_length);
+ file_transfer.state = FileTransfer.State.NOT_STARTED;
+ file_transfer.provider = 0;
+ file_transfer.info = message.body;
+ file_incoming(file_transfer);
+ });
}
- file_transfer.account = conversation.account;
- file_transfer.counterpart = message.counterpart;
- file_transfer.ourpart = message.ourpart;
- file_transfer.encryption = Encryption.NONE;
- file_transfer.time = message.time;
- file_transfer.local_time = message.local_time;
- file_transfer.direction = message.direction;
- file_transfer.file_name = message.body.substring(message.body.last_index_of("/") + 1);
- file_transfer.mime_type = content_type;
- file_transfer.size = int.parse(content_length);
- file_transfer.state = FileTransfer.State.NOT_STARTED;
- file_transfer.provider = 0;
- file_transfer.info = message.body;
- file_incoming(file_transfer);
- }
+ });
}
}
}