[seahorse] gkr: No keyring UI bits if failed to connect to Secret Service



commit 4619f1bb35aa5ea79b0b45ba40da6a10abd684ba
Author: Stef Walter <stefw gnome org>
Date:   Fri Jun 29 15:38:51 2012 +0200

    gkr: No keyring UI bits if failed to connect to Secret Service
    
     * Only register keyring ui bits with the interface once
       we've connected to the Secret Service
    
    https://bugzilla.gnome.org/show_bug.cgi?id=668770

 gkr/seahorse-gkr-actions.c |   33 ++++++++++++++++++++++++++++-----
 gkr/seahorse-gkr-actions.h |    3 ++-
 gkr/seahorse-gkr-backend.c |   16 ++++++++++++----
 3 files changed, 42 insertions(+), 10 deletions(-)
---
diff --git a/gkr/seahorse-gkr-actions.c b/gkr/seahorse-gkr-actions.c
index fe55fe6..e8de87d 100644
--- a/gkr/seahorse-gkr-actions.c
+++ b/gkr/seahorse-gkr-actions.c
@@ -48,6 +48,7 @@ GType   seahorse_gkr_backend_actions_get_type           (void) G_GNUC_CONST;
 
 typedef struct {
 	SeahorseActions parent;
+	gboolean initialized;
 } SeahorseGkrBackendActions;
 
 typedef struct {
@@ -98,11 +99,19 @@ static const gchar* BACKEND_UI =
 "</ui>";
 
 static void
-seahorse_gkr_backend_actions_init (SeahorseGkrBackendActions *self)
+on_backend_notify_service (GObject *obj,
+                           GParamSpec *pspec,
+                           gpointer user_data)
 {
+	SeahorseGkrBackendActions *self = SEAHORSE_GKR_BACKEND_ACTIONS (user_data);
 	GtkActionGroup *actions = GTK_ACTION_GROUP (self);
 
-	gtk_action_group_set_translation_domain (actions, GETTEXT_PACKAGE);
+	if (self->initialized)
+		return;
+	if (seahorse_gkr_backend_get_service (SEAHORSE_GKR_BACKEND (obj)) == NULL)
+		return;
+
+	self->initialized = TRUE;
 	gtk_action_group_add_actions (actions, BACKEND_ACTIONS, G_N_ELEMENTS (BACKEND_ACTIONS), NULL);
 	seahorse_actions_register_definition (SEAHORSE_ACTIONS (self), BACKEND_UI);
 
@@ -115,15 +124,22 @@ seahorse_gkr_backend_actions_init (SeahorseGkrBackendActions *self)
 }
 
 static void
+seahorse_gkr_backend_actions_init (SeahorseGkrBackendActions *self)
+{
+	GtkActionGroup *actions = GTK_ACTION_GROUP (self);
+	gtk_action_group_set_translation_domain (actions, GETTEXT_PACKAGE);
+}
+
+static void
 seahorse_gkr_backend_actions_class_init (SeahorseGkrBackendActionsClass *klass)
 {
 
 }
 
 GtkActionGroup *
-seahorse_gkr_backend_actions_instance (void)
+seahorse_gkr_backend_actions_instance (SeahorseGkrBackend *backend)
 {
-	static GtkActionGroup *actions = NULL;
+	static SeahorseGkrBackendActions *actions = NULL;
 
 	if (actions == NULL) {
 		actions = g_object_new (SEAHORSE_TYPE_GKR_BACKEND_ACTIONS,
@@ -131,11 +147,18 @@ seahorse_gkr_backend_actions_instance (void)
 		                        NULL);
 		g_object_add_weak_pointer (G_OBJECT (actions),
 		                           (gpointer *)&actions);
+
+		g_signal_connect_object (backend, "notify::service",
+		                         G_CALLBACK (on_backend_notify_service),
+		                         actions, G_CONNECT_AFTER);
+
+		if (seahorse_gkr_backend_get_service (backend) != NULL)
+			on_backend_notify_service (G_OBJECT (backend), NULL, actions);
 	} else {
 		g_object_ref (actions);
 	}
 
-	return actions;
+	return GTK_ACTION_GROUP (actions);
 }
 
 static void
diff --git a/gkr/seahorse-gkr-actions.h b/gkr/seahorse-gkr-actions.h
index bacdeb0..c8f0a3c 100644
--- a/gkr/seahorse-gkr-actions.h
+++ b/gkr/seahorse-gkr-actions.h
@@ -22,11 +22,12 @@
 #ifndef __SEAHORSE_GKR_ACTIONS_H__
 #define __SEAHORSE_GKR_ACTIONS_H__
 
+#include "seahorse-gkr-backend.h"
 #include "seahorse-gkr-keyring.h"
 
 #include <gtk/gtk.h>
 
-GtkActionGroup *     seahorse_gkr_backend_actions_instance      (void);
+GtkActionGroup *     seahorse_gkr_backend_actions_instance      (SeahorseGkrBackend *backend);
 
 GtkActionGroup *     seahorse_gkr_keyring_actions_new           (SeahorseGkrKeyring *keyring);
 
diff --git a/gkr/seahorse-gkr-backend.c b/gkr/seahorse-gkr-backend.c
index 48dbf01..720d7ff 100644
--- a/gkr/seahorse-gkr-backend.c
+++ b/gkr/seahorse-gkr-backend.c
@@ -57,7 +57,8 @@ enum {
 	PROP_LABEL,
 	PROP_DESCRIPTION,
 	PROP_ACTIONS,
-	PROP_ALIASES
+	PROP_ALIASES,
+	PROP_SERVICE
 };
 
 static SeahorseGkrBackend *gkr_backend = NULL;
@@ -89,7 +90,7 @@ seahorse_gkr_backend_init (SeahorseGkrBackend *self)
 	g_return_if_fail (gkr_backend == NULL);
 	gkr_backend = self;
 
-	self->actions = seahorse_gkr_backend_actions_instance ();
+	self->actions = seahorse_gkr_backend_actions_instance (self);
 	self->keyrings = g_hash_table_new_full (g_str_hash, g_str_equal,
 	                                        g_free, g_object_unref);
 	self->aliases = g_hash_table_new_full (g_str_hash, g_str_equal,
@@ -167,13 +168,13 @@ on_service_new (GObject *source,
 		refresh_collection (self);
 
 		secret_service_ensure_collections (self->service, NULL, NULL, NULL);
-		secret_service_ensure_session (self->service, NULL, NULL, NULL);
 		seahorse_gkr_backend_load_async (self, NULL, NULL, NULL);
 	} else {
 		g_warning ("couldn't connect to secret service: %s", error->message);
 		g_error_free (error);
 	}
 
+	g_object_notify (G_OBJECT (self), "service");
 	g_object_unref (self);
 }
 
@@ -184,7 +185,7 @@ seahorse_gkr_backend_constructed (GObject *obj)
 
 	G_OBJECT_CLASS (seahorse_gkr_backend_parent_class)->constructed (obj);
 
-	secret_service_new (my_secret_service_get_type (), NULL, SECRET_SERVICE_NONE,
+	secret_service_new (my_secret_service_get_type (), NULL, SECRET_SERVICE_OPEN_SESSION,
 	                    NULL, on_service_new, g_object_ref (self));
 }
 
@@ -212,6 +213,9 @@ seahorse_gkr_backend_get_property (GObject *obj,
 	case PROP_ALIASES:
 		g_value_set_boxed (value, self->aliases);
 		break;
+	case PROP_SERVICE:
+		g_value_set_object (value, self->service);
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
 		break;
@@ -271,6 +275,10 @@ seahorse_gkr_backend_class_init (SeahorseGkrBackendClass *klass)
 	g_object_class_install_property (gobject_class, PROP_ALIASES,
 	             g_param_spec_boxed ("aliases", "aliases", "Aliases",
 	                                 G_TYPE_HASH_TABLE, G_PARAM_READABLE));
+
+	g_object_class_install_property (gobject_class, PROP_SERVICE,
+	            g_param_spec_object ("service", "Service", "Service",
+	                                 SECRET_TYPE_SERVICE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 }
 
 static guint



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]