summaryrefslogtreecommitdiff
path: root/src/notification.c
diff options
context:
space:
mode:
authorGlynn Foster <glynn.foster@sun.com>2004-09-13 07:51:51 +0000
committerGlynn Foster <gman@src.gnome.org>2004-09-13 07:51:51 +0000
commit3e05834b4c23a5d5951403719b8594ff3d9fe30b (patch)
treef35532d3b2d0adb7ca74cd7c224c58c250d0ec62 /src/notification.c
parentUpdate Update. Patch from Lucas Rocha to implement save and directory (diff)
downloadzenity-3e05834b4c23a5d5951403719b8594ff3d9fe30b.tar.gz
zenity-3e05834b4c23a5d5951403719b8594ff3d9fe30b.tar.bz2
zenity-3e05834b4c23a5d5951403719b8594ff3d9fe30b.zip
Add new notification icon. Update for new files. Restructure code a little
2004-09-13 Glynn Foster <glynn.foster@sun.com> * 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.
Diffstat (limited to 'src/notification.c')
-rw-r--r--src/notification.c129
1 files changed, 129 insertions, 0 deletions
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 <glynn.foster@sun.com>
+ */
+
+#include <glade/glade.h>
+#include <time.h>
+#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 ();
+}
bgstack15