aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlberto Mardegan <alberto.mardegan@canonical.com>2012-08-21 09:56:28 +0300
committerAlberto Mardegan <alberto.mardegan@canonical.com>2012-08-21 09:56:28 +0300
commit6bdbcc0a3d63ce7e9dbc29a86e1c3570725bb9c5 (patch)
tree308cce1bac13b45495108750f600bb3cf8eb1517 /src
parentc69973f9c525f8c3c8681374111f2c0f839005d3 (diff)
parentdb65e23e1fa51bf8c18f59d126e7c397fba2a206 (diff)
downloadayatana-indicator-session-6bdbcc0a3d63ce7e9dbc29a86e1c3570725bb9c5.tar.gz
ayatana-indicator-session-6bdbcc0a3d63ce7e9dbc29a86e1c3570725bb9c5.tar.bz2
ayatana-indicator-session-6bdbcc0a3d63ce7e9dbc29a86e1c3570725bb9c5.zip
Apply old webcredentials patch to trunk
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am4
-rw-r--r--src/session-service.c1
-rw-r--r--src/webcredentials-mgr.c166
-rw-r--r--src/webcredentials-mgr.h50
4 files changed, 220 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 7bc6306..b28ca4a 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 \
+ webcredentials-mgr.c \
+ webcredentials-mgr.h
indicator_session_service_CFLAGS = \
$(SESSIONSERVICE_CFLAGS) \
diff --git a/src/session-service.c b/src/session-service.c
index 91bbccd..6d5a7f3 100644
--- a/src/session-service.c
+++ b/src/session-service.c
@@ -26,6 +26,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include "config.h"
+#include <locale.h>
#include <unistd.h>
#include <locale.h>
diff --git a/src/webcredentials-mgr.c b/src/webcredentials-mgr.c
new file mode 100644
index 0000000..8b44a95
--- /dev/null
+++ b/src/webcredentials-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 "webcredentials-mgr.h"
+
+#include <libdbusmenu-glib/client.h>
+
+struct _WebcredentialsMgr
+{
+ GObject parent_instance;
+ GDBusProxy *proxy;
+ DbusmenuMenuitem *menu_item;
+};
+
+#define WEBCREDENTIALS_OBJECT_PATH "/com/canonical/indicators/webcredentials"
+#define WEBCREDENTIALS_BUS_NAME "com.canonical.indicators.webcredentials"
+#define WEBCREDENTIALS_INTERFACE WEBCREDENTIALS_BUS_NAME
+
+G_DEFINE_TYPE (WebcredentialsMgr, webcredentials_mgr, G_TYPE_OBJECT);
+
+static void
+update_disposition (WebcredentialsMgr *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,
+ WebcredentialsMgr *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,
+ WebcredentialsMgr *self)
+{
+ GError *error = NULL;
+
+ if (!g_spawn_command_line_async("gnome-control-center credentials", &error))
+ {
+ g_warning("Unable to show control centre: %s", error->message);
+ g_error_free(error);
+ }
+}
+
+static void
+webcredentials_mgr_init (WebcredentialsMgr *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,
+ _("Web Accounts…"));
+ 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,
+ WEBCREDENTIALS_BUS_NAME,
+ WEBCREDENTIALS_OBJECT_PATH,
+ WEBCREDENTIALS_INTERFACE,
+ NULL,
+ &error);
+ if (G_UNLIKELY (error != NULL)) {
+ g_warning ("Couldn't create webcredentials 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
+webcredentials_mgr_dispose (GObject *object)
+{
+ WebcredentialsMgr *self = WEBCREDENTIALS_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 (webcredentials_mgr_parent_class)->dispose (object);
+}
+
+static void
+webcredentials_mgr_class_init (WebcredentialsMgrClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->dispose = webcredentials_mgr_dispose;
+}
+
+WebcredentialsMgr *webcredentials_mgr_new ()
+{
+ return g_object_new (WEBCREDENTIALS_TYPE_MGR, NULL);
+}
+
+DbusmenuMenuitem *webcredentials_mgr_get_menu_item (WebcredentialsMgr *self)
+{
+ g_return_val_if_fail (WEBCREDENTIALS_IS_MGR (self), NULL);
+ return self->menu_item;
+}
diff --git a/src/webcredentials-mgr.h b/src/webcredentials-mgr.h
new file mode 100644
index 0000000..6c16ea0
--- /dev/null
+++ b/src/webcredentials-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 _WEBCREDENTIALS_MGR_H_
+#define _WEBCREDENTIALS_MGR_H_
+
+#include <glib-object.h>
+#include <libdbusmenu-glib/menuitem.h>
+
+G_BEGIN_DECLS
+
+#define WEBCREDENTIALS_TYPE_MGR (webcredentials_mgr_get_type ())
+#define WEBCREDENTIALS_MGR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WEBCREDENTIALS_TYPE_MGR, WebcredentialsMgr))
+#define WEBCREDENTIALS_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WEBCREDENTIALS_TYPE_MGR, WebcredentialsMgrClass))
+#define WEBCREDENTIALS_IS_MGR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WEBCREDENTIALS_TYPE_MGR))
+#define WEBCREDENTIALS_IS_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WEBCREDENTIALS_TYPE_MGR))
+#define WEBCREDENTIALS_MGR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WEBCREDENTIALS_TYPE_MGR, WebcredentialsMgrClass))
+
+typedef struct _WebcredentialsMgrClass WebcredentialsMgrClass;
+typedef struct _WebcredentialsMgr WebcredentialsMgr;
+
+struct _WebcredentialsMgrClass
+{
+ GObjectClass parent_class;
+};
+
+GType webcredentials_mgr_get_type (void) G_GNUC_CONST;
+WebcredentialsMgr *webcredentials_mgr_new (void);
+
+DbusmenuMenuitem *webcredentials_mgr_get_menu_item (WebcredentialsMgr *self);
+
+G_END_DECLS
+
+#endif /* _WEBCREDENTIALS_MGR_H_ */