aboutsummaryrefslogtreecommitdiff
path: root/src/ui/accounts.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/accounts.c')
-rw-r--r--src/ui/accounts.c57
1 files changed, 15 insertions, 42 deletions
diff --git a/src/ui/accounts.c b/src/ui/accounts.c
index fcd4ad9..0741654 100644
--- a/src/ui/accounts.c
+++ b/src/ui/accounts.c
@@ -72,7 +72,7 @@ handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox,
72 } 72 }
73 73
74 struct GNUNET_CHAT_Account *account = (struct GNUNET_CHAT_Account*) ( 74 struct GNUNET_CHAT_Account *account = (struct GNUNET_CHAT_Account*) (
75 g_hash_table_lookup(app->ui.bindings, row) 75 bindings_get(app->bindings, row)
76 ); 76 );
77 77
78 if (!account) 78 if (!account)
@@ -109,25 +109,18 @@ _iterate_accounts(void *cls,
109{ 109{
110 MESSENGER_Application *app = (MESSENGER_Application*) cls; 110 MESSENGER_Application *app = (MESSENGER_Application*) cls;
111 111
112 const gchar *name = GNUNET_CHAT_account_get_name(account);
113
114 UI_ACCOUNT_ENTRY_Handle *entry = ui_account_entry_new(app); 112 UI_ACCOUNT_ENTRY_Handle *entry = ui_account_entry_new(app);
115 113
116 hdy_avatar_set_text(entry->entry_avatar, name); 114 ui_account_entry_set_account(entry, account);
117 gtk_label_set_text(entry->entry_label, name);
118 115
119 gtk_list_box_prepend(app->ui.accounts.accounts_listbox, entry->entry_box); 116 gtk_list_box_prepend(app->ui.accounts.accounts_listbox, entry->entry_box);
120 117
121 GtkListBoxRow *row = GTK_LIST_BOX_ROW( 118 GtkListBoxRow *row = GTK_LIST_BOX_ROW(
122 gtk_widget_get_parent(entry->entry_box) 119 gtk_widget_get_parent(entry->entry_box)
123 ); 120 );
124 121
125 g_hash_table_insert(app->ui.bindings, row, account); 122 bindings_put(app->bindings, row, account);
126 123 bindings_put(app->ui.accounts.bindings, row, entry);
127 app->ui.accounts.account_entries = g_list_append(
128 app->ui.accounts.account_entries,
129 entry
130 );
131 124
132 return GNUNET_YES; 125 return GNUNET_YES;
133} 126}
@@ -136,8 +129,7 @@ void
136ui_accounts_dialog_init(MESSENGER_Application *app, 129ui_accounts_dialog_init(MESSENGER_Application *app,
137 UI_ACCOUNTS_Handle *handle) 130 UI_ACCOUNTS_Handle *handle)
138{ 131{
139 handle->account_entries = NULL; 132 handle->bindings = bindings_create();
140 handle->bindings = app->ui.bindings;
141 handle->show_queued = 0; 133 handle->show_queued = 0;
142 134
143 handle->builder = gtk_builder_new_from_resource( 135 handle->builder = gtk_builder_new_from_resource(
@@ -198,35 +190,22 @@ _clear_accounts_listbox_rows(UI_ACCOUNTS_Handle *handle,
198 if ((!row) || (!gtk_list_box_row_get_selectable(row))) 190 if ((!row) || (!gtk_list_box_row_get_selectable(row)))
199 goto skip_row; 191 goto skip_row;
200 192
201 g_hash_table_remove(handle->bindings, row);
202
203 if (!bindings_only) 193 if (!bindings_only)
204 gtk_container_remove( 194 gtk_container_remove(
205 GTK_CONTAINER(handle->accounts_listbox), 195 GTK_CONTAINER(handle->accounts_listbox),
206 GTK_WIDGET(row) 196 GTK_WIDGET(row)
207 ); 197 );
208 198
209 skip_row: 199 bindings_remove(
210 list = list->next; 200 handle->bindings,
211 } 201 row,
212} 202 NULL,
213 203 (GDestroyNotify) ui_account_entry_delete
214static void 204 );
215_clear_accounts_entries(UI_ACCOUNTS_Handle *handle)
216{
217 GList *list = handle->account_entries;
218
219 while (list) {
220 if (list->data)
221 ui_account_entry_delete((UI_ACCOUNT_ENTRY_Handle*) list->data);
222 205
206 skip_row:
223 list = list->next; 207 list = list->next;
224 } 208 }
225
226 if (handle->account_entries)
227 g_list_free(handle->account_entries);
228
229 handle->account_entries = NULL;
230} 209}
231 210
232void 211void
@@ -236,20 +215,13 @@ ui_accounts_dialog_refresh(MESSENGER_Application *app,
236 if (!(handle->accounts_listbox)) 215 if (!(handle->accounts_listbox))
237 return; 216 return;
238 217
239 if (!(handle->account_entries))
240 goto add_account_entries;
241
242 _clear_accounts_listbox_rows(handle, FALSE); 218 _clear_accounts_listbox_rows(handle, FALSE);
243 _clear_accounts_entries(handle);
244 219
245add_account_entries:
246 GNUNET_CHAT_iterate_accounts( 220 GNUNET_CHAT_iterate_accounts(
247 app->chat.messenger.handle, 221 app->chat.messenger.handle,
248 _iterate_accounts, 222 _iterate_accounts,
249 app 223 app
250 ); 224 );
251
252 gtk_list_box_unselect_all(handle->accounts_listbox);
253} 225}
254 226
255void 227void
@@ -259,7 +231,8 @@ ui_accounts_dialog_cleanup(UI_ACCOUNTS_Handle *handle)
259 231
260 g_object_unref(handle->builder); 232 g_object_unref(handle->builder);
261 233
262 _clear_accounts_entries(handle); 234 bindings_destroy(handle->bindings);
235 handle->bindings = NULL;
263 236
264 handle->accounts_listbox = NULL; 237 handle->accounts_listbox = NULL;
265} 238}