diff options
Diffstat (limited to 'src/ui/chat.c')
-rw-r--r-- | src/ui/chat.c | 113 |
1 files changed, 106 insertions, 7 deletions
diff --git a/src/ui/chat.c b/src/ui/chat.c index 73e014c..0ddd59c 100644 --- a/src/ui/chat.c +++ b/src/ui/chat.c | |||
@@ -26,6 +26,7 @@ | |||
26 | 26 | ||
27 | #include "messenger.h" | 27 | #include "messenger.h" |
28 | #include "picker.h" | 28 | #include "picker.h" |
29 | #include "profile_entry.h" | ||
29 | #include "../application.h" | 30 | #include "../application.h" |
30 | 31 | ||
31 | static void | 32 | static void |
@@ -176,6 +177,10 @@ ui_chat_new(MESSENGER_Application *app) | |||
176 | messenger->leaflet_chat | 177 | messenger->leaflet_chat |
177 | ); | 178 | ); |
178 | 179 | ||
180 | handle->flap_chat_details = HDY_FLAP( | ||
181 | gtk_builder_get_object(handle->builder, "flap_chat_details") | ||
182 | ); | ||
183 | |||
179 | handle->chat_title = GTK_LABEL( | 184 | handle->chat_title = GTK_LABEL( |
180 | gtk_builder_get_object(handle->builder, "chat_title") | 185 | gtk_builder_get_object(handle->builder, "chat_title") |
181 | ); | 186 | ); |
@@ -192,7 +197,30 @@ ui_chat_new(MESSENGER_Application *app) | |||
192 | handle->chat_details_button, | 197 | handle->chat_details_button, |
193 | "clicked", | 198 | "clicked", |
194 | G_CALLBACK(handle_flap_via_button_click), | 199 | G_CALLBACK(handle_flap_via_button_click), |
195 | messenger->flap_chat_details | 200 | handle->flap_chat_details |
201 | ); | ||
202 | |||
203 | handle->chat_details_label = GTK_LABEL( | ||
204 | gtk_builder_get_object(handle->builder, "chat_details_label") | ||
205 | ); | ||
206 | |||
207 | handle->hide_chat_details_button = GTK_BUTTON( | ||
208 | gtk_builder_get_object(handle->builder, "hide_chat_details_button") | ||
209 | ); | ||
210 | |||
211 | g_signal_connect( | ||
212 | handle->hide_chat_details_button, | ||
213 | "clicked", | ||
214 | G_CALLBACK(handle_flap_via_button_click), | ||
215 | handle->flap_chat_details | ||
216 | ); | ||
217 | |||
218 | handle->chat_details_contacts_box = GTK_BOX( | ||
219 | gtk_builder_get_object(handle->builder, "chat_details_contacts_box") | ||
220 | ); | ||
221 | |||
222 | handle->chat_contacts_listbox = GTK_LIST_BOX( | ||
223 | gtk_builder_get_object(handle->builder, "chat_contacts_listbox") | ||
196 | ); | 224 | ); |
197 | 225 | ||
198 | handle->messages_listbox = GTK_LIST_BOX( | 226 | handle->messages_listbox = GTK_LIST_BOX( |
@@ -271,15 +299,86 @@ ui_chat_new(MESSENGER_Application *app) | |||
271 | return handle; | 299 | return handle; |
272 | } | 300 | } |
273 | 301 | ||
302 | static int | ||
303 | iterate_ui_chat_update_group_contacts(void *cls, | ||
304 | UNUSED const struct GNUNET_CHAT_Group *group, | ||
305 | struct GNUNET_CHAT_Contact *contact) | ||
306 | { | ||
307 | GtkListBox *listbox = GTK_LIST_BOX(cls); | ||
308 | UI_PROFILE_ENTRY_Handle* entry = ui_profile_entry_new(); | ||
309 | |||
310 | const char *name = GNUNET_CHAT_contact_get_name(contact); | ||
311 | |||
312 | if (name) | ||
313 | { | ||
314 | gtk_label_set_text(entry->entry_label, name); | ||
315 | hdy_avatar_set_text(entry->entry_avatar, name); | ||
316 | } | ||
317 | |||
318 | gtk_list_box_prepend(listbox, entry->entry_box); | ||
319 | |||
320 | ui_profile_entry_delete(entry); | ||
321 | return GNUNET_YES; | ||
322 | } | ||
323 | |||
274 | void | 324 | void |
275 | ui_chat_activate(UI_CHAT_Handle *handle) | 325 | ui_chat_update(UI_CHAT_Handle *handle, |
326 | const struct GNUNET_CHAT_Context* context) | ||
276 | { | 327 | { |
277 | gtk_text_view_set_editable(handle->send_text_view, TRUE); | 328 | const struct GNUNET_CHAT_Contact* contact; |
278 | gtk_widget_set_sensitive(GTK_WIDGET(handle->send_text_view), TRUE); | 329 | const struct GNUNET_CHAT_Group* group; |
330 | |||
331 | contact = GNUNET_CHAT_context_get_contact(context); | ||
332 | group = GNUNET_CHAT_context_get_group(context); | ||
333 | |||
334 | const char *title = NULL; | ||
335 | |||
336 | if (contact) | ||
337 | title = GNUNET_CHAT_contact_get_name(contact); | ||
338 | else if (group) | ||
339 | title = GNUNET_CHAT_group_get_name(group); | ||
340 | |||
341 | if (title) | ||
342 | { | ||
343 | gtk_label_set_text(handle->chat_title, title); | ||
344 | gtk_label_set_text(handle->chat_details_label, title); | ||
345 | } | ||
346 | |||
347 | GList* children = gtk_container_get_children( | ||
348 | GTK_CONTAINER(handle->chat_contacts_listbox) | ||
349 | ); | ||
350 | |||
351 | while ((children) && (children->next)) { | ||
352 | GtkWidget *widget = GTK_WIDGET(children->data); | ||
353 | children = children->next; | ||
354 | |||
355 | gtk_container_remove( | ||
356 | GTK_CONTAINER(handle->chat_contacts_listbox), | ||
357 | widget | ||
358 | ); | ||
359 | } | ||
360 | |||
361 | if (group) | ||
362 | GNUNET_CHAT_group_iterate_contacts( | ||
363 | group, | ||
364 | iterate_ui_chat_update_group_contacts, | ||
365 | handle->chat_contacts_listbox | ||
366 | ); | ||
367 | |||
368 | gtk_widget_set_visible( | ||
369 | GTK_WIDGET(handle->chat_details_contacts_box), | ||
370 | group? TRUE : FALSE | ||
371 | ); | ||
372 | |||
373 | const int status = GNUNET_CHAT_context_get_status(context); | ||
374 | const gboolean activated = (GNUNET_OK == status? TRUE : FALSE); | ||
375 | |||
376 | gtk_text_view_set_editable(handle->send_text_view, activated); | ||
377 | gtk_widget_set_sensitive(GTK_WIDGET(handle->send_text_view), activated); | ||
279 | 378 | ||
280 | gtk_widget_set_sensitive(GTK_WIDGET(handle->attach_file_button), TRUE); | 379 | gtk_widget_set_sensitive(GTK_WIDGET(handle->attach_file_button), activated); |
281 | gtk_widget_set_sensitive(GTK_WIDGET(handle->emoji_button), TRUE); | 380 | gtk_widget_set_sensitive(GTK_WIDGET(handle->emoji_button), activated); |
282 | gtk_widget_set_sensitive(GTK_WIDGET(handle->send_record_button), TRUE); | 381 | gtk_widget_set_sensitive(GTK_WIDGET(handle->send_record_button), activated); |
283 | } | 382 | } |
284 | 383 | ||
285 | void | 384 | void |