diff options
author | Marvin W <git@larma.de> | 2022-03-30 10:36:52 -0600 |
---|---|---|
committer | Marvin W <git@larma.de> | 2022-03-30 10:36:52 -0600 |
commit | 193bf38a790b2a124493c3b7ad591f826e0f773d (patch) | |
tree | 2568a9d2d4bad3f0c105a3fa23069a7cf1e56a72 /main/src/ui/conversation_content_view | |
parent | 339d1d8f557e88ef6bb5812980b8988dc8fdf10d (diff) | |
download | dino-193bf38a790b2a124493c3b7ad591f826e0f773d.tar.gz dino-193bf38a790b2a124493c3b7ad591f826e0f773d.zip |
Allow cancellation of file transfers
Diffstat (limited to 'main/src/ui/conversation_content_view')
-rw-r--r-- | main/src/ui/conversation_content_view/file_default_widget.vala | 16 | ||||
-rw-r--r-- | main/src/ui/conversation_content_view/file_widget.vala | 5 |
2 files changed, 20 insertions, 1 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 28b7d477..638dab15 100644 --- a/main/src/ui/conversation_content_view/file_default_widget.vala +++ b/main/src/ui/conversation_content_view/file_default_widget.vala @@ -19,6 +19,7 @@ public class FileDefaultWidget : EventBox { public ModelButton file_open_button; public ModelButton file_save_button; + public ModelButton cancel_button; private FileTransfer.State state; @@ -27,6 +28,7 @@ public class FileDefaultWidget : EventBox { this.leave_notify_event.connect(on_pointer_left_event); file_open_button = new ModelButton() { text=_("Open"), visible=true }; file_save_button = new ModelButton() { text=_("Save as…"), visible=true }; + cancel_button = new ModelButton() { text=_("Cancel"), visible=true }; } public void update_file_info(string? mime_type, FileTransfer.State state, long size) { @@ -59,6 +61,18 @@ public class FileDefaultWidget : EventBox { mime_label.label = _("Downloading %s…").printf(get_size_string(size)); spinner.active = true; image_stack.set_visible_child_name("spinner"); + + // Create a menu + Gtk.PopoverMenu popover_menu = new Gtk.PopoverMenu(); + Box file_menu_box = new Box(Orientation.VERTICAL, 0) { margin=10, visible=true }; + file_menu_box.add(cancel_button); + popover_menu.add(file_menu_box); + file_menu.popover = popover_menu; + file_menu.button_release_event.connect(() => { + popover_menu.visible = true; + return true; + }); + popover_menu.closed.connect(on_pointer_left); break; case FileTransfer.State.NOT_STARTED: if (mime_description != null) { @@ -84,7 +98,7 @@ public class FileDefaultWidget : EventBox { if (state == FileTransfer.State.NOT_STARTED) { image_stack.set_visible_child_name("download_image"); } - if (state == FileTransfer.State.COMPLETE) { + if (state == FileTransfer.State.COMPLETE || state == FileTransfer.State.IN_PROGRESS) { file_menu.opacity = 1; } return false; diff --git a/main/src/ui/conversation_content_view/file_widget.vala b/main/src/ui/conversation_content_view/file_widget.vala index 0040db3c..b63195dc 100644 --- a/main/src/ui/conversation_content_view/file_widget.vala +++ b/main/src/ui/conversation_content_view/file_widget.vala @@ -131,6 +131,7 @@ public class FileDefaultWidgetController : Object { widget.button_release_event.connect(on_clicked); widget.file_open_button.clicked.connect(open_file); widget.file_save_button.clicked.connect(save_file); + widget.cancel_button.clicked.connect(cancel_download); } public void set_file_transfer(FileTransfer file_transfer, StreamInteractor stream_interactor) { @@ -186,6 +187,10 @@ public class FileDefaultWidgetController : Object { } } + private void cancel_download() { + file_transfer.cancellable.cancel(); + } + private bool on_clicked(EventButton event_button) { switch (state) { case FileTransfer.State.COMPLETE: |