aboutsummaryrefslogtreecommitdiff
path: root/src/ui/invite_contact.c
diff options
context:
space:
mode:
authorJacki <jacki@thejackimonster.de>2024-02-14 13:44:06 +0100
committerJacki <jacki@thejackimonster.de>2024-02-14 13:44:06 +0100
commit17392fe6169d39a75645728f44aa117f67b5331d (patch)
treecd9df10fc8a58c8104a494dcc6e1e44c09ccf8ca /src/ui/invite_contact.c
parent9ff0f0e2e8d554f465d7aad51ce7fb33e61a749c (diff)
downloadmessenger-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/invite_contact.c')
-rw-r--r--src/ui/invite_contact.c125
1 files changed, 70 insertions, 55 deletions
diff --git a/src/ui/invite_contact.c b/src/ui/invite_contact.c
index 8d410bc..7ebf03e 100644
--- a/src/ui/invite_contact.c
+++ b/src/ui/invite_contact.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,31 +24,34 @@
24 24
25#include "invite_contact.h" 25#include "invite_contact.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
31static void 30static void
32handle_close_button_click(UNUSED GtkButton *button, 31handle_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}
38 39
39static void 40static void
40handle_contacts_listbox_row_activated(GtkListBox* listbox, 41handle_contacts_listbox_row_activated(GtkListBox* listbox,
41 GtkListBoxRow* row, 42 GtkListBoxRow* row,
42 gpointer user_data) 43 gpointer user_data)
43{ 44{
45 g_assert((listbox) && (row) && (user_data));
46
44 MESSENGER_Application *app = (MESSENGER_Application*) user_data; 47 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
45 48
46 GtkTextView *text_view = GTK_TEXT_VIEW( 49 GtkTextView *text_view = GTK_TEXT_VIEW(
47 g_object_get_qdata(G_OBJECT(listbox), app->quarks.widget) 50 g_object_get_qdata(G_OBJECT(listbox), app->quarks.widget)
48 ); 51 );
49 52
50 struct GNUNET_CHAT_Contact *contact = (struct GNUNET_CHAT_Contact*) ( 53 struct GNUNET_CHAT_Contact *contact = (struct GNUNET_CHAT_Contact*) (
51 g_object_get_qdata(G_OBJECT(row), app->quarks.data) 54 g_object_get_qdata(G_OBJECT(row), app->quarks.data)
52 ); 55 );
53 56
54 if ((!contact) || (!GNUNET_CHAT_contact_get_key(contact)) || 57 if ((!contact) || (!GNUNET_CHAT_contact_get_key(contact)) ||
@@ -57,14 +60,14 @@ handle_contacts_listbox_row_activated(GtkListBox* listbox,
57 goto close_dialog; 60 goto close_dialog;
58 61
59 struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) ( 62 struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) (
60 g_object_get_qdata(G_OBJECT(text_view), app->quarks.data) 63 g_object_get_qdata(G_OBJECT(text_view), app->quarks.data)
61 ); 64 );
62 65
63 if (!context) 66 if (!context)
64 goto close_dialog; 67 goto close_dialog;
65 68
66 const struct GNUNET_CHAT_Group *group = GNUNET_CHAT_context_get_group( 69 const struct GNUNET_CHAT_Group *group = GNUNET_CHAT_context_get_group(
67 context 70 context
68 ); 71 );
69 72
70 if (group) 73 if (group)
@@ -76,22 +79,24 @@ close_dialog:
76 79
77static gboolean 80static gboolean
78handle_contacts_listbox_filter_func(GtkListBoxRow *row, 81handle_contacts_listbox_filter_func(GtkListBoxRow *row,
79 gpointer user_data) 82 gpointer user_data)
80{ 83{
84 g_assert((row) && (user_data));
85
81 MESSENGER_Application *app = (MESSENGER_Application*) user_data; 86 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
82 87
83 if ((!row) || (!gtk_list_box_row_get_selectable(row))) 88 if (!gtk_list_box_row_get_selectable(row))
84 return TRUE; 89 return TRUE;
85 90
86 const gchar *filter = gtk_entry_get_text( 91 const gchar *filter = gtk_entry_get_text(
87 GTK_ENTRY(app->ui.invite_contact.contact_search_entry) 92 GTK_ENTRY(app->ui.invite_contact.contact_search_entry)
88 ); 93 );
89 94
90 if (!filter) 95 if (!filter)
91 return TRUE; 96 return TRUE;
92 97
93 UI_CONTACT_ENTRY_Handle *entry = (UI_CONTACT_ENTRY_Handle*) ( 98 UI_CONTACT_ENTRY_Handle *entry = (UI_CONTACT_ENTRY_Handle*) (
94 g_object_get_qdata(G_OBJECT(row), app->quarks.ui) 99 g_object_get_qdata(G_OBJECT(row), app->quarks.ui)
95 ); 100 );
96 101
97 if (!entry) 102 if (!entry)
@@ -107,8 +112,10 @@ handle_contacts_listbox_filter_func(GtkListBoxRow *row,
107 112
108static void 113static void
109handle_contact_search_entry_search_changed(UNUSED GtkSearchEntry* search_entry, 114handle_contact_search_entry_search_changed(UNUSED GtkSearchEntry* search_entry,
110 gpointer user_data) 115 gpointer user_data)
111{ 116{
117 g_assert(user_data);
118
112 GtkListBox *listbox = GTK_LIST_BOX(user_data); 119 GtkListBox *listbox = GTK_LIST_BOX(user_data);
113 120
114 gtk_list_box_invalidate_filter(listbox); 121 gtk_list_box_invalidate_filter(listbox);
@@ -116,16 +123,20 @@ handle_contact_search_entry_search_changed(UNUSED GtkSearchEntry* search_entry,
116 123
117static void 124static void
118handle_dialog_destroy(UNUSED GtkWidget *window, 125handle_dialog_destroy(UNUSED GtkWidget *window,
119 gpointer user_data) 126 gpointer user_data)
120{ 127{
128 g_assert(user_data);
129
121 ui_contacts_dialog_cleanup((UI_CONTACTS_Handle*) user_data); 130 ui_contacts_dialog_cleanup((UI_CONTACTS_Handle*) user_data);
122} 131}
123 132
124static int 133static int
125_iterate_contacts(void *cls, 134_iterate_contacts(void *cls,
126 UNUSED struct GNUNET_CHAT_Handle *handle, 135 UNUSED struct GNUNET_CHAT_Handle *handle,
127 struct GNUNET_CHAT_Contact *contact) 136 struct GNUNET_CHAT_Contact *contact)
128{ 137{
138 g_assert((cls) && (contact));
139
129 if (GNUNET_YES == GNUNET_CHAT_contact_is_owned(contact)) 140 if (GNUNET_YES == GNUNET_CHAT_contact_is_owned(contact))
130 return GNUNET_YES; 141 return GNUNET_YES;
131 142
@@ -135,21 +146,21 @@ _iterate_contacts(void *cls,
135 ui_contact_entry_set_contact(entry, contact); 146 ui_contact_entry_set_contact(entry, contact);
136 147
137 gtk_list_box_prepend( 148 gtk_list_box_prepend(
138 app->ui.invite_contact.contacts_listbox, 149 app->ui.invite_contact.contacts_listbox,
139 entry->entry_box 150 entry->entry_box
140 ); 151 );
141 152
142 GtkListBoxRow *row = GTK_LIST_BOX_ROW( 153 GtkListBoxRow *row = GTK_LIST_BOX_ROW(
143 gtk_widget_get_parent(entry->entry_box) 154 gtk_widget_get_parent(entry->entry_box)
144 ); 155 );
145 156
146 g_object_set_qdata(G_OBJECT(row), app->quarks.data, contact); 157 g_object_set_qdata(G_OBJECT(row), app->quarks.data, contact);
147 158
148 g_object_set_qdata_full( 159 g_object_set_qdata_full(
149 G_OBJECT(row), 160 G_OBJECT(row),
150 app->quarks.ui, 161 app->quarks.ui,
151 entry, 162 entry,
152 (GDestroyNotify) ui_contact_entry_delete 163 (GDestroyNotify) ui_contact_entry_delete
153 ); 164 );
154 165
155 return GNUNET_YES; 166 return GNUNET_YES;
@@ -157,72 +168,74 @@ _iterate_contacts(void *cls,
157 168
158void 169void
159ui_invite_contact_dialog_init(MESSENGER_Application *app, 170ui_invite_contact_dialog_init(MESSENGER_Application *app,
160 UI_INVITE_CONTACT_Handle *handle) 171 UI_INVITE_CONTACT_Handle *handle)
161{ 172{
173 g_assert((app) && (handle));
174
162 handle->builder = gtk_builder_new_from_resource( 175 handle->builder = gtk_builder_new_from_resource(
163 application_get_resource_path(app, "ui/invite_contact.ui") 176 application_get_resource_path(app, "ui/invite_contact.ui")
164 ); 177 );
165 178
166 handle->dialog = GTK_DIALOG( 179 handle->dialog = GTK_DIALOG(
167 gtk_builder_get_object(handle->builder, "invite_contact_dialog") 180 gtk_builder_get_object(handle->builder, "invite_contact_dialog")
168 ); 181 );
169 182
170 gtk_window_set_transient_for( 183 gtk_window_set_transient_for(
171 GTK_WINDOW(handle->dialog), 184 GTK_WINDOW(handle->dialog),
172 GTK_WINDOW(app->ui.messenger.main_window) 185 GTK_WINDOW(app->ui.messenger.main_window)
173 ); 186 );
174 187
175 handle->contact_search_entry = GTK_SEARCH_ENTRY( 188 handle->contact_search_entry = GTK_SEARCH_ENTRY(
176 gtk_builder_get_object(handle->builder, "contact_search_entry") 189 gtk_builder_get_object(handle->builder, "contact_search_entry")
177 ); 190 );
178 191
179 handle->contacts_listbox = GTK_LIST_BOX( 192 handle->contacts_listbox = GTK_LIST_BOX(
180 gtk_builder_get_object(handle->builder, "contacts_listbox") 193 gtk_builder_get_object(handle->builder, "contacts_listbox")
181 ); 194 );
182 195
183 gtk_list_box_set_filter_func( 196 gtk_list_box_set_filter_func(
184 handle->contacts_listbox, 197 handle->contacts_listbox,
185 handle_contacts_listbox_filter_func, 198 handle_contacts_listbox_filter_func,
186 app, 199 app,
187 NULL 200 NULL
188 ); 201 );
189 202
190 g_signal_connect( 203 g_signal_connect(
191 handle->contact_search_entry, 204 handle->contact_search_entry,
192 "search-changed", 205 "search-changed",
193 G_CALLBACK(handle_contact_search_entry_search_changed), 206 G_CALLBACK(handle_contact_search_entry_search_changed),
194 handle->contacts_listbox 207 handle->contacts_listbox
195 ); 208 );
196 209
197 g_signal_connect( 210 g_signal_connect(
198 handle->contacts_listbox, 211 handle->contacts_listbox,
199 "row-activated", 212 "row-activated",
200 G_CALLBACK(handle_contacts_listbox_row_activated), 213 G_CALLBACK(handle_contacts_listbox_row_activated),
201 app 214 app
202 ); 215 );
203 216
204 handle->close_button = GTK_BUTTON( 217 handle->close_button = GTK_BUTTON(
205 gtk_builder_get_object(handle->builder, "close_button") 218 gtk_builder_get_object(handle->builder, "close_button")
206 ); 219 );
207 220
208 g_signal_connect( 221 g_signal_connect(
209 handle->close_button, 222 handle->close_button,
210 "clicked", 223 "clicked",
211 G_CALLBACK(handle_close_button_click), 224 G_CALLBACK(handle_close_button_click),
212 handle->dialog 225 handle->dialog
213 ); 226 );
214 227
215 g_signal_connect( 228 g_signal_connect(
216 handle->dialog, 229 handle->dialog,
217 "destroy", 230 "destroy",
218 G_CALLBACK(handle_dialog_destroy), 231 G_CALLBACK(handle_dialog_destroy),
219 handle 232 handle
220 ); 233 );
221 234
222 GNUNET_CHAT_iterate_contacts( 235 GNUNET_CHAT_iterate_contacts(
223 app->chat.messenger.handle, 236 app->chat.messenger.handle,
224 _iterate_contacts, 237 _iterate_contacts,
225 app 238 app
226 ); 239 );
227 240
228 gtk_list_box_invalidate_filter(handle->contacts_listbox); 241 gtk_list_box_invalidate_filter(handle->contacts_listbox);
@@ -231,6 +244,8 @@ ui_invite_contact_dialog_init(MESSENGER_Application *app,
231void 244void
232ui_invite_contact_dialog_cleanup(UI_INVITE_CONTACT_Handle *handle) 245ui_invite_contact_dialog_cleanup(UI_INVITE_CONTACT_Handle *handle)
233{ 246{
247 g_assert(handle);
248
234 g_object_unref(handle->builder); 249 g_object_unref(handle->builder);
235 250
236 memset(handle, 0, sizeof(*handle)); 251 memset(handle, 0, sizeof(*handle));