From 93aa4c33433352dec2650e680ad3266716cc610d Mon Sep 17 00:00:00 2001 From: Sebastien Bacher Date: Tue, 14 Feb 2012 23:50:08 +0100 Subject: debian/control: build-depends on dh-autoreconf as well --- debian/changelog | 6 ++++++ debian/control | 1 + 2 files changed, 7 insertions(+) diff --git a/debian/changelog b/debian/changelog index ef88047..161f895 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +indicator-messages (0.5.91-0ubuntu2) UNRELEASED; urgency=low + + * debian/control: build-depends on dh-autoreconf as well + + -- Sebastien Bacher Tue, 14 Feb 2012 23:49:45 +0100 + indicator-messages (0.5.91-0ubuntu1) precise; urgency=low * New upstream release. diff --git a/debian/control b/debian/control index 9db6511..4c623c8 100644 --- a/debian/control +++ b/debian/control @@ -6,6 +6,7 @@ XSBC-Original-Maintainer: The Ayatana Packagers Build-Depends: debhelper (>= 5.0), cdbs (>= 0.4.41), + dh-autoreconf, libgtk2.0-dev (>= 2.12.0), libgtk-3-dev, libdbus-glib-1-dev, -- cgit v1.2.3 From f336ed98510701a5f030e55e2503755ec6fe6160 Mon Sep 17 00:00:00 2001 From: Sebastien Bacher Date: Tue, 14 Feb 2012 23:50:20 +0100 Subject: releasing version 0.5.91-0ubuntu2 --- debian/changelog | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 161f895..7691c06 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,8 @@ -indicator-messages (0.5.91-0ubuntu2) UNRELEASED; urgency=low +indicator-messages (0.5.91-0ubuntu2) precise; urgency=low * debian/control: build-depends on dh-autoreconf as well - -- Sebastien Bacher Tue, 14 Feb 2012 23:49:45 +0100 + -- Sebastien Bacher Tue, 14 Feb 2012 23:50:15 +0100 indicator-messages (0.5.91-0ubuntu1) precise; urgency=low -- cgit v1.2.3 From 6bc1b1caa9d563b67e40751255c7547fcb5101c6 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 15 Feb 2012 15:32:55 -0500 Subject: * debian/source/format: - Make "3.0 (quilt)" * debian/patches/tell-accounts-service.patch: - Tell accountsservice when user has messages for the benefit of LightDM. --- debian/changelog | 10 ++ debian/patches/series | 1 + debian/patches/tell-accounts-service.patch | 240 +++++++++++++++++++++++++++++ debian/source/format | 1 + src/messages-service-dbus.c | 205 ++++++++++++++++++++++++ 5 files changed, 457 insertions(+) create mode 100644 debian/patches/tell-accounts-service.patch create mode 100644 debian/source/format diff --git a/debian/changelog b/debian/changelog index 7691c06..41e0896 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,13 @@ +indicator-messages (0.5.91-0ubuntu3) precise; urgency=low + + * debian/source/format: + - Make "3.0 (quilt)" + * debian/patches/tell-accounts-service.patch: + - Tell accountsservice when user has messages for the benefit of + LightDM. + + -- Michael Terry Wed, 15 Feb 2012 15:32:16 -0500 + indicator-messages (0.5.91-0ubuntu2) precise; urgency=low * debian/control: build-depends on dh-autoreconf as well diff --git a/debian/patches/series b/debian/patches/series index e69de29..e4b5738 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -0,0 +1 @@ +tell-accounts-service.patch diff --git a/debian/patches/tell-accounts-service.patch b/debian/patches/tell-accounts-service.patch new file mode 100644 index 0000000..05b59f4 --- /dev/null +++ b/debian/patches/tell-accounts-service.patch @@ -0,0 +1,240 @@ +Index: indicator-messages/src/messages-service-dbus.c +=================================================================== +--- indicator-messages.orig/src/messages-service-dbus.c 2012-02-15 14:36:39.800065000 -0500 ++++ indicator-messages/src/messages-service-dbus.c 2012-02-15 14:39:02.823505930 -0500 +@@ -42,6 +42,8 @@ + struct _MessageServiceDbusPrivate + { + GDBusConnection * connection; ++ GCancellable * accounts_cancel; ++ GDBusProxy * accounts_user; + gboolean dot; + gboolean hidden; + }; +@@ -155,9 +157,199 @@ + } + + static void ++accounts_notify_cb (GObject *source_object, GAsyncResult *res, ++ gpointer user_data) ++{ ++ GError * error = NULL; ++ GVariant * answer = g_dbus_proxy_call_finish(G_DBUS_PROXY(source_object), res, &error); ++ ++ if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { ++ g_error_free(error); ++ return; /* Must exit before accessing freed memory */ ++ } ++ ++ MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(user_data); ++ ++ if (priv->accounts_cancel != NULL) { ++ g_object_unref(priv->accounts_cancel); ++ priv->accounts_cancel = NULL; ++ } ++ ++ if (error != NULL) { ++ g_warning("Unable to get notify accounts service of message status: %s", error->message); ++ g_error_free(error); ++ return; ++ } ++ ++ g_variant_unref (answer); ++} ++ ++static void ++accounts_notify (MessageServiceDbus *self) ++{ ++ MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(self); ++ ++ if (priv->accounts_user == NULL) ++ return; /* We're not able to talk to accounts service */ ++ ++ if (priv->accounts_cancel != NULL) { ++ /* Cancel old notify before starting new one */ ++ g_cancellable_cancel(priv->accounts_cancel); ++ g_object_unref(priv->accounts_cancel); ++ priv->accounts_cancel = NULL; ++ } ++ ++ priv->accounts_cancel = g_cancellable_new(); ++ g_dbus_proxy_call(priv->accounts_user, ++ "SetXHasMessages", ++ g_variant_new ("(b)", priv->dot), ++ G_DBUS_CALL_FLAGS_NONE, ++ -1, /* timeout */ ++ priv->accounts_cancel, ++ accounts_notify_cb, ++ self); ++} ++ ++static void ++get_accounts_user_proxy_cb (GObject *source_object, GAsyncResult *res, ++ gpointer user_data) ++{ ++ GError * error = NULL; ++ GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error); ++ ++ if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { ++ g_error_free(error); ++ return; /* Must exit before accessing freed memory */ ++ } ++ ++ MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(user_data); ++ ++ if (priv->accounts_cancel != NULL) { ++ g_object_unref(priv->accounts_cancel); ++ priv->accounts_cancel = NULL; ++ } ++ ++ if (error != NULL) { ++ g_warning("Unable to get proxy of accountsservice: %s", error->message); ++ g_error_free(error); ++ return; ++ } ++ ++ priv->accounts_user = proxy; ++ accounts_notify (MESSAGE_SERVICE_DBUS (user_data)); ++} ++ ++static void ++get_accounts_user_find_user_cb (GObject *source_object, GAsyncResult *res, ++ gpointer user_data) ++{ ++ GError * error = NULL; ++ GVariant * answer = g_dbus_proxy_call_finish(G_DBUS_PROXY(source_object), res, &error); ++ ++ /* We're done with main accounts proxy now */ ++ g_object_unref (source_object); ++ ++ if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { ++ g_error_free(error); ++ return; /* Must exit before accessing freed memory */ ++ } ++ ++ MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(user_data); ++ ++ if (priv->accounts_cancel != NULL) { ++ g_object_unref(priv->accounts_cancel); ++ priv->accounts_cancel = NULL; ++ } ++ ++ if (error != NULL) { ++ g_warning("Unable to get object name of user from accountsservice: %s", error->message); ++ g_error_free(error); ++ return; ++ } ++ ++ if (!g_variant_is_of_type (answer, G_VARIANT_TYPE ("(o)"))) { ++ g_warning("Unexpected type from FindUserByName: %s", g_variant_get_type_string (answer)); ++ g_variant_unref(answer); ++ return; ++ } ++ ++ const gchar *path; ++ g_variant_get(answer, "(&o)", &path); ++ ++ priv->accounts_cancel = g_cancellable_new(); ++ g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, ++ G_DBUS_PROXY_FLAGS_NONE, ++ NULL, ++ "org.freedesktop.Accounts", ++ path, ++ "org.freedesktop.Accounts.User", ++ priv->accounts_cancel, ++ get_accounts_user_proxy_cb, ++ user_data); ++ ++ g_variant_unref (answer); ++} ++ ++static void ++get_accounts_proxy_cb (GObject *source_object, GAsyncResult *res, ++ gpointer user_data) ++{ ++ GError * error = NULL; ++ GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error); ++ ++ if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { ++ g_error_free(error); ++ return; /* Must exit before accessing freed memory */ ++ } ++ ++ MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(user_data); ++ ++ if (priv->accounts_cancel != NULL) { ++ g_object_unref(priv->accounts_cancel); ++ priv->accounts_cancel = NULL; ++ } ++ ++ if (error != NULL) { ++ g_warning("Unable to get proxy of accountsservice: %s", error->message); ++ g_error_free(error); ++ return; ++ } ++ ++ priv->accounts_cancel = g_cancellable_new(); ++ g_dbus_proxy_call(proxy, ++ "FindUserByName", ++ g_variant_new ("(s)", g_get_user_name ()), ++ G_DBUS_CALL_FLAGS_NONE, ++ -1, /* timeout */ ++ priv->accounts_cancel, ++ get_accounts_user_find_user_cb, ++ user_data); ++} ++ ++static void ++get_accounts_proxy (MessageServiceDbus *self) ++{ ++ MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(self); ++ ++ g_return_if_fail(priv->accounts_cancel == NULL); ++ ++ priv->accounts_cancel = g_cancellable_new(); ++ g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, ++ G_DBUS_PROXY_FLAGS_NONE, ++ NULL, ++ "org.freedesktop.Accounts", ++ "/org/freedesktop/Accounts", ++ "org.freedesktop.Accounts", ++ priv->accounts_cancel, ++ get_accounts_proxy_cb, ++ self); ++} ++ ++static void + message_service_dbus_init (MessageServiceDbus *self) + { + g_bus_get(G_BUS_TYPE_SESSION, NULL, connection_cb, self); ++ get_accounts_proxy (self); + + MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(self); + +@@ -177,6 +369,17 @@ + priv->connection = NULL; + } + ++ if (priv->accounts_cancel != NULL) { ++ g_cancellable_cancel(priv->accounts_cancel); ++ g_object_unref(priv->accounts_cancel); ++ priv->accounts_cancel = NULL; ++ } ++ ++ if (priv->accounts_user != NULL) { ++ g_object_unref(priv->accounts_user); ++ priv->accounts_user = NULL; ++ } ++ + G_OBJECT_CLASS (message_service_dbus_parent_class)->dispose (object); + return; + } +@@ -240,6 +443,8 @@ + g_variant_new("(b)", priv->dot), + NULL); + } ++ ++ accounts_notify (self); + } + return; + } diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..163aaf8 --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/src/messages-service-dbus.c b/src/messages-service-dbus.c index 1585ac0..2b72f2e 100644 --- a/src/messages-service-dbus.c +++ b/src/messages-service-dbus.c @@ -42,6 +42,8 @@ typedef struct _MessageServiceDbusPrivate MessageServiceDbusPrivate; struct _MessageServiceDbusPrivate { GDBusConnection * connection; + GCancellable * accounts_cancel; + GDBusProxy * accounts_user; gboolean dot; gboolean hidden; }; @@ -154,10 +156,200 @@ connection_cb (GObject * object, GAsyncResult * res, gpointer user_data) return; } +static void +accounts_notify_cb (GObject *source_object, GAsyncResult *res, + gpointer user_data) +{ + GError * error = NULL; + GVariant * answer = g_dbus_proxy_call_finish(G_DBUS_PROXY(source_object), res, &error); + + if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { + g_error_free(error); + return; /* Must exit before accessing freed memory */ + } + + MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(user_data); + + if (priv->accounts_cancel != NULL) { + g_object_unref(priv->accounts_cancel); + priv->accounts_cancel = NULL; + } + + if (error != NULL) { + g_warning("Unable to get notify accounts service of message status: %s", error->message); + g_error_free(error); + return; + } + + g_variant_unref (answer); +} + +static void +accounts_notify (MessageServiceDbus *self) +{ + MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(self); + + if (priv->accounts_user == NULL) + return; /* We're not able to talk to accounts service */ + + if (priv->accounts_cancel != NULL) { + /* Cancel old notify before starting new one */ + g_cancellable_cancel(priv->accounts_cancel); + g_object_unref(priv->accounts_cancel); + priv->accounts_cancel = NULL; + } + + priv->accounts_cancel = g_cancellable_new(); + g_dbus_proxy_call(priv->accounts_user, + "SetXHasMessages", + g_variant_new ("(b)", priv->dot), + G_DBUS_CALL_FLAGS_NONE, + -1, /* timeout */ + priv->accounts_cancel, + accounts_notify_cb, + self); +} + +static void +get_accounts_user_proxy_cb (GObject *source_object, GAsyncResult *res, + gpointer user_data) +{ + GError * error = NULL; + GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error); + + if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { + g_error_free(error); + return; /* Must exit before accessing freed memory */ + } + + MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(user_data); + + if (priv->accounts_cancel != NULL) { + g_object_unref(priv->accounts_cancel); + priv->accounts_cancel = NULL; + } + + if (error != NULL) { + g_warning("Unable to get proxy of accountsservice: %s", error->message); + g_error_free(error); + return; + } + + priv->accounts_user = proxy; + accounts_notify (MESSAGE_SERVICE_DBUS (user_data)); +} + +static void +get_accounts_user_find_user_cb (GObject *source_object, GAsyncResult *res, + gpointer user_data) +{ + GError * error = NULL; + GVariant * answer = g_dbus_proxy_call_finish(G_DBUS_PROXY(source_object), res, &error); + + /* We're done with main accounts proxy now */ + g_object_unref (source_object); + + if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { + g_error_free(error); + return; /* Must exit before accessing freed memory */ + } + + MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(user_data); + + if (priv->accounts_cancel != NULL) { + g_object_unref(priv->accounts_cancel); + priv->accounts_cancel = NULL; + } + + if (error != NULL) { + g_warning("Unable to get object name of user from accountsservice: %s", error->message); + g_error_free(error); + return; + } + + if (!g_variant_is_of_type (answer, G_VARIANT_TYPE ("(o)"))) { + g_warning("Unexpected type from FindUserByName: %s", g_variant_get_type_string (answer)); + g_variant_unref(answer); + return; + } + + const gchar *path; + g_variant_get(answer, "(&o)", &path); + + priv->accounts_cancel = g_cancellable_new(); + g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "org.freedesktop.Accounts", + path, + "org.freedesktop.Accounts.User", + priv->accounts_cancel, + get_accounts_user_proxy_cb, + user_data); + + g_variant_unref (answer); +} + +static void +get_accounts_proxy_cb (GObject *source_object, GAsyncResult *res, + gpointer user_data) +{ + GError * error = NULL; + GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error); + + if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { + g_error_free(error); + return; /* Must exit before accessing freed memory */ + } + + MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(user_data); + + if (priv->accounts_cancel != NULL) { + g_object_unref(priv->accounts_cancel); + priv->accounts_cancel = NULL; + } + + if (error != NULL) { + g_warning("Unable to get proxy of accountsservice: %s", error->message); + g_error_free(error); + return; + } + + priv->accounts_cancel = g_cancellable_new(); + g_dbus_proxy_call(proxy, + "FindUserByName", + g_variant_new ("(s)", g_get_user_name ()), + G_DBUS_CALL_FLAGS_NONE, + -1, /* timeout */ + priv->accounts_cancel, + get_accounts_user_find_user_cb, + user_data); +} + +static void +get_accounts_proxy (MessageServiceDbus *self) +{ + MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(self); + + g_return_if_fail(priv->accounts_cancel == NULL); + + priv->accounts_cancel = g_cancellable_new(); + g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "org.freedesktop.Accounts", + "/org/freedesktop/Accounts", + "org.freedesktop.Accounts", + priv->accounts_cancel, + get_accounts_proxy_cb, + self); +} + static void message_service_dbus_init (MessageServiceDbus *self) { g_bus_get(G_BUS_TYPE_SESSION, NULL, connection_cb, self); + get_accounts_proxy (self); MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(self); @@ -177,6 +369,17 @@ message_service_dbus_dispose (GObject *object) priv->connection = NULL; } + if (priv->accounts_cancel != NULL) { + g_cancellable_cancel(priv->accounts_cancel); + g_object_unref(priv->accounts_cancel); + priv->accounts_cancel = NULL; + } + + if (priv->accounts_user != NULL) { + g_object_unref(priv->accounts_user); + priv->accounts_user = NULL; + } + G_OBJECT_CLASS (message_service_dbus_parent_class)->dispose (object); return; } @@ -240,6 +443,8 @@ message_service_dbus_set_attention (MessageServiceDbus * self, gboolean attentio g_variant_new("(b)", priv->dot), NULL); } + + accounts_notify (self); } return; } -- cgit v1.2.3 From 9f20c997bf637e5f382c4247503dd6e2a774b48a Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 15 Feb 2012 15:34:55 -0500 Subject: add .pc directory too --- .pc/.quilt_patches | 1 + .pc/.quilt_series | 1 + .pc/.version | 1 + .pc/applied-patches | 1 + .pc/tell-accounts-service.patch/.timestamp | 0 .../src/messages-service-dbus.c | 267 +++++++++++++++++++++ 6 files changed, 271 insertions(+) create mode 100644 .pc/.quilt_patches create mode 100644 .pc/.quilt_series create mode 100644 .pc/.version create mode 100644 .pc/applied-patches create mode 100644 .pc/tell-accounts-service.patch/.timestamp create mode 100644 .pc/tell-accounts-service.patch/src/messages-service-dbus.c diff --git a/.pc/.quilt_patches b/.pc/.quilt_patches new file mode 100644 index 0000000..6857a8d --- /dev/null +++ b/.pc/.quilt_patches @@ -0,0 +1 @@ +debian/patches diff --git a/.pc/.quilt_series b/.pc/.quilt_series new file mode 100644 index 0000000..c206706 --- /dev/null +++ b/.pc/.quilt_series @@ -0,0 +1 @@ +series diff --git a/.pc/.version b/.pc/.version new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/.pc/.version @@ -0,0 +1 @@ +2 diff --git a/.pc/applied-patches b/.pc/applied-patches new file mode 100644 index 0000000..e4b5738 --- /dev/null +++ b/.pc/applied-patches @@ -0,0 +1 @@ +tell-accounts-service.patch diff --git a/.pc/tell-accounts-service.patch/.timestamp b/.pc/tell-accounts-service.patch/.timestamp new file mode 100644 index 0000000..e69de29 diff --git a/.pc/tell-accounts-service.patch/src/messages-service-dbus.c b/.pc/tell-accounts-service.patch/src/messages-service-dbus.c new file mode 100644 index 0000000..1585ac0 --- /dev/null +++ b/.pc/tell-accounts-service.patch/src/messages-service-dbus.c @@ -0,0 +1,267 @@ +/* +An indicator to show information that is in messaging applications +that the user is using. + +Copyright 2009 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, 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, see . +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include "messages-service-dbus.h" +#include "dbus-data.h" +#include "gen-messages-service.xml.h" + +enum { + ATTENTION_CHANGED, + ICON_CHANGED, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + +typedef struct _MessageServiceDbusPrivate MessageServiceDbusPrivate; + +struct _MessageServiceDbusPrivate +{ + GDBusConnection * connection; + gboolean dot; + gboolean hidden; +}; + +#define MESSAGE_SERVICE_DBUS_GET_PRIVATE(o) \ +(G_TYPE_INSTANCE_GET_PRIVATE ((o), MESSAGE_SERVICE_DBUS_TYPE, MessageServiceDbusPrivate)) + +static void message_service_dbus_class_init (MessageServiceDbusClass *klass); +static void message_service_dbus_init (MessageServiceDbus *self); +static void message_service_dbus_dispose (GObject *object); +static void message_service_dbus_finalize (GObject *object); +static void bus_method_call (GDBusConnection * connection, + const gchar * sender, + const gchar * path, + const gchar * interface, + const gchar * method, + GVariant * params, + GDBusMethodInvocation * invocation, + gpointer user_data); + +static GDBusNodeInfo * bus_node_info = NULL; +static GDBusInterfaceInfo * bus_interface_info = NULL; +static const GDBusInterfaceVTable bus_interface_table = { + method_call: bus_method_call, + get_property: NULL, /* No properties */ + set_property: NULL /* No properties */ +}; + +G_DEFINE_TYPE (MessageServiceDbus, message_service_dbus, G_TYPE_OBJECT); + + +static void +message_service_dbus_class_init (MessageServiceDbusClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (MessageServiceDbusPrivate)); + + object_class->dispose = message_service_dbus_dispose; + object_class->finalize = message_service_dbus_finalize; + + signals[ATTENTION_CHANGED] = g_signal_new(MESSAGE_SERVICE_DBUS_SIGNAL_ATTENTION_CHANGED, + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (MessageServiceDbusClass, attention_changed), + NULL, NULL, + g_cclosure_marshal_VOID__BOOLEAN, + G_TYPE_NONE, 1, G_TYPE_BOOLEAN); + + signals[ICON_CHANGED] = g_signal_new(MESSAGE_SERVICE_DBUS_SIGNAL_ICON_CHANGED, + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (MessageServiceDbusClass, icon_changed), + NULL, NULL, + g_cclosure_marshal_VOID__BOOLEAN, + G_TYPE_NONE, 1, G_TYPE_BOOLEAN); + + if (bus_node_info == NULL) { + GError * error = NULL; + + bus_node_info = g_dbus_node_info_new_for_xml(_messages_service, &error); + if (error != NULL) { + g_error("Unable to parse Messaging Menu Interface description: %s", error->message); + g_error_free(error); + } + } + + if (bus_interface_info == NULL) { + bus_interface_info = g_dbus_node_info_lookup_interface(bus_node_info, INDICATOR_MESSAGES_DBUS_SERVICE_INTERFACE); + + if (bus_interface_info == NULL) { + g_error("Unable to find interface '" INDICATOR_MESSAGES_DBUS_SERVICE_INTERFACE "'"); + } + } + + return; +} + +static void +connection_cb (GObject * object, GAsyncResult * res, gpointer user_data) +{ + GError * error = NULL; + GDBusConnection * connection = g_bus_get_finish(res, &error); + + if (error != NULL) { + g_error("Unable to connect to the session bus: %s", error->message); + g_error_free(error); + return; + } + + MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(user_data); + priv->connection = connection; + + g_dbus_connection_register_object(connection, + INDICATOR_MESSAGES_DBUS_SERVICE_OBJECT, + bus_interface_info, + &bus_interface_table, + user_data, + NULL, /* destroy */ + &error); + + if (error != NULL) { + g_error("Unable to register on session bus: %s", error->message); + g_error_free(error); + return; + } + + g_debug("Service on session bus"); + + return; +} + +static void +message_service_dbus_init (MessageServiceDbus *self) +{ + g_bus_get(G_BUS_TYPE_SESSION, NULL, connection_cb, self); + + MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(self); + + priv->dot = FALSE; + priv->hidden = FALSE; + + return; +} + +static void +message_service_dbus_dispose (GObject *object) +{ + MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(object); + + if (priv->connection != NULL) { + g_object_unref(priv->connection); + priv->connection = NULL; + } + + G_OBJECT_CLASS (message_service_dbus_parent_class)->dispose (object); + return; +} + +static void +message_service_dbus_finalize (GObject *object) +{ + + + G_OBJECT_CLASS (message_service_dbus_parent_class)->finalize (object); + return; +} + +MessageServiceDbus * +message_service_dbus_new (void) +{ + return MESSAGE_SERVICE_DBUS(g_object_new(MESSAGE_SERVICE_DBUS_TYPE, NULL)); +} + +/* Method request off of DBus */ +static void +bus_method_call (GDBusConnection * connection, const gchar * sender, const gchar * path, const gchar * interface, const gchar * method, GVariant * params, GDBusMethodInvocation * invocation, gpointer user_data) +{ + MessageServiceDbus * ms = MESSAGE_SERVICE_DBUS(user_data); + if (ms == NULL) { return; } + + MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(ms); + + if (g_strcmp0("AttentionRequested", method) == 0) { + g_dbus_method_invocation_return_value(invocation, g_variant_new("(b)", priv->dot)); + return; + } else if (g_strcmp0("IconShown", method) == 0) { + g_dbus_method_invocation_return_value(invocation, g_variant_new("(b)", priv->hidden)); + return; + } else if (g_strcmp0("ClearAttention", method) == 0) { + message_service_dbus_set_attention(ms, FALSE); + g_dbus_method_invocation_return_value(invocation, NULL); + return; + } else { + g_warning("Unknown function call '%s'", method); + } + + return; +} + +void +message_service_dbus_set_attention (MessageServiceDbus * self, gboolean attention) +{ + MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(self); + /* Do signal */ + if (attention != priv->dot) { + priv->dot = attention; + g_signal_emit(G_OBJECT(self), signals[ATTENTION_CHANGED], 0, priv->dot, TRUE); + + if (priv->connection != NULL) { + g_dbus_connection_emit_signal(priv->connection, + NULL, + INDICATOR_MESSAGES_DBUS_SERVICE_OBJECT, + INDICATOR_MESSAGES_DBUS_SERVICE_INTERFACE, + "AttentionChanged", + g_variant_new("(b)", priv->dot), + NULL); + } + } + return; +} + +void +message_service_dbus_set_icon (MessageServiceDbus * self, gboolean hidden) +{ + MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(self); + /* Do signal */ + if (hidden != priv->hidden) { + priv->hidden = hidden; + g_signal_emit(G_OBJECT(self), signals[ICON_CHANGED], 0, priv->hidden, TRUE); + + if (priv->connection != NULL) { + g_dbus_connection_emit_signal(priv->connection, + NULL, + INDICATOR_MESSAGES_DBUS_SERVICE_OBJECT, + INDICATOR_MESSAGES_DBUS_SERVICE_INTERFACE, + "IconChanged", + g_variant_new("(b)", priv->hidden), + NULL); + } + } + return; +} -- cgit v1.2.3