Commit 052337b5 authored by Andrea Schaefer's avatar Andrea Schaefer

Show user icons in message notifications

parent 65913a05
......@@ -177,7 +177,7 @@ chatty_connection_connected (PurpleConnection *gc)
message = g_strdup_printf ("Account %s reconnected", user_name);
if (!sms_match || (sms_match && sms_notifications)) {
chatty_notify_show_notification (NULL, message, CHATTY_NOTIFY_ACCOUNT_CONNECTED, NULL);
chatty_notify_show_notification (NULL, message, CHATTY_NOTIFY_ACCOUNT_CONNECTED, NULL, NULL);
}
g_free (message);
......@@ -307,7 +307,7 @@ chatty_connection_report_disconnect_reason (PurpleConnection *gc,
// in the 'cb_sms_modem_added' callback
if (sms_notifications) {
message = g_strdup_printf ("SMS disconnected: %s", text);
chatty_notify_show_notification (user_name, message, CHATTY_NOTIFY_ACCOUNT_GENERIC, NULL);
chatty_notify_show_notification (user_name, message, CHATTY_NOTIFY_ACCOUNT_GENERIC, NULL, NULL);
g_free (message);
}
......@@ -350,7 +350,7 @@ chatty_connection_report_disconnect_reason (PurpleConnection *gc,
chatty_dialogs_update_connection_status ();
message = g_strdup_printf ("Account %s disconnected: %s", user_name, text);
chatty_notify_show_notification (NULL, message, CHATTY_NOTIFY_ACCOUNT_DISCONNECTED, NULL);
chatty_notify_show_notification (NULL, message, CHATTY_NOTIFY_ACCOUNT_DISCONNECTED, NULL, NULL);
g_free (message);
}
......
......@@ -11,6 +11,7 @@
#include "chatty-window.h"
#include "chatty-icons.h"
#include "chatty-lurch.h"
#include "chatty-buddy-list.h"
#include "chatty-purple-init.h"
#include "chatty-message-list.h"
#include "chatty-conversation.h"
......@@ -2200,7 +2201,16 @@ chatty_conv_write_conversation (PurpleConversation *conv,
titel = g_strdup_printf (_("New message from %s"), buddy_name);
chatty_notify_show_notification (titel, message, CHATTY_NOTIFY_MESSAGE_RECEIVED, conv);
avatar = chatty_icon_get_buddy_icon ((PurpleBlistNode*)buddy,
alias,
CHATTY_ICON_SIZE_SMALL,
chatty_blist_protocol_is_sms (account) ?
CHATTY_COLOR_GREEN : CHATTY_COLOR_BLUE,
FALSE);
chatty_notify_show_notification (titel, message, CHATTY_NOTIFY_MESSAGE_RECEIVED, conv, avatar);
g_object_unref (avatar);
g_free (titel);
}
......
......@@ -379,3 +379,31 @@ chatty_icon_do_alphashift (GdkPixbuf *pixbuf,
pixels += padding;
}
}
GIcon *
chatty_icon_get_gicon_from_pixbuf (GdkPixbuf *pixbuf)
{
GIcon *icon;
GBytes *bytes;
gchar *buffer;
gsize size;
g_autoptr(GError) error = NULL;
gdk_pixbuf_save_to_buffer (pixbuf, &buffer, &size, "png", &error, NULL);
if (error != NULL) {
g_error ("%s Could not save pixbuf to buffer: %s", __func__, error->message);
return NULL;
}
bytes = g_bytes_new (buffer, size);
icon = g_bytes_icon_new (bytes);
g_free (buffer);
g_bytes_unref (bytes);
return icon;
}
......@@ -27,6 +27,7 @@ typedef enum
void chatty_icon_do_alphashift (GdkPixbuf *pixbuf, int shift);
GdkPixbuf *chatty_icon_shape_pixbuf (GdkPixbuf *pixbuf);
GIcon *chatty_icon_get_gicon_from_pixbuf (GdkPixbuf *pixbuf);
GdkPixbuf *chatty_icon_get_buddy_icon (PurpleBlistNode *node,
const char *name,
......
......@@ -11,6 +11,7 @@
#include "purple.h"
#include "chatty-window.h"
#include "chatty-notify.h"
#include "chatty-icons.h"
#include "chatty-conversation.h"
static PurpleConversation *conv_notify = NULL;
......@@ -45,7 +46,8 @@ void
chatty_notify_show_notification (const char *title,
const char *message,
guint notification_type,
PurpleConversation *conv)
PurpleConversation *conv,
GdkPixbuf *pixbuf)
{
GApplication *application;
GNotification *notification;
......@@ -59,14 +61,14 @@ chatty_notify_show_notification (const char *title,
notification = g_notification_new ("chatty");
g_notification_set_body (notification, message);
icon = g_icon_new_for_string ("sm.puri.Chatty-symbolic", NULL);
if (pixbuf) {
icon = chatty_icon_get_gicon_from_pixbuf (pixbuf);
if (icon) {
g_notification_set_icon (notification, icon);
}
g_notification_set_body (notification, message);
switch (notification_type) {
case CHATTY_NOTIFY_MESSAGE_RECEIVED:
g_notification_add_button (notification,
......
......@@ -22,6 +22,7 @@ enum {
void chatty_notify_show_notification (const char *title,
const char *message,
guint notification_type,
PurpleConversation *conv);
PurpleConversation *conv,
GdkPixbuf *pixbuf);
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment