messenger-gtk

Gtk+3 graphical user interfaces for GNUnet Messenger
Log | Files | Refs | Submodules | README | LICENSE

commit 17392fe6169d39a75645728f44aa117f67b5331d
parent 9ff0f0e2e8d554f465d7aad51ce7fb33e61a749c
Author: Jacki <jacki@thejackimonster.de>
Date:   Wed, 14 Feb 2024 13:44:06 +0100

Add asserts to verify reliability

Signed-off-by: Jacki <jacki@thejackimonster.de>

Diffstat:
Msrc/application.c | 55+++++++++++++++++++++++++++++++++++++++++++++++++------
Msrc/application.h | 22+++++++++++-----------
Msrc/chat/messenger.c | 18+++++++++++++-----
Msrc/contact.c | 18++++++++++++++----
Msrc/event.c | 52++++++++++++++++++++++++++--------------------------
Msrc/event.h | 30+++++++++++++++---------------
Msrc/file.c | 24++++++++++++++----------
Msrc/request.c | 20++++++++++++++++++++
Msrc/ui.c | 8+++++++-
Msrc/ui.h | 11+++++++----
Msrc/ui/about.c | 54+++++++++++++++++++++++++++++++-----------------------
Msrc/ui/about.h | 4++--
Msrc/ui/account_entry.c | 22+++++++++++++++-------
Msrc/ui/account_entry.h | 6+++---
Msrc/ui/accounts.c | 18++++++++++++++++++
Msrc/ui/chat.c | 85+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
Msrc/ui/chat.h | 16++++++++--------
Msrc/ui/chat_entry.c | 8+++++++-
Msrc/ui/chat_entry.h | 8++++----
Msrc/ui/contact_entry.c | 19++++++++++++-------
Msrc/ui/contact_entry.h | 4++--
Msrc/ui/contact_info.c | 38+++++++++++++++++++++++++++++++++-----
Msrc/ui/contact_info.h | 6+++---
Msrc/ui/contacts.c | 101++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
Msrc/ui/contacts.h | 4++--
Msrc/ui/delete_messages.c | 67+++++++++++++++++++++++++++++++++++++++----------------------------
Msrc/ui/delete_messages.h | 16+++++++++-------
Msrc/ui/file_load_entry.c | 10++++++++--
Msrc/ui/invite_contact.c | 125++++++++++++++++++++++++++++++++++++++++++++-----------------------------------
Msrc/ui/invite_contact.h | 4++--
Msrc/ui/message.c | 28++++++++++++++--------------
Msrc/ui/message.h | 8++++----
Msrc/ui/messenger.c | 53+++++++++++++++++++++++++++++++++++++++++++++++++----
Msrc/ui/messenger.h | 8++++----
Msrc/ui/new_account.c | 93+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
Msrc/ui/new_account.h | 4++--
Msrc/ui/new_contact.c | 36+++++++++++++++++++++++++++++++-----
Msrc/ui/new_contact.h | 2+-
Msrc/ui/new_group.c | 154++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
Msrc/ui/new_group.h | 4++--
Msrc/ui/new_lobby.c | 221+++++++++++++++++++++++++++++++++++++++++++------------------------------------
Msrc/ui/new_lobby.h | 4++--
Msrc/ui/new_platform.c | 95++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
Msrc/ui/new_platform.h | 4++--
Msrc/ui/picker.c | 16++++++++++++++++
Msrc/ui/picker.h | 4++--
Msrc/ui/play_media.c | 201+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
Msrc/ui/play_media.h | 6+++---
Msrc/ui/send_file.c | 147+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
Msrc/ui/send_file.h | 6+++---
Msrc/ui/settings.c | 32+++++++++++++++++++++++++++++---
Msrc/ui/settings.h | 2+-
52 files changed, 1266 insertions(+), 735 deletions(-)

diff --git a/src/application.c b/src/application.c @@ -36,6 +36,8 @@ static void _load_ui_stylesheets(MESSENGER_Application *app) { + g_assert(app); + GdkScreen* screen = gdk_screen_get_default(); GtkCssProvider* provider = gtk_css_provider_new(); @@ -54,6 +56,8 @@ _load_ui_stylesheets(MESSENGER_Application *app) static gboolean _application_accounts(gpointer user_data) { + g_assert(user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; app->init = 0; @@ -68,6 +72,8 @@ _application_accounts(gpointer user_data) static void _application_init(MESSENGER_Application *app) { + g_assert(app); + ui_messenger_init(app, &(app->ui.messenger)); if (app->portal) @@ -83,6 +89,8 @@ static void _application_activate(GApplication* application, gpointer user_data) { + g_assert((application) && (user_data)); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; g_application_hold(application); @@ -99,6 +107,8 @@ _application_open(GApplication* application, UNUSED gchar* hint, gpointer user_data) { + g_assert((application) && (files) && (user_data)); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; g_application_hold(application); @@ -141,6 +151,8 @@ on_core_done(void *data, UNUSED uint32_t id, int seq) { + g_assert(data); + MESSENGER_Application *app = (MESSENGER_Application*) data; if (seq == app->pw.pending) @@ -150,15 +162,17 @@ on_core_done(void *data, static void on_core_error(void *data, UNUSED uint32_t id, - int seq, + UNUSED int seq, int res, const char *message) { + g_assert((data) && (message)); + MESSENGER_Application *app = (MESSENGER_Application*) data; g_printerr("ERROR: %s\n", message); - if (id == PW_ID_CORE && res == -EPIPE) + if ((id == PW_ID_CORE) && (res == -EPIPE)) pw_main_loop_quit(app->pw.main_loop); } @@ -176,6 +190,8 @@ registry_event_global(void *data, uint32_t version, const struct spa_dict *props) { + g_assert(data); + MESSENGER_Application *app = (MESSENGER_Application*) data; if (!props) @@ -198,6 +214,8 @@ static void registry_event_global_remove(void *data, uint32_t id) { + g_assert(data); + MESSENGER_Application *app = (MESSENGER_Application*) data; struct pw_properties *properties = pw_map_lookup(&(app->pw.globals), id); @@ -219,6 +237,8 @@ application_init(MESSENGER_Application *app, int argc, char **argv) { + g_assert((app) && (argv)); + memset(app, 0, sizeof(*app)); app->argc = argc; @@ -339,6 +359,8 @@ const gchar* application_get_resource_path(MESSENGER_Application *app, const char *path) { + g_assert((app) && (path)); + static gchar resource_path [PATH_MAX]; const gchar *base_path = g_application_get_resource_base_path( @@ -352,6 +374,8 @@ application_get_resource_path(MESSENGER_Application *app, static void* _application_chat_thread(void *args) { + g_assert(args); + MESSENGER_Application *app = (MESSENGER_Application*) args; struct GNUNET_GETOPT_CommandLineOption options[] = { @@ -387,6 +411,8 @@ _application_chat_thread(void *args) void application_run(MESSENGER_Application *app) { + g_assert(app); + // Start thread to run GNUnet scheduler pthread_create( &(app->chat.tid), @@ -457,6 +483,8 @@ _request_background_callback(GObject *source_object, GAsyncResult *result, gpointer user_data) { + g_assert((source_object) && (result) && (user_data)); + XdpPortal *portal = XDP_PORTAL(source_object); MESSENGER_Request *request = (MESSENGER_Request*) user_data; @@ -482,6 +510,8 @@ _request_background_callback(GObject *source_object, void application_show_window(MESSENGER_Application *app) { + g_assert(app); + gtk_widget_show(GTK_WIDGET(app->ui.messenger.main_window)); request_new_background( @@ -508,6 +538,8 @@ typedef struct MESSENGER_ApplicationEventCall static gboolean _application_event_call(gpointer user_data) { + g_assert(user_data); + MESSENGER_ApplicationEventCall *call; call = (MESSENGER_ApplicationEventCall*) user_data; @@ -525,6 +557,8 @@ void application_call_event(MESSENGER_Application *app, MESSENGER_ApplicationEvent event) { + g_assert((app) && (event)); + MESSENGER_ApplicationEventCall *call; call = (MESSENGER_ApplicationEventCall*) GNUNET_malloc( @@ -549,6 +583,8 @@ typedef struct MESSENGER_ApplicationMessageEventCall static gboolean _application_message_event_call(gpointer user_data) { + g_assert(user_data); + MESSENGER_ApplicationMessageEventCall *call; call = (MESSENGER_ApplicationMessageEventCall*) user_data; @@ -568,10 +604,9 @@ application_call_message_event(MESSENGER_Application *app, struct GNUNET_CHAT_Context *context, const struct GNUNET_CHAT_Message *message) { - MESSENGER_ApplicationMessageEventCall *call; + g_assert((app) && (event) && (message)); - if (!event) - return; + MESSENGER_ApplicationMessageEventCall *call; call = (MESSENGER_ApplicationMessageEventCall*) GNUNET_malloc( sizeof(MESSENGER_ApplicationMessageEventCall) @@ -588,9 +623,13 @@ application_call_message_event(MESSENGER_Application *app, static int destroy_global(void *obj, - void *data) + UNUSED void *data) { struct pw_properties *properties = (struct pw_properties*) obj; + + if (!properties) + return 0; + pw_properties_free(properties); return 0; } @@ -599,6 +638,8 @@ void application_exit(MESSENGER_Application *app, MESSENGER_ApplicationSignal signal) { + g_assert(app); + // Forward a signal to the other thread causing it to shutdown the // GNUnet handles of the application. write(app->chat.pipe[1], &signal, sizeof(signal)); @@ -635,6 +676,8 @@ application_exit(MESSENGER_Application *app, int application_status(MESSENGER_Application *app) { + g_assert(app); + if (EXIT_SUCCESS != app->chat.status) return app->chat.status; diff --git a/src/application.h b/src/application.h @@ -164,8 +164,8 @@ typedef struct MESSENGER_Application */ void application_init(MESSENGER_Application *app, - int argc, - char **argv); + int argc, + char **argv); /** * Returns the path from resources of the @@ -177,7 +177,7 @@ application_init(MESSENGER_Application *app, */ const gchar* application_get_resource_path(MESSENGER_Application *app, - const char *path); + const char *path); /** * Runs the messenger application starting the @@ -198,13 +198,13 @@ void application_show_window(MESSENGER_Application *app); typedef void (*MESSENGER_ApplicationEvent) ( - MESSENGER_Application *app + MESSENGER_Application *app ); typedef void (*MESSENGER_ApplicationMessageEvent) ( - MESSENGER_Application *app, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *msg + MESSENGER_Application *app, + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *msg ); /** @@ -216,7 +216,7 @@ typedef void (*MESSENGER_ApplicationMessageEvent) ( */ void application_call_event(MESSENGER_Application *app, - MESSENGER_ApplicationEvent event); + MESSENGER_ApplicationEvent event); /** * Calls a given message event with the messenger @@ -230,8 +230,8 @@ application_call_event(MESSENGER_Application *app, */ void application_call_message_event(MESSENGER_Application *app, - MESSENGER_ApplicationMessageEvent event, - struct GNUNET_CHAT_Context *context, + MESSENGER_ApplicationMessageEvent event, + struct GNUNET_CHAT_Context *context, const struct GNUNET_CHAT_Message *message); /** @@ -242,7 +242,7 @@ application_call_message_event(MESSENGER_Application *app, */ void application_exit(MESSENGER_Application *app, - MESSENGER_ApplicationSignal signal); + MESSENGER_ApplicationSignal signal); /** * Returns the exit status of the messenger application. diff --git a/src/chat/messenger.c b/src/chat/messenger.c @@ -30,6 +30,8 @@ static void _chat_messenger_quit(void *cls) { + g_assert(cls); + MESSENGER_Application *app = (MESSENGER_Application*) cls; if (app->chat.messenger.idle) @@ -51,6 +53,8 @@ _chat_messenger_quit(void *cls) static void _chat_messenger_idle(void *cls) { + g_assert(cls); + MESSENGER_Application *app = (MESSENGER_Application*) cls; // Idling until the application shuts down @@ -65,9 +69,11 @@ _chat_messenger_idle(void *cls) static int _chat_messenger_message(void *cls, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *message) + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *message) { + g_assert((cls) && (message)); + MESSENGER_Application *app = (MESSENGER_Application*) cls; // Locking the mutex for synchronization @@ -184,10 +190,12 @@ _chat_messenger_message(void *cls, void chat_messenger_run(void *cls, - UNUSED char *const *args, - UNUSED const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) + UNUSED char *const *args, + UNUSED const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { + g_assert((cls) && (cfg)); + MESSENGER_Application *app = (MESSENGER_Application*) cls; // Start libgnunetchat handle diff --git a/src/contact.c b/src/contact.c @@ -45,6 +45,8 @@ contact_create_info(struct GNUNET_CHAT_Contact *contact) void contact_destroy_info(struct GNUNET_CHAT_Contact *contact) { + g_assert(contact); + MESSENGER_ContactInfo* info = GNUNET_CHAT_contact_get_user_pointer(contact); if (!info) @@ -88,9 +90,11 @@ void contact_add_name_label_to_info(const struct GNUNET_CHAT_Contact *contact, GtkLabel *label) { + g_assert(label); + MESSENGER_ContactInfo* info = GNUNET_CHAT_contact_get_user_pointer(contact); - if ((!info) || (!label)) + if (!info) return; const char *name = GNUNET_CHAT_contact_get_name(contact); @@ -104,9 +108,11 @@ void contact_remove_name_label_from_info(const struct GNUNET_CHAT_Contact *contact, GtkLabel *label) { + g_assert(label); + MESSENGER_ContactInfo* info = GNUNET_CHAT_contact_get_user_pointer(contact); - if ((!info) || (!label)) + if (!info) return; if (info->name_labels) @@ -117,9 +123,11 @@ void contact_add_name_avatar_to_info(const struct GNUNET_CHAT_Contact *contact, HdyAvatar *avatar) { + g_assert(avatar); + MESSENGER_ContactInfo* info = GNUNET_CHAT_contact_get_user_pointer(contact); - if ((!info) || (!avatar)) + if (!info) return; const char *name = GNUNET_CHAT_contact_get_name(contact); @@ -133,9 +141,11 @@ void contact_remove_name_avatar_from_info(const struct GNUNET_CHAT_Contact *contact, HdyAvatar *avatar) { + g_assert(avatar); + MESSENGER_ContactInfo* info = GNUNET_CHAT_contact_get_user_pointer(contact); - if ((!info) || (!avatar)) + if (!info) return; if (info->name_avatars) diff --git a/src/event.c b/src/event.c @@ -38,7 +38,7 @@ static void _close_notification(NotifyNotification* notification, gpointer user_data) { - GNUNET_assert((notification) && (user_data)); + g_assert((notification) && (user_data)); MESSENGER_Application *app = (MESSENGER_Application*) user_data; @@ -58,7 +58,7 @@ _show_notification(MESSENGER_Application *app, const char *icon, const char *category) { - GNUNET_assert( + g_assert( (app) && (context) && (contact) && (text) && (icon) && (category) ); @@ -94,7 +94,7 @@ event_handle_warning(MESSENGER_Application *app, struct GNUNET_CHAT_Context *context, const struct GNUNET_CHAT_Message *msg) { - GNUNET_assert((app) && (context) && (msg)); + g_assert((app) && (context) && (msg)); const char *text = GNUNET_CHAT_message_get_text(msg); @@ -117,7 +117,7 @@ event_handle_warning(MESSENGER_Application *app, static gboolean _idle_refresh_accounts(gpointer user_data) { - GNUNET_assert(user_data); + g_assert(user_data); MESSENGER_Application *app = (MESSENGER_Application*) user_data; @@ -137,7 +137,7 @@ refresh_exit: void event_refresh_accounts(MESSENGER_Application *app) { - GNUNET_assert(app); + g_assert(app); if (app->ui.messenger.account_refresh) g_source_remove(app->ui.messenger.account_refresh); @@ -154,7 +154,7 @@ event_refresh_accounts(MESSENGER_Application *app) static gboolean _select_chat_to_activate(gpointer user_data) { - GNUNET_assert(user_data); + g_assert(user_data); UI_CHAT_ENTRY_Handle *entry = (UI_CHAT_ENTRY_Handle*) user_data; @@ -187,7 +187,7 @@ _select_chat_to_activate(gpointer user_data) static gboolean _idle_chat_entry_update(gpointer user_data) { - GNUNET_assert(user_data); + g_assert(user_data); UI_CHAT_ENTRY_Handle *entry = (UI_CHAT_ENTRY_Handle*) user_data; @@ -212,7 +212,7 @@ update_exit: static void enqueue_chat_entry_update(UI_CHAT_ENTRY_Handle *entry) { - GNUNET_assert(entry); + g_assert(entry); if (entry->update) g_source_remove(entry->update); @@ -227,7 +227,7 @@ static void _add_new_chat_entry(MESSENGER_Application *app, struct GNUNET_CHAT_Context *context) { - GNUNET_assert((app) && (context)); + g_assert((app) && (context)); UI_MESSENGER_Handle *ui = &(app->ui.messenger); UI_CHAT_ENTRY_Handle *entry = ui_chat_entry_new(app); @@ -272,7 +272,7 @@ _iterate_profile_contacts(void *cls, UNUSED struct GNUNET_CHAT_Handle *handle, struct GNUNET_CHAT_Contact *contact) { - GNUNET_assert((cls) && (contact)); + g_assert((cls) && (contact)); MESSENGER_Application *app = (MESSENGER_Application*) cls; @@ -292,7 +292,7 @@ _iterate_profile_groups(void *cls, UNUSED struct GNUNET_CHAT_Handle *handle, UNUSED struct GNUNET_CHAT_Group *group) { - GNUNET_assert(cls); + g_assert(cls); MESSENGER_Application *app = (MESSENGER_Application*) cls; @@ -311,7 +311,7 @@ static void _clear_chat_entry(GtkWidget *widget, gpointer user_data) { - GNUNET_assert((widget) && (user_data)); + g_assert((widget) && (user_data)); MESSENGER_Application *app = (MESSENGER_Application*) user_data; UI_MESSENGER_Handle *ui = &(app->ui.messenger); @@ -340,7 +340,7 @@ _clear_chat_entry(GtkWidget *widget, void event_update_profile(MESSENGER_Application *app) { - GNUNET_assert(app); + g_assert(app); UI_MESSENGER_Handle *ui = &(app->ui.messenger); CHAT_MESSENGER_Handle *chat = &(app->chat.messenger); @@ -372,7 +372,7 @@ _cleanup_profile_contacts(void *cls, UNUSED struct GNUNET_CHAT_Handle *handle, struct GNUNET_CHAT_Contact *contact) { - GNUNET_assert((cls) && (contact)); + g_assert((cls) && (contact)); if (contact) contact_destroy_info(contact); @@ -382,7 +382,7 @@ _cleanup_profile_contacts(void *cls, void event_cleanup_profile(MESSENGER_Application *app) { - GNUNET_assert(app); + g_assert(app); CHAT_MESSENGER_Handle *chat = &(app->chat.messenger); @@ -392,7 +392,7 @@ event_cleanup_profile(MESSENGER_Application *app) gboolean _delayed_context_drop(gpointer user_data) { - GNUNET_assert(user_data); + g_assert(user_data); struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) user_data; @@ -412,7 +412,7 @@ event_update_chats(MESSENGER_Application *app, struct GNUNET_CHAT_Context *context, const struct GNUNET_CHAT_Message *msg) { - GNUNET_assert((app) && (context) && (msg)); + g_assert((app) && (context) && (msg)); UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context); @@ -443,7 +443,7 @@ event_update_chats(MESSENGER_Application *app, static void _update_contact_context(struct GNUNET_CHAT_Contact *contact) { - GNUNET_assert(contact); + g_assert(contact); struct GNUNET_CHAT_Context *context = GNUNET_CHAT_contact_get_context( contact @@ -465,7 +465,7 @@ event_presence_contact(MESSENGER_Application *app, struct GNUNET_CHAT_Context *context, const struct GNUNET_CHAT_Message *msg) { - GNUNET_assert((app) && (context) && (msg)); + g_assert((app) && (context) && (msg)); UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context); @@ -549,7 +549,7 @@ event_update_contacts(UNUSED MESSENGER_Application *app, struct GNUNET_CHAT_Context *context, const struct GNUNET_CHAT_Message *msg) { - GNUNET_assert((app) && (context) && (msg)); + g_assert((app) && (context) && (msg)); struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender( msg @@ -573,7 +573,7 @@ static void _event_invitation_accept_click(UNUSED GtkButton *button, gpointer user_data) { - GNUNET_assert(user_data); + g_assert(user_data); struct GNUNET_CHAT_Invitation *invitation = ( (struct GNUNET_CHAT_Invitation*) user_data @@ -586,7 +586,7 @@ static void _event_invitation_deny_click(UNUSED GtkButton *button, gpointer user_data) { - GNUNET_assert(user_data); + g_assert(user_data); struct GNUNET_CHAT_Invitation *invitation = ( (struct GNUNET_CHAT_Invitation*) user_data @@ -600,7 +600,7 @@ event_invitation(MESSENGER_Application *app, struct GNUNET_CHAT_Context *context, const struct GNUNET_CHAT_Message *msg) { - GNUNET_assert((app) && (context) && (msg)); + g_assert((app) && (context) && (msg)); UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context); @@ -684,7 +684,7 @@ event_receive_message(MESSENGER_Application *app, struct GNUNET_CHAT_Context *context, const struct GNUNET_CHAT_Message *msg) { - GNUNET_assert((app) && (context) && (msg)); + g_assert((app) && (context) && (msg)); UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context); @@ -767,7 +767,7 @@ event_delete_message(MESSENGER_Application *app, struct GNUNET_CHAT_Context *context, const struct GNUNET_CHAT_Message *msg) { - GNUNET_assert((app) && (context) && (msg)); + g_assert((app) && (context) && (msg)); UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context); @@ -802,7 +802,7 @@ event_tag_message(MESSENGER_Application *app, struct GNUNET_CHAT_Context *context, const struct GNUNET_CHAT_Message *msg) { - GNUNET_assert((app) && (context) && (msg)); + g_assert((app) && (context) && (msg)); UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context); diff --git a/src/event.h b/src/event.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021--2022 GNUnet e.V. + Copyright (C) 2021--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 @@ -39,8 +39,8 @@ */ void event_handle_warning(MESSENGER_Application *app, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *msg); + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *msg); /** * Event for the UI to be called whenever the accounts @@ -79,8 +79,8 @@ event_cleanup_profile(MESSENGER_Application *app); */ void event_update_chats(MESSENGER_Application *app, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *msg); + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *msg); /** * Event for the UI to be called whenever a contact @@ -92,8 +92,8 @@ event_update_chats(MESSENGER_Application *app, */ void event_presence_contact(MESSENGER_Application *app, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *msg); + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *msg); /** * Event for the UI to be called whenever a contact @@ -106,8 +106,8 @@ event_presence_contact(MESSENGER_Application *app, */ void event_update_contacts(MESSENGER_Application *app, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *msg); + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *msg); /** * Event for the UI to be called whenever an invitation @@ -119,8 +119,8 @@ event_update_contacts(MESSENGER_Application *app, */ void event_invitation(MESSENGER_Application *app, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *msg); + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *msg); /** * Event for the UI to be called whenever a content @@ -133,8 +133,8 @@ event_invitation(MESSENGER_Application *app, */ void event_receive_message(MESSENGER_Application *app, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *msg); + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *msg); /** * Event for the UI to be called whenever a message @@ -146,8 +146,8 @@ event_receive_message(MESSENGER_Application *app, */ void event_delete_message(MESSENGER_Application *app, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *msg); + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *msg); /** * Event for the UI to be called whenever a message diff --git a/src/file.c b/src/file.c @@ -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 @@ -40,6 +40,8 @@ file_create_info(struct GNUNET_CHAT_File *file) void file_destroy_info(struct GNUNET_CHAT_File *file) { + g_assert(file); + MESSENGER_FileInfo* info = GNUNET_CHAT_file_get_user_pointer(file); if (!info) @@ -55,11 +57,13 @@ 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) { + g_assert(message); + MESSENGER_FileInfo* info = GNUNET_CHAT_file_get_user_pointer(file); - if ((!info) || (!message)) + if (!info) return; info->file_messages = g_list_append(info->file_messages, message); @@ -67,8 +71,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) { MESSENGER_FileInfo* info = GNUNET_CHAT_file_get_user_pointer(file); @@ -92,9 +96,9 @@ 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) { MESSENGER_FileInfo* info = GNUNET_CHAT_file_get_user_pointer(file); @@ -108,8 +112,8 @@ file_update_download_info(const struct GNUNET_CHAT_File *file, UI_MESSAGE_Handle *message = (UI_MESSAGE_Handle*) list->data; gtk_progress_bar_set_fraction( - message->file_progress_bar, - 1.0 * completed / size + message->file_progress_bar, + 1.0 * completed / size ); if (completed >= size) diff --git a/src/request.c b/src/request.c @@ -29,6 +29,8 @@ request_new(MESSENGER_Application *application, GCancellable *cancellable, gpointer user_data) { + g_assert((application) && (cancellable)); + MESSENGER_Request* request = g_malloc(sizeof(MESSENGER_Request)); request->application = application; @@ -49,8 +51,13 @@ request_new_background(MESSENGER_Application *application, GAsyncReadyCallback callback, gpointer user_data) { + g_assert((application) && (callback)); + GCancellable* cancellable = g_cancellable_new(); + if (!cancellable) + return NULL; + MESSENGER_Request* request = request_new( application, cancellable, @@ -77,8 +84,13 @@ request_new_camera(MESSENGER_Application *application, GAsyncReadyCallback callback, gpointer user_data) { + g_assert((application) && (callback)); + GCancellable* cancellable = g_cancellable_new(); + if (!cancellable) + return NULL; + MESSENGER_Request* request = request_new( application, cancellable, @@ -100,6 +112,8 @@ request_new_camera(MESSENGER_Application *application, void request_cancel(MESSENGER_Request *request) { + g_assert(request); + if (!request->cancellable) return; @@ -110,6 +124,8 @@ request_cancel(MESSENGER_Request *request) void request_cleanup(MESSENGER_Request *request) { + g_assert(request); + if (!request->cancellable) return; @@ -120,6 +136,8 @@ request_cleanup(MESSENGER_Request *request) void request_drop(MESSENGER_Request *request) { + g_assert(request); + if (request->application->requests) request->application->requests = g_list_remove( request->application->requests, @@ -132,6 +150,8 @@ request_drop(MESSENGER_Request *request) void request_delete(MESSENGER_Request *request) { + g_assert(request); + request_cleanup(request); g_free(request); } diff --git a/src/ui.c b/src/ui.c @@ -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 @@ -27,6 +27,8 @@ void ui_label_set_text(GtkLabel *label, const char *text) { + g_assert(label); + if (!text) { gtk_label_set_text(label, ""); @@ -41,6 +43,8 @@ ui_label_set_text(GtkLabel *label, const char *text) void ui_entry_set_text(GtkEntry *entry, const char *text) { + g_assert(entry); + if (!text) { gtk_entry_set_text(entry, ""); @@ -55,6 +59,8 @@ ui_entry_set_text(GtkEntry *entry, const char *text) void ui_avatar_set_text(HdyAvatar *avatar, const char *text) { + g_assert(avatar); + if (!text) { const gchar *state = hdy_avatar_get_text(avatar); diff --git a/src/ui.h b/src/ui.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 @@ -36,7 +36,8 @@ * @param text Non-utf8 text */ void -ui_label_set_text(GtkLabel *label, const char *text); +ui_label_set_text(GtkLabel *label, + const char *text); /** * Sets the text of a GtkEntry applying automatic utf8 @@ -46,7 +47,8 @@ ui_label_set_text(GtkLabel *label, const char *text); * @param text Non-utf8 text */ void -ui_entry_set_text(GtkEntry *entry, const char *text); +ui_entry_set_text(GtkEntry *entry, + const char *text); /** * Sets the text of a HdyAvatar applying automatic utf8 @@ -56,6 +58,7 @@ ui_entry_set_text(GtkEntry *entry, const char *text); * @param text Non-utf8 text */ void -ui_avatar_set_text(HdyAvatar *avatar, const char *text); +ui_avatar_set_text(HdyAvatar *avatar, + const char *text); #endif /* UI_H_ */ diff --git a/src/ui/about.c b/src/ui/about.c @@ -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 @@ -28,73 +28,81 @@ static void handle_close_button_click(UNUSED GtkButton *button, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + GtkAboutDialog *dialog = GTK_ABOUT_DIALOG(user_data); gtk_window_close(GTK_WINDOW(dialog)); } static void handle_dialog_destroy(UNUSED GtkWidget *window, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + ui_about_dialog_cleanup((UI_ABOUT_Handle*) user_data); } void ui_about_dialog_init(MESSENGER_Application *app, - UI_ABOUT_Handle *handle) + UI_ABOUT_Handle *handle) { + g_assert((app) && (handle)); + handle->builder = gtk_builder_new_from_resource( - application_get_resource_path(app, "ui/about.ui") + application_get_resource_path(app, "ui/about.ui") ); handle->dialog = GTK_ABOUT_DIALOG( - gtk_builder_get_object(handle->builder, "about_dialog") + gtk_builder_get_object(handle->builder, "about_dialog") ); gtk_window_set_transient_for( - GTK_WINDOW(handle->dialog), - GTK_WINDOW(app->ui.messenger.main_window) + GTK_WINDOW(handle->dialog), + GTK_WINDOW(app->ui.messenger.main_window) ); gtk_about_dialog_set_program_name( - handle->dialog, - MESSENGER_APPLICATION_APPNAME + handle->dialog, + MESSENGER_APPLICATION_APPNAME ); gtk_about_dialog_set_version( - handle->dialog, - MESSENGER_APPLICATION_VERSION + handle->dialog, + MESSENGER_APPLICATION_VERSION ); gtk_about_dialog_set_logo_icon_name( - handle->dialog, - MESSENGER_APPLICATION_ID + handle->dialog, + MESSENGER_APPLICATION_ID ); handle->close_button = GTK_BUTTON( - gtk_builder_get_object(handle->builder, "close_button") + gtk_builder_get_object(handle->builder, "close_button") ); g_signal_connect( - handle->close_button, - "clicked", - G_CALLBACK(handle_close_button_click), - handle->dialog + handle->close_button, + "clicked", + G_CALLBACK(handle_close_button_click), + handle->dialog ); g_signal_connect( - handle->dialog, - "destroy", - G_CALLBACK(handle_dialog_destroy), - handle + handle->dialog, + "destroy", + G_CALLBACK(handle_dialog_destroy), + handle ); } void ui_about_dialog_cleanup(UI_ABOUT_Handle *handle) { + g_assert(handle); + g_object_unref(handle->builder); memset(handle, 0, sizeof(*handle)); diff --git a/src/ui/about.h b/src/ui/about.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 @@ -44,7 +44,7 @@ typedef struct UI_ABOUT_Handle */ void ui_about_dialog_init(MESSENGER_Application *app, - UI_ABOUT_Handle *handle); + UI_ABOUT_Handle *handle); /** * Cleans up the allocated resources and resets the diff --git a/src/ui/account_entry.c b/src/ui/account_entry.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021--2022 GNUnet e.V. + Copyright (C) 2021--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,22 +30,24 @@ UI_ACCOUNT_ENTRY_Handle* ui_account_entry_new(MESSENGER_Application *app) { + g_assert(app); + UI_ACCOUNT_ENTRY_Handle* handle = g_malloc(sizeof(UI_ACCOUNT_ENTRY_Handle)); handle->builder = gtk_builder_new_from_resource( - application_get_resource_path(app, "ui/account_entry.ui") + application_get_resource_path(app, "ui/account_entry.ui") ); handle->entry_box = GTK_WIDGET( - gtk_builder_get_object(handle->builder, "entry_box") + gtk_builder_get_object(handle->builder, "entry_box") ); handle->entry_avatar = HDY_AVATAR( - gtk_builder_get_object(handle->builder, "entry_avatar") + gtk_builder_get_object(handle->builder, "entry_avatar") ); handle->entry_label = GTK_LABEL( - gtk_builder_get_object(handle->builder, "entry_label") + gtk_builder_get_object(handle->builder, "entry_label") ); return handle; @@ -53,8 +55,10 @@ ui_account_entry_new(MESSENGER_Application *app) void ui_account_entry_set_account(UI_ACCOUNT_ENTRY_Handle* handle, - const struct GNUNET_CHAT_Account *account) + const struct GNUNET_CHAT_Account *account) { + g_assert((handle) && (account)); + const char *name = GNUNET_CHAT_account_get_name(account); ui_avatar_set_text(handle->entry_avatar, name); @@ -63,8 +67,10 @@ ui_account_entry_set_account(UI_ACCOUNT_ENTRY_Handle* handle, void ui_account_entry_set_contact(UI_ACCOUNT_ENTRY_Handle* handle, - const struct GNUNET_CHAT_Contact *contact) + const struct GNUNET_CHAT_Contact *contact) { + g_assert((handle) && (contact)); + const char *name = GNUNET_CHAT_contact_get_name(contact); ui_avatar_set_text(handle->entry_avatar, name); @@ -74,6 +80,8 @@ ui_account_entry_set_contact(UI_ACCOUNT_ENTRY_Handle* handle, void ui_account_entry_delete(UI_ACCOUNT_ENTRY_Handle *handle) { + g_assert(handle); + g_object_unref(handle->builder); g_free(handle); diff --git a/src/ui/account_entry.h b/src/ui/account_entry.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021--2022 GNUnet e.V. + Copyright (C) 2021--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 @@ -58,7 +58,7 @@ ui_account_entry_new(MESSENGER_Application *app); */ void ui_account_entry_set_account(UI_ACCOUNT_ENTRY_Handle* handle, - const struct GNUNET_CHAT_Account *account); + const struct GNUNET_CHAT_Account *account); /** * Sets the content of the given account entry @@ -70,7 +70,7 @@ ui_account_entry_set_account(UI_ACCOUNT_ENTRY_Handle* handle, */ void ui_account_entry_set_contact(UI_ACCOUNT_ENTRY_Handle* handle, - const struct GNUNET_CHAT_Contact *contact); + const struct GNUNET_CHAT_Contact *contact); /** * Frees its resources and destroys a given diff --git a/src/ui/accounts.c b/src/ui/accounts.c @@ -31,6 +31,8 @@ static void handle_close_button_click(UNUSED GtkButton *button, gpointer user_data) { + g_assert(user_data); + GtkDialog *dialog = GTK_DIALOG(user_data); gtk_window_close(GTK_WINDOW(dialog)); } @@ -38,6 +40,8 @@ handle_close_button_click(UNUSED GtkButton *button, static gboolean _open_new_account_dialog(gpointer user_data) { + g_assert(user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; ui_new_account_dialog_init(app, &(app->ui.new_account)); @@ -49,6 +53,8 @@ _open_new_account_dialog(gpointer user_data) static gboolean _show_messenger_main_window(gpointer user_data) { + g_assert(user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; // Refresh the account list @@ -63,6 +69,8 @@ handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox, GtkListBoxRow* row, gpointer user_data) { + g_assert((row) && (user_data)); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; // Drop activations of rows which do not contain accounts @@ -98,6 +106,8 @@ static void handle_dialog_destroy(UNUSED GtkWidget *window, gpointer user_data) { + g_assert(user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; if ((app->ui.accounts.show_queued) || @@ -112,6 +122,8 @@ _iterate_accounts(void *cls, UNUSED const struct GNUNET_CHAT_Handle *handle, struct GNUNET_CHAT_Account *account) { + g_assert((cls) && (account)); + MESSENGER_Application *app = (MESSENGER_Application*) cls; UI_ACCOUNT_ENTRY_Handle *entry = ui_account_entry_new(app); @@ -140,6 +152,8 @@ void ui_accounts_dialog_init(MESSENGER_Application *app, UI_ACCOUNTS_Handle *handle) { + g_assert((app) && (handle)); + handle->show_queued = 0; handle->builder = gtk_builder_new_from_resource( @@ -189,6 +203,8 @@ void ui_accounts_dialog_refresh(MESSENGER_Application *app, UI_ACCOUNTS_Handle *handle) { + g_assert((app) && (handle)); + if (!(handle->accounts_listbox)) return; @@ -226,6 +242,8 @@ ui_accounts_dialog_refresh(MESSENGER_Application *app, void ui_accounts_dialog_cleanup(UI_ACCOUNTS_Handle *handle) { + g_assert(handle); + g_object_unref(handle->builder); guint show = handle->show_queued; diff --git a/src/ui/chat.c b/src/ui/chat.c @@ -38,13 +38,14 @@ #include "delete_messages.h" #include "../application.h" -#include "../contact.h" #include "../file.h" #include "../ui.h" static gboolean _flap_chat_details_reveal_switch(gpointer user_data) { + g_assert(user_data); + UI_CHAT_Handle *handle = (UI_CHAT_Handle*) user_data; HdyFlap* flap = handle->flap_chat_details; @@ -62,6 +63,8 @@ static void handle_chat_details_via_button_click(UNUSED GtkButton* button, gpointer user_data) { + g_assert(user_data); + UI_CHAT_Handle *handle = (UI_CHAT_Handle*) user_data; gtk_widget_set_sensitive(GTK_WIDGET(handle->messages_listbox), FALSE); @@ -75,6 +78,8 @@ static void handle_popover_via_button_click(UNUSED GtkButton *button, gpointer user_data) { + g_assert(user_data); + GtkPopover *popover = GTK_POPOVER(user_data); if (gtk_widget_is_visible(GTK_WIDGET(popover))) @@ -88,6 +93,8 @@ handle_chat_contacts_listbox_row_activated(GtkListBox *listbox, GtkListBoxRow *row, gpointer user_data) { + g_assert((listbox) && (row) && (user_data)); + UI_CHAT_Handle *handle = (UI_CHAT_Handle*) user_data; MESSENGER_Application *app = handle->app; @@ -132,6 +139,8 @@ handle_chat_messages_listbox_size_allocate(UNUSED GtkWidget *widget, UNUSED GdkRectangle *allocation, gpointer user_data) { + g_assert(user_data); + UI_CHAT_Handle *handle = (UI_CHAT_Handle*) user_data; GtkAdjustment *adjustment = gtk_scrolled_window_get_vadjustment( @@ -154,6 +163,8 @@ static void handle_back_button_click(UNUSED GtkButton *button, gpointer user_data) { + g_assert(user_data); + HdyLeaflet *leaflet = HDY_LEAFLET(user_data); GList *children = gtk_container_get_children(GTK_CONTAINER(leaflet)); @@ -168,6 +179,8 @@ static void handle_reveal_identity_button_click(GtkButton *button, gpointer user_data) { + g_assert((button) && (user_data)); + UI_CHAT_Handle *handle = (UI_CHAT_Handle*) user_data; MESSENGER_Application *app = handle->app; @@ -190,6 +203,8 @@ static void handle_block_button_click(UNUSED GtkButton *button, gpointer user_data) { + g_assert(user_data); + UI_CHAT_Handle *handle = (UI_CHAT_Handle*) user_data; struct GNUNET_CHAT_Contact *contact = (struct GNUNET_CHAT_Contact*) ( @@ -208,6 +223,8 @@ static void handle_unblock_button_click(UNUSED GtkButton *button, gpointer user_data) { + g_assert(user_data); + UI_CHAT_Handle *handle = (UI_CHAT_Handle*) user_data; struct GNUNET_CHAT_Contact *contact = (struct GNUNET_CHAT_Contact*) ( @@ -226,6 +243,8 @@ static void handle_leave_chat_button_click(UNUSED GtkButton *button, gpointer user_data) { + g_assert(user_data); + UI_CHAT_Handle *handle = (UI_CHAT_Handle*) user_data; if ((!handle) || (!(handle->send_text_view))) @@ -267,6 +286,8 @@ handle_chat_messages_sort(GtkListBoxRow* row0, GtkListBoxRow* row1, gpointer user_data) { + g_assert((row0) && (row1) && (user_data)); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; UI_MESSAGE_Handle *message0 = (UI_MESSAGE_Handle*) ( @@ -295,6 +316,8 @@ static void handle_chat_messages_selected_rows_changed(GtkListBox *listbox, gpointer user_data) { + g_assert((listbox) && (user_data)); + UI_CHAT_Handle *handle = (UI_CHAT_Handle*) user_data; GList *selected = gtk_list_box_get_selected_rows(listbox); @@ -325,6 +348,8 @@ static void handle_chat_selection_close_button_click(UNUSED GtkButton *button, gpointer user_data) { + g_assert(user_data); + GtkListBox *listbox = GTK_LIST_BOX(user_data); gtk_list_box_unselect_all(listbox); @@ -335,6 +360,8 @@ _delete_messages_callback(MESSENGER_Application *app, GList *selected, gulong delay) { + g_assert(app); + UI_MESSAGE_Handle *message; while (selected) @@ -369,6 +396,8 @@ static void handle_chat_selection_delete_button_click(UNUSED GtkButton *button, gpointer user_data) { + g_assert(user_data); + UI_CHAT_Handle *handle = (UI_CHAT_Handle*) user_data; MESSENGER_Application *app = handle->app; @@ -400,6 +429,8 @@ static void handle_attach_file_button_click(GtkButton *button, gpointer user_data) { + g_assert((button) && (user_data)); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; GtkTextView *text_view = GTK_TEXT_VIEW( @@ -452,6 +483,8 @@ _update_send_record_symbol(GtkTextBuffer *buffer, GtkImage *symbol, gboolean picker_revealed) { + g_assert((buffer) && (symbol)); + GtkTextIter start, end; gtk_text_buffer_get_start_iter(buffer, &start); gtk_text_buffer_get_end_iter(buffer, &end); @@ -473,6 +506,8 @@ static void handle_send_text_buffer_changed(GtkTextBuffer *buffer, gpointer user_data) { + g_assert((buffer) && (user_data)); + UI_CHAT_Handle *handle = (UI_CHAT_Handle*) user_data; _update_send_record_symbol( @@ -488,6 +523,8 @@ _send_text_from_view(MESSENGER_Application *app, GtkTextView *text_view, gint64 action_time) { + g_assert((app) && (handle) && (text_view)); + GtkTextBuffer *buffer = gtk_text_view_get_buffer(text_view); GtkTextIter start, end; @@ -523,6 +560,8 @@ _send_text_from_view(MESSENGER_Application *app, static void _drop_any_recording(UI_CHAT_Handle *handle) { + g_assert(handle); + if ((handle->play_pipeline) && (handle->playing)) { gst_element_set_state(handle->play_pipeline, GST_STATE_NULL); @@ -550,6 +589,8 @@ handle_sending_recording_upload_file(UNUSED void *cls, uint64_t completed, uint64_t size) { + g_assert(file); + UI_FILE_LOAD_ENTRY_Handle *file_load = cls; gtk_progress_bar_set_fraction( @@ -567,6 +608,8 @@ static void handle_send_record_button_click(GtkButton *button, gpointer user_data) { + g_assert((button) && (user_data)); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; UI_CHAT_Handle *handle = (UI_CHAT_Handle*) ( @@ -620,6 +663,8 @@ static void handle_send_later_button_click(GtkButton *button, gpointer user_data) { + g_assert((button) && (user_data)); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; UI_CHAT_Handle *handle = (UI_CHAT_Handle*) ( @@ -641,6 +686,8 @@ static void handle_send_now_button_click(GtkButton *button, gpointer user_data) { + g_assert((button) && (user_data)); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; UI_CHAT_Handle *handle = (UI_CHAT_Handle*) ( @@ -665,6 +712,8 @@ handle_send_record_button_pressed(GtkWidget *widget, UNUSED GdkEvent *event, gpointer user_data) { + g_assert((widget) && (user_data)); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; GtkTextView *text_view = GTK_TEXT_VIEW( @@ -747,6 +796,8 @@ handle_send_record_button_released(GtkWidget *widget, UNUSED GdkEvent *event, gpointer user_data) { + g_assert((widget) && (user_data)); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; GtkTextView *text_view = GTK_TEXT_VIEW( @@ -799,6 +850,8 @@ handle_send_text_key_press (GtkWidget *widget, GdkEventKey *event, gpointer user_data) { + g_assert((widget) && (event) && (user_data)); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; if ((app->settings.mobile_design) || @@ -818,6 +871,8 @@ static void handle_recording_close_button_click(UNUSED GtkButton *button, gpointer user_data) { + g_assert(user_data); + UI_CHAT_Handle *handle = (UI_CHAT_Handle*) user_data; _drop_any_recording(handle); @@ -827,6 +882,8 @@ static void _stop_playing_recording(UI_CHAT_Handle *handle, gboolean reset_bar) { + g_assert(handle); + gst_element_set_state(handle->play_pipeline, GST_STATE_NULL); handle->playing = FALSE; @@ -852,6 +909,8 @@ static void handle_recording_play_button_click(UNUSED GtkButton *button, gpointer user_data) { + g_assert(user_data); + UI_CHAT_Handle *handle = (UI_CHAT_Handle*) user_data; if ((!(handle->recorded)) || (!(handle->play_pipeline))) @@ -883,6 +942,8 @@ static void handle_picker_button_click(UNUSED GtkButton *button, gpointer user_data) { + g_assert(user_data); + UI_CHAT_Handle *handle = (UI_CHAT_Handle*) user_data; gboolean reveal = !gtk_revealer_get_child_revealed(handle->picker_revealer); @@ -899,6 +960,8 @@ handle_picker_button_click(UNUSED GtkButton *button, static gboolean _record_timer_func(gpointer user_data) { + g_assert(user_data); + UI_CHAT_Handle *handle = (UI_CHAT_Handle*) user_data; GString *time_string = g_string_new(NULL); @@ -932,6 +995,8 @@ _record_timer_func(gpointer user_data) static gboolean _play_timer_func(gpointer user_data) { + g_assert(user_data); + UI_CHAT_Handle *handle = (UI_CHAT_Handle*) user_data; if (handle->play_time < handle->record_time * 100) @@ -965,6 +1030,8 @@ handle_record_bus_watch(UNUSED GstBus *bus, GstMessage *msg, gpointer data) { + g_assert((msg) && (data)); + UI_CHAT_Handle *handle = (UI_CHAT_Handle*) data; GstMessageType type = GST_MESSAGE_TYPE(msg); @@ -1019,6 +1086,8 @@ handle_play_bus_watch(UNUSED GstBus *bus, static void _setup_gst_pipelines(UI_CHAT_Handle *handle) { + g_assert(handle); + handle->record_pipeline = gst_parse_launch( "autoaudiosrc ! audioconvert ! vorbisenc ! oggmux ! filesink name=sink", NULL @@ -1065,7 +1134,7 @@ _setup_gst_pipelines(UI_CHAT_Handle *handle) UI_CHAT_Handle* ui_chat_new(MESSENGER_Application *app) { - GNUNET_assert(app); + g_assert(app); UI_CHAT_Handle *handle = g_malloc(sizeof(UI_CHAT_Handle)); UI_MESSENGER_Handle *messenger = &(app->ui.messenger); @@ -1554,7 +1623,7 @@ ui_chat_update(UI_CHAT_Handle *handle, MESSENGER_Application *app, struct GNUNET_CHAT_Context* context) { - GNUNET_assert((handle) && (app) && (context)); + g_assert((handle) && (app) && (context)); struct GNUNET_CHAT_Contact* contact; struct GNUNET_CHAT_Group* group; @@ -1715,7 +1784,7 @@ ui_chat_update(UI_CHAT_Handle *handle, void ui_chat_delete(UI_CHAT_Handle *handle) { - GNUNET_assert(handle); + g_assert(handle); ui_picker_delete(handle->picker); @@ -1753,7 +1822,7 @@ ui_chat_add_message(UI_CHAT_Handle *handle, MESSENGER_Application *app, UI_MESSAGE_Handle *message) { - GNUNET_assert((handle) && (message) && (message->message_box)); + g_assert((handle) && (message) && (message->message_box)); gtk_container_add( GTK_CONTAINER(handle->messages_listbox), @@ -1771,7 +1840,7 @@ ui_chat_remove_message(UI_CHAT_Handle *handle, UNUSED MESSENGER_Application *app, UI_MESSAGE_Handle *message) { - GNUNET_assert((handle) && (message) && (message->message_box)); + g_assert((handle) && (message) && (message->message_box)); GtkWidget *row = gtk_widget_get_parent(message->message_box); g_object_set_qdata(G_OBJECT(row), app->quarks.ui, NULL); @@ -1788,7 +1857,7 @@ void ui_chat_add_file_load(UI_CHAT_Handle *handle, UI_FILE_LOAD_ENTRY_Handle *file_load) { - GNUNET_assert((handle) && (file_load)); + g_assert((handle) && (file_load)); gtk_container_add( GTK_CONTAINER(handle->chat_load_listbox), @@ -1806,7 +1875,7 @@ void ui_chat_remove_file_load(UI_CHAT_Handle *handle, UI_FILE_LOAD_ENTRY_Handle *file_load) { - GNUNET_assert((handle) && (file_load) && (handle == file_load->chat) && + g_assert((handle) && (file_load) && (handle == file_load->chat) && (file_load->entry_box)); handle->loads = g_list_remove(handle->loads, file_load); diff --git a/src/ui/chat.h b/src/ui/chat.h @@ -161,8 +161,8 @@ ui_chat_new(MESSENGER_Application *app); */ void ui_chat_update(UI_CHAT_Handle *handle, - MESSENGER_Application *app, - struct GNUNET_CHAT_Context* context); + MESSENGER_Application *app, + struct GNUNET_CHAT_Context* context); /** * Frees its resources and destroys a given @@ -184,8 +184,8 @@ ui_chat_delete(UI_CHAT_Handle *handle); */ void ui_chat_add_message(UI_CHAT_Handle *handle, - MESSENGER_Application *app, - UI_MESSAGE_Handle *message); + MESSENGER_Application *app, + UI_MESSAGE_Handle *message); /** * Removes a message handle from a given chat @@ -198,8 +198,8 @@ ui_chat_add_message(UI_CHAT_Handle *handle, */ void ui_chat_remove_message(UI_CHAT_Handle *handle, - MESSENGER_Application *app, - UI_MESSAGE_Handle *message); + MESSENGER_Application *app, + UI_MESSAGE_Handle *message); /** * Add a file load entry handle to a given chat @@ -210,7 +210,7 @@ ui_chat_remove_message(UI_CHAT_Handle *handle, */ void ui_chat_add_file_load(UI_CHAT_Handle *handle, - UI_FILE_LOAD_ENTRY_Handle *file_load); + UI_FILE_LOAD_ENTRY_Handle *file_load); /** * Removes a file load entry handle from a given @@ -221,6 +221,6 @@ ui_chat_add_file_load(UI_CHAT_Handle *handle, */ void ui_chat_remove_file_load(UI_CHAT_Handle *handle, - UI_FILE_LOAD_ENTRY_Handle *file_load); + UI_FILE_LOAD_ENTRY_Handle *file_load); #endif /* UI_CHAT_H_ */ diff --git a/src/ui/chat_entry.c b/src/ui/chat_entry.c @@ -34,6 +34,8 @@ UI_CHAT_ENTRY_Handle* ui_chat_entry_new(MESSENGER_Application *app) { + g_assert(app); + UI_CHAT_ENTRY_Handle* handle = g_malloc(sizeof(UI_CHAT_ENTRY_Handle)); memset(handle, 0, sizeof(*handle)); @@ -77,6 +79,8 @@ ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle, MESSENGER_Application *app, struct GNUNET_CHAT_Context *context) { + g_assert((handle) && (app)); + const struct GNUNET_CHAT_Contact* contact; const struct GNUNET_CHAT_Group* group; @@ -173,6 +177,8 @@ ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle, void ui_chat_entry_delete(UI_CHAT_ENTRY_Handle *handle) { + g_assert(handle); + ui_chat_delete(handle->chat); g_object_unref(handle->builder); @@ -187,7 +193,7 @@ void ui_chat_entry_dispose(UI_CHAT_ENTRY_Handle *handle, MESSENGER_Application *app) { - GNUNET_assert((handle) && (handle->entry_box)); + g_assert((handle) && (handle->entry_box)); UI_MESSENGER_Handle *ui = &(app->ui.messenger); diff --git a/src/ui/chat_entry.h b/src/ui/chat_entry.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021--2022 GNUnet e.V. + Copyright (C) 2021--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 @@ -70,8 +70,8 @@ ui_chat_entry_new(MESSENGER_Application *app); */ void ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle, - MESSENGER_Application *app, - struct GNUNET_CHAT_Context *context); + MESSENGER_Application *app, + struct GNUNET_CHAT_Context *context); /** * Frees its resources and destroys a given @@ -93,6 +93,6 @@ ui_chat_entry_delete(UI_CHAT_ENTRY_Handle *handle); */ void ui_chat_entry_dispose(UI_CHAT_ENTRY_Handle *handle, - MESSENGER_Application *app); + MESSENGER_Application *app); #endif /* UI_CHAT_ENTRY_H_ */ diff --git a/src/ui/contact_entry.c b/src/ui/contact_entry.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021 GNUnet e.V. + Copyright (C) 2021--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,26 +30,28 @@ UI_CONTACT_ENTRY_Handle* ui_contact_entry_new(MESSENGER_Application *app) { + g_assert(app); + UI_CONTACT_ENTRY_Handle* handle = g_malloc(sizeof(UI_CONTACT_ENTRY_Handle)); handle->builder = gtk_builder_new_from_resource( - application_get_resource_path(app, "ui/contact_entry.ui") + application_get_resource_path(app, "ui/contact_entry.ui") ); handle->entry_box = GTK_WIDGET( - gtk_builder_get_object(handle->builder, "entry_box") + gtk_builder_get_object(handle->builder, "entry_box") ); handle->entry_avatar = HDY_AVATAR( - gtk_builder_get_object(handle->builder, "entry_avatar") + gtk_builder_get_object(handle->builder, "entry_avatar") ); handle->title_label = GTK_LABEL( - gtk_builder_get_object(handle->builder, "title_label") + gtk_builder_get_object(handle->builder, "title_label") ); handle->subtitle_label = GTK_LABEL( - gtk_builder_get_object(handle->builder, "subtitle_label") + gtk_builder_get_object(handle->builder, "subtitle_label") ); return handle; @@ -57,8 +59,9 @@ ui_contact_entry_new(MESSENGER_Application *app) void ui_contact_entry_set_contact(UI_CONTACT_ENTRY_Handle* handle, - const struct GNUNET_CHAT_Contact *contact) + const struct GNUNET_CHAT_Contact *contact) { + g_assert((handle) && (contact)); const char *name = GNUNET_CHAT_contact_get_name(contact); const char *key = GNUNET_CHAT_contact_get_key(contact); @@ -71,6 +74,8 @@ ui_contact_entry_set_contact(UI_CONTACT_ENTRY_Handle* handle, void ui_contact_entry_delete(UI_CONTACT_ENTRY_Handle *handle) { + g_assert(handle); + g_object_unref(handle->builder); g_free(handle); diff --git a/src/ui/contact_entry.h b/src/ui/contact_entry.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021--2022 GNUnet e.V. + Copyright (C) 2021--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 @@ -60,7 +60,7 @@ ui_contact_entry_new(MESSENGER_Application *app); */ void ui_contact_entry_set_contact(UI_CONTACT_ENTRY_Handle* handle, - const struct GNUNET_CHAT_Contact *contact); + const struct GNUNET_CHAT_Contact *contact); /** * Frees its resources and destroys a given diff --git a/src/ui/contact_info.c b/src/ui/contact_info.c @@ -34,6 +34,8 @@ static void handle_contact_edit_button_click(UNUSED GtkButton *button, gpointer user_data) { + g_assert(user_data); + UI_CONTACT_INFO_Handle *handle = (UI_CONTACT_INFO_Handle*) user_data; gboolean editable = gtk_widget_is_sensitive( @@ -85,6 +87,8 @@ static void handle_contact_name_entry_activate(UNUSED GtkEntry *entry, gpointer user_data) { + g_assert(user_data); + UI_CONTACT_INFO_Handle *handle = (UI_CONTACT_INFO_Handle*) user_data; handle_contact_edit_button_click(handle->contact_edit_button, handle); @@ -93,6 +97,8 @@ handle_contact_name_entry_activate(UNUSED GtkEntry *entry, static void _contact_info_reveal_identity(UI_CONTACT_INFO_Handle *handle) { + g_assert(handle); + gtk_widget_set_visible(GTK_WIDGET(handle->back_button), TRUE); gtk_stack_set_visible_child( @@ -105,6 +111,8 @@ static void handle_reveal_identity_button_click(UNUSED GtkButton *button, gpointer user_data) { + g_assert(user_data); + _contact_info_reveal_identity((UI_CONTACT_INFO_Handle*) user_data); } @@ -112,6 +120,8 @@ static void handle_block_button_click(UNUSED GtkButton *button, gpointer user_data) { + g_assert(user_data); + UI_CONTACT_INFO_Handle *handle = (UI_CONTACT_INFO_Handle*) user_data; struct GNUNET_CHAT_Contact *contact = (struct GNUNET_CHAT_Contact*) ( @@ -136,6 +146,8 @@ static void handle_unblock_button_click(UNUSED GtkButton *button, gpointer user_data) { + g_assert(user_data); + UI_CONTACT_INFO_Handle *handle = (UI_CONTACT_INFO_Handle*) user_data; struct GNUNET_CHAT_Contact *contact = (struct GNUNET_CHAT_Contact*) ( @@ -160,6 +172,8 @@ static void handle_open_chat_button_click(UNUSED GtkButton *button, gpointer user_data) { + g_assert(user_data); + UI_CONTACT_INFO_Handle *handle = (UI_CONTACT_INFO_Handle*) user_data; struct GNUNET_CHAT_Contact *contact = (struct GNUNET_CHAT_Contact*) ( @@ -210,6 +224,8 @@ static void handle_back_button_click(UNUSED GtkButton *button, gpointer user_data) { + g_assert(user_data); + UI_CONTACT_INFO_Handle *handle = (UI_CONTACT_INFO_Handle*) user_data; gtk_widget_set_visible(GTK_WIDGET(handle->back_button), FALSE); @@ -222,24 +238,30 @@ handle_back_button_click(UNUSED GtkButton *button, static void handle_close_button_click(UNUSED GtkButton *button, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + GtkDialog *dialog = GTK_DIALOG(user_data); gtk_window_close(GTK_WINDOW(dialog)); } static void handle_dialog_destroy(UNUSED GtkWidget *window, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + ui_contact_info_dialog_cleanup((UI_CONTACT_INFO_Handle*) user_data); } static gboolean handle_id_drawing_area_draw(GtkWidget* drawing_area, - cairo_t* cairo, - gpointer user_data) + cairo_t* cairo, + gpointer user_data) { + g_assert((drawing_area) && (cairo) && (user_data)); + UI_CONTACT_INFO_Handle *handle = (UI_CONTACT_INFO_Handle*) user_data; GtkStyleContext* context = gtk_widget_get_style_context(drawing_area); @@ -331,8 +353,10 @@ handle_id_drawing_area_draw(GtkWidget* drawing_area, void ui_contact_info_dialog_init(MESSENGER_Application *app, - UI_CONTACT_INFO_Handle *handle) + UI_CONTACT_INFO_Handle *handle) { + g_assert((app) && (handle)); + handle->app = app; handle->builder = gtk_builder_new_from_resource( @@ -492,6 +516,8 @@ ui_contact_info_dialog_update(UI_CONTACT_INFO_Handle *handle, struct GNUNET_CHAT_Contact *contact, gboolean reveal) { + g_assert((handle) && (contact)); + const char *name = GNUNET_CHAT_contact_get_name(contact); ui_avatar_set_text(handle->contact_avatar, name); @@ -565,6 +591,8 @@ ui_contact_info_dialog_update(UI_CONTACT_INFO_Handle *handle, void ui_contact_info_dialog_cleanup(UI_CONTACT_INFO_Handle *handle) { + g_assert(handle); + g_signal_handler_disconnect( handle->id_drawing_area, handle->id_draw_signal diff --git a/src/ui/contact_info.h b/src/ui/contact_info.h @@ -75,7 +75,7 @@ typedef struct UI_CONTACT_INFO_Handle */ void ui_contact_info_dialog_init(MESSENGER_Application *app, - UI_CONTACT_INFO_Handle *handle); + UI_CONTACT_INFO_Handle *handle); /** * Updates a given contact info dialog handle with @@ -89,8 +89,8 @@ ui_contact_info_dialog_init(MESSENGER_Application *app, */ void ui_contact_info_dialog_update(UI_CONTACT_INFO_Handle *handle, - struct GNUNET_CHAT_Contact *contact, - gboolean reveal); + struct GNUNET_CHAT_Contact *contact, + gboolean reveal); /** * Cleans up the allocated resources and resets the diff --git a/src/ui/contacts.c b/src/ui/contacts.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021--2022 GNUnet e.V. + Copyright (C) 2021--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 @@ -24,14 +24,15 @@ #include "contacts.h" -#include "chat_entry.h" #include "contact_entry.h" #include "../application.h" static void handle_close_button_click(UNUSED GtkButton *button, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + GtkDialog *dialog = GTK_DIALOG(user_data); gtk_window_close(GTK_WINDOW(dialog)); } @@ -39,6 +40,8 @@ handle_close_button_click(UNUSED GtkButton *button, static gboolean _open_new_contact_dialog(gpointer user_data) { + g_assert(user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; ui_new_contact_dialog_init(app, &(app->ui.new_contact)); @@ -49,9 +52,11 @@ _open_new_contact_dialog(gpointer user_data) static void handle_contacts_listbox_row_activated(UNUSED GtkListBox* listbox, - GtkListBoxRow* row, - gpointer user_data) + GtkListBoxRow* row, + gpointer user_data) { + g_assert((row) && (user_data)); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; if (!gtk_list_box_row_get_selectable(row)) @@ -84,11 +89,13 @@ close_dialog: static gboolean handle_contacts_listbox_filter_func(GtkListBoxRow *row, - gpointer user_data) + gpointer user_data) { + g_assert((row) && (user_data)); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; - if ((!row) || (!gtk_list_box_row_get_selectable(row))) + if (!gtk_list_box_row_get_selectable(row)) return TRUE; const gchar *filter = gtk_entry_get_text( @@ -115,8 +122,10 @@ handle_contacts_listbox_filter_func(GtkListBoxRow *row, static void handle_contact_search_entry_search_changed(UNUSED GtkSearchEntry* search_entry, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + GtkListBox *listbox = GTK_LIST_BOX(user_data); gtk_list_box_invalidate_filter(listbox); @@ -124,16 +133,20 @@ handle_contact_search_entry_search_changed(UNUSED GtkSearchEntry* search_entry, static void handle_dialog_destroy(UNUSED GtkWidget *window, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + ui_contacts_dialog_cleanup((UI_CONTACTS_Handle*) user_data); } static int _iterate_contacts(void *cls, - UNUSED struct GNUNET_CHAT_Handle *handle, - struct GNUNET_CHAT_Contact *contact) + UNUSED struct GNUNET_CHAT_Handle *handle, + struct GNUNET_CHAT_Contact *contact) { + g_assert((cls) && (contact)); + if (GNUNET_YES == GNUNET_CHAT_contact_is_owned(contact)) return GNUNET_YES; @@ -165,72 +178,74 @@ _iterate_contacts(void *cls, void ui_contacts_dialog_init(MESSENGER_Application *app, - UI_CONTACTS_Handle *handle) + UI_CONTACTS_Handle *handle) { + g_assert((app) && (handle)); + handle->builder = gtk_builder_new_from_resource( - application_get_resource_path(app, "ui/contacts.ui") + application_get_resource_path(app, "ui/contacts.ui") ); handle->dialog = GTK_DIALOG( - gtk_builder_get_object(handle->builder, "contacts_dialog") + gtk_builder_get_object(handle->builder, "contacts_dialog") ); gtk_window_set_transient_for( - GTK_WINDOW(handle->dialog), - GTK_WINDOW(app->ui.messenger.main_window) + GTK_WINDOW(handle->dialog), + GTK_WINDOW(app->ui.messenger.main_window) ); handle->contact_search_entry = GTK_SEARCH_ENTRY( - gtk_builder_get_object(handle->builder, "contact_search_entry") + gtk_builder_get_object(handle->builder, "contact_search_entry") ); handle->contacts_listbox = GTK_LIST_BOX( - gtk_builder_get_object(handle->builder, "contacts_listbox") + gtk_builder_get_object(handle->builder, "contacts_listbox") ); gtk_list_box_set_filter_func( - handle->contacts_listbox, - handle_contacts_listbox_filter_func, - app, - NULL + handle->contacts_listbox, + handle_contacts_listbox_filter_func, + app, + NULL ); g_signal_connect( - handle->contact_search_entry, - "search-changed", - G_CALLBACK(handle_contact_search_entry_search_changed), - handle->contacts_listbox + handle->contact_search_entry, + "search-changed", + G_CALLBACK(handle_contact_search_entry_search_changed), + handle->contacts_listbox ); g_signal_connect( - handle->contacts_listbox, - "row-activated", - G_CALLBACK(handle_contacts_listbox_row_activated), - app + handle->contacts_listbox, + "row-activated", + G_CALLBACK(handle_contacts_listbox_row_activated), + app ); handle->close_button = GTK_BUTTON( - gtk_builder_get_object(handle->builder, "close_button") + gtk_builder_get_object(handle->builder, "close_button") ); g_signal_connect( - handle->close_button, - "clicked", - G_CALLBACK(handle_close_button_click), - handle->dialog + handle->close_button, + "clicked", + G_CALLBACK(handle_close_button_click), + handle->dialog ); g_signal_connect( - handle->dialog, - "destroy", - G_CALLBACK(handle_dialog_destroy), - handle + handle->dialog, + "destroy", + G_CALLBACK(handle_dialog_destroy), + handle ); GNUNET_CHAT_iterate_contacts( - app->chat.messenger.handle, - _iterate_contacts, - app + app->chat.messenger.handle, + _iterate_contacts, + app ); gtk_list_box_invalidate_filter(handle->contacts_listbox); @@ -239,6 +254,8 @@ ui_contacts_dialog_init(MESSENGER_Application *app, void ui_contacts_dialog_cleanup(UI_CONTACTS_Handle *handle) { + g_assert(handle); + g_object_unref(handle->builder); memset(handle, 0, sizeof(*handle)); diff --git a/src/ui/contacts.h b/src/ui/contacts.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021--2022 GNUnet e.V. + Copyright (C) 2021--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 @@ -48,7 +48,7 @@ typedef struct UI_CONTACTS_Handle */ void ui_contacts_dialog_init(MESSENGER_Application *app, - UI_CONTACTS_Handle *handle); + UI_CONTACTS_Handle *handle); /** * Cleans up the allocated resources and resets the diff --git a/src/ui/delete_messages.c b/src/ui/delete_messages.c @@ -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 @@ -28,16 +28,20 @@ static void handle_cancel_button_click(UNUSED GtkButton *button, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + GtkDialog *dialog = GTK_DIALOG(user_data); gtk_window_close(GTK_WINDOW(dialog)); } static void handle_confirm_button_click(UNUSED GtkButton *button, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; app->settings.hide_delete_dialog = gtk_toggle_button_get_active( @@ -51,8 +55,7 @@ handle_confirm_button_click(UNUSED GtkButton *button, gulong delay = 0; GtkTreeIter iter; - if (gtk_combo_box_get_active_iter(app->ui.delete_messages.delay_combobox, - &iter)) + if (gtk_combo_box_get_active_iter(app->ui.delete_messages.delay_combobox, &iter)) gtk_tree_model_get(model, &iter, 1, &delay, -1); if (app->ui.delete_messages.callback) @@ -67,8 +70,10 @@ handle_confirm_button_click(UNUSED GtkButton *button, static void handle_dialog_destroy(UNUSED GtkWidget *window, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; ui_delete_messages_dialog_cleanup(&(app->ui.delete_messages)); @@ -76,63 +81,65 @@ handle_dialog_destroy(UNUSED GtkWidget *window, void ui_delete_messages_dialog_init(MESSENGER_Application *app, - UI_DELETE_MESSAGES_Handle *handle) + UI_DELETE_MESSAGES_Handle *handle) { + g_assert((app) && (handle)); + handle->selected = NULL; handle->callback = NULL; handle->builder = gtk_builder_new_from_resource( - application_get_resource_path(app, "ui/delete_messages.ui") + application_get_resource_path(app, "ui/delete_messages.ui") ); handle->dialog = GTK_DIALOG( - gtk_builder_get_object(handle->builder, "delete_messages_dialog") + gtk_builder_get_object(handle->builder, "delete_messages_dialog") ); gtk_window_set_transient_for( - GTK_WINDOW(handle->dialog), - GTK_WINDOW(app->ui.messenger.main_window) + GTK_WINDOW(handle->dialog), + GTK_WINDOW(app->ui.messenger.main_window) ); handle->delay_store = GTK_LIST_STORE( - gtk_builder_get_object(handle->builder, "delay_store") + gtk_builder_get_object(handle->builder, "delay_store") ); handle->delay_combobox = GTK_COMBO_BOX( - gtk_builder_get_object(handle->builder, "delay_combobox") + gtk_builder_get_object(handle->builder, "delay_combobox") ); handle->hide_checkbox = GTK_CHECK_BUTTON( - gtk_builder_get_object(handle->builder, "hide_checkbox") + gtk_builder_get_object(handle->builder, "hide_checkbox") ); handle->cancel_button = GTK_BUTTON( - gtk_builder_get_object(handle->builder, "cancel_button") + gtk_builder_get_object(handle->builder, "cancel_button") ); g_signal_connect( - handle->cancel_button, - "clicked", - G_CALLBACK(handle_cancel_button_click), - handle->dialog + handle->cancel_button, + "clicked", + G_CALLBACK(handle_cancel_button_click), + handle->dialog ); handle->confirm_button = GTK_BUTTON( - gtk_builder_get_object(handle->builder, "confirm_button") + gtk_builder_get_object(handle->builder, "confirm_button") ); g_signal_connect( - handle->confirm_button, - "clicked", - G_CALLBACK(handle_confirm_button_click), - app + handle->confirm_button, + "clicked", + G_CALLBACK(handle_confirm_button_click), + app ); g_signal_connect( - handle->dialog, - "destroy", - G_CALLBACK(handle_dialog_destroy), - app + handle->dialog, + "destroy", + G_CALLBACK(handle_dialog_destroy), + app ); } @@ -141,6 +148,8 @@ ui_delete_messages_dialog_link(UI_DELETE_MESSAGES_Handle *handle, UI_DELETE_MESSAGES_Callback callback, GList *selected) { + g_assert((handle) && (callback)); + handle->selected = selected; handle->callback = callback; } @@ -148,6 +157,8 @@ ui_delete_messages_dialog_link(UI_DELETE_MESSAGES_Handle *handle, void ui_delete_messages_dialog_cleanup(UI_DELETE_MESSAGES_Handle *handle) { + g_assert(handle); + g_object_unref(handle->builder); if (handle->selected) diff --git a/src/ui/delete_messages.h b/src/ui/delete_messages.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 @@ -28,9 +28,11 @@ #include "messenger.h" typedef void -(*UI_DELETE_MESSAGES_Callback) (MESSENGER_Application *app, - GList *selected, - gulong delay); +(*UI_DELETE_MESSAGES_Callback) ( + MESSENGER_Application *app, + GList *selected, + gulong delay +); typedef struct UI_DELETE_MESSAGES_Handle { @@ -59,7 +61,7 @@ typedef struct UI_DELETE_MESSAGES_Handle */ void ui_delete_messages_dialog_init(MESSENGER_Application *app, - UI_DELETE_MESSAGES_Handle *handle); + UI_DELETE_MESSAGES_Handle *handle); /** * Links a custom list and a callback to a @@ -72,8 +74,8 @@ ui_delete_messages_dialog_init(MESSENGER_Application *app, */ void ui_delete_messages_dialog_link(UI_DELETE_MESSAGES_Handle *handle, - UI_DELETE_MESSAGES_Callback callback, - GList *selected); + UI_DELETE_MESSAGES_Callback callback, + GList *selected); /** * Cleans up the allocated resources and resets the diff --git a/src/ui/file_load_entry.c b/src/ui/file_load_entry.c @@ -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,8 +30,10 @@ static void handle_cancel_button_click(GNUNET_UNUSED GtkButton *button, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + UI_FILE_LOAD_ENTRY_Handle* handle = (UI_FILE_LOAD_ENTRY_Handle*) user_data; if (handle->chat) @@ -43,6 +45,8 @@ handle_cancel_button_click(GNUNET_UNUSED GtkButton *button, UI_FILE_LOAD_ENTRY_Handle* ui_file_load_entry_new(MESSENGER_Application *app) { + g_assert(app); + UI_FILE_LOAD_ENTRY_Handle* handle = g_malloc(sizeof(UI_FILE_LOAD_ENTRY_Handle)); handle->chat = NULL; @@ -84,6 +88,8 @@ ui_file_load_entry_new(MESSENGER_Application *app) void ui_file_load_entry_delete(UI_FILE_LOAD_ENTRY_Handle *handle) { + g_assert(handle); + g_object_unref(handle->builder); g_free(handle); diff --git a/src/ui/invite_contact.c b/src/ui/invite_contact.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021--2022 GNUnet e.V. + Copyright (C) 2021--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 @@ -24,31 +24,34 @@ #include "invite_contact.h" -#include "chat_entry.h" #include "contact_entry.h" #include "../application.h" static void handle_close_button_click(UNUSED GtkButton *button, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + GtkDialog *dialog = GTK_DIALOG(user_data); gtk_window_close(GTK_WINDOW(dialog)); } static void handle_contacts_listbox_row_activated(GtkListBox* listbox, - GtkListBoxRow* row, - gpointer user_data) + GtkListBoxRow* row, + gpointer user_data) { + g_assert((listbox) && (row) && (user_data)); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; GtkTextView *text_view = GTK_TEXT_VIEW( - g_object_get_qdata(G_OBJECT(listbox), app->quarks.widget) + g_object_get_qdata(G_OBJECT(listbox), app->quarks.widget) ); struct GNUNET_CHAT_Contact *contact = (struct GNUNET_CHAT_Contact*) ( - g_object_get_qdata(G_OBJECT(row), app->quarks.data) + g_object_get_qdata(G_OBJECT(row), app->quarks.data) ); if ((!contact) || (!GNUNET_CHAT_contact_get_key(contact)) || @@ -57,14 +60,14 @@ handle_contacts_listbox_row_activated(GtkListBox* listbox, goto close_dialog; struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) ( - g_object_get_qdata(G_OBJECT(text_view), app->quarks.data) + g_object_get_qdata(G_OBJECT(text_view), app->quarks.data) ); if (!context) goto close_dialog; const struct GNUNET_CHAT_Group *group = GNUNET_CHAT_context_get_group( - context + context ); if (group) @@ -76,22 +79,24 @@ close_dialog: static gboolean handle_contacts_listbox_filter_func(GtkListBoxRow *row, - gpointer user_data) + gpointer user_data) { + g_assert((row) && (user_data)); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; - if ((!row) || (!gtk_list_box_row_get_selectable(row))) + if (!gtk_list_box_row_get_selectable(row)) return TRUE; const gchar *filter = gtk_entry_get_text( - GTK_ENTRY(app->ui.invite_contact.contact_search_entry) + GTK_ENTRY(app->ui.invite_contact.contact_search_entry) ); if (!filter) return TRUE; UI_CONTACT_ENTRY_Handle *entry = (UI_CONTACT_ENTRY_Handle*) ( - g_object_get_qdata(G_OBJECT(row), app->quarks.ui) + g_object_get_qdata(G_OBJECT(row), app->quarks.ui) ); if (!entry) @@ -107,8 +112,10 @@ handle_contacts_listbox_filter_func(GtkListBoxRow *row, static void handle_contact_search_entry_search_changed(UNUSED GtkSearchEntry* search_entry, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + GtkListBox *listbox = GTK_LIST_BOX(user_data); gtk_list_box_invalidate_filter(listbox); @@ -116,16 +123,20 @@ handle_contact_search_entry_search_changed(UNUSED GtkSearchEntry* search_entry, static void handle_dialog_destroy(UNUSED GtkWidget *window, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + ui_contacts_dialog_cleanup((UI_CONTACTS_Handle*) user_data); } static int _iterate_contacts(void *cls, - UNUSED struct GNUNET_CHAT_Handle *handle, - struct GNUNET_CHAT_Contact *contact) + UNUSED struct GNUNET_CHAT_Handle *handle, + struct GNUNET_CHAT_Contact *contact) { + g_assert((cls) && (contact)); + if (GNUNET_YES == GNUNET_CHAT_contact_is_owned(contact)) return GNUNET_YES; @@ -135,21 +146,21 @@ _iterate_contacts(void *cls, ui_contact_entry_set_contact(entry, contact); gtk_list_box_prepend( - app->ui.invite_contact.contacts_listbox, - entry->entry_box + app->ui.invite_contact.contacts_listbox, + entry->entry_box ); GtkListBoxRow *row = GTK_LIST_BOX_ROW( - gtk_widget_get_parent(entry->entry_box) + gtk_widget_get_parent(entry->entry_box) ); g_object_set_qdata(G_OBJECT(row), app->quarks.data, contact); g_object_set_qdata_full( - G_OBJECT(row), - app->quarks.ui, - entry, - (GDestroyNotify) ui_contact_entry_delete + G_OBJECT(row), + app->quarks.ui, + entry, + (GDestroyNotify) ui_contact_entry_delete ); return GNUNET_YES; @@ -157,72 +168,74 @@ _iterate_contacts(void *cls, void ui_invite_contact_dialog_init(MESSENGER_Application *app, - UI_INVITE_CONTACT_Handle *handle) + UI_INVITE_CONTACT_Handle *handle) { + g_assert((app) && (handle)); + handle->builder = gtk_builder_new_from_resource( - application_get_resource_path(app, "ui/invite_contact.ui") + application_get_resource_path(app, "ui/invite_contact.ui") ); handle->dialog = GTK_DIALOG( - gtk_builder_get_object(handle->builder, "invite_contact_dialog") + gtk_builder_get_object(handle->builder, "invite_contact_dialog") ); gtk_window_set_transient_for( - GTK_WINDOW(handle->dialog), - GTK_WINDOW(app->ui.messenger.main_window) + GTK_WINDOW(handle->dialog), + GTK_WINDOW(app->ui.messenger.main_window) ); handle->contact_search_entry = GTK_SEARCH_ENTRY( - gtk_builder_get_object(handle->builder, "contact_search_entry") + gtk_builder_get_object(handle->builder, "contact_search_entry") ); handle->contacts_listbox = GTK_LIST_BOX( - gtk_builder_get_object(handle->builder, "contacts_listbox") + gtk_builder_get_object(handle->builder, "contacts_listbox") ); gtk_list_box_set_filter_func( - handle->contacts_listbox, - handle_contacts_listbox_filter_func, - app, - NULL + handle->contacts_listbox, + handle_contacts_listbox_filter_func, + app, + NULL ); g_signal_connect( - handle->contact_search_entry, - "search-changed", - G_CALLBACK(handle_contact_search_entry_search_changed), - handle->contacts_listbox + handle->contact_search_entry, + "search-changed", + G_CALLBACK(handle_contact_search_entry_search_changed), + handle->contacts_listbox ); g_signal_connect( - handle->contacts_listbox, - "row-activated", - G_CALLBACK(handle_contacts_listbox_row_activated), - app + handle->contacts_listbox, + "row-activated", + G_CALLBACK(handle_contacts_listbox_row_activated), + app ); handle->close_button = GTK_BUTTON( - gtk_builder_get_object(handle->builder, "close_button") + gtk_builder_get_object(handle->builder, "close_button") ); g_signal_connect( - handle->close_button, - "clicked", - G_CALLBACK(handle_close_button_click), - handle->dialog + handle->close_button, + "clicked", + G_CALLBACK(handle_close_button_click), + handle->dialog ); g_signal_connect( - handle->dialog, - "destroy", - G_CALLBACK(handle_dialog_destroy), - handle + handle->dialog, + "destroy", + G_CALLBACK(handle_dialog_destroy), + handle ); GNUNET_CHAT_iterate_contacts( - app->chat.messenger.handle, - _iterate_contacts, - app + app->chat.messenger.handle, + _iterate_contacts, + app ); gtk_list_box_invalidate_filter(handle->contacts_listbox); @@ -231,6 +244,8 @@ ui_invite_contact_dialog_init(MESSENGER_Application *app, void ui_invite_contact_dialog_cleanup(UI_INVITE_CONTACT_Handle *handle) { + g_assert(handle); + g_object_unref(handle->builder); memset(handle, 0, sizeof(*handle)); diff --git a/src/ui/invite_contact.h b/src/ui/invite_contact.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021--2022 GNUnet e.V. + Copyright (C) 2021--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 @@ -48,7 +48,7 @@ typedef struct UI_INVITE_CONTACT_Handle */ void ui_invite_contact_dialog_init(MESSENGER_Application *app, - UI_INVITE_CONTACT_Handle *handle); + UI_INVITE_CONTACT_Handle *handle); /** * Cleans up the allocated resources and resets the diff --git a/src/ui/message.c b/src/ui/message.c @@ -38,7 +38,7 @@ handle_downloading_file(void *cls, uint64_t completed, uint64_t size) { - GNUNET_assert((cls) && (file)); + g_assert((cls) && (file)); MESSENGER_Application *app = (MESSENGER_Application*) cls; @@ -52,7 +52,7 @@ static void handle_file_button_click(GtkButton *button, gpointer user_data) { - GNUNET_assert((button) && (user_data)); + g_assert((button) && (user_data)); MESSENGER_Application *app = (MESSENGER_Application*) user_data; @@ -118,7 +118,7 @@ static void handle_media_button_click(GtkButton *button, gpointer user_data) { - GNUNET_assert((button) && (user_data)); + g_assert((button) && (user_data)); MESSENGER_Application *app = (MESSENGER_Application*) user_data; @@ -159,7 +159,7 @@ handle_media_button_click(GtkButton *button, static int handle_message_redraw_animation(gpointer user_data) { - GNUNET_assert(user_data); + g_assert(user_data); UI_MESSAGE_Handle *handle = (UI_MESSAGE_Handle*) user_data; @@ -179,7 +179,7 @@ handle_preview_drawing_area_draw(GtkWidget* drawing_area, cairo_t* cairo, gpointer user_data) { - GNUNET_assert((drawing_area) && (cairo) && (user_data)); + g_assert((drawing_area) && (cairo) && (user_data)); UI_MESSAGE_Handle *handle = (UI_MESSAGE_Handle*) user_data; @@ -261,7 +261,7 @@ render_image: static void _clear_message_preview_data(UI_MESSAGE_Handle *handle) { - GNUNET_assert(handle); + g_assert(handle); if (handle->preview_image) { @@ -299,7 +299,7 @@ UI_MESSAGE_Handle* ui_message_new(MESSENGER_Application *app, UI_MESSAGE_Type type) { - GNUNET_assert(app); + g_assert(app); UI_MESSAGE_Handle* handle = g_malloc(sizeof(UI_MESSAGE_Handle)); @@ -492,7 +492,7 @@ _iterate_read_receipts(void *cls, const struct GNUNET_CHAT_Contact *contact, int read_receipt) { - GNUNET_assert((cls) && (message) && (contact)); + g_assert((cls) && (message) && (contact)); int *count_read_receipts = (int*) cls; @@ -506,7 +506,7 @@ _iterate_read_receipts(void *cls, void ui_message_refresh(UI_MESSAGE_Handle *handle) { - GNUNET_assert(handle); + g_assert(handle); if ((!(handle->msg)) || (GNUNET_YES != GNUNET_CHAT_message_is_sent(handle->msg))) @@ -549,7 +549,7 @@ _update_invitation_message(UI_MESSAGE_Handle *handle, MESSENGER_Application *app, struct GNUNET_CHAT_Invitation *invitation) { - GNUNET_assert((handle) && (app) && (invitation)); + g_assert((handle) && (app) && (invitation)); enum GNUNET_GenericReturnValue accepted, rejected; accepted = GNUNET_CHAT_invitation_is_accepted(invitation); @@ -589,7 +589,7 @@ _update_file_message(UI_MESSAGE_Handle *handle, MESSENGER_Application *app, struct GNUNET_CHAT_File *file) { - GNUNET_assert((handle) && (app) && (file)); + g_assert((handle) && (app) && (file)); const char *filename = GNUNET_CHAT_file_get_name(file); @@ -713,7 +713,7 @@ ui_message_update(UI_MESSAGE_Handle *handle, MESSENGER_Application *app, const struct GNUNET_CHAT_Message *msg) { - GNUNET_assert((handle) && (app) && (msg)); + g_assert((handle) && (app) && (msg)); struct GNUNET_CHAT_File *file = NULL; struct GNUNET_CHAT_Invitation *invitation = NULL; @@ -760,7 +760,7 @@ void ui_message_set_contact(UI_MESSAGE_Handle *handle, const struct GNUNET_CHAT_Contact *contact) { - GNUNET_assert(handle); + g_assert(handle); if (handle->contact) { @@ -780,7 +780,7 @@ ui_message_set_contact(UI_MESSAGE_Handle *handle, void ui_message_delete(UI_MESSAGE_Handle *handle) { - GNUNET_assert(handle); + g_assert(handle); ui_message_set_contact(handle, NULL); diff --git a/src/ui/message.h b/src/ui/message.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021--2022 GNUnet e.V. + Copyright (C) 2021--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 @@ -101,7 +101,7 @@ typedef struct UI_MESSAGE_Handle */ UI_MESSAGE_Handle* ui_message_new(MESSENGER_Application *app, - UI_MESSAGE_Type type); + UI_MESSAGE_Type type); /** * Refreshes the visual state of the read receipt @@ -123,8 +123,8 @@ ui_message_refresh(UI_MESSAGE_Handle *handle); */ void ui_message_update(UI_MESSAGE_Handle *handle, - MESSENGER_Application *app, - const struct GNUNET_CHAT_Message *message); + MESSENGER_Application *app, + const struct GNUNET_CHAT_Message *message); /** * Sets the contact of a given message handle diff --git a/src/ui/messenger.c b/src/ui/messenger.c @@ -42,6 +42,8 @@ static gboolean _flap_user_details_reveal_switch(gpointer user_data) { + g_assert(user_data); + UI_MESSENGER_Handle *handle = (UI_MESSENGER_Handle*) user_data; HdyFlap* flap = handle->flap_user_details; @@ -60,6 +62,8 @@ static void handle_user_details_via_button_click(UNUSED GtkButton* button, gpointer user_data) { + g_assert(user_data); + UI_MESSENGER_Handle *handle = (UI_MESSENGER_Handle*) user_data; gtk_widget_set_sensitive(GTK_WIDGET(handle->chats_search), FALSE); @@ -74,6 +78,8 @@ static void handle_lobby_button_click(UNUSED GtkButton* button, gpointer user_data) { + g_assert(user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; hdy_flap_set_reveal_flap(HDY_FLAP(app->ui.messenger.flap_user_details), FALSE); @@ -87,6 +93,8 @@ static void _switch_details_revealer_visibility(UI_MESSENGER_Handle *handle, gboolean state) { + g_assert(handle); + GtkRevealer *revealer = handle->account_details_revealer; GtkImage *symbol = handle->account_details_symbol; @@ -104,6 +112,8 @@ static void handle_account_details_button_click(UNUSED GtkButton* button, gpointer user_data) { + g_assert(user_data); + UI_MESSENGER_Handle *handle = (UI_MESSENGER_Handle*) user_data; GtkRevealer *revealer = handle->account_details_revealer; @@ -118,6 +128,8 @@ handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox, GtkListBoxRow* row, gpointer user_data) { + g_assert((row) && (user_data)); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; if (row == app->ui.messenger.add_account_listbox_row) @@ -155,6 +167,8 @@ static void handle_new_contact_button_click(UNUSED GtkButton* button, gpointer user_data) { + g_assert(user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; hdy_flap_set_reveal_flap(HDY_FLAP(app->ui.messenger.flap_user_details), FALSE); @@ -166,6 +180,8 @@ static void handle_new_group_button_click(UNUSED GtkButton* button, gpointer user_data) { + g_assert(user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; hdy_flap_set_reveal_flap(HDY_FLAP(app->ui.messenger.flap_user_details), FALSE); @@ -177,6 +193,8 @@ static void handle_new_platform_button_click(UNUSED GtkButton* button, gpointer user_data) { + g_assert(user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; hdy_flap_set_reveal_flap(HDY_FLAP(app->ui.messenger.flap_user_details), FALSE); @@ -188,6 +206,8 @@ static void handle_contacts_button_click(UNUSED GtkButton* button, gpointer user_data) { + g_assert(user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; hdy_flap_set_reveal_flap(HDY_FLAP(app->ui.messenger.flap_user_details), FALSE); @@ -199,6 +219,8 @@ static void handle_settings_button_click(UNUSED GtkButton* button, gpointer user_data) { + g_assert(user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; hdy_flap_set_reveal_flap(HDY_FLAP(app->ui.messenger.flap_user_details), FALSE); @@ -210,6 +232,8 @@ static void handle_about_button_click(UNUSED GtkButton* button, gpointer user_data) { + g_assert(user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; hdy_flap_set_reveal_flap(HDY_FLAP(app->ui.messenger.flap_user_details), FALSE); @@ -222,6 +246,8 @@ handle_chats_listbox_row_activated(UNUSED GtkListBox* listbox, GtkListBoxRow* row, gpointer user_data) { + g_assert((row) && (user_data)); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; if (!gtk_list_box_row_get_selectable(row)) @@ -253,10 +279,11 @@ handle_chats_listbox_sort_func(GtkListBoxRow* row0, GtkListBoxRow* row1, gpointer user_data) { + g_assert((row0) && (row1) && (user_data)); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; - if ((!row0) || (!row1) || - (!gtk_list_box_row_get_selectable(row0)) || + if ((!gtk_list_box_row_get_selectable(row0)) || (!gtk_list_box_row_get_selectable(row1))) return 0; @@ -286,9 +313,11 @@ static gboolean handle_chats_listbox_filter_func(GtkListBoxRow *row, gpointer user_data) { + g_assert((row) && (user_data)); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; - if ((!row) || (!gtk_list_box_row_get_selectable(row)) || + if ((!gtk_list_box_row_get_selectable(row)) || (gtk_list_box_row_is_selected(row))) return TRUE; @@ -318,6 +347,8 @@ static void handle_chats_search_changed(UNUSED GtkSearchEntry *search, gpointer user_data) { + g_assert(user_data); + GtkListBox *listbox = GTK_LIST_BOX(user_data); gtk_list_box_invalidate_filter(listbox); @@ -327,6 +358,8 @@ static void handle_main_window_destroy(UNUSED GtkWidget *window, gpointer user_data) { + g_assert(user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; if (app->parent) @@ -344,6 +377,8 @@ void ui_messenger_init(MESSENGER_Application *app, UI_MESSENGER_Handle *handle) { + g_assert((app) && (handle)); + memset(handle, 0, sizeof(*handle)); handle->app = app; @@ -635,6 +670,8 @@ _messenger_iterate_accounts(void *cls, const struct GNUNET_CHAT_Handle *handle, struct GNUNET_CHAT_Account *account) { + g_assert((cls) && (handle) && (account)); + MESSENGER_Application *app = (MESSENGER_Application*) cls; UI_MESSENGER_Handle *ui = &(app->ui.messenger); @@ -663,10 +700,12 @@ static void _clear_accounts_listbox(GtkWidget *widget, gpointer data) { + g_assert((widget) && (data)); + GtkListBoxRow *row = GTK_LIST_BOX_ROW(widget); GtkListBox *listbox = GTK_LIST_BOX(data); - if ((!row) || (!listbox) || (!gtk_list_box_row_get_selectable(row))) + if (!gtk_list_box_row_get_selectable(row)) return; gtk_container_remove( @@ -679,6 +718,8 @@ void ui_messenger_refresh(MESSENGER_Application *app, UI_MESSENGER_Handle *handle) { + g_assert((app) && (handle)); + if (!(handle->accounts_listbox)) return; @@ -699,6 +740,8 @@ gboolean ui_messenger_is_context_active(UI_MESSENGER_Handle *handle, struct GNUNET_CHAT_Context *context) { + g_assert((handle) && (context)); + if (!gtk_window_is_active(GTK_WINDOW(handle->main_window))) return FALSE; @@ -720,6 +763,8 @@ ui_messenger_is_context_active(UI_MESSENGER_Handle *handle, void ui_messenger_cleanup(UI_MESSENGER_Handle *handle) { + g_assert(handle); + g_object_unref(handle->builder); if (handle->chat_entries) diff --git a/src/ui/messenger.h b/src/ui/messenger.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021--2022 GNUnet e.V. + Copyright (C) 2021--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 @@ -86,7 +86,7 @@ typedef struct UI_MESSENGER_Handle */ void ui_messenger_init(MESSENGER_Application *app, - UI_MESSENGER_Handle *handle); + UI_MESSENGER_Handle *handle); /** * Refreshes a given messenger window handle with @@ -98,7 +98,7 @@ ui_messenger_init(MESSENGER_Application *app, */ void ui_messenger_refresh(MESSENGER_Application *app, - UI_MESSENGER_Handle *handle); + UI_MESSENGER_Handle *handle); /** * Returns whether a certain chat context is currently @@ -110,7 +110,7 @@ ui_messenger_refresh(MESSENGER_Application *app, */ gboolean ui_messenger_is_context_active(UI_MESSENGER_Handle *handle, - struct GNUNET_CHAT_Context *context); + struct GNUNET_CHAT_Context *context); /** * Cleans up the allocated resources and resets the diff --git a/src/ui/new_account.c b/src/ui/new_account.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021--2022 GNUnet e.V. + Copyright (C) 2021--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 @@ -29,6 +29,8 @@ static gboolean _show_messenger_main_window(gpointer user_data) { + g_assert(user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; gtk_widget_show(GTK_WIDGET(app->ui.messenger.main_window)); @@ -36,8 +38,11 @@ _show_messenger_main_window(gpointer user_data) } static void -_open_new_account(GtkEntry *entry, MESSENGER_Application *app) +_open_new_account(GtkEntry *entry, + MESSENGER_Application *app) { + g_assert((entry) && (app)); + const gchar *name = gtk_entry_get_text(entry); if (GNUNET_OK != GNUNET_CHAT_account_create(app->chat.messenger.handle, name)) @@ -58,8 +63,10 @@ _open_new_account(GtkEntry *entry, MESSENGER_Application *app) static void handle_account_entry_changed(GtkEditable *editable, - gpointer user_data) + gpointer user_data) { + g_assert((editable) && (user_data)); + HdyAvatar *avatar = HDY_AVATAR(user_data); GtkEntry *entry = GTK_ENTRY(editable); @@ -70,8 +77,10 @@ handle_account_entry_changed(GtkEditable *editable, static void handle_account_entry_activate(UNUSED GtkEntry *entry, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; _open_new_account(app->ui.new_account.account_entry, app); @@ -81,16 +90,20 @@ handle_account_entry_activate(UNUSED GtkEntry *entry, static void handle_cancel_button_click(UNUSED GtkButton *button, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + GtkDialog *dialog = GTK_DIALOG(user_data); gtk_window_close(GTK_WINDOW(dialog)); } static void handle_confirm_button_click(UNUSED GtkButton *button, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; _open_new_account(app->ui.new_account.account_entry, app); @@ -100,8 +113,10 @@ handle_confirm_button_click(UNUSED GtkButton *button, static void handle_dialog_destroy(UNUSED GtkWidget *window, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; ui_new_account_dialog_cleanup(&(app->ui.new_account)); @@ -113,82 +128,86 @@ handle_dialog_destroy(UNUSED GtkWidget *window, void ui_new_account_dialog_init(MESSENGER_Application *app, - UI_NEW_ACCOUNT_Handle *handle) + UI_NEW_ACCOUNT_Handle *handle) { + g_assert((app) && (handle)); + handle->show_queued = 0; handle->builder = gtk_builder_new_from_resource( - application_get_resource_path(app, "ui/new_account.ui") + application_get_resource_path(app, "ui/new_account.ui") ); handle->dialog = GTK_DIALOG( - gtk_builder_get_object(handle->builder, "new_account_dialog") + gtk_builder_get_object(handle->builder, "new_account_dialog") ); gtk_window_set_transient_for( - GTK_WINDOW(handle->dialog), - GTK_WINDOW(app->ui.messenger.main_window) + GTK_WINDOW(handle->dialog), + GTK_WINDOW(app->ui.messenger.main_window) ); handle->account_avatar = HDY_AVATAR( - gtk_builder_get_object(handle->builder, "account_avatar") + gtk_builder_get_object(handle->builder, "account_avatar") ); handle->account_avatar_file = GTK_FILE_CHOOSER_BUTTON( - gtk_builder_get_object(handle->builder, "account_avatar_file") + gtk_builder_get_object(handle->builder, "account_avatar_file") ); handle->account_entry = GTK_ENTRY( - gtk_builder_get_object(handle->builder, "account_entry") + gtk_builder_get_object(handle->builder, "account_entry") ); g_signal_connect( - handle->account_entry, - "changed", - G_CALLBACK(handle_account_entry_changed), - handle->account_avatar + handle->account_entry, + "changed", + G_CALLBACK(handle_account_entry_changed), + handle->account_avatar ); g_signal_connect( - handle->account_entry, - "activate", - G_CALLBACK(handle_account_entry_activate), - app + handle->account_entry, + "activate", + G_CALLBACK(handle_account_entry_activate), + app ); handle->cancel_button = GTK_BUTTON( - gtk_builder_get_object(handle->builder, "cancel_button") + gtk_builder_get_object(handle->builder, "cancel_button") ); g_signal_connect( - handle->cancel_button, - "clicked", - G_CALLBACK(handle_cancel_button_click), - handle->dialog + handle->cancel_button, + "clicked", + G_CALLBACK(handle_cancel_button_click), + handle->dialog ); handle->confirm_button = GTK_BUTTON( - gtk_builder_get_object(handle->builder, "confirm_button") + gtk_builder_get_object(handle->builder, "confirm_button") ); g_signal_connect( - handle->confirm_button, - "clicked", - G_CALLBACK(handle_confirm_button_click), - app + handle->confirm_button, + "clicked", + G_CALLBACK(handle_confirm_button_click), + app ); g_signal_connect( - handle->dialog, - "destroy", - G_CALLBACK(handle_dialog_destroy), - app + handle->dialog, + "destroy", + G_CALLBACK(handle_dialog_destroy), + app ); } void ui_new_account_dialog_cleanup(UI_NEW_ACCOUNT_Handle *handle) { + g_assert(handle); + g_object_unref(handle->builder); guint show = handle->show_queued; diff --git a/src/ui/new_account.h b/src/ui/new_account.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021--2022 GNUnet e.V. + Copyright (C) 2021--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 @@ -52,7 +52,7 @@ typedef struct UI_NEW_ACCOUNT_Handle */ void ui_new_account_dialog_init(MESSENGER_Application *app, - UI_NEW_ACCOUNT_Handle *handle); + UI_NEW_ACCOUNT_Handle *handle); /** * Cleans up the allocated resources and resets the diff --git a/src/ui/new_contact.c b/src/ui/new_contact.c @@ -33,6 +33,8 @@ static void handle_cancel_button_click(UNUSED GtkButton *button, gpointer user_data) { + g_assert(user_data); + GtkDialog *dialog = GTK_DIALOG(user_data); gtk_window_close(GTK_WINDOW(dialog)); } @@ -41,6 +43,8 @@ static void handle_confirm_button_click(UNUSED GtkButton *button, gpointer user_data) { + g_assert(user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; const gint id_length = gtk_entry_get_text_length(app->ui.new_contact.id_entry); @@ -72,6 +76,8 @@ static void handle_dialog_destroy(UNUSED GtkWidget *window, gpointer user_data) { + g_assert(user_data); + ui_new_contact_dialog_cleanup((UI_NEW_CONTACT_Handle*) user_data); } @@ -79,6 +85,8 @@ static void handle_camera_combo_box_change(GtkComboBox *widget, gpointer user_data) { + g_assert((widget) && (user_data)); + UI_NEW_CONTACT_Handle *handle = (UI_NEW_CONTACT_Handle*) user_data; gchar *name = NULL; @@ -116,7 +124,7 @@ static void _disable_video_processing(UI_NEW_CONTACT_Handle *handle, gboolean drop_pipeline) { - GNUNET_assert(handle); + g_assert(handle); if (handle->preview_stack) goto skip_stack; @@ -138,6 +146,8 @@ msg_error_cb(UNUSED GstBus *bus, GstMessage *msg, gpointer data) { + g_assert((msg) && (data)); + UI_NEW_CONTACT_Handle *handle = (UI_NEW_CONTACT_Handle*) data; GError* error; @@ -158,6 +168,8 @@ msg_eos_cb(UNUSED GstBus *bus, UNUSED GstMessage *msg, gpointer data) { + g_assert(data); + UI_NEW_CONTACT_Handle *handle = (UI_NEW_CONTACT_Handle*) data; if (GST_MESSAGE_SRC(msg) == GST_OBJECT(handle->pipeline)) @@ -169,6 +181,8 @@ msg_state_changed_cb(UNUSED GstBus *bus, GstMessage *msg, gpointer data) { + g_assert((msg) && (data)); + UI_NEW_CONTACT_Handle *handle = (UI_NEW_CONTACT_Handle*) data; GstState old_state, new_state, pending_state; @@ -192,6 +206,8 @@ msg_barcode_cb(UNUSED GstBus *bus, GstMessage *msg, gpointer data) { + g_assert((msg) && (data)); + UI_NEW_CONTACT_Handle *handle = (UI_NEW_CONTACT_Handle*) data; GstMessageType msg_type = GST_MESSAGE_TYPE(msg); @@ -217,6 +233,8 @@ msg_barcode_cb(UNUSED GstBus *bus, static void _setup_gst_pipeline(UI_NEW_CONTACT_Handle *handle) { + g_assert(handle); + handle->pipeline = gst_parse_launch( "pipewiresrc name=source ! videoconvert ! zbar name=scanner" " ! videoconvert ! aspectratiocrop aspect-ratio=1/1" @@ -281,6 +299,8 @@ _setup_gst_pipeline(UI_NEW_CONTACT_Handle *handle) static void* _ui_new_contact_video_thread(void *args) { + g_assert(args); + UI_NEW_CONTACT_Handle *handle = (UI_NEW_CONTACT_Handle*) args; if (!(handle->pipeline)) @@ -301,6 +321,8 @@ static int iterate_global(void *obj, void *data) { + g_assert(data); + UI_NEW_CONTACT_Handle *handle = (UI_NEW_CONTACT_Handle*) data; struct pw_properties *properties = (struct pw_properties*) obj; @@ -356,6 +378,8 @@ _init_camera_pipeline(MESSENGER_Application *app, UI_NEW_CONTACT_Handle *handle, gboolean access) { + g_assert((app) && (handle)); + handle->camera_count = 0; if ((app->portal) && ((access) || xdp_portal_is_camera_present(app->portal))) @@ -384,9 +408,11 @@ _init_camera_pipeline(MESSENGER_Application *app, static void _request_camera_callback(GObject *source_object, - GAsyncResult *result, - gpointer user_data) + GAsyncResult *result, + gpointer user_data) { + g_assert((source_object) && (result) && (user_data)); + XdpPortal *portal = (XdpPortal*) source_object; MESSENGER_Request *request = (MESSENGER_Request*) user_data; @@ -414,7 +440,7 @@ void ui_new_contact_dialog_init(MESSENGER_Application *app, UI_NEW_CONTACT_Handle *handle) { - GNUNET_assert((app) && (handle)); + g_assert((app) && (handle)); handle->camera_count = 0; @@ -545,7 +571,7 @@ ui_new_contact_dialog_init(MESSENGER_Application *app, void ui_new_contact_dialog_cleanup(UI_NEW_CONTACT_Handle *handle) { - GNUNET_assert(handle); + g_assert(handle); pthread_join(handle->video_tid, NULL); diff --git a/src/ui/new_contact.h b/src/ui/new_contact.h @@ -71,7 +71,7 @@ typedef struct UI_NEW_CONTACT_Handle */ void ui_new_contact_dialog_init(MESSENGER_Application *app, - UI_NEW_CONTACT_Handle *handle); + UI_NEW_CONTACT_Handle *handle); /** * Cleans up the allocated resources and resets the diff --git a/src/ui/new_group.c b/src/ui/new_group.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021--2022 GNUnet e.V. + Copyright (C) 2021--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 @@ -29,9 +29,11 @@ static void _open_new_group(GtkEntry *entry, - GtkListBox *listbox, - MESSENGER_Application *app) + GtkListBox *listbox, + MESSENGER_Application *app) { + g_assert((entry) && (listbox) && (app)); + const gchar *name = gtk_entry_get_text(entry); struct GNUNET_CHAT_Group *group = GNUNET_CHAT_group_create( @@ -67,8 +69,10 @@ _open_new_group(GtkEntry *entry, static void handle_group_entry_changed(GtkEditable *editable, - gpointer user_data) + gpointer user_data) { + g_assert((editable) && (user_data)); + HdyAvatar *avatar = HDY_AVATAR(user_data); GtkEntry *entry = GTK_ENTRY(editable); @@ -80,6 +84,8 @@ handle_group_entry_changed(GtkEditable *editable, static void _go_page_details(UI_NEW_GROUP_Handle *handle) { + g_assert(handle); + gtk_stack_set_visible_child(handle->stack, handle->details_box); gtk_widget_hide(GTK_WIDGET(handle->previous_button)); @@ -92,6 +98,8 @@ _go_page_details(UI_NEW_GROUP_Handle *handle) static void _go_page_contacts(UI_NEW_GROUP_Handle *handle) { + g_assert(handle); + gtk_stack_set_visible_child(handle->stack, handle->contacts_box); gtk_widget_hide(GTK_WIDGET(handle->cancel_button)); @@ -103,8 +111,10 @@ _go_page_contacts(UI_NEW_GROUP_Handle *handle) static void handle_group_entry_activate(UNUSED GtkEntry *entry, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; _go_page_contacts(&(app->ui.new_group)); @@ -112,30 +122,38 @@ handle_group_entry_activate(UNUSED GtkEntry *entry, static void handle_cancel_button_click(UNUSED GtkButton *button, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + GtkDialog *dialog = GTK_DIALOG(user_data); gtk_window_close(GTK_WINDOW(dialog)); } static void handle_previous_button_click(UNUSED GtkButton *button, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + _go_page_details((UI_NEW_GROUP_Handle*) user_data); } static void handle_next_button_click(UNUSED GtkButton *button, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + _go_page_contacts((UI_NEW_GROUP_Handle*) user_data); } static void handle_confirm_button_click(UNUSED GtkButton *button, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; _open_new_group( @@ -149,16 +167,20 @@ handle_confirm_button_click(UNUSED GtkButton *button, static void handle_dialog_destroy(UNUSED GtkWidget *window, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + ui_new_group_dialog_cleanup((UI_NEW_GROUP_Handle*) user_data); } static int _iterate_contacts(void *cls, - UNUSED struct GNUNET_CHAT_Handle *handle, - struct GNUNET_CHAT_Contact *contact) + UNUSED struct GNUNET_CHAT_Handle *handle, + struct GNUNET_CHAT_Contact *contact) { + g_assert((cls) && (contact)); + if (GNUNET_YES == GNUNET_CHAT_contact_is_owned(contact)) return GNUNET_YES; @@ -168,16 +190,16 @@ _iterate_contacts(void *cls, ui_contact_entry_set_contact(entry, contact); gtk_list_box_prepend( - app->ui.new_group.contacts_listbox, - entry->entry_box + app->ui.new_group.contacts_listbox, + entry->entry_box ); GtkWidget *row = gtk_widget_get_parent(entry->entry_box); g_object_set_qdata(G_OBJECT(row), app->quarks.data, contact); app->ui.new_group.contact_entries = g_list_append( - app->ui.new_group.contact_entries, - entry + app->ui.new_group.contact_entries, + entry ); return GNUNET_YES; @@ -185,130 +207,134 @@ _iterate_contacts(void *cls, void ui_new_group_dialog_init(MESSENGER_Application *app, - UI_NEW_GROUP_Handle *handle) + UI_NEW_GROUP_Handle *handle) { + g_assert((app) && (handle)); + handle->contact_entries = NULL; handle->builder = gtk_builder_new_from_resource( - application_get_resource_path(app, "ui/new_group.ui") + application_get_resource_path(app, "ui/new_group.ui") ); handle->dialog = GTK_DIALOG( - gtk_builder_get_object(handle->builder, "new_group_dialog") + gtk_builder_get_object(handle->builder, "new_group_dialog") ); gtk_window_set_transient_for( - GTK_WINDOW(handle->dialog), - GTK_WINDOW(app->ui.messenger.main_window) + GTK_WINDOW(handle->dialog), + GTK_WINDOW(app->ui.messenger.main_window) ); handle->stack = GTK_STACK( - gtk_builder_get_object(handle->builder, "new_group_stack") + gtk_builder_get_object(handle->builder, "new_group_stack") ); handle->details_box = GTK_WIDGET( - gtk_builder_get_object(handle->builder, "details_box") + gtk_builder_get_object(handle->builder, "details_box") ); handle->contacts_box = GTK_WIDGET( - gtk_builder_get_object(handle->builder, "contacts_box") + gtk_builder_get_object(handle->builder, "contacts_box") ); handle->group_avatar = HDY_AVATAR( - gtk_builder_get_object(handle->builder, "group_avatar") + gtk_builder_get_object(handle->builder, "group_avatar") ); handle->group_avatar_file = GTK_FILE_CHOOSER_BUTTON( - gtk_builder_get_object(handle->builder, "group_avatar_file") + gtk_builder_get_object(handle->builder, "group_avatar_file") ); handle->group_entry = GTK_ENTRY( - gtk_builder_get_object(handle->builder, "group_entry") + gtk_builder_get_object(handle->builder, "group_entry") ); g_signal_connect( - handle->group_entry, - "changed", - G_CALLBACK(handle_group_entry_changed), - handle->group_avatar + handle->group_entry, + "changed", + G_CALLBACK(handle_group_entry_changed), + handle->group_avatar ); g_signal_connect( - handle->group_entry, - "activate", - G_CALLBACK(handle_group_entry_activate), - app + handle->group_entry, + "activate", + G_CALLBACK(handle_group_entry_activate), + app ); handle->contact_search_entry = GTK_SEARCH_ENTRY( - gtk_builder_get_object(handle->builder, "contact_search_entry") + gtk_builder_get_object(handle->builder, "contact_search_entry") ); handle->contacts_listbox = GTK_LIST_BOX( - gtk_builder_get_object(handle->builder, "contacts_listbox") + gtk_builder_get_object(handle->builder, "contacts_listbox") ); handle->cancel_button = GTK_BUTTON( - gtk_builder_get_object(handle->builder, "cancel_button") + gtk_builder_get_object(handle->builder, "cancel_button") ); g_signal_connect( - handle->cancel_button, - "clicked", - G_CALLBACK(handle_cancel_button_click), - handle->dialog + handle->cancel_button, + "clicked", + G_CALLBACK(handle_cancel_button_click), + handle->dialog ); handle->previous_button = GTK_BUTTON( - gtk_builder_get_object(handle->builder, "previous_button") + gtk_builder_get_object(handle->builder, "previous_button") ); g_signal_connect( - handle->previous_button, - "clicked", - G_CALLBACK(handle_previous_button_click), - handle + handle->previous_button, + "clicked", + G_CALLBACK(handle_previous_button_click), + handle ); handle->next_button = GTK_BUTTON( - gtk_builder_get_object(handle->builder, "next_button") + gtk_builder_get_object(handle->builder, "next_button") ); g_signal_connect( - handle->next_button, - "clicked", - G_CALLBACK(handle_next_button_click), - handle + handle->next_button, + "clicked", + G_CALLBACK(handle_next_button_click), + handle ); handle->confirm_button = GTK_BUTTON( - gtk_builder_get_object(handle->builder, "confirm_button") + gtk_builder_get_object(handle->builder, "confirm_button") ); g_signal_connect( - handle->confirm_button, - "clicked", - G_CALLBACK(handle_confirm_button_click), - app + handle->confirm_button, + "clicked", + G_CALLBACK(handle_confirm_button_click), + app ); g_signal_connect( - handle->dialog, - "destroy", - G_CALLBACK(handle_dialog_destroy), - handle + handle->dialog, + "destroy", + G_CALLBACK(handle_dialog_destroy), + handle ); GNUNET_CHAT_iterate_contacts( - app->chat.messenger.handle, - _iterate_contacts, - app + app->chat.messenger.handle, + _iterate_contacts, + app ); } void ui_new_group_dialog_cleanup(UI_NEW_GROUP_Handle *handle) { + g_assert(handle); + g_object_unref(handle->builder); for (GList *list = handle->contact_entries; list; list = list->next) diff --git a/src/ui/new_group.h b/src/ui/new_group.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021--2022 GNUnet e.V. + Copyright (C) 2021--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 @@ -62,7 +62,7 @@ typedef struct UI_NEW_GROUP_Handle */ void ui_new_group_dialog_init(MESSENGER_Application *app, - UI_NEW_GROUP_Handle *handle); + UI_NEW_GROUP_Handle *handle); /** * Cleans up the allocated resources and resets the diff --git a/src/ui/new_lobby.c b/src/ui/new_lobby.c @@ -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 @@ -28,31 +28,39 @@ static void handle_warning_info_bar_close(GtkInfoBar *info_bar, - UNUSED gpointer user_data) + UNUSED gpointer user_data) { + g_assert(info_bar); + gtk_info_bar_set_revealed(info_bar, FALSE); } static void handle_warning_info_bar_response(GtkInfoBar *info_bar, - UNUSED int response_id, - UNUSED gpointer user_data) + UNUSED int response_id, + UNUSED gpointer user_data) { + g_assert(info_bar); + gtk_info_bar_set_revealed(info_bar, FALSE); } static void handle_cancel_button_click(UNUSED GtkButton *button, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + GtkDialog *dialog = GTK_DIALOG(user_data); gtk_window_close(GTK_WINDOW(dialog)); } void handle_lobby_opened_and_uri_generated(void *cls, - const struct GNUNET_CHAT_Uri *uri) + const struct GNUNET_CHAT_Uri *uri) { + g_assert(cls); + MESSENGER_Application *app = (MESSENGER_Application*) cls; if (app->ui.new_lobby.qr) @@ -62,8 +70,8 @@ handle_lobby_opened_and_uri_generated(void *cls, { if (app->ui.new_lobby.preview_stack) gtk_stack_set_visible_child( - app->ui.new_lobby.preview_stack, - app->ui.new_lobby.fail_box + app->ui.new_lobby.preview_stack, + app->ui.new_lobby.fail_box ); app->ui.new_lobby.qr = NULL; @@ -73,11 +81,11 @@ handle_lobby_opened_and_uri_generated(void *cls, gchar *uri_string = GNUNET_CHAT_uri_to_string(uri); app->ui.new_lobby.qr = QRcode_encodeString( - uri_string, - 0, - QR_ECLEVEL_L, - QR_MODE_8, - 0 + uri_string, + 0, + QR_ECLEVEL_L, + QR_MODE_8, + 0 ); if (app->ui.new_lobby.id_drawing_area) @@ -85,8 +93,8 @@ handle_lobby_opened_and_uri_generated(void *cls, if (app->ui.new_lobby.preview_stack) gtk_stack_set_visible_child( - app->ui.new_lobby.preview_stack, - GTK_WIDGET(app->ui.new_lobby.id_drawing_area) + app->ui.new_lobby.preview_stack, + GTK_WIDGET(app->ui.new_lobby.id_drawing_area) ); if (app->ui.new_lobby.id_entry) @@ -100,41 +108,42 @@ handle_lobby_opened_and_uri_generated(void *cls, const gint id_length = gtk_entry_get_text_length(app->ui.new_lobby.id_entry); gtk_widget_set_sensitive( - GTK_WIDGET(app->ui.new_lobby.copy_button), - id_length > 0? TRUE : FALSE + GTK_WIDGET(app->ui.new_lobby.copy_button), + id_length > 0? TRUE : FALSE ); } static void handle_generate_button_click(UNUSED GtkButton *button, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; GtkTreeModel *model = gtk_combo_box_get_model( - app->ui.new_lobby.expiration_combo_box + app->ui.new_lobby.expiration_combo_box ); gulong delay = 0; GtkTreeIter iter; - if (gtk_combo_box_get_active_iter(app->ui.new_lobby.expiration_combo_box, - &iter)) + if (gtk_combo_box_get_active_iter(app->ui.new_lobby.expiration_combo_box, &iter)) gtk_tree_model_get(model, &iter, 1, &delay, -1); struct GNUNET_TIME_Relative expiration = GNUNET_TIME_relative_multiply( - GNUNET_TIME_relative_get_second_(), - delay + GNUNET_TIME_relative_get_second_(), + delay ); gtk_stack_set_visible_child( - app->ui.new_lobby.preview_stack, - GTK_WIDGET(app->ui.new_lobby.loading_spinner) + app->ui.new_lobby.preview_stack, + GTK_WIDGET(app->ui.new_lobby.loading_spinner) ); gtk_stack_set_visible_child( - app->ui.new_lobby.stack, - app->ui.new_lobby.copy_box + app->ui.new_lobby.stack, + app->ui.new_lobby.copy_box ); gtk_widget_set_sensitive(GTK_WIDGET(app->ui.new_lobby.copy_button), FALSE); @@ -143,17 +152,19 @@ handle_generate_button_click(UNUSED GtkButton *button, gtk_widget_set_visible(GTK_WIDGET(app->ui.new_lobby.copy_button), TRUE); GNUNET_CHAT_lobby_open( - app->chat.messenger.handle, - expiration, - handle_lobby_opened_and_uri_generated, - app + app->chat.messenger.handle, + expiration, + handle_lobby_opened_and_uri_generated, + app ); } static void handle_copy_button_click(UNUSED GtkButton *button, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; const gint id_length = gtk_entry_get_text_length(app->ui.new_lobby.id_entry); @@ -169,16 +180,20 @@ handle_copy_button_click(UNUSED GtkButton *button, static void handle_dialog_destroy(UNUSED GtkWidget *window, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + ui_new_lobby_dialog_cleanup((UI_NEW_LOBBY_Handle*) user_data); } static gboolean handle_id_drawing_area_draw(GtkWidget* drawing_area, - cairo_t* cairo, - gpointer user_data) + cairo_t* cairo, + gpointer user_data) { + g_assert((drawing_area) && (cairo) && (user_data)); + UI_NEW_LOBBY_Handle *handle = (UI_NEW_LOBBY_Handle*) user_data; GtkStyleContext* context = gtk_widget_get_style_context(drawing_area); @@ -207,24 +222,24 @@ handle_id_drawing_area_draw(GtkWidget* drawing_area, guchar value; if ((x >= m) && (y >= m) && (x - m < w) && (y - m < w)) - value = ((handle->qr->data[(y - m) * w + x - m]) & 1); + value = ((handle->qr->data[(y - m) * w + x - m]) & 1); else - value = 0; + value = 0; for (z = 0; z < 3; z++) - pixels[(y * w2 + x) * 3 + z] = value? 0x00 : 0xff; + pixels[(y * w2 + x) * 3 + z] = value? 0x00 : 0xff; } GdkPixbuf *image = gdk_pixbuf_new_from_data( - pixels, - GDK_COLORSPACE_RGB, - FALSE, - 8, - w2, - w2, - w2 * 3, - NULL, - NULL + pixels, + GDK_COLORSPACE_RGB, + FALSE, + 8, + w2, + w2, + w2 * 3, + NULL, + NULL ); if (!image) @@ -245,15 +260,15 @@ handle_id_drawing_area_draw(GtkWidget* drawing_area, double dy = (height - dheight) * 0.5; const int interp_type = (ratio >= 1.0? - GDK_INTERP_NEAREST : - GDK_INTERP_BILINEAR + GDK_INTERP_NEAREST : + GDK_INTERP_BILINEAR ); GdkPixbuf* scaled = gdk_pixbuf_scale_simple( - image, - dwidth, - dheight, - interp_type + image, + dwidth, + dheight, + interp_type ); gtk_render_icon(context, cairo, scaled, dx, dy); @@ -270,129 +285,133 @@ handle_id_drawing_area_draw(GtkWidget* drawing_area, void ui_new_lobby_dialog_init(MESSENGER_Application *app, - UI_NEW_LOBBY_Handle *handle) + UI_NEW_LOBBY_Handle *handle) { + g_assert((app) && (handle)); + handle->builder = gtk_builder_new_from_resource( - application_get_resource_path(app, "ui/new_lobby.ui") + application_get_resource_path(app, "ui/new_lobby.ui") ); handle->dialog = GTK_DIALOG( - gtk_builder_get_object(handle->builder, "new_lobby_dialog") + gtk_builder_get_object(handle->builder, "new_lobby_dialog") ); gtk_window_set_transient_for( - GTK_WINDOW(handle->dialog), - GTK_WINDOW(app->ui.messenger.main_window) + GTK_WINDOW(handle->dialog), + GTK_WINDOW(app->ui.messenger.main_window) ); handle->warning_info_bar = GTK_INFO_BAR( - gtk_builder_get_object(handle->builder, "warning_info_bar") + gtk_builder_get_object(handle->builder, "warning_info_bar") ); g_signal_connect( - handle->warning_info_bar, - "close", - G_CALLBACK(handle_warning_info_bar_close), - NULL + handle->warning_info_bar, + "close", + G_CALLBACK(handle_warning_info_bar_close), + NULL ); g_signal_connect( - handle->warning_info_bar, - "response", - G_CALLBACK(handle_warning_info_bar_response), - NULL + handle->warning_info_bar, + "response", + G_CALLBACK(handle_warning_info_bar_response), + NULL ); handle->stack = GTK_STACK( - gtk_builder_get_object(handle->builder, "new_lobby_stack") + gtk_builder_get_object(handle->builder, "new_lobby_stack") ); handle->generate_box = GTK_WIDGET( - gtk_builder_get_object(handle->builder, "generate_box") + gtk_builder_get_object(handle->builder, "generate_box") ); handle->copy_box = GTK_WIDGET( - gtk_builder_get_object(handle->builder, "copy_box") + gtk_builder_get_object(handle->builder, "copy_box") ); handle->expiration_combo_box = GTK_COMBO_BOX( - gtk_builder_get_object(handle->builder, "expiration_combo_box") + gtk_builder_get_object(handle->builder, "expiration_combo_box") ); handle->preview_stack = GTK_STACK( - gtk_builder_get_object(handle->builder, "preview_stack") + gtk_builder_get_object(handle->builder, "preview_stack") ); handle->fail_box = GTK_WIDGET( - gtk_builder_get_object(handle->builder, "fail_box") + gtk_builder_get_object(handle->builder, "fail_box") ); handle->loading_spinner = GTK_SPINNER( - gtk_builder_get_object(handle->builder, "loading_spinner") + gtk_builder_get_object(handle->builder, "loading_spinner") ); handle->id_drawing_area = GTK_DRAWING_AREA( - gtk_builder_get_object(handle->builder, "id_drawing_area") + gtk_builder_get_object(handle->builder, "id_drawing_area") ); handle->id_draw_signal = g_signal_connect( - handle->id_drawing_area, - "draw", - G_CALLBACK(handle_id_drawing_area_draw), - handle + handle->id_drawing_area, + "draw", + G_CALLBACK(handle_id_drawing_area_draw), + handle ); handle->id_entry = GTK_ENTRY( - gtk_builder_get_object(handle->builder, "id_entry") + gtk_builder_get_object(handle->builder, "id_entry") ); handle->cancel_button = GTK_BUTTON( - gtk_builder_get_object(handle->builder, "cancel_button") + gtk_builder_get_object(handle->builder, "cancel_button") ); g_signal_connect( - handle->cancel_button, - "clicked", - G_CALLBACK(handle_cancel_button_click), - handle->dialog + handle->cancel_button, + "clicked", + G_CALLBACK(handle_cancel_button_click), + handle->dialog ); handle->generate_button = GTK_BUTTON( - gtk_builder_get_object(handle->builder, "generate_button") + gtk_builder_get_object(handle->builder, "generate_button") ); g_signal_connect( - handle->generate_button, - "clicked", - G_CALLBACK(handle_generate_button_click), - app + handle->generate_button, + "clicked", + G_CALLBACK(handle_generate_button_click), + app ); handle->copy_button = GTK_BUTTON( - gtk_builder_get_object(handle->builder, "copy_button") + gtk_builder_get_object(handle->builder, "copy_button") ); g_signal_connect( - handle->copy_button, - "clicked", - G_CALLBACK(handle_copy_button_click), - app + handle->copy_button, + "clicked", + G_CALLBACK(handle_copy_button_click), + app ); g_signal_connect( - handle->dialog, - "destroy", - G_CALLBACK(handle_dialog_destroy), - handle + handle->dialog, + "destroy", + G_CALLBACK(handle_dialog_destroy), + handle ); } void ui_new_lobby_dialog_cleanup(UI_NEW_LOBBY_Handle *handle) { + g_assert(handle); + g_signal_handler_disconnect( - handle->id_drawing_area, - handle->id_draw_signal + handle->id_drawing_area, + handle->id_draw_signal ); g_object_unref(handle->builder); diff --git a/src/ui/new_lobby.h b/src/ui/new_lobby.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 @@ -70,7 +70,7 @@ typedef struct UI_NEW_LOBBY_Handle */ void ui_new_lobby_dialog_init(MESSENGER_Application *app, - UI_NEW_LOBBY_Handle *handle); + UI_NEW_LOBBY_Handle *handle); /** * Cleans up the allocated resources and resets the diff --git a/src/ui/new_platform.c b/src/ui/new_platform.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021--2022 GNUnet e.V. + Copyright (C) 2021--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 @@ -27,15 +27,18 @@ #include "../application.h" static void -_open_new_platform(GtkEntry *entry, MESSENGER_Application *app) +_open_new_platform(GtkEntry *entry, + MESSENGER_Application *app) { + g_assert((entry) && (app)); + const gchar *topic = gtk_entry_get_text(entry); GString *topic_string = g_string_new(topic); struct GNUNET_CHAT_Group *group = GNUNET_CHAT_group_create( - app->chat.messenger.handle, - topic_string->str + app->chat.messenger.handle, + topic_string->str ); g_string_prepend_c(topic_string, '#'); @@ -46,8 +49,10 @@ _open_new_platform(GtkEntry *entry, MESSENGER_Application *app) static void handle_platform_entry_changed(GtkEditable *editable, - gpointer user_data) + gpointer user_data) { + g_assert((editable) && (user_data)); + HdyAvatar *avatar = HDY_AVATAR(user_data); GtkEntry *entry = GTK_ENTRY(editable); @@ -65,8 +70,10 @@ handle_platform_entry_changed(GtkEditable *editable, static void handle_platform_entry_activate(GtkEntry *entry, - gpointer user_data) + gpointer user_data) { + g_assert((entry) && (user_data)); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; _open_new_platform(entry, app); @@ -76,16 +83,20 @@ handle_platform_entry_activate(GtkEntry *entry, static void handle_cancel_button_click(UNUSED GtkButton *button, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + GtkDialog *dialog = GTK_DIALOG(user_data); gtk_window_close(GTK_WINDOW(dialog)); } static void handle_confirm_button_click(UNUSED GtkButton *button, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; _open_new_platform(app->ui.new_platform.platform_entry, app); @@ -95,87 +106,93 @@ handle_confirm_button_click(UNUSED GtkButton *button, static void handle_dialog_destroy(UNUSED GtkWidget *window, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + ui_new_platform_dialog_cleanup((UI_NEW_PLATFORM_Handle*) user_data); } void ui_new_platform_dialog_init(MESSENGER_Application *app, - UI_NEW_PLATFORM_Handle *handle) + UI_NEW_PLATFORM_Handle *handle) { + g_assert((app) && (handle)); + handle->builder = gtk_builder_new_from_resource( - application_get_resource_path(app, "ui/new_platform.ui") + application_get_resource_path(app, "ui/new_platform.ui") ); handle->dialog = GTK_DIALOG( - gtk_builder_get_object(handle->builder, "new_platform_dialog") + gtk_builder_get_object(handle->builder, "new_platform_dialog") ); gtk_window_set_transient_for( - GTK_WINDOW(handle->dialog), - GTK_WINDOW(app->ui.messenger.main_window) + GTK_WINDOW(handle->dialog), + GTK_WINDOW(app->ui.messenger.main_window) ); handle->platform_avatar = HDY_AVATAR( - gtk_builder_get_object(handle->builder, "platform_avatar") + gtk_builder_get_object(handle->builder, "platform_avatar") ); handle->platform_avatar_file = GTK_FILE_CHOOSER_BUTTON( - gtk_builder_get_object(handle->builder, "platform_avatar_file") + gtk_builder_get_object(handle->builder, "platform_avatar_file") ); handle->platform_entry = GTK_ENTRY( - gtk_builder_get_object(handle->builder, "platform_entry") + gtk_builder_get_object(handle->builder, "platform_entry") ); g_signal_connect( - handle->platform_entry, - "changed", - G_CALLBACK(handle_platform_entry_changed), - handle->platform_avatar + handle->platform_entry, + "changed", + G_CALLBACK(handle_platform_entry_changed), + handle->platform_avatar ); g_signal_connect( - handle->platform_entry, - "activate", - G_CALLBACK(handle_platform_entry_activate), - app + handle->platform_entry, + "activate", + G_CALLBACK(handle_platform_entry_activate), + app ); handle->cancel_button = GTK_BUTTON( - gtk_builder_get_object(handle->builder, "cancel_button") + gtk_builder_get_object(handle->builder, "cancel_button") ); g_signal_connect( - handle->cancel_button, - "clicked", - G_CALLBACK(handle_cancel_button_click), - handle->dialog + handle->cancel_button, + "clicked", + G_CALLBACK(handle_cancel_button_click), + handle->dialog ); handle->confirm_button = GTK_BUTTON( - gtk_builder_get_object(handle->builder, "confirm_button") + gtk_builder_get_object(handle->builder, "confirm_button") ); g_signal_connect( - handle->confirm_button, - "clicked", - G_CALLBACK(handle_confirm_button_click), - app + handle->confirm_button, + "clicked", + G_CALLBACK(handle_confirm_button_click), + app ); g_signal_connect( - handle->dialog, - "destroy", - G_CALLBACK(handle_dialog_destroy), - handle + handle->dialog, + "destroy", + G_CALLBACK(handle_dialog_destroy), + handle ); } void ui_new_platform_dialog_cleanup(UI_NEW_PLATFORM_Handle *handle) { + g_assert(handle); + g_object_unref(handle->builder); memset(handle, 0, sizeof(*handle)); diff --git a/src/ui/new_platform.h b/src/ui/new_platform.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021--2022 GNUnet e.V. + Copyright (C) 2021--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 @@ -50,7 +50,7 @@ typedef struct UI_NEW_PLATFORM_Handle */ void ui_new_platform_dialog_init(MESSENGER_Application *app, - UI_NEW_PLATFORM_Handle *handle); + UI_NEW_PLATFORM_Handle *handle); /** * Cleans up the allocated resources and resets the diff --git a/src/ui/picker.c b/src/ui/picker.c @@ -34,6 +34,8 @@ static void handle_emoji_button_click(GtkButton *button, gpointer user_data) { + g_assert((button) && (user_data)); + GtkTextView *text_view = GTK_TEXT_VIEW(user_data); GtkTextBuffer *text_buffer = gtk_text_view_get_buffer(text_view); @@ -49,6 +51,8 @@ _add_emoji_buttons(GtkFlowBox *flow_box, size_t characters_count, const uint32_t *characters) { + g_assert((flow_box) && (text_view) && (characters)); + glong items_written; GError *error; gchar *utf8; @@ -87,6 +91,8 @@ static void _filter_emoji_buttons(GtkWidget* widget, gpointer user_data) { + g_assert((widget) && (user_data)); + GtkSearchEntry *entry = GTK_SEARCH_ENTRY(user_data); const gchar *filter = gtk_entry_get_text(GTK_ENTRY(entry)); @@ -152,6 +158,8 @@ static void handle_emoji_search_entry_search_changed(GtkSearchEntry *entry, gpointer user_data) { + g_assert((entry) && (user_data)); + UI_PICKER_Handle *handle = (UI_PICKER_Handle*) user_data; gtk_container_foreach( @@ -213,6 +221,8 @@ static void handle_search_button_click(UNUSED GtkButton *button, gpointer user_data) { + g_assert(user_data); + UI_PICKER_Handle *handle = (UI_PICKER_Handle*) user_data; const gchar* picked = gtk_stack_get_visible_child_name(handle->picker_stack); @@ -233,6 +243,8 @@ static void handle_settings_button_click(UNUSED GtkButton *button, UNUSED gpointer user_data) { + // g_assert(user_data); + // MESSENGER_Application *app = (MESSENGER_Application*) user_data; // TODO } @@ -241,6 +253,8 @@ UI_PICKER_Handle* ui_picker_new(MESSENGER_Application *app, UI_CHAT_Handle *chat) { + g_assert((app) && (chat)); + UI_PICKER_Handle *handle = g_malloc(sizeof(UI_PICKER_Handle)); handle->builder = gtk_builder_new_from_resource( @@ -406,6 +420,8 @@ ui_picker_new(MESSENGER_Application *app, void ui_picker_delete(UI_PICKER_Handle *handle) { + g_assert(handle); + hdy_view_switcher_bar_set_stack(handle->picker_switcher_bar, NULL); hdy_view_switcher_bar_set_stack(handle->emoji_switcher_bar, NULL); diff --git a/src/ui/picker.h b/src/ui/picker.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021--2022 GNUnet e.V. + Copyright (C) 2021--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 @@ -68,7 +68,7 @@ typedef struct UI_PICKER_Handle */ UI_PICKER_Handle* ui_picker_new(MESSENGER_Application *app, - UI_CHAT_Handle *chat); + UI_CHAT_Handle *chat); /** * Frees its resources and destroys a given picker diff --git a/src/ui/play_media.c b/src/ui/play_media.c @@ -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 @@ -26,6 +26,7 @@ #include "../application.h" #include "../ui.h" +#include "../util.h" gboolean ui_play_media_window_supports_file_extension(const gchar *filename) @@ -49,17 +50,21 @@ ui_play_media_window_supports_file_extension(const gchar *filename) } static void -handle_back_button_click(GtkButton *button, - gpointer user_data) +handle_back_button_click(UNUSED GtkButton *button, + gpointer user_data) { + g_assert(user_data); + GtkWindow *window = GTK_WINDOW(user_data); gtk_window_close(window); } static void _set_media_controls_sensivity(UI_PLAY_MEDIA_Handle *handle, - gboolean sensitive) + gboolean sensitive) { + g_assert(handle); + if (handle->play_pause_button) gtk_widget_set_sensitive( GTK_WIDGET(handle->play_pause_button), @@ -81,12 +86,14 @@ _set_media_controls_sensivity(UI_PLAY_MEDIA_Handle *handle, static void handle_timeline_scale_value_changed(GtkRange *range, - gpointer user_data); + gpointer user_data); static void _set_signal_connection_of_timeline(UI_PLAY_MEDIA_Handle *handle, - gboolean connected) + gboolean connected) { + g_assert(handle); + if (!(handle->timeline_scale)) return; @@ -95,7 +102,7 @@ _set_signal_connection_of_timeline(UI_PLAY_MEDIA_Handle *handle, if (connected) handle->timeline_signal = g_signal_connect( - handle->timeline_scale, + handle->timeline_scale, "value-changed", G_CALLBACK(handle_timeline_scale_value_changed), handle @@ -103,8 +110,8 @@ _set_signal_connection_of_timeline(UI_PLAY_MEDIA_Handle *handle, else { g_signal_handler_disconnect( - handle->timeline_scale, - handle->timeline_signal + handle->timeline_scale, + handle->timeline_signal ); handle->timeline_signal = 0; @@ -113,10 +120,12 @@ _set_signal_connection_of_timeline(UI_PLAY_MEDIA_Handle *handle, static void _set_media_position(UI_PLAY_MEDIA_Handle *handle, - gint64 pos, - gint64 len, - gboolean include_scale) + gint64 pos, + gint64 len, + gboolean include_scale) { + g_assert(handle); + const gdouble position = ( len > 0? 1.0 * pos / len : 0.0 ); @@ -163,6 +172,8 @@ _set_media_position(UI_PLAY_MEDIA_Handle *handle, static gboolean _adjust_playing_media_position(UI_PLAY_MEDIA_Handle *handle) { + g_assert(handle); + gint64 pos, len; if (!(handle->pipeline)) @@ -180,8 +191,10 @@ _adjust_playing_media_position(UI_PLAY_MEDIA_Handle *handle) static void _set_timeout_callback_of_timeline(UI_PLAY_MEDIA_Handle *handle, - gboolean connected) + gboolean connected) { + g_assert(handle); + if (handle->timeline) g_source_remove(handle->timeline); @@ -197,8 +210,10 @@ _set_timeout_callback_of_timeline(UI_PLAY_MEDIA_Handle *handle, static void _set_media_state(UI_PLAY_MEDIA_Handle *handle, - gboolean playing) + gboolean playing) { + g_assert(handle); + if (handle->play_symbol_stack) gtk_stack_set_visible_child_name( handle->play_symbol_stack, @@ -210,9 +225,9 @@ _set_media_state(UI_PLAY_MEDIA_Handle *handle, static void _disable_video_processing(UI_PLAY_MEDIA_Handle *handle, - gboolean drop_pipeline) + gboolean drop_pipeline) { - GNUNET_assert(handle); + g_assert(handle); if (handle->preview_stack) gtk_stack_set_visible_child(handle->preview_stack, handle->fail_box); @@ -437,16 +452,20 @@ handle_media_motion_notify(GtkWidget *widget, static void handle_window_destroy(UNUSED GtkWidget *window, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + ui_play_media_window_cleanup((UI_PLAY_MEDIA_Handle*) user_data); } static void msg_error_cb(UNUSED GstBus *bus, - GstMessage *msg, - gpointer data) + GstMessage *msg, + gpointer data) { + g_assert((msg) && (data)); + UI_PLAY_MEDIA_Handle *handle = (UI_PLAY_MEDIA_Handle*) data; GError* error; @@ -464,9 +483,11 @@ msg_error_cb(UNUSED GstBus *bus, static void msg_eos_cb(UNUSED GstBus *bus, - UNUSED GstMessage *msg, - gpointer data) + UNUSED GstMessage *msg, + gpointer data) { + g_assert(data); + UI_PLAY_MEDIA_Handle *handle = (UI_PLAY_MEDIA_Handle*) data; if (GST_MESSAGE_SRC(msg) != GST_OBJECT(handle->pipeline)) @@ -480,9 +501,11 @@ msg_eos_cb(UNUSED GstBus *bus, static void msg_state_changed_cb(UNUSED GstBus *bus, - GstMessage *msg, - gpointer data) + GstMessage *msg, + gpointer data) { + g_assert((msg) && (data)); + UI_PLAY_MEDIA_Handle *handle = (UI_PLAY_MEDIA_Handle*) data; GstState old_state, new_state, pending_state; @@ -508,9 +531,11 @@ msg_state_changed_cb(UNUSED GstBus *bus, static void msg_buffering_cb(UNUSED GstBus *bus, - GstMessage *msg, - gpointer data) + GstMessage *msg, + gpointer data) { + g_assert((msg) && (data)); + UI_PLAY_MEDIA_Handle *handle = (UI_PLAY_MEDIA_Handle*) data; gint percent = 0; @@ -528,6 +553,8 @@ msg_buffering_cb(UNUSED GstBus *bus, static void _setup_gst_pipeline(UI_PLAY_MEDIA_Handle *handle) { + g_assert(handle); + handle->pipeline = gst_element_factory_make("playbin", NULL); if (!(handle->pipeline)) @@ -586,6 +613,8 @@ _setup_gst_pipeline(UI_PLAY_MEDIA_Handle *handle) static void* _ui_play_media_video_thread(void *args) { + g_assert(args); + UI_PLAY_MEDIA_Handle *handle = (UI_PLAY_MEDIA_Handle*) args; _continue_playing_media(handle); return NULL; @@ -593,67 +622,67 @@ _ui_play_media_video_thread(void *args) void ui_play_media_window_init(MESSENGER_Application *app, - UI_PLAY_MEDIA_Handle *handle) + UI_PLAY_MEDIA_Handle *handle) { - GNUNET_assert((app) && (handle)); + g_assert((app) && (handle)); _setup_gst_pipeline(handle); handle->parent = GTK_WINDOW(app->ui.messenger.main_window); handle->builder = gtk_builder_new_from_resource( - application_get_resource_path(app, "ui/play_media.ui") + application_get_resource_path(app, "ui/play_media.ui") ); handle->window = HDY_WINDOW( - gtk_builder_get_object(handle->builder, "play_media_window") + gtk_builder_get_object(handle->builder, "play_media_window") ); gtk_window_set_position( - GTK_WINDOW(handle->window), - GTK_WIN_POS_CENTER_ON_PARENT + GTK_WINDOW(handle->window), + GTK_WIN_POS_CENTER_ON_PARENT ); gtk_window_set_transient_for( - GTK_WINDOW(handle->window), - handle->parent + GTK_WINDOW(handle->window), + handle->parent ); handle->header_revealer = GTK_REVEALER( - gtk_builder_get_object(handle->builder, "header_revealer") + gtk_builder_get_object(handle->builder, "header_revealer") ); handle->title_bar = HDY_HEADER_BAR( - gtk_builder_get_object(handle->builder, "title_bar") + gtk_builder_get_object(handle->builder, "title_bar") ); hdy_header_bar_set_title(handle->title_bar, _("Play Media")); handle->back_button = GTK_BUTTON( - gtk_builder_get_object(handle->builder, "back_button") + gtk_builder_get_object(handle->builder, "back_button") ); g_signal_connect( - handle->back_button, - "clicked", - G_CALLBACK(handle_back_button_click), - handle->window + handle->back_button, + "clicked", + G_CALLBACK(handle_back_button_click), + handle->window ); handle->controls_flap = HDY_FLAP( - gtk_builder_get_object(handle->builder, "controls_flap") + gtk_builder_get_object(handle->builder, "controls_flap") ); handle->preview_stack = GTK_STACK( - gtk_builder_get_object(handle->builder, "preview_stack") + gtk_builder_get_object(handle->builder, "preview_stack") ); handle->fail_box = GTK_WIDGET( - gtk_builder_get_object(handle->builder, "fail_box") + gtk_builder_get_object(handle->builder, "fail_box") ); handle->video_box = GTK_WIDGET( - gtk_builder_get_object(handle->builder, "video_box") + gtk_builder_get_object(handle->builder, "video_box") ); GtkWidget *widget; @@ -679,87 +708,87 @@ ui_play_media_window_init(MESSENGER_Application *app, } handle->play_pause_button = GTK_BUTTON( - gtk_builder_get_object(handle->builder, "play_pause_button") + gtk_builder_get_object(handle->builder, "play_pause_button") ); handle->play_symbol_stack = GTK_STACK( - gtk_builder_get_object(handle->builder, "play_symbol_stack") + gtk_builder_get_object(handle->builder, "play_symbol_stack") ); g_signal_connect( - handle->play_pause_button, - "clicked", - G_CALLBACK(handle_play_pause_button_click), - handle + handle->play_pause_button, + "clicked", + G_CALLBACK(handle_play_pause_button_click), + handle ); handle->volume_button = GTK_VOLUME_BUTTON( - gtk_builder_get_object(handle->builder, "volume_button") + gtk_builder_get_object(handle->builder, "volume_button") ); g_signal_connect( - handle->volume_button, - "value-changed", - G_CALLBACK(handle_volume_button_value_changed), - handle + handle->volume_button, + "value-changed", + G_CALLBACK(handle_volume_button_value_changed), + handle ); handle->timeline_label = GTK_LABEL( - gtk_builder_get_object(handle->builder, "timeline_label") + gtk_builder_get_object(handle->builder, "timeline_label") ); handle->timeline_progress_bar = GTK_PROGRESS_BAR( - gtk_builder_get_object(handle->builder, "timeline_progress_bar") + gtk_builder_get_object(handle->builder, "timeline_progress_bar") ); handle->timeline_scale = GTK_SCALE( - gtk_builder_get_object(handle->builder, "timeline_scale") + gtk_builder_get_object(handle->builder, "timeline_scale") ); _set_signal_connection_of_timeline(handle, handle->sink? TRUE : FALSE); handle->settings_button = GTK_BUTTON( - gtk_builder_get_object(handle->builder, "settings_button") + gtk_builder_get_object(handle->builder, "settings_button") ); handle->fullscreen_button = GTK_BUTTON( - gtk_builder_get_object(handle->builder, "fullscreen_button") + gtk_builder_get_object(handle->builder, "fullscreen_button") ); handle->fullscreen_symbol_stack = GTK_STACK( - gtk_builder_get_object(handle->builder, "fullscreen_symbol_stack") + gtk_builder_get_object(handle->builder, "fullscreen_symbol_stack") ); g_signal_connect( - handle->fullscreen_button, - "clicked", - G_CALLBACK(handle_fullscreen_button_click), - handle + handle->fullscreen_button, + "clicked", + G_CALLBACK(handle_fullscreen_button_click), + handle ); g_signal_connect( - handle->window, - "motion-notify-event", - G_CALLBACK(handle_media_motion_notify), - handle + handle->window, + "motion-notify-event", + G_CALLBACK(handle_media_motion_notify), + handle ); gtk_widget_add_events( - GTK_WIDGET(handle->window), - GDK_POINTER_MOTION_HINT_MASK | - GDK_POINTER_MOTION_MASK + GTK_WIDGET(handle->window), + GDK_POINTER_MOTION_HINT_MASK | + GDK_POINTER_MOTION_MASK ); g_signal_connect( - handle->window, - "destroy", - G_CALLBACK(handle_window_destroy), - handle + handle->window, + "destroy", + G_CALLBACK(handle_window_destroy), + handle ); gtk_scale_button_set_value( - GTK_SCALE_BUTTON(handle->volume_button), - 1.0 + GTK_SCALE_BUTTON(handle->volume_button), + 1.0 ); gtk_widget_show_all(GTK_WIDGET(handle->window)); @@ -770,7 +799,7 @@ ui_play_media_window_update(UI_PLAY_MEDIA_Handle *handle, const gchar *uri, const struct GNUNET_CHAT_File *file) { - GNUNET_assert((handle) && (uri)); + g_assert((handle) && (uri)); if (handle->video_tid) pthread_join(handle->video_tid, NULL); @@ -789,22 +818,22 @@ ui_play_media_window_update(UI_PLAY_MEDIA_Handle *handle, filename = uri; hdy_header_bar_set_subtitle( - handle->title_bar, - filename? filename : "" + handle->title_bar, + filename? filename : "" ); pthread_create( - &(handle->video_tid), - NULL, - _ui_play_media_video_thread, - handle + &(handle->video_tid), + NULL, + _ui_play_media_video_thread, + handle ); } void ui_play_media_window_cleanup(UI_PLAY_MEDIA_Handle *handle) { - GNUNET_assert(handle); + g_assert(handle); if (handle->video_tid) pthread_join(handle->video_tid, NULL); diff --git a/src/ui/play_media.h b/src/ui/play_media.h @@ -94,7 +94,7 @@ ui_play_media_window_supports_file_extension(const gchar *filename); */ void ui_play_media_window_init(MESSENGER_Application *app, - UI_PLAY_MEDIA_Handle *handle); + UI_PLAY_MEDIA_Handle *handle); /** * Updates a handle for the play media window with @@ -106,8 +106,8 @@ ui_play_media_window_init(MESSENGER_Application *app, */ void ui_play_media_window_update(UI_PLAY_MEDIA_Handle *handle, - const gchar *uri, - const struct GNUNET_CHAT_File *file); + const gchar *uri, + const struct GNUNET_CHAT_File *file); /** * Cleans up the allocated resources and resets the diff --git a/src/ui/send_file.c b/src/ui/send_file.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021--2022 GNUnet e.V. + Copyright (C) 2021--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,22 +30,25 @@ #include "../application.h" #include "../file.h" -#include "../ui.h" static void handle_cancel_button_click(UNUSED GtkButton *button, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + GtkDialog *dialog = GTK_DIALOG(user_data); gtk_window_close(GTK_WINDOW(dialog)); } static void handle_sending_upload_file(UNUSED void *cls, - const struct GNUNET_CHAT_File *file, - uint64_t completed, - uint64_t size) + const struct GNUNET_CHAT_File *file, + uint64_t completed, + uint64_t size) { + g_assert(file); + UI_FILE_LOAD_ENTRY_Handle *file_load = cls; gtk_progress_bar_set_fraction( @@ -61,26 +64,28 @@ handle_sending_upload_file(UNUSED void *cls, static void handle_send_button_click(GtkButton *button, - gpointer user_data) + gpointer user_data) { + g_assert((button) && (user_data)); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; GtkTextView *text_view = GTK_TEXT_VIEW( - g_object_get_qdata(G_OBJECT(button), app->quarks.widget) + g_object_get_qdata(G_OBJECT(button), app->quarks.widget) ); if (!text_view) return; gchar *filename = gtk_file_chooser_get_filename( - GTK_FILE_CHOOSER(app->ui.send_file.file_chooser_button) + GTK_FILE_CHOOSER(app->ui.send_file.file_chooser_button) ); if (!filename) return; struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) ( - g_object_get_qdata(G_OBJECT(text_view), app->quarks.data) + g_object_get_qdata(G_OBJECT(text_view), app->quarks.data) ); UI_CHAT_ENTRY_Handle *entry = GNUNET_CHAT_context_get_user_pointer(context); @@ -97,10 +102,10 @@ handle_send_button_click(GtkButton *button, gtk_progress_bar_set_fraction(file_load->load_progress_bar, 0.0); file = GNUNET_CHAT_context_send_file( - context, - filename, - handle_sending_upload_file, - file_load + context, + filename, + handle_sending_upload_file, + file_load ); } @@ -123,14 +128,18 @@ handle_send_button_click(GtkButton *button, static void handle_dialog_destroy(UNUSED GtkWidget *window, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + ui_send_file_dialog_cleanup((UI_SEND_FILE_Handle*) user_data); } static int handle_file_redraw_animation(gpointer user_data) { + g_assert(user_data); + UI_SEND_FILE_Handle *handle = (UI_SEND_FILE_Handle*) user_data; handle->redraw_animation = 0; @@ -144,9 +153,11 @@ handle_file_redraw_animation(gpointer user_data) static gboolean handle_file_drawing_area_draw(GtkWidget* drawing_area, - cairo_t* cairo, - gpointer user_data) + cairo_t* cairo, + gpointer user_data) { + g_assert((drawing_area) && (cairo) && (user_data)); + UI_SEND_FILE_Handle *handle = (UI_SEND_FILE_Handle*) user_data; GtkStyleContext* context = gtk_widget_get_style_context(drawing_area); @@ -165,17 +176,17 @@ handle_file_drawing_area_draw(GtkWidget* drawing_area, gdk_pixbuf_animation_iter_advance(handle->animation_iter, NULL); else handle->animation_iter = gdk_pixbuf_animation_get_iter( - handle->animation, NULL + handle->animation, NULL ); image = gdk_pixbuf_animation_iter_get_pixbuf(handle->animation_iter); const int delay = gdk_pixbuf_animation_iter_get_delay_time( - handle->animation_iter + handle->animation_iter ); handle->redraw_animation = g_timeout_add( - delay, handle_file_redraw_animation, handle + delay, handle_file_redraw_animation, handle ); render_image: @@ -197,15 +208,15 @@ render_image: double dy = (height - dheight) * 0.5; const int interp_type = (ratio >= 1.0? - GDK_INTERP_NEAREST : - GDK_INTERP_BILINEAR + GDK_INTERP_NEAREST : + GDK_INTERP_BILINEAR ); GdkPixbuf* scaled = gdk_pixbuf_scale_simple( - image, - dwidth, - dheight, - interp_type + image, + dwidth, + dheight, + interp_type ); gtk_render_icon(context, cairo, scaled, dx, dy); @@ -219,6 +230,8 @@ render_image: static void _clear_file_preview_data(UI_SEND_FILE_Handle *handle) { + g_assert(handle); + if (handle->image) { g_object_unref(handle->image); @@ -246,8 +259,10 @@ _clear_file_preview_data(UI_SEND_FILE_Handle *handle) static void handle_file_chooser_button_file_set(GtkFileChooserButton *file_chooser_button, - gpointer user_data) + gpointer user_data) { + g_assert((file_chooser_button) && (user_data)); + UI_SEND_FILE_Handle *handle = (UI_SEND_FILE_Handle*) user_data; _clear_file_preview_data(handle); @@ -272,75 +287,77 @@ handle_file_chooser_button_file_set(GtkFileChooserButton *file_chooser_button, void ui_send_file_dialog_init(MESSENGER_Application *app, - UI_SEND_FILE_Handle *handle) + UI_SEND_FILE_Handle *handle) { + g_assert((app) && (handle)); + handle->builder = gtk_builder_new_from_resource( - application_get_resource_path(app, "ui/send_file.ui") + application_get_resource_path(app, "ui/send_file.ui") ); handle->dialog = GTK_DIALOG( - gtk_builder_get_object(handle->builder, "send_file_dialog") + gtk_builder_get_object(handle->builder, "send_file_dialog") ); gtk_window_set_title( - GTK_WINDOW(handle->dialog), - _("Send File") + GTK_WINDOW(handle->dialog), + _("Send File") ); gtk_window_set_transient_for( - GTK_WINDOW(handle->dialog), - GTK_WINDOW(app->ui.messenger.main_window) + GTK_WINDOW(handle->dialog), + GTK_WINDOW(app->ui.messenger.main_window) ); handle->file_drawing_area = GTK_DRAWING_AREA( - gtk_builder_get_object(handle->builder, "file_drawing_area") + gtk_builder_get_object(handle->builder, "file_drawing_area") ); handle->file_chooser_button = GTK_FILE_CHOOSER_BUTTON( - gtk_builder_get_object(handle->builder, "file_chooser_button") + gtk_builder_get_object(handle->builder, "file_chooser_button") ); handle->file_draw_signal = g_signal_connect( - handle->file_drawing_area, - "draw", - G_CALLBACK(handle_file_drawing_area_draw), - handle + handle->file_drawing_area, + "draw", + G_CALLBACK(handle_file_drawing_area_draw), + handle ); g_signal_connect( - handle->file_chooser_button, - "file-set", - G_CALLBACK(handle_file_chooser_button_file_set), - handle + handle->file_chooser_button, + "file-set", + G_CALLBACK(handle_file_chooser_button_file_set), + handle ); handle->cancel_button = GTK_BUTTON( - gtk_builder_get_object(handle->builder, "cancel_button") + gtk_builder_get_object(handle->builder, "cancel_button") ); g_signal_connect( - handle->cancel_button, - "clicked", - G_CALLBACK(handle_cancel_button_click), - handle->dialog + handle->cancel_button, + "clicked", + G_CALLBACK(handle_cancel_button_click), + handle->dialog ); handle->send_button = GTK_BUTTON( - gtk_builder_get_object(handle->builder, "send_button") + gtk_builder_get_object(handle->builder, "send_button") ); g_signal_connect( - handle->send_button, - "clicked", - G_CALLBACK(handle_send_button_click), - app + handle->send_button, + "clicked", + G_CALLBACK(handle_send_button_click), + app ); g_signal_connect( - handle->dialog, - "destroy", - G_CALLBACK(handle_dialog_destroy), - handle + handle->dialog, + "destroy", + G_CALLBACK(handle_dialog_destroy), + handle ); handle->image = NULL; @@ -352,25 +369,29 @@ ui_send_file_dialog_init(MESSENGER_Application *app, void ui_send_file_dialog_update(UI_SEND_FILE_Handle *handle, - const gchar *filename) + const gchar *filename) { + g_assert((handle) && (filename)); + if (!(handle->file_chooser_button)) return; gtk_file_chooser_set_filename( - GTK_FILE_CHOOSER(handle->file_chooser_button), - filename + GTK_FILE_CHOOSER(handle->file_chooser_button), + filename ); handle_file_chooser_button_file_set( - handle->file_chooser_button, - handle + handle->file_chooser_button, + handle ); } void ui_send_file_dialog_cleanup(UI_SEND_FILE_Handle *handle) { + g_assert(handle); + _clear_file_preview_data(handle); g_signal_handler_disconnect( diff --git a/src/ui/send_file.h b/src/ui/send_file.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021--2022 GNUnet e.V. + Copyright (C) 2021--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 @@ -58,7 +58,7 @@ typedef struct UI_SEND_FILE_Handle */ void ui_send_file_dialog_init(MESSENGER_Application *app, - UI_SEND_FILE_Handle *handle); + UI_SEND_FILE_Handle *handle); /** * Updates a given send file dialog handle with @@ -70,7 +70,7 @@ ui_send_file_dialog_init(MESSENGER_Application *app, */ void ui_send_file_dialog_update(UI_SEND_FILE_Handle *handle, - const gchar *filename); + const gchar *filename); /** * Cleans up the allocated resources and resets the diff --git a/src/ui/settings.c b/src/ui/settings.c @@ -36,6 +36,8 @@ handle_general_switch_state(UNUSED GtkSwitch *widget, gboolean state, gpointer user_data) { + g_assert(user_data); + gboolean *setting = (gboolean*) user_data; *setting = state; return FALSE; @@ -46,6 +48,8 @@ _request_background_callback(GObject *source_object, GAsyncResult *result, gpointer user_data) { + g_assert((source_object) && (result) && (user_data)); + XdpPortal *portal = XDP_PORTAL(source_object); MESSENGER_Request *request = (MESSENGER_Request*) user_data; @@ -82,6 +86,8 @@ handle_background_switch_state(GtkSwitch *widget, gboolean state, gpointer user_data) { + g_assert((widget) && (user_data)); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; gboolean *setting = (gboolean*) ( @@ -114,6 +120,8 @@ handle_inverted_switch_state(GtkSwitch *widget, gboolean state, gpointer user_data) { + g_assert((widget) && (user_data)); + return handle_general_switch_state(widget, !state, user_data); } @@ -121,6 +129,8 @@ static void handle_general_combo_box_change(GtkComboBox *widget, gpointer user_data) { + g_assert((widget) && (user_data)); + gulong *delay = (gulong*) user_data; GtkTreeModel *model = gtk_combo_box_get_model(widget); @@ -134,6 +144,8 @@ _leave_group_iteration(UNUSED void *cls, UNUSED struct GNUNET_CHAT_Handle *handle, struct GNUNET_CHAT_Group *group) { + g_assert(group); + GNUNET_CHAT_group_leave(group); return GNUNET_YES; } @@ -143,6 +155,8 @@ _delete_contact_iteration(UNUSED void *cls, UNUSED struct GNUNET_CHAT_Handle *handle, struct GNUNET_CHAT_Contact *contact) { + g_assert(contact); + GNUNET_CHAT_contact_delete(contact); return GNUNET_YES; } @@ -151,6 +165,8 @@ static void handle_leave_chats_button_click(UNUSED GtkButton* button, gpointer user_data) { + g_assert(user_data); + MESSENGER_Application *app = (MESSENGER_Application*) user_data; GNUNET_CHAT_iterate_groups( @@ -168,15 +184,19 @@ handle_leave_chats_button_click(UNUSED GtkButton* button, static void handle_dialog_destroy(UNUSED GtkWidget *window, - gpointer user_data) + gpointer user_data) { + g_assert(user_data); + ui_settings_dialog_cleanup((UI_SETTINGS_Handle*) user_data); } static void _set_combobox_to_active_by_delay(GtkComboBox *widget, - gulong delay) + gulong delay) { + g_assert(widget); + GtkTreeModel *model = gtk_combo_box_get_model(widget); GtkTreeIter iter; @@ -200,9 +220,11 @@ set_active: static enum GNUNET_GenericReturnValue _count_blocked_contacts(void *cls, - struct GNUNET_CHAT_Handle *handle, + UNUSED struct GNUNET_CHAT_Handle *handle, struct GNUNET_CHAT_Contact *contact) { + g_assert((cls) && (contact)); + guint *count = (guint*) cls; if (GNUNET_YES == GNUNET_CHAT_contact_is_blocked(contact)) @@ -215,6 +237,8 @@ void ui_settings_dialog_init(MESSENGER_Application *app, UI_SETTINGS_Handle *handle) { + g_assert((app) && (handle)); + handle->builder = gtk_builder_new_from_resource( application_get_resource_path(app, "ui/settings.ui") ); @@ -472,6 +496,8 @@ ui_settings_dialog_init(MESSENGER_Application *app, void ui_settings_dialog_cleanup(UI_SETTINGS_Handle *handle) { + g_assert(handle); + g_object_unref(handle->builder); memset(handle, 0, sizeof(*handle)); diff --git a/src/ui/settings.h b/src/ui/settings.h @@ -64,7 +64,7 @@ typedef struct UI_SETTINGS_Handle */ void ui_settings_dialog_init(MESSENGER_Application *app, - UI_SETTINGS_Handle *handle); + UI_SETTINGS_Handle *handle); /** * Cleans up the allocated resources and resets the