diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2021-12-22 00:13:00 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2021-12-22 00:13:00 +0100 |
commit | beaa1080606c0ce173cd61afd0b6ac25ffd94116 (patch) | |
tree | 968a01dd1ea139811d3a0122af38782f0c5a1816 | |
parent | 412c7d4f210096c7cde549c48e3e2a2262724d00 (diff) | |
download | messenger-gtk-beaa1080606c0ce173cd61afd0b6ac25ffd94116.tar.gz messenger-gtk-beaa1080606c0ce173cd61afd0b6ac25ffd94116.zip |
Added notifications in case of lost focus
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | src/contact.c | 3 | ||||
-rw-r--r-- | src/contact.h | 1 | ||||
-rw-r--r-- | src/event.c | 74 | ||||
-rw-r--r-- | src/ui/message.c | 7 | ||||
-rw-r--r-- | src/ui/messenger.c | 19 | ||||
-rw-r--r-- | src/ui/messenger.h | 6 |
6 files changed, 107 insertions, 3 deletions
diff --git a/src/contact.c b/src/contact.c index e87e87b..e1ae097 100644 --- a/src/contact.c +++ b/src/contact.c | |||
@@ -52,6 +52,9 @@ contact_destroy_info(struct GNUNET_CHAT_Contact *contact) | |||
52 | if (info->name_avatars) | 52 | if (info->name_avatars) |
53 | g_list_free(info->name_avatars); | 53 | g_list_free(info->name_avatars); |
54 | 54 | ||
55 | if (info->name_notifications) | ||
56 | g_list_free(info->name_notifications); | ||
57 | |||
55 | g_free(info); | 58 | g_free(info); |
56 | 59 | ||
57 | GNUNET_CHAT_contact_set_user_pointer(contact, NULL); | 60 | GNUNET_CHAT_contact_set_user_pointer(contact, NULL); |
diff --git a/src/contact.h b/src/contact.h index 15c7c9f..4ff1d7e 100644 --- a/src/contact.h +++ b/src/contact.h | |||
@@ -31,6 +31,7 @@ typedef struct MESSENGER_ContactInfo | |||
31 | { | 31 | { |
32 | GList *name_labels; | 32 | GList *name_labels; |
33 | GList *name_avatars; | 33 | GList *name_avatars; |
34 | GList *name_notifications; | ||
34 | } MESSENGER_ContactInfo; | 35 | } MESSENGER_ContactInfo; |
35 | 36 | ||
36 | void | 37 | void |
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 | ||
diff --git a/src/ui/message.c b/src/ui/message.c index 6f379d7..cd8be30 100644 --- a/src/ui/message.c +++ b/src/ui/message.c | |||
@@ -174,7 +174,12 @@ ui_message_update(UI_MESSAGE_Handle *handle, | |||
174 | if (!file) | 174 | if (!file) |
175 | return; | 175 | return; |
176 | 176 | ||
177 | // TODO | 177 | gtk_stack_set_visible_child( |
178 | handle->content_stack, | ||
179 | GTK_WIDGET(handle->file_revealer) | ||
180 | ); | ||
181 | |||
182 | gtk_revealer_set_reveal_child(handle->file_revealer, TRUE); | ||
178 | } | 183 | } |
179 | 184 | ||
180 | void | 185 | void |
diff --git a/src/ui/messenger.c b/src/ui/messenger.c index afa444b..0db82a0 100644 --- a/src/ui/messenger.c +++ b/src/ui/messenger.c | |||
@@ -396,6 +396,25 @@ ui_messenger_init(MESSENGER_Application *app, | |||
396 | ); | 396 | ); |
397 | } | 397 | } |
398 | 398 | ||
399 | gboolean | ||
400 | ui_messenger_is_context_active(UI_MESSENGER_Handle *handle, | ||
401 | struct GNUNET_CHAT_Context *context) | ||
402 | { | ||
403 | if (!gtk_window_is_active(GTK_WINDOW(handle->main_window))) | ||
404 | return FALSE; | ||
405 | |||
406 | UI_CHAT_ENTRY_Handle *entry = GNUNET_CHAT_context_get_user_pointer(context); | ||
407 | |||
408 | if (!entry) | ||
409 | return FALSE; | ||
410 | |||
411 | GtkListBoxRow *row = GTK_LIST_BOX_ROW( | ||
412 | gtk_widget_get_parent(entry->entry_box) | ||
413 | ); | ||
414 | |||
415 | return gtk_list_box_row_is_selected(row); | ||
416 | } | ||
417 | |||
399 | void | 418 | void |
400 | ui_messenger_cleanup(UI_MESSENGER_Handle *handle) | 419 | ui_messenger_cleanup(UI_MESSENGER_Handle *handle) |
401 | { | 420 | { |
diff --git a/src/ui/messenger.h b/src/ui/messenger.h index 44deb3c..e16487b 100644 --- a/src/ui/messenger.h +++ b/src/ui/messenger.h | |||
@@ -29,6 +29,8 @@ | |||
29 | #include <libhandy-1/handy.h> | 29 | #include <libhandy-1/handy.h> |
30 | #include <libnotify/notify.h> | 30 | #include <libnotify/notify.h> |
31 | 31 | ||
32 | #include <gnunet/gnunet_chat_lib.h> | ||
33 | |||
32 | typedef struct MESSENGER_Application MESSENGER_Application; | 34 | typedef struct MESSENGER_Application MESSENGER_Application; |
33 | 35 | ||
34 | typedef struct UI_MESSENGER_Handle | 36 | typedef struct UI_MESSENGER_Handle |
@@ -73,6 +75,10 @@ void | |||
73 | ui_messenger_init(MESSENGER_Application *app, | 75 | ui_messenger_init(MESSENGER_Application *app, |
74 | UI_MESSENGER_Handle *handle); | 76 | UI_MESSENGER_Handle *handle); |
75 | 77 | ||
78 | gboolean | ||
79 | ui_messenger_is_context_active(UI_MESSENGER_Handle *handle, | ||
80 | struct GNUNET_CHAT_Context *context); | ||
81 | |||
76 | void | 82 | void |
77 | ui_messenger_cleanup(UI_MESSENGER_Handle *handle); | 83 | ui_messenger_cleanup(UI_MESSENGER_Handle *handle); |
78 | 84 | ||