From: Guillaume Desmottes Date: Wed, 11 Nov 2009 13:26:33 +0000 (+0000) Subject: add empathy_tp_chat_provide_password_{async,finish} X-Git-Url: https://git.0d.be/?p=empathy.git;a=commitdiff_plain;h=fe838cf55249bf53c3f42098feb55edd5318bf34 add empathy_tp_chat_provide_password_{async,finish} --- diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c index aea12546..92faa65f 100644 --- a/libempathy/empathy-tp-chat.c +++ b/libempathy/empathy-tp-chat.c @@ -1521,3 +1521,57 @@ empathy_tp_chat_password_needed (EmpathyTpChat *self) return priv->password_flags & TP_CHANNEL_PASSWORD_FLAG_PROVIDE; } + +static void +provide_password_cb (TpChannel *channel, + gboolean correct, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + GSimpleAsyncResult *result = user_data; + + if (error != NULL) { + g_simple_async_result_set_from_error (result, error); + } + else if (!correct) { + /* The current D-Bus API is a bit weird so re-use the + * AuthenticationFailed error */ + g_simple_async_result_set_error (result, TP_ERRORS, + TP_ERROR_AUTHENTICATION_FAILED, "Wrong password"); + } + + g_simple_async_result_complete (result); + g_object_unref (result); +} + +void +empathy_tp_chat_provide_password_async (EmpathyTpChat *self, + const gchar *password, + GAsyncReadyCallback callback, + gpointer user_data) +{ + EmpathyTpChatPriv *priv = GET_PRIV (self); + GSimpleAsyncResult *result; + + result = g_simple_async_result_new (G_OBJECT (self), + callback, user_data, empathy_tp_chat_provide_password_finish); + + tp_cli_channel_interface_password_call_provide_password (priv->channel, -1, + password, provide_password_cb, result, NULL, G_OBJECT (self)); +} + +gboolean +empathy_tp_chat_provide_password_finish (EmpathyTpChat *self, + GAsyncResult *result, + GError **error) +{ + if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), + error)) + return FALSE; + + g_return_val_if_fail (g_simple_async_result_is_valid (result, + G_OBJECT (self), empathy_tp_chat_provide_password_finish), FALSE); + + return TRUE; +} diff --git a/libempathy/empathy-tp-chat.h b/libempathy/empathy-tp-chat.h index 4dec0cd2..013a926b 100644 --- a/libempathy/empathy-tp-chat.h +++ b/libempathy/empathy-tp-chat.h @@ -88,6 +88,15 @@ void empathy_tp_chat_acknowledge_messages (EmpathyTpChat *chat, gboolean empathy_tp_chat_password_needed (EmpathyTpChat *chat); +void empathy_tp_chat_provide_password_async (EmpathyTpChat *chat, + const gchar *password, + GAsyncReadyCallback callback, + gpointer user_data); + +gboolean empathy_tp_chat_provide_password_finish (EmpathyTpChat *chat, + GAsyncResult *result, + GError **error); + G_END_DECLS #endif /* __EMPATHY_TP_CHAT_H__ */