commit beaa1080606c0ce173cd61afd0b6ac25ffd94116
parent 412c7d4f210096c7cde549c48e3e2a2262724d00
Author: TheJackiMonster <thejackimonster@gmail.com>
Date: Wed, 22 Dec 2021 00:13:00 +0100
Added notifications in case of lost focus
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat:
6 files changed, 107 insertions(+), 3 deletions(-)
diff --git a/src/contact.c b/src/contact.c
@@ -52,6 +52,9 @@ contact_destroy_info(struct GNUNET_CHAT_Contact *contact)
if (info->name_avatars)
g_list_free(info->name_avatars);
+ if (info->name_notifications)
+ g_list_free(info->name_notifications);
+
g_free(info);
GNUNET_CHAT_contact_set_user_pointer(contact, NULL);
diff --git a/src/contact.h b/src/contact.h
@@ -31,6 +31,7 @@ typedef struct MESSENGER_ContactInfo
{
GList *name_labels;
GList *name_avatars;
+ GList *name_notifications;
} MESSENGER_ContactInfo;
void
diff --git a/src/event.c b/src/event.c
@@ -32,6 +32,44 @@
#include "ui/profile_entry.h"
static void
+_close_notification(NotifyNotification* notification,
+ UNUSED gpointer user_data)
+{
+ notify_notification_clear_actions(notification);
+ notify_notification_clear_hints(notification);
+
+ g_object_unref(notification);
+}
+
+static void
+_show_notification(UNUSED MESSENGER_Application *app,
+ UNUSED struct GNUNET_CHAT_Context *context,
+ const struct GNUNET_CHAT_Contact *contact,
+ const gchar *text,
+ const gchar *icon)
+{
+ const char *sender = GNUNET_CHAT_contact_get_name(contact);
+
+ NotifyNotification *notification = notify_notification_new(
+ sender? sender : "(unknown)", text, icon
+ );
+
+ if (0 == g_strcmp0(icon, "avatar-default-symbolic"))
+ notify_notification_set_category(notification, "presence.online");
+ else
+ notify_notification_set_category(notification, "im.received");
+
+ g_signal_connect(
+ notification,
+ "closed",
+ G_CALLBACK(_close_notification),
+ NULL
+ );
+
+ notify_notification_show(notification, NULL);
+}
+
+static void
_add_new_chat_entry(MESSENGER_Application *app,
struct GNUNET_CHAT_Context *context)
{
@@ -205,7 +243,18 @@ event_joining_contact(MESSENGER_Application *app,
contact_add_name_avatar_to_info(contact, message->sender_avatar);
contact_add_name_label_to_info(contact, message->sender_label);
- gtk_label_set_text(message->text_label, _("joined the chat"));
+ const gchar *join_message = _("joined the chat");
+
+ if (!ui_messenger_is_context_active(&(app->ui.messenger), context))
+ _show_notification(
+ app,
+ context,
+ contact,
+ join_message,
+ "avatar-default-symbolic"
+ );
+
+ gtk_label_set_text(message->text_label, join_message);
gtk_container_add(
GTK_CONTAINER(handle->chat->messages_listbox),
@@ -274,7 +323,18 @@ event_invitation(UNUSED MESSENGER_Application *app,
contact_add_name_avatar_to_info(contact, message->sender_avatar);
contact_add_name_label_to_info(contact, message->sender_label);
- gtk_label_set_text(message->text_label, _("invited you to a chat"));
+ const gchar *invite_message = _("invited you to a chat");
+
+ if (!ui_messenger_is_context_active(&(app->ui.messenger), context))
+ _show_notification(
+ app,
+ context,
+ contact,
+ invite_message,
+ "mail-message-new-symbolic"
+ );
+
+ gtk_label_set_text(message->text_label, invite_message);
g_signal_connect(
message->accept_button,
@@ -327,6 +387,16 @@ event_receive_message(UNUSED MESSENGER_Application *app,
const char *text = GNUNET_CHAT_message_get_text(msg);
const char *time = GNUNET_STRINGS_absolute_time_to_string(timestamp);
+ if ((!ui_messenger_is_context_active(&(app->ui.messenger), context)) &&
+ (GNUNET_YES != sent))
+ _show_notification(
+ app,
+ context,
+ contact,
+ text,
+ "mail-unread-symbolic"
+ );
+
gtk_label_set_text(message->text_label, text? text : "");
gtk_label_set_text(message->timestamp_label, time? time : "");
diff --git a/src/ui/message.c b/src/ui/message.c
@@ -174,7 +174,12 @@ ui_message_update(UI_MESSAGE_Handle *handle,
if (!file)
return;
- // TODO
+ gtk_stack_set_visible_child(
+ handle->content_stack,
+ GTK_WIDGET(handle->file_revealer)
+ );
+
+ gtk_revealer_set_reveal_child(handle->file_revealer, TRUE);
}
void
diff --git a/src/ui/messenger.c b/src/ui/messenger.c
@@ -396,6 +396,25 @@ ui_messenger_init(MESSENGER_Application *app,
);
}
+gboolean
+ui_messenger_is_context_active(UI_MESSENGER_Handle *handle,
+ struct GNUNET_CHAT_Context *context)
+{
+ if (!gtk_window_is_active(GTK_WINDOW(handle->main_window)))
+ return FALSE;
+
+ UI_CHAT_ENTRY_Handle *entry = GNUNET_CHAT_context_get_user_pointer(context);
+
+ if (!entry)
+ return FALSE;
+
+ GtkListBoxRow *row = GTK_LIST_BOX_ROW(
+ gtk_widget_get_parent(entry->entry_box)
+ );
+
+ return gtk_list_box_row_is_selected(row);
+}
+
void
ui_messenger_cleanup(UI_MESSENGER_Handle *handle)
{
diff --git a/src/ui/messenger.h b/src/ui/messenger.h
@@ -29,6 +29,8 @@
#include <libhandy-1/handy.h>
#include <libnotify/notify.h>
+#include <gnunet/gnunet_chat_lib.h>
+
typedef struct MESSENGER_Application MESSENGER_Application;
typedef struct UI_MESSENGER_Handle
@@ -73,6 +75,10 @@ void
ui_messenger_init(MESSENGER_Application *app,
UI_MESSENGER_Handle *handle);
+gboolean
+ui_messenger_is_context_active(UI_MESSENGER_Handle *handle,
+ struct GNUNET_CHAT_Context *context);
+
void
ui_messenger_cleanup(UI_MESSENGER_Handle *handle);