[seahorse] Add way to lookup places, and refresh appropriate place after import
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [seahorse] Add way to lookup places, and refresh appropriate place after import
- Date: Tue, 13 Dec 2011 19:12:24 +0000 (UTC)
commit 7907fc56b1e9a406b7baa0c7da4ed188757b029e
Author: Stef Walter <stefw collabora co uk>
Date: Tue Dec 13 19:39:57 2011 +0100
Add way to lookup places, and refresh appropriate place after import
* Since importing is done by libgcr, we look up the uri on the
importer.
* So then we need a way to find the place that matches a uri.
URIs aren't always unique, so virtual method on SeahorseBackend
* Make refresh methods on place be virtual, so we can call from
generic code.
gkr/seahorse-gkr-backend.c | 33 +++++++++++++++++-------
gkr/seahorse-gkr-keyring.c | 37 ++++++++++++---------------
gkr/seahorse-gkr-keyring.h | 11 --------
libseahorse/seahorse-backend.c | 33 ++++++++++++++++++++++++
libseahorse/seahorse-backend.h | 13 ++++++++-
libseahorse/seahorse-place.c | 27 +++++++++++++++++--
libseahorse/seahorse-place.h | 22 ++++++++++++++-
pgp/seahorse-gpgme-keyring.c | 15 ++++++----
pgp/seahorse-gpgme-keyring.h | 9 ------
pgp/seahorse-pgp-backend.c | 22 ++++++++++++----
pkcs11/seahorse-pkcs11-backend.c | 50 ++++++++++++++++++++++++++----------
pkcs11/seahorse-pkcs11-backend.h | 1 +
pkcs11/seahorse-pkcs11-generate.c | 2 +-
pkcs11/seahorse-token.c | 38 ++++++++++++++--------------
pkcs11/seahorse-token.h | 9 ------
src/seahorse-import-dialog.c | 16 ++++++++++++
src/seahorse-sidebar.c | 3 +-
ssh/seahorse-ssh-backend.c | 32 ++++++++++++++++++-----
ssh/seahorse-ssh-source.c | 15 ++++++----
ssh/seahorse-ssh-source.h | 9 ------
20 files changed, 260 insertions(+), 137 deletions(-)
---
diff --git a/gkr/seahorse-gkr-backend.c b/gkr/seahorse-gkr-backend.c
index 28a06ff..4f009be 100644
--- a/gkr/seahorse-gkr-backend.c
+++ b/gkr/seahorse-gkr-backend.c
@@ -28,7 +28,6 @@
#include "seahorse-backend.h"
#include "seahorse-progress.h"
-#include "seahorse-registry.h"
#include <gnome-keyring.h>
@@ -54,13 +53,13 @@ struct _SeahorseGkrBackendClass {
GObjectClass parent_class;
};
-static void seahorse_gkr_backend_iface_init (SeahorseBackendIface *iface);
+static void seahorse_gkr_backend_iface (SeahorseBackendIface *iface);
static void seahorse_gkr_backend_collection_init (GcrCollectionIface *iface);
G_DEFINE_TYPE_WITH_CODE (SeahorseGkrBackend, seahorse_gkr_backend, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (GCR_TYPE_COLLECTION, seahorse_gkr_backend_collection_init);
- G_IMPLEMENT_INTERFACE (SEAHORSE_TYPE_BACKEND, seahorse_gkr_backend_iface_init);
+ G_IMPLEMENT_INTERFACE (SEAHORSE_TYPE_BACKEND, seahorse_gkr_backend_iface);
);
static void
@@ -188,10 +187,24 @@ seahorse_gkr_backend_collection_init (GcrCollectionIface *iface)
iface->get_objects = seahorse_gkr_backend_get_objects;
}
-static void
-seahorse_gkr_backend_iface_init (SeahorseBackendIface *iface)
+static SeahorsePlace *
+seahorse_gkr_backend_lookup_place (SeahorseBackend *backend,
+ const gchar *uri)
{
+ SeahorseGkrBackend *self = SEAHORSE_GKR_BACKEND (backend);
+
+ if (g_str_has_prefix (uri, "secret-service://")) {
+ uri += strlen ("secret-service://");
+ return g_hash_table_lookup (self->keyrings, uri);
+ }
+ return NULL;
+}
+
+static void
+seahorse_gkr_backend_iface (SeahorseBackendIface *iface)
+{
+ iface->lookup_place = seahorse_gkr_backend_lookup_place;
}
void
@@ -202,7 +215,7 @@ seahorse_gkr_backend_initialize (void)
g_return_if_fail (gkr_backend == NULL);
self = g_object_new (SEAHORSE_TYPE_GKR_BACKEND, NULL);
- seahorse_registry_register_object (NULL, G_OBJECT (self), "backend", "gnome-keyring", NULL);
+ seahorse_backend_register (SEAHORSE_BACKEND (self));
g_object_unref (self);
g_return_if_fail (gkr_backend != NULL);
@@ -319,7 +332,7 @@ on_backend_load_keyring_complete (GObject *object,
closure->num_loads--;
seahorse_progress_end (closure->cancellable, keyring);
- if (!seahorse_gkr_keyring_load_finish (keyring, result, &error))
+ if (!seahorse_place_load_finish (SEAHORSE_PLACE (keyring), result, &error))
g_simple_async_result_take_error (res, error);
if (closure->num_loads == 0)
@@ -381,9 +394,9 @@ on_backend_load_list_keyring_names_complete (GnomeKeyringResult result,
}
/* Refresh the keyring as well, and track the load */
- seahorse_gkr_keyring_load_async (keyring, closure->cancellable,
- on_backend_load_keyring_complete,
- g_object_ref (res));
+ seahorse_place_load_async (SEAHORSE_PLACE (keyring), closure->cancellable,
+ on_backend_load_keyring_complete,
+ g_object_ref (res));
seahorse_progress_prep_and_begin (closure->cancellable, keyring, NULL);
closure->num_loads++;
g_object_unref (keyring);
diff --git a/gkr/seahorse-gkr-keyring.c b/gkr/seahorse-gkr-keyring.c
index 5b58383..c158fa2 100644
--- a/gkr/seahorse-gkr-keyring.c
+++ b/gkr/seahorse-gkr-keyring.c
@@ -64,7 +64,7 @@ struct _SeahorseGkrKeyringPrivate {
GnomeKeyringInfo *keyring_info;
};
-static void seahorse_keyring_place_iface (SeahorsePlaceIface *iface);
+static void seahorse_gkr_keyring_place_iface (SeahorsePlaceIface *iface);
static void seahorse_keyring_collection_iface (GcrCollectionIface *iface);
@@ -76,7 +76,7 @@ static void seahorse_keyring_viewable_iface (SeahorseViewableIface *ifac
G_DEFINE_TYPE_WITH_CODE (SeahorseGkrKeyring, seahorse_gkr_keyring, SEAHORSE_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (GCR_TYPE_COLLECTION, seahorse_keyring_collection_iface);
- G_IMPLEMENT_INTERFACE (SEAHORSE_TYPE_PLACE, seahorse_keyring_place_iface);
+ G_IMPLEMENT_INTERFACE (SEAHORSE_TYPE_PLACE, seahorse_gkr_keyring_place_iface);
G_IMPLEMENT_INTERFACE (SEAHORSE_TYPE_DELETABLE, seahorse_keyring_deletable_iface);
G_IMPLEMENT_INTERFACE (SEAHORSE_TYPE_LOCKABLE, seahorse_keyring_lockable_iface);
G_IMPLEMENT_INTERFACE (SEAHORSE_TYPE_VIEWABLE, seahorse_keyring_viewable_iface);
@@ -163,13 +163,6 @@ seahorse_gkr_keyring_realize (SeahorseGkrKeyring *self)
}
void
-seahorse_gkr_keyring_refresh (SeahorseGkrKeyring *self)
-{
- if (self->pv->keyring_info)
- load_keyring_info (self);
-}
-
-void
seahorse_gkr_keyring_remove_item (SeahorseGkrKeyring *self,
guint32 item_id)
{
@@ -315,12 +308,13 @@ on_keyring_load_cancelled (GCancellable *cancellable,
gnome_keyring_cancel_request (closure->request);
}
-void
-seahorse_gkr_keyring_load_async (SeahorseGkrKeyring *self,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+static void
+seahorse_gkr_keyring_load_async (SeahorsePlace *place,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
+ SeahorseGkrKeyring *self = SEAHORSE_GKR_KEYRING (place);
keyring_load_closure *closure;
GSimpleAsyncResult *res;
@@ -345,12 +339,12 @@ seahorse_gkr_keyring_load_async (SeahorseGkrKeyring *self,
g_object_unref (res);
}
-gboolean
-seahorse_gkr_keyring_load_finish (SeahorseGkrKeyring *self,
- GAsyncResult *result,
- GError **error)
+static gboolean
+seahorse_gkr_keyring_load_finish (SeahorsePlace *place,
+ GAsyncResult *result,
+ GError **error)
{
- g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
+ g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (place),
seahorse_gkr_keyring_load_async), FALSE);
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
@@ -501,9 +495,10 @@ seahorse_gkr_keyring_class_init (SeahorseGkrKeyringClass *klass)
}
static void
-seahorse_keyring_place_iface (SeahorsePlaceIface *iface)
+seahorse_gkr_keyring_place_iface (SeahorsePlaceIface *iface)
{
-
+ iface->load_async = seahorse_gkr_keyring_load_async;
+ iface->load_finish = seahorse_gkr_keyring_load_finish;
}
static guint
diff --git a/gkr/seahorse-gkr-keyring.h b/gkr/seahorse-gkr-keyring.h
index 8e61323..67e25eb 100644
--- a/gkr/seahorse-gkr-keyring.h
+++ b/gkr/seahorse-gkr-keyring.h
@@ -53,8 +53,6 @@ GType seahorse_gkr_keyring_get_type (void);
SeahorseGkrKeyring* seahorse_gkr_keyring_new (const gchar *keyring_name);
-void seahorse_gkr_keyring_refresh (SeahorseGkrKeyring *self);
-
void seahorse_gkr_keyring_realize (SeahorseGkrKeyring *self);
void seahorse_gkr_keyring_remove_item (SeahorseGkrKeyring *self,
@@ -76,13 +74,4 @@ void seahorse_gkr_keyring_set_is_default (SeahorseGkrKeyring *
gboolean seahorse_gkr_keyring_get_locked (SeahorseGkrKeyring *self);
-void seahorse_gkr_keyring_load_async (SeahorseGkrKeyring *self,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-
-gboolean seahorse_gkr_keyring_load_finish (SeahorseGkrKeyring *self,
- GAsyncResult *result,
- GError **error);
-
#endif /* __SEAHORSE_GKR_KEYRING_H__ */
diff --git a/libseahorse/seahorse-backend.c b/libseahorse/seahorse-backend.c
index 0e7ddc2..aa70c51 100644
--- a/libseahorse/seahorse-backend.c
+++ b/libseahorse/seahorse-backend.c
@@ -22,6 +22,7 @@
#include "config.h"
#include "seahorse-backend.h"
+#include "seahorse-registry.h"
#include <gcr/gcr.h>
@@ -53,3 +54,35 @@ seahorse_backend_default_init (SeahorseBackendIface *iface)
initialized = TRUE;
}
}
+
+SeahorsePlace *
+seahorse_backend_lookup_place (SeahorseBackend *backend,
+ const gchar *uri)
+{
+ SeahorseBackendIface *iface;
+
+ g_return_val_if_fail (SEAHORSE_IS_BACKEND (backend), NULL);
+
+ iface = SEAHORSE_BACKEND_GET_INTERFACE (backend);
+ g_return_val_if_fail (iface->lookup_place != NULL, NULL);
+
+ return (iface->lookup_place) (backend, uri);
+}
+
+void
+seahorse_backend_register (SeahorseBackend *backend)
+{
+ gchar *name = NULL;
+
+ g_return_if_fail (SEAHORSE_IS_BACKEND (backend));
+
+ g_object_get (backend, "name", &name, NULL);
+ seahorse_registry_register_object (NULL, G_OBJECT (backend), "backend", name, NULL);
+ g_free (name);
+}
+
+GList *
+seahorse_backend_get_registered (void)
+{
+ return seahorse_registry_object_instances (NULL, "backend", NULL);
+}
diff --git a/libseahorse/seahorse-backend.h b/libseahorse/seahorse-backend.h
index dcb335c..d8dd75f 100644
--- a/libseahorse/seahorse-backend.h
+++ b/libseahorse/seahorse-backend.h
@@ -22,8 +22,9 @@
#ifndef __SEAHORSE_BACKEND_H__
#define __SEAHORSE_BACKEND_H__
+#include "seahorse-place.h"
+
#include <glib-object.h>
-#include <gtk/gtk.h>
#define SEAHORSE_TYPE_BACKEND (seahorse_backend_get_type ())
#define SEAHORSE_BACKEND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SEAHORSE_TYPE_BACKEND, SeahorseBackend))
@@ -35,10 +36,18 @@ typedef struct _SeahorseBackendIface SeahorseBackendIface;
struct _SeahorseBackendIface {
GTypeInterface parent;
+
+ SeahorsePlace * (* lookup_place) (SeahorseBackend *backend,
+ const gchar *uri);
};
GType seahorse_backend_get_type (void) G_GNUC_CONST;
-GtkActionGroup * seahorse_backend_get_actions (SeahorseBackend *backend);
+SeahorsePlace * seahorse_backend_lookup_place (SeahorseBackend *backend,
+ const gchar *uri);
+
+void seahorse_backend_register (SeahorseBackend *backend);
+
+GList * seahorse_backend_get_registered (void);
#endif /* __SEAHORSE_BACKEND_H__ */
diff --git a/libseahorse/seahorse-place.c b/libseahorse/seahorse-place.c
index 1bbe98a..437149f 100644
--- a/libseahorse/seahorse-place.c
+++ b/libseahorse/seahorse-place.c
@@ -79,9 +79,30 @@ seahorse_place_default_init (SeahorsePlaceIface *iface)
}
}
-/* ---------------------------------------------------------------------------------
- * PUBLIC
- */
+void
+seahorse_place_load_async (SeahorsePlace *place,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_return_if_fail (SEAHORSE_IS_PLACE (place));
+ g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
+ g_return_if_fail (SEAHORSE_PLACE_GET_INTERFACE (place)->load_async);
+ SEAHORSE_PLACE_GET_INTERFACE (place)->load_async (place, cancellable,
+ callback, user_data);
+}
+
+gboolean
+seahorse_place_load_finish (SeahorsePlace *place,
+ GAsyncResult *result,
+ GError **error)
+{
+ g_return_val_if_fail (SEAHORSE_IS_PLACE (place), FALSE);
+ g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+ g_return_val_if_fail (SEAHORSE_PLACE_GET_INTERFACE (place)->load_finish, FALSE);
+ return SEAHORSE_PLACE_GET_INTERFACE (place)->load_finish (place, result, error);
+}
void
seahorse_place_import_async (SeahorsePlace *place,
diff --git a/libseahorse/seahorse-place.h b/libseahorse/seahorse-place.h
index c0e72da..06e04a0 100644
--- a/libseahorse/seahorse-place.h
+++ b/libseahorse/seahorse-place.h
@@ -49,13 +49,22 @@ struct _SeahorsePlaceIface {
/* virtual methods ------------------------------------------------- */
- void (*import_async) (SeahorsePlace *place,
+ void (* import_async) (SeahorsePlace *place,
GInputStream *input,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
- GList * (*import_finish) (SeahorsePlace *place,
+ GList * (* import_finish) (SeahorsePlace *place,
+ GAsyncResult *result,
+ GError **error);
+
+ void (* load_async) (SeahorsePlace *place,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+ gboolean (* load_finish) (SeahorsePlace *place,
GAsyncResult *result,
GError **error);
};
@@ -74,4 +83,13 @@ GList * seahorse_place_import_finish (SeahorsePlace *place,
GAsyncResult *result,
GError **error);
+void seahorse_place_load_async (SeahorsePlace *place,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+gboolean seahorse_place_load_finish (SeahorsePlace *place,
+ GAsyncResult *result,
+ GError **error);
+
#endif /* __SEAHORSE_PLACE_H__ */
diff --git a/pgp/seahorse-gpgme-keyring.c b/pgp/seahorse-gpgme-keyring.c
index 2d0b144..a6487ac 100644
--- a/pgp/seahorse-gpgme-keyring.c
+++ b/pgp/seahorse-gpgme-keyring.c
@@ -538,22 +538,23 @@ seahorse_gpgme_keyring_remove_key (SeahorseGpgmeKeyring *self,
}
-void
-seahorse_gpgme_keyring_load_async (SeahorseGpgmeKeyring *self,
+static void
+seahorse_gpgme_keyring_load_async (SeahorsePlace *place,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
+ SeahorseGpgmeKeyring *self = SEAHORSE_GPGME_KEYRING (place);
seahorse_gpgme_keyring_load_full_async (self, NULL, 0, cancellable,
callback, user_data);
}
-gboolean
-seahorse_gpgme_keyring_load_finish (SeahorseGpgmeKeyring *self,
+static gboolean
+seahorse_gpgme_keyring_load_finish (SeahorsePlace *place,
GAsyncResult *result,
GError **error)
{
- g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
+ g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (place),
seahorse_gpgme_keyring_load_full_async), FALSE);
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
@@ -736,7 +737,7 @@ scheduled_refresh (gpointer user_data)
seahorse_debug ("scheduled refresh event ocurring now");
cancel_scheduled_refresh (self);
- seahorse_gpgme_keyring_load_async (self, NULL, NULL, NULL);
+ seahorse_gpgme_keyring_load_async (SEAHORSE_PLACE (self), NULL, NULL, NULL);
return FALSE; /* don't run again */
}
@@ -900,6 +901,8 @@ seahorse_gpgme_keyring_place_iface (SeahorsePlaceIface *iface)
{
iface->import_async = seahorse_gpgme_keyring_import_async;
iface->import_finish = seahorse_gpgme_keyring_import_finish;
+ iface->load_async = seahorse_gpgme_keyring_load_async;
+ iface->load_finish = seahorse_gpgme_keyring_load_finish;
}
static guint
diff --git a/pgp/seahorse-gpgme-keyring.h b/pgp/seahorse-gpgme-keyring.h
index 893c214..f5d092e 100644
--- a/pgp/seahorse-gpgme-keyring.h
+++ b/pgp/seahorse-gpgme-keyring.h
@@ -78,13 +78,4 @@ SeahorseGpgmeKey * seahorse_gpgme_keyring_lookup (SeahorseGpgmeKeyri
void seahorse_gpgme_keyring_remove_key (SeahorseGpgmeKeyring *self,
SeahorseGpgmeKey *key);
-void seahorse_gpgme_keyring_load_async (SeahorseGpgmeKeyring *self,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-
-gboolean seahorse_gpgme_keyring_load_finish (SeahorseGpgmeKeyring *self,
- GAsyncResult *result,
- GError **error);
-
#endif /* __SEAHORSE_GPGME_KEYRING_H__ */
diff --git a/pgp/seahorse-pgp-backend.c b/pgp/seahorse-pgp-backend.c
index 28f9f71..2b1e093 100644
--- a/pgp/seahorse-pgp-backend.c
+++ b/pgp/seahorse-pgp-backend.c
@@ -63,13 +63,13 @@ struct _SeahorsePgpBackendClass {
GObjectClass parent_class;
};
-static void seahorse_pgp_backend_iface_init (SeahorseBackendIface *iface);
+static void seahorse_pgp_backend_iface (SeahorseBackendIface *iface);
static void seahorse_pgp_backend_collection_init (GcrCollectionIface *iface);
G_DEFINE_TYPE_WITH_CODE (SeahorsePgpBackend, seahorse_pgp_backend, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (GCR_TYPE_COLLECTION, seahorse_pgp_backend_collection_init);
- G_IMPLEMENT_INTERFACE (SEAHORSE_TYPE_BACKEND, seahorse_pgp_backend_iface_init);
+ G_IMPLEMENT_INTERFACE (SEAHORSE_TYPE_BACKEND, seahorse_pgp_backend_iface);
);
static void
@@ -144,7 +144,7 @@ seahorse_pgp_backend_constructed (GObject *obj)
G_OBJECT_CLASS (seahorse_pgp_backend_parent_class)->constructed (obj);
self->keyring = seahorse_gpgme_keyring_new ();
- seahorse_gpgme_keyring_load_async (self->keyring, NULL, NULL, NULL);
+ seahorse_place_load_async (SEAHORSE_PLACE (self->keyring), NULL, NULL, NULL);
self->discovery = seahorse_discovery_new ();
self->unknown = seahorse_unknown_source_new ();
@@ -249,10 +249,20 @@ seahorse_pgp_backend_collection_init (GcrCollectionIface *iface)
iface->get_objects = seahorse_pgp_backend_get_objects;
}
-static void
-seahorse_pgp_backend_iface_init (SeahorseBackendIface *iface)
+static SeahorsePlace *
+seahorse_pgp_backend_lookup_place (SeahorseBackend *backend,
+ const gchar *uri)
{
+ SeahorsePgpBackend *self = SEAHORSE_PGP_BACKEND (backend);
+ if (g_str_equal (uri, "gnupg://"))
+ return SEAHORSE_PLACE (seahorse_pgp_backend_get_default_keyring (self));
+ return NULL;
+}
+static void
+seahorse_pgp_backend_iface (SeahorseBackendIface *iface)
+{
+ iface->lookup_place = seahorse_pgp_backend_lookup_place;
}
SeahorsePgpBackend *
@@ -270,7 +280,7 @@ seahorse_pgp_backend_initialize (void)
g_return_if_fail (pgp_backend == NULL);
self = g_object_new (SEAHORSE_TYPE_PGP_BACKEND, NULL);
- seahorse_registry_register_object (NULL, G_OBJECT (self), "backend", "openpgp", NULL);
+ seahorse_backend_register (SEAHORSE_BACKEND (self));
g_object_unref (self);
g_return_if_fail (pgp_backend != NULL);
diff --git a/pkcs11/seahorse-pkcs11-backend.c b/pkcs11/seahorse-pkcs11-backend.c
index 787d6ea..749b58e 100644
--- a/pkcs11/seahorse-pkcs11-backend.c
+++ b/pkcs11/seahorse-pkcs11-backend.c
@@ -27,7 +27,6 @@
#include "seahorse-backend.h"
#include "seahorse-place.h"
-#include "seahorse-registry.h"
#include "seahorse-util.h"
#include <gcr/gcr-base.h>
@@ -48,7 +47,7 @@ static SeahorsePkcs11Backend *pkcs11_backend = NULL;
struct _SeahorsePkcs11Backend {
GObject parent;
- GList *slots;
+ GList *tokens;
GList *blacklist;
};
@@ -63,13 +62,13 @@ static const char *token_blacklist[] = {
NULL
};
-static void seahorse_pkcs11_backend_iface_init (SeahorseBackendIface *iface);
+static void seahorse_pkcs11_backend_iface (SeahorseBackendIface *iface);
static void seahorse_pkcs11_backend_collection_init (GcrCollectionIface *iface);
G_DEFINE_TYPE_WITH_CODE (SeahorsePkcs11Backend, seahorse_pkcs11_backend, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (GCR_TYPE_COLLECTION, seahorse_pkcs11_backend_collection_init)
- G_IMPLEMENT_INTERFACE (SEAHORSE_TYPE_BACKEND, seahorse_pkcs11_backend_iface_init);
+ G_IMPLEMENT_INTERFACE (SEAHORSE_TYPE_BACKEND, seahorse_pkcs11_backend_iface);
);
static void
@@ -145,7 +144,7 @@ on_initialized_registered (GObject *unused,
continue;
if (is_token_usable (self, s->data, token)) {
place = SEAHORSE_PLACE (seahorse_token_new (s->data));
- self->slots = g_list_append (self->slots, place);
+ self->tokens = g_list_append (self->tokens, place);
gcr_collection_emit_added (GCR_COLLECTION (self), G_OBJECT (place));
}
gck_token_info_free (token);
@@ -200,8 +199,8 @@ seahorse_pkcs11_backend_dispose (GObject *obj)
{
SeahorsePkcs11Backend *self = SEAHORSE_PKCS11_BACKEND (obj);
- g_list_free_full (self->slots, g_object_unref);
- self->slots = NULL;
+ g_list_free_full (self->tokens, g_object_unref);
+ self->tokens = NULL;
G_OBJECT_CLASS (seahorse_pkcs11_backend_parent_class)->dispose (obj);
}
@@ -212,7 +211,7 @@ seahorse_pkcs11_backend_finalize (GObject *obj)
SeahorsePkcs11Backend *self = SEAHORSE_PKCS11_BACKEND (obj);
g_list_free_full (self->blacklist, (GDestroyNotify)gck_uri_data_free);
- g_assert (self->slots == NULL);
+ g_assert (self->tokens == NULL);
g_return_if_fail (pkcs11_backend == self);
pkcs11_backend = NULL;
@@ -239,14 +238,14 @@ static guint
seahorse_pkcs11_backend_get_length (GcrCollection *collection)
{
SeahorsePkcs11Backend *self = SEAHORSE_PKCS11_BACKEND (collection);
- return g_list_length (self->slots);
+ return g_list_length (self->tokens);
}
static GList *
seahorse_pkcs11_backend_get_objects (GcrCollection *collection)
{
SeahorsePkcs11Backend *self = SEAHORSE_PKCS11_BACKEND (collection);
- return g_list_copy (self->slots);
+ return g_list_copy (self->tokens);
}
static gboolean
@@ -254,7 +253,7 @@ seahorse_pkcs11_backend_contains (GcrCollection *collection,
GObject *object)
{
SeahorsePkcs11Backend *self = SEAHORSE_PKCS11_BACKEND (collection);
- return g_list_find (self->slots, object) != NULL;
+ return g_list_find (self->tokens, object) != NULL;
}
static void
@@ -265,11 +264,34 @@ seahorse_pkcs11_backend_collection_init (GcrCollectionIface *iface)
iface->get_objects = seahorse_pkcs11_backend_get_objects;
}
+static SeahorsePlace *
+seahorse_pkcs11_backend_lookup_place (SeahorseBackend *backend,
+ const gchar *uri)
+{
+ SeahorsePkcs11Backend *self = SEAHORSE_PKCS11_BACKEND (backend);
+ GckUriData *uri_data;
+ GList *l;
+
+ if (!g_str_has_prefix (uri, "pkcs11:"))
+ return NULL;
+
+ uri_data = gck_uri_parse (uri, GCK_URI_FOR_TOKEN | GCK_URI_FOR_MODULE, NULL);
+ if (uri_data == NULL)
+ return NULL;
+
+ for (l = self->tokens; l != NULL; l = g_list_next (l)) {
+ if (gck_slot_match (seahorse_token_get_slot (l->data), uri_data))
+ break;
+ }
+
+ gck_uri_data_free (uri_data);
+ return l != NULL ? l->data : NULL;
+}
static void
-seahorse_pkcs11_backend_iface_init (SeahorseBackendIface *iface)
+seahorse_pkcs11_backend_iface (SeahorseBackendIface *iface)
{
-
+ iface->lookup_place = seahorse_pkcs11_backend_lookup_place;
}
void
@@ -280,7 +302,7 @@ seahorse_pkcs11_backend_initialize (void)
g_return_if_fail (pkcs11_backend == NULL);
self = g_object_new (SEAHORSE_TYPE_PKCS11_BACKEND, NULL);
- seahorse_registry_register_object (NULL, G_OBJECT (self), "backend", "pkcs11", NULL);
+ seahorse_backend_register (SEAHORSE_BACKEND (self));
g_object_unref (self);
g_return_if_fail (pkcs11_backend != NULL);
diff --git a/pkcs11/seahorse-pkcs11-backend.h b/pkcs11/seahorse-pkcs11-backend.h
index e367be1..a2de024 100644
--- a/pkcs11/seahorse-pkcs11-backend.h
+++ b/pkcs11/seahorse-pkcs11-backend.h
@@ -23,6 +23,7 @@
#define SEAHORSE_PKCS11_BACKEND_H_
#include "seahorse-pkcs11.h"
+#include "seahorse-token.h"
#include <gcr/gcr.h>
diff --git a/pkcs11/seahorse-pkcs11-generate.c b/pkcs11/seahorse-pkcs11-generate.c
index 9e422e2..cc8c15a 100644
--- a/pkcs11/seahorse-pkcs11-generate.c
+++ b/pkcs11/seahorse-pkcs11-generate.c
@@ -115,7 +115,7 @@ complete_generate (SeahorsePkcs11Generate *self,
if (*error != NULL)
seahorse_util_handle_error (error, NULL, _("Couldn't generate private key"));
else
- seahorse_token_refresh_async (self->token, self->cancellable, NULL, NULL);
+ seahorse_place_load_async (SEAHORSE_PLACE (self->token), self->cancellable, NULL, NULL);
g_clear_object (&self->cancellable);
gck_attributes_unref (self->pub_attrs);
diff --git a/pkcs11/seahorse-token.c b/pkcs11/seahorse-token.c
index 3041638..0faf04c 100644
--- a/pkcs11/seahorse-token.c
+++ b/pkcs11/seahorse-token.c
@@ -465,24 +465,23 @@ calculate_session_options (SeahorseToken *self)
return GCK_SESSION_READ_WRITE;
}
-void
-seahorse_token_refresh_async (SeahorseToken *self,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+static void
+seahorse_token_load_async (SeahorsePlace *place,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
+ SeahorseToken *self = SEAHORSE_TOKEN (place);
GSimpleAsyncResult *res;
RefreshClosure *closure;
GckSessionOptions options;
GList *objects, *l;
gulong handle;
- g_return_if_fail (SEAHORSE_IS_TOKEN (self));
-
update_token_info (self);
res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
- seahorse_token_refresh_async);
+ seahorse_token_load_async);
closure = g_new0 (RefreshClosure, 1);
closure->checks = g_hash_table_new_full (seahorse_pkcs11_ulong_hash,
seahorse_pkcs11_ulong_equal,
@@ -512,13 +511,13 @@ seahorse_token_refresh_async (SeahorseToken *self,
g_object_unref (res);
}
-gboolean
-seahorse_token_refresh_finish (SeahorseToken *token,
- GAsyncResult *result,
- GError **error)
+static gboolean
+seahorse_token_load_finish (SeahorsePlace *place,
+ GAsyncResult *result,
+ GError **error)
{
- g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (token),
- seahorse_token_refresh_async), FALSE);
+ g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (place),
+ seahorse_token_load_async), FALSE);
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
return FALSE;
@@ -552,7 +551,7 @@ seahorse_token_constructed (GObject *obj)
g_return_if_fail (self->pv->slot != NULL);
- seahorse_token_refresh_async (self, NULL, NULL, NULL);
+ seahorse_place_load_async (SEAHORSE_PLACE (self), NULL, NULL, NULL);
data = gck_uri_data_new ();
data->token_info = seahorse_token_get_info (self);
@@ -726,7 +725,8 @@ seahorse_token_class_init (SeahorseTokenClass *klass)
static void
seahorse_token_place_iface (SeahorsePlaceIface *iface)
{
-
+ iface->load_async = seahorse_token_load_async;
+ iface->load_finish = seahorse_token_load_finish;
}
static guint
@@ -789,7 +789,7 @@ on_session_logout (GObject *source,
gck_session_logout_finish (GCK_SESSION (source), result, &error);
if (error == NULL)
- seahorse_token_refresh_async (self, NULL, NULL, NULL);
+ seahorse_place_load_async (SEAHORSE_PLACE (self), NULL, NULL, NULL);
else
g_simple_async_result_take_error (res, error);
@@ -809,7 +809,7 @@ on_login_interactive (GObject *source,
gck_session_logout_finish (GCK_SESSION (source), result, &error);
if (error == NULL)
- seahorse_token_refresh_async (self, NULL, NULL, NULL);
+ seahorse_token_load_async (SEAHORSE_PLACE (self), NULL, NULL, NULL);
else
g_simple_async_result_take_error (res, error);
@@ -831,7 +831,7 @@ on_session_login_open (GObject *source,
session = gck_session_open_finish (result, &error);
if (error == NULL) {
seahorse_token_set_session (self, session);
- seahorse_token_refresh_async (self, NULL, NULL, NULL);
+ seahorse_place_load_async (SEAHORSE_PLACE (self), NULL, NULL, NULL);
g_object_unref (session);
} else {
g_simple_async_result_take_error (res, error);
diff --git a/pkcs11/seahorse-token.h b/pkcs11/seahorse-token.h
index bf3a64c..2a02c84 100644
--- a/pkcs11/seahorse-token.h
+++ b/pkcs11/seahorse-token.h
@@ -73,13 +73,4 @@ void seahorse_token_remove_object (SeahorseToken *self,
gboolean seahorse_token_is_deletable (SeahorseToken *self,
GckObject *object);
-void seahorse_token_refresh_async (SeahorseToken *self,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-
-gboolean seahorse_token_refresh_finish (SeahorseToken *self,
- GAsyncResult *result,
- GError **error);
-
#endif /* __SEAHORSE_TOKEN_H__ */
diff --git a/src/seahorse-import-dialog.c b/src/seahorse-import-dialog.c
index 3c310a7..c6843b2 100644
--- a/src/seahorse-import-dialog.c
+++ b/src/seahorse-import-dialog.c
@@ -23,6 +23,9 @@
#include "config.h"
+#include "seahorse-backend.h"
+#include "seahorse-place.h"
+
#include "seahorse-import-dialog.h"
#include <gcr/gcr.h>
@@ -73,9 +76,22 @@ on_import_button_imported (GcrImportButton *button,
gpointer user_data)
{
SeahorseImportDialog *self = SEAHORSE_IMPORT_DIALOG (user_data);
+ SeahorsePlace *place;
+ GList *backends, *l;
+ gchar *uri;
if (error == NULL) {
gtk_dialog_response (GTK_DIALOG (self), GTK_RESPONSE_OK);
+ g_object_get (importer, "uri", &uri, NULL);
+
+ backends = seahorse_backend_get_registered ();
+ for (l = backends; l != NULL; l = g_list_next (l)) {
+ place = seahorse_backend_lookup_place (l->data, uri);
+ if (place != NULL)
+ seahorse_place_load_async (place, NULL, NULL, NULL);
+ }
+ g_list_free (backends);
+ g_free (uri);
} else {
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
diff --git a/src/seahorse-sidebar.c b/src/seahorse-sidebar.c
index 481da2f..a3253fc 100644
--- a/src/seahorse-sidebar.c
+++ b/src/seahorse-sidebar.c
@@ -30,7 +30,6 @@
#include "seahorse-interaction.h"
#include "seahorse-lockable.h"
#include "seahorse-place.h"
-#include "seahorse-registry.h"
#include "seahorse-util.h"
#include "seahorse-viewable.h"
@@ -769,7 +768,7 @@ load_backends (SeahorseSidebar *self)
GList *backends, *l;
GList *places, *p;
- backends = seahorse_registry_object_instances (NULL, "backend", NULL);
+ backends = seahorse_backend_get_registered ();
for (l = backends; l != NULL; l = g_list_next (l)) {
g_ptr_array_add (self->backends, l->data);
g_signal_connect (l->data, "added", G_CALLBACK (on_place_added), self);
diff --git a/ssh/seahorse-ssh-backend.c b/ssh/seahorse-ssh-backend.c
index 2733bc6..72e0ed0 100644
--- a/ssh/seahorse-ssh-backend.c
+++ b/ssh/seahorse-ssh-backend.c
@@ -26,7 +26,6 @@
#include "seahorse-ssh-source.h"
#include "seahorse-backend.h"
-#include "seahorse-registry.h"
#include <glib/gi18n.h>
@@ -49,13 +48,13 @@ struct _SeahorseSshBackendClass {
GObjectClass parent_class;
};
-static void seahorse_ssh_backend_iface_init (SeahorseBackendIface *iface);
+static void seahorse_ssh_backend_iface (SeahorseBackendIface *iface);
static void seahorse_ssh_backend_collection_init (GcrCollectionIface *iface);
G_DEFINE_TYPE_WITH_CODE (SeahorseSshBackend, seahorse_ssh_backend, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (GCR_TYPE_COLLECTION, seahorse_ssh_backend_collection_init);
- G_IMPLEMENT_INTERFACE (SEAHORSE_TYPE_BACKEND, seahorse_ssh_backend_iface_init);
+ G_IMPLEMENT_INTERFACE (SEAHORSE_TYPE_BACKEND, seahorse_ssh_backend_iface);
);
static void
@@ -75,7 +74,7 @@ seahorse_ssh_backend_constructed (GObject *obj)
G_OBJECT_CLASS (seahorse_ssh_backend_parent_class)->constructed (obj);
self->dot_ssh = seahorse_ssh_source_new ();
- seahorse_ssh_source_load_async (self->dot_ssh, NULL, NULL, NULL);
+ seahorse_place_load_async (SEAHORSE_PLACE (self->dot_ssh), NULL, NULL, NULL);
}
static void
@@ -158,10 +157,29 @@ seahorse_ssh_backend_collection_init (GcrCollectionIface *iface)
iface->get_objects = seahorse_ssh_backend_get_objects;
}
-static void
-seahorse_ssh_backend_iface_init (SeahorseBackendIface *iface)
+static SeahorsePlace *
+seahorse_ssh_backend_lookup_place (SeahorseBackend *backend,
+ const gchar *uri)
{
+ SeahorseSshBackend *self = SEAHORSE_SSH_BACKEND (backend);
+ gchar *our_uri = NULL;
+ gboolean match;
+
+ if (self->dot_ssh) {
+ g_object_get (self->dot_ssh, "uri", &our_uri, NULL);
+ match = (our_uri && g_str_equal (our_uri, uri));
+ g_free (our_uri);
+ if (match)
+ return SEAHORSE_PLACE (self->dot_ssh);
+ }
+
+ return NULL;
+}
+static void
+seahorse_ssh_backend_iface (SeahorseBackendIface *iface)
+{
+ iface->lookup_place = seahorse_ssh_backend_lookup_place;
}
void
@@ -172,7 +190,7 @@ seahorse_ssh_backend_initialize (void)
g_return_if_fail (ssh_backend == NULL);
self = g_object_new (SEAHORSE_TYPE_SSH_BACKEND, NULL);
- seahorse_registry_register_object (NULL, G_OBJECT (self), "backend", "openssh", NULL);
+ seahorse_backend_register (SEAHORSE_BACKEND (self));
g_object_unref (self);
g_return_if_fail (ssh_backend != NULL);
diff --git a/ssh/seahorse-ssh-source.c b/ssh/seahorse-ssh-source.c
index a30e84e..6dc7221 100644
--- a/ssh/seahorse-ssh-source.c
+++ b/ssh/seahorse-ssh-source.c
@@ -149,7 +149,7 @@ scheduled_refresh (SeahorseSSHSource *ssrc)
{
seahorse_debug ("scheduled refresh event ocurring now");
cancel_scheduled_refresh (ssrc);
- seahorse_ssh_source_load_async (ssrc, NULL, NULL, NULL);
+ seahorse_place_load_async (SEAHORSE_PLACE (ssrc), NULL, NULL, NULL);
return FALSE; /* don't run again */
}
@@ -573,12 +573,13 @@ seahorse_ssh_source_load_one_sync (SeahorseSSHSource *self,
return key;
}
-void
-seahorse_ssh_source_load_async (SeahorseSSHSource *self,
+static void
+seahorse_ssh_source_load_async (SeahorsePlace *place,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
+ SeahorseSSHSource *self = SEAHORSE_SSH_SOURCE (place);
GSimpleAsyncResult *res;
source_load_closure *closure;
GError *error = NULL;
@@ -667,12 +668,12 @@ seahorse_ssh_source_load_async (SeahorseSSHSource *self,
g_object_unref (res);
}
-gboolean
-seahorse_ssh_source_load_finish (SeahorseSSHSource *self,
+static gboolean
+seahorse_ssh_source_load_finish (SeahorsePlace *place,
GAsyncResult *result,
GError **error)
{
- g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
+ g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (place),
seahorse_ssh_source_load_async), FALSE);
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
@@ -829,6 +830,8 @@ seahorse_ssh_source_place_iface (SeahorsePlaceIface *iface)
{
iface->import_async = seahorse_ssh_source_import_async;
iface->import_finish = seahorse_ssh_source_import_finish;
+ iface->load_async = seahorse_ssh_source_load_async;
+ iface->load_finish = seahorse_ssh_source_load_finish;
}
/* -----------------------------------------------------------------------------
diff --git a/ssh/seahorse-ssh-source.h b/ssh/seahorse-ssh-source.h
index 7a85d8c..c9612d9 100644
--- a/ssh/seahorse-ssh-source.h
+++ b/ssh/seahorse-ssh-source.h
@@ -84,13 +84,4 @@ guchar* seahorse_ssh_source_export_private (SeahorseSSHSource *
gsize *n_results,
GError **err);
-void seahorse_ssh_source_load_async (SeahorseSSHSource *self,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-
-gboolean seahorse_ssh_source_load_finish (SeahorseSSHSource *self,
- GAsyncResult *result,
- GError **error);
-
#endif /* __SEAHORSE_SSH_SOURCE_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]