aboutsummaryrefslogtreecommitdiff
path: root/src/ui/contacts.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/contacts.c')
-rw-r--r--src/ui/contacts.c83
1 files changed, 41 insertions, 42 deletions
diff --git a/src/ui/contacts.c b/src/ui/contacts.c
index 2e3b0ec..21d2f2f 100644
--- a/src/ui/contacts.c
+++ b/src/ui/contacts.c
@@ -61,7 +61,7 @@ handle_contacts_listbox_row_activated(UNUSED GtkListBox* listbox,
61 } 61 }
62 62
63 struct GNUNET_CHAT_Contact *contact = (struct GNUNET_CHAT_Contact*) ( 63 struct GNUNET_CHAT_Contact *contact = (struct GNUNET_CHAT_Contact*) (
64 g_hash_table_lookup(app->ui.bindings, row) 64 bindings_get(app->bindings, row)
65 ); 65 );
66 66
67 if ((!contact) || (!GNUNET_CHAT_contact_get_key(contact)) || 67 if ((!contact) || (!GNUNET_CHAT_contact_get_key(contact)) ||
@@ -88,7 +88,7 @@ handle_contacts_listbox_filter_func(GtkListBoxRow *row,
88{ 88{
89 UI_CONTACTS_Handle *handle = (UI_CONTACTS_Handle*) user_data; 89 UI_CONTACTS_Handle *handle = (UI_CONTACTS_Handle*) user_data;
90 90
91 if (!gtk_list_box_row_get_selectable(row)) 91 if ((!row) || (!gtk_list_box_row_get_selectable(row)))
92 return TRUE; 92 return TRUE;
93 93
94 const gchar *filter = gtk_entry_get_text( 94 const gchar *filter = gtk_entry_get_text(
@@ -98,14 +98,14 @@ handle_contacts_listbox_filter_func(GtkListBoxRow *row,
98 if (!filter) 98 if (!filter)
99 return TRUE; 99 return TRUE;
100 100
101 struct GNUNET_CHAT_Contact *contact = (struct GNUNET_CHAT_Contact*) ( 101 UI_CONTACT_ENTRY_Handle *entry = (UI_CONTACT_ENTRY_Handle*) (
102 g_hash_table_lookup(handle->bindings, row) 102 bindings_get(handle->bindings, row)
103 ); 103 );
104 104
105 if (!contact) 105 if (!entry)
106 return FALSE; 106 return FALSE;
107 107
108 const gchar *name = GNUNET_CHAT_contact_get_name(contact); 108 const gchar *name = gtk_label_get_text(entry->title_label);
109 109
110 if (!name) 110 if (!name)
111 return FALSE; 111 return FALSE;
@@ -139,36 +139,20 @@ _iterate_contacts(void *cls,
139 139
140 MESSENGER_Application *app = (MESSENGER_Application*) cls; 140 MESSENGER_Application *app = (MESSENGER_Application*) cls;
141 141
142 const char *title;
143 title = GNUNET_CHAT_contact_get_name(contact);
144
145 const char *key = GNUNET_CHAT_contact_get_key(contact);
146
147 UI_CONTACT_ENTRY_Handle *entry = ui_contact_entry_new(app); 142 UI_CONTACT_ENTRY_Handle *entry = ui_contact_entry_new(app);
143 ui_contact_entry_set_contact(entry, contact);
144
148 gtk_list_box_prepend( 145 gtk_list_box_prepend(
149 app->ui.contacts.contacts_listbox, 146 app->ui.contacts.contacts_listbox,
150 entry->entry_box 147 entry->entry_box
151 ); 148 );
152 149
153 if (title)
154 {
155 gtk_label_set_text(entry->title_label, title);
156 hdy_avatar_set_text(entry->entry_avatar, title);
157 }
158
159 if (key)
160 gtk_label_set_text(entry->subtitle_label, key);
161
162 GtkListBoxRow *row = GTK_LIST_BOX_ROW( 150 GtkListBoxRow *row = GTK_LIST_BOX_ROW(
163 gtk_widget_get_parent(entry->entry_box) 151 gtk_widget_get_parent(entry->entry_box)
164 ); 152 );
165 153
166 g_hash_table_insert(app->ui.bindings, row, contact); 154 bindings_put(app->bindings, row, contact);
167 155 bindings_put(app->ui.contacts.bindings, row, entry);
168 app->ui.contacts.contact_entries = g_list_append(
169 app->ui.contacts.contact_entries,
170 entry
171 );
172 156
173 return GNUNET_YES; 157 return GNUNET_YES;
174} 158}
@@ -177,8 +161,7 @@ void
177ui_contacts_dialog_init(MESSENGER_Application *app, 161ui_contacts_dialog_init(MESSENGER_Application *app,
178 UI_CONTACTS_Handle *handle) 162 UI_CONTACTS_Handle *handle)
179{ 163{
180 handle->contact_entries = NULL; 164 handle->bindings = bindings_create();
181 handle->bindings = app->ui.bindings;
182 165
183 handle->builder = gtk_builder_new_from_resource( 166 handle->builder = gtk_builder_new_from_resource(
184 application_get_resource_path(app, "ui/contacts.ui") 167 application_get_resource_path(app, "ui/contacts.ui")
@@ -249,8 +232,9 @@ ui_contacts_dialog_init(MESSENGER_Application *app,
249 gtk_list_box_invalidate_filter(handle->contacts_listbox); 232 gtk_list_box_invalidate_filter(handle->contacts_listbox);
250} 233}
251 234
252void 235static void
253ui_contacts_dialog_cleanup(UI_CONTACTS_Handle *handle) 236_clear_contacts_listbox_rows(UI_CONTACTS_Handle *handle,
237 gboolean bindings_only)
254{ 238{
255 GList *list = gtk_container_get_children( 239 GList *list = gtk_container_get_children(
256 GTK_CONTAINER(handle->contacts_listbox) 240 GTK_CONTAINER(handle->contacts_listbox)
@@ -258,23 +242,38 @@ ui_contacts_dialog_cleanup(UI_CONTACTS_Handle *handle)
258 242
259 while (list) 243 while (list)
260 { 244 {
261 if (list->data) 245 GtkListBoxRow *row = GTK_LIST_BOX_ROW(list->data);
262 g_hash_table_remove(handle->bindings, list->data);
263 246
264 list = list->next; 247 if ((!row) || (!gtk_list_box_row_get_selectable(row)))
265 } 248 goto skip_row;
266 249
267 g_object_unref(handle->builder); 250 if (!bindings_only)
251 gtk_container_remove(
252 GTK_CONTAINER(handle->contacts_listbox),
253 GTK_WIDGET(row)
254 );
268 255
269 list = handle->contact_entries; 256 bindings_remove(
270 257 handle->bindings,
271 while (list) { 258 row,
272 if (list->data) 259 NULL,
273 ui_contact_entry_delete((UI_CONTACT_ENTRY_Handle*) list->data); 260 (GDestroyNotify) ui_contact_entry_delete
261 );
274 262
263 skip_row:
275 list = list->next; 264 list = list->next;
276 } 265 }
266}
267
268void
269ui_contacts_dialog_cleanup(UI_CONTACTS_Handle *handle)
270{
271 _clear_contacts_listbox_rows(handle, TRUE);
272
273 g_object_unref(handle->builder);
274
275 bindings_destroy(handle->bindings);
276 handle->bindings = NULL;
277 277
278 if (handle->contact_entries) 278 handle->contacts_listbox = NULL;
279 g_list_free(handle->contact_entries);
280} 279}