diff options
author | Alberto Mardegan <alberto.mardegan@canonical.com> | 2012-08-30 19:00:10 +0000 |
---|---|---|
committer | Tarmac <Unknown> | 2012-08-30 19:00:10 +0000 |
commit | 697c5fa7233269b39bb89dd3a0b2e6adcd2b694a (patch) | |
tree | 05baf2dc22ccc250a3e215ad538e6f95148d5054 /src | |
parent | a1ad57994ebf3e7b4acbbe6b7df3d41377b49e6f (diff) | |
parent | 0a7f9ed274047c0228a5a5f9e053308e755bf89d (diff) | |
download | ayatana-indicator-session-697c5fa7233269b39bb89dd3a0b2e6adcd2b694a.tar.gz ayatana-indicator-session-697c5fa7233269b39bb89dd3a0b2e6adcd2b694a.tar.bz2 ayatana-indicator-session-697c5fa7233269b39bb89dd3a0b2e6adcd2b694a.zip |
Add the "Online Accounts" item to the session menu.
This item, beside opening the Online Accounts applet of the GNOME Control Center, also acts as an indicator, by turning red when some accounts need to be re-authenticated.. Approved by Charles Kerr, Matthew Paul Thomas, jenkins.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/online-accounts-mgr.c | 166 | ||||
-rw-r--r-- | src/online-accounts-mgr.h | 50 | ||||
-rw-r--r-- | src/session-menu-mgr.c | 38 |
4 files changed, 257 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 7bc6306..cd82812 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -133,7 +133,9 @@ indicator_session_service_SOURCES = \ users-service-dbus.h \ users-service-dbus.c \ session-menu-mgr.h \ - session-menu-mgr.c + session-menu-mgr.c \ + online-accounts-mgr.c \ + online-accounts-mgr.h indicator_session_service_CFLAGS = \ $(SESSIONSERVICE_CFLAGS) \ diff --git a/src/online-accounts-mgr.c b/src/online-accounts-mgr.c new file mode 100644 index 0000000..4abba00 --- /dev/null +++ b/src/online-accounts-mgr.c @@ -0,0 +1,166 @@ +/* +Copyright 2012 Canonical Ltd. + +Authors: + Alberto Mardegan <alberto.mardegan@canonical.com> + +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 <http://www.gnu.org/licenses/>. +*/ + +#include <gio/gio.h> +#include <glib/gi18n.h> + +#include "online-accounts-mgr.h" + +#include <libdbusmenu-glib/client.h> + +struct _OnlineAccountsMgr +{ + GObject parent_instance; + GDBusProxy *proxy; + DbusmenuMenuitem *menu_item; +}; + +#define ONLINE_ACCOUNTS_OBJECT_PATH "/com/canonical/indicators/webcredentials" +#define ONLINE_ACCOUNTS_BUS_NAME "com.canonical.indicators.webcredentials" +#define ONLINE_ACCOUNTS_INTERFACE ONLINE_ACCOUNTS_BUS_NAME + +G_DEFINE_TYPE (OnlineAccountsMgr, online_accounts_mgr, G_TYPE_OBJECT); + +static void +update_disposition (OnlineAccountsMgr *self, GVariant *error_status_prop) +{ + gboolean error_status; + + error_status = g_variant_get_boolean (error_status_prop); + dbusmenu_menuitem_property_set (self->menu_item, + DBUSMENU_MENUITEM_PROP_DISPOSITION, + error_status ? + DBUSMENU_MENUITEM_DISPOSITION_ALERT : + DBUSMENU_MENUITEM_DISPOSITION_NORMAL); +} + +static void +on_properties_changed (GDBusProxy *proxy, + GVariant *changed_properties, + GStrv invalidated_properties, + OnlineAccountsMgr *self) +{ + if (g_variant_n_children (changed_properties) > 0) { + GVariantIter *iter; + const gchar *key; + GVariant *value; + + g_variant_get (changed_properties, "a{sv}", &iter); + while (g_variant_iter_loop (iter, "{&sv}", &key, &value)) { + if (g_strcmp0 (key, "ErrorStatus") == 0) { + update_disposition (self, value); + } + } + g_variant_iter_free (iter); + } +} + +static void +on_menu_item_activated (DbusmenuMenuitem *menu_item, + guint timestamp, + OnlineAccountsMgr *self) +{ + GError *error = NULL; + + if (!g_spawn_command_line_async("gnome-control-center credentials", &error)) + { + g_warning("Unable to show control center: %s", error->message); + g_error_free(error); + } +} + +static void +online_accounts_mgr_init (OnlineAccountsMgr *self) +{ + GError *error = NULL; + GVariant *error_status_prop; + + self->menu_item = dbusmenu_menuitem_new (); + dbusmenu_menuitem_property_set (self->menu_item, + DBUSMENU_MENUITEM_PROP_TYPE, + DBUSMENU_CLIENT_TYPES_DEFAULT); + dbusmenu_menuitem_property_set (self->menu_item, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Online Accounts\342\200\246")); + g_signal_connect (self->menu_item, + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK (on_menu_item_activated), + self); + + self->proxy = + g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, + NULL, + ONLINE_ACCOUNTS_BUS_NAME, + ONLINE_ACCOUNTS_OBJECT_PATH, + ONLINE_ACCOUNTS_INTERFACE, + NULL, + &error); + if (G_UNLIKELY (error != NULL)) { + g_warning ("Couldn't create online_accounts proxy: %s", error->message); + g_clear_error (&error); + return; + } + + g_signal_connect (self->proxy, "g-properties-changed", + G_CALLBACK (on_properties_changed), self); + + error_status_prop = + g_dbus_proxy_get_cached_property (self->proxy, "ErrorStatus"); + if (error_status_prop != NULL) { + update_disposition (self, error_status_prop); + g_variant_unref (error_status_prop); + } +} + +static void +online_accounts_mgr_dispose (GObject *object) +{ + OnlineAccountsMgr *self = ONLINE_ACCOUNTS_MGR (object); + + if (self->proxy != NULL) { + g_object_unref (self->proxy); + self->proxy = NULL; + } + + if (self->menu_item != NULL) { + g_object_unref (self->menu_item); + self->menu_item = NULL; + } + + G_OBJECT_CLASS (online_accounts_mgr_parent_class)->dispose (object); +} + +static void +online_accounts_mgr_class_init (OnlineAccountsMgrClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + object_class->dispose = online_accounts_mgr_dispose; +} + +OnlineAccountsMgr *online_accounts_mgr_new () +{ + return g_object_new (ONLINE_ACCOUNTS_TYPE_MGR, NULL); +} + +DbusmenuMenuitem *online_accounts_mgr_get_menu_item (OnlineAccountsMgr *self) +{ + g_return_val_if_fail (ONLINE_ACCOUNTS_IS_MGR (self), NULL); + return self->menu_item; +} diff --git a/src/online-accounts-mgr.h b/src/online-accounts-mgr.h new file mode 100644 index 0000000..16c0461 --- /dev/null +++ b/src/online-accounts-mgr.h @@ -0,0 +1,50 @@ +/* +Copyright 2012 Canonical Ltd. + +Authors: + Alberto Mardegan <alberto.mardegan@canonical.com> + +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 <http://www.gnu.org/licenses/>. +*/ + +#ifndef _ONLINE_ACCOUNTS_MGR_H_ +#define _ONLINE_ACCOUNTS_MGR_H_ + +#include <glib-object.h> +#include <libdbusmenu-glib/menuitem.h> + +G_BEGIN_DECLS + +#define ONLINE_ACCOUNTS_TYPE_MGR (online_accounts_mgr_get_type ()) +#define ONLINE_ACCOUNTS_MGR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ONLINE_ACCOUNTS_TYPE_MGR, OnlineAccountsMgr)) +#define ONLINE_ACCOUNTS_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ONLINE_ACCOUNTS_TYPE_MGR, OnlineAccountsMgrClass)) +#define ONLINE_ACCOUNTS_IS_MGR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ONLINE_ACCOUNTS_TYPE_MGR)) +#define ONLINE_ACCOUNTS_IS_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ONLINE_ACCOUNTS_TYPE_MGR)) +#define ONLINE_ACCOUNTS_MGR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ONLINE_ACCOUNTS_TYPE_MGR, OnlineAccountsMgrClass)) + +typedef struct _OnlineAccountsMgrClass OnlineAccountsMgrClass; +typedef struct _OnlineAccountsMgr OnlineAccountsMgr; + +struct _OnlineAccountsMgrClass +{ + GObjectClass parent_class; +}; + +GType online_accounts_mgr_get_type (void) G_GNUC_CONST; +OnlineAccountsMgr *online_accounts_mgr_new (void); + +DbusmenuMenuitem *online_accounts_mgr_get_menu_item (OnlineAccountsMgr *self); + +G_END_DECLS + +#endif /* _ONLINE_ACCOUNTS_MGR_H_ */ diff --git a/src/session-menu-mgr.c b/src/session-menu-mgr.c index 96fc2a0..643abd1 100644 --- a/src/session-menu-mgr.c +++ b/src/session-menu-mgr.c @@ -33,6 +33,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include "session-menu-mgr.h" #include "shared-names.h" #include "users-service-dbus.h" +#include "online-accounts-mgr.h" #define DEBUG_SHOW_ALL FALSE @@ -88,6 +89,7 @@ struct _SessionMenuMgr DbusmenuMenuitem * lock_mi; DbusmenuMenuitem * lock_switch_mi; DbusmenuMenuitem * guest_mi; + DbusmenuMenuitem * online_accounts_mi; DbusmenuMenuitem * logout_mi; DbusmenuMenuitem * suspend_mi; DbusmenuMenuitem * hibernate_mi; @@ -113,6 +115,7 @@ struct _SessionMenuMgr DBusUPower * upower_proxy; SessionDbus * session_dbus; UsersServiceDbus * users_dbus_facade; + OnlineAccountsMgr * online_accounts_mgr; }; static SwitcherMode get_switcher_mode (SessionMenuMgr *); @@ -192,6 +195,9 @@ session_menu_mgr_init (SessionMenuMgr *mgr) G_CALLBACK(on_guest_logged_in_changed), mgr); init_upower_proxy (mgr); + + /* Online accounts menu item */ + mgr->online_accounts_mgr = online_accounts_mgr_new (); } static void @@ -212,6 +218,7 @@ session_menu_mgr_dispose (GObject *object) g_clear_object (&mgr->users_dbus_facade); g_clear_object (&mgr->top_mi); g_clear_object (&mgr->session_dbus); + g_clear_object (&mgr->online_accounts_mgr); g_slist_free (mgr->user_menuitems); mgr->user_menuitems = NULL; @@ -362,6 +369,29 @@ mi_new (const char * label) return mi; } +static void +check_online_accounts_status (SessionMenuMgr * mgr, DbusmenuMenuitem * mi) +{ + const gchar *disposition; + gboolean on_alert; + + disposition = + dbusmenu_menuitem_property_get (mi, DBUSMENU_MENUITEM_PROP_DISPOSITION); + on_alert = g_strcmp0 (disposition, DBUSMENU_MENUITEM_DISPOSITION_ALERT) == 0; + + mi_set_visible (mi, on_alert); +} + +static void +on_online_accounts_changed (SessionMenuMgr * mgr, const gchar * property, + GVariant *value, DbusmenuMenuitem *mi) +{ + if (g_strcmp0 (property, DBUSMENU_MENUITEM_PROP_DISPOSITION) == 0) + { + check_online_accounts_status(mgr, mi); + } +} + /*** **** Admin Menuitems **** <https://wiki.ubuntu.com/SystemMenu#Admin_items> @@ -396,6 +426,14 @@ build_admin_menuitems (SessionMenuMgr * mgr) G_CALLBACK(action_func_spawn_async), CMD_SYSTEM_SETTINGS); + mi = mgr->online_accounts_mi = + online_accounts_mgr_get_menu_item (mgr->online_accounts_mgr); + dbusmenu_menuitem_child_append (mgr->top_mi, mi); + g_signal_connect_swapped (mi, DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, + G_CALLBACK(on_online_accounts_changed), + mgr); + check_online_accounts_status (mgr, mi); + mi = mi_new_separator (); dbusmenu_menuitem_child_append (mgr->top_mi, mi); } |