From 3e05834b4c23a5d5951403719b8594ff3d9fe30b Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Mon, 13 Sep 2004 07:51:51 +0000 Subject: Add new notification icon. Update for new files. Restructure code a little 2004-09-13 Glynn Foster * data/Makefile.am, data/zenity-notification.png: Add new notification icon. * src/Makefile.am: Update for new files. * src/about.c, src/calendar.c, src/entry.c, src/fileselection.c, src/progress.c, src/text.c, src/tree.c, src/msg.c: Restructure code a little bit for new utility functions for setting window icons. * src/eggtrayicon.c, src/eggtrayicon.h: New files for notification area support. * src/main.c, src/notification.c, src/util.c, src/util.h, src/zenity.h: Add support for notification area. * data/zenity.1, help/*: Update docs for notification and new file selection changes. --- src/notification.c | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 src/notification.c (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c new file mode 100644 index 00000000..42f72c5b --- /dev/null +++ b/src/notification.c @@ -0,0 +1,129 @@ +/* + * notification.c + * + * Copyright (C) 2002 Sun Microsystems, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Authors: Glynn Foster + */ + +#include +#include +#include "zenity.h" +#include "eggtrayicon.h" +#include "util.h" + +EggTrayIcon *tray_icon; + +static gboolean +zenity_notification_icon_press_callback (GtkWidget *widget, GdkEventButton *event, gpointer data) +{ + ZenityData *zen_data; + + zen_data = data; + + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); + gtk_main_quit (); +} + +static gboolean +zenity_notification_icon_expose_callback (GtkWidget *widget, GdkEventExpose *event, gpointer data) +{ + if (GTK_WIDGET_HAS_FOCUS (widget)) { + gint focus_width, focus_pad; + gint x, y, width, height; + + gtk_widget_style_get (widget, + "focus-line-width", &focus_width, + "focus-padding", &focus_pad, + NULL); + x = widget->allocation.x + focus_pad; + y = widget->allocation.y + focus_pad; + width = widget->allocation.width - 2 * focus_pad; + height = widget->allocation.height - 2 * focus_pad; + + gtk_paint_focus (widget->style, widget->window, + GTK_WIDGET_STATE (widget), + &event->area, widget, "button", + x, y, width, height); + } + + return FALSE; +} + +static gboolean +zenity_notification_icon_destroy_callback (GtkWidget *widget, gpointer data) +{ + ZenityData *zen_data; + + zen_data = data; + gtk_widget_destroy (GTK_WIDGET (tray_icon)); + + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); + gtk_main_quit (); +} + +void +zenity_notification (ZenityData *data, ZenityNotificationData *notification_data) +{ + GtkWidget *icon_image; + GtkWidget *icon_event_box; + GtkTooltips *tooltips; + GdkPixbuf *pixbuf = NULL; + + tray_icon = egg_tray_icon_new (_("Zenity notification")); + tooltips = gtk_tooltips_new (); + + if (data->window_icon != NULL) + pixbuf = zenity_util_pixbuf_new_from_file (GTK_WIDGET (tray_icon), data->window_icon); + else + pixbuf = gdk_pixbuf_new_from_file (ZENITY_IMAGE_FULLPATH ("zenity-notification.png"), NULL); + + icon_event_box = gtk_event_box_new (); + + if (pixbuf) { + icon_image = gtk_image_new_from_pixbuf (pixbuf); + gdk_pixbuf_unref (pixbuf); + } else { + g_warning ("Could not load notification icon : %s", ZENITY_IMAGE_FULLPATH ("zenity-notification.png")); + return; + } + + gtk_container_add (GTK_CONTAINER (icon_event_box), icon_image); + + if (notification_data->notification_text) + gtk_tooltips_set_tip (tooltips, icon_event_box, notification_data->notification_text, notification_data->notification_text); + else + gtk_tooltips_set_tip (tooltips, icon_event_box, _("Zenity notification"), _("Zenity notification")); + + gtk_widget_add_events (GTK_WIDGET (tray_icon), GDK_BUTTON_PRESS_MASK | GDK_FOCUS_CHANGE_MASK); + gtk_container_add (GTK_CONTAINER (tray_icon), icon_event_box); + + g_signal_connect (tray_icon, "button_press_event", + G_CALLBACK (zenity_notification_icon_press_callback), data); + + g_signal_connect (tray_icon, "destroy", + G_CALLBACK (zenity_notification_icon_destroy_callback), data); + + g_signal_connect (tray_icon, "expose_event", + G_CALLBACK (zenity_notification_icon_expose_callback), data); + + gtk_widget_show_all (GTK_WIDGET (tray_icon)); + + /* Does nothing at the moment */ + gtk_main (); +} -- cgit From 963241dd15b3046e97e526b1547fdd3543b18b14 Mon Sep 17 00:00:00 2001 From: James Henstridge Date: Thu, 16 Sep 2004 09:28:09 +0000 Subject: add code to listen for commands on stdin when in listen mode. 2004-09-16 James Henstridge * src/notification.c: add code to listen for commands on stdin when in listen mode. * src/main.c: parse the --listen argument for --notification mode. * src/zenity.h (ZenityNotificationData): add a field for the "listen" argument. --- src/notification.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 116 insertions(+), 7 deletions(-) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index 42f72c5b..f3b3b1f9 100644 --- a/src/notification.c +++ b/src/notification.c @@ -27,7 +27,11 @@ #include "eggtrayicon.h" #include "util.h" -EggTrayIcon *tray_icon; +static EggTrayIcon *tray_icon; +static GtkWidget *icon_image; +static GtkWidget *icon_event_box; +static GtkTooltips *tooltips; + static gboolean zenity_notification_icon_press_callback (GtkWidget *widget, GdkEventButton *event, gpointer data) @@ -77,12 +81,112 @@ zenity_notification_icon_destroy_callback (GtkWidget *widget, gpointer data) gtk_main_quit (); } +static gboolean +zenity_notification_handle_stdin (GIOChannel *channel, + GIOCondition condition, + gpointer user_data) +{ + ZenityData *zen_data; + + zen_data = (ZenityData *)user_data; + + if ((condition & G_IO_IN) != 0) { + GString *string; + GError *error = NULL; + + string = g_string_new (NULL); + while (channel->is_readable != TRUE) + ; + do { + gint status; + gchar *command, *value, *colon; + + do { + status = g_io_channel_read_line_string (channel, string, NULL, &error); + while (gdk_events_pending ()) + gtk_main_iteration (); + + } while (status == G_IO_STATUS_AGAIN); + + if (status != G_IO_STATUS_NORMAL) { + if (error) { + g_warning ("zenity_notification_handle_stdin () : %s", + error->message); + g_error_free (error); + error = NULL; + } + continue; + } + + zenity_util_strip_newline (string->str); + colon = strchr(string->str, ':'); + if (colon == NULL) { + g_printerr (_("could not parse command from stdin\n")); + continue; + } + /* split off the command and value */ + command = g_strndup (string->str, colon - string->str); + command = g_strstrip (command); + g_strdown (command); + + value = colon + 1; + while (*value && g_ascii_isspace (*value)) value++; + + if (!strcmp (command, "icon")) { + GdkPixbuf *pixbuf; + + pixbuf = zenity_util_pixbuf_new_from_file (GTK_WIDGET (tray_icon), + value); + if (pixbuf != NULL) { + gtk_image_set_from_pixbuf (GTK_IMAGE (icon_image), pixbuf); + gdk_pixbuf_unref (pixbuf); + } else { + g_warning ("Could not load notification icon : %s", value); + } + } else if (!strcmp (command, "message")) { + g_warning ("haven't implemented message support yet"); + } else if (!strcmp (command, "tooltip")) { + gtk_tooltips_set_tip (tooltips, icon_event_box, value, value); + } else if (!strcmp (command, "visible")) { + if (!strcasecmp (value, "false")) { + gtk_widget_hide (GTK_WIDGET (tray_icon)); + } else { + gtk_widget_show (GTK_WIDGET (tray_icon)); + } + } else { + g_warning ("Unknown command '%s'", command); + } + g_free (command); + + } while (g_io_channel_get_buffer_condition (channel) == G_IO_IN); + g_string_free (string, TRUE); + } + + if ((condition & G_IO_HUP) != 0) { + g_io_channel_shutdown (channel, TRUE, NULL); + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); + gtk_main_quit (); + return FALSE; + } + + return TRUE; +} + +static void +zenity_notification_listen_on_stdin (ZenityData *data) +{ + GIOChannel *channel; + + channel = g_io_channel_unix_new (0); + g_io_channel_set_encoding (channel, NULL, NULL); + g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL); + g_io_add_watch (channel, G_IO_IN | G_IO_HUP, + zenity_notification_handle_stdin, data); +} + void zenity_notification (ZenityData *data, ZenityNotificationData *notification_data) { - GtkWidget *icon_image; - GtkWidget *icon_event_box; - GtkTooltips *tooltips; GdkPixbuf *pixbuf = NULL; tray_icon = egg_tray_icon_new (_("Zenity notification")); @@ -113,15 +217,20 @@ zenity_notification (ZenityData *data, ZenityNotificationData *notification_data gtk_widget_add_events (GTK_WIDGET (tray_icon), GDK_BUTTON_PRESS_MASK | GDK_FOCUS_CHANGE_MASK); gtk_container_add (GTK_CONTAINER (tray_icon), icon_event_box); - g_signal_connect (tray_icon, "button_press_event", - G_CALLBACK (zenity_notification_icon_press_callback), data); - g_signal_connect (tray_icon, "destroy", G_CALLBACK (zenity_notification_icon_destroy_callback), data); g_signal_connect (tray_icon, "expose_event", G_CALLBACK (zenity_notification_icon_expose_callback), data); + if (notification_data->listen) { + zenity_notification_listen_on_stdin (data); + } else { + /* if we aren't listening for changes, then close on button_press */ + g_signal_connect (tray_icon, "button_press_event", + G_CALLBACK (zenity_notification_icon_press_callback), data); + } + gtk_widget_show_all (GTK_WIDGET (tray_icon)); /* Does nothing at the moment */ -- cgit From 17cd55e682d5b78738f03255b2638bb9da937962 Mon Sep 17 00:00:00 2001 From: James Henstridge Date: Thu, 30 Sep 2004 11:25:37 +0000 Subject: function to set a GtkImage to a scaled pixbuf. 2004-09-30 James Henstridge * src/notification.c (set_scaled_pixbuf): function to set a GtkImage to a scaled pixbuf. (zenity_notification_handle_stdin): set the image to a GTK_ICON_SIZE_BUTTON sized image. (zenity_notification): same here. --- src/notification.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index f3b3b1f9..a67b7308 100644 --- a/src/notification.c +++ b/src/notification.c @@ -33,6 +33,39 @@ static GtkWidget *icon_event_box; static GtkTooltips *tooltips; +static void +set_scaled_pixbuf (GtkImage *image, GdkPixbuf *pixbuf, GtkIconSize icon_size) +{ + GdkScreen *screen; + GtkSettings *settings; + int width, height, desired_width, desired_height; + GdkPixbuf *new_pixbuf; + + screen = gtk_widget_get_screen (GTK_WIDGET (image)); + settings = gtk_settings_get_for_screen (screen); + if (!gtk_icon_size_lookup_for_settings (settings, icon_size, + &desired_width, &desired_height)) + return; + + width = gdk_pixbuf_get_width (pixbuf); + height = gdk_pixbuf_get_height (pixbuf); + if (height > desired_height || width > desired_width) { + if (width * desired_height / height > desired_width) + desired_height = height * desired_width / width; + else + desired_width = width * desired_height / height; + + new_pixbuf = gdk_pixbuf_scale_simple (pixbuf, + desired_width, + desired_height, + GDK_INTERP_BILINEAR); + gtk_image_set_from_pixbuf (image, new_pixbuf); + g_object_unref (new_pixbuf); + } else { + gtk_image_set_from_pixbuf (image, pixbuf); + } +} + static gboolean zenity_notification_icon_press_callback (GtkWidget *widget, GdkEventButton *event, gpointer data) { @@ -138,7 +171,8 @@ zenity_notification_handle_stdin (GIOChannel *channel, pixbuf = zenity_util_pixbuf_new_from_file (GTK_WIDGET (tray_icon), value); if (pixbuf != NULL) { - gtk_image_set_from_pixbuf (GTK_IMAGE (icon_image), pixbuf); + set_scaled_pixbuf (GTK_IMAGE (icon_image), pixbuf, + GTK_ICON_SIZE_BUTTON); gdk_pixbuf_unref (pixbuf); } else { g_warning ("Could not load notification icon : %s", value); @@ -198,9 +232,11 @@ zenity_notification (ZenityData *data, ZenityNotificationData *notification_data pixbuf = gdk_pixbuf_new_from_file (ZENITY_IMAGE_FULLPATH ("zenity-notification.png"), NULL); icon_event_box = gtk_event_box_new (); + icon_image = gtk_image_new (); if (pixbuf) { - icon_image = gtk_image_new_from_pixbuf (pixbuf); + set_scaled_pixbuf (GTK_IMAGE (icon_image), pixbuf, + GTK_ICON_SIZE_BUTTON); gdk_pixbuf_unref (pixbuf); } else { g_warning ("Could not load notification icon : %s", ZENITY_IMAGE_FULLPATH ("zenity-notification.png")); -- cgit From a626476abbeafed0c70ed42e51037df3907d415c Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Sun, 19 Dec 2004 21:27:25 +0000 Subject: Fix #161539, and try and hide the parent widget, rather than the tray 2004-12-20 Glynn Foster * src/notification.c: Fix #161539, and try and hide the parent widget, rather than the tray icon, since it saves space. --- src/notification.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index a67b7308..4dcc63d7 100644 --- a/src/notification.c +++ b/src/notification.c @@ -183,9 +183,12 @@ zenity_notification_handle_stdin (GIOChannel *channel, gtk_tooltips_set_tip (tooltips, icon_event_box, value, value); } else if (!strcmp (command, "visible")) { if (!strcasecmp (value, "false")) { - gtk_widget_hide (GTK_WIDGET (tray_icon)); + /* We need to get the parent, because just hiding the tray_icon + * doesn't save on space. See #161539 for details + */ + gtk_widget_hide (gtk_widget_get_parent (GTK_WIDGET (tray_icon))); } else { - gtk_widget_show (GTK_WIDGET (tray_icon)); + gtk_widget_show (gtk_widget_get_parent (GTK_WIDGET (tray_icon))); } } else { g_warning ("Unknown command '%s'", command); -- cgit From 01872ab746227b3d38faa8f746c504af0defc39a Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Sun, 9 Jan 2005 20:13:18 +0000 Subject: Correct error message for notification icon. Fixes #163462. 2005-01-07 Glynn Foster * src/notification.c: Correct error message for notification icon. Fixes #163462. --- src/notification.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index 4dcc63d7..63b15116 100644 --- a/src/notification.c +++ b/src/notification.c @@ -242,7 +242,11 @@ zenity_notification (ZenityData *data, ZenityNotificationData *notification_data GTK_ICON_SIZE_BUTTON); gdk_pixbuf_unref (pixbuf); } else { - g_warning ("Could not load notification icon : %s", ZENITY_IMAGE_FULLPATH ("zenity-notification.png")); + if (data->window_icon != NULL) { + g_warning ("Could not load notification icon : %s", data->window_icon); + } + else + g_warning ("Could not load notification icon : %s", ZENITY_IMAGE_FULLPATH ("zenity-notification.png")); return; } -- cgit From a4777781d1b7c0294048e78dbc758de238b386c2 Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Mon, 31 Jan 2005 22:17:38 +0000 Subject: Patch from Chris Lahey for #165456. Updated. 2005-02-01 Glynn Foster * src/notification.c, src/option.c: Patch from Chris Lahey for #165456. * src/about.c, THANKS: Updated. --- src/notification.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index 63b15116..0a723854 100644 --- a/src/notification.c +++ b/src/notification.c @@ -75,6 +75,7 @@ zenity_notification_icon_press_callback (GtkWidget *widget, GdkEventButton *even zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); gtk_main_quit (); + return TRUE; } static gboolean @@ -102,7 +103,7 @@ zenity_notification_icon_expose_callback (GtkWidget *widget, GdkEventExpose *eve return FALSE; } -static gboolean +static void zenity_notification_icon_destroy_callback (GtkWidget *widget, gpointer data) { ZenityData *zen_data; -- cgit From 6abd93050f533752e47b75158e95431575c652ac Mon Sep 17 00:00:00 2001 From: Glynn Foster Date: Mon, 25 Apr 2005 03:20:45 +0000 Subject: COPYING, src/about.c, src/calendar.c, src/eggtrayicon.c, src/entry.c, 2005-04-25 Glynn Foster * COPYING, src/about.c, src/calendar.c, src/eggtrayicon.c, * src/entry.c, src/fileselection.c, src/main.c, src/msg.c, * src/notification.c, src/option.c, src/progress.c, * src/text.c, src/tree.c, src/util.c: Update the FSF address to point to 51 Franklin Street, Fifth Floor as per forwarded mail from Alvaro Lopez Ortega. --- src/notification.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index 0a723854..8aa0d917 100644 --- a/src/notification.c +++ b/src/notification.c @@ -15,8 +15,8 @@ * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. * * Authors: Glynn Foster */ -- cgit From 14c0bf10c84cf576135c9fdb1e549351ebf5e27c Mon Sep 17 00:00:00 2001 From: Lucas Almeida Rocha Date: Fri, 17 Jun 2005 03:18:41 +0000 Subject: Don't use the parent widget for hiding tray icon --- src/notification.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index 8aa0d917..509d2f8e 100644 --- a/src/notification.c +++ b/src/notification.c @@ -184,12 +184,9 @@ zenity_notification_handle_stdin (GIOChannel *channel, gtk_tooltips_set_tip (tooltips, icon_event_box, value, value); } else if (!strcmp (command, "visible")) { if (!strcasecmp (value, "false")) { - /* We need to get the parent, because just hiding the tray_icon - * doesn't save on space. See #161539 for details - */ - gtk_widget_hide (gtk_widget_get_parent (GTK_WIDGET (tray_icon))); + gtk_widget_hide (GTK_WIDGET (tray_icon)); } else { - gtk_widget_show (gtk_widget_get_parent (GTK_WIDGET (tray_icon))); + gtk_widget_show (GTK_WIDGET (tray_icon)); } } else { g_warning ("Unknown command '%s'", command); -- cgit From 4c328078b6ff16a0ba648f53c3bee7a68fe4dbc5 Mon Sep 17 00:00:00 2001 From: Lucas Almeida Rocha Date: Wed, 6 Jul 2005 20:13:11 +0000 Subject: Include cleanups (config.h) --- src/notification.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index 509d2f8e..26600cb3 100644 --- a/src/notification.c +++ b/src/notification.c @@ -21,8 +21,11 @@ * Authors: Glynn Foster */ +#include + #include #include +#include #include "zenity.h" #include "eggtrayicon.h" #include "util.h" -- cgit From e919741e641a82d7eb99dd5f0463c7006024c474 Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Thu, 23 Mar 2006 03:43:23 +0000 Subject: Implement the "message" command on notification icon with libnotify 2006-03-22 Lucas Rocha Implement the "message" command on notification icon with libnotify bubbles. Patch from Davyd Madeley . * configure.in: add libnotify checking. * src/notification.c (zenity_notification_handle_stdin, zenity_notification): initialize libnotify and implement "message" command. --- src/notification.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index 26600cb3..6d5f8dd7 100644 --- a/src/notification.c +++ b/src/notification.c @@ -26,6 +26,11 @@ #include #include #include + +#ifdef HAVE_LIBNOTIFY +#include +#endif + #include "zenity.h" #include "eggtrayicon.h" #include "util.h" @@ -182,7 +187,33 @@ zenity_notification_handle_stdin (GIOChannel *channel, g_warning ("Could not load notification icon : %s", value); } } else if (!strcmp (command, "message")) { - g_warning ("haven't implemented message support yet"); +#ifdef HAVE_LIBNOTIFY + /* display a notification bubble */ + if (notify_is_initted ()) { + GError *error = NULL; + NotifyNotification *n; + GdkPixbuf *icon; + + n = notify_notification_new (g_strcompress (value), NULL, NULL, + GTK_WIDGET (tray_icon)); + + icon = gtk_image_get_pixbuf (GTK_IMAGE (icon_image)); + + notify_notification_set_icon_from_pixbuf (n, icon); + + notify_notification_show (n, &error); + if (error) { + g_warning (error->message); + g_error_free (error); + } + + g_object_unref (G_OBJECT (n)); + } else { +#else + { /* this brace is for balance */ +#endif + g_warning ("Notification framework not available"); + } } else if (!strcmp (command, "tooltip")) { gtk_tooltips_set_tip (tooltips, icon_event_box, value, value); } else if (!strcmp (command, "visible")) { @@ -275,6 +306,12 @@ zenity_notification (ZenityData *data, ZenityNotificationData *notification_data G_CALLBACK (zenity_notification_icon_press_callback), data); } +#ifdef HAVE_LIBNOTIFY + /* create the notification widget */ + if (!notify_is_initted ()) + notify_init (_("Zenity notification")); +#endif + gtk_widget_show_all (GTK_WIDGET (tray_icon)); /* Does nothing at the moment */ -- cgit From d373b3f3ce9e1876f2e267bf240fbb807abd6815 Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Fri, 28 Jul 2006 21:25:11 +0000 Subject: src/notification.c (-set_scaled_pixbuf, +zenity_notification_icon_update, 2006-07-27 Lucas Rocha * src/notification.c (-set_scaled_pixbuf, +zenity_notification_icon_update, -zenity_notification_icon_press_callback, +zenity_notification_icon_size_changed_cb, -zenity_notification_icon_expose_callback, -zenity_notification_icon_destroy_callback, +zenity_notification_icon_activate_cb, zenity_notification_handle_stdin, zenity_notification), src/util.[ch] (+zenity_util_stock_from_filename, zenity_util_pixbuf_new_from_file), Makefile.am, configure.in: Migration to gtk_status_icon (Fixes bug #341451). Patch from Christian Persch . * src/eggtrayicon.[ch]: removed. --- src/notification.c | 287 ++++++++++++++++++++++++----------------------------- 1 file changed, 127 insertions(+), 160 deletions(-) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index 6d5f8dd7..222fbc8a 100644 --- a/src/notification.c +++ b/src/notification.c @@ -2,6 +2,7 @@ * notification.c * * Copyright (C) 2002 Sun Microsystems, Inc. + * Copyright (C) 2006 Christian Persch * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -23,6 +24,7 @@ #include +#include #include #include #include @@ -32,101 +34,71 @@ #endif #include "zenity.h" -#include "eggtrayicon.h" #include "util.h" -static EggTrayIcon *tray_icon; -static GtkWidget *icon_image; -static GtkWidget *icon_event_box; -static GtkTooltips *tooltips; - +static GtkStatusIcon *status_icon; +static gchar *icon_file; +static const gchar *icon_stock; +static gint icon_size; static void -set_scaled_pixbuf (GtkImage *image, GdkPixbuf *pixbuf, GtkIconSize icon_size) +zenity_notification_icon_update (void) { - GdkScreen *screen; - GtkSettings *settings; - int width, height, desired_width, desired_height; - GdkPixbuf *new_pixbuf; - - screen = gtk_widget_get_screen (GTK_WIDGET (image)); - settings = gtk_settings_get_for_screen (screen); - if (!gtk_icon_size_lookup_for_settings (settings, icon_size, - &desired_width, &desired_height)) - return; - - width = gdk_pixbuf_get_width (pixbuf); - height = gdk_pixbuf_get_height (pixbuf); - if (height > desired_height || width > desired_width) { - if (width * desired_height / height > desired_width) - desired_height = height * desired_width / width; - else - desired_width = width * desired_height / height; - - new_pixbuf = gdk_pixbuf_scale_simple (pixbuf, - desired_width, - desired_height, - GDK_INTERP_BILINEAR); - gtk_image_set_from_pixbuf (image, new_pixbuf); - g_object_unref (new_pixbuf); - } else { - gtk_image_set_from_pixbuf (image, pixbuf); + GdkPixbuf *pixbuf; + GError *error = NULL; + + pixbuf = gdk_pixbuf_new_from_file_at_scale (icon_file, icon_size, icon_size, TRUE, &error); + if (error) { + g_warning ("Could not load notification icon '%s': %s", + icon_file, error->message); + g_clear_error (&error); + } + if (!pixbuf) { + pixbuf = gdk_pixbuf_new_from_file_at_scale (ZENITY_IMAGE_FULLPATH ("zenity-notification.png"), + icon_size, icon_size, TRUE, NULL); + } + + gtk_status_icon_set_from_pixbuf (status_icon, pixbuf); + + if (pixbuf) { + g_object_unref (pixbuf); } } static gboolean -zenity_notification_icon_press_callback (GtkWidget *widget, GdkEventButton *event, gpointer data) +zenity_notification_icon_size_changed_cb (GtkStatusIcon *icon, + gint size, + gpointer user_data) { - ZenityData *zen_data; + icon_size = size; - zen_data = data; + /* If we're displaying not a stock icon but a custom pixbuf, + * we need to update the icon for the new size. + */ + if (!icon_stock) { + zenity_notification_icon_update (); - zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); - gtk_main_quit (); - return TRUE; -} + return TRUE; + } -static gboolean -zenity_notification_icon_expose_callback (GtkWidget *widget, GdkEventExpose *event, gpointer data) -{ - if (GTK_WIDGET_HAS_FOCUS (widget)) { - gint focus_width, focus_pad; - gint x, y, width, height; - - gtk_widget_style_get (widget, - "focus-line-width", &focus_width, - "focus-padding", &focus_pad, - NULL); - x = widget->allocation.x + focus_pad; - y = widget->allocation.y + focus_pad; - width = widget->allocation.width - 2 * focus_pad; - height = widget->allocation.height - 2 * focus_pad; - - gtk_paint_focus (widget->style, widget->window, - GTK_WIDGET_STATE (widget), - &event->area, widget, "button", - x, y, width, height); - } - - return FALSE; + return FALSE; } -static void -zenity_notification_icon_destroy_callback (GtkWidget *widget, gpointer data) +static gboolean +zenity_notification_icon_activate_cb (GtkWidget *widget, + ZenityData *data) { - ZenityData *zen_data; + data->exit_code = zenity_util_return_exit_code (ZENITY_OK); - zen_data = data; - gtk_widget_destroy (GTK_WIDGET (tray_icon)); - - zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); gtk_main_quit (); + + return TRUE; } static gboolean -zenity_notification_handle_stdin (GIOChannel *channel, +zenity_notification_handle_stdin (GIOChannel *channel, GIOCondition condition, - gpointer user_data) + gpointer user_data) { ZenityData *zen_data; @@ -137,7 +109,7 @@ zenity_notification_handle_stdin (GIOChannel *channel, GError *error = NULL; string = g_string_new (NULL); - while (channel->is_readable != TRUE) + while (channel->is_readable == FALSE) ; do { gint status; @@ -167,60 +139,72 @@ zenity_notification_handle_stdin (GIOChannel *channel, continue; } /* split off the command and value */ - command = g_strndup (string->str, colon - string->str); - command = g_strstrip (command); - g_strdown (command); + command = g_strstrip (g_strndup (string->str, colon - string->str)); value = colon + 1; while (*value && g_ascii_isspace (*value)) value++; - if (!strcmp (command, "icon")) { - GdkPixbuf *pixbuf; - - pixbuf = zenity_util_pixbuf_new_from_file (GTK_WIDGET (tray_icon), - value); - if (pixbuf != NULL) { - set_scaled_pixbuf (GTK_IMAGE (icon_image), pixbuf, - GTK_ICON_SIZE_BUTTON); - gdk_pixbuf_unref (pixbuf); - } else { - g_warning ("Could not load notification icon : %s", value); - } - } else if (!strcmp (command, "message")) { -#ifdef HAVE_LIBNOTIFY - /* display a notification bubble */ - if (notify_is_initted ()) { - GError *error = NULL; - NotifyNotification *n; - GdkPixbuf *icon; - - n = notify_notification_new (g_strcompress (value), NULL, NULL, - GTK_WIDGET (tray_icon)); + if (!g_ascii_strcasecmp (command, "icon")) { + icon_stock = zenity_util_stock_from_filename (value); - icon = gtk_image_get_pixbuf (GTK_IMAGE (icon_image)); + g_free (icon_file); + icon_file = g_strdup (value); - notify_notification_set_icon_from_pixbuf (n, icon); - - notify_notification_show (n, &error); + if (icon_stock) { + gtk_status_icon_set_from_stock (status_icon, icon_stock); + } else if (gtk_status_icon_get_visible (status_icon) && + gtk_status_icon_is_embedded (status_icon)) { + zenity_notification_icon_update (); + } + } else if (!g_ascii_strcasecmp (command, "message")) { +#ifdef HAVE_LIBNOTIFY + /* display a notification bubble */ + if (!g_utf8_validate (value, -1, NULL)) { + g_warning ("Invalid UTF-8 in input!"); + } else if (notify_is_initted ()) { + GError *error = NULL; + NotifyNotification *notif; + const gchar *icon = NULL; + gchar *freeme = NULL; + gchar *message; + + message = g_strcompress (value); + + if (icon_stock) { + icon = icon_stock; + } else if (icon_file) { + icon = freeme = g_filename_to_uri (icon_file, NULL, NULL); + } + + notif = notify_notification_new_with_status_icon (message, NULL /* summary */, + icon, status_icon); + g_free (message); + g_free (freeme); + + notify_notification_show (notif, &error); if (error) { - g_warning (error->message); + g_warning ("Error showing notification: %s", error->message); g_error_free (error); } - g_object_unref (G_OBJECT (n)); + g_object_unref (notif); } else { #else { /* this brace is for balance */ #endif g_warning ("Notification framework not available"); } - } else if (!strcmp (command, "tooltip")) { - gtk_tooltips_set_tip (tooltips, icon_event_box, value, value); - } else if (!strcmp (command, "visible")) { - if (!strcasecmp (value, "false")) { - gtk_widget_hide (GTK_WIDGET (tray_icon)); - } else { - gtk_widget_show (GTK_WIDGET (tray_icon)); + } else if (!g_ascii_strcasecmp (command, "tooltip")) { + if (g_utf8_validate (value, -1, NULL)) { + gtk_status_icon_set_tooltip (status_icon, value); + } else { + g_warning ("Invalid UTF-8 in input!"); + } + } else if (!g_ascii_strcasecmp (command, "visible")) { + if (!g_ascii_strcasecmp (value, "false")) { + gtk_status_icon_set_visible (status_icon, FALSE); + } else { + gtk_status_icon_set_visible (status_icon, TRUE); } } else { g_warning ("Unknown command '%s'", command); @@ -256,64 +240,47 @@ zenity_notification_listen_on_stdin (ZenityData *data) void zenity_notification (ZenityData *data, ZenityNotificationData *notification_data) { - GdkPixbuf *pixbuf = NULL; + status_icon = gtk_status_icon_new (); + g_signal_connect (status_icon, "size-changed", + G_CALLBACK (zenity_notification_icon_size_changed_cb), data); - tray_icon = egg_tray_icon_new (_("Zenity notification")); - tooltips = gtk_tooltips_new (); - - if (data->window_icon != NULL) - pixbuf = zenity_util_pixbuf_new_from_file (GTK_WIDGET (tray_icon), data->window_icon); - else - pixbuf = gdk_pixbuf_new_from_file (ZENITY_IMAGE_FULLPATH ("zenity-notification.png"), NULL); - - icon_event_box = gtk_event_box_new (); - icon_image = gtk_image_new (); - - if (pixbuf) { - set_scaled_pixbuf (GTK_IMAGE (icon_image), pixbuf, - GTK_ICON_SIZE_BUTTON); - gdk_pixbuf_unref (pixbuf); + if (notification_data->notification_text) { + gtk_status_icon_set_tooltip (status_icon, notification_data->notification_text); } else { - if (data->window_icon != NULL) { - g_warning ("Could not load notification icon : %s", data->window_icon); - } - else - g_warning ("Could not load notification icon : %s", ZENITY_IMAGE_FULLPATH ("zenity-notification.png")); - return; + gtk_status_icon_set_tooltip (status_icon, _("Zenity notification")); } - gtk_container_add (GTK_CONTAINER (icon_event_box), icon_image); - - if (notification_data->notification_text) - gtk_tooltips_set_tip (tooltips, icon_event_box, notification_data->notification_text, notification_data->notification_text); - else - gtk_tooltips_set_tip (tooltips, icon_event_box, _("Zenity notification"), _("Zenity notification")); - - gtk_widget_add_events (GTK_WIDGET (tray_icon), GDK_BUTTON_PRESS_MASK | GDK_FOCUS_CHANGE_MASK); - gtk_container_add (GTK_CONTAINER (tray_icon), icon_event_box); + icon_file = g_strdup (data->window_icon); + icon_stock = zenity_util_stock_from_filename (data->window_icon); - g_signal_connect (tray_icon, "destroy", - G_CALLBACK (zenity_notification_icon_destroy_callback), data); - - g_signal_connect (tray_icon, "expose_event", - G_CALLBACK (zenity_notification_icon_expose_callback), data); + /* Only set the stock icon here; if we're going to display a + * custom pixbuf we wait for the size-changed signal to load + * it at the right size. + */ + if (icon_stock) { + gtk_status_icon_set_from_stock (status_icon, icon_stock); + } +#ifdef HAVE_LIBNOTIFY + /* create the notification widget */ + if (!notify_is_initted ()) { + notify_init (_("Zenity notification")); + } +#endif + if (notification_data->listen) { zenity_notification_listen_on_stdin (data); } else { - /* if we aren't listening for changes, then close on button_press */ - g_signal_connect (tray_icon, "button_press_event", - G_CALLBACK (zenity_notification_icon_press_callback), data); + /* if we aren't listening for changes, then close on activate (left-click) */ + g_signal_connect (status_icon, "activate", + G_CALLBACK (zenity_notification_icon_activate_cb), data); } -#ifdef HAVE_LIBNOTIFY - /* create the notification widget */ - if (!notify_is_initted ()) - notify_init (_("Zenity notification")); -#endif - - gtk_widget_show_all (GTK_WIDGET (tray_icon)); - - /* Does nothing at the moment */ + /* Show icon and wait */ + gtk_status_icon_set_visible (status_icon, TRUE); gtk_main (); + + /* Cleanup */ + g_object_unref (status_icon); + g_free (icon_file); } -- cgit From 94e6ab1132d0510edb6a733593de7f031d259101 Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Wed, 9 Aug 2006 00:55:59 +0000 Subject: Release 2.15.91 Update. 2006-07-28 Lucas Rocha * configure.in: Release 2.15.91 * NEWS: Update. --- src/notification.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index 222fbc8a..745d8a35 100644 --- a/src/notification.c +++ b/src/notification.c @@ -182,6 +182,7 @@ zenity_notification_handle_stdin (GIOChannel *channel, g_free (freeme); notify_notification_show (notif, &error); + if (error) { g_warning ("Error showing notification: %s", error->message); g_error_free (error); -- cgit From adee9db56646cc297fd226db983d40f3ba0d4793 Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Mon, 14 May 2007 21:26:08 +0000 Subject: general cleanups for build warnings (Fixes bug #416196). Patch from 2007-05-14 Lucas Rocha * src/progress.c (zenity_progress_handle_stdin), src/option.c (zenity_create_context), src/about.c, src/notification.c (zenity_notification_handle_stdin): general cleanups for build warnings (Fixes bug #416196). Patch from Kjartan Maraas . svn path=/trunk/; revision=1208 --- src/notification.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index 745d8a35..35747be4 100644 --- a/src/notification.c +++ b/src/notification.c @@ -162,11 +162,11 @@ zenity_notification_handle_stdin (GIOChannel *channel, if (!g_utf8_validate (value, -1, NULL)) { g_warning ("Invalid UTF-8 in input!"); } else if (notify_is_initted ()) { - GError *error = NULL; NotifyNotification *notif; const gchar *icon = NULL; gchar *freeme = NULL; gchar *message; + error = NULL; message = g_strcompress (value); -- cgit From b73e72bcfea040aaf4ea681068676de3ee013ac8 Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Sun, 27 May 2007 20:09:27 +0000 Subject: initialize GTK+ before parsing command line options to better handle 2007-05-27 Lucas Rocha * src/main.c: initialize GTK+ before parsing command line options to better handle errors on display setting (Fixes bug #410055). svn path=/trunk/; revision=1217 --- src/notification.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index 35747be4..b5cdd406 100644 --- a/src/notification.c +++ b/src/notification.c @@ -48,6 +48,7 @@ zenity_notification_icon_update (void) GError *error = NULL; pixbuf = gdk_pixbuf_new_from_file_at_scale (icon_file, icon_size, icon_size, TRUE, &error); + if (error) { g_warning ("Could not load notification icon '%s': %s", icon_file, error->message); -- cgit From 8b16d4d4122e6337517ec16b9ca22dd27df0dafb Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Mon, 13 Aug 2007 20:36:29 +0000 Subject: added timeout option to all dialogs (Fixes bug #160654). Based on patch 2007-08-13 Lucas Rocha * src/*.c: added timeout option to all dialogs (Fixes bug #160654). Based on patch from Muthiah Annamalai . svn path=/trunk/; revision=1231 --- src/notification.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index b5cdd406..b2ab18fe 100644 --- a/src/notification.c +++ b/src/notification.c @@ -280,6 +280,11 @@ zenity_notification (ZenityData *data, ZenityNotificationData *notification_data /* Show icon and wait */ gtk_status_icon_set_visible (status_icon, TRUE); + + if(data->timeout_delay > 0) { + g_timeout_add (data->timeout_delay * 1000, (GSourceFunc) zenity_util_timeout_handle, NULL); + } + gtk_main (); /* Cleanup */ -- cgit From 6dd1d4b5e674014d1eeaad82d5b057e6537fc346 Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Sun, 8 Mar 2009 22:04:02 +0000 Subject: replace deprecated GTK+ calls (fixes bug #571869). Patch from Felix 2009-03-08 Lucas Rocha * configure.in, src/notification.c: replace deprecated GTK+ calls (fixes bug #571869). Patch from Felix Riemann . svn path=/trunk/; revision=1488 --- src/notification.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index b2ab18fe..6c8f7463 100644 --- a/src/notification.c +++ b/src/notification.c @@ -198,7 +198,7 @@ zenity_notification_handle_stdin (GIOChannel *channel, } } else if (!g_ascii_strcasecmp (command, "tooltip")) { if (g_utf8_validate (value, -1, NULL)) { - gtk_status_icon_set_tooltip (status_icon, value); + gtk_status_icon_set_tooltip_text (status_icon, value); } else { g_warning ("Invalid UTF-8 in input!"); } @@ -247,9 +247,9 @@ zenity_notification (ZenityData *data, ZenityNotificationData *notification_data G_CALLBACK (zenity_notification_icon_size_changed_cb), data); if (notification_data->notification_text) { - gtk_status_icon_set_tooltip (status_icon, notification_data->notification_text); + gtk_status_icon_set_tooltip_text (status_icon, notification_data->notification_text); } else { - gtk_status_icon_set_tooltip (status_icon, _("Zenity notification")); + gtk_status_icon_set_tooltip_text (status_icon, _("Zenity notification")); } icon_file = g_strdup (data->window_icon); -- cgit From 3f33966167cf2216f813c091d47461c451837602 Mon Sep 17 00:00:00 2001 From: Felix Riemann Date: Mon, 20 Jul 2009 10:23:32 +0200 Subject: Bug 578393 – convert from libglade to GtkBuilder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/notification.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index 6c8f7463..1d80fa15 100644 --- a/src/notification.c +++ b/src/notification.c @@ -25,7 +25,6 @@ #include #include -#include #include #include -- cgit From 533edc70443741edd36fe7b332ce47c2f2701167 Mon Sep 17 00:00:00 2001 From: "Aurélio A. Heckert" Date: Mon, 10 Aug 2009 00:08:14 +0100 Subject: Bug 573802 - Support notification summary You can now define title and summary on notifications. The first line of the provided text will be considered the title and the following lines are the summary. --- src/notification.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index 1d80fa15..674eaec9 100644 --- a/src/notification.c +++ b/src/notification.c @@ -165,10 +165,18 @@ zenity_notification_handle_stdin (GIOChannel *channel, NotifyNotification *notif; const gchar *icon = NULL; gchar *freeme = NULL; - gchar *message; + gchar **message; error = NULL; - message = g_strcompress (value); + /* message[1] (the summary) will be NULL in case there's + * no \n in the string. In which case only the title is + * defined */ + message = g_strsplit (g_strcompress (value), "\n", 2); + + if (*message == NULL) { + g_printerr (_("Could not parse message from stdin\n")); + continue; + } if (icon_stock) { icon = icon_stock; @@ -176,9 +184,12 @@ zenity_notification_handle_stdin (GIOChannel *channel, icon = freeme = g_filename_to_uri (icon_file, NULL, NULL); } - notif = notify_notification_new_with_status_icon (message, NULL /* summary */, - icon, status_icon); - g_free (message); + notif = notify_notification_new_with_status_icon ( + message[0] /* title */, + message[1] /* summary */, + icon, status_icon); + + g_strfreev (message); g_free (freeme); notify_notification_show (notif, &error); -- cgit From 1570a2bbf07627cb5f8d9828a95db67b7d00634c Mon Sep 17 00:00:00 2001 From: Philippe Gauthier Date: Fri, 30 Oct 2009 14:51:16 -0400 Subject: Use g_timeout_add_seconds instead g_timeout_add The calls to g_timeout_add are replaced with g_timeout_add_seconds to reduce the number or program wake ups. See the GNOME Goal description: http://live.gnome.org/GnomeGoals/UseTimeoutAddSeconds --- src/notification.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index 674eaec9..99a2e36a 100644 --- a/src/notification.c +++ b/src/notification.c @@ -292,7 +292,7 @@ zenity_notification (ZenityData *data, ZenityNotificationData *notification_data gtk_status_icon_set_visible (status_icon, TRUE); if(data->timeout_delay > 0) { - g_timeout_add (data->timeout_delay * 1000, (GSourceFunc) zenity_util_timeout_handle, NULL); + g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, NULL); } gtk_main (); -- cgit From 620d5505c59b5b5dd092bfa35bdf3e7723f1e7c3 Mon Sep 17 00:00:00 2001 From: William Jon McCann Date: Sat, 9 Oct 2010 04:59:44 -0400 Subject: Require libnotify 0.6.1 https://bugzilla.gnome.org/show_bug.cgi?id=631737 --- src/notification.c | 198 ++++++++++++++++++----------------------------------- 1 file changed, 65 insertions(+), 133 deletions(-) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index 99a2e36a..531aed22 100644 --- a/src/notification.c +++ b/src/notification.c @@ -24,75 +24,31 @@ #include +#include +#include #include #include #include - -#ifdef HAVE_LIBNOTIFY #include -#endif #include "zenity.h" #include "util.h" -static GtkStatusIcon *status_icon; -static gchar *icon_file; -static const gchar *icon_stock; -static gint icon_size; +static char *icon_file; static void -zenity_notification_icon_update (void) +on_notification_default_action (NotifyNotification *n, + const char *action, + void *user_data) { - GdkPixbuf *pixbuf; - GError *error = NULL; - - pixbuf = gdk_pixbuf_new_from_file_at_scale (icon_file, icon_size, icon_size, TRUE, &error); - - if (error) { - g_warning ("Could not load notification icon '%s': %s", - icon_file, error->message); - g_clear_error (&error); - } - if (!pixbuf) { - pixbuf = gdk_pixbuf_new_from_file_at_scale (ZENITY_IMAGE_FULLPATH ("zenity-notification.png"), - icon_size, icon_size, TRUE, NULL); - } - - gtk_status_icon_set_from_pixbuf (status_icon, pixbuf); - - if (pixbuf) { - g_object_unref (pixbuf); - } -} - -static gboolean -zenity_notification_icon_size_changed_cb (GtkStatusIcon *icon, - gint size, - gpointer user_data) -{ - icon_size = size; - - /* If we're displaying not a stock icon but a custom pixbuf, - * we need to update the icon for the new size. - */ - if (!icon_stock) { - zenity_notification_icon_update (); - - return TRUE; - } + ZenityData *zen_data; - return FALSE; -} + zen_data = (ZenityData *)user_data; + notify_notification_close (n, NULL); -static gboolean -zenity_notification_icon_activate_cb (GtkWidget *widget, - ZenityData *data) -{ - data->exit_code = zenity_util_return_exit_code (ZENITY_OK); + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); gtk_main_quit (); - - return TRUE; } static gboolean @@ -145,26 +101,14 @@ zenity_notification_handle_stdin (GIOChannel *channel, while (*value && g_ascii_isspace (*value)) value++; if (!g_ascii_strcasecmp (command, "icon")) { - icon_stock = zenity_util_stock_from_filename (value); - g_free (icon_file); icon_file = g_strdup (value); - - if (icon_stock) { - gtk_status_icon_set_from_stock (status_icon, icon_stock); - } else if (gtk_status_icon_get_visible (status_icon) && - gtk_status_icon_is_embedded (status_icon)) { - zenity_notification_icon_update (); - } } else if (!g_ascii_strcasecmp (command, "message")) { -#ifdef HAVE_LIBNOTIFY /* display a notification bubble */ if (!g_utf8_validate (value, -1, NULL)) { g_warning ("Invalid UTF-8 in input!"); - } else if (notify_is_initted ()) { + } else { NotifyNotification *notif; - const gchar *icon = NULL; - gchar *freeme = NULL; gchar **message; error = NULL; @@ -178,46 +122,37 @@ zenity_notification_handle_stdin (GIOChannel *channel, continue; } - if (icon_stock) { - icon = icon_stock; - } else if (icon_file) { - icon = freeme = g_filename_to_uri (icon_file, NULL, NULL); - } - - notif = notify_notification_new_with_status_icon ( - message[0] /* title */, - message[1] /* summary */, - icon, status_icon); + notif = notify_notification_new (message[0] /* title */, + message[1] /* summary */, + icon_file); g_strfreev (message); - g_free (freeme); - notify_notification_show (notif, &error); - - if (error) { - g_warning ("Error showing notification: %s", error->message); - g_error_free (error); - } + notify_notification_show (notif, &error); + if (error) { + g_warning ("Error showing notification: %s", error->message); + g_error_free (error); + } g_object_unref (notif); - } else { -#else - { /* this brace is for balance */ -#endif - g_warning ("Notification framework not available"); - } + } } else if (!g_ascii_strcasecmp (command, "tooltip")) { - if (g_utf8_validate (value, -1, NULL)) { - gtk_status_icon_set_tooltip_text (status_icon, value); - } else { + if (!g_utf8_validate (value, -1, NULL)) { g_warning ("Invalid UTF-8 in input!"); + } else { + NotifyNotification *notif; + + notif = notify_notification_new (value, + NULL, + icon_file); + notify_notification_show (notif, &error); + if (error) { + g_warning ("Error showing notification: %s", error->message); + g_error_free (error); + } } } else if (!g_ascii_strcasecmp (command, "visible")) { - if (!g_ascii_strcasecmp (value, "false")) { - gtk_status_icon_set_visible (status_icon, FALSE); - } else { - gtk_status_icon_set_visible (status_icon, TRUE); - } + } else { g_warning ("Unknown command '%s'", command); } @@ -249,55 +184,52 @@ zenity_notification_listen_on_stdin (ZenityData *data) zenity_notification_handle_stdin, data); } -void +void zenity_notification (ZenityData *data, ZenityNotificationData *notification_data) { - status_icon = gtk_status_icon_new (); - g_signal_connect (status_icon, "size-changed", - G_CALLBACK (zenity_notification_icon_size_changed_cb), data); + GError *error; + NotifyNotification *notification; - if (notification_data->notification_text) { - gtk_status_icon_set_tooltip_text (status_icon, notification_data->notification_text); - } else { - gtk_status_icon_set_tooltip_text (status_icon, _("Zenity notification")); - } - - icon_file = g_strdup (data->window_icon); - icon_stock = zenity_util_stock_from_filename (data->window_icon); - - /* Only set the stock icon here; if we're going to display a - * custom pixbuf we wait for the size-changed signal to load - * it at the right size. - */ - if (icon_stock) { - gtk_status_icon_set_from_stock (status_icon, icon_stock); - } - -#ifdef HAVE_LIBNOTIFY /* create the notification widget */ if (!notify_is_initted ()) { notify_init (_("Zenity notification")); } -#endif - + if (notification_data->listen) { zenity_notification_listen_on_stdin (data); } else { - /* if we aren't listening for changes, then close on activate (left-click) */ - g_signal_connect (status_icon, "activate", - G_CALLBACK (zenity_notification_icon_activate_cb), data); - } + if (notification_data->notification_text == NULL) { + exit (1); + } + + notification = notify_notification_new (notification_data->notification_text, NULL, data->window_icon); + if (notification == NULL) { + exit (1); + } + + /* if we aren't listening for changes, then close on default action */ + notify_notification_add_action (notification, + "default", + "Do Default Action", + (NotifyActionCallback) on_notification_default_action, + data, + NULL); + + /* Show icon and wait */ + error = NULL; + if (!notify_notification_show (notification, &error)) { + if (error != NULL) { + g_warning ("Error showing notification: %s", error->message); + g_error_free (error); + } + exit (1); + } - /* Show icon and wait */ - gtk_status_icon_set_visible (status_icon, TRUE); + } - if(data->timeout_delay > 0) { + if (data->timeout_delay > 0) { g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, NULL); } gtk_main (); - - /* Cleanup */ - g_object_unref (status_icon); - g_free (icon_file); } -- cgit From 079254bb48c28f62d15270028e64308347888a76 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Thu, 4 Nov 2010 17:12:52 -0200 Subject: Add libnotify as optional in zenity instalation --- src/notification.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index 531aed22..6fe44f1d 100644 --- a/src/notification.c +++ b/src/notification.c @@ -34,6 +34,7 @@ #include "zenity.h" #include "util.h" +#ifdef HAVE_LIBNOTIFY static char *icon_file; static void @@ -233,3 +234,4 @@ zenity_notification (ZenityData *data, ZenityNotificationData *notification_data gtk_main (); } +#endif -- cgit From 55df95a2f737ae89bab9fe82c5e2a9e620761f05 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 25 Jan 2011 18:49:01 -0500 Subject: Reset errors after freeing them This was causing segfaults: https://bugzilla.redhat.com/show_bug.cgi?id=670895 --- src/notification.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index 6fe44f1d..41d64e24 100644 --- a/src/notification.c +++ b/src/notification.c @@ -133,6 +133,7 @@ zenity_notification_handle_stdin (GIOChannel *channel, if (error) { g_warning ("Error showing notification: %s", error->message); g_error_free (error); + error = NULL; } g_object_unref (notif); @@ -150,6 +151,7 @@ zenity_notification_handle_stdin (GIOChannel *channel, if (error) { g_warning ("Error showing notification: %s", error->message); g_error_free (error); + error = NULL; } } } else if (!g_ascii_strcasecmp (command, "visible")) { -- cgit From 2fa457ed44afa5f4bbb35e3f3731ac11e64c0b7a Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Thu, 2 Jun 2011 22:42:33 +0530 Subject: Fix bug 651723, don't look for libnotify.h if not requested --- src/notification.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index 41d64e24..3f4c454e 100644 --- a/src/notification.c +++ b/src/notification.c @@ -29,12 +29,12 @@ #include #include #include +#ifdef HAVE_LIBNOTIFY #include #include "zenity.h" #include "util.h" -#ifdef HAVE_LIBNOTIFY static char *icon_file; static void -- cgit From 9beba8872dd01d6c9347717d9ce156c059e85a0d Mon Sep 17 00:00:00 2001 From: Marc Ruiz - radykal - Date: Mon, 12 Nov 2012 21:57:07 +0100 Subject: Replaced string 'could' to start with an Uppercase. BUG ID: 687180 --- src/notification.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index 3f4c454e..0a36e09e 100644 --- a/src/notification.c +++ b/src/notification.c @@ -92,7 +92,7 @@ zenity_notification_handle_stdin (GIOChannel *channel, zenity_util_strip_newline (string->str); colon = strchr(string->str, ':'); if (colon == NULL) { - g_printerr (_("could not parse command from stdin\n")); + g_printerr (_("Could not parse command from stdin\n")); continue; } /* split off the command and value */ -- cgit From 74d867c2aa9dde9dc21297c67af9e6432124b054 Mon Sep 17 00:00:00 2001 From: Nuno Araujo Date: Thu, 14 Feb 2013 01:08:56 +0100 Subject: Allow to specify notification's hints Desktop Notifications Specification [1] specifies that hints can be used to provide extra data to a notification server. A new command line option --hint allows to add a hint to the notification to display. This option can be used multiple times, one for each hint to add. --hint option format is name:value. The new 'hints' command allow to specify hints in 'listen' mode. Same format that in the command line option is used. Several hints can be passed by separating them by '\n'. Hints of value type '(iiibiiay)' are not supported. This value type is used to pass a raw data image as a hint value. This new change is useful for implementing the NotificationSource [2] GNOME Goal. A application using zenity and having a desktop file, can now specify that it is a notification emitter and it's notifications can be filtered in the new Notifications GNOME control panel pane. [1] http://people.gnome.org/~mccann/docs/notification-spec/notification-spec-latest.html#hints [2] https://live.gnome.org/GnomeGoals/NotificationSource https://bugzilla.gnome.org/show_bug.cgi?id=693751 --- src/notification.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index 0a36e09e..3a552026 100644 --- a/src/notification.c +++ b/src/notification.c @@ -35,7 +35,10 @@ #include "zenity.h" #include "util.h" +#define MAX_HINTS 16 + static char *icon_file; +static GHashTable *notification_hints; static void on_notification_default_action (NotifyNotification *n, @@ -52,6 +55,117 @@ on_notification_default_action (NotifyNotification *n, gtk_main_quit (); } +static GHashTable * +zenity_notification_parse_hints_array (gchar **hints) +{ + GHashTable *result; + gchar** pair; + int i; + + result = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, + g_free); + + for(i = 0; i < g_strv_length (hints); i++) { + pair = g_strsplit (hints[i], ":", 2); + g_hash_table_replace (result, g_strdup (pair[0]), g_strdup (pair[1])); + g_strfreev (pair); + } + if (g_hash_table_size (result) == 0) { + g_hash_table_unref (result); + return NULL; + } else { + return result; + } +} + +static GHashTable * +zenity_notification_parse_hints (gchar *hints) +{ + GHashTable *result; + gchar** hint_array; + + hint_array = g_strsplit (g_strcompress (hints), "\n", MAX_HINTS); + result = zenity_notification_parse_hints_array (hint_array); + g_strfreev (hint_array); + return result; +} + +static void +zenity_notification_set_hint(gpointer key, gpointer value, gpointer user_data) +{ + NotifyNotification *notification; + gchar *hint_name; + GVariant *hint_value; + + gchar *string_value; + gboolean boolean_value; + gint32 int_value; + guchar byte_value; + + hint_name = (gchar *) key; + string_value = (gchar *) value; + notification = (NotifyNotification *) user_data; + + if ((g_ascii_strcasecmp ("action-icons", hint_name) == 0) + || (g_ascii_strcasecmp ("resident", hint_name) == 0) + || (g_ascii_strcasecmp ("suppress-sound", hint_name) == 0) + || (g_ascii_strcasecmp ("transient", hint_name) == 0)) { + /* boolean hints */ + if (g_ascii_strcasecmp ("true", string_value) == 0) { + boolean_value = TRUE; + } else if (g_ascii_strcasecmp ("false", string_value) == 0) { + boolean_value = FALSE; + } else { + g_printerr (_("Invalid value for a boolean typed hint.\nSupported values are 'true' or 'false'.\n")); + return; + } + hint_value = g_variant_new_boolean (boolean_value); + } else if ((g_ascii_strcasecmp ("category", hint_name) == 0) + || (g_ascii_strcasecmp ("desktop-entry", hint_name) == 0) + || (g_ascii_strcasecmp ("image-path", hint_name) == 0) + || (g_ascii_strcasecmp ("image_path", hint_name) == 0) + || (g_ascii_strcasecmp ("sound-file", hint_name) == 0) + || (g_ascii_strcasecmp ("sound-name", hint_name) == 0)) { + /* string hints */ + hint_value = g_variant_new_string (string_value); + } else if ((g_ascii_strcasecmp ("image-data", hint_name) == 0) + || (g_ascii_strcasecmp ("image_data", hint_name) == 0) + || (g_ascii_strcasecmp ("icon-data", hint_name) == 0)) { + /* (iibiiay) */ + g_printerr (_("Unsupported hint. Skipping.\n")); + return; + } else if ((g_ascii_strcasecmp ("x", hint_name) == 0) + || (g_ascii_strcasecmp ("y", hint_name) == 0)) { + /* int hints */ + int_value = (gint32) g_ascii_strtoll (string_value, NULL, 0); + hint_value = g_variant_new_int32 (int_value); + } else if ((g_ascii_strcasecmp ("urgency", hint_name) == 0)) { + /* byte hints */ + byte_value = (guchar) g_ascii_strtoll (string_value, NULL, 0); + hint_value = g_variant_new_byte (byte_value); + } else { + /* unknown hints */ + g_printerr (_("Unknown hint name. Skipping.\n")); + return; + } + + notify_notification_set_hint (notification, + hint_name, + hint_value); +} + +static void +zenity_notification_set_hints (NotifyNotification *notification, GHashTable *hints) +{ + if (hints == NULL) { + return; + } + + g_hash_table_foreach (hints, zenity_notification_set_hint, notification); +} + static gboolean zenity_notification_handle_stdin (GIOChannel *channel, GIOCondition condition, @@ -104,6 +218,11 @@ zenity_notification_handle_stdin (GIOChannel *channel, if (!g_ascii_strcasecmp (command, "icon")) { g_free (icon_file); icon_file = g_strdup (value); + } else if (!g_ascii_strcasecmp (command, "hints")) { + if (notification_hints != NULL) { + g_hash_table_unref (notification_hints); + } + notification_hints = zenity_notification_parse_hints (value); } else if (!g_ascii_strcasecmp (command, "message")) { /* display a notification bubble */ if (!g_utf8_validate (value, -1, NULL)) { @@ -129,6 +248,8 @@ zenity_notification_handle_stdin (GIOChannel *channel, g_strfreev (message); + zenity_notification_set_hints (notif, notification_hints); + notify_notification_show (notif, &error); if (error) { g_warning ("Error showing notification: %s", error->message); @@ -147,6 +268,9 @@ zenity_notification_handle_stdin (GIOChannel *channel, notif = notify_notification_new (value, NULL, icon_file); + + zenity_notification_set_hints (notif, notification_hints); + notify_notification_show (notif, &error); if (error) { g_warning ("Error showing notification: %s", error->message); @@ -192,6 +316,7 @@ zenity_notification (ZenityData *data, ZenityNotificationData *notification_data { GError *error; NotifyNotification *notification; + GHashTable *notification_hints; /* create the notification widget */ if (!notify_is_initted ()) { @@ -218,6 +343,11 @@ zenity_notification (ZenityData *data, ZenityNotificationData *notification_data data, NULL); + /* set the notification hints for the displayed notification */ + notification_hints = zenity_notification_parse_hints_array (notification_data->notification_hints); + zenity_notification_set_hints(notification, notification_hints); + g_hash_table_unref (notification_hints); + /* Show icon and wait */ error = NULL; if (!notify_notification_show (notification, &error)) { @@ -236,4 +366,5 @@ zenity_notification (ZenityData *data, ZenityNotificationData *notification_data gtk_main (); } + #endif -- cgit From 9d03f0d006ad3080d6bbb91bff6ea5e71c7c98a2 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Fri, 29 Aug 2014 14:31:57 +0200 Subject: Bug 733870 - Segmentation fault on zenity --notification This fix a problem when user calls --hint=urgency without specify a :NOTIFY_URGENCY --- src/notification.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index 3a552026..d5631573 100644 --- a/src/notification.c +++ b/src/notification.c @@ -139,10 +139,14 @@ zenity_notification_set_hint(gpointer key, gpointer value, gpointer user_data) } else if ((g_ascii_strcasecmp ("x", hint_name) == 0) || (g_ascii_strcasecmp ("y", hint_name) == 0)) { /* int hints */ + if (string_value == NULL) + string_value = ""; int_value = (gint32) g_ascii_strtoll (string_value, NULL, 0); hint_value = g_variant_new_int32 (int_value); } else if ((g_ascii_strcasecmp ("urgency", hint_name) == 0)) { /* byte hints */ + if (string_value == NULL) + string_value = ""; byte_value = (guchar) g_ascii_strtoll (string_value, NULL, 0); hint_value = g_variant_new_byte (byte_value); } else { -- cgit From fc76e0c19be22d47cf6044ca591f0e01010a1a80 Mon Sep 17 00:00:00 2001 From: Emilio Pozuelo Monfort Date: Sat, 27 Feb 2010 15:32:23 +0100 Subject: Don't quit zenity when the input stream is closed When using --listen for a notification, zenity quits when the stream ends. This makes it impossible to read commands from a pipe as in `echo icon:info | zenity --notification --listen'. https://bugzilla.gnome.org/show_bug.cgi?id=525596 --- src/notification.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index d5631573..06ac1dde 100644 --- a/src/notification.c +++ b/src/notification.c @@ -295,8 +295,6 @@ zenity_notification_handle_stdin (GIOChannel *channel, if ((condition & G_IO_HUP) != 0) { g_io_channel_shutdown (channel, TRUE, NULL); - zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); - gtk_main_quit (); return FALSE; } -- cgit From a3568bc51baa1ceccb430c31b0f95c2672eccbcb Mon Sep 17 00:00:00 2001 From: Javier Jardón Date: Sun, 22 Mar 2015 09:05:23 +0000 Subject: src/notification.c: Remove non-used variable --- src/notification.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index 06ac1dde..2bdd05b6 100644 --- a/src/notification.c +++ b/src/notification.c @@ -175,10 +175,6 @@ zenity_notification_handle_stdin (GIOChannel *channel, GIOCondition condition, gpointer user_data) { - ZenityData *zen_data; - - zen_data = (ZenityData *)user_data; - if ((condition & G_IO_IN) != 0) { GString *string; GError *error = NULL; -- cgit From 160f0442c62579b79b15f953a9e6766a833952fd Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Fri, 29 May 2015 14:29:12 +0200 Subject: Fix GLib critical messages --- src/notification.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index 2bdd05b6..a4355a1e 100644 --- a/src/notification.c +++ b/src/notification.c @@ -342,9 +342,11 @@ zenity_notification (ZenityData *data, ZenityNotificationData *notification_data NULL); /* set the notification hints for the displayed notification */ - notification_hints = zenity_notification_parse_hints_array (notification_data->notification_hints); - zenity_notification_set_hints(notification, notification_hints); - g_hash_table_unref (notification_hints); + if (notification_data->notification_hints != NULL) { + notification_hints = zenity_notification_parse_hints_array (notification_data->notification_hints); + zenity_notification_set_hints(notification, notification_hints); + g_hash_table_unref (notification_hints); + } /* Show icon and wait */ error = NULL; -- cgit From 297380bad9004876c873a86dbd25bc5fa420e4a3 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Fri, 29 May 2015 14:46:37 +0200 Subject: Bug #742963 - Basic notifications do not return --- src/notification.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index a4355a1e..3169a994 100644 --- a/src/notification.c +++ b/src/notification.c @@ -323,6 +323,7 @@ zenity_notification (ZenityData *data, ZenityNotificationData *notification_data if (notification_data->listen) { zenity_notification_listen_on_stdin (data); + gtk_main(); } else { if (notification_data->notification_text == NULL) { exit (1); @@ -362,9 +363,8 @@ zenity_notification (ZenityData *data, ZenityNotificationData *notification_data if (data->timeout_delay > 0) { g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, NULL); + gtk_main(); } - - gtk_main (); } #endif -- cgit From d44ca5978053bb79a406acb4c824f79068f329b8 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Wed, 3 Jun 2015 11:54:52 +0200 Subject: Add the possibility to pass title and the summary to zenity notification Now you can use zenity --notification --text="Title\nSummary" and it will use the first string before the first escape \n as the title, and the rest of the string as summary text. --- src/notification.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index 3169a994..8086be61 100644 --- a/src/notification.c +++ b/src/notification.c @@ -315,6 +315,7 @@ zenity_notification (ZenityData *data, ZenityNotificationData *notification_data GError *error; NotifyNotification *notification; GHashTable *notification_hints; + gchar **message; /* create the notification widget */ if (!notify_is_initted ()) { @@ -328,8 +329,16 @@ zenity_notification (ZenityData *data, ZenityNotificationData *notification_data if (notification_data->notification_text == NULL) { exit (1); } + + message = g_strsplit (g_strcompress (notification_data->notification_text), "\n", 2); + if (*message == NULL) { + g_printerr (_("Could not parse message\n")); + exit (1); + } - notification = notify_notification_new (notification_data->notification_text, NULL, data->window_icon); + notification = notify_notification_new (message[0], /* title */ + message[1], /* summary */ + data->window_icon); if (notification == NULL) { exit (1); } -- cgit From abf0777b35e70c23688a4c29dc1a0fb241b770c6 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Wed, 3 Jun 2015 13:32:32 +0200 Subject: Bug #638582 - zenity --notification --listen can't show multi line tooltip This create a new function to call the notify_notification_new handling properly the multi line parser --- src/notification.c | 56 ++++++++++++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 29 deletions(-) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index 8086be61..9bbd6ce1 100644 --- a/src/notification.c +++ b/src/notification.c @@ -40,6 +40,25 @@ static char *icon_file; static GHashTable *notification_hints; +static NotifyNotification * +zenity_notification_new(gchar *message, gchar *icon_file) +{ + NotifyNotification *notif; + gchar **text; + + text = g_strsplit (g_strcompress (message), "\n", 2); + if (*text == NULL) { + g_printerr (_("Could not parse message\n")); + return NULL; + } + + notif = notify_notification_new (text[0], /* title */ + text[1], /* summary */ + icon_file); + g_strfreev (text); + return notif; +} + static void on_notification_default_action (NotifyNotification *n, const char *action, @@ -229,24 +248,11 @@ zenity_notification_handle_stdin (GIOChannel *channel, g_warning ("Invalid UTF-8 in input!"); } else { NotifyNotification *notif; - gchar **message; error = NULL; - /* message[1] (the summary) will be NULL in case there's - * no \n in the string. In which case only the title is - * defined */ - message = g_strsplit (g_strcompress (value), "\n", 2); - - if (*message == NULL) { - g_printerr (_("Could not parse message from stdin\n")); - continue; - } - - notif = notify_notification_new (message[0] /* title */, - message[1] /* summary */, - icon_file); - - g_strfreev (message); + notif = zenity_notification_new (value, icon_file); + if (notif == NULL) + continue; zenity_notification_set_hints (notif, notification_hints); @@ -264,10 +270,9 @@ zenity_notification_handle_stdin (GIOChannel *channel, g_warning ("Invalid UTF-8 in input!"); } else { NotifyNotification *notif; - - notif = notify_notification_new (value, - NULL, - icon_file); + notif = zenity_notification_new (value, icon_file); + if (notif == NULL) + continue; zenity_notification_set_hints (notif, notification_hints); @@ -315,7 +320,6 @@ zenity_notification (ZenityData *data, ZenityNotificationData *notification_data GError *error; NotifyNotification *notification; GHashTable *notification_hints; - gchar **message; /* create the notification widget */ if (!notify_is_initted ()) { @@ -329,16 +333,10 @@ zenity_notification (ZenityData *data, ZenityNotificationData *notification_data if (notification_data->notification_text == NULL) { exit (1); } - - message = g_strsplit (g_strcompress (notification_data->notification_text), "\n", 2); - if (*message == NULL) { - g_printerr (_("Could not parse message\n")); - exit (1); - } - notification = notify_notification_new (message[0], /* title */ - message[1], /* summary */ + notification = zenity_notification_new (notification_data->notification_text, data->window_icon); + if (notification == NULL) { exit (1); } -- cgit From 4eddb202cafdcabc254aa941ad1348ff09372627 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Fri, 7 Apr 2017 14:00:42 +0200 Subject: Fix style Fixing style in all zenity code, removing useless spaces, empty lines, all code in 80 columns, etc. --- src/notification.c | 606 ++++++++++++++++++++++++++--------------------------- 1 file changed, 300 insertions(+), 306 deletions(-) (limited to 'src/notification.c') diff --git a/src/notification.c b/src/notification.c index 9bbd6ce1..eb0e79eb 100644 --- a/src/notification.c +++ b/src/notification.c @@ -24,16 +24,16 @@ #include -#include -#include #include -#include +#include #include +#include +#include #ifdef HAVE_LIBNOTIFY #include -#include "zenity.h" #include "util.h" +#include "zenity.h" #define MAX_HINTS 16 @@ -41,337 +41,331 @@ static char *icon_file; static GHashTable *notification_hints; static NotifyNotification * -zenity_notification_new(gchar *message, gchar *icon_file) -{ - NotifyNotification *notif; - gchar **text; - - text = g_strsplit (g_strcompress (message), "\n", 2); - if (*text == NULL) { - g_printerr (_("Could not parse message\n")); - return NULL; - } - - notif = notify_notification_new (text[0], /* title */ - text[1], /* summary */ - icon_file); - g_strfreev (text); - return notif; +zenity_notification_new (gchar *message, gchar *icon_file) { + NotifyNotification *notif; + gchar **text; + + text = g_strsplit (g_strcompress (message), "\n", 2); + if (*text == NULL) { + g_printerr (_ ("Could not parse message\n")); + return NULL; + } + + notif = notify_notification_new (text[0], /* title */ + text[1], /* summary */ + icon_file); + g_strfreev (text); + return notif; } static void -on_notification_default_action (NotifyNotification *n, - const char *action, - void *user_data) -{ - ZenityData *zen_data; +on_notification_default_action ( + NotifyNotification *n, const char *action, void *user_data) { + ZenityData *zen_data; - zen_data = (ZenityData *)user_data; - notify_notification_close (n, NULL); + zen_data = (ZenityData *) user_data; + notify_notification_close (n, NULL); - zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); - gtk_main_quit (); + gtk_main_quit (); } static GHashTable * -zenity_notification_parse_hints_array (gchar **hints) -{ - GHashTable *result; - gchar** pair; - int i; - - result = g_hash_table_new_full (g_str_hash, - g_str_equal, - g_free, - g_free); - - for(i = 0; i < g_strv_length (hints); i++) { - pair = g_strsplit (hints[i], ":", 2); - g_hash_table_replace (result, g_strdup (pair[0]), g_strdup (pair[1])); - g_strfreev (pair); - } - if (g_hash_table_size (result) == 0) { - g_hash_table_unref (result); - return NULL; - } else { - return result; - } +zenity_notification_parse_hints_array (gchar **hints) { + GHashTable *result; + gchar **pair; + int i; + + result = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + + for (i = 0; i < g_strv_length (hints); i++) { + pair = g_strsplit (hints[i], ":", 2); + g_hash_table_replace (result, g_strdup (pair[0]), g_strdup (pair[1])); + g_strfreev (pair); + } + if (g_hash_table_size (result) == 0) { + g_hash_table_unref (result); + return NULL; + } else { + return result; + } } static GHashTable * -zenity_notification_parse_hints (gchar *hints) -{ - GHashTable *result; - gchar** hint_array; - - hint_array = g_strsplit (g_strcompress (hints), "\n", MAX_HINTS); - result = zenity_notification_parse_hints_array (hint_array); - g_strfreev (hint_array); - return result; +zenity_notification_parse_hints (gchar *hints) { + GHashTable *result; + gchar **hint_array; + + hint_array = g_strsplit (g_strcompress (hints), "\n", MAX_HINTS); + result = zenity_notification_parse_hints_array (hint_array); + g_strfreev (hint_array); + return result; } static void -zenity_notification_set_hint(gpointer key, gpointer value, gpointer user_data) -{ - NotifyNotification *notification; - gchar *hint_name; - GVariant *hint_value; - - gchar *string_value; - gboolean boolean_value; - gint32 int_value; - guchar byte_value; - - hint_name = (gchar *) key; - string_value = (gchar *) value; - notification = (NotifyNotification *) user_data; - - if ((g_ascii_strcasecmp ("action-icons", hint_name) == 0) - || (g_ascii_strcasecmp ("resident", hint_name) == 0) - || (g_ascii_strcasecmp ("suppress-sound", hint_name) == 0) - || (g_ascii_strcasecmp ("transient", hint_name) == 0)) { - /* boolean hints */ - if (g_ascii_strcasecmp ("true", string_value) == 0) { - boolean_value = TRUE; - } else if (g_ascii_strcasecmp ("false", string_value) == 0) { - boolean_value = FALSE; - } else { - g_printerr (_("Invalid value for a boolean typed hint.\nSupported values are 'true' or 'false'.\n")); - return; - } - hint_value = g_variant_new_boolean (boolean_value); - } else if ((g_ascii_strcasecmp ("category", hint_name) == 0) - || (g_ascii_strcasecmp ("desktop-entry", hint_name) == 0) - || (g_ascii_strcasecmp ("image-path", hint_name) == 0) - || (g_ascii_strcasecmp ("image_path", hint_name) == 0) - || (g_ascii_strcasecmp ("sound-file", hint_name) == 0) - || (g_ascii_strcasecmp ("sound-name", hint_name) == 0)) { - /* string hints */ - hint_value = g_variant_new_string (string_value); - } else if ((g_ascii_strcasecmp ("image-data", hint_name) == 0) - || (g_ascii_strcasecmp ("image_data", hint_name) == 0) - || (g_ascii_strcasecmp ("icon-data", hint_name) == 0)) { - /* (iibiiay) */ - g_printerr (_("Unsupported hint. Skipping.\n")); - return; - } else if ((g_ascii_strcasecmp ("x", hint_name) == 0) - || (g_ascii_strcasecmp ("y", hint_name) == 0)) { - /* int hints */ - if (string_value == NULL) - string_value = ""; - int_value = (gint32) g_ascii_strtoll (string_value, NULL, 0); - hint_value = g_variant_new_int32 (int_value); - } else if ((g_ascii_strcasecmp ("urgency", hint_name) == 0)) { - /* byte hints */ - if (string_value == NULL) - string_value = ""; - byte_value = (guchar) g_ascii_strtoll (string_value, NULL, 0); - hint_value = g_variant_new_byte (byte_value); - } else { - /* unknown hints */ - g_printerr (_("Unknown hint name. Skipping.\n")); - return; - } - - notify_notification_set_hint (notification, - hint_name, - hint_value); +zenity_notification_set_hint ( + gpointer key, gpointer value, gpointer user_data) { + NotifyNotification *notification; + gchar *hint_name; + GVariant *hint_value; + + gchar *string_value; + gboolean boolean_value; + gint32 int_value; + guchar byte_value; + + hint_name = (gchar *) key; + string_value = (gchar *) value; + notification = (NotifyNotification *) user_data; + + if ((g_ascii_strcasecmp ("action-icons", hint_name) == 0) || + (g_ascii_strcasecmp ("resident", hint_name) == 0) || + (g_ascii_strcasecmp ("suppress-sound", hint_name) == 0) || + (g_ascii_strcasecmp ("transient", hint_name) == 0)) { + /* boolean hints */ + if (g_ascii_strcasecmp ("true", string_value) == 0) { + boolean_value = TRUE; + } else if (g_ascii_strcasecmp ("false", string_value) == 0) { + boolean_value = FALSE; + } else { + g_printerr (_ ("Invalid value for a boolean typed hint.\nSupported " + "values are 'true' or 'false'.\n")); + return; + } + hint_value = g_variant_new_boolean (boolean_value); + } else if ((g_ascii_strcasecmp ("category", hint_name) == 0) || + (g_ascii_strcasecmp ("desktop-entry", hint_name) == 0) || + (g_ascii_strcasecmp ("image-path", hint_name) == 0) || + (g_ascii_strcasecmp ("image_path", hint_name) == 0) || + (g_ascii_strcasecmp ("sound-file", hint_name) == 0) || + (g_ascii_strcasecmp ("sound-name", hint_name) == 0)) { + /* string hints */ + hint_value = g_variant_new_string (string_value); + } else if ((g_ascii_strcasecmp ("image-data", hint_name) == 0) || + (g_ascii_strcasecmp ("image_data", hint_name) == 0) || + (g_ascii_strcasecmp ("icon-data", hint_name) == 0)) { + /* (iibiiay) */ + g_printerr (_ ("Unsupported hint. Skipping.\n")); + return; + } else if ((g_ascii_strcasecmp ("x", hint_name) == 0) || + (g_ascii_strcasecmp ("y", hint_name) == 0)) { + /* int hints */ + if (string_value == NULL) + string_value = ""; + int_value = (gint32) g_ascii_strtoll (string_value, NULL, 0); + hint_value = g_variant_new_int32 (int_value); + } else if ((g_ascii_strcasecmp ("urgency", hint_name) == 0)) { + /* byte hints */ + if (string_value == NULL) + string_value = ""; + byte_value = (guchar) g_ascii_strtoll (string_value, NULL, 0); + hint_value = g_variant_new_byte (byte_value); + } else { + /* unknown hints */ + g_printerr (_ ("Unknown hint name. Skipping.\n")); + return; + } + + notify_notification_set_hint (notification, hint_name, hint_value); } static void -zenity_notification_set_hints (NotifyNotification *notification, GHashTable *hints) -{ - if (hints == NULL) { - return; - } +zenity_notification_set_hints ( + NotifyNotification *notification, GHashTable *hints) { + if (hints == NULL) { + return; + } - g_hash_table_foreach (hints, zenity_notification_set_hint, notification); + g_hash_table_foreach (hints, zenity_notification_set_hint, notification); } static gboolean -zenity_notification_handle_stdin (GIOChannel *channel, - GIOCondition condition, - gpointer user_data) -{ - if ((condition & G_IO_IN) != 0) { - GString *string; - GError *error = NULL; - - string = g_string_new (NULL); - while (channel->is_readable == FALSE) - ; - do { - gint status; - gchar *command, *value, *colon; - - do { - status = g_io_channel_read_line_string (channel, string, NULL, &error); - while (gdk_events_pending ()) - gtk_main_iteration (); - - } while (status == G_IO_STATUS_AGAIN); - - if (status != G_IO_STATUS_NORMAL) { - if (error) { - g_warning ("zenity_notification_handle_stdin () : %s", - error->message); - g_error_free (error); - error = NULL; +zenity_notification_handle_stdin ( + GIOChannel *channel, GIOCondition condition, gpointer user_data) { + if ((condition & G_IO_IN) != 0) { + GString *string; + GError *error = NULL; + + string = g_string_new (NULL); + while (channel->is_readable == FALSE) + ; + do { + gint status; + gchar *command, *value, *colon; + + do { + status = g_io_channel_read_line_string ( + channel, string, NULL, &error); + while (gdk_events_pending ()) + gtk_main_iteration (); + + } while (status == G_IO_STATUS_AGAIN); + + if (status != G_IO_STATUS_NORMAL) { + if (error) { + g_warning ("zenity_notification_handle_stdin () : %s", + error->message); + g_error_free (error); + error = NULL; + } + continue; + } + + zenity_util_strip_newline (string->str); + colon = strchr (string->str, ':'); + if (colon == NULL) { + g_printerr (_ ("Could not parse command from stdin\n")); + continue; + } + /* split off the command and value */ + command = g_strstrip (g_strndup (string->str, colon - string->str)); + + value = colon + 1; + while (*value && g_ascii_isspace (*value)) + value++; + + if (!g_ascii_strcasecmp (command, "icon")) { + g_free (icon_file); + icon_file = g_strdup (value); + } else if (!g_ascii_strcasecmp (command, "hints")) { + if (notification_hints != NULL) { + g_hash_table_unref (notification_hints); + } + notification_hints = zenity_notification_parse_hints (value); + } else if (!g_ascii_strcasecmp (command, "message")) { + /* display a notification bubble */ + if (!g_utf8_validate (value, -1, NULL)) { + g_warning ("Invalid UTF-8 in input!"); + } else { + NotifyNotification *notif; + error = NULL; + + notif = zenity_notification_new (value, icon_file); + if (notif == NULL) + continue; + + zenity_notification_set_hints (notif, notification_hints); + + notify_notification_show (notif, &error); + if (error) { + g_warning ( + "Error showing notification: %s", error->message); + g_error_free (error); + error = NULL; + } + + g_object_unref (notif); + } + } else if (!g_ascii_strcasecmp (command, "tooltip")) { + if (!g_utf8_validate (value, -1, NULL)) { + g_warning ("Invalid UTF-8 in input!"); + } else { + NotifyNotification *notif; + notif = zenity_notification_new (value, icon_file); + if (notif == NULL) + continue; + + zenity_notification_set_hints (notif, notification_hints); + + notify_notification_show (notif, &error); + if (error) { + g_warning ( + "Error showing notification: %s", error->message); + g_error_free (error); + error = NULL; + } + } + } else if (!g_ascii_strcasecmp (command, "visible")) { + + } else { + g_warning ("Unknown command '%s'", command); + } + g_free (command); + + } while (g_io_channel_get_buffer_condition (channel) == G_IO_IN); + g_string_free (string, TRUE); + } + + if ((condition & G_IO_HUP) != 0) { + g_io_channel_shutdown (channel, TRUE, NULL); + return FALSE; } - continue; - } - - zenity_util_strip_newline (string->str); - colon = strchr(string->str, ':'); - if (colon == NULL) { - g_printerr (_("Could not parse command from stdin\n")); - continue; - } - /* split off the command and value */ - command = g_strstrip (g_strndup (string->str, colon - string->str)); - - value = colon + 1; - while (*value && g_ascii_isspace (*value)) value++; - - if (!g_ascii_strcasecmp (command, "icon")) { - g_free (icon_file); - icon_file = g_strdup (value); - } else if (!g_ascii_strcasecmp (command, "hints")) { - if (notification_hints != NULL) { - g_hash_table_unref (notification_hints); - } - notification_hints = zenity_notification_parse_hints (value); - } else if (!g_ascii_strcasecmp (command, "message")) { - /* display a notification bubble */ - if (!g_utf8_validate (value, -1, NULL)) { - g_warning ("Invalid UTF-8 in input!"); - } else { - NotifyNotification *notif; - error = NULL; - - notif = zenity_notification_new (value, icon_file); - if (notif == NULL) - continue; - - zenity_notification_set_hints (notif, notification_hints); - - notify_notification_show (notif, &error); - if (error) { - g_warning ("Error showing notification: %s", error->message); - g_error_free (error); - error = NULL; - } - - g_object_unref (notif); - } - } else if (!g_ascii_strcasecmp (command, "tooltip")) { - if (!g_utf8_validate (value, -1, NULL)) { - g_warning ("Invalid UTF-8 in input!"); - } else { - NotifyNotification *notif; - notif = zenity_notification_new (value, icon_file); - if (notif == NULL) - continue; - - zenity_notification_set_hints (notif, notification_hints); - - notify_notification_show (notif, &error); - if (error) { - g_warning ("Error showing notification: %s", error->message); - g_error_free (error); - error = NULL; - } - } - } else if (!g_ascii_strcasecmp (command, "visible")) { - - } else { - g_warning ("Unknown command '%s'", command); - } - g_free (command); - - } while (g_io_channel_get_buffer_condition (channel) == G_IO_IN); - g_string_free (string, TRUE); - } - - if ((condition & G_IO_HUP) != 0) { - g_io_channel_shutdown (channel, TRUE, NULL); - return FALSE; - } - - return TRUE; + + return TRUE; } static void -zenity_notification_listen_on_stdin (ZenityData *data) -{ - GIOChannel *channel; - - channel = g_io_channel_unix_new (0); - g_io_channel_set_encoding (channel, NULL, NULL); - g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL); - g_io_add_watch (channel, G_IO_IN | G_IO_HUP, - zenity_notification_handle_stdin, data); +zenity_notification_listen_on_stdin (ZenityData *data) { + GIOChannel *channel; + + channel = g_io_channel_unix_new (0); + g_io_channel_set_encoding (channel, NULL, NULL); + g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL); + g_io_add_watch ( + channel, G_IO_IN | G_IO_HUP, zenity_notification_handle_stdin, data); } void -zenity_notification (ZenityData *data, ZenityNotificationData *notification_data) -{ - GError *error; - NotifyNotification *notification; - GHashTable *notification_hints; - - /* create the notification widget */ - if (!notify_is_initted ()) { - notify_init (_("Zenity notification")); - } - - if (notification_data->listen) { - zenity_notification_listen_on_stdin (data); - gtk_main(); - } else { - if (notification_data->notification_text == NULL) { - exit (1); - } - - notification = zenity_notification_new (notification_data->notification_text, - data->window_icon); - - if (notification == NULL) { - exit (1); - } - - /* if we aren't listening for changes, then close on default action */ - notify_notification_add_action (notification, - "default", - "Do Default Action", - (NotifyActionCallback) on_notification_default_action, - data, - NULL); - - /* set the notification hints for the displayed notification */ - if (notification_data->notification_hints != NULL) { - notification_hints = zenity_notification_parse_hints_array (notification_data->notification_hints); - zenity_notification_set_hints(notification, notification_hints); - g_hash_table_unref (notification_hints); - } - - /* Show icon and wait */ - error = NULL; - if (!notify_notification_show (notification, &error)) { - if (error != NULL) { - g_warning ("Error showing notification: %s", error->message); - g_error_free (error); - } - exit (1); - } - - } - - if (data->timeout_delay > 0) { - g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, NULL); - gtk_main(); - } +zenity_notification ( + ZenityData *data, ZenityNotificationData *notification_data) { + GError *error; + NotifyNotification *notification; + GHashTable *notification_hints; + + /* create the notification widget */ + if (!notify_is_initted ()) { + notify_init (_ ("Zenity notification")); + } + + if (notification_data->listen) { + zenity_notification_listen_on_stdin (data); + gtk_main (); + } else { + if (notification_data->notification_text == NULL) { + exit (1); + } + + notification = zenity_notification_new ( + notification_data->notification_text, data->window_icon); + + if (notification == NULL) { + exit (1); + } + + /* if we aren't listening for changes, then close on default action */ + notify_notification_add_action (notification, + "default", + "Do Default Action", + (NotifyActionCallback) on_notification_default_action, + data, + NULL); + + /* set the notification hints for the displayed notification */ + if (notification_data->notification_hints != NULL) { + notification_hints = zenity_notification_parse_hints_array ( + notification_data->notification_hints); + zenity_notification_set_hints (notification, notification_hints); + g_hash_table_unref (notification_hints); + } + + /* Show icon and wait */ + error = NULL; + if (!notify_notification_show (notification, &error)) { + if (error != NULL) { + g_warning ("Error showing notification: %s", error->message); + g_error_free (error); + } + exit (1); + } + } + + if (data->timeout_delay > 0) { + g_timeout_add_seconds (data->timeout_delay, + (GSourceFunc) zenity_util_timeout_handle, + NULL); + gtk_main (); + } } #endif -- cgit