aboutsummaryrefslogtreecommitdiff
path: root/src/event.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/event.c')
-rw-r--r--src/event.c88
1 files changed, 63 insertions, 25 deletions
diff --git a/src/event.c b/src/event.c
index 193ecfa..5409d7b 100644
--- a/src/event.c
+++ b/src/event.c
@@ -80,6 +80,68 @@ _show_notification(MESSENGER_Application *app,
80} 80}
81 81
82static void 82static void
83_clear_each_selectable_widget(GtkWidget *widget,
84 gpointer user_data)
85{
86 GtkContainer *container = GTK_CONTAINER(user_data);
87 GtkListBoxRow *row = GTK_LIST_BOX_ROW(widget);
88
89 if (gtk_list_box_row_get_selectable(row))
90 gtk_container_remove(container, widget);
91}
92
93static int
94_iterate_accounts(void *cls,
95 const struct GNUNET_CHAT_Handle *handle,
96 struct GNUNET_CHAT_Account *account)
97{
98 MESSENGER_Application *app = (MESSENGER_Application*) cls;
99 UI_MESSENGER_Handle *ui = &(app->ui.messenger);
100
101 const gchar *name = GNUNET_CHAT_account_get_name(account);
102
103 UI_PROFILE_ENTRY_Handle *profile = ui_profile_entry_new(app);
104
105 hdy_avatar_set_text(profile->entry_avatar, name);
106 gtk_label_set_text(profile->entry_label, name);
107
108 gtk_list_box_prepend(ui->accounts_listbox, profile->entry_box);
109
110 GtkListBoxRow *row = GTK_LIST_BOX_ROW(
111 gtk_widget_get_parent(profile->entry_box)
112 );
113
114 g_hash_table_insert(ui->bindings, row, account);
115
116 if ((account == GNUNET_CHAT_get_connected(handle)) ||
117 ((app->chat.identity) && (0 == g_strcmp0(app->chat.identity, name))))
118 gtk_list_box_select_row(ui->accounts_listbox, row);
119
120 ui_profile_entry_delete(profile);
121 return GNUNET_YES;
122}
123
124void
125event_refresh_accounts(MESSENGER_Application *app)
126{
127 UI_MESSENGER_Handle *ui = &(app->ui.messenger);
128 CHAT_MESSENGER_Handle *chat = &(app->chat.messenger);
129
130 if (!(ui->accounts_listbox))
131 return;
132
133 gtk_list_box_unselect_all(ui->accounts_listbox);
134
135 gtk_container_foreach(
136 GTK_CONTAINER(ui->accounts_listbox),
137 _clear_each_selectable_widget,
138 ui->accounts_listbox
139 );
140
141 GNUNET_CHAT_iterate_accounts(chat->handle, _iterate_accounts, app);
142}
143
144static void
83_add_new_chat_entry(MESSENGER_Application *app, 145_add_new_chat_entry(MESSENGER_Application *app,
84 struct GNUNET_CHAT_Context *context) 146 struct GNUNET_CHAT_Context *context)
85{ 147{
@@ -156,15 +218,6 @@ _iterate_profile_groups(void *cls,
156 return GNUNET_YES; 218 return GNUNET_YES;
157} 219}
158 220
159static void
160_clear_each_widget(GtkWidget *widget,
161 gpointer user_data)
162{
163 GtkContainer *container = GTK_CONTAINER(user_data);
164
165 gtk_container_remove(container, widget);
166}
167
168void 221void
169event_update_profile(MESSENGER_Application *app) 222event_update_profile(MESSENGER_Application *app)
170{ 223{
@@ -177,21 +230,6 @@ event_update_profile(MESSENGER_Application *app)
177 { 230 {
178 hdy_avatar_set_text(ui->profile_avatar, name); 231 hdy_avatar_set_text(ui->profile_avatar, name);
179 gtk_label_set_text(ui->profile_label, name); 232 gtk_label_set_text(ui->profile_label, name);
180
181 UI_PROFILE_ENTRY_Handle *profile = ui_profile_entry_new(app);
182
183 hdy_avatar_set_text(profile->entry_avatar, name);
184 gtk_label_set_text(profile->entry_label, name);
185
186 gtk_list_box_prepend(ui->accounts_listbox, profile->entry_box);
187
188 GtkListBoxRow *row = GTK_LIST_BOX_ROW(
189 gtk_widget_get_parent(profile->entry_box)
190 );
191
192 gtk_list_box_select_row(ui->accounts_listbox, row);
193
194 ui_profile_entry_delete(profile);
195 } 233 }
196 234
197 const char *key = GNUNET_CHAT_get_key(chat->handle); 235 const char *key = GNUNET_CHAT_get_key(chat->handle);
@@ -201,7 +239,7 @@ event_update_profile(MESSENGER_Application *app)
201 239
202 gtk_container_foreach( 240 gtk_container_foreach(
203 GTK_CONTAINER(ui->chats_listbox), 241 GTK_CONTAINER(ui->chats_listbox),
204 _clear_each_widget, 242 _clear_each_selectable_widget,
205 ui->chats_listbox 243 ui->chats_listbox
206 ); 244 );
207 245