diff options
author | fiaxh <git@lightrise.org> | 2024-12-02 20:42:45 +0100 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2025-01-12 19:35:06 +0100 |
commit | d78ec0562288fa4ed7d414d2269c00b7b8c2c588 (patch) | |
tree | cb93751ba7ddbf883f41c728e6147b85b4a4acac /main | |
parent | d5c280476902d72627c863177a6adcbef4f94f3e (diff) | |
download | dino-d78ec0562288fa4ed7d414d2269c00b7b8c2c588.tar.gz dino-d78ec0562288fa4ed7d414d2269c00b7b8c2c588.zip |
Show file upload/download progress
Diffstat (limited to 'main')
-rw-r--r-- | main/src/ui/conversation_content_view/file_default_widget.vala | 14 | ||||
-rw-r--r-- | main/src/ui/conversation_content_view/file_widget.vala | 5 | ||||
-rw-r--r-- | main/src/ui/file_send_overlay.vala | 2 |
3 files changed, 17 insertions, 4 deletions
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; } |