messenger-gtk

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

commit d78b20cbeda819ccc01bc2d89c951b3e76954270
parent c10ee1dd9e12f3dad6ac1920890552af77d049f3
Author: Jacki <jacki@thejackimonster.de>
Date:   Tue, 17 Jun 2025 01:44:17 +0200

Fix issue opening notes chat

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

Diffstat:
Msrc/event.c | 40+++++++++++++---------------------------
Msrc/ui/message.c | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Msrc/ui/message.h | 21+++++++++++++++++++++
3 files changed, 103 insertions(+), 29 deletions(-)

diff --git a/src/event.c b/src/event.c @@ -35,6 +35,7 @@ #include "ui/chat_title.h" #include "ui/message.h" +#include <glib-2.0/glib.h> #include <gnunet/gnunet_chat_lib.h> #include <gnunet/gnunet_common.h> #include <stdio.h> @@ -650,29 +651,24 @@ event_update_contacts(UNUSED MESSENGER_Application *app, } static void -_event_invitation_accept_click(UNUSED GtkButton *button, - gpointer user_data) +_event_invitation_action(MESSENGER_Application *app, + gboolean status, + gpointer user_data) { - g_assert(user_data); + g_assert((app) && (user_data)); struct GNUNET_CHAT_Invitation *invitation = ( (struct GNUNET_CHAT_Invitation*) user_data ); - GNUNET_CHAT_invitation_accept(invitation); -} + application_chat_lock(app); -static void -_event_invitation_deny_click(UNUSED GtkButton *button, - gpointer user_data) -{ - g_assert(user_data); - - struct GNUNET_CHAT_Invitation *invitation = ( - (struct GNUNET_CHAT_Invitation*) user_data - ); + if (status) + GNUNET_CHAT_invitation_accept(invitation); + else + GNUNET_CHAT_invitation_reject(invitation); - GNUNET_CHAT_invitation_reject(invitation); + application_chat_unlock(app); } void @@ -740,18 +736,8 @@ event_invitation(MESSENGER_Application *app, ui_label_set_text(message->text_label, message_string->str); g_string_free(message_string, TRUE); - g_signal_connect( - message->accept_button, - "clicked", - G_CALLBACK(_event_invitation_accept_click), - invitation - ); - - g_signal_connect( - message->deny_button, - "clicked", - G_CALLBACK(_event_invitation_deny_click), - invitation + ui_message_set_status_callback( + message, _event_invitation_action, invitation ); ui_chat_add_message(handle->chat, app, message); diff --git a/src/ui/message.c b/src/ui/message.c @@ -138,6 +138,42 @@ handle_file_button_click(GtkButton *button, } static void +handle_accept_button_click(GtkButton *button, + gpointer user_data) +{ + g_assert((button) && (user_data)); + + MESSENGER_Application *app = (MESSENGER_Application*) user_data; + + UI_MESSAGE_Handle* handle = (UI_MESSAGE_Handle*) ( + g_object_get_qdata(G_OBJECT(button), app->quarks.ui) + ); + + if ((!handle) || (!(handle->status_cb))) + return; + + handle->status_cb(app, true, handle->status_cls); +} + +static void +handle_deny_button_click(GtkButton *button, + gpointer user_data) +{ + g_assert((button) && (user_data)); + + MESSENGER_Application *app = (MESSENGER_Application*) user_data; + + UI_MESSAGE_Handle* handle = (UI_MESSAGE_Handle*) ( + g_object_get_qdata(G_OBJECT(button), app->quarks.ui) + ); + + if ((!handle) || (!(handle->status_cb))) + return; + + handle->status_cb(app, false, handle->status_cls); +} + +static void handle_media_button_click(GtkButton *button, gpointer user_data) { @@ -266,6 +302,9 @@ ui_message_new(MESSENGER_Application *app, handle->msg = NULL; handle->contact = NULL; + handle->status_cb = NULL; + handle->status_cls = NULL; + const char *ui_builder_file; switch (handle->type) @@ -318,6 +357,23 @@ ui_message_new(MESSENGER_Application *app, handle->accept_button = GTK_BUTTON( gtk_builder_get_object(handle->builder[0], "accept_button") ); + + g_object_set_qdata(G_OBJECT(handle->accept_button), app->quarks.ui, handle); + g_object_set_qdata(G_OBJECT(handle->deny_button), app->quarks.ui, handle); + + g_signal_connect( + handle->accept_button, + "clicked", + G_CALLBACK(handle_accept_button_click), + app + ); + + g_signal_connect( + handle->deny_button, + "clicked", + G_CALLBACK(handle_deny_button_click), + app + ); } else { @@ -418,6 +474,8 @@ ui_message_new(MESSENGER_Application *app, handle->app = app; + g_object_set_qdata(G_OBJECT(handle->media_button), app->quarks.ui, handle); + g_signal_connect( handle->media_button, "clicked", @@ -425,8 +483,6 @@ ui_message_new(MESSENGER_Application *app, app ); - g_object_set_qdata(G_OBJECT(handle->media_button), app->quarks.ui, handle); - switch (handle->type) { case UI_MESSAGE_STATUS: @@ -752,6 +808,17 @@ ui_message_set_contact(UI_MESSAGE_Handle *handle, } void +ui_message_set_status_callback(UI_MESSAGE_Handle *handle, + UI_MESSAGE_StatusCallback cb, + gpointer cls) +{ + g_assert(handle); + + handle->status_cb = cb; + handle->status_cls = cls; +} + +void ui_message_add_tag(UI_MESSAGE_Handle *handle, MESSENGER_Application *app, struct GNUNET_CHAT_Message *tag_message) diff --git a/src/ui/message.h b/src/ui/message.h @@ -27,6 +27,7 @@ #include <stdbool.h> +#include <glib-2.0/glib.h> #include <gtk-3.0/gtk/gtk.h> #include <libhandy-1/handy.h> @@ -41,6 +42,10 @@ typedef enum UI_MESSAGE_Type UI_MESSAGE_STATUS = 2 } UI_MESSAGE_Type; +typedef void (*UI_MESSAGE_StatusCallback)(MESSENGER_Application *app, + gboolean status, + gpointer user_data); + typedef struct UI_MESSAGE_Handle { UI_MESSAGE_Type type; @@ -49,6 +54,9 @@ typedef struct UI_MESSAGE_Handle struct GNUNET_CHAT_Message *msg; struct GNUNET_CHAT_Contact *contact; + UI_MESSAGE_StatusCallback status_cb; + gpointer status_cls; + GtkBuilder *builder [2]; GtkWidget *message_box; GtkFlowBox *tag_flow_box; @@ -135,6 +143,19 @@ ui_message_set_contact(UI_MESSAGE_Handle *handle, struct GNUNET_CHAT_Contact *contact); /** + * Sets the callback and closure of a given message + * handle for actions of a status message. + * + * @param handle Message handle + * @param cb Status callback + * @param cls Status closure + */ +void +ui_message_set_status_callback(UI_MESSAGE_Handle *handle, + UI_MESSAGE_StatusCallback cb, + gpointer cls); + +/** * Adds a widget to represent a given tag message * to another message handle. *