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,
206 GHashTable *properties)
208 EmpathyAccountPriv *priv = GET_PRIV (account);
209 const gchar *conn_path;
211 TpConnectionStatus old_s = priv->connection_status;
212 gboolean presence_changed = FALSE;
214 if (g_hash_table_lookup (properties, "ConnectionStatus") != NULL)
215 priv->connection_status =
216 tp_asv_get_int32 (properties, "ConnectionStatus", NULL);
218 if (g_hash_table_lookup (properties, "ConnectionStatusReason") != NULL)
219 priv->reason = tp_asv_get_int32 (properties,
220 "ConnectionStatusReason", NULL);
222 if (g_hash_table_lookup (properties, "CurrentPresence") != NULL)
224 presence_changed = TRUE;
225 arr = tp_asv_get_boxed (properties, "CurrentPresence",
226 TP_STRUCT_TYPE_SIMPLE_PRESENCE);
227 priv->presence = g_value_get_uint (g_value_array_get_nth (arr, 0));
229 g_free (priv->status);
230 priv->status = g_value_dup_string (g_value_array_get_nth (arr, 1));
232 g_free (priv->message);
233 priv->message = g_value_dup_string (g_value_array_get_nth (arr, 2));
236 if (g_hash_table_lookup (properties, "DisplayName") != NULL)
238 g_strdup (tp_asv_get_string (properties, "DisplayName"));
240 if (g_hash_table_lookup (properties, "Enabled") != NULL)
242 gboolean enabled = tp_asv_get_boolean (properties, "Enabled", NULL);
243 if (priv->enabled != enabled)
245 priv->enabled = enabled;
246 g_object_notify (G_OBJECT (account), "enabled");
250 if (g_hash_table_lookup (properties, "Valid") != NULL)
251 priv->valid = tp_asv_get_boolean (properties, "Valid", NULL);
253 if (g_hash_table_lookup (properties, "Parameters") != NULL)
255 GHashTable *parameters;
257 parameters = tp_asv_get_boxed (properties, "Parameters",
258 TP_HASH_TYPE_STRING_VARIANT_MAP);
260 priv->parameters = g_boxed_copy (TP_HASH_TYPE_STRING_VARIANT_MAP,
267 g_object_notify (G_OBJECT (account), "ready");
270 if (priv->connection_status != old_s)
272 if (priv->connection_status == TP_CONNECTION_STATUS_CONNECTED)
275 g_get_current_time (&val);
277 priv->connect_time = val.tv_sec;
280 g_signal_emit (account, signals[STATUS_CHANGED], 0,
281 old_s, priv->connection_status, priv->reason);
283 g_object_notify (G_OBJECT (account), "status");
286 if (presence_changed)
288 g_signal_emit (account, signals[PRESENCE_CHANGED], 0,
289 priv->presence, priv->status, priv->message);
290 g_object_notify (G_OBJECT (account), "presence");
291 g_object_notify (G_OBJECT (account), "status");
292 g_object_notify (G_OBJECT (account), "status-message");
295 if (g_hash_table_lookup (properties, "Connection") != NULL)
297 conn_path = tp_asv_get_object_path (properties, "Connection");
299 if (tp_strdiff (conn_path, "/") && priv->connection == NULL)
302 GError *error = NULL;
303 conn = tp_connection_new (priv->dbus, NULL, conn_path, &error);
307 DEBUG ("Failed to create a new TpConnection: %s",
309 g_error_free (error);
312 _empathy_account_set_connection (account, conn);
318 empathy_account_properties_changed (TpAccount *proxy,
319 GHashTable *properties,
321 GObject *weak_object)
323 EmpathyAccount *account = EMPATHY_ACCOUNT (weak_object);
324 EmpathyAccountPriv *priv = GET_PRIV (account);
329 empathy_account_update (account, properties);
333 empathy_account_removed_cb (TpAccount *proxy,
335 GObject *weak_object)
337 EmpathyAccount *account = EMPATHY_ACCOUNT (weak_object);
338 EmpathyAccountPriv *priv = GET_PRIV (account);
343 priv->removed = TRUE;
345 g_signal_emit (account, signals[REMOVED], 0);
349 empathy_account_got_all_cb (TpProxy *proxy,
350 GHashTable *properties,
353 GObject *weak_object)
355 EmpathyAccount *account = EMPATHY_ACCOUNT (weak_object);
357 DEBUG ("Got initial set of properties for %s",
358 empathy_account_get_unique_name (account));
362 DEBUG ("Failed to get the initial set of account properties: %s",
367 empathy_account_update (account, properties);
371 empathy_account_unescape_protocol (const gchar *protocol, gssize len)
373 gchar *result, *escape;
374 /* Bad implementation might accidentally use tp_escape_as_identifier,
375 * which escapes - in the wrong way... */
376 if ((escape = g_strstr_len (protocol, len, "_2d")) != NULL)
381 str = g_string_new ("");
384 g_string_append_len (str, input, escape - input);
385 g_string_append_c (str, '-');
387 len -= escape - input + 3;
389 } while ((escape = g_strstr_len (input, len, "_2d")) != NULL);
391 g_string_append_len (str, input, len);
393 result = g_string_free (str, FALSE);
397 result = g_strndup (protocol, len);
400 g_strdelimit (result, "_", '-');
406 empathy_account_parse_unique_name (const gchar *bus_name,
407 gchar **protocol, gchar **manager)
409 const gchar *proto, *proto_end;
410 const gchar *cm, *cm_end;
412 g_return_val_if_fail (
413 g_str_has_prefix (bus_name, UNIQUE_NAME_PREFIX), FALSE);
415 cm = bus_name + strlen (UNIQUE_NAME_PREFIX);
417 for (cm_end = cm; *cm_end != '/' && *cm_end != '\0'; cm_end++)
428 for (proto_end = proto; *proto_end != '/' && *proto_end != '\0'; proto_end++)
431 if (*proto_end == '\0')
434 if (protocol != NULL)
436 *protocol = empathy_account_unescape_protocol (proto, proto_end - proto);
440 *manager = g_strndup (cm, cm_end - cm);
446 account_invalidated_cb (TpProxy *proxy, guint domain, gint code,
447 gchar *message, gpointer user_data)
449 EmpathyAccount *account = EMPATHY_ACCOUNT (user_data);
450 EmpathyAccountPriv *priv = GET_PRIV (account);
455 priv->removed = TRUE;
457 g_signal_emit (account, signals[REMOVED], 0);
461 empathy_account_constructed (GObject *object)
463 EmpathyAccount *account = EMPATHY_ACCOUNT (object);
464 EmpathyAccountPriv *priv = GET_PRIV (account);
466 priv->account = tp_account_new (priv->dbus, priv->unique_name, NULL);
468 g_signal_connect (priv->account, "invalidated",
469 G_CALLBACK (account_invalidated_cb), object);
471 empathy_account_parse_unique_name (priv->unique_name,
472 &(priv->proto_name), &(priv->cm_name));
474 priv->icon_name = empathy_protocol_icon_name (priv->proto_name);
476 tp_cli_account_connect_to_account_property_changed (priv->account,
477 empathy_account_properties_changed,
478 NULL, NULL, object, NULL);
480 tp_cli_account_connect_to_removed (priv->account,
481 empathy_account_removed_cb,
482 NULL, NULL, object, NULL);
484 tp_cli_dbus_properties_call_get_all (priv->account, -1,
486 empathy_account_got_all_cb,
492 static void empathy_account_dispose (GObject *object);
493 static void empathy_account_finalize (GObject *object);
496 empathy_account_class_init (EmpathyAccountClass *empathy_account_class)
498 GObjectClass *object_class = G_OBJECT_CLASS (empathy_account_class);
500 g_type_class_add_private (empathy_account_class,
501 sizeof (EmpathyAccountPriv));
503 object_class->set_property = empathy_account_set_property;
504 object_class->get_property = empathy_account_get_property;
505 object_class->dispose = empathy_account_dispose;
506 object_class->finalize = empathy_account_finalize;
507 object_class->constructed = empathy_account_constructed;
509 g_object_class_install_property (object_class, PROP_ENABLED,
510 g_param_spec_boolean ("enabled",
512 "Whether this account is enabled or not",
514 G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE));
516 g_object_class_install_property (object_class, PROP_READY,
517 g_param_spec_boolean ("ready",
519 "Whether this account is ready to be used",
521 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
523 g_object_class_install_property (object_class, PROP_PRESENCE,
524 g_param_spec_uint ("presence",
526 "The account connections presence type",
528 NUM_TP_CONNECTION_PRESENCE_TYPES,
529 TP_CONNECTION_PRESENCE_TYPE_UNSET,
530 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
532 g_object_class_install_property (object_class, PROP_STATUS,
533 g_param_spec_string ("status",
535 "The Status string of the account",
537 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
539 g_object_class_install_property (object_class, PROP_STATUS_MESSAGE,
540 g_param_spec_string ("status-message",
542 "The Status message string of the account",
544 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
546 g_object_class_install_property (object_class, PROP_CONNECTION_STATUS,
547 g_param_spec_uint ("connection-status",
549 "The accounts connections status type",
551 NUM_TP_CONNECTION_STATUSES,
552 TP_CONNECTION_STATUS_DISCONNECTED,
553 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
555 g_object_class_install_property (object_class, PROP_CONNECTION_STATUS_REASON,
556 g_param_spec_uint ("status-reason",
557 "ConnectionStatusReason",
558 "The account connections status reason",
560 NUM_TP_CONNECTION_STATUS_REASONS,
561 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
562 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
564 g_object_class_install_property (object_class, PROP_CONNECTION,
565 g_param_spec_object ("connection",
567 "The accounts connection",
569 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
571 g_object_class_install_property (object_class, PROP_UNIQUE_NAME,
572 g_param_spec_string ("unique-name",
574 "The accounts unique name",
576 G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
578 g_object_class_install_property (object_class, PROP_DBUS_DAEMON,
579 g_param_spec_object ("dbus-daemon",
581 "The Tp Dbus daemon on which this account exists",
583 G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
585 g_object_class_install_property (object_class, PROP_DISPLAY_NAME,
586 g_param_spec_string ("display-name",
588 "The accounts display name",
590 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
592 signals[STATUS_CHANGED] = g_signal_new ("status-changed",
593 G_TYPE_FROM_CLASS (object_class),
596 _empathy_marshal_VOID__UINT_UINT_UINT,
597 G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT);
599 signals[PRESENCE_CHANGED] = g_signal_new ("presence-changed",
600 G_TYPE_FROM_CLASS (object_class),
603 _empathy_marshal_VOID__UINT_STRING_STRING,
604 G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING);
606 signals[REMOVED] = g_signal_new ("removed",
607 G_TYPE_FROM_CLASS (object_class),
610 g_cclosure_marshal_VOID__VOID,
615 empathy_account_free_connection (EmpathyAccount *account)
617 EmpathyAccountPriv *priv = GET_PRIV (account);
619 if (priv->connection_invalidated_id != 0)
620 g_signal_handler_disconnect (priv->connection,
621 priv->connection_invalidated_id);
622 priv->connection_invalidated_id = 0;
624 if (priv->connection != NULL)
625 g_object_unref (priv->connection);
626 priv->connection = NULL;
630 empathy_account_dispose (GObject *object)
632 EmpathyAccount *self = EMPATHY_ACCOUNT (object);
633 EmpathyAccountPriv *priv = GET_PRIV (self);
635 if (priv->dispose_has_run)
638 priv->dispose_has_run = TRUE;
640 empathy_account_free_connection (self);
642 /* release any references held by the object here */
643 if (G_OBJECT_CLASS (empathy_account_parent_class)->dispose != NULL)
644 G_OBJECT_CLASS (empathy_account_parent_class)->dispose (object);
648 empathy_account_finalize (GObject *object)
650 EmpathyAccountPriv *priv = GET_PRIV (object);
652 g_free (priv->status);
653 g_free (priv->message);
655 g_free (priv->cm_name);
656 g_free (priv->proto_name);
657 g_free (priv->icon_name);
658 g_free (priv->display_name);
660 /* free any data held directly by the object here */
661 if (G_OBJECT_CLASS (empathy_account_parent_class)->finalize != NULL)
662 G_OBJECT_CLASS (empathy_account_parent_class)->finalize (object);
666 empathy_account_is_just_connected (EmpathyAccount *account)
668 EmpathyAccountPriv *priv = GET_PRIV (account);
671 if (priv->connection_status != TP_CONNECTION_STATUS_CONNECTED)
674 g_get_current_time (&val);
676 return (val.tv_sec - priv->connect_time) < 10;
680 * empathy_account_get_connection:
681 * @account: a #EmpathyAccount
683 * Get the connection of the account, or NULL if account is offline or the
684 * connection is not yet ready. This function does not return a new ref.
686 * Returns: the connection of the account.
689 empathy_account_get_connection (EmpathyAccount *account)
691 EmpathyAccountPriv *priv = GET_PRIV (account);
693 if (priv->connection != NULL &&
694 tp_connection_is_ready (priv->connection))
695 return priv->connection;
701 * empathy_account_get_unique_name:
702 * @account: a #EmpathyAccount
704 * Returns: the unique name of the account.
707 empathy_account_get_unique_name (EmpathyAccount *account)
709 EmpathyAccountPriv *priv = GET_PRIV (account);
711 return priv->unique_name;
715 * empathy_account_get_display_name:
716 * @account: a #EmpathyAccount
718 * Returns: the display name of the account.
721 empathy_account_get_display_name (EmpathyAccount *account)
723 EmpathyAccountPriv *priv = GET_PRIV (account);
725 return priv->display_name;
729 empathy_account_is_valid (EmpathyAccount *account)
731 EmpathyAccountPriv *priv = GET_PRIV (account);
737 empathy_account_get_connection_manager (EmpathyAccount *account)
739 EmpathyAccountPriv *priv = GET_PRIV (account);
741 return priv->cm_name;
745 empathy_account_get_protocol (EmpathyAccount *account)
747 EmpathyAccountPriv *priv = GET_PRIV (account);
749 return priv->proto_name;
753 empathy_account_get_icon_name (EmpathyAccount *account)
755 EmpathyAccountPriv *priv = GET_PRIV (account);
757 return priv->icon_name;
761 empathy_account_get_parameters (EmpathyAccount *account)
763 EmpathyAccountPriv *priv = GET_PRIV (account);
765 return priv->parameters;
769 empathy_account_is_enabled (EmpathyAccount *account)
771 EmpathyAccountPriv *priv = GET_PRIV (account);
773 return priv->enabled;
777 empathy_account_is_ready (EmpathyAccount *account)
779 EmpathyAccountPriv *priv = GET_PRIV (account);
786 empathy_account_new (TpDBusDaemon *dbus,
787 const gchar *unique_name)
789 return EMPATHY_ACCOUNT (g_object_new (EMPATHY_TYPE_ACCOUNT,
791 "unique-name", unique_name,
796 empathy_account_connection_ready_cb (TpConnection *connection,
800 EmpathyAccount *account = EMPATHY_ACCOUNT (user_data);
804 DEBUG ("(%s) Connection failed to become ready: %s",
805 empathy_account_get_unique_name (account), error->message);
806 empathy_account_free_connection (account);
810 DEBUG ("(%s) Connection ready",
811 empathy_account_get_unique_name (account));
812 g_object_notify (G_OBJECT (account), "connection");
817 _empathy_account_connection_invalidated_cb (TpProxy *self,
823 EmpathyAccount *account = EMPATHY_ACCOUNT (user_data);
824 EmpathyAccountPriv *priv = GET_PRIV (account);
826 if (priv->connection == NULL)
829 DEBUG ("(%s) Connection invalidated",
830 empathy_account_get_unique_name (account));
832 g_assert (priv->connection == TP_CONNECTION (self));
834 g_signal_handler_disconnect (priv->connection,
835 priv->connection_invalidated_id);
836 priv->connection_invalidated_id = 0;
838 g_object_unref (priv->connection);
839 priv->connection = NULL;
841 g_object_notify (G_OBJECT (account), "connection");
845 _empathy_account_set_connection (EmpathyAccount *account,
846 TpConnection *connection)
848 EmpathyAccountPriv *priv = GET_PRIV (account);
850 if (priv->connection == connection)
853 /* Connection already set, don't set the new one */
854 if (connection != NULL && priv->connection != NULL)
857 if (connection == NULL)
859 g_signal_handler_disconnect (priv->connection,
860 priv->connection_invalidated_id);
861 priv->connection_invalidated_id = 0;
863 g_object_unref (priv->connection);
864 priv->connection = NULL;
865 g_object_notify (G_OBJECT (account), "connection");
869 priv->connection = g_object_ref (connection);
870 priv->connection_invalidated_id = g_signal_connect (priv->connection,
872 G_CALLBACK (_empathy_account_connection_invalidated_cb),
875 DEBUG ("Readying connection for %s", priv->unique_name);
876 /* notify a change in the connection property when it's ready */
877 tp_connection_call_when_ready (priv->connection,
878 empathy_account_connection_ready_cb, account);
883 empathy_account_set_enabled (EmpathyAccount *account,
886 EmpathyAccountPriv *priv = GET_PRIV (account);
887 GValue value = {0, };
889 if (priv->enabled == enabled)
892 g_value_init (&value, G_TYPE_BOOLEAN);
893 g_value_set_boolean (&value, enabled);
895 tp_cli_dbus_properties_call_set (TP_PROXY (priv->account),
905 g_value_unset (&value);
909 empathy_account_requested_presence_cb (TpProxy *proxy,
912 GObject *weak_object)
915 DEBUG ("Failed to set the requested presence: %s", error->message);
920 empathy_account_request_presence (EmpathyAccount *account,
921 TpConnectionPresenceType type,
923 const gchar *message)
925 EmpathyAccountPriv *priv = GET_PRIV (account);
926 GValue value = {0, };
929 g_value_init (&value, TP_STRUCT_TYPE_SIMPLE_PRESENCE);
930 g_value_take_boxed (&value, dbus_g_type_specialized_construct
931 (TP_STRUCT_TYPE_SIMPLE_PRESENCE));
932 arr = (GValueArray *) g_value_get_boxed (&value);
934 g_value_set_uint (arr->values, type);
935 g_value_set_static_string (arr->values + 1, status);
936 g_value_set_static_string (arr->values + 2, message);
938 tp_cli_dbus_properties_call_set (TP_PROXY (priv->account),
943 empathy_account_requested_presence_cb,
948 g_value_unset (&value);
952 empathy_account_updated_cb (TpAccount *proxy,
953 const gchar **reconnect_required,
956 GObject *weak_object)
958 GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data);
962 g_simple_async_result_set_from_error (result, (GError *) error);
965 g_simple_async_result_complete (result);
966 g_object_unref (G_OBJECT (result));
970 empathy_account_update_settings_async (EmpathyAccount *account,
971 GHashTable *parameters, const gchar **unset_parameters,
972 GAsyncReadyCallback callback, gpointer user_data)
974 EmpathyAccountPriv *priv = GET_PRIV (account);
975 GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (account),
976 callback, user_data, empathy_account_update_settings_finish);
978 tp_cli_account_call_update_parameters (priv->account,
982 empathy_account_updated_cb,
989 empathy_account_update_settings_finish (EmpathyAccount *account,
990 GAsyncResult *result, GError **error)
992 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
996 g_return_val_if_fail (g_simple_async_result_is_valid (result,
997 G_OBJECT (account), empathy_account_update_settings_finish), FALSE);
1003 account_display_name_set_cb (TpProxy *proxy,
1004 const GError *error,
1006 GObject *weak_object)
1008 GSimpleAsyncResult *result = user_data;
1011 g_simple_async_result_set_from_error (result, (GError *) error);
1013 g_simple_async_result_complete (result);
1014 g_object_unref (result);
1018 empathy_account_set_display_name_async (EmpathyAccount *account,
1019 const char *display_name,
1020 GAsyncReadyCallback callback,
1023 GSimpleAsyncResult *result;
1024 GValue value = {0, };
1025 EmpathyAccountPriv *priv = GET_PRIV (account);
1027 if (display_name == NULL)
1029 g_simple_async_report_error_in_idle (G_OBJECT (account),
1030 callback, user_data, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
1031 _("Can't set an empty display name"));
1035 result = g_simple_async_result_new (G_OBJECT (account), callback,
1036 user_data, empathy_account_set_display_name_finish);
1038 g_value_init (&value, G_TYPE_STRING);
1039 g_value_set_string (&value, display_name);
1041 tp_cli_dbus_properties_call_set (priv->account, -1, TP_IFACE_ACCOUNT,
1042 "DisplayName", &value, account_display_name_set_cb, result, NULL,
1043 G_OBJECT (account));
1047 empathy_account_set_display_name_finish (EmpathyAccount *account,
1048 GAsyncResult *result, GError **error)
1050 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
1052 !g_simple_async_result_is_valid (result, G_OBJECT (account),
1053 empathy_account_set_display_name_finish))
1060 empathy_account_remove_cb (TpAccount *proxy,
1061 const GError *error,
1063 GObject *weak_object)
1065 GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data);
1069 g_simple_async_result_set_from_error (result, (GError *) error);
1072 g_simple_async_result_complete (result);
1073 g_object_unref (G_OBJECT (result));
1077 empathy_account_remove_async (EmpathyAccount *account,
1078 GAsyncReadyCallback callback, gpointer user_data)
1080 EmpathyAccountPriv *priv = GET_PRIV (account);
1081 GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (account),
1082 callback, user_data, empathy_account_remove_finish);
1084 tp_cli_account_call_remove (priv->account,
1086 empathy_account_remove_cb,
1089 G_OBJECT (account));
1093 empathy_account_remove_finish (EmpathyAccount *account,
1094 GAsyncResult *result, GError **error)
1096 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
1100 g_return_val_if_fail (g_simple_async_result_is_valid (result,
1101 G_OBJECT (account), empathy_account_update_settings_finish), FALSE);