2
Copyright 2012 Canonical Ltd.
5
Alberto Mardegan <alberto.mardegan@canonical.com>
7
This program is free software: you can redistribute it and/or modify it
8
under the terms of the GNU General Public License version 3, as published
9
by the Free Software Foundation.
11
This program is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranties of
13
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14
PURPOSE. See the GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License along
17
with this program. If not, see <http://www.gnu.org/licenses/>.
21
#include <glib/gi18n.h>
23
#include "online-accounts-mgr.h"
25
#include <libdbusmenu-glib/client.h>
27
struct _OnlineAccountsMgr
29
GObject parent_instance;
31
DbusmenuMenuitem *menu_item;
34
#define ONLINE_ACCOUNTS_OBJECT_PATH "/com/canonical/indicators/webcredentials"
35
#define ONLINE_ACCOUNTS_BUS_NAME "com.canonical.indicators.webcredentials"
36
#define ONLINE_ACCOUNTS_INTERFACE ONLINE_ACCOUNTS_BUS_NAME
38
G_DEFINE_TYPE (OnlineAccountsMgr, online_accounts_mgr, G_TYPE_OBJECT);
41
update_disposition (OnlineAccountsMgr *self, GVariant *error_status_prop)
43
gboolean error_status;
45
error_status = g_variant_get_boolean (error_status_prop);
46
dbusmenu_menuitem_property_set (self->menu_item,
47
DBUSMENU_MENUITEM_PROP_DISPOSITION,
49
DBUSMENU_MENUITEM_DISPOSITION_ALERT :
50
DBUSMENU_MENUITEM_DISPOSITION_NORMAL);
54
on_properties_changed (GDBusProxy *proxy,
55
GVariant *changed_properties,
56
GStrv invalidated_properties,
57
OnlineAccountsMgr *self)
59
if (g_variant_n_children (changed_properties) > 0) {
64
g_variant_get (changed_properties, "a{sv}", &iter);
65
while (g_variant_iter_loop (iter, "{&sv}", &key, &value)) {
66
if (g_strcmp0 (key, "ErrorStatus") == 0) {
67
update_disposition (self, value);
70
g_variant_iter_free (iter);
75
on_menu_item_activated (DbusmenuMenuitem *menu_item,
77
OnlineAccountsMgr *self)
81
if (!g_spawn_command_line_async("gnome-control-center credentials", &error))
83
g_warning("Unable to show control center: %s", error->message);
89
online_accounts_mgr_init (OnlineAccountsMgr *self)
92
GVariant *error_status_prop;
94
self->menu_item = dbusmenu_menuitem_new ();
95
dbusmenu_menuitem_property_set (self->menu_item,
96
DBUSMENU_MENUITEM_PROP_TYPE,
97
DBUSMENU_CLIENT_TYPES_DEFAULT);
98
dbusmenu_menuitem_property_set (self->menu_item,
99
DBUSMENU_MENUITEM_PROP_LABEL,
100
_("Online Accounts\342\200\246"));
101
g_signal_connect (self->menu_item,
102
DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
103
G_CALLBACK (on_menu_item_activated),
107
g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
108
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
110
ONLINE_ACCOUNTS_BUS_NAME,
111
ONLINE_ACCOUNTS_OBJECT_PATH,
112
ONLINE_ACCOUNTS_INTERFACE,
115
if (G_UNLIKELY (error != NULL)) {
116
g_warning ("Couldn't create online_accounts proxy: %s", error->message);
117
g_clear_error (&error);
121
g_signal_connect (self->proxy, "g-properties-changed",
122
G_CALLBACK (on_properties_changed), self);
125
g_dbus_proxy_get_cached_property (self->proxy, "ErrorStatus");
126
if (error_status_prop != NULL) {
127
update_disposition (self, error_status_prop);
128
g_variant_unref (error_status_prop);
133
online_accounts_mgr_dispose (GObject *object)
135
OnlineAccountsMgr *self = ONLINE_ACCOUNTS_MGR (object);
137
if (self->proxy != NULL) {
138
g_object_unref (self->proxy);
142
if (self->menu_item != NULL) {
143
g_object_unref (self->menu_item);
144
self->menu_item = NULL;
147
G_OBJECT_CLASS (online_accounts_mgr_parent_class)->dispose (object);
151
online_accounts_mgr_class_init (OnlineAccountsMgrClass *klass)
153
GObjectClass *object_class = G_OBJECT_CLASS (klass);
154
object_class->dispose = online_accounts_mgr_dispose;
157
OnlineAccountsMgr *online_accounts_mgr_new ()
159
return g_object_new (ONLINE_ACCOUNTS_TYPE_MGR, NULL);
162
DbusmenuMenuitem *online_accounts_mgr_get_menu_item (OnlineAccountsMgr *self)
164
g_return_val_if_fail (ONLINE_ACCOUNTS_IS_MGR (self), NULL);
165
return self->menu_item;