aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/conversation_content_view/file_image_widget.vala
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2024-12-27 16:43:36 +0100
committerMarvin W <git@larma.de>2024-12-27 16:44:22 +0100
commitb3976246ec0918e93ffb4a154913ab33229ebdc7 (patch)
tree0d726d6832cc73c3995260a244cd4dc2742c9a79 /main/src/ui/conversation_content_view/file_image_widget.vala
parent045e55535758ffce5958ac8436ddc9d952cfe052 (diff)
downloaddino-b3976246ec0918e93ffb4a154913ab33229ebdc7.tar.gz
dino-b3976246ec0918e93ffb4a154913ab33229ebdc7.zip
Fix memory leak when displaying image files
Diffstat (limited to 'main/src/ui/conversation_content_view/file_image_widget.vala')
-rw-r--r--main/src/ui/conversation_content_view/file_image_widget.vala30
1 files changed, 20 insertions, 10 deletions
diff --git a/main/src/ui/conversation_content_view/file_image_widget.vala b/main/src/ui/conversation_content_view/file_image_widget.vala
index d5415f31..1c8d4c02 100644
--- a/main/src/ui/conversation_content_view/file_image_widget.vala
+++ b/main/src/ui/conversation_content_view/file_image_widget.vala
@@ -63,25 +63,30 @@ public class FileImageWidget : Box {
EventControllerMotion this_motion_events = new EventControllerMotion();
this.add_controller(this_motion_events);
- this_motion_events.enter.connect(() => {
- image_overlay_toolbar.visible = show_image_overlay_toolbar;
- file_size_label.visible = file_transfer != null && file_transfer.direction == FileTransfer.DIRECTION_RECEIVED && file_transfer.state == FileTransfer.State.NOT_STARTED && !file_transfer.sfs_sources.is_empty;
+ this_motion_events.enter.connect((controller, x, y) => {
+ (controller.widget as FileImageWidget).on_motion_event_enter();
});
- this_motion_events.leave.connect(() => {
+ attach_on_motion_event_leave(this_motion_events, button);
+ }
+
+ private static void attach_on_motion_event_leave(EventControllerMotion this_motion_events, MenuButton button) {
+ this_motion_events.leave.connect((controller) => {
if (button.popover != null && button.popover.visible) return;
- image_overlay_toolbar.visible = false;
- file_size_label.visible = false;
+ (controller.widget as FileImageWidget).image_overlay_toolbar.visible = false;
+ (controller.widget as FileImageWidget).file_size_label.visible = false;
});
}
+ private void on_motion_event_enter() {
+ image_overlay_toolbar.visible = show_image_overlay_toolbar;
+ file_size_label.visible = file_transfer != null && file_transfer.direction == FileTransfer.DIRECTION_RECEIVED && file_transfer.state == FileTransfer.State.NOT_STARTED && !file_transfer.sfs_sources.is_empty;
+ }
+
public async void set_file_transfer(FileTransfer file_transfer) {
this.file_transfer = file_transfer;
- this.file_transfer.bind_property("size", file_size_label, "label", BindingFlags.SYNC_CREATE, (_, from_value, ref to_value) => {
- to_value = FileDefaultWidget.get_size_string((int64) from_value);
- return true;
- });
+ this.file_transfer.bind_property("size", file_size_label, "label", BindingFlags.SYNC_CREATE, file_size_label_transform);
this.file_transfer.bind_property("size", transmission_progress, "file-size", BindingFlags.SYNC_CREATE);
this.file_transfer.bind_property("transferred-bytes", transmission_progress, "transferred-size");
@@ -90,6 +95,11 @@ public class FileImageWidget : Box {
refresh_state();
}
+ private static bool file_size_label_transform(Binding binding, Value from_value, ref Value to_value) {
+ to_value = FileDefaultWidget.get_size_string((int64) from_value);
+ return true;
+ }
+
private void refresh_state() {
if ((state == EMPTY || state == PREVIEW) && file_transfer.path != null) {
if (state == EMPTY) {