From 9c9ceb681c943447178c66fafb0fe825db3fd25d Mon Sep 17 00:00:00 2001 From: Jason Conti Date: Fri, 13 May 2011 14:34:34 -0400 Subject: Integrated the dbus-spy. Menu items for notification summaries are appended as they arrive. --- src/Makefile.am | 4 ++++ src/dbus-spy.c | 2 +- src/dbus-spy.h | 2 ++ src/notification.c | 24 ++++++++++++++++++++++++ src/notification.h | 28 ++++++++++++++-------------- src/notifications-service.c | 17 +++++++++++++++++ 6 files changed, 62 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 67aecd2..7d3cf35 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,6 +2,10 @@ libexec_PROGRAMS = indicator-notifications-service indicator_notifications_service_SOURCES = \ + dbus-spy.c \ + dbus-spy.h \ + notification.c \ + notification.h \ notifications-service.c \ dbus-shared.h \ settings-shared.h diff --git a/src/dbus-spy.c b/src/dbus-spy.c index af3e492..4fe5141 100644 --- a/src/dbus-spy.c +++ b/src/dbus-spy.c @@ -36,7 +36,7 @@ dbus_spy_class_init(DBusSpyClass *klass) object_class->dispose = dbus_spy_dispose; signals[MESSAGE_RECEIVED] = - g_signal_new("message-received", + g_signal_new(DBUS_SPY_SIGNAL_MESSAGE_RECEIVED, G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET(DBusSpyClass, message_received), diff --git a/src/dbus-spy.h b/src/dbus-spy.h index 1f9f79e..efa4732 100644 --- a/src/dbus-spy.h +++ b/src/dbus-spy.h @@ -45,6 +45,8 @@ struct _DBusSpyPrivate { #define DBUS_SPY_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUS_SPY_TYPE, DBusSpyPrivate)) +#define DBUS_SPY_SIGNAL_MESSAGE_RECEIVED "message-received" + GType dbus_spy_get_type(void); DBusSpy* dbus_spy_new(void); diff --git a/src/notification.c b/src/notification.c index 9b0a3c9..10f83e8 100644 --- a/src/notification.c +++ b/src/notification.c @@ -122,6 +122,30 @@ notification_new_from_dbus_message(GDBusMessage *message) return self; } +const gchar* +notification_get_app_name(Notification *self) +{ + return self->priv->app_name; +} + +const gchar* +notification_get_app_icon(Notification *self) +{ + return self->priv->app_icon; +} + +const gchar* +notification_get_summary(Notification *self) +{ + return self->priv->summary; +} + +const gchar* +notification_get_body(Notification *self) +{ + return self->priv->body; +} + void notification_print(Notification *self) { diff --git a/src/notification.h b/src/notification.h index d31a76d..a11036f 100644 --- a/src/notification.h +++ b/src/notification.h @@ -33,16 +33,16 @@ struct _NotificationClass }; struct _NotificationPrivate { - gchar *app_name; - gsize app_name_length; - guint32 replaces_id; - gchar *app_icon; - gsize app_icon_length; - gchar *summary; - gsize summary_length; - gchar *body; - gsize body_length; - gint expire_timeout; + gchar *app_name; + gsize app_name_length; + guint32 replaces_id; + gchar *app_icon; + gsize app_icon_length; + gchar *summary; + gsize summary_length; + gchar *body; + gsize body_length; + gint expire_timeout; }; #define NOTIFICATION_GET_PRIVATE(o) \ @@ -51,10 +51,10 @@ struct _NotificationPrivate { GType notification_get_type(void); Notification *notification_new(void); Notification *notification_new_from_dbus_message(GDBusMessage *); -gchar *notification_get_app_name(Notification *); -gchar *notification_get_app_icon(Notification *); -gchar *notification_get_summary(Notification *); -gchar *notification_get_body(Notification *); +const gchar *notification_get_app_name(Notification *); +const gchar *notification_get_app_icon(Notification *); +const gchar *notification_get_summary(Notification *); +const gchar *notification_get_body(Notification *); void notification_print(Notification *); G_END_DECLS diff --git a/src/notifications-service.c b/src/notifications-service.c index 2d551e9..7adfa68 100644 --- a/src/notifications-service.c +++ b/src/notifications-service.c @@ -32,12 +32,14 @@ with this program. If not, see . #include #include "dbus-shared.h" +#include "dbus-spy.h" #include "settings-shared.h" static IndicatorService *service = NULL; static GMainLoop *mainloop = NULL; static DbusmenuServer *server = NULL; static DbusmenuMenuitem *root = NULL; +static DBusSpy *spy = NULL; /* Global Items */ static DbusmenuMenuitem *item_1 = NULL; @@ -79,6 +81,16 @@ build_menus(DbusmenuMenuitem *root) return; } +static void +message_received_cb(DBusSpy *spy, Notification *note, gpointer user_data) +{ + DbusmenuMenuitem *item; + + item = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, notification_get_summary(note)); + dbusmenu_menuitem_child_append(root, item); +} + /* Responds to the service object saying it's time to shutdown. It stops the mainloop. */ static void @@ -112,9 +124,14 @@ main(int argc, char **argv) build_menus(root); + /* Set up the notification spy */ + spy = dbus_spy_new(); + g_signal_connect(spy, DBUS_SPY_SIGNAL_MESSAGE_RECEIVED, G_CALLBACK(message_received_cb), NULL); + mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); + g_object_unref(G_OBJECT(spy)); g_object_unref(G_OBJECT(service)); g_object_unref(G_OBJECT(server)); g_object_unref(G_OBJECT(root)); -- cgit v1.2.3