diff options
Diffstat (limited to 'src/event.c')
-rw-r--r-- | src/event.c | 74 |
1 files changed, 72 insertions, 2 deletions
diff --git a/src/event.c b/src/event.c index a99f13d..4540567 100644 --- a/src/event.c +++ b/src/event.c | |||
@@ -32,6 +32,44 @@ | |||
32 | #include "ui/profile_entry.h" | 32 | #include "ui/profile_entry.h" |
33 | 33 | ||
34 | static void | 34 | static void |
35 | _close_notification(NotifyNotification* notification, | ||
36 | UNUSED gpointer user_data) | ||
37 | { | ||
38 | notify_notification_clear_actions(notification); | ||
39 | notify_notification_clear_hints(notification); | ||
40 | |||
41 | g_object_unref(notification); | ||
42 | } | ||
43 | |||
44 | static void | ||
45 | _show_notification(UNUSED MESSENGER_Application *app, | ||
46 | UNUSED struct GNUNET_CHAT_Context *context, | ||
47 | const struct GNUNET_CHAT_Contact *contact, | ||
48 | const gchar *text, | ||
49 | const gchar *icon) | ||
50 | { | ||
51 | const char *sender = GNUNET_CHAT_contact_get_name(contact); | ||
52 | |||
53 | NotifyNotification *notification = notify_notification_new( | ||
54 | sender? sender : "(unknown)", text, icon | ||
55 | ); | ||
56 | |||
57 | if (0 == g_strcmp0(icon, "avatar-default-symbolic")) | ||
58 | notify_notification_set_category(notification, "presence.online"); | ||
59 | else | ||
60 | notify_notification_set_category(notification, "im.received"); | ||
61 | |||
62 | g_signal_connect( | ||
63 | notification, | ||
64 | "closed", | ||
65 | G_CALLBACK(_close_notification), | ||
66 | NULL | ||
67 | ); | ||
68 | |||
69 | notify_notification_show(notification, NULL); | ||
70 | } | ||
71 | |||
72 | static void | ||
35 | _add_new_chat_entry(MESSENGER_Application *app, | 73 | _add_new_chat_entry(MESSENGER_Application *app, |
36 | struct GNUNET_CHAT_Context *context) | 74 | struct GNUNET_CHAT_Context *context) |
37 | { | 75 | { |
@@ -205,7 +243,18 @@ event_joining_contact(MESSENGER_Application *app, | |||
205 | contact_add_name_avatar_to_info(contact, message->sender_avatar); | 243 | contact_add_name_avatar_to_info(contact, message->sender_avatar); |
206 | contact_add_name_label_to_info(contact, message->sender_label); | 244 | contact_add_name_label_to_info(contact, message->sender_label); |
207 | 245 | ||
208 | gtk_label_set_text(message->text_label, _("joined the chat")); | 246 | const gchar *join_message = _("joined the chat"); |
247 | |||
248 | if (!ui_messenger_is_context_active(&(app->ui.messenger), context)) | ||
249 | _show_notification( | ||
250 | app, | ||
251 | context, | ||
252 | contact, | ||
253 | join_message, | ||
254 | "avatar-default-symbolic" | ||
255 | ); | ||
256 | |||
257 | gtk_label_set_text(message->text_label, join_message); | ||
209 | 258 | ||
210 | gtk_container_add( | 259 | gtk_container_add( |
211 | GTK_CONTAINER(handle->chat->messages_listbox), | 260 | GTK_CONTAINER(handle->chat->messages_listbox), |
@@ -274,7 +323,18 @@ event_invitation(UNUSED MESSENGER_Application *app, | |||
274 | contact_add_name_avatar_to_info(contact, message->sender_avatar); | 323 | contact_add_name_avatar_to_info(contact, message->sender_avatar); |
275 | contact_add_name_label_to_info(contact, message->sender_label); | 324 | contact_add_name_label_to_info(contact, message->sender_label); |
276 | 325 | ||
277 | gtk_label_set_text(message->text_label, _("invited you to a chat")); | 326 | const gchar *invite_message = _("invited you to a chat"); |
327 | |||
328 | if (!ui_messenger_is_context_active(&(app->ui.messenger), context)) | ||
329 | _show_notification( | ||
330 | app, | ||
331 | context, | ||
332 | contact, | ||
333 | invite_message, | ||
334 | "mail-message-new-symbolic" | ||
335 | ); | ||
336 | |||
337 | gtk_label_set_text(message->text_label, invite_message); | ||
278 | 338 | ||
279 | g_signal_connect( | 339 | g_signal_connect( |
280 | message->accept_button, | 340 | message->accept_button, |
@@ -327,6 +387,16 @@ event_receive_message(UNUSED MESSENGER_Application *app, | |||
327 | const char *text = GNUNET_CHAT_message_get_text(msg); | 387 | const char *text = GNUNET_CHAT_message_get_text(msg); |
328 | const char *time = GNUNET_STRINGS_absolute_time_to_string(timestamp); | 388 | const char *time = GNUNET_STRINGS_absolute_time_to_string(timestamp); |
329 | 389 | ||
390 | if ((!ui_messenger_is_context_active(&(app->ui.messenger), context)) && | ||
391 | (GNUNET_YES != sent)) | ||
392 | _show_notification( | ||
393 | app, | ||
394 | context, | ||
395 | contact, | ||
396 | text, | ||
397 | "mail-unread-symbolic" | ||
398 | ); | ||
399 | |||
330 | gtk_label_set_text(message->text_label, text? text : ""); | 400 | gtk_label_set_text(message->text_label, text? text : ""); |
331 | gtk_label_set_text(message->timestamp_label, time? time : ""); | 401 | gtk_label_set_text(message->timestamp_label, time? time : ""); |
332 | 402 | ||