From c64309f5a4bcbc62d4ab5810735be97e7abcf335 Mon Sep 17 00:00:00 2001 From: Jason Conti Date: Fri, 13 May 2011 14:10:30 -0400 Subject: Importing dbus-spy and notification dbus objects to watch dbus for org.freedesktop.Notification.Notify messages (from test project). --- src/notification.c | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 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 0000000..9b0a3c9 --- /dev/null +++ b/src/notification.c @@ -0,0 +1,132 @@ +/* + * notification.c - A gobject subclass to represent a org.freedesktop.Notification.Notify message. + */ + +#include "notification.h" + +#define COLUMN_APP_NAME 0 +#define COLUMN_REPLACES_ID 1 +#define COLUMN_APP_ICON 2 +#define COLUMN_SUMMARY 3 +#define COLUMN_BODY 4 +#define COLUMN_ACTIONS 5 +#define COLUMN_HINTS 6 +#define COLUMN_EXPIRE_TIMEOUT 7 + +#define COLUMN_COUNT 8 + +static void notification_class_init(NotificationClass *klass); +static void notification_init(Notification *self); +static void notification_dispose(GObject *object); + +G_DEFINE_TYPE (Notification, notification, G_TYPE_OBJECT); + +static void +notification_class_init(NotificationClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS(klass); + + g_type_class_add_private(klass, sizeof(NotificationPrivate)); + + object_class->dispose = notification_dispose; +} + +static void +notification_init(Notification *self) +{ + self->priv = NOTIFICATION_GET_PRIVATE(self); + + self->priv->app_name = NULL; + self->priv->replaces_id = 0; + self->priv->app_icon = NULL; + self->priv->summary = NULL; + self->priv->body = NULL; + self->priv->expire_timeout = 0; +} + +static void +notification_dispose(GObject *object) +{ + Notification *self = NOTIFICATION(object); + + if(self->priv->app_name != NULL) { + g_free(self->priv->app_name); + self->priv->app_name = NULL; + } + + if(self->priv->app_icon != NULL) { + g_free(self->priv->app_icon); + self->priv->app_icon = NULL; + } + + if(self->priv->summary != NULL) { + g_free(self->priv->summary); + self->priv->summary = NULL; + } + + if(self->priv->body != NULL) { + g_free(self->priv->body); + self->priv->body = NULL; + } + + G_OBJECT_CLASS(notification_parent_class)->dispose(object); +} + +Notification* +notification_new(void) +{ + return NOTIFICATION(g_object_new(NOTIFICATION_TYPE, NULL)); +} + +Notification* +notification_new_from_dbus_message(GDBusMessage *message) +{ + Notification *self = notification_new(); + + GVariant *body = g_dbus_message_get_body(message); + GVariant *child = NULL; + g_assert(g_variant_is_of_type(body, G_VARIANT_TYPE_TUPLE)); + g_assert(g_variant_n_children(body) == COLUMN_COUNT); + + /* app_name */ + child = g_variant_get_child_value(body, COLUMN_APP_NAME); + g_assert(g_variant_is_of_type(child, G_VARIANT_TYPE_STRING)); + self->priv->app_name = g_variant_dup_string(child, + &(self->priv->app_name_length)); + + /* replaces_id */ + child = g_variant_get_child_value(body, COLUMN_REPLACES_ID); + g_assert(g_variant_is_of_type(child, G_VARIANT_TYPE_UINT32)); + self->priv->replaces_id = g_variant_get_uint32(child); + + /* app_icon */ + child = g_variant_get_child_value(body, COLUMN_APP_ICON); + g_assert(g_variant_is_of_type(child, G_VARIANT_TYPE_STRING)); + self->priv->app_icon = g_variant_dup_string(child, + &(self->priv->app_icon_length)); + + /* summary */ + child = g_variant_get_child_value(body, COLUMN_SUMMARY); + g_assert(g_variant_is_of_type(child, G_VARIANT_TYPE_STRING)); + self->priv->summary = g_variant_dup_string(child, + &(self->priv->summary_length)); + + /* body */ + child = g_variant_get_child_value(body, COLUMN_BODY); + g_assert(g_variant_is_of_type(child, G_VARIANT_TYPE_STRING)); + self->priv->body = g_variant_dup_string(child, + &(self->priv->body_length)); + + child = NULL; + + return self; +} + +void +notification_print(Notification *self) +{ + g_print("app_name = %s\n", self->priv->app_name); + g_print("app_icon = %s\n", self->priv->app_icon); + g_print("summary = %s\n", self->priv->summary); + g_print("body = %s\n", self->priv->body); +} -- cgit v1.2.3