aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2024-12-02 20:42:45 +0100
committerfiaxh <git@lightrise.org>2025-01-12 19:35:06 +0100
commitd78ec0562288fa4ed7d414d2269c00b7b8c2c588 (patch)
treecb93751ba7ddbf883f41c728e6147b85b4a4acac
parentd5c280476902d72627c863177a6adcbef4f94f3e (diff)
downloaddino-d78ec0562288fa4ed7d414d2269c00b7b8c2c588.tar.gz
dino-d78ec0562288fa4ed7d414d2269c00b7b8c2c588.zip
Show file upload/download progress
-rw-r--r--libdino/src/service/file_manager.vala12
-rw-r--r--libdino/src/service/jingle_file_transfers.vala2
-rw-r--r--main/src/ui/conversation_content_view/file_default_widget.vala14
-rw-r--r--main/src/ui/conversation_content_view/file_widget.vala5
-rw-r--r--main/src/ui/file_send_overlay.vala2
5 files changed, 25 insertions, 10 deletions
diff --git a/libdino/src/service/file_manager.vala b/libdino/src/service/file_manager.vala
index 2a665e1e..fa3042dd 100644
--- a/libdino/src/service/file_manager.vala
+++ b/libdino/src/service/file_manager.vala
@@ -152,6 +152,10 @@ public class FileManager : StreamInteractionModule, Object {
// Update current download progress in the FileTransfer
LimitInputStream? limit_stream = file_transfer.input_stream as LimitInputStream;
+ if (limit_stream == null) {
+ limit_stream = new LimitInputStream(file_transfer.input_stream, file_meta.size);
+ file_transfer.input_stream = limit_stream;
+ }
if (limit_stream != null) {
limit_stream.bind_property("retrieved-bytes", file_transfer, "transferred-bytes", BindingFlags.SYNC_CREATE);
}
@@ -267,9 +271,6 @@ public class FileManager : StreamInteractionModule, Object {
FileMeta file_meta = yield get_file_meta(file_provider, file_transfer, conversation, receive_data);
-
- InputStream? input_stream = null;
-
// Download and decrypt file
file_transfer.state = FileTransfer.State.IN_PROGRESS;
@@ -277,13 +278,14 @@ public class FileManager : StreamInteractionModule, Object {
file_meta = file_decryptor.prepare_download_file(conversation, file_transfer, receive_data, file_meta);
}
- input_stream = yield file_provider.download(file_transfer, receive_data, file_meta);
+ InputStream download_input_stream = yield file_provider.download(file_transfer, receive_data, file_meta);
+ InputStream input_stream = download_input_stream;
if (file_decryptor != null) {
input_stream = yield file_decryptor.decrypt_file(input_stream, conversation, file_transfer, receive_data);
}
// Update current download progress in the FileTransfer
- LimitInputStream? limit_stream = input_stream as LimitInputStream;
+ LimitInputStream? limit_stream = download_input_stream as LimitInputStream;
if (limit_stream != null) {
limit_stream.bind_property("retrieved-bytes", file_transfer, "transferred-bytes", BindingFlags.SYNC_CREATE);
}
diff --git a/libdino/src/service/jingle_file_transfers.vala b/libdino/src/service/jingle_file_transfers.vala
index e0d3fce1..9e9d7ec8 100644
--- a/libdino/src/service/jingle_file_transfers.vala
+++ b/libdino/src/service/jingle_file_transfers.vala
@@ -103,7 +103,7 @@ public class JingleFileProvider : FileProvider, Object {
throw new IOError.FAILED("Transfer data not available anymore");
}
yield jingle_file_transfer.accept(stream);
- return jingle_file_transfer.stream;
+ return new LimitInputStream(jingle_file_transfer.stream, file_meta.size);
}
public int get_id() {
diff --git a/main/src/ui/conversation_content_view/file_default_widget.vala b/main/src/ui/conversation_content_view/file_default_widget.vala
index 02249b3f..aaf36b57 100644
--- a/main/src/ui/conversation_content_view/file_default_widget.vala
+++ b/main/src/ui/conversation_content_view/file_default_widget.vala
@@ -39,7 +39,7 @@ public class FileDefaultWidget : Box {
});
}
- public void update_file_info(string? mime_type, FileTransfer.State state, int64 size) {
+ public void update_file_info(string? mime_type, FileTransfer.State state, bool direction, int64 size, int64 transferred_bytes) {
this.state = state;
spinner.stop(); // A hidden spinning spinner still uses CPU. Deactivate asap
@@ -61,7 +61,17 @@ public class FileDefaultWidget : Box {
popover_menu.closed.connect(on_pointer_left);
break;
case FileTransfer.State.IN_PROGRESS:
- mime_label.label = _("Downloading %s…").printf(get_size_string(size));
+ if (direction == FileTransfer.DIRECTION_RECEIVED) {
+ if (size > 0) {
+ int64 progress = transferred_bytes * 100 / size;
+ mime_label.label = _("Downloading %s… (%u%%)").printf(get_size_string(size), progress);
+ } else {
+ mime_label.label = _("Downloading %s…").printf(get_size_string(size));
+ }
+ } else {
+ int64 progress = transferred_bytes * 100 / size;
+ mime_label.label = _("Uploading %s… (%u%%)").printf(get_size_string(size), progress);
+ }
spinner.start();
image_stack.set_visible_child_name("spinner");
diff --git a/main/src/ui/conversation_content_view/file_widget.vala b/main/src/ui/conversation_content_view/file_widget.vala
index 583609d2..1cf84eb4 100644
--- a/main/src/ui/conversation_content_view/file_widget.vala
+++ b/main/src/ui/conversation_content_view/file_widget.vala
@@ -196,6 +196,7 @@ public class FileDefaultWidgetController : Object {
private FileTransfer? file_transfer;
public string file_transfer_state { get; set; }
public string file_transfer_mime_type { get; set; }
+ public int64 file_transfer_transferred_bytes { get; set; }
private FileTransfer.State state;
@@ -206,6 +207,7 @@ public class FileDefaultWidgetController : Object {
this.notify["file-transfer-state"].connect(update_file_info);
this.notify["file-transfer-mime-type"].connect(update_file_info);
+ this.notify["file-transfer-transferred-bytes"].connect(update_file_info);
}
public void set_file_transfer(FileTransfer file_transfer) {
@@ -215,13 +217,14 @@ public class FileDefaultWidgetController : Object {
file_transfer.bind_property("state", this, "file-transfer-state");
file_transfer.bind_property("mime-type", this, "file-transfer-mime-type");
+ file_transfer.bind_property("transferred-bytes", this, "file-transfer-transferred-bytes");
update_file_info();
}
private void update_file_info() {
state = file_transfer.state;
- widget.update_file_info(file_transfer.mime_type, file_transfer.state, file_transfer.size);
+ widget.update_file_info(file_transfer.mime_type, file_transfer.state, file_transfer.direction, file_transfer.size, file_transfer.transferred_bytes);
}
private void on_clicked() {
diff --git a/main/src/ui/file_send_overlay.vala b/main/src/ui/file_send_overlay.vala
index 11bd9a11..992ab92e 100644
--- a/main/src/ui/file_send_overlay.vala
+++ b/main/src/ui/file_send_overlay.vala
@@ -81,7 +81,7 @@ public class FileSendOverlay {
if (widget == null) {
FileDefaultWidget default_widget = new FileDefaultWidget();
default_widget.name_label.label = file_name;
- default_widget.update_file_info(mime_type, FileTransfer.State.COMPLETE, (long)file_info.get_size());
+ default_widget.update_file_info(mime_type, FileTransfer.State.COMPLETE, FileTransfer.DIRECTION_SENT, (long)file_info.get_size(), 0);
widget = default_widget;
}