commit c93a05d13a8ee20fb55994210e26d57e2f017f74
parent 4a798618d5d59449d139ae3c1b8452be5bddffca
Author: Jacki <jacki@thejackimonster.de>
Date: Wed, 13 Mar 2024 01:47:53 +0100
Update file messages on download completion
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
2 files changed, 45 insertions(+), 10 deletions(-)
diff --git a/src/file.c b/src/file.c
@@ -32,6 +32,9 @@ file_create_info(struct GNUNET_CHAT_File *file)
MESSENGER_FileInfo* info = g_malloc(sizeof(MESSENGER_FileInfo));
+ info->app = NULL;
+
+ info->update_task = 0;
info->file_messages = NULL;
GNUNET_CHAT_file_set_user_pointer(file, info);
@@ -47,6 +50,9 @@ file_destroy_info(struct GNUNET_CHAT_File *file)
if (!info)
return;
+ if (info->update_task)
+ g_source_remove(info->update_task);
+
if (info->file_messages)
g_list_free(info->file_messages);
@@ -94,6 +100,29 @@ file_update_upload_info(const struct GNUNET_CHAT_File *file,
}
}
+static gboolean
+file_update_messages(gpointer user_data)
+{
+ g_assert(user_data);
+
+ MESSENGER_FileInfo* info = (MESSENGER_FileInfo*) user_data;
+
+ info->update_task = 0;
+
+ GList *list = info->file_messages;
+
+ while (list)
+ {
+ UI_MESSAGE_Handle *message = (UI_MESSAGE_Handle*) list->data;
+
+ ui_message_update(message, info->app, message->msg);
+
+ list = list->next;
+ }
+
+ return FALSE;
+}
+
void
file_update_download_info(const struct GNUNET_CHAT_File *file,
MESSENGER_Application *app,
@@ -116,9 +145,12 @@ file_update_download_info(const struct GNUNET_CHAT_File *file,
1.0 * completed / size
);
- if (completed >= size)
- ui_message_update(message, app, NULL);
-
list = list->next;
}
+
+ if ((completed < size) || (info->update_task))
+ return;
+
+ info->app = app;
+ info->update_task = g_idle_add(file_update_messages, info);
}
diff --git a/src/file.h b/src/file.h
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2022 GNUnet e.V.
+ Copyright (C) 2022--2024 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
@@ -30,6 +30,9 @@
typedef struct MESSENGER_FileInfo
{
+ MESSENGER_Application *app;
+
+ guint update_task;
GList *file_messages;
} MESSENGER_FileInfo;
@@ -60,7 +63,7 @@ file_destroy_info(struct GNUNET_CHAT_File *file);
*/
void
file_add_ui_message_to_info(const struct GNUNET_CHAT_File *file,
- UI_MESSAGE_Handle *message);
+ UI_MESSAGE_Handle *message);
/**
* Updates the connected UI elements for a given
@@ -73,8 +76,8 @@ file_add_ui_message_to_info(const struct GNUNET_CHAT_File *file,
*/
void
file_update_upload_info(const struct GNUNET_CHAT_File *file,
- uint64_t completed,
- uint64_t size);
+ uint64_t completed,
+ uint64_t size);
/**
* Updates the connected UI elements for a given
@@ -88,8 +91,8 @@ file_update_upload_info(const struct GNUNET_CHAT_File *file,
*/
void
file_update_download_info(const struct GNUNET_CHAT_File *file,
- MESSENGER_Application *app,
- uint64_t completed,
- uint64_t size);
+ MESSENGER_Application *app,
+ uint64_t completed,
+ uint64_t size);
#endif /* FILE_H_ */