aboutsummaryrefslogtreecommitdiff
path: root/libdino
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2022-03-30 10:36:52 -0600
committerMarvin W <git@larma.de>2022-03-30 10:36:52 -0600
commit193bf38a790b2a124493c3b7ad591f826e0f773d (patch)
tree2568a9d2d4bad3f0c105a3fa23069a7cf1e56a72 /libdino
parent339d1d8f557e88ef6bb5812980b8988dc8fdf10d (diff)
downloaddino-193bf38a790b2a124493c3b7ad591f826e0f773d.tar.gz
dino-193bf38a790b2a124493c3b7ad591f826e0f773d.zip
Allow cancellation of file transfers
Diffstat (limited to 'libdino')
-rw-r--r--libdino/src/entity/file_transfer.vala1
-rw-r--r--libdino/src/service/file_manager.vala11
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;