aboutsummaryrefslogtreecommitdiff
path: root/src/ui/invite_contact.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/invite_contact.c')
-rw-r--r--src/ui/invite_contact.c93
1 files changed, 52 insertions, 41 deletions
diff --git a/src/ui/invite_contact.c b/src/ui/invite_contact.c
index 3afeee0..4229067 100644
--- a/src/ui/invite_contact.c
+++ b/src/ui/invite_contact.c
@@ -44,11 +44,11 @@ handle_contacts_listbox_row_activated(GtkListBox* listbox,
44 MESSENGER_Application *app = (MESSENGER_Application*) user_data; 44 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
45 45
46 GtkTextView *text_view = GTK_TEXT_VIEW( 46 GtkTextView *text_view = GTK_TEXT_VIEW(
47 g_hash_table_lookup(app->ui.bindings, listbox) 47 bindings_get(app->bindings, listbox)
48 ); 48 );
49 49
50 struct GNUNET_CHAT_Contact *contact = (struct GNUNET_CHAT_Contact*) ( 50 struct GNUNET_CHAT_Contact *contact = (struct GNUNET_CHAT_Contact*) (
51 g_hash_table_lookup(app->ui.bindings, row) 51 bindings_get(app->bindings, row)
52 ); 52 );
53 53
54 if ((!contact) || (!GNUNET_CHAT_contact_get_key(contact)) || 54 if ((!contact) || (!GNUNET_CHAT_contact_get_key(contact)) ||
@@ -56,8 +56,8 @@ handle_contacts_listbox_row_activated(GtkListBox* listbox,
56 (!text_view)) 56 (!text_view))
57 goto close_dialog; 57 goto close_dialog;
58 58
59 struct GNUNET_CHAT_Context *context = g_hash_table_lookup( 59 struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) (
60 app->ui.bindings, text_view 60 bindings_get(app->bindings, text_view)
61 ); 61 );
62 62
63 if (!context) 63 if (!context)
@@ -78,9 +78,9 @@ static gboolean
78handle_contacts_listbox_filter_func(GtkListBoxRow *row, 78handle_contacts_listbox_filter_func(GtkListBoxRow *row,
79 gpointer user_data) 79 gpointer user_data)
80{ 80{
81 UI_CONTACTS_Handle *handle = (UI_CONTACTS_Handle*) user_data; 81 UI_INVITE_CONTACT_Handle *handle = (UI_INVITE_CONTACT_Handle*) user_data;
82 82
83 if (!gtk_list_box_row_get_selectable(row)) 83 if ((!row) || (!gtk_list_box_row_get_selectable(row)))
84 return TRUE; 84 return TRUE;
85 85
86 const gchar *filter = gtk_entry_get_text( 86 const gchar *filter = gtk_entry_get_text(
@@ -90,14 +90,14 @@ handle_contacts_listbox_filter_func(GtkListBoxRow *row,
90 if (!filter) 90 if (!filter)
91 return TRUE; 91 return TRUE;
92 92
93 struct GNUNET_CHAT_Contact *contact = (struct GNUNET_CHAT_Contact*) ( 93 UI_CONTACT_ENTRY_Handle *entry = (UI_CONTACT_ENTRY_Handle*) (
94 g_hash_table_lookup(handle->bindings, row) 94 bindings_get(handle->bindings, row)
95 ); 95 );
96 96
97 if (!contact) 97 if (!entry)
98 return FALSE; 98 return FALSE;
99 99
100 const gchar *name = GNUNET_CHAT_contact_get_name(contact); 100 const gchar *name = gtk_label_get_text(entry->title_label);
101 101
102 if (!name) 102 if (!name)
103 return FALSE; 103 return FALSE;
@@ -131,36 +131,20 @@ _iterate_contacts(void *cls,
131 131
132 MESSENGER_Application *app = (MESSENGER_Application*) cls; 132 MESSENGER_Application *app = (MESSENGER_Application*) cls;
133 133
134 const char *title;
135 title = GNUNET_CHAT_contact_get_name(contact);
136
137 const char *key = GNUNET_CHAT_contact_get_key(contact);
138
139 UI_CONTACT_ENTRY_Handle *entry = ui_contact_entry_new(app); 134 UI_CONTACT_ENTRY_Handle *entry = ui_contact_entry_new(app);
135 ui_contact_entry_set_contact(entry, contact);
136
140 gtk_list_box_prepend( 137 gtk_list_box_prepend(
141 app->ui.invite_contact.contacts_listbox, 138 app->ui.invite_contact.contacts_listbox,
142 entry->entry_box 139 entry->entry_box
143 ); 140 );
144 141
145 if (title)
146 {
147 gtk_label_set_text(entry->title_label, title);
148 hdy_avatar_set_text(entry->entry_avatar, title);
149 }
150
151 if (key)
152 gtk_label_set_text(entry->subtitle_label, key);
153
154 GtkListBoxRow *row = GTK_LIST_BOX_ROW( 142 GtkListBoxRow *row = GTK_LIST_BOX_ROW(
155 gtk_widget_get_parent(entry->entry_box) 143 gtk_widget_get_parent(entry->entry_box)
156 ); 144 );
157 145
158 g_hash_table_insert(app->ui.bindings, row, contact); 146 bindings_put(app->bindings, row, contact);
159 147 bindings_put(app->ui.invite_contact.bindings, row, entry);
160 app->ui.invite_contact.contact_entries = g_list_append(
161 app->ui.invite_contact.contact_entries,
162 entry
163 );
164 148
165 return GNUNET_YES; 149 return GNUNET_YES;
166} 150}
@@ -169,8 +153,7 @@ void
169ui_invite_contact_dialog_init(MESSENGER_Application *app, 153ui_invite_contact_dialog_init(MESSENGER_Application *app,
170 UI_INVITE_CONTACT_Handle *handle) 154 UI_INVITE_CONTACT_Handle *handle)
171{ 155{
172 handle->contact_entries = NULL; 156 handle->bindings = bindings_create();
173 handle->bindings = app->ui.bindings;
174 157
175 handle->builder = gtk_builder_new_from_resource( 158 handle->builder = gtk_builder_new_from_resource(
176 application_get_resource_path(app, "ui/invite_contact.ui") 159 application_get_resource_path(app, "ui/invite_contact.ui")
@@ -241,20 +224,48 @@ ui_invite_contact_dialog_init(MESSENGER_Application *app,
241 gtk_list_box_invalidate_filter(handle->contacts_listbox); 224 gtk_list_box_invalidate_filter(handle->contacts_listbox);
242} 225}
243 226
244void 227static void
245ui_invite_contact_dialog_cleanup(UI_INVITE_CONTACT_Handle *handle) 228_clear_contacts_listbox_rows(UI_INVITE_CONTACT_Handle *handle,
229 gboolean bindings_only)
246{ 230{
247 g_object_unref(handle->builder); 231 GList *list = gtk_container_get_children(
232 GTK_CONTAINER(handle->contacts_listbox)
233 );
234
235 while (list)
236 {
237 GtkListBoxRow *row = GTK_LIST_BOX_ROW(list->data);
248 238
249 GList *list = handle->contact_entries; 239 if ((!row) || (!gtk_list_box_row_get_selectable(row)))
240 goto skip_row;
250 241
251 while (list) { 242 if (!bindings_only)
252 if (list->data) 243 gtk_container_remove(
253 ui_contact_entry_delete((UI_CONTACT_ENTRY_Handle*) list->data); 244 GTK_CONTAINER(handle->contacts_listbox),
245 GTK_WIDGET(row)
246 );
254 247
248 bindings_remove(
249 handle->bindings,
250 row,
251 NULL,
252 (GDestroyNotify) ui_contact_entry_delete
253 );
254
255 skip_row:
255 list = list->next; 256 list = list->next;
256 } 257 }
258}
259
260void
261ui_invite_contact_dialog_cleanup(UI_INVITE_CONTACT_Handle *handle)
262{
263 _clear_contacts_listbox_rows(handle, TRUE);
264
265 g_object_unref(handle->builder);
266
267 bindings_destroy(handle->bindings);
268 handle->bindings = NULL;
257 269
258 if (handle->contact_entries) 270 handle->contacts_listbox = NULL;
259 g_list_free(handle->contact_entries);
260} 271}