[seahorse] pgp: Move the import_async/import_finish virtual methods into pgp code
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [seahorse] pgp: Move the import_async/import_finish virtual methods into pgp code
- Date: Tue, 13 Dec 2011 19:12:29 +0000 (UTC)
commit 581b91c05bdfd8ae6090c5f3bfe67756e6ab62c1
Author: Stef Walter <stefw collabora co uk>
Date: Tue Dec 13 20:11:43 2011 +0100
pgp: Move the import_async/import_finish virtual methods into pgp code
* Only used from pgp code, specifically seahorse-transfer.c so
move these there instead of in SeahorsePlace
libseahorse/seahorse-place.c | 39 ++++++---------------------------------
libseahorse/seahorse-place.h | 24 ++----------------------
pgp/seahorse-gpgme-keyring.c | 15 ++++++---------
pgp/seahorse-gpgme-keyring.h | 10 ++++++++++
pgp/seahorse-hkp-source.c | 15 ++++++++-------
pgp/seahorse-ldap-source.c | 14 +++++++-------
pgp/seahorse-server-source.c | 27 +++++++++++++++++++++++++++
pgp/seahorse-server-source.h | 20 ++++++++++++++++++++
pgp/seahorse-transfer.c | 26 +++++++++++++++++++++++---
ssh/seahorse-ssh-source.c | 15 ++++++---------
ssh/seahorse-ssh-source.h | 10 ++++++++++
11 files changed, 125 insertions(+), 90 deletions(-)
---
diff --git a/libseahorse/seahorse-place.c b/libseahorse/seahorse-place.c
index 437149f..a50a536 100644
--- a/libseahorse/seahorse-place.c
+++ b/libseahorse/seahorse-place.c
@@ -81,21 +81,21 @@ seahorse_place_default_init (SeahorsePlaceIface *iface)
void
seahorse_place_load_async (SeahorsePlace *place,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+ 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);
+ callback, user_data);
}
gboolean
seahorse_place_load_finish (SeahorsePlace *place,
- GAsyncResult *result,
- GError **error)
+ 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);
@@ -103,30 +103,3 @@ seahorse_place_load_finish (SeahorsePlace *place,
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,
- GInputStream *input,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- g_return_if_fail (SEAHORSE_IS_PLACE (place));
- g_return_if_fail (G_IS_INPUT_STREAM (input));
- g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
- g_return_if_fail (SEAHORSE_PLACE_GET_INTERFACE (place)->import_async);
- SEAHORSE_PLACE_GET_INTERFACE (place)->import_async (place, input, cancellable,
- callback, user_data);
-}
-
-GList *
-seahorse_place_import_finish (SeahorsePlace *place,
- GAsyncResult *result,
- GError **error)
-{
- g_return_val_if_fail (SEAHORSE_IS_PLACE (place), NULL);
- g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
- g_return_val_if_fail (SEAHORSE_PLACE_GET_INTERFACE (place)->import_finish, NULL);
- return SEAHORSE_PLACE_GET_INTERFACE (place)->import_finish (place, result, error);
-}
diff --git a/libseahorse/seahorse-place.h b/libseahorse/seahorse-place.h
index 06e04a0..b915a81 100644
--- a/libseahorse/seahorse-place.h
+++ b/libseahorse/seahorse-place.h
@@ -49,16 +49,6 @@ struct _SeahorsePlaceIface {
/* virtual methods ------------------------------------------------- */
- void (* import_async) (SeahorsePlace *place,
- GInputStream *input,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-
- GList * (* import_finish) (SeahorsePlace *place,
- GAsyncResult *result,
- GError **error);
-
void (* load_async) (SeahorsePlace *place,
GCancellable *cancellable,
GAsyncReadyCallback callback,
@@ -73,22 +63,12 @@ GType seahorse_place_get_type (void) G_GNUC_CONST;
GtkActionGroup * seahorse_place_get_actions (SeahorsePlace *self);
-void seahorse_place_import_async (SeahorsePlace *place,
- GInputStream *input,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-
-GList * seahorse_place_import_finish (SeahorsePlace *place,
- GAsyncResult *result,
- GError **error);
-
-void seahorse_place_load_async (SeahorsePlace *place,
+void seahorse_place_load_async (SeahorsePlace *place,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
-gboolean seahorse_place_load_finish (SeahorsePlace *place,
+gboolean seahorse_place_load_finish (SeahorsePlace *place,
GAsyncResult *result,
GError **error);
diff --git a/pgp/seahorse-gpgme-keyring.c b/pgp/seahorse-gpgme-keyring.c
index a6487ac..0543a2d 100644
--- a/pgp/seahorse-gpgme-keyring.c
+++ b/pgp/seahorse-gpgme-keyring.c
@@ -667,21 +667,20 @@ on_keyring_import_complete (gpgme_error_t gerr,
return FALSE; /* don't call again */
}
-static void
-seahorse_gpgme_keyring_import_async (SeahorsePlace *place,
+void
+seahorse_gpgme_keyring_import_async (SeahorseGpgmeKeyring *self,
GInputStream *input,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
- SeahorseGpgmeKeyring *self = SEAHORSE_GPGME_KEYRING (place);
GSimpleAsyncResult *res;
keyring_import_closure *closure;
gpgme_error_t gerr = 0;
GError *error = NULL;
GSource *gsource = NULL;
- res = g_simple_async_result_new (G_OBJECT (place), callback, user_data,
+ res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
seahorse_gpgme_keyring_import_async);
closure = g_new0 (keyring_import_closure, 1);
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
@@ -710,15 +709,15 @@ seahorse_gpgme_keyring_import_async (SeahorsePlace *place,
g_object_unref (res);
}
-static GList *
-seahorse_gpgme_keyring_import_finish (SeahorsePlace *place,
+GList *
+seahorse_gpgme_keyring_import_finish (SeahorseGpgmeKeyring *self,
GAsyncResult *result,
GError **error)
{
keyring_import_closure *closure;
GList *results;
- g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (place),
+ g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
seahorse_gpgme_keyring_import_async), NULL);
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
@@ -899,8 +898,6 @@ seahorse_gpgme_keyring_class_init (SeahorseGpgmeKeyringClass *klass)
static void
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;
}
diff --git a/pgp/seahorse-gpgme-keyring.h b/pgp/seahorse-gpgme-keyring.h
index f5d092e..260cc40 100644
--- a/pgp/seahorse-gpgme-keyring.h
+++ b/pgp/seahorse-gpgme-keyring.h
@@ -78,4 +78,14 @@ SeahorseGpgmeKey * seahorse_gpgme_keyring_lookup (SeahorseGpgmeKeyri
void seahorse_gpgme_keyring_remove_key (SeahorseGpgmeKeyring *self,
SeahorseGpgmeKey *key);
+void seahorse_gpgme_keyring_import_async (SeahorseGpgmeKeyring *self,
+ GInputStream *input,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+GList * seahorse_gpgme_keyring_import_finish (SeahorseGpgmeKeyring *self,
+ GAsyncResult *result,
+ GError **error);
+
#endif /* __SEAHORSE_GPGME_KEYRING_H__ */
diff --git a/pgp/seahorse-hkp-source.c b/pgp/seahorse-hkp-source.c
index d821c1a..afd6cbd 100644
--- a/pgp/seahorse-hkp-source.c
+++ b/pgp/seahorse-hkp-source.c
@@ -818,13 +818,13 @@ on_import_message_complete (SoupSession *session,
* Imports a list of keys from the input stream to the keyserver
**/
static void
-seahorse_hkp_source_import_async (SeahorsePlace *place,
+seahorse_hkp_source_import_async (SeahorseServerSource *source,
GInputStream *input,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
- SeahorseHKPSource *self = SEAHORSE_HKP_SOURCE (place);
+ SeahorseHKPSource *self = SEAHORSE_HKP_SOURCE (source);
GSimpleAsyncResult *res;
source_import_closure *closure;
SoupMessage *message;
@@ -836,7 +836,7 @@ seahorse_hkp_source_import_async (SeahorsePlace *place,
GList *l;
guint len;
- res = g_simple_async_result_new (G_OBJECT (place), callback, user_data,
+ res = g_simple_async_result_new (G_OBJECT (source), callback, user_data,
seahorse_hkp_source_import_async);
closure = g_new0 (source_import_closure, 1);
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
@@ -908,11 +908,11 @@ seahorse_hkp_source_import_async (SeahorsePlace *place,
}
static GList *
-seahorse_hkp_source_import_finish (SeahorsePlace *place,
+seahorse_hkp_source_import_finish (SeahorseServerSource *source,
GAsyncResult *result,
GError **error)
{
- g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (place),
+ g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (source),
seahorse_hkp_source_import_async), NULL);
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
@@ -1105,8 +1105,7 @@ seahorse_hkp_source_export_finish (SeahorseServerSource *source,
static void
seahorse_place_iface (SeahorsePlaceIface *iface)
{
- iface->import_async = seahorse_hkp_source_import_async;
- iface->import_finish = seahorse_hkp_source_import_finish;
+
}
/**
@@ -1124,6 +1123,8 @@ seahorse_hkp_source_class_init (SeahorseHKPSourceClass *klass)
server_class->search_finish = seahorse_hkp_source_search_finish;
server_class->export_async = seahorse_hkp_source_export_async;
server_class->export_finish = seahorse_hkp_source_export_finish;
+ server_class->import_async = seahorse_hkp_source_import_async;
+ server_class->import_finish = seahorse_hkp_source_import_finish;
seahorse_servers_register_type ("hkp", _("HTTP Key Server"), seahorse_hkp_is_valid_uri);
}
diff --git a/pgp/seahorse-ldap-source.c b/pgp/seahorse-ldap-source.c
index 5d2e8a7..676eee1 100644
--- a/pgp/seahorse-ldap-source.c
+++ b/pgp/seahorse-ldap-source.c
@@ -1145,19 +1145,19 @@ on_import_connect_completed (GObject *source,
}
static void
-seahorse_ldap_source_import_async (SeahorsePlace *place,
+seahorse_ldap_source_import_async (SeahorseServerSource *source,
GInputStream *input,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
- SeahorseLDAPSource *self = SEAHORSE_LDAP_SOURCE (place);
+ SeahorseLDAPSource *self = SEAHORSE_LDAP_SOURCE (source);
source_import_closure *closure;
GSimpleAsyncResult *res;
gchar *keydata;
guint len;
- res = g_simple_async_result_new (G_OBJECT (place), callback, user_data,
+ res = g_simple_async_result_new (G_OBJECT (source), callback, user_data,
seahorse_ldap_source_import_async);
closure = g_new0 (source_import_closure, 1);
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
@@ -1187,11 +1187,11 @@ seahorse_ldap_source_import_async (SeahorsePlace *place,
}
static GList *
-seahorse_ldap_source_import_finish (SeahorsePlace *place,
+seahorse_ldap_source_import_finish (SeahorseServerSource *source,
GAsyncResult *result,
GError **error)
{
- g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (place),
+ g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (source),
seahorse_ldap_source_import_async), NULL);
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
@@ -1428,8 +1428,6 @@ seahorse_ldap_source_export_finish (SeahorseServerSource *source,
static void
seahorse_place_iface (SeahorsePlaceIface *iface)
{
- iface->import_async = seahorse_ldap_source_import_async;
- iface->import_finish = seahorse_ldap_source_import_finish;
}
/* Initialize the basic class stuff */
@@ -1442,6 +1440,8 @@ seahorse_ldap_source_class_init (SeahorseLDAPSourceClass *klass)
server_class->search_finish = seahorse_ldap_source_search_finish;
server_class->export_async = seahorse_ldap_source_export_async;
server_class->export_finish = seahorse_ldap_source_export_finish;
+ server_class->import_async = seahorse_ldap_source_import_async;
+ server_class->import_finish = seahorse_ldap_source_import_finish;
seahorse_servers_register_type ("ldap", _("LDAP Key Server"), seahorse_ldap_is_valid_uri);
}
diff --git a/pgp/seahorse-server-source.c b/pgp/seahorse-server-source.c
index 2a7a5d0..6f1039f 100644
--- a/pgp/seahorse-server-source.c
+++ b/pgp/seahorse-server-source.c
@@ -431,3 +431,30 @@ seahorse_server_source_export_finish (SeahorseServerSource *self,
g_return_val_if_fail (klass->export_finish != NULL, NULL);
return (klass->export_finish) (self, result, size, error);
}
+
+void
+seahorse_server_source_import_async (SeahorseServerSource *source,
+ GInputStream *input,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_return_if_fail (SEAHORSE_IS_SERVER_SOURCE (source));
+ g_return_if_fail (G_IS_INPUT_STREAM (input));
+ g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
+ g_return_if_fail (SEAHORSE_SERVER_SOURCE_GET_CLASS (source)->import_async);
+ SEAHORSE_SERVER_SOURCE_GET_CLASS (source)->import_async (source, input, cancellable,
+ callback, user_data);
+}
+
+GList *
+seahorse_server_source_import_finish (SeahorseServerSource *source,
+ GAsyncResult *result,
+ GError **error)
+{
+ g_return_val_if_fail (SEAHORSE_IS_SERVER_SOURCE (source), NULL);
+ g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+ g_return_val_if_fail (SEAHORSE_SERVER_SOURCE_GET_CLASS (source)->import_finish, NULL);
+ return SEAHORSE_SERVER_SOURCE_GET_CLASS (source)->import_finish (source, result, error);
+}
diff --git a/pgp/seahorse-server-source.h b/pgp/seahorse-server-source.h
index c9ceafe..fb85257 100644
--- a/pgp/seahorse-server-source.h
+++ b/pgp/seahorse-server-source.h
@@ -64,6 +64,16 @@ struct _SeahorseServerSource {
struct _SeahorseServerSourceClass {
GObjectClass parent_class;
+ void (* import_async) (SeahorseServerSource *source,
+ GInputStream *input,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+ GList * (* import_finish) (SeahorseServerSource *source,
+ GAsyncResult *result,
+ GError **error);
+
void (*export_async) (SeahorseServerSource *source,
const gchar **keyids,
GCancellable *cancellable,
@@ -102,6 +112,16 @@ gboolean seahorse_server_source_search_finish (SeahorseServerSo
GAsyncResult *result,
GError **error);
+void seahorse_server_source_import_async (SeahorseServerSource *self,
+ GInputStream *input,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+GList * seahorse_server_source_import_finish (SeahorseServerSource *self,
+ GAsyncResult *result,
+ GError **error);
+
void seahorse_server_source_export_async (SeahorseServerSource *self,
const gchar **keyids,
GCancellable *cancellable,
diff --git a/pgp/seahorse-transfer.c b/pgp/seahorse-transfer.c
index b2cce2e..c824a39 100644
--- a/pgp/seahorse-transfer.c
+++ b/pgp/seahorse-transfer.c
@@ -66,13 +66,24 @@ on_source_import_ready (GObject *object,
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
TransferClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
GError *error = NULL;
+ GList *results;
seahorse_debug ("[transfer] import done");
seahorse_progress_end (closure->cancellable, &closure->to);
- if (seahorse_place_import_finish (closure->to, result, &error))
+ if (SEAHORSE_IS_GPGME_KEYRING (closure->to)) {
+ results = seahorse_gpgme_keyring_import_finish (SEAHORSE_GPGME_KEYRING (closure->to),
+ result, &error);
+ } else {
+ results = seahorse_server_source_import_finish (SEAHORSE_SERVER_SOURCE (closure->to),
+ result, &error);
+ }
+
+ if (results != NULL)
g_cancellable_set_error_if_cancelled (closure->cancellable, &error);
+ g_list_free (results);
+
if (error != NULL)
g_simple_async_result_take_error (res, error);
@@ -124,8 +135,17 @@ on_source_export_ready (GObject *object,
stream_size = 0;
seahorse_debug ("[transfer] starting import");
- seahorse_place_import_async (closure->to, input, closure->cancellable,
- on_source_import_ready, g_object_ref (res));
+ if (SEAHORSE_IS_GPGME_KEYRING (closure->to)) {
+ seahorse_gpgme_keyring_import_async (SEAHORSE_GPGME_KEYRING (closure->to),
+ input, closure->cancellable,
+ on_source_import_ready,
+ g_object_ref (res));
+ } else {
+ seahorse_server_source_import_async (SEAHORSE_SERVER_SOURCE (closure->to),
+ input, closure->cancellable,
+ on_source_import_ready,
+ g_object_ref (res));
+ }
g_object_unref (input);
}
diff --git a/ssh/seahorse-ssh-source.c b/ssh/seahorse-ssh-source.c
index 6dc7221..e28559b 100644
--- a/ssh/seahorse-ssh-source.c
+++ b/ssh/seahorse-ssh-source.c
@@ -779,20 +779,19 @@ on_import_found_private_key (SeahorseSSHSecData *data,
return TRUE;
}
-static void
-seahorse_ssh_source_import_async (SeahorsePlace *place,
+void
+seahorse_ssh_source_import_async (SeahorseSSHSource *self,
GInputStream *input,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
- SeahorseSSHSource *self = SEAHORSE_SSH_SOURCE (place);
source_import_closure *closure;
gchar *contents;
GSimpleAsyncResult *res;
guint count;
- res = g_simple_async_result_new (G_OBJECT (place), callback, user_data,
+ res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
seahorse_ssh_source_import_async);
closure = g_new0 (source_import_closure, 1);
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
@@ -810,12 +809,12 @@ seahorse_ssh_source_import_async (SeahorsePlace *place,
g_object_unref (res);
}
-static GList *
-seahorse_ssh_source_import_finish (SeahorsePlace *place,
+GList *
+seahorse_ssh_source_import_finish (SeahorseSSHSource *self,
GAsyncResult *result,
GError **error)
{
- g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (place),
+ g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
seahorse_ssh_source_import_async), NULL);
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
@@ -828,8 +827,6 @@ seahorse_ssh_source_import_finish (SeahorsePlace *place,
static void
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 c9612d9..39db4c9 100644
--- a/ssh/seahorse-ssh-source.h
+++ b/ssh/seahorse-ssh-source.h
@@ -84,4 +84,14 @@ guchar* seahorse_ssh_source_export_private (SeahorseSSHSource *
gsize *n_results,
GError **err);
+void seahorse_ssh_source_import_async (SeahorseSSHSource *self,
+ GInputStream *input,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+GList * seahorse_ssh_source_import_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]