diff options
author | Ken VanDine <ken.vandine@canonical.com> | 2012-04-05 15:06:52 -0400 |
---|---|---|
committer | Ken VanDine <ken.vandine@canonical.com> | 2012-04-05 15:06:52 -0400 |
commit | 252f925b889ac6f9035d5d5455b403f48e95d215 (patch) | |
tree | 8a935b1d6301afde6b9e523ef99e1e382814c974 /src | |
parent | 7250f0ebe2da013ad45d52a92520da3a0a87ced7 (diff) | |
parent | dbcfa95ae39e04b2cb23245967bcfc6fa7b39612 (diff) | |
download | ayatana-indicator-messages-252f925b889ac6f9035d5d5455b403f48e95d215.tar.gz ayatana-indicator-messages-252f925b889ac6f9035d5d5455b403f48e95d215.tar.bz2 ayatana-indicator-messages-252f925b889ac6f9035d5d5455b403f48e95d215.zip |
* New upstream release.
* Fix 0.5.94 blacklist regression.
* Fix broken icon images in Thunderbird (LP: #956147)
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.in | 5 | ||||
-rw-r--r-- | src/messages-service-dbus.c | 205 | ||||
-rw-r--r-- | src/messages-service.c | 50 |
3 files changed, 258 insertions, 2 deletions
diff --git a/src/Makefile.in b/src/Makefile.in index 6063ef4..a66adb2 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -43,7 +43,10 @@ DIST_COMMON = $(libindicator_messages_status_provider_la_HEADERS) \ $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ $(srcdir)/indicator-messages-status-provider-0.5.pc.in.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/m4/gcov.m4 \ +am__aclocal_m4_deps = $(top_srcdir)/m4/intltool.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/gcov.m4 \ $(top_srcdir)/m4/gtest.m4 $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) 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; }; @@ -155,9 +157,199 @@ connection_cb (GObject * object, GAsyncResult * res, gpointer user_data) } 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; } diff --git a/src/messages-service.c b/src/messages-service.c index c975df1..8e85da2 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -29,6 +29,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include <libindicator/indicator-service.h> #include <gio/gio.h> #include <glib/gi18n.h> +#include <gtk/gtk.h> #include <libdbusmenu-glib/client.h> #include <libdbusmenu-glib/server.h> @@ -321,14 +322,58 @@ desktop_file_from_keyfile (const gchar * definition_file) return desktopfile; } +/* Check if path is a symlink and return its target if it is */ +static gchar * +get_symlink_target (const gchar *path) +{ + GFile *file; + GFileInfo *fileinfo; + gchar *target = NULL; + + file = g_file_new_for_path (path); + + fileinfo = g_file_query_info (file, "standard::is-symlink", + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, + NULL, NULL); + g_object_unref (file); + + if (!fileinfo) + return NULL; + + if (g_file_info_get_is_symlink (fileinfo)) + target = g_strdup (g_file_info_get_symlink_target (fileinfo)); + + g_object_unref (fileinfo); + return target; +} + /* Add a definition file into the black list and eclipse any launchers that have the same file. */ static gboolean blacklist_add (gpointer udata) { gchar * definition_file = (gchar *)udata; + gchar * symlink_target = get_symlink_target (definition_file); + gchar * contents = NULL; - blacklist_add_core(definition_file, definition_file); + if (symlink_target) + { + blacklist_add_core (symlink_target, definition_file); + g_free (symlink_target); + } + else if (g_str_has_suffix (definition_file, ".desktop")) + { + blacklist_add_core(definition_file, definition_file); + } + else if (g_file_get_contents (definition_file, &contents, NULL, NULL)) + { + gchar *trimmed = pango_trim_string (contents); + blacklist_add_core (trimmed, definition_file); + g_free (trimmed); + g_free (contents); + } + else + g_warning ("invalid blacklist entry: %s", definition_file); return FALSE; } @@ -620,7 +665,9 @@ server_shortcut_added (AppMenuItem * appitem, DbusmenuMenuitem * mi, gpointer da g_debug("Application Shortcut added: %s", mi != NULL ? dbusmenu_menuitem_property_get(mi, DBUSMENU_MENUITEM_PROP_LABEL) : "none"); DbusmenuMenuitem * shell = DBUSMENU_MENUITEM(data); if (mi != NULL) { +#if GTK_CHECK_VERSION(3, 0, 0) dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_ICON_NAME, ""); +#endif dbusmenu_menuitem_child_append(shell, mi); } resort_menu(shell); @@ -1055,6 +1102,7 @@ indicator_added (IndicateListener * listener, IndicateListenerServer * server, I } else { g_warning("Unable to find server menu item"); dbusmenu_menuitem_child_append(menushell, DBUSMENU_MENUITEM(menuitem)); + resort_menu (root_menuitem); } return; |