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/>.
20
#include <glib/gi18n.h>
22
#include "webcredentials-mgr.h"
24
struct _WebcredentialsMgr
26
WebcredentialsSkeleton parent_instance;
27
GDBusConnection *connection;
28
DbusmenuMenuitem *menu_item;
29
GHashTable *failed_accounts;
32
#define WEBCREDENTIALS_OBJECT_PATH "/com/canonical/indicators/webcredentials"
34
G_DEFINE_TYPE (WebcredentialsMgr, webcredentials_mgr,
35
TYPE_WEBCREDENTIALS_SKELETON);
38
update_failed_accounts_property (WebcredentialsMgr *self)
45
account_ids = g_array_sized_new (FALSE, FALSE,
47
g_hash_table_size (self->failed_accounts));
49
g_hash_table_iter_init (&iter, self->failed_accounts);
50
while (g_hash_table_iter_next (&iter, &key, NULL)) {
51
g_array_append_val (account_ids, key);
54
value = g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32,
58
g_object_set ((GObject *)self,
61
g_array_free (account_ids, TRUE);
65
webcredentials_mgr_clear_error_status (WebcredentialsMgr *self,
66
GDBusMethodInvocation *invocation)
68
g_return_val_if_fail (WEBCREDENTIALS_IS_MGR (self), FALSE);
72
webcredentials_complete_clear_error_status ((Webcredentials *)self,
78
webcredentials_mgr_remove_failures (WebcredentialsMgr *self,
79
GDBusMethodInvocation *invocation,
80
GVariant *arg_account_ids)
83
const guint32 *account_ids;
85
gboolean changed = FALSE;
87
g_return_val_if_fail (WEBCREDENTIALS_IS_MGR (self), FALSE);
89
account_ids = g_variant_get_fixed_array (arg_account_ids,
92
for (i = 0; i < n_accounts; i++) {
93
if (g_hash_table_remove (self->failed_accounts,
94
GINT_TO_POINTER (account_ids[i])))
99
update_failed_accounts_property (self);
101
webcredentials_complete_remove_failures ((Webcredentials *)self,
107
webcredentials_mgr_report_failure (WebcredentialsMgr *self,
108
GDBusMethodInvocation *invocation,
110
GVariant *arg_notification)
112
g_return_val_if_fail (WEBCREDENTIALS_IS_MGR (self), FALSE);
114
g_hash_table_insert (self->failed_accounts,
115
GINT_TO_POINTER(account_id),
116
GINT_TO_POINTER(TRUE));
117
update_failed_accounts_property (self);
119
/* TODO: emit the notification and set the error status */
121
webcredentials_complete_report_failure ((Webcredentials *)self,
127
webcredentials_mgr_init (WebcredentialsMgr *self)
129
GError *error = NULL;
131
self->menu_item = dbusmenu_menuitem_new ();
132
/* TODO: setup the menu item */
134
self->failed_accounts = g_hash_table_new (g_direct_hash,
136
self->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
137
if (G_UNLIKELY (error != NULL)) {
138
g_warning ("Couldn't connect to session bus: %s", error->message);
139
g_clear_error (&error);
143
g_signal_connect (self, "handle-clear-error-status",
144
G_CALLBACK (webcredentials_mgr_clear_error_status), NULL);
145
g_signal_connect (self, "handle-remove-failures",
146
G_CALLBACK (webcredentials_mgr_remove_failures), NULL);
147
g_signal_connect (self, "handle-report-failure",
148
G_CALLBACK (webcredentials_mgr_report_failure), NULL);
150
if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (self),
152
WEBCREDENTIALS_OBJECT_PATH,
154
g_return_if_fail (error != NULL);
155
g_warning ("Couldn't register webcredentials service: %s", error->message);
156
g_clear_error (&error);
161
webcredentials_mgr_dispose (GObject *object)
163
WebcredentialsMgr *self = WEBCREDENTIALS_MGR (object);
165
if (self->menu_item != NULL) {
166
g_object_unref (self->menu_item);
167
self->menu_item = NULL;
170
if (self->connection != NULL) {
171
g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (self));
172
g_object_unref (self->connection);
173
self->connection = NULL;
176
G_OBJECT_CLASS (webcredentials_mgr_parent_class)->dispose (object);
180
webcredentials_mgr_finalize (GObject *object)
182
WebcredentialsMgr *self = WEBCREDENTIALS_MGR (object);
184
g_hash_table_destroy (self->failed_accounts);
186
G_OBJECT_CLASS (webcredentials_mgr_parent_class)->finalize (object);
190
webcredentials_mgr_class_init (WebcredentialsMgrClass *klass)
192
GObjectClass *object_class = G_OBJECT_CLASS (klass);
193
object_class->dispose = webcredentials_mgr_dispose;
194
object_class->finalize = webcredentials_mgr_finalize;
197
WebcredentialsMgr *webcredentials_mgr_new ()
199
return g_object_new (WEBCREDENTIALS_TYPE_MGR, NULL);
202
DbusmenuMenuitem *webcredentials_mgr_get_menu_item (WebcredentialsMgr *self)
204
g_return_val_if_fail (WEBCREDENTIALS_IS_MGR (self), NULL);
205
return self->menu_item;