2 * empathy-account.c - Source for EmpathyAccount
3 * Copyright (C) 2009 Collabora Ltd.
4 * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <telepathy-glib/enums.h>
26 #include <telepathy-glib/dbus.h>
27 #include <telepathy-glib/account.h>
28 #include <telepathy-glib/gtypes.h>
29 #include <telepathy-glib/util.h>
30 #include <telepathy-glib/interfaces.h>
32 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
33 #include <libempathy/empathy-debug.h>
35 #include <glib/gi18n-lib.h>
37 #include "empathy-account.h"
38 #include "empathy-utils.h"
39 #include "empathy-marshal.h"
41 #define UNIQUE_NAME_PREFIX "/org/freedesktop/Telepathy/Account/"
51 static guint signals[LAST_SIGNAL];
60 PROP_CONNECTION_STATUS,
61 PROP_CONNECTION_STATUS_REASON,
68 G_DEFINE_TYPE(EmpathyAccount, empathy_account, G_TYPE_OBJECT)
70 /* private structure */
71 typedef struct _EmpathyAccountPriv EmpathyAccountPriv;
73 struct _EmpathyAccountPriv
75 gboolean dispose_has_run;
77 TpConnection *connection;
78 guint connection_invalidated_id;
80 TpConnectionStatus connection_status;
81 TpConnectionStatusReason reason;
83 TpConnectionPresenceType presence;
91 /* Timestamp when the connection got connected in seconds since the epoch */
103 GHashTable *parameters;
106 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccount)
108 static void _empathy_account_set_connection (EmpathyAccount *account,
109 TpConnection *connection);
112 empathy_account_init (EmpathyAccount *obj)
114 EmpathyAccountPriv *priv;
116 priv = G_TYPE_INSTANCE_GET_PRIVATE (obj,
117 EMPATHY_TYPE_ACCOUNT, EmpathyAccountPriv);
121 priv->connection_status = TP_CONNECTION_STATUS_DISCONNECTED;
125 empathy_account_set_property (GObject *object,
130 EmpathyAccount *account = EMPATHY_ACCOUNT (object);
131 EmpathyAccountPriv *priv = GET_PRIV (account);
136 empathy_account_set_enabled (account, g_value_get_boolean (value));
138 case PROP_UNIQUE_NAME:
139 priv->unique_name = g_value_dup_string (value);
141 case PROP_DBUS_DAEMON:
142 priv->dbus = g_value_get_object (value);
145 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
151 empathy_account_get_property (GObject *object,
156 EmpathyAccount *account = EMPATHY_ACCOUNT (object);
157 EmpathyAccountPriv *priv = GET_PRIV (account);
162 g_value_set_boolean (value, priv->enabled);
165 g_value_set_boolean (value, priv->ready);
168 g_value_set_uint (value, priv->presence);
171 g_value_set_string (value, priv->status);
173 case PROP_STATUS_MESSAGE:
174 g_value_set_string (value, priv->message);
176 case PROP_CONNECTION_STATUS:
177 g_value_set_uint (value, priv->connection_status);
179 case PROP_CONNECTION_STATUS_REASON:
180 g_value_set_uint (value, priv->reason);
182 case PROP_CONNECTION:
183 g_value_set_object (value,
184 empathy_account_get_connection (account));
186 case PROP_UNIQUE_NAME:
187 g_value_set_string (value,
188 empathy_account_get_unique_name (account));
190 case PROP_DISPLAY_NAME:
191 g_value_set_string (value,
192 empathy_account_get_display_name (account));
194 case PROP_DBUS_DAEMON:
195 g_value_set_string (value,
196 empathy_account_get_display_name (account));
199 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
205 empathy_account_update (EmpathyAccount *account, GHashTable *properties)
207 EmpathyAccountPriv *priv = GET_PRIV (account);
208 const gchar *conn_path;
210 TpConnectionStatus old_s = priv->connection_status;
211 gboolean presence_changed = FALSE;
213 if (g_hash_table_lookup (properties, "ConnectionStatus") != NULL)
214 priv->connection_status =
215 tp_asv_get_int32 (properties, "ConnectionStatus", NULL);
217 if (g_hash_table_lookup (properties, "ConnectionStatusReason") != NULL)
218 priv->reason = tp_asv_get_int32 (properties,
219 "ConnectionStatusReason", NULL);
221 if (g_hash_table_lookup (properties, "CurrentPresence") != NULL)
223 presence_changed = TRUE;
224 arr = tp_asv_get_boxed (properties, "CurrentPresence",
225 TP_STRUCT_TYPE_SIMPLE_PRESENCE);
226 priv->presence = g_value_get_uint (g_value_array_get_nth (arr, 0));
228 g_free (priv->status);
229 priv->status = g_value_dup_string (g_value_array_get_nth (arr, 1));
231 g_free (priv->message);
232 priv->message = g_value_dup_string (g_value_array_get_nth (arr, 2));
235 if (g_hash_table_lookup (properties, "DisplayName") != NULL)
237 g_strdup (tp_asv_get_string (properties, "DisplayName"));
239 if (g_hash_table_lookup (properties, "Enabled") != NULL)
241 gboolean enabled = tp_asv_get_boolean (properties, "Enabled", NULL);
242 if (priv->enabled != enabled)
244 priv->enabled = enabled;
245 g_object_notify (G_OBJECT (account), "enabled");
249 if (g_hash_table_lookup (properties, "Valid") != NULL)
250 priv->valid = tp_asv_get_boolean (properties, "Valid", NULL);
252 if (g_hash_table_lookup (properties, "Parameters") != NULL)
254 GHashTable *parameters;
256 parameters = tp_asv_get_boxed (properties, "Parameters",
257 TP_HASH_TYPE_STRING_VARIANT_MAP);
259 priv->parameters = g_boxed_copy (TP_HASH_TYPE_STRING_VARIANT_MAP,
266 g_object_notify (G_OBJECT (account), "ready");
269 if (priv->connection_status != old_s)
271 if (priv->connection_status == TP_CONNECTION_STATUS_CONNECTED)
274 g_get_current_time (&val);
276 priv->connect_time = val.tv_sec;
279 g_signal_emit (account, signals[STATUS_CHANGED], 0,
280 old_s, priv->connection_status, priv->reason);
282 g_object_notify (G_OBJECT (account), "status");
285 if (presence_changed)
287 g_signal_emit (account, signals[PRESENCE_CHANGED], 0,
288 priv->presence, priv->status, priv->message);
289 g_object_notify (G_OBJECT (account), "presence");
290 g_object_notify (G_OBJECT (account), "status");
291 g_object_notify (G_OBJECT (account), "status-message");
294 if (g_hash_table_lookup (properties, "Connection") != NULL)
296 conn_path = tp_asv_get_object_path (properties, "Connection");
298 if (tp_strdiff (conn_path, "/") && priv->connection == NULL)
301 GError *error = NULL;
302 conn = tp_connection_new (priv->dbus, NULL, conn_path, &error);
306 DEBUG ("Failed to create a new TpConnection: %s",
308 g_error_free (error);
311 _empathy_account_set_connection (account, conn);
317 empathy_account_properties_changed (TpAccount *proxy,
318 GHashTable *properties,
320 GObject *weak_object)
322 EmpathyAccount *account = EMPATHY_ACCOUNT (weak_object);
323 EmpathyAccountPriv *priv = GET_PRIV (account);
328 empathy_account_update (account, properties);
332 empathy_account_removed_cb (TpAccount *proxy,
334 GObject *weak_object)
336 EmpathyAccount *account = EMPATHY_ACCOUNT (weak_object);
337 EmpathyAccountPriv *priv = GET_PRIV (account);
342 priv->removed = TRUE;
344 g_signal_emit (account, signals[REMOVED], 0);
348 empathy_account_got_all_cb (TpProxy *proxy,
349 GHashTable *properties,
352 GObject *weak_object)
354 EmpathyAccount *account = EMPATHY_ACCOUNT (weak_object);
356 DEBUG ("Got initial set of properties for %s",
357 empathy_account_get_unique_name (account));
361 printf ("Unhappy\n");
365 empathy_account_update (account, properties);
369 empathy_account_unescape_protocol (const gchar *protocol, gssize len)
371 gchar *result, *escape;
372 /* Bad implementation might accidentally use tp_escape_as_identifier,
373 * which escapes - in the wrong way... */
374 if ((escape = g_strstr_len (protocol, len, "_2d")) != NULL)
379 str = g_string_new ("");
382 g_string_append_len (str, input, escape - input);
383 g_string_append_c (str, '-');
385 len -= escape - input + 3;
387 } while ((escape = g_strstr_len (input, len, "_2d")) != NULL);
389 g_string_append_len (str, input, len);
391 result = g_string_free (str, FALSE);
395 result = g_strndup (protocol, len);
398 g_strdelimit (result, "_", '-');
404 empathy_account_parse_unique_name (const gchar *bus_name,
405 gchar **protocol, gchar **manager)
407 const gchar *proto, *proto_end;
408 const gchar *cm, *cm_end;
410 g_return_val_if_fail (
411 g_str_has_prefix (bus_name, UNIQUE_NAME_PREFIX), FALSE);
413 cm = bus_name + strlen (UNIQUE_NAME_PREFIX);
415 for (cm_end = cm; *cm_end != '/' && *cm_end != '\0'; cm_end++)
426 for (proto_end = proto; *proto_end != '/' && *proto_end != '\0'; proto_end++)
429 if (*proto_end == '\0')
432 if (protocol != NULL)
434 *protocol = empathy_account_unescape_protocol (proto, proto_end - proto);
438 *manager = g_strndup (cm, cm_end - cm);
444 account_invalidated_cb (TpProxy *proxy, guint domain, gint code,
445 gchar *message, gpointer user_data)
447 EmpathyAccount *account = EMPATHY_ACCOUNT (user_data);
448 EmpathyAccountPriv *priv = GET_PRIV (account);
453 priv->removed = TRUE;
455 g_signal_emit (account, signals[REMOVED], 0);
459 empathy_account_constructed (GObject *object)
461 EmpathyAccount *account = EMPATHY_ACCOUNT (object);
462 EmpathyAccountPriv *priv = GET_PRIV (account);
464 priv->account = tp_account_new (priv->dbus, priv->unique_name, NULL);
466 g_signal_connect (priv->account, "invalidated",
467 G_CALLBACK (account_invalidated_cb), object);
469 empathy_account_parse_unique_name (priv->unique_name,
470 &(priv->proto_name), &(priv->cm_name));
472 priv->icon_name = g_strdup_printf ("im-%s", priv->proto_name);
474 tp_cli_account_connect_to_account_property_changed (priv->account,
475 empathy_account_properties_changed,
476 NULL, NULL, object, NULL);
478 tp_cli_account_connect_to_removed (priv->account,
479 empathy_account_removed_cb,
480 NULL, NULL, object, NULL);
482 tp_cli_dbus_properties_call_get_all (priv->account, -1,
484 empathy_account_got_all_cb,
490 static void empathy_account_dispose (GObject *object);
491 static void empathy_account_finalize (GObject *object);
494 empathy_account_class_init (EmpathyAccountClass *empathy_account_class)
496 GObjectClass *object_class = G_OBJECT_CLASS (empathy_account_class);
498 g_type_class_add_private (empathy_account_class,
499 sizeof (EmpathyAccountPriv));
501 object_class->set_property = empathy_account_set_property;
502 object_class->get_property = empathy_account_get_property;
503 object_class->dispose = empathy_account_dispose;
504 object_class->finalize = empathy_account_finalize;
505 object_class->constructed = empathy_account_constructed;
507 g_object_class_install_property (object_class, PROP_ENABLED,
508 g_param_spec_boolean ("enabled",
510 "Whether this account is enabled or not",
512 G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE));
514 g_object_class_install_property (object_class, PROP_READY,
515 g_param_spec_boolean ("ready",
517 "Whether this account is ready to be used",
519 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
521 g_object_class_install_property (object_class, PROP_PRESENCE,
522 g_param_spec_uint ("presence",
524 "The account connections presence type",
526 NUM_TP_CONNECTION_PRESENCE_TYPES,
527 TP_CONNECTION_PRESENCE_TYPE_UNSET,
528 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
530 g_object_class_install_property (object_class, PROP_STATUS,
531 g_param_spec_string ("status",
533 "The Status string of the account",
535 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
537 g_object_class_install_property (object_class, PROP_STATUS_MESSAGE,
538 g_param_spec_string ("status-message",
540 "The Status message string of the account",
542 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
544 g_object_class_install_property (object_class, PROP_CONNECTION_STATUS,
545 g_param_spec_uint ("connection-status",
547 "The accounts connections status type",
549 NUM_TP_CONNECTION_STATUSES,
550 TP_CONNECTION_STATUS_DISCONNECTED,
551 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
553 g_object_class_install_property (object_class, PROP_CONNECTION_STATUS_REASON,
554 g_param_spec_uint ("status-reason",
555 "ConnectionStatusReason",
556 "The account connections status reason",
558 NUM_TP_CONNECTION_STATUS_REASONS,
559 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
560 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
562 g_object_class_install_property (object_class, PROP_CONNECTION,
563 g_param_spec_object ("connection",
565 "The accounts connection",
567 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
569 g_object_class_install_property (object_class, PROP_UNIQUE_NAME,
570 g_param_spec_string ("unique-name",
572 "The accounts unique name",
574 G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
576 g_object_class_install_property (object_class, PROP_DBUS_DAEMON,
577 g_param_spec_object ("dbus-daemon",
579 "The Tp Dbus daemon on which this account exists",
581 G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
583 g_object_class_install_property (object_class, PROP_DISPLAY_NAME,
584 g_param_spec_string ("display-name",
586 "The accounts display name",
588 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
590 signals[STATUS_CHANGED] = g_signal_new ("status-changed",
591 G_TYPE_FROM_CLASS (object_class),
594 _empathy_marshal_VOID__UINT_UINT_UINT,
595 G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT);
597 signals[PRESENCE_CHANGED] = g_signal_new ("presence-changed",
598 G_TYPE_FROM_CLASS (object_class),
601 _empathy_marshal_VOID__UINT_STRING_STRING,
602 G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING);
604 signals[REMOVED] = g_signal_new ("removed",
605 G_TYPE_FROM_CLASS (object_class),
608 g_cclosure_marshal_VOID__VOID,
613 empathy_account_dispose (GObject *object)
615 EmpathyAccount *self = EMPATHY_ACCOUNT (object);
616 EmpathyAccountPriv *priv = GET_PRIV (self);
618 if (priv->dispose_has_run)
621 priv->dispose_has_run = TRUE;
623 if (priv->connection_invalidated_id != 0)
624 g_signal_handler_disconnect (priv->connection,
625 priv->connection_invalidated_id);
626 priv->connection_invalidated_id = 0;
628 if (priv->connection != NULL)
629 g_object_unref (priv->connection);
630 priv->connection = NULL;
632 /* release any references held by the object here */
633 if (G_OBJECT_CLASS (empathy_account_parent_class)->dispose != NULL)
634 G_OBJECT_CLASS (empathy_account_parent_class)->dispose (object);
638 empathy_account_finalize (GObject *object)
640 EmpathyAccountPriv *priv = GET_PRIV (object);
642 g_free (priv->status);
643 g_free (priv->message);
645 g_free (priv->cm_name);
646 g_free (priv->proto_name);
647 g_free (priv->icon_name);
648 g_free (priv->display_name);
650 /* free any data held directly by the object here */
651 if (G_OBJECT_CLASS (empathy_account_parent_class)->finalize != NULL)
652 G_OBJECT_CLASS (empathy_account_parent_class)->finalize (object);
656 empathy_account_is_just_connected (EmpathyAccount *account)
658 EmpathyAccountPriv *priv = GET_PRIV (account);
661 if (priv->connection_status != TP_CONNECTION_STATUS_CONNECTED)
664 g_get_current_time (&val);
666 return (val.tv_sec - priv->connect_time) < 10;
670 * empathy_account_get_connection:
671 * @account: a #EmpathyAccount
673 * Get the connection of the account, or NULL if account is offline or the
674 * connection is not yet ready. This function does not return a new ref.
676 * Returns: the connection of the account.
679 empathy_account_get_connection (EmpathyAccount *account)
681 EmpathyAccountPriv *priv = GET_PRIV (account);
683 if (priv->connection != NULL &&
684 tp_connection_is_ready (priv->connection))
685 return priv->connection;
691 * empathy_account_get_unique_name:
692 * @account: a #EmpathyAccount
694 * Returns: the unique name of the account.
697 empathy_account_get_unique_name (EmpathyAccount *account)
699 EmpathyAccountPriv *priv = GET_PRIV (account);
701 return priv->unique_name;
705 * empathy_account_get_display_name:
706 * @account: a #EmpathyAccount
708 * Returns: the display name of the account.
711 empathy_account_get_display_name (EmpathyAccount *account)
713 EmpathyAccountPriv *priv = GET_PRIV (account);
715 return priv->display_name;
719 empathy_account_is_valid (EmpathyAccount *account)
721 EmpathyAccountPriv *priv = GET_PRIV (account);
727 empathy_account_get_connection_manager (EmpathyAccount *account)
729 EmpathyAccountPriv *priv = GET_PRIV (account);
731 return priv->cm_name;
735 empathy_account_get_protocol (EmpathyAccount *account)
737 EmpathyAccountPriv *priv = GET_PRIV (account);
739 return priv->proto_name;
743 empathy_account_get_icon_name (EmpathyAccount *account)
745 EmpathyAccountPriv *priv = GET_PRIV (account);
747 return priv->icon_name;
751 empathy_account_get_parameters (EmpathyAccount *account)
753 EmpathyAccountPriv *priv = GET_PRIV (account);
755 return priv->parameters;
759 empathy_account_is_enabled (EmpathyAccount *account)
761 EmpathyAccountPriv *priv = GET_PRIV (account);
763 return priv->enabled;
767 empathy_account_is_ready (EmpathyAccount *account)
769 EmpathyAccountPriv *priv = GET_PRIV (account);
776 empathy_account_new (TpDBusDaemon *dbus, const gchar *unique_name)
778 return EMPATHY_ACCOUNT (g_object_new (EMPATHY_TYPE_ACCOUNT,
780 "unique-name", unique_name,
785 empathy_account_connection_ready_cb (TpConnection *connection,
789 EmpathyAccount *account = EMPATHY_ACCOUNT (user_data);
790 EmpathyAccountPriv *priv = GET_PRIV (account);
794 DEBUG ("(%s) Connection failed to become ready: %s",
795 empathy_account_get_unique_name (account), error->message);
796 priv->connection = NULL;
800 DEBUG ("(%s) Connection ready",
801 empathy_account_get_unique_name (account));
802 g_object_notify (G_OBJECT (account), "connection");
807 _empathy_account_connection_invalidated_cb (TpProxy *self,
813 EmpathyAccount *account = EMPATHY_ACCOUNT (user_data);
814 EmpathyAccountPriv *priv = GET_PRIV (account);
816 if (priv->connection == NULL)
819 DEBUG ("(%s) Connection invalidated",
820 empathy_account_get_unique_name (account));
822 g_assert (priv->connection == TP_CONNECTION (self));
824 g_signal_handler_disconnect (priv->connection,
825 priv->connection_invalidated_id);
826 priv->connection_invalidated_id = 0;
828 g_object_unref (priv->connection);
829 priv->connection = NULL;
831 g_object_notify (G_OBJECT (account), "connection");
835 _empathy_account_set_connection (EmpathyAccount *account,
836 TpConnection *connection)
838 EmpathyAccountPriv *priv = GET_PRIV (account);
840 if (priv->connection == connection)
843 /* Connection already set, don't set the new one */
844 if (connection != NULL && priv->connection != NULL)
847 if (connection == NULL)
849 g_signal_handler_disconnect (priv->connection,
850 priv->connection_invalidated_id);
851 priv->connection_invalidated_id = 0;
853 g_object_unref (priv->connection);
854 priv->connection = NULL;
855 g_object_notify (G_OBJECT (account), "connection");
859 priv->connection = g_object_ref (connection);
860 priv->connection_invalidated_id = g_signal_connect (priv->connection,
862 G_CALLBACK (_empathy_account_connection_invalidated_cb),
865 DEBUG ("Readying connection for %s", priv->unique_name);
866 /* notify a change in the connection property when it's ready */
867 tp_connection_call_when_ready (priv->connection,
868 empathy_account_connection_ready_cb, account);
873 empathy_account_set_enabled (EmpathyAccount *account,
876 EmpathyAccountPriv *priv = GET_PRIV (account);
877 GValue value = {0, };
879 if (priv->enabled == enabled)
882 g_value_init (&value, G_TYPE_BOOLEAN);
883 g_value_set_boolean (&value, enabled);
885 tp_cli_dbus_properties_call_set (TP_PROXY (priv->account),
895 g_value_unset (&value);
899 empathy_account_requested_presence_cb (TpProxy *proxy,
902 GObject *weak_object)
905 DEBUG (":( : %s", error->message);
910 empathy_account_request_presence (EmpathyAccount *account,
911 TpConnectionPresenceType type,
913 const gchar *message)
915 EmpathyAccountPriv *priv = GET_PRIV (account);
916 GValue value = {0, };
919 g_value_init (&value, TP_STRUCT_TYPE_SIMPLE_PRESENCE);
920 g_value_take_boxed (&value, dbus_g_type_specialized_construct
921 (TP_STRUCT_TYPE_SIMPLE_PRESENCE));
922 arr = (GValueArray *) g_value_get_boxed (&value);
924 g_value_set_uint (arr->values, type);
925 g_value_set_static_string (arr->values + 1, status);
926 g_value_set_static_string (arr->values + 2, message);
928 tp_cli_dbus_properties_call_set (TP_PROXY (priv->account),
933 empathy_account_requested_presence_cb,
938 g_value_unset (&value);
942 empathy_account_updated_cb (TpAccount *proxy,
943 const gchar **reconnect_required,
946 GObject *weak_object)
948 GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data);
952 g_simple_async_result_set_from_error (result, (GError *) error);
955 g_simple_async_result_complete (result);
956 g_object_unref (G_OBJECT (result));
960 empathy_account_update_settings_async (EmpathyAccount *account,
961 GHashTable *parameters, const gchar **unset_parameters,
962 GAsyncReadyCallback callback, gpointer user_data)
964 EmpathyAccountPriv *priv = GET_PRIV (account);
965 GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (account),
966 callback, user_data, empathy_account_update_settings_finish);
968 tp_cli_account_call_update_parameters (priv->account,
972 empathy_account_updated_cb,
979 empathy_account_update_settings_finish (EmpathyAccount *account,
980 GAsyncResult *result, GError **error)
982 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
986 g_return_val_if_fail (g_simple_async_result_is_valid (result,
987 G_OBJECT (account), empathy_account_update_settings_finish), FALSE);
993 account_display_name_set_cb (TpProxy *proxy,
996 GObject *weak_object)
998 GSimpleAsyncResult *result = user_data;
1001 g_simple_async_result_set_from_error (result, (GError *) error);
1003 g_simple_async_result_complete (result);
1004 g_object_unref (result);
1008 empathy_account_set_display_name_async (EmpathyAccount *account,
1009 const char *display_name,
1010 GAsyncReadyCallback callback,
1013 GSimpleAsyncResult *result;
1014 GValue value = {0, };
1015 EmpathyAccountPriv *priv = GET_PRIV (account);
1017 if (display_name == NULL)
1019 g_simple_async_report_error_in_idle (G_OBJECT (account),
1020 callback, user_data, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
1021 _("Can't set an empty display name"));
1025 result = g_simple_async_result_new (G_OBJECT (account), callback,
1026 user_data, empathy_account_set_display_name_finish);
1028 g_value_init (&value, G_TYPE_STRING);
1029 g_value_set_string (&value, display_name);
1031 tp_cli_dbus_properties_call_set (priv->account, -1, TP_IFACE_ACCOUNT,
1032 "DisplayName", &value, account_display_name_set_cb, result, NULL,
1033 G_OBJECT (account));
1037 empathy_account_set_display_name_finish (EmpathyAccount *account,
1038 GAsyncResult *result, GError **error)
1040 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
1042 !g_simple_async_result_is_valid (result, G_OBJECT (account),
1043 empathy_account_set_display_name_finish))
1050 empathy_account_remove_cb (TpAccount *proxy,
1051 const GError *error,
1053 GObject *weak_object)
1055 GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data);
1059 g_simple_async_result_set_from_error (result, (GError *) error);
1062 g_simple_async_result_complete (result);
1063 g_object_unref (G_OBJECT (result));
1067 empathy_account_remove_async (EmpathyAccount *account,
1068 GAsyncReadyCallback callback, gpointer user_data)
1070 EmpathyAccountPriv *priv = GET_PRIV (account);
1071 GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (account),
1072 callback, user_data, empathy_account_remove_finish);
1074 tp_cli_account_call_remove (priv->account,
1076 empathy_account_remove_cb,
1079 G_OBJECT (account));
1083 empathy_account_remove_finish (EmpathyAccount *account,
1084 GAsyncResult *result, GError **error)
1086 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
1090 g_return_val_if_fail (g_simple_async_result_is_valid (result,
1091 G_OBJECT (account), empathy_account_update_settings_finish), FALSE);