[Xfce4-commits] [apps/xfce4-notifyd] 01/02: Implement image-data support for the log
noreply at xfce.org
noreply at xfce.org
Sun Aug 27 00:46:04 CEST 2017
This is an automated email from the git hooks/post-receive script.
o c h o s i p u s h e d a c o m m i t t o b r a n c h m a s t e r
in repository apps/xfce4-notifyd.
commit fa4861e10400756d56e2dbca443c2602956819e6
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date: Sun Aug 27 00:43:57 2017 +0200
Implement image-data support for the log
So far all notifications that sent pixbufs in the
image-data hint were saved without icon.
The current implementation hashes every pixbuf and
uses the md5sum as filename to avoid saving the same
icon twice.
---
xfce4-notifyd-config/main.c | 19 ++++++++-
xfce4-notifyd/xfce-notify-daemon.c | 60 ++++------------------------
xfce4-notifyd/xfce-notify-log.c | 80 +++++++++++++++++++++++++++++++++++++-
xfce4-notifyd/xfce-notify-log.h | 27 ++++++++-----
4 files changed, 121 insertions(+), 65 deletions(-)
diff --git a/xfce4-notifyd-config/main.c b/xfce4-notifyd-config/main.c
index 373f77c..1f41e70 100644
--- a/xfce4-notifyd-config/main.c
+++ b/xfce4-notifyd-config/main.c
@@ -500,12 +500,17 @@ xfce4_notifyd_log_populate (NotificationLogWidgets *log_widgets)
gchar *limit_label;
GtkWidget *limit_button;
gsize num_groups = 0;
+ GdkPixbuf *pixbuf = NULL;
+ gchar *notify_log_icon_folder;
+ gchar *notify_log_icon_path;
today = g_date_time_new_now_local ();
timestamp = g_date_time_format (today, "%F");
gtk_container_foreach (GTK_CONTAINER (log_listbox), func, log_listbox);
notify_log = xfce_notify_log_get();
+ notify_log_icon_folder = xfce_resource_save_location (XFCE_RESOURCE_CACHE,
+ XFCE_NOTIFY_ICON_PATH, TRUE);
if (notify_log) {
gchar **groups;
@@ -571,9 +576,19 @@ xfce4_notifyd_log_populate (NotificationLogWidgets *log_widgets)
#endif
gtk_label_set_ellipsize (GTK_LABEL (body), PANGO_ELLIPSIZE_END);
tmp = g_key_file_get_string (notify_log, group, "app_icon", NULL);
- app_icon = gtk_image_new_from_icon_name (tmp, GTK_ICON_SIZE_LARGE_TOOLBAR);
+ notify_log_icon_path = g_strconcat (notify_log_icon_folder , tmp, ".png", NULL);
+ if (g_file_test (notify_log_icon_path, G_FILE_TEST_EXISTS))
+ {
+ pixbuf = gdk_pixbuf_new_from_file_at_scale (notify_log_icon_path,
+ 24, 24, FALSE, NULL);
+ app_icon = gtk_image_new_from_pixbuf (pixbuf);
+ }
+ else
+ {
+ app_icon = gtk_image_new_from_icon_name (tmp, GTK_ICON_SIZE_LARGE_TOOLBAR);
+ gtk_image_set_pixel_size (GTK_IMAGE (app_icon), 24);
+ }
g_free (tmp);
- gtk_image_set_pixel_size (GTK_IMAGE (app_icon), 24);
gtk_widget_set_margin_start (app_icon, 3);
tmp = g_key_file_get_string (notify_log, group, "expire-timeout", NULL);
expire_timeout = gtk_label_new (tmp);
diff --git a/xfce4-notifyd/xfce-notify-daemon.c b/xfce4-notifyd/xfce-notify-daemon.c
index 1001e80..0d67431 100644
--- a/xfce4-notifyd/xfce-notify-daemon.c
+++ b/xfce4-notifyd/xfce-notify-daemon.c
@@ -117,8 +117,6 @@ static void xfce_notify_daemon_get_workarea(GdkScreen *screen,
GdkRectangle *rect);
static void daemon_quit (XfceNotifyDaemon *xndaemon);
-static GdkPixbuf *notify_pixbuf_from_image_data(GVariant *image_data);
-
/* DBus method callbacks forward declarations */
static gboolean notify_get_capabilities (XfceNotifyGBus *skeleton,
GDBusMethodInvocation *invocation,
@@ -1165,6 +1163,8 @@ notify_notify (XfceNotifyGBus *skeleton,
transient = TRUE;
else if (g_strcmp0 (key, "x-canonical-private-icon-only") == 0)
x_canonical = TRUE;
+ else if (g_strcmp0 (key, "urgency") == 0)
+ g_warning ("the urgency bit is set");
g_variant_unref (item);
}
@@ -1198,7 +1198,9 @@ notify_notify (XfceNotifyGBus *skeleton,
if (xndaemon->log_level_apps == 0 ||
xndaemon->log_level_apps == 1 && application_is_muted == FALSE ||
xndaemon->log_level_apps == 2 && application_is_muted == TRUE)
- xfce_notify_log_insert (new_app_name, summary, body, app_icon, expire_timeout, actions);
+ xfce_notify_log_insert (new_app_name, summary, body,
+ image_data, image_path, app_icon,
+ expire_timeout, actions);
}
xfce_notify_gbus_complete_notify(skeleton, invocation, OUT_id);
@@ -1294,14 +1296,13 @@ notify_notify (XfceNotifyGBus *skeleton,
}
}
- // for a complete notification we need:
- // app_name, summary, body, app_icon, expire_timeout, actions
- // TODO: icons need to be handled, app_icon is bad - what shall be done with image_data??
if (xndaemon->notification_log == TRUE &&
xndaemon->log_level == 1 &&
xndaemon->log_level_apps <= 1 &&
transient == FALSE)
- xfce_notify_log_insert (new_app_name, summary, body, app_icon, expire_timeout, actions);
+ xfce_notify_log_insert (new_app_name, summary, body,
+ image_data, image_path, app_icon,
+ expire_timeout, actions);
xfce_notify_window_set_icon_only(window, x_canonical);
@@ -1369,51 +1370,6 @@ static gboolean notify_quit (XfceNotifyOrgXfceNotifyd *skeleton,
}
-static GdkPixbuf *
-notify_pixbuf_from_image_data(GVariant *image_data)
-{
- GdkPixbuf *pix = NULL;
- gint32 width, height, rowstride, bits_per_sample, channels;
- gboolean has_alpha;
- GVariant *pixel_data;
- gsize correct_len;
- guchar *data;
-
- if (!g_variant_is_of_type (image_data, G_VARIANT_TYPE ("(iiibiiay)")))
- {
- g_warning ("Image data is not the correct type");
- return NULL;
- }
-
- g_variant_get (image_data,
- "(iiibii at ay)",
- &width,
- &height,
- &rowstride,
- &has_alpha,
- &bits_per_sample,
- &channels,
- &pixel_data);
-
- correct_len = (height - 1) * rowstride + width
- * ((channels * bits_per_sample + 7) / 8);
- if(correct_len != g_variant_get_size (pixel_data)) {
- g_message ("Pixel data length (%lu) did not match expected value (%u)",
- g_variant_get_size (pixel_data), (guint)correct_len);
- return NULL;
- }
-
- data = (guchar *) g_memdup (g_variant_get_data (pixel_data),
- g_variant_get_size (pixel_data));
-
- pix = gdk_pixbuf_new_from_data(data,
- GDK_COLORSPACE_RGB, has_alpha,
- bits_per_sample, width, height,
- rowstride,
- (GdkPixbufDestroyNotify)g_free, NULL);
- return pix;
-}
-
static void
xfce_notify_daemon_set_theme(XfceNotifyDaemon *xndaemon,
const gchar *theme)
diff --git a/xfce4-notifyd/xfce-notify-log.c b/xfce4-notifyd/xfce-notify-log.c
index c20f903..5b756f2 100644
--- a/xfce4-notifyd/xfce-notify-log.c
+++ b/xfce4-notifyd/xfce-notify-log.c
@@ -31,10 +31,57 @@
#include <libxfce4util/libxfce4util.h>
+#include <gdk/gdkx.h>
#include <glib.h>
+#include "xfce-notify-daemon.h"
#include "xfce-notify-log.h"
+GdkPixbuf *
+notify_pixbuf_from_image_data(GVariant *image_data)
+{
+ GdkPixbuf *pix = NULL;
+ gint32 width, height, rowstride, bits_per_sample, channels;
+ gboolean has_alpha;
+ GVariant *pixel_data;
+ gsize correct_len;
+ guchar *data;
+
+ if (!g_variant_is_of_type (image_data, G_VARIANT_TYPE ("(iiibiiay)")))
+ {
+ g_warning ("Image data is not the correct type");
+ return NULL;
+ }
+
+ g_variant_get (image_data,
+ "(iiibii at ay)",
+ &width,
+ &height,
+ &rowstride,
+ &has_alpha,
+ &bits_per_sample,
+ &channels,
+ &pixel_data);
+
+ correct_len = (height - 1) * rowstride + width
+ * ((channels * bits_per_sample + 7) / 8);
+ if(correct_len != g_variant_get_size (pixel_data)) {
+ g_message ("Pixel data length (%lu) did not match expected value (%u)",
+ g_variant_get_size (pixel_data), (guint)correct_len);
+ return NULL;
+ }
+
+ data = (guchar *) g_memdup (g_variant_get_data (pixel_data),
+ g_variant_get_size (pixel_data));
+
+ pix = gdk_pixbuf_new_from_data(data,
+ GDK_COLORSPACE_RGB, has_alpha,
+ bits_per_sample, width, height,
+ rowstride,
+ (GdkPixbufDestroyNotify)g_free, NULL);
+ return pix;
+}
+
GKeyFile *
xfce_notify_log_get (void)
{
@@ -59,6 +106,8 @@ xfce_notify_log_get (void)
void xfce_notify_log_insert (const gchar *app_name,
const gchar *summary,
const gchar *body,
+ GVariant *image_data,
+ const gchar *image_path,
const gchar *app_icon,
gint expire_timeout,
const gchar **actions)
@@ -72,6 +121,11 @@ void xfce_notify_log_insert (const gchar *app_name,
gint j = 0;
GDateTime *now;
gchar *timestamp;
+ GBytes *image_bytes;
+ const gchar *icon_name;
+ GdkPixbuf *pixbuf = NULL;
+ gchar *notify_log_icon_folder;
+ gchar *notify_log_icon_path;
notify_log_path = xfce_resource_save_location (XFCE_RESOURCE_CACHE,
XFCE_NOTIFY_LOG_FILE, TRUE);
@@ -91,7 +145,31 @@ void xfce_notify_log_insert (const gchar *app_name,
g_key_file_set_string (notify_log, group, "app_name", app_name);
g_key_file_set_string (notify_log, group, "summary", summary);
g_key_file_set_string (notify_log, group, "body", body);
- g_key_file_set_string (notify_log, group, "app_icon", app_icon);
+ if (image_data) {
+ image_bytes = g_variant_get_data_as_bytes (image_data);
+ icon_name = g_compute_checksum_for_bytes (G_CHECKSUM_MD5, image_bytes);
+ pixbuf = notify_pixbuf_from_image_data (image_data);
+ if (pixbuf) {
+ notify_log_icon_folder = xfce_resource_save_location (XFCE_RESOURCE_CACHE,
+ XFCE_NOTIFY_ICON_PATH, TRUE);
+ notify_log_icon_path = g_strconcat (notify_log_icon_folder , icon_name, ".png", NULL);
+ if (!g_file_test (notify_log_icon_path, G_FILE_TEST_EXISTS)) {
+ if (!gdk_pixbuf_save (pixbuf, notify_log_icon_path, "png", NULL, NULL))
+ g_warning ("Could not save the pixbuf to: %s", notify_log_icon_path);
+ }
+ g_object_unref (G_OBJECT (pixbuf));
+ }
+ }
+ else if (image_path) {
+ icon_name = image_path;
+ }
+ else if (app_icon && (g_strcmp0 (app_icon, "") != 0)) {
+ icon_name = app_icon;
+ }
+// else
+// g_warning ("everything failed. :'(");
+
+ g_key_file_set_string (notify_log, group, "app_icon", icon_name);
timeout = g_strdup_printf ("%d", expire_timeout);
g_key_file_set_string (notify_log, group, "expire-timeout", timeout);
for (i = 0; actions && actions[i]; i += 2) {
diff --git a/xfce4-notifyd/xfce-notify-log.h b/xfce4-notifyd/xfce-notify-log.h
index 3f9729e..07595ed 100644
--- a/xfce4-notifyd/xfce-notify-log.h
+++ b/xfce4-notifyd/xfce-notify-log.h
@@ -21,15 +21,22 @@
#define __XFCE_NOTIFY_LOG_H_
-#define XFCE_NOTIFY_LOG_FILE "xfce4/notifyd/log"
-
-GKeyFile *xfce_notify_log_get (void);
-void xfce_notify_log_insert (const gchar *app_name,
- const gchar *summary,
- const gchar *body,
- const gchar *app_icon,
- gint expire_timeout,
- const gchar **actions);
-void xfce_notify_log_clear (void);
+#define XFCE_NOTIFY_LOG_FILE "xfce4/notifyd/log"
+#define XFCE_NOTIFY_ICON_PATH "xfce4/notifyd/icons/"
+
+GdkPixbuf *notify_pixbuf_from_image_data(GVariant *image_data);
+
+GKeyFile *xfce_notify_log_get (void);
+
+void xfce_notify_log_insert (const gchar *app_name,
+ const gchar *summary,
+ const gchar *body,
+ GVariant *image_data,
+ const gchar *image_path,
+ const gchar *app_icon,
+ gint expire_timeout,
+ const gchar **actions);
+
+void xfce_notify_log_clear (void);
#endif /* __XFCE_NOTIFY_LOG_H_ */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list