diff options
-rw-r--r-- | libempathy-gtk/empathy-protocol-chooser.c | 11 | ||||
-rw-r--r-- | libempathy/empathy-connection-managers.c | 78 | ||||
-rw-r--r-- | libempathy/empathy-connection-managers.h | 11 | ||||
-rw-r--r-- | src/empathy-import-widget.c | 11 | ||||
-rw-r--r-- | src/empathy.c | 12 |
5 files changed, 57 insertions, 66 deletions
diff --git a/libempathy-gtk/empathy-protocol-chooser.c b/libempathy-gtk/empathy-protocol-chooser.c index 0dc60d4eb..86f6af57b 100644 --- a/libempathy-gtk/empathy-protocol-chooser.c +++ b/libempathy-gtk/empathy-protocol-chooser.c @@ -253,13 +253,14 @@ protocol_chooser_add_cms_list (EmpathyProtocolChooser *protocol_chooser, } static void -protocol_chooser_cms_ready_cb (EmpathyConnectionManagers *cms, - const GError *error, +protocol_chooser_cms_prepare_cb (GObject *source, + GAsyncResult *result, gpointer user_data) { + EmpathyConnectionManagers *cms = EMPATHY_CONNECTION_MANAGERS (source); EmpathyProtocolChooser *protocol_chooser = user_data; - if (error != NULL) + if (!empathy_connection_managers_prepare_finish (cms, result, NULL)) return; protocol_chooser_add_cms_list (protocol_chooser, @@ -309,8 +310,8 @@ protocol_chooser_constructed (GObject *object) "text", COL_LABEL, NULL); - empathy_connection_managers_call_when_ready (priv->cms, - protocol_chooser_cms_ready_cb, protocol_chooser); + empathy_connection_managers_prepare_async (priv->cms, + protocol_chooser_cms_prepare_cb, protocol_chooser); if (G_OBJECT_CLASS (empathy_protocol_chooser_parent_class)->constructed) G_OBJECT_CLASS diff --git a/libempathy/empathy-connection-managers.c b/libempathy/empathy-connection-managers.c index 7085b507b..9cda1a331 100644 --- a/libempathy/empathy-connection-managers.c +++ b/libempathy/empathy-connection-managers.c @@ -292,65 +292,51 @@ empathy_connection_managers_get_cms_num (EmpathyConnectionManagers *self) return g_list_length (priv->cms); } -typedef struct -{ - EmpathyConnectionManagers *self; - EmpathyConnectionManagersWhenReadyCb callback; - gpointer user_data; - guint ready_id; -} CallWhenReadyContext; - static void -call_when_ready_ctx_free (CallWhenReadyContext *ctx) -{ - g_signal_handler_disconnect (ctx->self, ctx->ready_id); - g_object_unref (ctx->self); - g_slice_free (CallWhenReadyContext, ctx); -} - -static void -cwr_ready (EmpathyConnectionManagers *self, +notify_ready_cb (EmpathyConnectionManagers *self, GParamSpec *spec, - CallWhenReadyContext *ctx) + GSimpleAsyncResult *result) { - g_assert (ctx->callback != NULL); - - ctx->callback (self, NULL, ctx->user_data); - - call_when_ready_ctx_free (ctx); + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); } -static CallWhenReadyContext * -call_when_ready_ctx_new (EmpathyConnectionManagers *self, - EmpathyConnectionManagersWhenReadyCb callback, +void +empathy_connection_managers_prepare_async ( + EmpathyConnectionManagers *self, + GAsyncReadyCallback callback, gpointer user_data) { - CallWhenReadyContext *ctx = g_slice_new (CallWhenReadyContext); + EmpathyConnectionManagersPriv *priv = GET_PRIV (self); + GSimpleAsyncResult *result; - ctx->self = g_object_ref (self); - ctx->callback = callback; - ctx->user_data = user_data; + result = g_simple_async_result_new (G_OBJECT (managers), + callback, user_data, empathy_connection_managers_prepare_finish); - ctx->ready_id = g_signal_connect (self, "notify::ready", - G_CALLBACK (cwr_ready), ctx); + if (priv->ready) + { + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); + return; + } - return ctx; + g_signal_connect (self, "notify::ready", G_CALLBACK (notify_ready_cb), + result); } -void -empathy_connection_managers_call_when_ready ( +gboolean +empathy_connection_managers_prepare_finish ( EmpathyConnectionManagers *self, - EmpathyConnectionManagersWhenReadyCb callback, - gpointer user_data) + GAsyncResult *result, + GError **error) { - EmpathyConnectionManagersPriv *priv = GET_PRIV (self); + GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result); - if (priv->ready) - { - callback (self, NULL, user_data); - } - else - { - call_when_ready_ctx_new (self, callback, user_data); - } + g_return_val_if_fail (g_simple_async_result_is_valid (result, + G_OBJECT (self), empathy_connection_managers_prepare_finish), FALSE); + + if (g_simple_async_result_propagate_error (simple, error)) + return FALSE; + + return TRUE; } diff --git a/libempathy/empathy-connection-managers.h b/libempathy/empathy-connection-managers.h index 956f24315..14833734c 100644 --- a/libempathy/empathy-connection-managers.h +++ b/libempathy/empathy-connection-managers.h @@ -22,6 +22,7 @@ #define __EMPATHY_CONNECTION_MANAGERS_H__ #include <glib-object.h> +#include <gio/gio.h> #include <telepathy-glib/connection-manager.h> @@ -72,15 +73,15 @@ guint empathy_connection_managers_get_cms_num TpConnectionManager *empathy_connection_managers_get_cm ( EmpathyConnectionManagers *managers, const gchar *cm); -typedef void (*EmpathyConnectionManagersWhenReadyCb) ( +void empathy_connection_managers_prepare_async ( EmpathyConnectionManagers *managers, - const GError *error, + GAsyncReadyCallback callback, gpointer user_data); -void empathy_connection_managers_call_when_ready ( +gboolean empathy_connection_managers_prepare_finish ( EmpathyConnectionManagers *managers, - EmpathyConnectionManagersWhenReadyCb callback, - gpointer user_data); + GAsyncResult *result, + GError **error); G_END_DECLS diff --git a/src/empathy-import-widget.c b/src/empathy-import-widget.c index 915db533e..a5bc0ef24 100644 --- a/src/empathy-import-widget.c +++ b/src/empathy-import-widget.c @@ -334,13 +334,14 @@ import_widget_set_up_account_list (EmpathyImportWidget *self) } static void -import_widget_cms_ready_cb (EmpathyConnectionManagers *cms, - const GError *error, +import_widget_cms_prepare_cb (GObject *source, + GAsyncResult *result, gpointer user_data) { EmpathyImportWidget *self = user_data; - if (error != NULL) + if (!empathy_connection_managers_prepare_finish ( + EMPATHY_CONNECTION_MANAGERS (source), result, NULL)) return; import_widget_set_up_account_list (self); @@ -442,8 +443,8 @@ do_constructed (GObject *obj) g_signal_connect (priv->vbox, "destroy", G_CALLBACK (import_widget_destroy_cb), self); - empathy_connection_managers_call_when_ready (priv->cms, - import_widget_cms_ready_cb, self); + empathy_connection_managers_prepare_async (priv->cms, + import_widget_cms_prepare_cb, self); } static void diff --git a/src/empathy.c b/src/empathy.c index 5647789c8..7bdea3be9 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -201,11 +201,13 @@ maybe_show_account_assistant (void) } static void -connection_managers_ready_cb (EmpathyConnectionManagers *managers, - const GError *error, +connection_managers_prepare_cb (GObject *source, + GAsyncResult *result, gpointer user_data) { - if (error != NULL) + EmpathyConnectionManagers *managers = EMPATHY_CONNECTION_MANAGERS (source); + + if (!empathy_connection_managers_prepare_finish (managers, result, NULL)) goto out; if (!empathy_import_mc4_accounts (managers) && !start_hidden) @@ -488,8 +490,8 @@ account_manager_ready_cb (GObject *source_object, EmpathyConnectionManagers *managers; managers = empathy_connection_managers_dup_singleton (); - empathy_connection_managers_call_when_ready (managers, - connection_managers_ready_cb, NULL); + empathy_connection_managers_prepare_async (managers, + connection_managers_prepare_cb, NULL); } else if (!start_hidden) { |