[Galago-commits] r2417 - in trunk/notification-daemon: . src

galago-commits at freedesktop.org galago-commits at freedesktop.org
Tue Jan 10 23:58:25 PST 2006


Author: chipx86
Date: 2006-01-10 23:58:22 -0800 (Tue, 10 Jan 2006)
New Revision: 2417

Added:
   trunk/notification-daemon/notification-daemon.service.in
   trunk/notification-daemon/src/daemon.c
   trunk/notification-daemon/src/daemon.h
   trunk/notification-daemon/src/notificationdaemon.xml
Removed:
   trunk/notification-daemon/notify-daemon.service.in
   trunk/notification-daemon/src/notifydaemon.c
   trunk/notification-daemon/src/notifydaemon.h
   trunk/notification-daemon/src/notifydaemon.xml
Modified:
   trunk/notification-daemon/ChangeLog
   trunk/notification-daemon/Makefile.am
   trunk/notification-daemon/autogen.sh
   trunk/notification-daemon/configure.ac
   trunk/notification-daemon/src/Makefile.am
Log:
Rename from notify-daemon to notification-daemon. I've received a number of questions and some complaints about the name change, some of which are packaging concerns, some upgrade concerns, and just general confusion and "Why?" As this is the "Desktop Notifications" project, and due to reasons expressed to me from others, I feel it's best to revert the name.


Modified: trunk/notification-daemon/ChangeLog
===================================================================
--- trunk/notification-daemon/ChangeLog	2006-01-11 07:48:56 UTC (rev 2416)
+++ trunk/notification-daemon/ChangeLog	2006-01-11 07:58:22 UTC (rev 2417)
@@ -1,3 +1,24 @@
+Tue Jan 10 23:56:01 PST 2006  Christian Hammond <chipx86 at chipx86.com>
+
+	* src/Makefile.am:
+	A src/daemon.c:
+	A src/daemon.h:
+	A src/notificationdaemon.xml:
+	D src/notifydaemon.c:
+	D src/notifydaemon.h:
+	D src/notifydaemon.xml:
+	* Makefile.am:
+	* autogen.sh:
+	* configure.ac:
+	A notification-daemon.service.in:
+	D notify-daemon.service.in:
+	  - Rename from notify-daemon to notification-daemon. I've received a
+	    number of questions and some complaints about the name change,
+	    some of which are packaging concerns, some upgrade concerns, and
+	    just general confusion and "Why?" As this is the "Desktop
+	    Notifications" project, and due to reasons expressed to me from
+	    others, I feel it's best to revert the name.
+
 Tue Jan 10 23:32:55 PST 2006  Christian Hammond <chipx86 at chipx86.com>
 
 	* src/eggnotificationbubblewidget.c:

Modified: trunk/notification-daemon/Makefile.am
===================================================================
--- trunk/notification-daemon/Makefile.am	2006-01-11 07:48:56 UTC (rev 2416)
+++ trunk/notification-daemon/Makefile.am	2006-01-11 07:58:22 UTC (rev 2417)
@@ -1,14 +1,14 @@
 SUBDIRS = src
 
 servicedir       = $(DBUS_SERVICES_DIR)
-service_DATA     = notify-daemon.service
+service_DATA     = notification-daemon.service
 
 EXTRA_DIST = \
 	AUTHORS NEWS INSTALL COPYING README \
 	ChangeLog \
 	autogen.sh \
 	configure.ac \
-	notify-daemon.service
+	notification-daemon.service
 
 $(OBJECTS): libtool
 libtool: $(LIBTOOL_DEPS)

Modified: trunk/notification-daemon/autogen.sh
===================================================================
--- trunk/notification-daemon/autogen.sh	2006-01-11 07:48:56 UTC (rev 2416)
+++ trunk/notification-daemon/autogen.sh	2006-01-11 07:58:22 UTC (rev 2417)
@@ -3,7 +3,7 @@
 
 DIE=0
 
-PACKAGE=notify-daemon
+PACKAGE=notification-daemon
 
 echo "Generating configuration files for $PACKAGE, please wait..."
 

Modified: trunk/notification-daemon/configure.ac
===================================================================
--- trunk/notification-daemon/configure.ac	2006-01-11 07:48:56 UTC (rev 2416)
+++ trunk/notification-daemon/configure.ac	2006-01-11 07:58:22 UTC (rev 2417)
@@ -3,7 +3,7 @@
 dnl ################################################################
 dnl # Initialize autoconf
 dnl ################################################################
-AC_INIT(notify-daemon, 0.3.1, johnp at redhat.com)
+AC_INIT(notification-daemon, 0.3.1, galago-devel at lists.freedesktop.org)
 AC_PREREQ(2.50)
 AC_CONFIG_SRCDIR(config.h.in)
 AC_COPYRIGHT([Copyright 2005 John (J5) Palmieri])
@@ -12,36 +12,36 @@
 dnl ################################################################
 dnl # Version information
 dnl ################################################################
-NOTIFY_DAEMON_MAJOR_VERSION=0
-NOTIFY_DAEMON_MINOR_VERSION=3
-NOTIFY_DAEMON_MICRO_VERSION=1
-NOTIFY_DAEMON_DEVEL_VERSION=0
+NOTIFICATION_DAEMON_MAJOR_VERSION=0
+NOTIFICATION_DAEMON_MINOR_VERSION=3
+NOTIFICATION_DAEMON_MICRO_VERSION=1
+NOTIFICATION_DAEMON_DEVEL_VERSION=0
 
-NOTIFY_DAEMON_VERSION=$NOTIFY_DAEMON_MAJOR_VERSION.$NOTIFY_DAEMON_MINOR_VERSION.$NOTIFY_DAEMON_MICRO_VERSION
+NOTIFICATION_DAEMON_VERSION=$NOTIFICATION_DAEMON_MAJOR_VERSION.$NOTIFICATION_DAEMON_MINOR_VERSION.$NOTIFICATION_DAEMON_MICRO_VERSION
 
-if test "x$NOTIFY_DAEMON_DEVEL_VERSION" != "x0"; then
-	if test "x$NOTIFY_DAEMON_MICRO_VERSION" = "x0"; then
-		NOTIFY_DAEMON_MICRO_VERSION=$NOTIFY_DAEMON_DEVEL_VERSION
-		NOTIFY_DAEMON_VERSION=$NOTIFY_DAEMON_MAJOR_VERSION.$NOTIFY_DAEMON_MINOR_VERSION.$NOTIFY_DAEMON_DEVEL_VERSION
+if test "x$NOTIFICATION_DAEMON_DEVEL_VERSION" != "x0"; then
+	if test "x$NOTIFICATION_DAEMON_MICRO_VERSION" = "x0"; then
+		NOTIFICATION_DAEMON_MICRO_VERSION=$NOTIFICATION_DAEMON_DEVEL_VERSION
+		NOTIFICATION_DAEMON_VERSION=$NOTIFICATION_DAEMON_MAJOR_VERSION.$NOTIFICATION_DAEMON_MINOR_VERSION.$NOTIFICATION_DAEMON_DEVEL_VERSION
 	else
-		NOTIFY_DAEMON_VERSION=$NOTIFY_DAEMON_VERSION.$NOTIFY_DAEMON_DEVEL_VERSION
+		NOTIFICATION_DAEMON_VERSION=$NOTIFICATION_DAEMON_VERSION.$NOTIFICATION_DAEMON_DEVEL_VERSION
 	fi
 fi
 
-AC_DEFINE_UNQUOTED(NOTIFY_DAEMON_MAJOR_VERSION, $NOTIFY_DAEMON_MAJOR_VERSION,
-	[notify-daemon major version.])
-AC_DEFINE_UNQUOTED(NOTIFY_DAEMON_MINOR_VERSION, $NOTIFY_DAEMON_MINOR_VERSION,
-	[notify-daemon minor version.])
-AC_DEFINE_UNQUOTED(NOTIFY_DAEMON_MICRO_VERSION, $NOTIFY_DAEMON_MICRO_VERSION,
-	[notify-daemon micro version.])
-AC_DEFINE_UNQUOTED(NOTIFY_DAEMON_VERSION, "$NOTIFY_DAEMON_VERSION",
-	[notify-daemon version.])
+AC_DEFINE_UNQUOTED(NOTIFICATION_DAEMON_MAJOR_VERSION, $NOTIFICATION_DAEMON_MAJOR_VERSION,
+	[notification-daemon major version.])
+AC_DEFINE_UNQUOTED(NOTIFICATION_DAEMON_MINOR_VERSION, $NOTIFICATION_DAEMON_MINOR_VERSION,
+	[notification-daemon minor version.])
+AC_DEFINE_UNQUOTED(NOTIFICATION_DAEMON_MICRO_VERSION, $NOTIFICATION_DAEMON_MICRO_VERSION,
+	[notification-daemon micro version.])
+AC_DEFINE_UNQUOTED(NOTIFICATION_DAEMON_VERSION, "$NOTIFICATION_DAEMON_VERSION",
+	[notification-daemon version.])
 
 dnl ################################################################
 dnl # Initialize automake
 dnl ################################################################
-VERSION=$NOTIFY_DAEMON_VERSION
-PACKAGE=notify-daemon
+VERSION=$NOTIFICATION_DAEMON_VERSION
+PACKAGE=notification-daemon
 
 AM_INIT_AUTOMAKE($PACKAGE, $VERSION)
 
@@ -70,9 +70,9 @@
 
 REQ_DBUS_VERSION=0.36
 pkg_modules="gtk+-2.0 >= 2.2.2 glib-2.0 >= 2.2.2, dbus-1 >= $REQ_DBUS_VERSION, dbus-glib-1 >= $REQ_DBUS_VERSION"
-PKG_CHECK_MODULES(NOTIFY_DAEMON, [$pkg_modules])
-AC_SUBST(NOTIFY_DAEMON_CFLAGS)
-AC_SUBST(NOTIFY_DAEMON_LIBS)
+PKG_CHECK_MODULES(NOTIFICATION_DAEMON, [$pkg_modules])
+AC_SUBST(NOTIFICATION_DAEMON_CFLAGS)
+AC_SUBST(NOTIFICATION_DAEMON_LIBS)
 
 gdk_modules="gdk-2.0 gdk-pixbuf-2.0"
 PKG_CHECK_MODULES(GDK, [$gdk_modules], have_gdk=yes,
@@ -141,7 +141,7 @@
 dnl ################################################################
 AC_CONFIG_FILES([
 Makefile
-notify-daemon.service
+notification-daemon.service
 src/Makefile
 ])
 

Copied: trunk/notification-daemon/notification-daemon.service.in (from rev 2416, trunk/notification-daemon/notify-daemon.service.in)
===================================================================
--- trunk/notification-daemon/notify-daemon.service.in	2006-01-11 07:48:56 UTC (rev 2416)
+++ trunk/notification-daemon/notification-daemon.service.in	2006-01-11 07:58:22 UTC (rev 2417)
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.freedesktop.Notifications
+Exec=@LIBEXECDIR@/notification-daemon

Deleted: trunk/notification-daemon/notify-daemon.service.in
===================================================================
--- trunk/notification-daemon/notify-daemon.service.in	2006-01-11 07:48:56 UTC (rev 2416)
+++ trunk/notification-daemon/notify-daemon.service.in	2006-01-11 07:58:22 UTC (rev 2417)
@@ -1,3 +0,0 @@
-[D-BUS Service]
-Name=org.freedesktop.Notifications
-Exec=@LIBEXECDIR@/notify-daemon

Modified: trunk/notification-daemon/src/Makefile.am
===================================================================
--- trunk/notification-daemon/src/Makefile.am	2006-01-11 07:48:56 UTC (rev 2416)
+++ trunk/notification-daemon/src/Makefile.am	2006-01-11 07:58:22 UTC (rev 2417)
@@ -1,18 +1,18 @@
-INCLUDES=-I$(top_srcdir) $(NOTIFY_DAEMON_CFLAGS)
+INCLUDES = -I$(top_srcdir) $(NOTIFICATION_DAEMON_CFLAGS)
 
-EXTRA_DIST=notifydaemon.xml
+EXTRA_DIST = notificationdaemon.xml
 
-libexec_PROGRAMS = notify-daemon
+libexec_PROGRAMS = notification-daemon
 
-notify_daemon_SOURCES=		\
+notification_daemon_SOURCES =		\
 	eggnotificationbubblewidget.c	\
 	eggnotificationbubblewidget.h	\
-	notifydaemon.c			\
-	notifydaemon.h
+	daemon.c			\
+	daemon.h
 
-notify_daemon_LDADD= $(NOTIFY_DAEMON_LIBS)
+notification_daemon_LDADD = $(NOTIFICATION_DAEMON_LIBS)
 
-BUILT_SOURCES = notifydaemon-dbus-glue.h
+BUILT_SOURCES = notificationdaemon-dbus-glue.h
 
-notifydaemon-dbus-glue.h: notifydaemon.xml
-	dbus-binding-tool --mode=glib-server $(srcdir)/notifydaemon.xml > notifydaemon-dbus-glue.h
+notificationdaemon-dbus-glue.h: notificationdaemon.xml
+	dbus-binding-tool --mode=glib-server $(srcdir)/notificationdaemon.xml > notificationdaemon-dbus-glue.h

Copied: trunk/notification-daemon/src/daemon.c (from rev 2416, trunk/notification-daemon/src/notifydaemon.c)
===================================================================
--- trunk/notification-daemon/src/notifydaemon.c	2006-01-11 07:48:56 UTC (rev 2416)
+++ trunk/notification-daemon/src/daemon.c	2006-01-11 07:58:22 UTC (rev 2417)
@@ -0,0 +1,849 @@
+/* notifydaemon.c - Implementation of the destop notification spec
+ *
+ * Copyright (C) 2005 John (J5) Palmieri <johnp at redhat.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.  
+ */
+
+#include "config.h"
+#include "daemon.h"
+#include "eggnotificationbubblewidget.h"
+#include "notificationdaemon-dbus-glue.h"
+
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <glib.h>
+#include <glib-object.h>
+#include <glib/gi18n.h>
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib.h>
+#include <gtk/gtk.h>
+
+struct _NotifyTimeout
+{
+   GTimeVal expiration;
+   gboolean has_timeout;
+   guint id;
+
+   EggNotificationBubbleWidget *widget;
+};
+
+typedef struct _NotifyTimeout NotifyTimeout;
+
+struct _NotifyDaemonPrivate
+{
+  guint next_id;
+  guint timeout_source;
+  GHashTable *notification_hash;
+  GSList *poptart_stack;
+};
+
+#define CHECK_DBUS_VERSION(major, minor) \
+	(DBUS_MAJOR_VER > (major) || \
+	 (DBUS_MAJOR_VER == (major) && DBUS_MINOR_VER >= (minor)))
+
+#if !CHECK_DBUS_VERSION(0, 60)
+/* This is a hack that will go away in time. For now, it's fairly safe. */
+struct _DBusGMethodInvocation
+{
+	DBusGConnection *connection;
+	DBusGMessage *message;
+	const DBusGObjectInfo *object;
+	const DBusGMethodInfo *method;
+};
+#endif /* D-BUS < 0.60 */
+
+static void notify_daemon_finalize (GObject * object);
+static void _emit_closed_signal (GObject *notify_widget);
+
+G_DEFINE_TYPE (NotifyDaemon, notify_daemon, G_TYPE_OBJECT);
+
+static void
+notify_daemon_class_init (NotifyDaemonClass * daemon_class)
+{
+  GObjectClass *object_class;
+
+  object_class = G_OBJECT_CLASS (daemon_class);
+
+  object_class->finalize = notify_daemon_finalize;
+
+  g_type_class_add_private (daemon_class, sizeof (NotifyDaemonPrivate));
+}
+
+static void
+_notify_timeout_destroy (NotifyTimeout *nt)
+{
+  gtk_widget_destroy ((GtkWidget *)nt->widget);
+  g_free (nt);
+}
+
+static void
+notify_daemon_init (NotifyDaemon * daemon)
+{
+  daemon->priv = G_TYPE_INSTANCE_GET_PRIVATE (daemon,
+					      NOTIFY_TYPE_DAEMON,
+					      NotifyDaemonPrivate);
+
+  daemon->priv->next_id = 1;
+  daemon->priv->timeout_source = 0;
+  daemon->priv->notification_hash = g_hash_table_new_full ((GHashFunc) g_int_hash, 
+                                                           (GEqualFunc) g_int_equal,
+                                                           (GDestroyNotify) g_free,
+                                                           (GDestroyNotify) _notify_timeout_destroy);
+}
+
+static void
+notify_daemon_finalize (GObject * object)
+{
+  NotifyDaemon *daemon;
+  GObjectClass *parent_class;
+
+  daemon = NOTIFY_DAEMON (object);
+
+  g_hash_table_destroy (daemon->priv->notification_hash);
+  g_slist_free (daemon->priv->poptart_stack);
+
+  parent_class = G_OBJECT_CLASS (notify_daemon_parent_class);
+
+  if (parent_class->finalize != NULL)
+    parent_class->finalize (object);
+}
+
+NotifyDaemon *
+notify_daemon_new (void)
+{
+  NotifyDaemon *daemon;
+
+  daemon = g_object_new (NOTIFY_TYPE_DAEMON, NULL);
+
+  return daemon;
+}
+
+static void
+_emit_action_invoked_signal (GObject *notify_widget, gchar *action)
+{
+  DBusConnection *con;
+  DBusError error;
+
+  dbus_error_init (&error);
+
+  con = dbus_bus_get (DBUS_BUS_SESSION, &error);
+
+  if (con == NULL)
+    {
+      g_warning ("Error sending ActionInvoked signal: %s", error.message);
+      dbus_error_free (&error);
+    }
+  else
+    {
+      DBusMessage *message;
+          
+      gchar *dest;
+      guint id;
+        
+      message = dbus_message_new_signal ("/org/freedesktop/Notifications", 
+                                         "org.freedesktop.Notifications",
+                                         "ActionInvoked");
+
+      dest = g_object_get_data (notify_widget,
+                                "_notify_sender");
+      id = GPOINTER_TO_UINT (g_object_get_data (notify_widget, "_notify_id"));
+
+      g_assert (dest != NULL);
+
+      dbus_message_set_destination (message, dest); 
+      dbus_message_append_args (message, 
+                                DBUS_TYPE_UINT32, &id, 
+                                DBUS_TYPE_STRING, &action,
+                                DBUS_TYPE_INVALID);
+                                 
+      dbus_connection_send (con, message, NULL);
+     
+      dbus_message_unref (message);
+      dbus_connection_unref (con);
+    }
+}
+
+static void
+_emit_closed_signal (GObject *notify_widget)
+{
+  DBusConnection *con;
+  DBusError error;
+
+  dbus_error_init (&error);
+
+  con = dbus_bus_get (DBUS_BUS_SESSION, &error);
+
+  if (con == NULL)
+    {
+      g_warning ("Error sending Close signal: %s", error.message);
+      dbus_error_free (&error);
+    }
+  else
+    {
+      DBusMessage *message;
+          
+      gchar *dest;
+      guint id;
+        
+      message = dbus_message_new_signal ("/org/freedesktop/Notifications", 
+                                         "org.freedesktop.Notifications",
+                                         "NotificationClosed");
+
+      dest = g_object_get_data (notify_widget,
+                                "_notify_sender");
+      id = GPOINTER_TO_UINT (g_object_get_data (notify_widget,
+                                                "_notify_id"));
+
+      g_assert (dest != NULL);
+
+      dbus_message_set_destination (message, dest); 
+      dbus_message_append_args (message, 
+                                DBUS_TYPE_UINT32, &id,
+                                DBUS_TYPE_INVALID);
+                                 
+      dbus_connection_send (con, message, NULL);
+     
+      dbus_message_unref (message);
+      dbus_connection_unref (con);
+    }
+}
+
+static void
+_close_notification (NotifyDaemon *daemon, 
+                     guint id)
+{
+  NotifyDaemonPrivate *priv;
+  NotifyTimeout *nt;
+
+  priv = daemon->priv;
+
+  nt = (NotifyTimeout *)
+          g_hash_table_lookup (priv->notification_hash, &id);
+
+  if (nt)
+    {
+      _emit_closed_signal (G_OBJECT (nt->widget));
+
+      egg_notification_bubble_widget_hide (nt->widget);
+      g_hash_table_remove (priv->notification_hash, &id);
+    }
+}
+
+
+static gboolean
+_is_expired (gpointer key,
+             gpointer value,
+             gpointer data)
+{
+  NotifyTimeout *nt;
+  gboolean *phas_more_timeouts;
+  GTimeVal now;
+  GTimeVal expiration;
+
+  nt = (NotifyTimeout *) value;
+  phas_more_timeouts = data;
+
+  if (!nt->has_timeout)
+    return FALSE;
+
+  g_get_current_time (&now);
+  expiration = nt->expiration;
+
+  if (now.tv_sec > expiration.tv_sec)
+    {
+      _emit_closed_signal (G_OBJECT (nt->widget));
+      return TRUE;
+    }
+  else if (now.tv_sec == expiration.tv_sec)
+    {
+      if (now.tv_usec > expiration.tv_usec)
+        {
+          _emit_closed_signal (G_OBJECT (nt->widget));
+          return TRUE;
+        }
+    }
+
+  *phas_more_timeouts = TRUE;
+  
+  return FALSE;
+}
+
+static gboolean
+_check_expiration (gpointer data)
+{
+  NotifyDaemon *daemon;
+  gboolean has_more_timeouts;
+
+  has_more_timeouts = FALSE;
+
+  daemon = (NotifyDaemon *) data;
+
+  g_hash_table_foreach_remove (daemon->priv->notification_hash, 
+                                (GHRFunc) _is_expired, 
+                                (gpointer) &has_more_timeouts);
+
+  if (!has_more_timeouts)
+    daemon->priv->timeout_source = 0;
+
+  return has_more_timeouts;
+
+}
+
+static void
+_calculate_timeout (NotifyDaemon *daemon, NotifyTimeout *nt, int timeout)
+{
+  if (timeout == 0)
+      nt->has_timeout = FALSE;
+  else
+    {
+      gulong usec;
+    
+      nt->has_timeout = TRUE;
+      if (timeout == -1)
+        timeout = NOTIFY_DAEMON_DEFAULT_TIMEOUT;
+
+      usec = timeout * 1000; /* convert from msec to usec */
+      g_get_current_time (&nt->expiration);
+      g_time_val_add (&nt->expiration, usec);
+      
+      if (daemon->priv->timeout_source == 0)
+        daemon->priv->timeout_source = 
+          g_timeout_add (500, 
+                         (GSourceFunc) _check_expiration, 
+                         (gpointer) daemon);
+    }
+
+}
+
+static guint
+_store_notification (NotifyDaemon *daemon, 
+                     EggNotificationBubbleWidget *bw,
+                     int timeout)
+{
+  NotifyDaemonPrivate *priv;
+  NotifyTimeout *nt;
+  guint id;
+  priv = daemon->priv;
+  id = 0;
+
+  do 
+    {
+      id = priv->next_id;
+
+      if (id != UINT_MAX)
+        priv->next_id++;
+      else
+        priv->next_id = 1;
+
+      if (g_hash_table_lookup (priv->notification_hash, &id) != NULL)
+        id = 0;
+    }
+  while (id == 0);
+  
+  nt = (NotifyTimeout *) g_new0(NotifyTimeout, 1);
+
+  nt->id = id;
+  nt->widget = bw;
+  
+  _calculate_timeout (daemon, nt, timeout);
+  
+  g_hash_table_insert (priv->notification_hash, 
+                       g_memdup(&id, sizeof (guint)), 
+                       (gpointer) nt);
+
+  return id;
+}
+
+static gboolean 
+_notify_daemon_process_icon_data (NotifyDaemon *daemon, 
+                                  EggNotificationBubbleWidget *bw,
+                                  GValue *icon_data)
+{
+  const guchar *data;
+  gboolean has_alpha;
+  int bits_per_sample;
+  int width;
+  int height;
+  int rowstride;
+  int n_channels;
+  gsize expected_len;
+  
+  GValueArray *image_struct;
+  GValue *value;
+  GArray *tmp_array;
+ 
+  data = NULL;
+ 
+  if (!G_VALUE_HOLDS (icon_data, G_TYPE_VALUE_ARRAY))
+    {
+      g_warning ("_notify_daemon_process_icon_data expected a GValue of type GValueArray");
+      return FALSE;
+    }
+ 
+  image_struct = (GValueArray *) (g_value_get_boxed (icon_data));
+  
+  value = g_value_array_get_nth (image_struct, 0);
+  if (!value)
+    {
+      g_warning ("_notify_daemon_process_icon_data expected possition 0 of the GValueArray to exist");
+      return FALSE;
+    }
+
+  if (!G_VALUE_HOLDS (value, G_TYPE_INT))
+    {
+      g_warning ("_notify_daemon_process_icon_data expected possition 0 of the GValueArray to be of type int");
+      return FALSE;
+    }
+
+  width = g_value_get_int (value);
+  
+  value = g_value_array_get_nth (image_struct, 1);
+  if (!value)
+    {
+      g_warning ("_notify_daemon_process_icon_data expected possition 1 of the GValueArray to exist");
+      return FALSE;
+    }
+
+  if (!G_VALUE_HOLDS (value, G_TYPE_INT))
+    {
+      g_warning ("_notify_daemon_process_icon_data expected possition 1 of the GValueArray to be of type int");
+      return FALSE;
+    }
+
+  height = g_value_get_int (value);
+
+  value = g_value_array_get_nth (image_struct, 2);
+  if (!value)
+    {
+      g_warning ("_notify_daemon_process_icon_data expected possition 2 of the GValueArray to exist");
+      return FALSE;
+    }
+
+  if (!G_VALUE_HOLDS (value, G_TYPE_INT))
+    {
+      g_warning ("_notify_daemon_process_icon_data expected possition 2 of the GValueArray to be of type int");
+      return FALSE;
+    }
+
+  rowstride = g_value_get_int (value);
+
+  value = g_value_array_get_nth (image_struct, 3);
+  if (!value)
+    {
+      g_warning ("_notify_daemon_process_icon_data expected possition 3 of the GValueArray to exist");
+      return FALSE;
+    }
+
+  if (!G_VALUE_HOLDS (value, G_TYPE_BOOLEAN))
+    {
+      g_warning ("_notify_daemon_process_icon_data expected possition 3 of the GValueArray to be of type gboolean");
+      return FALSE;
+    }
+
+  has_alpha = g_value_get_boolean (value);
+
+  value = g_value_array_get_nth (image_struct, 4);
+  if (!value)
+    {
+      g_warning ("_notify_daemon_process_icon_data expected possition 4 of the GValueArray to exist");
+      return FALSE;
+    }
+
+  if (!G_VALUE_HOLDS (value, G_TYPE_INT))
+    {
+      g_warning ("_notify_daemon_process_icon_data expected possition 4 of the GValueArray to be of type int");
+      return FALSE;
+    }
+
+  bits_per_sample = g_value_get_int (value);
+
+  value = g_value_array_get_nth (image_struct, 5);
+  if (!value)
+    {
+      g_warning ("_notify_daemon_process_icon_data expected possition 5 of the GValueArray to exist");
+      return FALSE;
+    }
+
+  if (!G_VALUE_HOLDS (value, G_TYPE_INT))
+    {
+      g_warning ("_notify_daemon_process_icon_data expected possition 5 of the GValueArray to be of type int");
+      return FALSE;
+    }
+
+  n_channels = g_value_get_int (value);
+
+
+  value = g_value_array_get_nth (image_struct, 6);
+  if (!value)
+    {
+      g_warning ("_notify_daemon_process_icon_data expected possition 6 of the GValueArray to exist");
+      return FALSE;
+    }
+
+  if (!G_VALUE_HOLDS (value, dbus_g_type_get_collection ("GArray", G_TYPE_UCHAR)))
+    {
+      g_warning ("_notify_daemon_process_icon_data expected possition 6 of the GValueArray to be of type GArray");
+      return FALSE;
+    }
+
+  tmp_array = (GArray *) g_value_get_boxed (value);  
+  expected_len = (height -1) * rowstride + width * ((n_channels * bits_per_sample + 7) / 8);
+
+  if (expected_len != tmp_array->len)
+    {
+      g_warning ("_notify_daemon_process_icon_data expected image data to be of length %i but got a length of %i", expected_len, tmp_array->len);
+      return FALSE;
+    }
+
+  data = (guchar *)g_memdup (tmp_array->data, tmp_array->len);
+
+  egg_notification_bubble_widget_set_icon_from_data (bw,
+                                                     data,
+                                                     has_alpha,
+                                                     bits_per_sample,
+                                                     width,
+                                                     height,
+                                                     rowstride);
+  return TRUE;
+}
+
+static void
+_notification_daemon_handle_bubble_widget_action (GtkWidget *b, 
+                                                  EggNotificationBubbleWidget *bw)
+{
+  gchar *action;
+
+  action = (gchar *) g_object_get_data (G_OBJECT (b), "_notify_action");
+
+  _emit_action_invoked_signal (G_OBJECT (bw), action);  
+}
+
+static void
+_notification_daemon_handle_bubble_widget_default (EggNotificationBubbleWidget *bw,
+                                                   NotifyDaemon *daemon)
+{
+  _close_notification (daemon, GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (bw), "_notify_id")));
+}
+
+static void
+_remove_bubble_from_poptart_stack (EggNotificationBubbleWidget *bw,
+                                   NotifyDaemon *daemon)
+{
+  NotifyDaemonPrivate *priv;
+  GdkRectangle workarea;
+  GSList *remove_link;
+  GSList *link;
+
+  gint x, y;
+  
+  priv = daemon->priv;
+
+  link = priv->poptart_stack;
+  remove_link = NULL;
+
+  workarea.x = 0;
+  workarea.y = 0;
+  workarea.width  = gdk_screen_width();
+  workarea.height = gdk_screen_height();
+
+  y = workarea.y + workarea.height;
+  x = 0;
+  while (link)
+    {
+      EggNotificationBubbleWidget *b;
+      GtkRequisition req;
+
+      b = EGG_NOTIFICATION_BUBBLE_WIDGET (link->data);
+      if (b != bw)
+        {
+          printf ("dude\n");
+ 
+          gtk_widget_size_request (GTK_WIDGET (b), &req);
+
+          x = workarea.x + workarea.width - req.width;
+          y = y - req.height;
+
+          egg_notification_bubble_widget_set_pos (b, x, y);
+        }
+      else 
+        {
+          remove_link = link;
+        }
+
+      link = link->next;
+    }
+
+    if (remove_link)
+      priv->poptart_stack = g_slist_remove_link (priv->poptart_stack, remove_link);
+}
+
+static void
+_notify_daemon_add_bubble_to_poptart_stack (NotifyDaemon *daemon, 
+                                            EggNotificationBubbleWidget *bw)
+{
+  NotifyDaemonPrivate *priv;
+  GtkRequisition req;
+  GdkRectangle workarea;
+  GSList *link;
+  gint x, y;  
+
+  priv = daemon->priv;
+ 
+  gtk_widget_size_request (GTK_WIDGET (bw), &req);
+
+  workarea.x = 0;
+  workarea.y = 0;
+  workarea.width  = gdk_screen_width();
+  workarea.height = gdk_screen_height();
+
+  x = workarea.x + workarea.width - req.width;
+  y = workarea.y + workarea.height - req.height;
+
+  g_message ("x %i y %i width %i height %i", x, y, req.width, req.height);
+
+  egg_notification_bubble_widget_set_pos (bw, x, y);
+
+  link = priv->poptart_stack;
+  while (link)
+    {
+      EggNotificationBubbleWidget *b;
+
+      b = EGG_NOTIFICATION_BUBBLE_WIDGET (link->data);
+      gtk_widget_size_request (GTK_WIDGET (b), &req);
+
+      x = workarea.x + workarea.width - req.width;
+      y = y - req.height;
+      g_message ("x %i y %i width %i height %i", x, y, req.width, req.height);
+      egg_notification_bubble_widget_set_pos (b, x, y);
+
+      link = link->next;
+    }
+
+  g_signal_connect(G_OBJECT(bw), "destroy",
+				   G_CALLBACK(_remove_bubble_from_poptart_stack), daemon);
+  priv->poptart_stack = g_slist_prepend (priv->poptart_stack, bw); 
+}
+
+
+
+gboolean 
+notify_daemon_notify_handler (NotifyDaemon *daemon,
+                              const gchar *app_name,
+                              const gchar *icon,
+                              guint id,
+                              const gchar *summary,
+                              const gchar *body,
+                              gchar **actions,
+                              GHashTable *hints,
+                              int timeout,
+                              DBusGMethodInvocation *context)
+{
+  NotifyDaemonPrivate *priv;
+  NotifyTimeout *nt;
+  EggNotificationBubbleWidget *bw;
+  GValue *data;
+  gboolean use_pos_data;
+  gint x, y;
+  guint return_id;
+  gchar *sender;
+  gint i;
+
+  x = 0;
+  y = 0;
+
+  nt = NULL;
+
+  priv = daemon->priv;
+  bw = NULL;
+  if (id > 0)
+    nt = (NotifyTimeout *) 
+           g_hash_table_lookup (priv->notification_hash, &id);
+
+  if (!nt)
+    {
+      bw = egg_notification_bubble_widget_new ();
+      id = 0;
+    }
+  else
+    bw = nt->widget;
+
+  use_pos_data = FALSE;
+
+  egg_notification_bubble_widget_set (bw, summary, icon, body);
+ 
+  /* deal with x, and y hints */
+  data = (GValue *) (g_hash_table_lookup (hints, "x"));
+  if (data)
+    {
+      x = g_value_get_int (data);
+      data = (GValue *) g_hash_table_lookup (hints, "y");
+
+      if (data)
+        {
+          y = g_value_get_int (data);
+          use_pos_data = TRUE;       
+        }
+    }
+
+  /* set up action buttons */
+  i = 0;
+  while (actions[i] != NULL)
+    {
+      gchar *l;
+      GtkWidget *b;
+
+      l = actions[i + 1];
+      if (l == NULL)
+        {
+          g_warning ("Label not found for action %s. "
+                     "The protocol specifies that a label must "
+                     "follow an action in the actions array", actions[i]);
+
+          break;
+        }
+
+      b = egg_notification_bubble_widget_create_button (bw, l);
+       
+      g_object_set_data_full (G_OBJECT (b), 
+                              "_notify_action", 
+                              g_strdup (actions[i]), 
+                              (GDestroyNotify) g_free);
+
+      g_signal_connect (b, 
+                        "clicked",
+                        (GCallback)_notification_daemon_handle_bubble_widget_action, 
+                        bw);
+
+      i = i + 2;
+    }
+
+  if (use_pos_data)
+    {
+      egg_notification_bubble_widget_set_draw_arrow (bw, TRUE);
+      egg_notification_bubble_widget_set_pos (bw, x, y);
+    }
+  else
+    {
+      egg_notification_bubble_widget_set_draw_arrow (bw, FALSE);
+      _notify_daemon_add_bubble_to_poptart_stack (daemon, bw);
+    }
+
+  /* check for icon_data if icon == "" */
+  if (strcmp ("", icon) == 0)
+    {
+      data = (GValue *) (g_hash_table_lookup (hints, "icon_data"));
+      if (data)
+        _notify_daemon_process_icon_data (daemon, bw, data);
+    }
+
+  g_signal_connect (bw, "clicked", (GCallback)_notification_daemon_handle_bubble_widget_default, daemon);  
+
+  egg_notification_bubble_widget_show (bw);
+
+  if (id == 0)
+    return_id = _store_notification (daemon, bw, timeout);
+  else
+    return_id = id;
+
+#if CHECK_DBUS_VERSION(0, 60)
+  sender = dbus_g_method_get_sender (context);
+#else
+  sender = g_strdup(dbus_message_get_sender(
+	dbus_g_message_get_message(context->message)));
+#endif
+
+  g_object_set_data (G_OBJECT (bw), "_notify_id", GUINT_TO_POINTER (return_id));
+  g_object_set_data_full (G_OBJECT (bw), 
+                          "_notify_sender", 
+                          sender, 
+                          (GDestroyNotify) g_free);
+
+  if (nt)
+    _calculate_timeout (daemon, nt, timeout);
+
+  dbus_g_method_return (context, return_id);
+
+  return TRUE;
+}
+
+gboolean 
+notify_daemon_close_notification_handler (NotifyDaemon *daemon,
+                                          guint id,
+                                          GError **error)
+{
+  _close_notification (daemon, id);
+
+  return TRUE;
+}
+
+int
+main (int argc, char **argv)
+{
+  NotifyDaemon *daemon;
+  DBusGConnection *connection;
+  DBusGProxy *bus_proxy;
+  GError *error;
+  guint request_name_result;
+  g_log_set_always_fatal (G_LOG_LEVEL_ERROR
+			  | G_LOG_LEVEL_CRITICAL);
+
+  g_message ("initializing glib type system");
+  gtk_init (&argc, &argv);
+
+  error = NULL;
+  connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+
+  if (connection == NULL)
+    {
+      g_printerr ("Failed to open connection to bus: %s\n",
+                  error->message);
+      g_error_free (error);
+      exit (1);
+    }
+
+  g_message ("register 'daemon' type with dbus-glib...");
+  dbus_g_object_type_install_info (NOTIFY_TYPE_DAEMON, &dbus_glib__object_info);
+  g_message ("'daemon' successfully registered");
+
+  bus_proxy = dbus_g_proxy_new_for_name (connection, "org.freedesktop.DBus",
+                                         "/org/freedesktop/DBus",
+                                         "org.freedesktop.DBus");
+
+  if (!dbus_g_proxy_call (bus_proxy, "RequestName", &error,
+                          G_TYPE_STRING, "org.freedesktop.Notifications",
+                          G_TYPE_UINT, 0,
+                          G_TYPE_INVALID,
+                          G_TYPE_UINT, &request_name_result,
+                          G_TYPE_INVALID))
+    g_error ("Could not aquire name: %s", error->message);
+
+  g_message ("creating instance of 'daemon' object...");
+  daemon = notify_daemon_new ();
+  g_message ("'daemon' object created successfully");
+
+  g_message ("exporting instance of 'daemon' object over the bus...");
+  dbus_g_connection_register_g_object (connection, "/org/freedesktop/Notifications", G_OBJECT (daemon));
+  g_message ("'daemon' object exported successfully");
+
+  gtk_main();
+
+  return 0;
+}
+

Copied: trunk/notification-daemon/src/daemon.h (from rev 2416, trunk/notification-daemon/src/notifydaemon.h)

Copied: trunk/notification-daemon/src/notificationdaemon.xml (from rev 2416, trunk/notification-daemon/src/notifydaemon.xml)

Deleted: trunk/notification-daemon/src/notifydaemon.c
===================================================================
--- trunk/notification-daemon/src/notifydaemon.c	2006-01-11 07:48:56 UTC (rev 2416)
+++ trunk/notification-daemon/src/notifydaemon.c	2006-01-11 07:58:22 UTC (rev 2417)
@@ -1,849 +0,0 @@
-/* notifydaemon.c - Implementation of the destop notification spec
- *
- * Copyright (C) 2005 John (J5) Palmieri <johnp at redhat.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.  
- */
-
-#include "config.h"
-#include "notifydaemon.h"
-#include "eggnotificationbubblewidget.h"
-#include "notifydaemon-dbus-glue.h"
-
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <stdio.h>
-
-#include <glib.h>
-#include <glib-object.h>
-#include <glib/gi18n.h>
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib.h>
-#include <gtk/gtk.h>
-
-struct _NotifyTimeout
-{
-   GTimeVal expiration;
-   gboolean has_timeout;
-   guint id;
-
-   EggNotificationBubbleWidget *widget;
-};
-
-typedef struct _NotifyTimeout NotifyTimeout;
-
-struct _NotifyDaemonPrivate
-{
-  guint next_id;
-  guint timeout_source;
-  GHashTable *notification_hash;
-  GSList *poptart_stack;
-};
-
-#define CHECK_DBUS_VERSION(major, minor) \
-	(DBUS_MAJOR_VER > (major) || \
-	 (DBUS_MAJOR_VER == (major) && DBUS_MINOR_VER >= (minor)))
-
-#if !CHECK_DBUS_VERSION(0, 60)
-/* This is a hack that will go away in time. For now, it's fairly safe. */
-struct _DBusGMethodInvocation
-{
-	DBusGConnection *connection;
-	DBusGMessage *message;
-	const DBusGObjectInfo *object;
-	const DBusGMethodInfo *method;
-};
-#endif /* D-BUS < 0.60 */
-
-static void notify_daemon_finalize (GObject * object);
-static void _emit_closed_signal (GObject *notify_widget);
-
-G_DEFINE_TYPE (NotifyDaemon, notify_daemon, G_TYPE_OBJECT);
-
-static void
-notify_daemon_class_init (NotifyDaemonClass * daemon_class)
-{
-  GObjectClass *object_class;
-
-  object_class = G_OBJECT_CLASS (daemon_class);
-
-  object_class->finalize = notify_daemon_finalize;
-
-  g_type_class_add_private (daemon_class, sizeof (NotifyDaemonPrivate));
-}
-
-static void
-_notify_timeout_destroy (NotifyTimeout *nt)
-{
-  gtk_widget_destroy ((GtkWidget *)nt->widget);
-  g_free (nt);
-}
-
-static void
-notify_daemon_init (NotifyDaemon * daemon)
-{
-  daemon->priv = G_TYPE_INSTANCE_GET_PRIVATE (daemon,
-					      NOTIFY_TYPE_DAEMON,
-					      NotifyDaemonPrivate);
-
-  daemon->priv->next_id = 1;
-  daemon->priv->timeout_source = 0;
-  daemon->priv->notification_hash = g_hash_table_new_full ((GHashFunc) g_int_hash, 
-                                                           (GEqualFunc) g_int_equal,
-                                                           (GDestroyNotify) g_free,
-                                                           (GDestroyNotify) _notify_timeout_destroy);
-}
-
-static void
-notify_daemon_finalize (GObject * object)
-{
-  NotifyDaemon *daemon;
-  GObjectClass *parent_class;
-
-  daemon = NOTIFY_DAEMON (object);
-
-  g_hash_table_destroy (daemon->priv->notification_hash);
-  g_slist_free (daemon->priv->poptart_stack);
-
-  parent_class = G_OBJECT_CLASS (notify_daemon_parent_class);
-
-  if (parent_class->finalize != NULL)
-    parent_class->finalize (object);
-}
-
-NotifyDaemon *
-notify_daemon_new (void)
-{
-  NotifyDaemon *daemon;
-
-  daemon = g_object_new (NOTIFY_TYPE_DAEMON, NULL);
-
-  return daemon;
-}
-
-static void
-_emit_action_invoked_signal (GObject *notify_widget, gchar *action)
-{
-  DBusConnection *con;
-  DBusError error;
-
-  dbus_error_init (&error);
-
-  con = dbus_bus_get (DBUS_BUS_SESSION, &error);
-
-  if (con == NULL)
-    {
-      g_warning ("Error sending ActionInvoked signal: %s", error.message);
-      dbus_error_free (&error);
-    }
-  else
-    {
-      DBusMessage *message;
-          
-      gchar *dest;
-      guint id;
-        
-      message = dbus_message_new_signal ("/org/freedesktop/Notifications", 
-                                         "org.freedesktop.Notifications",
-                                         "ActionInvoked");
-
-      dest = g_object_get_data (notify_widget,
-                                "_notify_sender");
-      id = GPOINTER_TO_UINT (g_object_get_data (notify_widget, "_notify_id"));
-
-      g_assert (dest != NULL);
-
-      dbus_message_set_destination (message, dest); 
-      dbus_message_append_args (message, 
-                                DBUS_TYPE_UINT32, &id, 
-                                DBUS_TYPE_STRING, &action,
-                                DBUS_TYPE_INVALID);
-                                 
-      dbus_connection_send (con, message, NULL);
-     
-      dbus_message_unref (message);
-      dbus_connection_unref (con);
-    }
-}
-
-static void
-_emit_closed_signal (GObject *notify_widget)
-{
-  DBusConnection *con;
-  DBusError error;
-
-  dbus_error_init (&error);
-
-  con = dbus_bus_get (DBUS_BUS_SESSION, &error);
-
-  if (con == NULL)
-    {
-      g_warning ("Error sending Close signal: %s", error.message);
-      dbus_error_free (&error);
-    }
-  else
-    {
-      DBusMessage *message;
-          
-      gchar *dest;
-      guint id;
-        
-      message = dbus_message_new_signal ("/org/freedesktop/Notifications", 
-                                         "org.freedesktop.Notifications",
-                                         "NotificationClosed");
-
-      dest = g_object_get_data (notify_widget,
-                                "_notify_sender");
-      id = GPOINTER_TO_UINT (g_object_get_data (notify_widget,
-                                                "_notify_id"));
-
-      g_assert (dest != NULL);
-
-      dbus_message_set_destination (message, dest); 
-      dbus_message_append_args (message, 
-                                DBUS_TYPE_UINT32, &id,
-                                DBUS_TYPE_INVALID);
-                                 
-      dbus_connection_send (con, message, NULL);
-     
-      dbus_message_unref (message);
-      dbus_connection_unref (con);
-    }
-}
-
-static void
-_close_notification (NotifyDaemon *daemon, 
-                     guint id)
-{
-  NotifyDaemonPrivate *priv;
-  NotifyTimeout *nt;
-
-  priv = daemon->priv;
-
-  nt = (NotifyTimeout *)
-          g_hash_table_lookup (priv->notification_hash, &id);
-
-  if (nt)
-    {
-      _emit_closed_signal (G_OBJECT (nt->widget));
-
-      egg_notification_bubble_widget_hide (nt->widget);
-      g_hash_table_remove (priv->notification_hash, &id);
-    }
-}
-
-
-static gboolean
-_is_expired (gpointer key,
-             gpointer value,
-             gpointer data)
-{
-  NotifyTimeout *nt;
-  gboolean *phas_more_timeouts;
-  GTimeVal now;
-  GTimeVal expiration;
-
-  nt = (NotifyTimeout *) value;
-  phas_more_timeouts = data;
-
-  if (!nt->has_timeout)
-    return FALSE;
-
-  g_get_current_time (&now);
-  expiration = nt->expiration;
-
-  if (now.tv_sec > expiration.tv_sec)
-    {
-      _emit_closed_signal (G_OBJECT (nt->widget));
-      return TRUE;
-    }
-  else if (now.tv_sec == expiration.tv_sec)
-    {
-      if (now.tv_usec > expiration.tv_usec)
-        {
-          _emit_closed_signal (G_OBJECT (nt->widget));
-          return TRUE;
-        }
-    }
-
-  *phas_more_timeouts = TRUE;
-  
-  return FALSE;
-}
-
-static gboolean
-_check_expiration (gpointer data)
-{
-  NotifyDaemon *daemon;
-  gboolean has_more_timeouts;
-
-  has_more_timeouts = FALSE;
-
-  daemon = (NotifyDaemon *) data;
-
-  g_hash_table_foreach_remove (daemon->priv->notification_hash, 
-                                (GHRFunc) _is_expired, 
-                                (gpointer) &has_more_timeouts);
-
-  if (!has_more_timeouts)
-    daemon->priv->timeout_source = 0;
-
-  return has_more_timeouts;
-
-}
-
-static void
-_calculate_timeout (NotifyDaemon *daemon, NotifyTimeout *nt, int timeout)
-{
-  if (timeout == 0)
-      nt->has_timeout = FALSE;
-  else
-    {
-      gulong usec;
-    
-      nt->has_timeout = TRUE;
-      if (timeout == -1)
-        timeout = NOTIFY_DAEMON_DEFAULT_TIMEOUT;
-
-      usec = timeout * 1000; /* convert from msec to usec */
-      g_get_current_time (&nt->expiration);
-      g_time_val_add (&nt->expiration, usec);
-      
-      if (daemon->priv->timeout_source == 0)
-        daemon->priv->timeout_source = 
-          g_timeout_add (500, 
-                         (GSourceFunc) _check_expiration, 
-                         (gpointer) daemon);
-    }
-
-}
-
-static guint
-_store_notification (NotifyDaemon *daemon, 
-                     EggNotificationBubbleWidget *bw,
-                     int timeout)
-{
-  NotifyDaemonPrivate *priv;
-  NotifyTimeout *nt;
-  guint id;
-  priv = daemon->priv;
-  id = 0;
-
-  do 
-    {
-      id = priv->next_id;
-
-      if (id != UINT_MAX)
-        priv->next_id++;
-      else
-        priv->next_id = 1;
-
-      if (g_hash_table_lookup (priv->notification_hash, &id) != NULL)
-        id = 0;
-    }
-  while (id == 0);
-  
-  nt = (NotifyTimeout *) g_new0(NotifyTimeout, 1);
-
-  nt->id = id;
-  nt->widget = bw;
-  
-  _calculate_timeout (daemon, nt, timeout);
-  
-  g_hash_table_insert (priv->notification_hash, 
-                       g_memdup(&id, sizeof (guint)), 
-                       (gpointer) nt);
-
-  return id;
-}
-
-static gboolean 
-_notify_daemon_process_icon_data (NotifyDaemon *daemon, 
-                                  EggNotificationBubbleWidget *bw,
-                                  GValue *icon_data)
-{
-  const guchar *data;
-  gboolean has_alpha;
-  int bits_per_sample;
-  int width;
-  int height;
-  int rowstride;
-  int n_channels;
-  gsize expected_len;
-  
-  GValueArray *image_struct;
-  GValue *value;
-  GArray *tmp_array;
- 
-  data = NULL;
- 
-  if (!G_VALUE_HOLDS (icon_data, G_TYPE_VALUE_ARRAY))
-    {
-      g_warning ("_notify_daemon_process_icon_data expected a GValue of type GValueArray");
-      return FALSE;
-    }
- 
-  image_struct = (GValueArray *) (g_value_get_boxed (icon_data));
-  
-  value = g_value_array_get_nth (image_struct, 0);
-  if (!value)
-    {
-      g_warning ("_notify_daemon_process_icon_data expected possition 0 of the GValueArray to exist");
-      return FALSE;
-    }
-
-  if (!G_VALUE_HOLDS (value, G_TYPE_INT))
-    {
-      g_warning ("_notify_daemon_process_icon_data expected possition 0 of the GValueArray to be of type int");
-      return FALSE;
-    }
-
-  width = g_value_get_int (value);
-  
-  value = g_value_array_get_nth (image_struct, 1);
-  if (!value)
-    {
-      g_warning ("_notify_daemon_process_icon_data expected possition 1 of the GValueArray to exist");
-      return FALSE;
-    }
-
-  if (!G_VALUE_HOLDS (value, G_TYPE_INT))
-    {
-      g_warning ("_notify_daemon_process_icon_data expected possition 1 of the GValueArray to be of type int");
-      return FALSE;
-    }
-
-  height = g_value_get_int (value);
-
-  value = g_value_array_get_nth (image_struct, 2);
-  if (!value)
-    {
-      g_warning ("_notify_daemon_process_icon_data expected possition 2 of the GValueArray to exist");
-      return FALSE;
-    }
-
-  if (!G_VALUE_HOLDS (value, G_TYPE_INT))
-    {
-      g_warning ("_notify_daemon_process_icon_data expected possition 2 of the GValueArray to be of type int");
-      return FALSE;
-    }
-
-  rowstride = g_value_get_int (value);
-
-  value = g_value_array_get_nth (image_struct, 3);
-  if (!value)
-    {
-      g_warning ("_notify_daemon_process_icon_data expected possition 3 of the GValueArray to exist");
-      return FALSE;
-    }
-
-  if (!G_VALUE_HOLDS (value, G_TYPE_BOOLEAN))
-    {
-      g_warning ("_notify_daemon_process_icon_data expected possition 3 of the GValueArray to be of type gboolean");
-      return FALSE;
-    }
-
-  has_alpha = g_value_get_boolean (value);
-
-  value = g_value_array_get_nth (image_struct, 4);
-  if (!value)
-    {
-      g_warning ("_notify_daemon_process_icon_data expected possition 4 of the GValueArray to exist");
-      return FALSE;
-    }
-
-  if (!G_VALUE_HOLDS (value, G_TYPE_INT))
-    {
-      g_warning ("_notify_daemon_process_icon_data expected possition 4 of the GValueArray to be of type int");
-      return FALSE;
-    }
-
-  bits_per_sample = g_value_get_int (value);
-
-  value = g_value_array_get_nth (image_struct, 5);
-  if (!value)
-    {
-      g_warning ("_notify_daemon_process_icon_data expected possition 5 of the GValueArray to exist");
-      return FALSE;
-    }
-
-  if (!G_VALUE_HOLDS (value, G_TYPE_INT))
-    {
-      g_warning ("_notify_daemon_process_icon_data expected possition 5 of the GValueArray to be of type int");
-      return FALSE;
-    }
-
-  n_channels = g_value_get_int (value);
-
-
-  value = g_value_array_get_nth (image_struct, 6);
-  if (!value)
-    {
-      g_warning ("_notify_daemon_process_icon_data expected possition 6 of the GValueArray to exist");
-      return FALSE;
-    }
-
-  if (!G_VALUE_HOLDS (value, dbus_g_type_get_collection ("GArray", G_TYPE_UCHAR)))
-    {
-      g_warning ("_notify_daemon_process_icon_data expected possition 6 of the GValueArray to be of type GArray");
-      return FALSE;
-    }
-
-  tmp_array = (GArray *) g_value_get_boxed (value);  
-  expected_len = (height -1) * rowstride + width * ((n_channels * bits_per_sample + 7) / 8);
-
-  if (expected_len != tmp_array->len)
-    {
-      g_warning ("_notify_daemon_process_icon_data expected image data to be of length %i but got a length of %i", expected_len, tmp_array->len);
-      return FALSE;
-    }
-
-  data = (guchar *)g_memdup (tmp_array->data, tmp_array->len);
-
-  egg_notification_bubble_widget_set_icon_from_data (bw,
-                                                     data,
-                                                     has_alpha,
-                                                     bits_per_sample,
-                                                     width,
-                                                     height,
-                                                     rowstride);
-  return TRUE;
-}
-
-static void
-_notification_daemon_handle_bubble_widget_action (GtkWidget *b, 
-                                                  EggNotificationBubbleWidget *bw)
-{
-  gchar *action;
-
-  action = (gchar *) g_object_get_data (G_OBJECT (b), "_notify_action");
-
-  _emit_action_invoked_signal (G_OBJECT (bw), action);  
-}
-
-static void
-_notification_daemon_handle_bubble_widget_default (EggNotificationBubbleWidget *bw,
-                                                   NotifyDaemon *daemon)
-{
-  _close_notification (daemon, GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (bw), "_notify_id")));
-}
-
-static void
-_remove_bubble_from_poptart_stack (EggNotificationBubbleWidget *bw,
-                                   NotifyDaemon *daemon)
-{
-  NotifyDaemonPrivate *priv;
-  GdkRectangle workarea;
-  GSList *remove_link;
-  GSList *link;
-
-  gint x, y;
-  
-  priv = daemon->priv;
-
-  link = priv->poptart_stack;
-  remove_link = NULL;
-
-  workarea.x = 0;
-  workarea.y = 0;
-  workarea.width  = gdk_screen_width();
-  workarea.height = gdk_screen_height();
-
-  y = workarea.y + workarea.height;
-  x = 0;
-  while (link)
-    {
-      EggNotificationBubbleWidget *b;
-      GtkRequisition req;
-
-      b = EGG_NOTIFICATION_BUBBLE_WIDGET (link->data);
-      if (b != bw)
-        {
-          printf ("dude\n");
- 
-          gtk_widget_size_request (GTK_WIDGET (b), &req);
-
-          x = workarea.x + workarea.width - req.width;
-          y = y - req.height;
-
-          egg_notification_bubble_widget_set_pos (b, x, y);
-        }
-      else 
-        {
-          remove_link = link;
-        }
-
-      link = link->next;
-    }
-
-    if (remove_link)
-      priv->poptart_stack = g_slist_remove_link (priv->poptart_stack, remove_link);
-}
-
-static void
-_notify_daemon_add_bubble_to_poptart_stack (NotifyDaemon *daemon, 
-                                            EggNotificationBubbleWidget *bw)
-{
-  NotifyDaemonPrivate *priv;
-  GtkRequisition req;
-  GdkRectangle workarea;
-  GSList *link;
-  gint x, y;  
-
-  priv = daemon->priv;
- 
-  gtk_widget_size_request (GTK_WIDGET (bw), &req);
-
-  workarea.x = 0;
-  workarea.y = 0;
-  workarea.width  = gdk_screen_width();
-  workarea.height = gdk_screen_height();
-
-  x = workarea.x + workarea.width - req.width;
-  y = workarea.y + workarea.height - req.height;
-
-  g_message ("x %i y %i width %i height %i", x, y, req.width, req.height);
-
-  egg_notification_bubble_widget_set_pos (bw, x, y);
-
-  link = priv->poptart_stack;
-  while (link)
-    {
-      EggNotificationBubbleWidget *b;
-
-      b = EGG_NOTIFICATION_BUBBLE_WIDGET (link->data);
-      gtk_widget_size_request (GTK_WIDGET (b), &req);
-
-      x = workarea.x + workarea.width - req.width;
-      y = y - req.height;
-      g_message ("x %i y %i width %i height %i", x, y, req.width, req.height);
-      egg_notification_bubble_widget_set_pos (b, x, y);
-
-      link = link->next;
-    }
-
-  g_signal_connect(G_OBJECT(bw), "destroy",
-				   G_CALLBACK(_remove_bubble_from_poptart_stack), daemon);
-  priv->poptart_stack = g_slist_prepend (priv->poptart_stack, bw); 
-}
-
-
-
-gboolean 
-notify_daemon_notify_handler (NotifyDaemon *daemon,
-                              const gchar *app_name,
-                              const gchar *icon,
-                              guint id,
-                              const gchar *summary,
-                              const gchar *body,
-                              gchar **actions,
-                              GHashTable *hints,
-                              int timeout,
-                              DBusGMethodInvocation *context)
-{
-  NotifyDaemonPrivate *priv;
-  NotifyTimeout *nt;
-  EggNotificationBubbleWidget *bw;
-  GValue *data;
-  gboolean use_pos_data;
-  gint x, y;
-  guint return_id;
-  gchar *sender;
-  gint i;
-
-  x = 0;
-  y = 0;
-
-  nt = NULL;
-
-  priv = daemon->priv;
-  bw = NULL;
-  if (id > 0)
-    nt = (NotifyTimeout *) 
-           g_hash_table_lookup (priv->notification_hash, &id);
-
-  if (!nt)
-    {
-      bw = egg_notification_bubble_widget_new ();
-      id = 0;
-    }
-  else
-    bw = nt->widget;
-
-  use_pos_data = FALSE;
-
-  egg_notification_bubble_widget_set (bw, summary, icon, body);
- 
-  /* deal with x, and y hints */
-  data = (GValue *) (g_hash_table_lookup (hints, "x"));
-  if (data)
-    {
-      x = g_value_get_int (data);
-      data = (GValue *) g_hash_table_lookup (hints, "y");
-
-      if (data)
-        {
-          y = g_value_get_int (data);
-          use_pos_data = TRUE;       
-        }
-    }
-
-  /* set up action buttons */
-  i = 0;
-  while (actions[i] != NULL)
-    {
-      gchar *l;
-      GtkWidget *b;
-
-      l = actions[i + 1];
-      if (l == NULL)
-        {
-          g_warning ("Label not found for action %s. "
-                     "The protocol specifies that a label must "
-                     "follow an action in the actions array", actions[i]);
-
-          break;
-        }
-
-      b = egg_notification_bubble_widget_create_button (bw, l);
-       
-      g_object_set_data_full (G_OBJECT (b), 
-                              "_notify_action", 
-                              g_strdup (actions[i]), 
-                              (GDestroyNotify) g_free);
-
-      g_signal_connect (b, 
-                        "clicked",
-                        (GCallback)_notification_daemon_handle_bubble_widget_action, 
-                        bw);
-
-      i = i + 2;
-    }
-
-  if (use_pos_data)
-    {
-      egg_notification_bubble_widget_set_draw_arrow (bw, TRUE);
-      egg_notification_bubble_widget_set_pos (bw, x, y);
-    }
-  else
-    {
-      egg_notification_bubble_widget_set_draw_arrow (bw, FALSE);
-      _notify_daemon_add_bubble_to_poptart_stack (daemon, bw);
-    }
-
-  /* check for icon_data if icon == "" */
-  if (strcmp ("", icon) == 0)
-    {
-      data = (GValue *) (g_hash_table_lookup (hints, "icon_data"));
-      if (data)
-        _notify_daemon_process_icon_data (daemon, bw, data);
-    }
-
-  g_signal_connect (bw, "clicked", (GCallback)_notification_daemon_handle_bubble_widget_default, daemon);  
-
-  egg_notification_bubble_widget_show (bw);
-
-  if (id == 0)
-    return_id = _store_notification (daemon, bw, timeout);
-  else
-    return_id = id;
-
-#if CHECK_DBUS_VERSION(0, 60)
-  sender = dbus_g_method_get_sender (context);
-#else
-  sender = g_strdup(dbus_message_get_sender(
-	dbus_g_message_get_message(context->message)));
-#endif
-
-  g_object_set_data (G_OBJECT (bw), "_notify_id", GUINT_TO_POINTER (return_id));
-  g_object_set_data_full (G_OBJECT (bw), 
-                          "_notify_sender", 
-                          sender, 
-                          (GDestroyNotify) g_free);
-
-  if (nt)
-    _calculate_timeout (daemon, nt, timeout);
-
-  dbus_g_method_return (context, return_id);
-
-  return TRUE;
-}
-
-gboolean 
-notify_daemon_close_notification_handler (NotifyDaemon *daemon,
-                                          guint id,
-                                          GError **error)
-{
-  _close_notification (daemon, id);
-
-  return TRUE;
-}
-
-int
-main (int argc, char **argv)
-{
-  NotifyDaemon *daemon;
-  DBusGConnection *connection;
-  DBusGProxy *bus_proxy;
-  GError *error;
-  guint request_name_result;
-  g_log_set_always_fatal (G_LOG_LEVEL_ERROR
-			  | G_LOG_LEVEL_CRITICAL);
-
-  g_message ("initializing glib type system");
-  gtk_init (&argc, &argv);
-
-  error = NULL;
-  connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
-
-  if (connection == NULL)
-    {
-      g_printerr ("Failed to open connection to bus: %s\n",
-                  error->message);
-      g_error_free (error);
-      exit (1);
-    }
-
-  g_message ("register 'daemon' type with dbus-glib...");
-  dbus_g_object_type_install_info (NOTIFY_TYPE_DAEMON, &dbus_glib__object_info);
-  g_message ("'daemon' successfully registered");
-
-  bus_proxy = dbus_g_proxy_new_for_name (connection, "org.freedesktop.DBus",
-                                         "/org/freedesktop/DBus",
-                                         "org.freedesktop.DBus");
-
-  if (!dbus_g_proxy_call (bus_proxy, "RequestName", &error,
-                          G_TYPE_STRING, "org.freedesktop.Notifications",
-                          G_TYPE_UINT, 0,
-                          G_TYPE_INVALID,
-                          G_TYPE_UINT, &request_name_result,
-                          G_TYPE_INVALID))
-    g_error ("Could not aquire name: %s", error->message);
-
-  g_message ("creating instance of 'daemon' object...");
-  daemon = notify_daemon_new ();
-  g_message ("'daemon' object created successfully");
-
-  g_message ("exporting instance of 'daemon' object over the bus...");
-  dbus_g_connection_register_g_object (connection, "/org/freedesktop/Notifications", G_OBJECT (daemon));
-  g_message ("'daemon' object exported successfully");
-
-  gtk_main();
-
-  return 0;
-}
-

Deleted: trunk/notification-daemon/src/notifydaemon.h
===================================================================
--- trunk/notification-daemon/src/notifydaemon.h	2006-01-11 07:48:56 UTC (rev 2416)
+++ trunk/notification-daemon/src/notifydaemon.h	2006-01-11 07:58:22 UTC (rev 2417)
@@ -1,84 +0,0 @@
-/* notifydaemon.h - Implementation of the destop notification spec
- *
- * Copyright (C) 2005 John (J5) Palmieri <johnp at redhat.com>
- *
- * Written by John (J5) Palmieri <johnp at redhat.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.  
- */
-#ifndef NOTIFY_DAEMON_H
-#define NOTIFY_DAEMON_H
-
-#include <glib.h>
-#include <glib-object.h>
-
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
-
-G_BEGIN_DECLS
-#define NOTIFY_TYPE_DAEMON (notify_daemon_get_type ())
-#define NOTIFY_DAEMON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NOTIFY_TYPE_DAEMON, NotifyDaemon))
-#define NOTIFY_DAEMON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NOTIFY_TYPE_DAEMON, NotifyDaemonClass))
-#define NOTIFY_IS_DAEMON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NOTIFY_TYPE_DAEMON))
-#define NOTIFY_IS_DAEMON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NOTIFY_TYPE_DAEMON))
-#define NOTIFY_DAEMON_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), NOTIFY_TYPE_DAEMON, NotifyDaemonClass))
-
-#define NOTIFY_DAEMON_DEFAULT_TIMEOUT 7000
-
-typedef struct _NotifyDaemon NotifyDaemon;
-typedef struct _NotifyDaemonClass NotifyDaemonClass;
-typedef struct _NotifyDaemonPrivate NotifyDaemonPrivate;
-
-struct _NotifyDaemon
-{
-  GObject parent;
-
-  /*< private > */
-  NotifyDaemonPrivate *priv;
-};
-
-struct _NotifyDaemonClass
-{
-  GObjectClass parent_class;
-};
-
-enum _NotifyDaemonError
-{
-  NOTIFY_DAEMON_ERROR_GENERIC = 0,
-};
-
-GType notify_daemon_get_type (void);
-
-NotifyDaemon *notify_daemon_new (void)
-  G_GNUC_MALLOC;
-
-gboolean notify_daemon_notify_handler (NotifyDaemon *daemon,
-                                       const gchar *app_name,
-                                       const gchar *icon,
-                                       guint id,
-                                       const gchar *summary,
-                                       const gchar *body,
-                                       gchar **actions,
-                                       GHashTable *hints,
-                                       int timeout,
-                                       DBusGMethodInvocation *context);
-
-gboolean notify_daemon_close_notification_handler (NotifyDaemon *daemon,
-                                                   guint id,
-                                                   GError **error);
-
-G_END_DECLS
-#endif /* NOTIFY_DAEMON_H */

Deleted: trunk/notification-daemon/src/notifydaemon.xml
===================================================================
--- trunk/notification-daemon/src/notifydaemon.xml	2006-01-11 07:48:56 UTC (rev 2416)
+++ trunk/notification-daemon/src/notifydaemon.xml	2006-01-11 07:58:22 UTC (rev 2417)
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-
-<node name="/org/freedesktop/Notifications">
-
-  <interface name="org.freedesktop.Notifications">
-    <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="NotifyDaemon"/>
-    <method name="Notify">
-      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="notify_daemon_notify_handler"/>
-      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
-      <arg type="s" name="app_name" direction="in" />
-      <arg type="s" name="icon" direction="in" />
-      <arg type="u" name="id" direction="in" />
-      <arg type="s" name="trouble" direction="in" />
-      <arg type="s" name="d_ret" direction="in" />
-      <arg type="as" name="str_ret" direction="in" />
-      <arg type="a{sv}" name="hints" direction="in" />
-      <arg type="i" name="timeout" direction="in" />
-      <arg type="u" name="return_id" direction="out" />
-    </method>
-    <method name="CloseNotification">
-      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="notify_daemon_close_notification_handler"/>
-      <arg type="u" name="id" direction="in" />
-    </method>
-  </interface>
-</node>



More information about the galago-commits mailing list