diff options
Diffstat (limited to 'libdino')
-rw-r--r-- | libdino/src/entity/file_transfer.vala | 1 | ||||
-rw-r--r-- | libdino/src/service/file_manager.vala | 11 |
2 files changed, 7 insertions, 5 deletions
diff --git a/libdino/src/entity/file_transfer.vala b/libdino/src/entity/file_transfer.vala index 1823478f..20bc1a7a 100644 --- a/libdino/src/entity/file_transfer.vala +++ b/libdino/src/entity/file_transfer.vala @@ -70,6 +70,7 @@ public class FileTransfer : Object { public State state { get; set; default=State.NOT_STARTED; } public int provider { get; set; } public string info { get; set; } + public Cancellable cancellable { get; default=new Cancellable(); } private Database? db; private string storage_dir; diff --git a/libdino/src/service/file_manager.vala b/libdino/src/service/file_manager.vala index a478695c..b82e0afb 100644 --- a/libdino/src/service/file_manager.vala +++ b/libdino/src/service/file_manager.vala @@ -246,7 +246,7 @@ public class FileManager : StreamInteractionModule, Object { File file = File.new_for_path(Path.build_filename(get_storage_dir(), filename)); OutputStream os = file.create(FileCreateFlags.REPLACE_DESTINATION); - yield os.splice_async(input_stream, OutputStreamSpliceFlags.CLOSE_SOURCE|OutputStreamSpliceFlags.CLOSE_TARGET); + yield os.splice_async(input_stream, OutputStreamSpliceFlags.CLOSE_SOURCE | OutputStreamSpliceFlags.CLOSE_TARGET, Priority.LOW, file_transfer.cancellable); file_transfer.path = file.get_basename(); file_transfer.input_stream = yield file.read_async(); @@ -292,14 +292,15 @@ public class FileManager : StreamInteractionModule, Object { if (is_sender_trustworthy(file_transfer, conversation)) { try { yield get_file_meta(file_provider, file_transfer, conversation, receive_data); - - if (file_transfer.size >= 0 && file_transfer.size < 5000000) { - yield download_file_internal(file_provider, file_transfer, conversation); - } } catch (Error e) { warning("Error downloading file: %s", e.message); file_transfer.state = FileTransfer.State.FAILED; } + if (file_transfer.size >= 0 && file_transfer.size < 5000000) { + download_file_internal.begin(file_provider, file_transfer, conversation, (_, res) => { + download_file_internal.end(res); + }); + } } conversation.last_active = file_transfer.time; |