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.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/ui/contacts.c b/src/ui/contacts.c
index 3750f8f..34ceaed 100644
--- a/src/ui/contacts.c
+++ b/src/ui/contacts.c
@@ -24,8 +24,11 @@
24 24
25#include "contacts.h" 25#include "contacts.h"
26 26
27#include "contact_entry.h"
27#include "../application.h" 28#include "../application.h"
28 29
30#include <gnunet/gnunet_identity_service.h>
31
29static void 32static void
30handle_close_button_click(UNUSED GtkButton *button, 33handle_close_button_click(UNUSED GtkButton *button,
31 gpointer user_data) 34 gpointer user_data)
@@ -41,10 +44,66 @@ handle_dialog_destroy(UNUSED GtkWidget *window,
41 ui_contacts_dialog_cleanup((UI_CONTACTS_Handle*) user_data); 44 ui_contacts_dialog_cleanup((UI_CONTACTS_Handle*) user_data);
42} 45}
43 46
47static int
48_iterate_clear_contacts(UNUSED void *cls,
49 UNUSED struct GNUNET_CHAT_Handle *handle,
50 struct GNUNET_CHAT_Contact *contact)
51{
52 GNUNET_CHAT_contact_set_user_pointer(contact, NULL);
53 return GNUNET_YES;
54}
55
56static int
57_iterate_contacts(void *cls,
58 UNUSED struct GNUNET_CHAT_Handle *handle,
59 struct GNUNET_CHAT_Contact *contact)
60{
61 MESSENGER_Application *app = (MESSENGER_Application*) cls;
62
63 if (GNUNET_CHAT_contact_get_user_pointer(contact))
64 return GNUNET_YES;
65
66 const char *title;
67 title = GNUNET_CHAT_contact_get_name(contact);
68
69 const struct GNUNET_IDENTITY_PublicKey *key;
70 key = GNUNET_CHAT_contact_get_key(contact);
71
72 UI_CONTACT_ENTRY_Handle *entry = ui_contact_entry_new();
73 gtk_container_add(
74 GTK_CONTAINER(app->ui.contacts.contacts_listbox),
75 entry->entry_box
76 );
77
78 GNUNET_CHAT_contact_set_user_pointer(contact, entry);
79
80 if (title)
81 {
82 gtk_label_set_text(entry->title_label, title);
83 hdy_avatar_set_text(entry->entry_avatar, title);
84 }
85
86 if (key)
87 {
88 char *key_string = GNUNET_IDENTITY_public_key_to_string(key);
89 gtk_label_set_text(entry->subtitle_label, key_string);
90 GNUNET_free(key_string);
91 }
92
93 app->ui.contacts.contact_entries = g_list_append(
94 app->ui.contacts.contact_entries,
95 entry
96 );
97
98 return GNUNET_YES;
99}
100
44void 101void
45ui_contacts_dialog_init(MESSENGER_Application *app, 102ui_contacts_dialog_init(MESSENGER_Application *app,
46 UI_CONTACTS_Handle *handle) 103 UI_CONTACTS_Handle *handle)
47{ 104{
105 handle->contact_entries = g_list_alloc();
106
48 handle->builder = gtk_builder_new_from_file("resources/ui/contacts.ui"); 107 handle->builder = gtk_builder_new_from_file("resources/ui/contacts.ui");
49 108
50 handle->dialog = GTK_DIALOG( 109 handle->dialog = GTK_DIALOG(
@@ -65,6 +124,10 @@ ui_contacts_dialog_init(MESSENGER_Application *app,
65 gtk_builder_get_object(handle->builder, "contact_search_entry") 124 gtk_builder_get_object(handle->builder, "contact_search_entry")
66 ); 125 );
67 126
127 handle->contacts_listbox = GTK_LIST_BOX(
128 gtk_builder_get_object(handle->builder, "contacts_listbox")
129 );
130
68 handle->close_button = GTK_BUTTON( 131 handle->close_button = GTK_BUTTON(
69 gtk_builder_get_object(handle->builder, "close_button") 132 gtk_builder_get_object(handle->builder, "close_button")
70 ); 133 );
@@ -82,10 +145,33 @@ ui_contacts_dialog_init(MESSENGER_Application *app,
82 G_CALLBACK(handle_dialog_destroy), 145 G_CALLBACK(handle_dialog_destroy),
83 handle 146 handle
84 ); 147 );
148
149 GNUNET_CHAT_iterate_contacts(
150 app->chat.messenger.handle,
151 _iterate_clear_contacts,
152 NULL
153 );
154
155 GNUNET_CHAT_iterate_contacts(
156 app->chat.messenger.handle,
157 _iterate_contacts,
158 app
159 );
85} 160}
86 161
87void 162void
88ui_contacts_dialog_cleanup(UI_CONTACTS_Handle *handle) 163ui_contacts_dialog_cleanup(UI_CONTACTS_Handle *handle)
89{ 164{
90 g_object_unref(handle->builder); 165 g_object_unref(handle->builder);
166
167 GList *list = handle->contact_entries;
168
169 while (list) {
170 if (list->data)
171 ui_contact_entry_delete((UI_CONTACT_ENTRY_Handle*) list->data);
172
173 list = list->next;
174 }
175
176 g_list_free(handle->contact_entries);
91} 177}