diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2022-03-13 13:56:02 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2022-03-13 13:56:02 +0100 |
commit | 43019c37a2a12147c401d75327e19e2ac383d6f4 (patch) | |
tree | 50c569d564b9c75559e1d7165f973ae956da04a1 | |
parent | 85b243c149d96ac88c5afd20993bbe18c50e16ca (diff) |
Added warning handling and leave messages, cleaning some code and fixed issue with QR pixel data
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | src/chat/messenger.c | 28 | ||||
-rw-r--r-- | src/event.c | 120 | ||||
-rw-r--r-- | src/event.h | 13 | ||||
-rw-r--r-- | src/ui/accounts.c | 10 | ||||
-rw-r--r-- | src/ui/contacts.c | 2 | ||||
-rw-r--r-- | src/ui/delete_messages.c | 2 | ||||
-rw-r--r-- | src/ui/invite_contact.c | 2 | ||||
-rw-r--r-- | src/ui/messenger.c | 1 | ||||
-rw-r--r-- | src/ui/new_account.c | 2 | ||||
-rw-r--r-- | src/ui/new_contact.c | 6 | ||||
-rw-r--r-- | src/ui/new_group.c | 2 | ||||
-rw-r--r-- | src/ui/new_lobby.c | 6 | ||||
-rw-r--r-- | src/ui/new_platform.c | 2 | ||||
-rw-r--r-- | src/ui/send_file.c | 2 | ||||
-rw-r--r-- | src/ui/settings.c | 4 |
15 files changed, 144 insertions, 58 deletions
diff --git a/src/chat/messenger.c b/src/chat/messenger.c index 452e476..6a3f0b9 100644 --- a/src/chat/messenger.c +++ b/src/chat/messenger.c @@ -101,6 +101,14 @@ _chat_messenger_message(void *cls, switch (kind) { + case GNUNET_CHAT_KIND_WARNING: + application_call_message_event( + app, + event_handle_warning, + context, + message + ); + break; case GNUNET_CHAT_KIND_REFRESH: { application_call_event(app, event_refresh_accounts); @@ -122,23 +130,19 @@ _chat_messenger_message(void *cls, break; } case GNUNET_CHAT_KIND_JOIN: + case GNUNET_CHAT_KIND_LEAVE: { application_call_message_event( - app, - (GNUNET_YES == GNUNET_CHAT_message_is_sent(message)? - event_update_chats : - event_joining_contact - ), - context, - message + app, + (GNUNET_YES == GNUNET_CHAT_message_is_sent(message)? + event_update_chats : + event_presence_contact + ), + context, + message ); break; } - case GNUNET_CHAT_KIND_LEAVE: - { - // TODO: add status message - break; - } case GNUNET_CHAT_KIND_CONTACT: { application_call_message_event( diff --git a/src/event.c b/src/event.c index c4f3a19..544bf43 100644 --- a/src/event.c +++ b/src/event.c @@ -51,7 +51,8 @@ _show_notification(MESSENGER_Application *app, UNUSED struct GNUNET_CHAT_Context *context, const struct GNUNET_CHAT_Contact *contact, const gchar *text, - const gchar *icon) + const gchar *icon, + const gchar *category) { if (app->settings.disable_notifications) return; @@ -67,10 +68,7 @@ _show_notification(MESSENGER_Application *app, app->notifications = g_list_append(app->notifications, notification); - if (0 == g_strcmp0(icon, "avatar-default-symbolic")) - notify_notification_set_category(notification, "presence.online"); - else - notify_notification_set_category(notification, "im.received"); + notify_notification_set_category(notification, category); g_signal_connect( notification, @@ -82,15 +80,25 @@ _show_notification(MESSENGER_Application *app, notify_notification_show(notification, NULL); } -static void -_clear_each_selectable_widget(GtkWidget *widget, - gpointer user_data) +void +event_handle_warning(MESSENGER_Application *app, + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *msg) { - GtkContainer *container = GTK_CONTAINER(user_data); - GtkListBoxRow *row = GTK_LIST_BOX_ROW(widget); + const gchar *text = GNUNET_CHAT_message_get_text(msg); - if (gtk_list_box_row_get_selectable(row)) - gtk_container_remove(container, widget); + const struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender( + msg + ); + + _show_notification( + app, + context, + contact, + text, + "dialog-warning-symbolic", + "im.error" + ); } void @@ -177,6 +185,48 @@ _iterate_profile_groups(void *cls, return GNUNET_YES; } +static void +_clear_chat_entry(GtkWidget *widget, + gpointer user_data) +{ + MESSENGER_Application *app = (MESSENGER_Application*) user_data; + + UI_MESSENGER_Handle *ui = &(app->ui.messenger); + GtkListBoxRow *row = GTK_LIST_BOX_ROW(widget); + + if (!gtk_list_box_row_get_selectable(row)) + return; + + UI_CHAT_ENTRY_Handle *entry = (UI_CHAT_ENTRY_Handle*) g_object_get_qdata( + G_OBJECT(row), + app->quarks.ui + ); + + ui->chat_entries = g_list_remove(ui->chat_entries, entry); + + gtk_container_remove( + GTK_CONTAINER(ui->chats_listbox), + widget + ); + + struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) ( + g_object_get_qdata( + G_OBJECT(entry->chat->send_text_view), + app->quarks.data + ) + ); + + if (context) + GNUNET_CHAT_context_set_user_pointer(context, NULL); + + gtk_container_remove( + GTK_CONTAINER(ui->chats_stack), + entry->chat->chat_box + ); + + ui_chat_entry_delete(entry); +} + void event_update_profile(MESSENGER_Application *app) { @@ -198,8 +248,8 @@ event_update_profile(MESSENGER_Application *app) gtk_container_foreach( GTK_CONTAINER(ui->chats_listbox), - _clear_each_selectable_widget, - ui->chats_listbox + _clear_chat_entry, + app ); gtk_stack_set_visible_child(ui->chats_stack, ui->no_chat_box); @@ -215,10 +265,17 @@ event_update_chats(MESSENGER_Application *app, { UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context); - if (!handle) - _add_new_chat_entry(app, context); - else - ui_chat_entry_update(handle, app, context); + const enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind( + msg + ); + + if (GNUNET_CHAT_KIND_JOIN == kind) + if (!handle) + _add_new_chat_entry(app, context); + else + ui_chat_entry_update(handle, app, context); + else if (handle) + _clear_chat_entry(gtk_widget_get_parent(handle->entry_box), app); contact_create_info(GNUNET_CHAT_message_get_sender(msg)); } @@ -243,9 +300,9 @@ _update_contact_context(MESSENGER_Application *app, } void -event_joining_contact(MESSENGER_Application *app, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *msg) +event_presence_contact(MESSENGER_Application *app, + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *msg) { UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context); @@ -259,6 +316,10 @@ event_joining_contact(MESSENGER_Application *app, if (!contact) return; + const enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind( + msg + ); + UI_MESSAGE_Handle *message = (UI_MESSAGE_Handle*) ( GNUNET_CHAT_member_get_user_pointer(context, contact) ); @@ -275,15 +336,18 @@ event_joining_contact(MESSENGER_Application *app, contact_add_name_avatar_to_info(contact, message->sender_avatar); contact_add_name_label_to_info(contact, message->sender_label); - const gchar *join_message = _("joined the chat"); + const gchar *presence_message = ( + GNUNET_CHAT_KIND_JOIN == kind? _("joined the chat") : _("left the chat") + ); if (!ui_messenger_is_context_active(&(app->ui.messenger), context)) _show_notification( app, context, contact, - join_message, - "avatar-default-symbolic" + presence_message, + "avatar-default-symbolic", + "presence.online" ); struct GNUNET_TIME_Absolute timestamp = GNUNET_CHAT_message_get_timestamp( @@ -292,7 +356,7 @@ event_joining_contact(MESSENGER_Application *app, const gchar *time = GNUNET_STRINGS_absolute_time_to_string(timestamp); - gtk_label_set_text(message->text_label, join_message); + gtk_label_set_text(message->text_label, presence_message); gtk_label_set_text(message->timestamp_label, time? time : ""); ui_chat_add_message(handle->chat, app, message); @@ -370,7 +434,8 @@ event_invitation(MESSENGER_Application *app, context, contact, invite_message, - "mail-message-new-symbolic" + "mail-message-new-symbolic", + "im.received" ); gtk_label_set_text(message->text_label, invite_message); @@ -441,7 +506,8 @@ event_receive_message(MESSENGER_Application *app, context, contact, text, - "mail-unread-symbolic" + "mail-unread-symbolic", + "im.received" ); gtk_label_set_text(message->text_label, text? text : ""); diff --git a/src/event.h b/src/event.h index 59dd348..505309c 100644 --- a/src/event.h +++ b/src/event.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021 GNUnet e.V. + Copyright (C) 2021--2022 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,6 +28,11 @@ #include "application.h" void +event_handle_warning(MESSENGER_Application *app, + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *msg); + +void event_refresh_accounts(MESSENGER_Application *app); void @@ -39,9 +44,9 @@ event_update_chats(MESSENGER_Application *app, const struct GNUNET_CHAT_Message *msg); void -event_joining_contact(MESSENGER_Application *app, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *msg); +event_presence_contact(MESSENGER_Application *app, + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *msg); void event_update_contacts(MESSENGER_Application *app, diff --git a/src/ui/accounts.c b/src/ui/accounts.c index 969c23d..84e932e 100644 --- a/src/ui/accounts.c +++ b/src/ui/accounts.c @@ -95,11 +95,11 @@ handle_dialog_destroy(UNUSED GtkWidget *window, { MESSENGER_Application *app = (MESSENGER_Application*) user_data; - ui_accounts_dialog_cleanup(&(app->ui.accounts)); + if ((app->ui.accounts.show_queued) || + (gtk_widget_is_visible(GTK_WIDGET(app->ui.messenger.main_window)))) + return; - if ((!(app->ui.accounts.show_queued)) && - (!gtk_widget_is_visible(GTK_WIDGET(app->ui.messenger.main_window)))) - gtk_widget_destroy(GTK_WIDGET(app->ui.messenger.main_window)); + gtk_widget_destroy(GTK_WIDGET(app->ui.messenger.main_window)); } static int @@ -219,5 +219,5 @@ ui_accounts_dialog_cleanup(UI_ACCOUNTS_Handle *handle) { g_object_unref(handle->builder); - handle->accounts_listbox = NULL; + memset(handle, 0, sizeof(*handle)); } diff --git a/src/ui/contacts.c b/src/ui/contacts.c index 68d18b4..5898fde 100644 --- a/src/ui/contacts.c +++ b/src/ui/contacts.c @@ -241,5 +241,5 @@ ui_contacts_dialog_cleanup(UI_CONTACTS_Handle *handle) { g_object_unref(handle->builder); - handle->contacts_listbox = NULL; + memset(handle, 0, sizeof(*handle)); } diff --git a/src/ui/delete_messages.c b/src/ui/delete_messages.c index 300c42e..1d6b812 100644 --- a/src/ui/delete_messages.c +++ b/src/ui/delete_messages.c @@ -149,4 +149,6 @@ void ui_delete_messages_dialog_cleanup(UI_DELETE_MESSAGES_Handle *handle) { g_object_unref(handle->builder); + + memset(handle, 0, sizeof(*handle)); } diff --git a/src/ui/invite_contact.c b/src/ui/invite_contact.c index 272550f..8d410bc 100644 --- a/src/ui/invite_contact.c +++ b/src/ui/invite_contact.c @@ -233,5 +233,5 @@ ui_invite_contact_dialog_cleanup(UI_INVITE_CONTACT_Handle *handle) { g_object_unref(handle->builder); - handle->contacts_listbox = NULL; + memset(handle, 0, sizeof(*handle)); } diff --git a/src/ui/messenger.c b/src/ui/messenger.c index 270360d..633920c 100644 --- a/src/ui/messenger.c +++ b/src/ui/messenger.c @@ -275,6 +275,7 @@ handle_main_window_destroy(UNUSED GtkWidget *window, MESSENGER_Application *app = (MESSENGER_Application*) user_data; ui_messenger_cleanup(&(app->ui.messenger)); + ui_accounts_dialog_cleanup(&(app->ui.accounts)); application_exit(app, MESSENGER_QUIT); } diff --git a/src/ui/new_account.c b/src/ui/new_account.c index 6642261..2778825 100644 --- a/src/ui/new_account.c +++ b/src/ui/new_account.c @@ -188,4 +188,6 @@ void ui_new_account_dialog_cleanup(UI_NEW_ACCOUNT_Handle *handle) { g_object_unref(handle->builder); + + memset(handle, 0, sizeof(*handle)); } diff --git a/src/ui/new_contact.c b/src/ui/new_contact.c index 6438331..7d5d395 100644 --- a/src/ui/new_contact.c +++ b/src/ui/new_contact.c @@ -393,8 +393,6 @@ ui_new_contact_dialog_cleanup(UI_NEW_CONTACT_Handle *handle) if (0 != handle->idle_processing) g_source_remove(handle->idle_processing); - handle->idle_processing = 0; - g_signal_handler_disconnect( handle->id_drawing_area, handle->id_draw_signal @@ -405,8 +403,8 @@ ui_new_contact_dialog_cleanup(UI_NEW_CONTACT_Handle *handle) if (handle->image) zbar_image_destroy(handle->image); - handle->image = NULL; - zbar_image_scanner_destroy(handle->scanner); zbar_video_destroy(handle->video); + + memset(handle, 0, sizeof(*handle)); } diff --git a/src/ui/new_group.c b/src/ui/new_group.c index d2b287e..6b60145 100644 --- a/src/ui/new_group.c +++ b/src/ui/new_group.c @@ -313,4 +313,6 @@ ui_new_group_dialog_cleanup(UI_NEW_GROUP_Handle *handle) if (handle->contact_entries) g_list_free(handle->contact_entries); + + memset(handle, 0, sizeof(*handle)); } diff --git a/src/ui/new_lobby.c b/src/ui/new_lobby.c index 0a9fe37..e75c371 100644 --- a/src/ui/new_lobby.c +++ b/src/ui/new_lobby.c @@ -198,7 +198,7 @@ handle_id_drawing_area_draw(GtkWidget* drawing_area, const guint w = handle->qr->width; const guint w2 = w + m * 2; - guchar pixels [w2 * w2 * 3]; + guchar *pixels = (guchar*) g_malloc(sizeof(guchar) * w2 * w2 * 3); guint x, y, z; for (y = 0; y < w2; y++) @@ -263,10 +263,11 @@ handle_id_drawing_area_draw(GtkWidget* drawing_area, g_object_unref(scaled); g_object_unref(image); + g_free(pixels); + return FALSE; } - void ui_new_lobby_dialog_init(MESSENGER_Application *app, UI_NEW_LOBBY_Handle *handle) @@ -386,7 +387,6 @@ ui_new_lobby_dialog_init(MESSENGER_Application *app, ); } - void ui_new_lobby_dialog_cleanup(UI_NEW_LOBBY_Handle *handle) { diff --git a/src/ui/new_platform.c b/src/ui/new_platform.c index 8611432..5eea8d5 100644 --- a/src/ui/new_platform.c +++ b/src/ui/new_platform.c @@ -173,4 +173,6 @@ void ui_new_platform_dialog_cleanup(UI_NEW_PLATFORM_Handle *handle) { g_object_unref(handle->builder); + + memset(handle, 0, sizeof(*handle)); } diff --git a/src/ui/send_file.c b/src/ui/send_file.c index 991e8ce..b2e6bb0 100644 --- a/src/ui/send_file.c +++ b/src/ui/send_file.c @@ -378,4 +378,6 @@ ui_send_file_dialog_cleanup(UI_SEND_FILE_Handle *handle) ); g_object_unref(handle->builder); + + memset(handle, 0, sizeof(*handle)); } diff --git a/src/ui/settings.c b/src/ui/settings.c index 6863968..7583941 100644 --- a/src/ui/settings.c +++ b/src/ui/settings.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021 GNUnet e.V. + Copyright (C) 2021--2022 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,4 +62,6 @@ void ui_settings_dialog_cleanup(UI_SETTINGS_Handle *handle) { g_object_unref(handle->builder); + + memset(handle, 0, sizeof(*handle)); } |