diff options
author | Jacki <jacki@thejackimonster.de> | 2024-02-14 13:44:06 +0100 |
---|---|---|
committer | Jacki <jacki@thejackimonster.de> | 2024-02-14 13:44:06 +0100 |
commit | 17392fe6169d39a75645728f44aa117f67b5331d (patch) | |
tree | cd9df10fc8a58c8104a494dcc6e1e44c09ccf8ca /src/ui/contacts.c | |
parent | 9ff0f0e2e8d554f465d7aad51ce7fb33e61a749c (diff) | |
download | messenger-gtk-17392fe6169d39a75645728f44aa117f67b5331d.tar.gz messenger-gtk-17392fe6169d39a75645728f44aa117f67b5331d.zip |
Add asserts to verify reliability
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat (limited to 'src/ui/contacts.c')
-rw-r--r-- | src/ui/contacts.c | 101 |
1 files changed, 59 insertions, 42 deletions
diff --git a/src/ui/contacts.c b/src/ui/contacts.c index 5898fde..75b1870 100644 --- a/src/ui/contacts.c +++ b/src/ui/contacts.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2021--2022 GNUnet e.V. | 3 | Copyright (C) 2021--2024 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -24,14 +24,15 @@ | |||
24 | 24 | ||
25 | #include "contacts.h" | 25 | #include "contacts.h" |
26 | 26 | ||
27 | #include "chat_entry.h" | ||
28 | #include "contact_entry.h" | 27 | #include "contact_entry.h" |
29 | #include "../application.h" | 28 | #include "../application.h" |
30 | 29 | ||
31 | static void | 30 | static void |
32 | handle_close_button_click(UNUSED GtkButton *button, | 31 | handle_close_button_click(UNUSED GtkButton *button, |
33 | gpointer user_data) | 32 | gpointer user_data) |
34 | { | 33 | { |
34 | g_assert(user_data); | ||
35 | |||
35 | GtkDialog *dialog = GTK_DIALOG(user_data); | 36 | GtkDialog *dialog = GTK_DIALOG(user_data); |
36 | gtk_window_close(GTK_WINDOW(dialog)); | 37 | gtk_window_close(GTK_WINDOW(dialog)); |
37 | } | 38 | } |
@@ -39,6 +40,8 @@ handle_close_button_click(UNUSED GtkButton *button, | |||
39 | static gboolean | 40 | static gboolean |
40 | _open_new_contact_dialog(gpointer user_data) | 41 | _open_new_contact_dialog(gpointer user_data) |
41 | { | 42 | { |
43 | g_assert(user_data); | ||
44 | |||
42 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; | 45 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; |
43 | 46 | ||
44 | ui_new_contact_dialog_init(app, &(app->ui.new_contact)); | 47 | ui_new_contact_dialog_init(app, &(app->ui.new_contact)); |
@@ -49,9 +52,11 @@ _open_new_contact_dialog(gpointer user_data) | |||
49 | 52 | ||
50 | static void | 53 | static void |
51 | handle_contacts_listbox_row_activated(UNUSED GtkListBox* listbox, | 54 | handle_contacts_listbox_row_activated(UNUSED GtkListBox* listbox, |
52 | GtkListBoxRow* row, | 55 | GtkListBoxRow* row, |
53 | gpointer user_data) | 56 | gpointer user_data) |
54 | { | 57 | { |
58 | g_assert((row) && (user_data)); | ||
59 | |||
55 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; | 60 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; |
56 | 61 | ||
57 | if (!gtk_list_box_row_get_selectable(row)) | 62 | if (!gtk_list_box_row_get_selectable(row)) |
@@ -84,11 +89,13 @@ close_dialog: | |||
84 | 89 | ||
85 | static gboolean | 90 | static gboolean |
86 | handle_contacts_listbox_filter_func(GtkListBoxRow *row, | 91 | handle_contacts_listbox_filter_func(GtkListBoxRow *row, |
87 | gpointer user_data) | 92 | gpointer user_data) |
88 | { | 93 | { |
94 | g_assert((row) && (user_data)); | ||
95 | |||
89 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; | 96 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; |
90 | 97 | ||
91 | if ((!row) || (!gtk_list_box_row_get_selectable(row))) | 98 | if (!gtk_list_box_row_get_selectable(row)) |
92 | return TRUE; | 99 | return TRUE; |
93 | 100 | ||
94 | const gchar *filter = gtk_entry_get_text( | 101 | const gchar *filter = gtk_entry_get_text( |
@@ -115,8 +122,10 @@ handle_contacts_listbox_filter_func(GtkListBoxRow *row, | |||
115 | 122 | ||
116 | static void | 123 | static void |
117 | handle_contact_search_entry_search_changed(UNUSED GtkSearchEntry* search_entry, | 124 | handle_contact_search_entry_search_changed(UNUSED GtkSearchEntry* search_entry, |
118 | gpointer user_data) | 125 | gpointer user_data) |
119 | { | 126 | { |
127 | g_assert(user_data); | ||
128 | |||
120 | GtkListBox *listbox = GTK_LIST_BOX(user_data); | 129 | GtkListBox *listbox = GTK_LIST_BOX(user_data); |
121 | 130 | ||
122 | gtk_list_box_invalidate_filter(listbox); | 131 | gtk_list_box_invalidate_filter(listbox); |
@@ -124,16 +133,20 @@ handle_contact_search_entry_search_changed(UNUSED GtkSearchEntry* search_entry, | |||
124 | 133 | ||
125 | static void | 134 | static void |
126 | handle_dialog_destroy(UNUSED GtkWidget *window, | 135 | handle_dialog_destroy(UNUSED GtkWidget *window, |
127 | gpointer user_data) | 136 | gpointer user_data) |
128 | { | 137 | { |
138 | g_assert(user_data); | ||
139 | |||
129 | ui_contacts_dialog_cleanup((UI_CONTACTS_Handle*) user_data); | 140 | ui_contacts_dialog_cleanup((UI_CONTACTS_Handle*) user_data); |
130 | } | 141 | } |
131 | 142 | ||
132 | static int | 143 | static int |
133 | _iterate_contacts(void *cls, | 144 | _iterate_contacts(void *cls, |
134 | UNUSED struct GNUNET_CHAT_Handle *handle, | 145 | UNUSED struct GNUNET_CHAT_Handle *handle, |
135 | struct GNUNET_CHAT_Contact *contact) | 146 | struct GNUNET_CHAT_Contact *contact) |
136 | { | 147 | { |
148 | g_assert((cls) && (contact)); | ||
149 | |||
137 | if (GNUNET_YES == GNUNET_CHAT_contact_is_owned(contact)) | 150 | if (GNUNET_YES == GNUNET_CHAT_contact_is_owned(contact)) |
138 | return GNUNET_YES; | 151 | return GNUNET_YES; |
139 | 152 | ||
@@ -165,72 +178,74 @@ _iterate_contacts(void *cls, | |||
165 | 178 | ||
166 | void | 179 | void |
167 | ui_contacts_dialog_init(MESSENGER_Application *app, | 180 | ui_contacts_dialog_init(MESSENGER_Application *app, |
168 | UI_CONTACTS_Handle *handle) | 181 | UI_CONTACTS_Handle *handle) |
169 | { | 182 | { |
183 | g_assert((app) && (handle)); | ||
184 | |||
170 | handle->builder = gtk_builder_new_from_resource( | 185 | handle->builder = gtk_builder_new_from_resource( |
171 | application_get_resource_path(app, "ui/contacts.ui") | 186 | application_get_resource_path(app, "ui/contacts.ui") |
172 | ); | 187 | ); |
173 | 188 | ||
174 | handle->dialog = GTK_DIALOG( | 189 | handle->dialog = GTK_DIALOG( |
175 | gtk_builder_get_object(handle->builder, "contacts_dialog") | 190 | gtk_builder_get_object(handle->builder, "contacts_dialog") |
176 | ); | 191 | ); |
177 | 192 | ||
178 | gtk_window_set_transient_for( | 193 | gtk_window_set_transient_for( |
179 | GTK_WINDOW(handle->dialog), | 194 | GTK_WINDOW(handle->dialog), |
180 | GTK_WINDOW(app->ui.messenger.main_window) | 195 | GTK_WINDOW(app->ui.messenger.main_window) |
181 | ); | 196 | ); |
182 | 197 | ||
183 | handle->contact_search_entry = GTK_SEARCH_ENTRY( | 198 | handle->contact_search_entry = GTK_SEARCH_ENTRY( |
184 | gtk_builder_get_object(handle->builder, "contact_search_entry") | 199 | gtk_builder_get_object(handle->builder, "contact_search_entry") |
185 | ); | 200 | ); |
186 | 201 | ||
187 | handle->contacts_listbox = GTK_LIST_BOX( | 202 | handle->contacts_listbox = GTK_LIST_BOX( |
188 | gtk_builder_get_object(handle->builder, "contacts_listbox") | 203 | gtk_builder_get_object(handle->builder, "contacts_listbox") |
189 | ); | 204 | ); |
190 | 205 | ||
191 | gtk_list_box_set_filter_func( | 206 | gtk_list_box_set_filter_func( |
192 | handle->contacts_listbox, | 207 | handle->contacts_listbox, |
193 | handle_contacts_listbox_filter_func, | 208 | handle_contacts_listbox_filter_func, |
194 | app, | 209 | app, |
195 | NULL | 210 | NULL |
196 | ); | 211 | ); |
197 | 212 | ||
198 | g_signal_connect( | 213 | g_signal_connect( |
199 | handle->contact_search_entry, | 214 | handle->contact_search_entry, |
200 | "search-changed", | 215 | "search-changed", |
201 | G_CALLBACK(handle_contact_search_entry_search_changed), | 216 | G_CALLBACK(handle_contact_search_entry_search_changed), |
202 | handle->contacts_listbox | 217 | handle->contacts_listbox |
203 | ); | 218 | ); |
204 | 219 | ||
205 | g_signal_connect( | 220 | g_signal_connect( |
206 | handle->contacts_listbox, | 221 | handle->contacts_listbox, |
207 | "row-activated", | 222 | "row-activated", |
208 | G_CALLBACK(handle_contacts_listbox_row_activated), | 223 | G_CALLBACK(handle_contacts_listbox_row_activated), |
209 | app | 224 | app |
210 | ); | 225 | ); |
211 | 226 | ||
212 | handle->close_button = GTK_BUTTON( | 227 | handle->close_button = GTK_BUTTON( |
213 | gtk_builder_get_object(handle->builder, "close_button") | 228 | gtk_builder_get_object(handle->builder, "close_button") |
214 | ); | 229 | ); |
215 | 230 | ||
216 | g_signal_connect( | 231 | g_signal_connect( |
217 | handle->close_button, | 232 | handle->close_button, |
218 | "clicked", | 233 | "clicked", |
219 | G_CALLBACK(handle_close_button_click), | 234 | G_CALLBACK(handle_close_button_click), |
220 | handle->dialog | 235 | handle->dialog |
221 | ); | 236 | ); |
222 | 237 | ||
223 | g_signal_connect( | 238 | g_signal_connect( |
224 | handle->dialog, | 239 | handle->dialog, |
225 | "destroy", | 240 | "destroy", |
226 | G_CALLBACK(handle_dialog_destroy), | 241 | G_CALLBACK(handle_dialog_destroy), |
227 | handle | 242 | handle |
228 | ); | 243 | ); |
229 | 244 | ||
230 | GNUNET_CHAT_iterate_contacts( | 245 | GNUNET_CHAT_iterate_contacts( |
231 | app->chat.messenger.handle, | 246 | app->chat.messenger.handle, |
232 | _iterate_contacts, | 247 | _iterate_contacts, |
233 | app | 248 | app |
234 | ); | 249 | ); |
235 | 250 | ||
236 | gtk_list_box_invalidate_filter(handle->contacts_listbox); | 251 | gtk_list_box_invalidate_filter(handle->contacts_listbox); |
@@ -239,6 +254,8 @@ ui_contacts_dialog_init(MESSENGER_Application *app, | |||
239 | void | 254 | void |
240 | ui_contacts_dialog_cleanup(UI_CONTACTS_Handle *handle) | 255 | ui_contacts_dialog_cleanup(UI_CONTACTS_Handle *handle) |
241 | { | 256 | { |
257 | g_assert(handle); | ||
258 | |||
242 | g_object_unref(handle->builder); | 259 | g_object_unref(handle->builder); |
243 | 260 | ||
244 | memset(handle, 0, sizeof(*handle)); | 261 | memset(handle, 0, sizeof(*handle)); |