messenger-gtk

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

commit 4065995bbc9f0c605b63e57574753e7c7ee9985c
parent 3090047dcd647bd1daddf904472a7f909b00f875
Author: TheJackiMonster <thejackimonster@gmail.com>
Date:   Thu, 10 Mar 2022 02:19:37 +0100

Replaced unstable bindings with glib quark data

Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>

Diffstat:
MMakefile | 1-
Msrc/application.c | 6+++---
Msrc/application.h | 7+++++--
Dsrc/bindings.c | 129-------------------------------------------------------------------------------
Dsrc/bindings.h | 60------------------------------------------------------------
Msrc/event.c | 17+++++++++++++----
Msrc/ui/accounts.c | 51++++++++++++++++++---------------------------------
Msrc/ui/accounts.h | 2--
Msrc/ui/chat.c | 73++++++++++++++++++++++++++++++++++++++++++++++++-------------------------
Msrc/ui/chat_entry.c | 4----
Msrc/ui/chat_entry.h | 5+----
Msrc/ui/contacts.c | 60+++++++++++++-----------------------------------------------
Msrc/ui/contacts.h | 3---
Msrc/ui/invite_contact.c | 64+++++++++++++++-------------------------------------------------
Msrc/ui/invite_contact.h | 3---
Msrc/ui/message.c | 16++++++++++------
Msrc/ui/messenger.c | 68++++++++++++++++++++++++++++++--------------------------------------
Msrc/ui/new_group.c | 4++--
Msrc/ui/send_file.c | 4++--
19 files changed, 160 insertions(+), 417 deletions(-)

diff --git a/Makefile b/Makefile @@ -8,7 +8,6 @@ INSTALL_DIR ?= /usr/local/ BINARY = messenger-gtk SOURCES = messenger_gtk.c\ application.c\ - bindings.c\ contact.c\ event.c\ file.c\ diff --git a/src/application.c b/src/application.c @@ -100,7 +100,9 @@ application_init(MESSENGER_Application *app, pthread_mutex_init(&(app->chat.mutex), NULL); - app->bindings = bindings_create(); + app->quarks.widget = g_quark_from_string("messenger_widget"); + app->quarks.data = g_quark_from_string("messenger_data"); + app->quarks.ui = g_quark_from_string("messenger_ui"); g_application_add_main_option( G_APPLICATION(app->application), @@ -195,8 +197,6 @@ application_run(MESSENGER_Application *app) pthread_join(app->chat.tid, NULL); - bindings_destroy(app->bindings); - close(app->chat.pipe[0]); close(app->chat.pipe[1]); diff --git a/src/application.h b/src/application.h @@ -42,7 +42,6 @@ #include "ui/send_file.h" #include "ui/settings.h" -#include "bindings.h" #include "util.h" typedef enum MESSENGER_ApplicationSignal @@ -60,7 +59,11 @@ typedef struct MESSENGER_Application GtkApplication *application; GList *notifications; - MESSENGER_Bindings *bindings; + struct { + GQuark widget; + GQuark data; + GQuark ui; + } quarks; struct { int status; diff --git a/src/bindings.c b/src/bindings.c @@ -1,129 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 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 - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - SPDX-License-Identifier: AGPL3.0-or-later - */ -/* - * @author Tobias Frisch - * @file bindings.h - */ - -#include "bindings.h" -#include "util.h" - -MESSENGER_Bindings* -bindings_create() -{ - MESSENGER_Bindings *bindings = GNUNET_new(MESSENGER_Bindings); - - bindings->map = GNUNET_CONTAINER_multishortmap_create(8, GNUNET_NO); - - return bindings; -} - -void -bindings_put(MESSENGER_Bindings *bindings, - gconstpointer key, - gpointer value) -{ - struct GNUNET_ShortHashCode hash; - memset(&hash, 0, sizeof(hash)); - memcpy(&hash, &key, sizeof(key)); - - GNUNET_CONTAINER_multishortmap_put( - bindings->map, - &hash, - (void*) value, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE - ); -} - -int -_bindings_append_list(void *cls, - UNUSED const struct GNUNET_ShortHashCode *key, - void *value) -{ - GList **list = (GList**) cls; - *list = g_list_append(*list, (gpointer) value); - return GNUNET_YES; -} - -void -bindings_remove(MESSENGER_Bindings *bindings, - const void *key, - void *value, - void (destroy)(void*)) -{ - struct GNUNET_ShortHashCode hash; - memset(&hash, 0, sizeof(hash)); - memcpy(&hash, &key, sizeof(key)); - - if (value) - { - GNUNET_CONTAINER_multishortmap_remove( - bindings->map, - &hash, - (void*) value - ); - - if (destroy) - destroy(value); - } - else - { - GList *values = NULL; - - GNUNET_CONTAINER_multishortmap_get_multiple( - bindings->map, - &hash, - _bindings_append_list, - &values - ); - - GNUNET_CONTAINER_multishortmap_remove_all( - bindings->map, - &hash - ); - - if (destroy) - g_list_free_full(values, destroy); - else - g_list_free(values); - } -} - -void* -bindings_get(const MESSENGER_Bindings *bindings, - const void *key) -{ - struct GNUNET_ShortHashCode hash; - memset(&hash, 0, sizeof(hash)); - memcpy(&hash, &key, sizeof(key)); - - return GNUNET_CONTAINER_multishortmap_get( - bindings->map, - &hash - ); -} - -void -bindings_destroy(MESSENGER_Bindings *bindings) -{ - GNUNET_CONTAINER_multishortmap_destroy(bindings->map); - - GNUNET_free(bindings); -} diff --git a/src/bindings.h b/src/bindings.h @@ -1,60 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 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 - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - SPDX-License-Identifier: AGPL3.0-or-later - */ -/* - * @author Tobias Frisch - * @file bindings.h - */ - -#ifndef BINDINGS_H_ -#define BINDINGS_H_ - -#include <gnunet/platform.h> -#include <gnunet/gnunet_common.h> -#include <gnunet/gnunet_container_lib.h> - -#include <glib.h> - -typedef struct MESSENGER_Bindings -{ - struct GNUNET_CONTAINER_MultiShortmap *map; -} MESSENGER_Bindings; - -MESSENGER_Bindings* -bindings_create(); - -void -bindings_put(MESSENGER_Bindings *bindings, - gconstpointer key, - gpointer value); - -void -bindings_remove(MESSENGER_Bindings *bindings, - gconstpointer key, - gpointer value, - GDestroyNotify destroy); - -void* -bindings_get(const MESSENGER_Bindings *bindings, - gconstpointer key); - -void -bindings_destroy(MESSENGER_Bindings *bindings); - -#endif /* BINDINGS_H_ */ diff --git a/src/event.c b/src/event.c @@ -117,7 +117,11 @@ _add_new_chat_entry(MESSENGER_Application *app, entry->chat->chat_box ); - bindings_put(app->bindings, entry->chat->send_text_view, context); + g_object_set_qdata( + G_OBJECT(entry->chat->send_text_view), + app->quarks.data, + context + ); ui->chat_entries = g_list_append(ui->chat_entries, entry); @@ -125,7 +129,11 @@ _add_new_chat_entry(MESSENGER_Application *app, gtk_widget_get_parent(entry->entry_box) ); - bindings_put(app->bindings, row, entry); + g_object_set_qdata( + G_OBJECT(row), + app->quarks.ui, + entry + ); gtk_list_box_select_row(ui->chats_listbox, row); gtk_list_box_invalidate_filter(ui->chats_listbox); @@ -252,7 +260,7 @@ event_joining_contact(MESSENGER_Application *app, return; UI_MESSAGE_Handle *message = (UI_MESSAGE_Handle*) ( - bindings_get(handle->joining, contact) + GNUNET_CHAT_member_get_user_pointer(context, contact) ); if (message) @@ -288,7 +296,8 @@ event_joining_contact(MESSENGER_Application *app, gtk_label_set_text(message->timestamp_label, time? time : ""); ui_chat_add_message(handle->chat, app, message); - bindings_put(handle->joining, contact, message); + + GNUNET_CHAT_member_set_user_pointer(context, contact, message); ui_chat_entry_update(handle, app, context); } diff --git a/src/ui/accounts.c b/src/ui/accounts.c @@ -72,7 +72,7 @@ handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox, } struct GNUNET_CHAT_Account *account = (struct GNUNET_CHAT_Account*) ( - bindings_get(app->bindings, row) + g_object_get_qdata(G_OBJECT(row), app->quarks.data) ); if (!account) @@ -119,8 +119,14 @@ _iterate_accounts(void *cls, gtk_widget_get_parent(entry->entry_box) ); - bindings_put(app->bindings, row, account); - bindings_put(app->ui.accounts.bindings, row, entry); + g_object_set_qdata(G_OBJECT(row), app->quarks.data, account); + + g_object_set_qdata_full( + G_OBJECT(row), + app->quarks.ui, + entry, + (GDestroyNotify) ui_account_entry_delete + ); return GNUNET_YES; } @@ -129,7 +135,6 @@ void ui_accounts_dialog_init(MESSENGER_Application *app, UI_ACCOUNTS_Handle *handle) { - handle->bindings = bindings_create(); handle->show_queued = 0; handle->builder = gtk_builder_new_from_resource( @@ -175,10 +180,13 @@ ui_accounts_dialog_init(MESSENGER_Application *app, ); } -static void -_clear_accounts_listbox_rows(UI_ACCOUNTS_Handle *handle, - gboolean bindings_only) +void +ui_accounts_dialog_refresh(MESSENGER_Application *app, + UI_ACCOUNTS_Handle *handle) { + if (!(handle->accounts_listbox)) + return; + GList *list = gtk_container_get_children( GTK_CONTAINER(handle->accounts_listbox) ); @@ -190,32 +198,14 @@ _clear_accounts_listbox_rows(UI_ACCOUNTS_Handle *handle, if ((!row) || (!gtk_list_box_row_get_selectable(row))) goto skip_row; - if (!bindings_only) - gtk_container_remove( - GTK_CONTAINER(handle->accounts_listbox), - GTK_WIDGET(row) - ); - - bindings_remove( - handle->bindings, - row, - NULL, - (GDestroyNotify) ui_account_entry_delete + gtk_container_remove( + GTK_CONTAINER(handle->accounts_listbox), + GTK_WIDGET(row) ); skip_row: list = list->next; } -} - -void -ui_accounts_dialog_refresh(MESSENGER_Application *app, - UI_ACCOUNTS_Handle *handle) -{ - if (!(handle->accounts_listbox)) - return; - - _clear_accounts_listbox_rows(handle, FALSE); GNUNET_CHAT_iterate_accounts( app->chat.messenger.handle, @@ -227,12 +217,7 @@ ui_accounts_dialog_refresh(MESSENGER_Application *app, void ui_accounts_dialog_cleanup(UI_ACCOUNTS_Handle *handle) { - _clear_accounts_listbox_rows(handle, TRUE); - g_object_unref(handle->builder); - bindings_destroy(handle->bindings); - handle->bindings = NULL; - handle->accounts_listbox = NULL; } diff --git a/src/ui/accounts.h b/src/ui/accounts.h @@ -26,11 +26,9 @@ #define UI_ACCOUNTS_H_ #include "messenger.h" -#include "../bindings.h" typedef struct UI_ACCOUNTS_Handle { - MESSENGER_Bindings *bindings; guint show_queued; GtkBuilder *builder; diff --git a/src/ui/chat.c b/src/ui/chat.c @@ -76,7 +76,7 @@ handle_chat_contacts_listbox_row_activated(GtkListBox *listbox, MESSENGER_Application *app = (MESSENGER_Application*) user_data; GtkTextView *text_view = GTK_TEXT_VIEW( - bindings_get(app->bindings, listbox) + g_object_get_qdata(G_OBJECT(listbox), app->quarks.widget) ); if (!text_view) @@ -86,14 +86,18 @@ handle_chat_contacts_listbox_row_activated(GtkListBox *listbox, { ui_invite_contact_dialog_init(app, &(app->ui.invite_contact)); - bindings_put(app->bindings, app->ui.invite_contact.contacts_listbox, text_view); + g_object_set_qdata( + G_OBJECT(app->ui.invite_contact.contacts_listbox), + app->quarks.widget, + text_view + ); gtk_widget_show(GTK_WIDGET(app->ui.invite_contact.dialog)); return; } struct GNUNET_CHAT_Contact *contact = (struct GNUNET_CHAT_Contact*) ( - bindings_get(app->bindings, row) + g_object_get_qdata(G_OBJECT(row), app->quarks.data) ); if ((!contact) || (!GNUNET_CHAT_contact_get_key(contact)) || @@ -155,11 +159,11 @@ handle_chat_messages_sort(GtkListBoxRow* row0, MESSENGER_Application *app = (MESSENGER_Application*) user_data; UI_MESSAGE_Handle *message0 = (UI_MESSAGE_Handle*) ( - bindings_get(app->bindings, row0) + g_object_get_qdata(G_OBJECT(row0), app->quarks.ui) ); UI_MESSAGE_Handle *message1 = (UI_MESSAGE_Handle*) ( - bindings_get(app->bindings, row1) + g_object_get_qdata(G_OBJECT(row1), app->quarks.ui) ); if ((!message0) || (!message1)) @@ -225,7 +229,10 @@ _delete_messages_callback(MESSENGER_Application *app, if (!row) goto skip_row; - message = bindings_get(app->bindings, row); + message = (UI_MESSAGE_Handle*) g_object_get_qdata( + G_OBJECT(row), + app->quarks.ui + ); if ((!message) || (!(message->msg))) goto skip_row; @@ -276,7 +283,7 @@ handle_attach_file_button_click(GtkButton *button, MESSENGER_Application *app = (MESSENGER_Application*) user_data; GtkTextView *text_view = GTK_TEXT_VIEW( - bindings_get(app->bindings, button) + g_object_get_qdata(G_OBJECT(button), app->quarks.widget) ); if (!text_view) @@ -308,7 +315,11 @@ handle_attach_file_button_click(GtkButton *button, g_free(filename); - bindings_put(app->bindings, app->ui.send_file.send_button, text_view); + g_object_set_qdata( + G_OBJECT(app->ui.send_file.send_button), + app->quarks.widget, + text_view + ); gtk_widget_show(GTK_WIDGET(app->ui.send_file.dialog)); @@ -353,7 +364,7 @@ _send_text_from_view(MESSENGER_Application *app, return FALSE; struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) ( - bindings_get(app->bindings, text_view) + g_object_get_qdata(G_OBJECT(text_view), app->quarks.data) ); if (context) @@ -370,7 +381,7 @@ handle_send_record_button_click(GtkButton *button, MESSENGER_Application *app = (MESSENGER_Application*) user_data; GtkTextView *text_view = GTK_TEXT_VIEW( - bindings_get(app->bindings, button) + g_object_get_qdata(G_OBJECT(button), app->quarks.widget) ); if (!_send_text_from_view(app, text_view)) @@ -646,9 +657,23 @@ ui_chat_new(MESSENGER_Application *app) app ); - bindings_put(app->bindings, handle->chat_contacts_listbox, handle->send_text_view); - bindings_put(app->bindings, handle->attach_file_button, handle->send_text_view); - bindings_put(app->bindings, handle->send_record_button, handle->send_text_view); + g_object_set_qdata( + G_OBJECT(handle->chat_contacts_listbox), + app->quarks.widget, + handle->send_text_view + ); + + g_object_set_qdata( + G_OBJECT(handle->attach_file_button), + app->quarks.widget, + handle->send_text_view + ); + + g_object_set_qdata( + G_OBJECT(handle->send_record_button), + app->quarks.widget, + handle->send_text_view + ); handle->picker_revealer = GTK_REVEALER( gtk_builder_get_object(handle->builder, "picker_revealer") @@ -696,9 +721,14 @@ iterate_ui_chat_update_group_contacts(void *cls, gtk_widget_get_parent(entry->entry_box) ); - bindings_put(closure->app->bindings, row, contact); + g_object_set_qdata(G_OBJECT(row), closure->app->quarks.data, contact); + g_object_set_qdata_full( + G_OBJECT(row), + closure->app->quarks.ui, + entry, + (GDestroyNotify) ui_account_entry_delete + ); - ui_account_entry_delete(entry); return GNUNET_YES; } @@ -750,8 +780,6 @@ ui_chat_update(UI_CHAT_Handle *handle, GtkWidget *widget = GTK_WIDGET(children->data); children = children->next; - bindings_remove(app->bindings, widget, NULL, NULL); - gtk_container_remove( GTK_CONTAINER(handle->chat_contacts_listbox), widget @@ -840,7 +868,7 @@ ui_chat_add_message(UI_CHAT_Handle *handle, GtkWidget *row = gtk_widget_get_parent(message->message_box); - bindings_put(app->bindings, row, message); + g_object_set_qdata(G_OBJECT(row), app->quarks.ui, message); handle->messages = g_list_prepend(handle->messages, message); @@ -849,7 +877,7 @@ ui_chat_add_message(UI_CHAT_Handle *handle, void ui_chat_remove_message(UI_CHAT_Handle *handle, - MESSENGER_Application *app, + UNUSED MESSENGER_Application *app, UI_MESSAGE_Handle *message) { GNUNET_assert((handle) && (message)); @@ -858,12 +886,7 @@ ui_chat_remove_message(UI_CHAT_Handle *handle, GtkWidget *row = gtk_widget_get_parent(message->message_box); - bindings_remove(app->bindings, row, NULL, NULL); - - gtk_container_remove( - GTK_CONTAINER(handle->messages_listbox), - gtk_widget_get_parent(GTK_WIDGET(message->message_box)) - ); + gtk_container_remove(GTK_CONTAINER(handle->messages_listbox), row); handle->messages = g_list_append(handle->messages, message); } diff --git a/src/ui/chat_entry.c b/src/ui/chat_entry.c @@ -34,8 +34,6 @@ ui_chat_entry_new(MESSENGER_Application *app) { UI_CHAT_ENTRY_Handle* handle = g_malloc(sizeof(UI_CHAT_ENTRY_Handle)); - handle->joining = bindings_create(); - handle->chat = ui_chat_new(app); handle->builder = gtk_builder_new_from_resource( application_get_resource_path(app, "ui/chat_entry.ui") @@ -155,7 +153,5 @@ ui_chat_entry_delete(UI_CHAT_ENTRY_Handle *handle) g_object_unref(handle->builder); - bindings_destroy(handle->joining); - g_free(handle); } 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 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 @@ -26,12 +26,9 @@ #define UI_CHAT_ENTRY_H_ #include "chat.h" -#include "../bindings.h" typedef struct UI_CHAT_ENTRY_Handle { - MESSENGER_Bindings *joining; - UI_CHAT_Handle *chat; GtkBuilder *builder; diff --git a/src/ui/contacts.c b/src/ui/contacts.c @@ -61,7 +61,7 @@ handle_contacts_listbox_row_activated(UNUSED GtkListBox* listbox, } struct GNUNET_CHAT_Contact *contact = (struct GNUNET_CHAT_Contact*) ( - bindings_get(app->bindings, row) + g_object_get_qdata(G_OBJECT(row), app->quarks.data) ); if ((!contact) || (!GNUNET_CHAT_contact_get_key(contact)) || @@ -86,20 +86,20 @@ static gboolean handle_contacts_listbox_filter_func(GtkListBoxRow *row, gpointer user_data) { - UI_CONTACTS_Handle *handle = (UI_CONTACTS_Handle*) user_data; + MESSENGER_Application *app = (MESSENGER_Application*) user_data; if ((!row) || (!gtk_list_box_row_get_selectable(row))) return TRUE; const gchar *filter = gtk_entry_get_text( - GTK_ENTRY(handle->contact_search_entry) + GTK_ENTRY(app->ui.contacts.contact_search_entry) ); if (!filter) return TRUE; UI_CONTACT_ENTRY_Handle *entry = (UI_CONTACT_ENTRY_Handle*) ( - bindings_get(handle->bindings, row) + g_object_get_qdata(G_OBJECT(row), app->quarks.ui) ); if (!entry) @@ -151,8 +151,14 @@ _iterate_contacts(void *cls, gtk_widget_get_parent(entry->entry_box) ); - bindings_put(app->bindings, row, contact); - bindings_put(app->ui.contacts.bindings, row, entry); + 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 + ); return GNUNET_YES; } @@ -161,8 +167,6 @@ void ui_contacts_dialog_init(MESSENGER_Application *app, UI_CONTACTS_Handle *handle) { - handle->bindings = bindings_create(); - handle->builder = gtk_builder_new_from_resource( application_get_resource_path(app, "ui/contacts.ui") ); @@ -187,7 +191,7 @@ ui_contacts_dialog_init(MESSENGER_Application *app, gtk_list_box_set_filter_func( handle->contacts_listbox, handle_contacts_listbox_filter_func, - handle, + app, NULL ); @@ -232,48 +236,10 @@ ui_contacts_dialog_init(MESSENGER_Application *app, gtk_list_box_invalidate_filter(handle->contacts_listbox); } -static void -_clear_contacts_listbox_rows(UI_CONTACTS_Handle *handle, - gboolean bindings_only) -{ - GList *list = gtk_container_get_children( - GTK_CONTAINER(handle->contacts_listbox) - ); - - while (list) - { - GtkListBoxRow *row = GTK_LIST_BOX_ROW(list->data); - - if ((!row) || (!gtk_list_box_row_get_selectable(row))) - goto skip_row; - - if (!bindings_only) - gtk_container_remove( - GTK_CONTAINER(handle->contacts_listbox), - GTK_WIDGET(row) - ); - - bindings_remove( - handle->bindings, - row, - NULL, - (GDestroyNotify) ui_contact_entry_delete - ); - - skip_row: - list = list->next; - } -} - void ui_contacts_dialog_cleanup(UI_CONTACTS_Handle *handle) { - _clear_contacts_listbox_rows(handle, TRUE); - g_object_unref(handle->builder); - bindings_destroy(handle->bindings); - handle->bindings = NULL; - handle->contacts_listbox = NULL; } diff --git a/src/ui/contacts.h b/src/ui/contacts.h @@ -26,12 +26,9 @@ #define UI_CONTACTS_H_ #include "messenger.h" -#include "../bindings.h" typedef struct UI_CONTACTS_Handle { - MESSENGER_Bindings *bindings; - GtkBuilder *builder; GtkDialog *dialog; diff --git a/src/ui/invite_contact.c b/src/ui/invite_contact.c @@ -44,11 +44,11 @@ handle_contacts_listbox_row_activated(GtkListBox* listbox, MESSENGER_Application *app = (MESSENGER_Application*) user_data; GtkTextView *text_view = GTK_TEXT_VIEW( - bindings_get(app->bindings, listbox) + g_object_get_qdata(G_OBJECT(listbox), app->quarks.widget) ); struct GNUNET_CHAT_Contact *contact = (struct GNUNET_CHAT_Contact*) ( - bindings_get(app->bindings, row) + g_object_get_qdata(G_OBJECT(row), app->quarks.data) ); if ((!contact) || (!GNUNET_CHAT_contact_get_key(contact)) || @@ -57,7 +57,7 @@ handle_contacts_listbox_row_activated(GtkListBox* listbox, goto close_dialog; struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) ( - bindings_get(app->bindings, text_view) + g_object_get_qdata(G_OBJECT(text_view), app->quarks.data) ); if (!context) @@ -78,20 +78,20 @@ static gboolean handle_contacts_listbox_filter_func(GtkListBoxRow *row, gpointer user_data) { - UI_INVITE_CONTACT_Handle *handle = (UI_INVITE_CONTACT_Handle*) user_data; + MESSENGER_Application *app = (MESSENGER_Application*) user_data; if ((!row) || (!gtk_list_box_row_get_selectable(row))) return TRUE; const gchar *filter = gtk_entry_get_text( - GTK_ENTRY(handle->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*) ( - bindings_get(handle->bindings, row) + g_object_get_qdata(G_OBJECT(row), app->quarks.ui) ); if (!entry) @@ -143,8 +143,14 @@ _iterate_contacts(void *cls, gtk_widget_get_parent(entry->entry_box) ); - bindings_put(app->bindings, row, contact); - bindings_put(app->ui.invite_contact.bindings, row, entry); + 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 + ); return GNUNET_YES; } @@ -153,8 +159,6 @@ void ui_invite_contact_dialog_init(MESSENGER_Application *app, UI_INVITE_CONTACT_Handle *handle) { - handle->bindings = bindings_create(); - handle->builder = gtk_builder_new_from_resource( application_get_resource_path(app, "ui/invite_contact.ui") ); @@ -179,7 +183,7 @@ ui_invite_contact_dialog_init(MESSENGER_Application *app, gtk_list_box_set_filter_func( handle->contacts_listbox, handle_contacts_listbox_filter_func, - handle, + app, NULL ); @@ -224,48 +228,10 @@ ui_invite_contact_dialog_init(MESSENGER_Application *app, gtk_list_box_invalidate_filter(handle->contacts_listbox); } -static void -_clear_contacts_listbox_rows(UI_INVITE_CONTACT_Handle *handle, - gboolean bindings_only) -{ - GList *list = gtk_container_get_children( - GTK_CONTAINER(handle->contacts_listbox) - ); - - while (list) - { - GtkListBoxRow *row = GTK_LIST_BOX_ROW(list->data); - - if ((!row) || (!gtk_list_box_row_get_selectable(row))) - goto skip_row; - - if (!bindings_only) - gtk_container_remove( - GTK_CONTAINER(handle->contacts_listbox), - GTK_WIDGET(row) - ); - - bindings_remove( - handle->bindings, - row, - NULL, - (GDestroyNotify) ui_contact_entry_delete - ); - - skip_row: - list = list->next; - } -} - void ui_invite_contact_dialog_cleanup(UI_INVITE_CONTACT_Handle *handle) { - _clear_contacts_listbox_rows(handle, TRUE); - g_object_unref(handle->builder); - bindings_destroy(handle->bindings); - handle->bindings = NULL; - handle->contacts_listbox = NULL; } diff --git a/src/ui/invite_contact.h b/src/ui/invite_contact.h @@ -26,12 +26,9 @@ #define UI_INVITE_CONTACT_H_ #include "messenger.h" -#include "../bindings.h" typedef struct UI_INVITE_CONTACT_Handle { - MESSENGER_Bindings *bindings; - GtkBuilder *builder; GtkDialog *dialog; diff --git a/src/ui/message.c b/src/ui/message.c @@ -50,14 +50,14 @@ handle_file_button_click(GtkButton *button, MESSENGER_Application *app = (MESSENGER_Application*) user_data; UI_MESSAGE_Handle* handle = (UI_MESSAGE_Handle*) ( - bindings_get(app->bindings, button) + g_object_get_qdata(G_OBJECT(button), app->quarks.ui) ); if (!handle) return; struct GNUNET_CHAT_File *file = (struct GNUNET_CHAT_File*) ( - bindings_get(app->bindings, handle->file_progress_bar) + g_object_get_qdata(G_OBJECT(handle->file_progress_bar), app->quarks.data) ); if (!file) @@ -360,7 +360,7 @@ ui_message_new(MESSENGER_Application *app, gtk_builder_get_object(handle->builder[1], "file_status_image") ); - bindings_put(app->bindings, handle->file_button, handle); + g_object_set_qdata(G_OBJECT(handle->file_button), app->quarks.ui, handle); handle->preview_drawing_area = GTK_DRAWING_AREA( gtk_builder_get_object(handle->builder[1], "preview_drawing_area") @@ -444,13 +444,13 @@ ui_message_update(UI_MESSAGE_Handle *handle, } else file = (struct GNUNET_CHAT_File*) ( - bindings_get(app->bindings, handle->message_box) + g_object_get_qdata(G_OBJECT(handle->message_box), app->quarks.data) ); if (!file) return; - bindings_put(app->bindings, handle->message_box, file); + g_object_set_qdata(G_OBJECT(handle->message_box), app->quarks.data, file); uint64_t size = GNUNET_CHAT_file_get_size(file); uint64_t local_size = GNUNET_CHAT_file_get_local_size(file); @@ -519,7 +519,11 @@ file_content: gtk_revealer_set_reveal_child(handle->file_revealer, TRUE); - bindings_put(app->bindings, handle->file_progress_bar, file); + g_object_set_qdata( + G_OBJECT(handle->file_progress_bar), + app->quarks.data, + file + ); } void diff --git a/src/ui/messenger.c b/src/ui/messenger.c @@ -106,7 +106,7 @@ handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox, } struct GNUNET_CHAT_Account *account = (struct GNUNET_CHAT_Account*) ( - bindings_get(app->bindings, row) + g_object_get_qdata(G_OBJECT(row), app->quarks.data) ); if (!account) @@ -188,20 +188,20 @@ handle_chats_listbox_row_activated(UNUSED GtkListBox* listbox, GtkListBoxRow* row, gpointer user_data) { - UI_MESSENGER_Handle *handle = (UI_MESSENGER_Handle*) user_data; + MESSENGER_Application *app = (MESSENGER_Application*) user_data; if (!gtk_list_box_row_get_selectable(row)) return; UI_CHAT_ENTRY_Handle *entry = (UI_CHAT_ENTRY_Handle*) ( - bindings_get(handle->app->bindings, row) + g_object_get_qdata(G_OBJECT(row), app->quarks.ui) ); if ((!entry) || (!(entry->chat)) || (!(entry->chat->chat_box))) return; - GtkStack *stack = handle->chats_stack; - HdyLeaflet *leaflet = handle->leaflet_chat; + GtkStack *stack = app->ui.messenger.chats_stack; + HdyLeaflet *leaflet = app->ui.messenger.leaflet_chat; GList *children = gtk_container_get_children(GTK_CONTAINER(leaflet)); @@ -216,21 +216,21 @@ static gboolean handle_chats_listbox_filter_func(GtkListBoxRow *row, gpointer user_data) { - UI_MESSENGER_Handle *handle = (UI_MESSENGER_Handle*) user_data; + MESSENGER_Application *app = (MESSENGER_Application*) user_data; if ((!row) || (!gtk_list_box_row_get_selectable(row)) || (gtk_list_box_row_is_selected(row))) return TRUE; const gchar *filter = gtk_entry_get_text( - GTK_ENTRY(handle->chats_search) + GTK_ENTRY(app->ui.messenger.chats_search) ); if (!filter) return TRUE; UI_CHAT_ENTRY_Handle *entry = (UI_CHAT_ENTRY_Handle*) ( - bindings_get(handle->app->bindings, row) + g_object_get_qdata(G_OBJECT(row), app->quarks.ui) ); if ((!entry) || (!(entry->title_label))) @@ -457,7 +457,7 @@ ui_messenger_init(MESSENGER_Application *app, gtk_list_box_set_filter_func( handle->chats_listbox, handle_chats_listbox_filter_func, - handle, + app, NULL ); @@ -472,7 +472,7 @@ ui_messenger_init(MESSENGER_Application *app, handle->chats_listbox, "row-activated", G_CALLBACK(handle_chats_listbox_row_activated), - handle + app ); handle->chats_stack = GTK_STACK( @@ -491,32 +491,6 @@ ui_messenger_init(MESSENGER_Application *app, ); } -static void -_messenger_clear_accounts_listbox_rows(UI_MESSENGER_Handle *handle) -{ - GList *list = gtk_container_get_children( - GTK_CONTAINER(handle->accounts_listbox) - ); - - while (list) - { - GtkListBoxRow *row = GTK_LIST_BOX_ROW(list->data); - - if ((!row) || (!gtk_list_box_row_get_selectable(row))) - goto skip_row; - - bindings_remove(handle->app->bindings, row, NULL, NULL); - - gtk_container_remove( - GTK_CONTAINER(handle->accounts_listbox), - GTK_WIDGET(row) - ); - - skip_row: - list = list->next; - } -} - static int _messenger_iterate_accounts(void *cls, const struct GNUNET_CHAT_Handle *handle, @@ -538,7 +512,7 @@ _messenger_iterate_accounts(void *cls, gtk_widget_get_parent(entry->entry_box) ); - bindings_put(app->bindings, row, account); + g_object_set_qdata(G_OBJECT(row), app->quarks.data, account); if ((account == GNUNET_CHAT_get_connected(handle)) || ((app->chat.identity) && (0 == g_strcmp0(app->chat.identity, name)))) @@ -555,7 +529,25 @@ ui_messenger_refresh(MESSENGER_Application *app, if (!(handle->accounts_listbox)) return; - _messenger_clear_accounts_listbox_rows(handle); + GList *list = gtk_container_get_children( + GTK_CONTAINER(handle->accounts_listbox) + ); + + while (list) + { + GtkListBoxRow *row = GTK_LIST_BOX_ROW(list->data); + + if ((!row) || (!gtk_list_box_row_get_selectable(row))) + goto skip_row; + + gtk_container_remove( + GTK_CONTAINER(handle->accounts_listbox), + GTK_WIDGET(row) + ); + + skip_row: + list = list->next; + } GNUNET_CHAT_iterate_accounts( app->chat.messenger.handle, diff --git a/src/ui/new_group.c b/src/ui/new_group.c @@ -51,7 +51,7 @@ _open_new_group(GtkEntry *entry, GtkListBoxRow *row = GTK_LIST_BOX_ROW(selected->data); struct GNUNET_CHAT_Contact *contact = (struct GNUNET_CHAT_Contact*) ( - bindings_get(app->bindings, row) + g_object_get_qdata(G_OBJECT(row), app->quarks.data) ); GNUNET_CHAT_group_invite_contact(group, contact); @@ -170,7 +170,7 @@ _iterate_contacts(void *cls, gtk_widget_get_parent(entry->entry_box) ); - bindings_put(app->bindings, row, contact); + 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, diff --git a/src/ui/send_file.c b/src/ui/send_file.c @@ -65,7 +65,7 @@ handle_send_button_click(GtkButton *button, MESSENGER_Application *app = (MESSENGER_Application*) user_data; GtkTextView *text_view = GTK_TEXT_VIEW( - bindings_get(app->bindings, button) + g_object_get_qdata(G_OBJECT(button), app->quarks.widget) ); if (!text_view) @@ -79,7 +79,7 @@ handle_send_button_click(GtkButton *button, return; struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) ( - bindings_get(app->bindings, text_view) + g_object_get_qdata(G_OBJECT(text_view), app->quarks.data) ); UI_CHAT_ENTRY_Handle *entry = GNUNET_CHAT_context_get_user_pointer(context);