aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libempathy/empathy-account-settings.c46
-rw-r--r--libempathy/empathy-account.c59
-rw-r--r--libempathy/empathy-account.h7
3 files changed, 110 insertions, 2 deletions
diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c
index 2763f0702..989d2d355 100644
--- a/libempathy/empathy-account-settings.c
+++ b/libempathy/empathy-account-settings.c
@@ -799,6 +799,26 @@ empathy_account_settings_set_boolean (EmpathyAccountSettings *settings,
tp_asv_set_boolean (priv->parameters, param, value);
}
+static void
+account_settings_display_name_set_cb (GObject *src,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GError *error = NULL;
+ EmpathyAccount *account = EMPATHY_ACCOUNT (src);
+ GSimpleAsyncResult *set_result = user_data;
+
+ empathy_account_set_display_name_finish (account, res, &error);
+
+ if (error != NULL)
+ {
+ g_simple_async_result_set_from_error (set_result, error);
+ g_error_free (error);
+ }
+
+ g_simple_async_result_complete (set_result);
+ g_object_unref (set_result);
+}
void
empathy_account_settings_set_display_name_async (
@@ -807,6 +827,26 @@ empathy_account_settings_set_display_name_async (
GAsyncReadyCallback callback,
gpointer user_data)
{
+ EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
+ GSimpleAsyncResult *result;
+
+ result = g_simple_async_result_new (G_OBJECT (settings),
+ callback, user_data, empathy_account_settings_set_display_name_finish);
+
+ if (priv->account == NULL)
+ {
+ if (priv->display_name != NULL)
+ g_free (priv->display_name);
+
+ priv->display_name = g_strdup (name);
+
+ g_simple_async_result_complete_in_idle (result);
+
+ return;
+ }
+
+ empathy_account_set_display_name_async (priv->account, name,
+ account_settings_display_name_set_cb, result);
}
gboolean
@@ -815,6 +855,12 @@ empathy_account_settings_set_display_name_finish (
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 (settings), empathy_account_settings_set_display_name_finish), FALSE);
return TRUE;
}
diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c
index cc982aea7..bb55abed7 100644
--- a/libempathy/empathy-account.c
+++ b/libempathy/empathy-account.c
@@ -32,6 +32,8 @@
#define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
#include <libempathy/empathy-debug.h>
+#include <glib/gi18n-lib.h>
+
#include "empathy-account.h"
#include "empathy-utils.h"
#include "empathy-marshal.h"
@@ -988,6 +990,63 @@ empathy_account_update_settings_finish (EmpathyAccount *account,
}
static void
+account_display_name_set_cb (TpProxy *proxy,
+ const GError *error,
+ gpointer user_data,
+ GObject *weak_object)
+{
+ GSimpleAsyncResult *result = user_data;
+
+ if (error != NULL)
+ g_simple_async_result_set_from_error (result, (GError *) error);
+
+ g_simple_async_result_complete (result);
+ g_object_unref (result);
+}
+
+void
+empathy_account_set_display_name_async (EmpathyAccount *account,
+ const char *display_name,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+ GValue value = {0, };
+ EmpathyAccountPriv *priv = GET_PRIV (account);
+
+ if (display_name == NULL)
+ {
+ g_simple_async_report_error_in_idle (G_OBJECT (account),
+ callback, user_data, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
+ _("Can't set an empty display name"));
+ return;
+ }
+
+ result = g_simple_async_result_new (G_OBJECT (account), callback,
+ user_data, empathy_account_set_display_name_finish);
+
+ g_value_init (&value, G_TYPE_STRING);
+ g_value_set_string (&value, display_name);
+
+ tp_cli_dbus_properties_call_set (priv->account, -1, TP_IFACE_ACCOUNT,
+ "DisplayName", &value, account_display_name_set_cb, result, NULL,
+ G_OBJECT (account));
+}
+
+gboolean
+empathy_account_set_display_name_finish (EmpathyAccount *account,
+ GAsyncResult *result, GError **error)
+{
+ if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
+ error) ||
+ !g_simple_async_result_is_valid (result, G_OBJECT (account),
+ empathy_account_set_display_name_finish))
+ return FALSE;
+
+ return TRUE;
+}
+
+static void
empathy_account_remove_cb (TpAccount *proxy,
const GError *error,
gpointer user_data,
diff --git a/libempathy/empathy-account.h b/libempathy/empathy-account.h
index 00daa46ee..67939d748 100644
--- a/libempathy/empathy-account.h
+++ b/libempathy/empathy-account.h
@@ -84,8 +84,11 @@ void empathy_account_remove_async (EmpathyAccount *account,
gboolean empathy_account_remove_finish (EmpathyAccount *account,
GAsyncResult *result, GError **error);
-void empathy_account_set_display_name (EmpathyAccount *account,
- const gchar *display_name);
+void empathy_account_set_display_name_async (EmpathyAccount *account,
+ const gchar *display_name, GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean empathy_account_set_display_name_finish (EmpathyAccount *account,
+ GAsyncResult *result, GError **error);
EmpathyAccount *empathy_account_new (TpDBusDaemon *bus_daemon,
const gchar *unique_name);