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>
31 #include <telepathy-glib/defs.h>
33 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
34 #include <libempathy/empathy-debug.h>
36 #include <glib/gi18n-lib.h>
38 #include "empathy-account.h"
39 #include "empathy-utils.h"
40 #include "empathy-marshal.h"
50 static guint signals[LAST_SIGNAL];
59 PROP_CONNECTION_STATUS,
60 PROP_CONNECTION_STATUS_REASON,
67 G_DEFINE_TYPE(EmpathyAccount, empathy_account, G_TYPE_OBJECT)
69 /* private structure */
70 typedef struct _EmpathyAccountPriv EmpathyAccountPriv;
72 struct _EmpathyAccountPriv
74 gboolean dispose_has_run;
76 TpConnection *connection;
77 guint connection_invalidated_id;
79 TpConnectionStatus connection_status;
80 TpConnectionStatusReason reason;
82 TpConnectionPresenceType presence;
90 /* Timestamp when the connection got connected in seconds since the epoch */
102 GHashTable *parameters;
105 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccount)
107 static void _empathy_account_set_connection (EmpathyAccount *account,
111 empathy_account_init (EmpathyAccount *obj)
113 EmpathyAccountPriv *priv;
115 priv = G_TYPE_INSTANCE_GET_PRIVATE (obj,
116 EMPATHY_TYPE_ACCOUNT, EmpathyAccountPriv);
120 priv->connection_status = TP_CONNECTION_STATUS_DISCONNECTED;
124 empathy_account_set_property (GObject *object,
129 EmpathyAccount *account = EMPATHY_ACCOUNT (object);
130 EmpathyAccountPriv *priv = GET_PRIV (account);
135 empathy_account_set_enabled_async (account,
136 g_value_get_boolean (value), NULL, NULL);
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_object (value, priv->dbus);
198 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
204 empathy_account_update (EmpathyAccount *account,
205 GHashTable *properties)
207 EmpathyAccountPriv *priv = GET_PRIV (account);
209 TpConnectionStatus old_s = priv->connection_status;
210 gboolean presence_changed = FALSE;
212 if (g_hash_table_lookup (properties, "ConnectionStatus") != NULL)
213 priv->connection_status =
214 tp_asv_get_int32 (properties, "ConnectionStatus", NULL);
216 if (g_hash_table_lookup (properties, "ConnectionStatusReason") != NULL)
217 priv->reason = tp_asv_get_int32 (properties,
218 "ConnectionStatusReason", NULL);
220 if (g_hash_table_lookup (properties, "CurrentPresence") != NULL)
222 presence_changed = TRUE;
223 arr = tp_asv_get_boxed (properties, "CurrentPresence",
224 TP_STRUCT_TYPE_SIMPLE_PRESENCE);
225 priv->presence = g_value_get_uint (g_value_array_get_nth (arr, 0));
227 g_free (priv->status);
228 priv->status = g_value_dup_string (g_value_array_get_nth (arr, 1));
230 g_free (priv->message);
231 priv->message = g_value_dup_string (g_value_array_get_nth (arr, 2));
234 if (g_hash_table_lookup (properties, "DisplayName") != NULL)
236 g_free (priv->display_name);
238 g_strdup (tp_asv_get_string (properties, "DisplayName"));
239 g_object_notify (G_OBJECT (account), "display-name");
242 if (g_hash_table_lookup (properties, "Enabled") != NULL)
244 gboolean enabled = tp_asv_get_boolean (properties, "Enabled", NULL);
245 if (priv->enabled != enabled)
247 priv->enabled = enabled;
248 g_object_notify (G_OBJECT (account), "enabled");
252 if (g_hash_table_lookup (properties, "Valid") != NULL)
253 priv->valid = tp_asv_get_boolean (properties, "Valid", NULL);
255 if (g_hash_table_lookup (properties, "Parameters") != NULL)
257 GHashTable *parameters;
259 parameters = tp_asv_get_boxed (properties, "Parameters",
260 TP_HASH_TYPE_STRING_VARIANT_MAP);
262 if (priv->parameters != NULL)
263 g_hash_table_unref (priv->parameters);
265 priv->parameters = g_boxed_copy (TP_HASH_TYPE_STRING_VARIANT_MAP,
272 g_object_notify (G_OBJECT (account), "ready");
275 if (priv->connection_status != old_s)
277 if (priv->connection_status == TP_CONNECTION_STATUS_CONNECTED)
280 g_get_current_time (&val);
282 priv->connect_time = val.tv_sec;
285 g_signal_emit (account, signals[STATUS_CHANGED], 0,
286 old_s, priv->connection_status, priv->reason);
288 g_object_notify (G_OBJECT (account), "connection-status");
289 g_object_notify (G_OBJECT (account), "connection-status-reason");
292 if (presence_changed)
294 g_signal_emit (account, signals[PRESENCE_CHANGED], 0,
295 priv->presence, priv->status, priv->message);
296 g_object_notify (G_OBJECT (account), "presence");
297 g_object_notify (G_OBJECT (account), "status");
298 g_object_notify (G_OBJECT (account), "status-message");
301 if (g_hash_table_lookup (properties, "Connection") != NULL)
303 const gchar *conn_path =
304 tp_asv_get_object_path (properties, "Connection");
306 _empathy_account_set_connection (account, conn_path);
311 empathy_account_properties_changed (TpAccount *proxy,
312 GHashTable *properties,
314 GObject *weak_object)
316 EmpathyAccount *account = EMPATHY_ACCOUNT (weak_object);
317 EmpathyAccountPriv *priv = GET_PRIV (account);
322 empathy_account_update (account, properties);
326 empathy_account_removed_cb (TpAccount *proxy,
328 GObject *weak_object)
330 EmpathyAccount *account = EMPATHY_ACCOUNT (weak_object);
331 EmpathyAccountPriv *priv = GET_PRIV (account);
336 priv->removed = TRUE;
338 g_signal_emit (account, signals[REMOVED], 0);
342 empathy_account_got_all_cb (TpProxy *proxy,
343 GHashTable *properties,
346 GObject *weak_object)
348 EmpathyAccount *account = EMPATHY_ACCOUNT (weak_object);
350 DEBUG ("Got initial set of properties for %s",
351 empathy_account_get_unique_name (account));
355 DEBUG ("Failed to get the initial set of account properties: %s",
360 empathy_account_update (account, properties);
364 empathy_account_unescape_protocol (const gchar *protocol, gssize len)
366 gchar *result, *escape;
367 /* Bad implementation might accidentally use tp_escape_as_identifier,
368 * which escapes - in the wrong way... */
369 if ((escape = g_strstr_len (protocol, len, "_2d")) != NULL)
374 str = g_string_new ("");
377 g_string_append_len (str, input, escape - input);
378 g_string_append_c (str, '-');
380 len -= escape - input + 3;
382 } while ((escape = g_strstr_len (input, len, "_2d")) != NULL);
384 g_string_append_len (str, input, len);
386 result = g_string_free (str, FALSE);
390 result = g_strndup (protocol, len);
393 g_strdelimit (result, "_", '-');
399 empathy_account_parse_unique_name (const gchar *bus_name,
400 gchar **protocol, gchar **manager)
402 const gchar *proto, *proto_end;
403 const gchar *cm, *cm_end;
405 g_return_val_if_fail (
406 g_str_has_prefix (bus_name, TP_ACCOUNT_OBJECT_PATH_BASE), FALSE);
408 cm = bus_name + strlen (TP_ACCOUNT_OBJECT_PATH_BASE);
410 for (cm_end = cm; *cm_end != '/' && *cm_end != '\0'; cm_end++)
421 for (proto_end = proto; *proto_end != '/' && *proto_end != '\0'; proto_end++)
424 if (*proto_end == '\0')
427 if (protocol != NULL)
429 *protocol = empathy_account_unescape_protocol (proto, proto_end - proto);
433 *manager = g_strndup (cm, cm_end - cm);
439 account_invalidated_cb (TpProxy *proxy, guint domain, gint code,
440 gchar *message, gpointer user_data)
442 EmpathyAccount *account = EMPATHY_ACCOUNT (user_data);
443 EmpathyAccountPriv *priv = GET_PRIV (account);
448 priv->removed = TRUE;
450 g_signal_emit (account, signals[REMOVED], 0);
454 empathy_account_constructed (GObject *object)
456 EmpathyAccount *account = EMPATHY_ACCOUNT (object);
457 EmpathyAccountPriv *priv = GET_PRIV (account);
459 priv->account = tp_account_new (priv->dbus, priv->unique_name, NULL);
461 g_signal_connect (priv->account, "invalidated",
462 G_CALLBACK (account_invalidated_cb), object);
464 empathy_account_parse_unique_name (priv->unique_name,
465 &(priv->proto_name), &(priv->cm_name));
467 priv->icon_name = empathy_protocol_icon_name (priv->proto_name);
469 tp_cli_account_connect_to_account_property_changed (priv->account,
470 empathy_account_properties_changed,
471 NULL, NULL, object, NULL);
473 tp_cli_account_connect_to_removed (priv->account,
474 empathy_account_removed_cb,
475 NULL, NULL, object, NULL);
477 tp_cli_dbus_properties_call_get_all (priv->account, -1,
479 empathy_account_got_all_cb,
485 static void empathy_account_dispose (GObject *object);
486 static void empathy_account_finalize (GObject *object);
489 empathy_account_class_init (EmpathyAccountClass *empathy_account_class)
491 GObjectClass *object_class = G_OBJECT_CLASS (empathy_account_class);
493 g_type_class_add_private (empathy_account_class,
494 sizeof (EmpathyAccountPriv));
496 object_class->set_property = empathy_account_set_property;
497 object_class->get_property = empathy_account_get_property;
498 object_class->dispose = empathy_account_dispose;
499 object_class->finalize = empathy_account_finalize;
500 object_class->constructed = empathy_account_constructed;
502 g_object_class_install_property (object_class, PROP_ENABLED,
503 g_param_spec_boolean ("enabled",
505 "Whether this account is enabled or not",
507 G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE));
509 g_object_class_install_property (object_class, PROP_READY,
510 g_param_spec_boolean ("ready",
512 "Whether this account is ready to be used",
514 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
516 g_object_class_install_property (object_class, PROP_PRESENCE,
517 g_param_spec_uint ("presence",
519 "The account connections presence type",
521 NUM_TP_CONNECTION_PRESENCE_TYPES,
522 TP_CONNECTION_PRESENCE_TYPE_UNSET,
523 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
525 g_object_class_install_property (object_class, PROP_STATUS,
526 g_param_spec_string ("status",
528 "The Status string of the account",
530 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
532 g_object_class_install_property (object_class, PROP_STATUS_MESSAGE,
533 g_param_spec_string ("status-message",
535 "The Status message string of the account",
537 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
539 g_object_class_install_property (object_class, PROP_CONNECTION_STATUS,
540 g_param_spec_uint ("connection-status",
542 "The accounts connections status type",
544 NUM_TP_CONNECTION_STATUSES,
545 TP_CONNECTION_STATUS_DISCONNECTED,
546 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
548 g_object_class_install_property (object_class, PROP_CONNECTION_STATUS_REASON,
549 g_param_spec_uint ("connection-status-reason",
550 "ConnectionStatusReason",
551 "The account connections status reason",
553 NUM_TP_CONNECTION_STATUS_REASONS,
554 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
555 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
557 g_object_class_install_property (object_class, PROP_CONNECTION,
558 g_param_spec_object ("connection",
560 "The accounts connection",
562 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
564 g_object_class_install_property (object_class, PROP_UNIQUE_NAME,
565 g_param_spec_string ("unique-name",
567 "The accounts unique name",
569 G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
571 g_object_class_install_property (object_class, PROP_DBUS_DAEMON,
572 g_param_spec_object ("dbus-daemon",
574 "The Tp Dbus daemon on which this account exists",
576 G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
578 g_object_class_install_property (object_class, PROP_DISPLAY_NAME,
579 g_param_spec_string ("display-name",
581 "The accounts display name",
583 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
585 signals[STATUS_CHANGED] = g_signal_new ("status-changed",
586 G_TYPE_FROM_CLASS (object_class),
589 _empathy_marshal_VOID__UINT_UINT_UINT,
590 G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT);
592 signals[PRESENCE_CHANGED] = g_signal_new ("presence-changed",
593 G_TYPE_FROM_CLASS (object_class),
596 _empathy_marshal_VOID__UINT_STRING_STRING,
597 G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING);
599 signals[REMOVED] = g_signal_new ("removed",
600 G_TYPE_FROM_CLASS (object_class),
603 g_cclosure_marshal_VOID__VOID,
608 empathy_account_free_connection (EmpathyAccount *account)
610 EmpathyAccountPriv *priv = GET_PRIV (account);
612 if (priv->connection_invalidated_id != 0)
613 g_signal_handler_disconnect (priv->connection,
614 priv->connection_invalidated_id);
615 priv->connection_invalidated_id = 0;
617 if (priv->connection != NULL)
618 g_object_unref (priv->connection);
619 priv->connection = NULL;
623 empathy_account_dispose (GObject *object)
625 EmpathyAccount *self = EMPATHY_ACCOUNT (object);
626 EmpathyAccountPriv *priv = GET_PRIV (self);
628 if (priv->dispose_has_run)
631 priv->dispose_has_run = TRUE;
633 empathy_account_free_connection (self);
635 /* release any references held by the object here */
636 if (G_OBJECT_CLASS (empathy_account_parent_class)->dispose != NULL)
637 G_OBJECT_CLASS (empathy_account_parent_class)->dispose (object);
641 empathy_account_finalize (GObject *object)
643 EmpathyAccountPriv *priv = GET_PRIV (object);
645 g_free (priv->status);
646 g_free (priv->message);
648 g_free (priv->cm_name);
649 g_free (priv->proto_name);
650 g_free (priv->icon_name);
651 g_free (priv->display_name);
653 /* free any data held directly by the object here */
654 if (G_OBJECT_CLASS (empathy_account_parent_class)->finalize != NULL)
655 G_OBJECT_CLASS (empathy_account_parent_class)->finalize (object);
659 empathy_account_is_just_connected (EmpathyAccount *account)
661 EmpathyAccountPriv *priv = GET_PRIV (account);
664 if (priv->connection_status != TP_CONNECTION_STATUS_CONNECTED)
667 g_get_current_time (&val);
669 return (val.tv_sec - priv->connect_time) < 10;
673 * empathy_account_get_connection:
674 * @account: a #EmpathyAccount
676 * Get the connection of the account, or NULL if account is offline or the
677 * connection is not yet ready. This function does not return a new ref.
679 * Returns: the connection of the account.
682 empathy_account_get_connection (EmpathyAccount *account)
684 EmpathyAccountPriv *priv = GET_PRIV (account);
686 if (priv->connection != NULL &&
687 tp_connection_is_ready (priv->connection))
688 return priv->connection;
694 * empathy_account_get_connection_for_path:
695 * @account: a #EmpathyAccount
696 * @patch: the path to connection object for #EmpathyAccount
698 * Get the connection of the account on path. This function does not return a
699 * new ref. It is not guaranteed that the returned connection object is ready
701 * Returns: the connection of the account.
704 empathy_account_get_connection_for_path (EmpathyAccount *account,
707 EmpathyAccountPriv *priv = GET_PRIV (account);
709 /* double-check that the object path is valid */
710 if (!tp_dbus_check_valid_object_path (path, NULL))
713 /* Should be a full object path, not the special "/" value */
714 if (strlen (path) == 1)
717 _empathy_account_set_connection (account, path);
719 return priv->connection;
723 * empathy_account_get_unique_name:
724 * @account: a #EmpathyAccount
726 * Returns: the unique name of the account.
729 empathy_account_get_unique_name (EmpathyAccount *account)
731 EmpathyAccountPriv *priv = GET_PRIV (account);
733 return priv->unique_name;
737 * empathy_account_get_display_name:
738 * @account: a #EmpathyAccount
740 * Returns: the display name of the account.
743 empathy_account_get_display_name (EmpathyAccount *account)
745 EmpathyAccountPriv *priv = GET_PRIV (account);
747 return priv->display_name;
751 empathy_account_is_valid (EmpathyAccount *account)
753 EmpathyAccountPriv *priv = GET_PRIV (account);
759 empathy_account_get_connection_manager (EmpathyAccount *account)
761 EmpathyAccountPriv *priv = GET_PRIV (account);
763 return priv->cm_name;
767 empathy_account_get_protocol (EmpathyAccount *account)
769 EmpathyAccountPriv *priv = GET_PRIV (account);
771 return priv->proto_name;
775 empathy_account_get_icon_name (EmpathyAccount *account)
777 EmpathyAccountPriv *priv = GET_PRIV (account);
779 return priv->icon_name;
783 empathy_account_get_parameters (EmpathyAccount *account)
785 EmpathyAccountPriv *priv = GET_PRIV (account);
787 return priv->parameters;
791 empathy_account_is_enabled (EmpathyAccount *account)
793 EmpathyAccountPriv *priv = GET_PRIV (account);
795 return priv->enabled;
799 empathy_account_is_ready (EmpathyAccount *account)
801 EmpathyAccountPriv *priv = GET_PRIV (account);
808 empathy_account_new (TpDBusDaemon *dbus,
809 const gchar *unique_name)
811 return EMPATHY_ACCOUNT (g_object_new (EMPATHY_TYPE_ACCOUNT,
813 "unique-name", unique_name,
818 empathy_account_connection_ready_cb (TpConnection *connection,
822 EmpathyAccount *account = EMPATHY_ACCOUNT (user_data);
826 DEBUG ("(%s) Connection failed to become ready: %s",
827 empathy_account_get_unique_name (account), error->message);
828 empathy_account_free_connection (account);
832 DEBUG ("(%s) Connection ready",
833 empathy_account_get_unique_name (account));
834 g_object_notify (G_OBJECT (account), "connection");
839 _empathy_account_connection_invalidated_cb (TpProxy *self,
845 EmpathyAccount *account = EMPATHY_ACCOUNT (user_data);
846 EmpathyAccountPriv *priv = GET_PRIV (account);
848 if (priv->connection == NULL)
851 DEBUG ("(%s) Connection invalidated",
852 empathy_account_get_unique_name (account));
854 g_assert (priv->connection == TP_CONNECTION (self));
856 g_signal_handler_disconnect (priv->connection,
857 priv->connection_invalidated_id);
858 priv->connection_invalidated_id = 0;
860 g_object_unref (priv->connection);
861 priv->connection = NULL;
863 g_object_notify (G_OBJECT (account), "connection");
867 _empathy_account_set_connection (EmpathyAccount *account,
870 EmpathyAccountPriv *priv = GET_PRIV (account);
872 if (priv->connection != NULL)
874 const gchar *current;
876 current = tp_proxy_get_object_path (priv->connection);
877 if (!tp_strdiff (current, path))
881 if (priv->connection != NULL)
883 g_signal_handler_disconnect (priv->connection,
884 priv->connection_invalidated_id);
885 priv->connection_invalidated_id = 0;
887 g_object_unref (priv->connection);
888 priv->connection = NULL;
891 if (tp_strdiff ("/", path))
893 GError *error = NULL;
894 priv->connection = tp_connection_new (priv->dbus, NULL, path, &error);
896 if (priv->connection == NULL)
898 DEBUG ("Failed to create a new TpConnection: %s",
900 g_error_free (error);
904 priv->connection_invalidated_id = g_signal_connect (priv->connection,
906 G_CALLBACK (_empathy_account_connection_invalidated_cb), account);
908 DEBUG ("Readying connection for %s", priv->unique_name);
909 /* notify a change in the connection property when it's ready */
910 tp_connection_call_when_ready (priv->connection,
911 empathy_account_connection_ready_cb, account);
915 g_object_notify (G_OBJECT (account), "connection");
919 account_enabled_set_cb (TpProxy *proxy,
922 GObject *weak_object)
924 GSimpleAsyncResult *result = user_data;
927 g_simple_async_result_set_from_error (result, (GError *) error);
929 g_simple_async_result_complete (result);
930 g_object_unref (result);
934 empathy_account_set_enabled_finish (EmpathyAccount *account,
935 GAsyncResult *result,
938 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
940 !g_simple_async_result_is_valid (result, G_OBJECT (account),
941 empathy_account_set_enabled_finish))
948 empathy_account_set_enabled_async (EmpathyAccount *account,
950 GAsyncReadyCallback callback,
953 EmpathyAccountPriv *priv = GET_PRIV (account);
954 GValue value = {0, };
955 GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (account),
956 callback, user_data, empathy_account_set_enabled_finish);
958 if (priv->enabled == enabled)
960 g_simple_async_result_complete_in_idle (result);
964 g_value_init (&value, G_TYPE_BOOLEAN);
965 g_value_set_boolean (&value, enabled);
967 tp_cli_dbus_properties_call_set (TP_PROXY (priv->account),
968 -1, TP_IFACE_ACCOUNT, "Enabled", &value,
969 account_enabled_set_cb, result, NULL, G_OBJECT (account));
973 empathy_account_requested_presence_cb (TpProxy *proxy,
976 GObject *weak_object)
979 DEBUG ("Failed to set the requested presence: %s", error->message);
984 empathy_account_request_presence (EmpathyAccount *account,
985 TpConnectionPresenceType type,
987 const gchar *message)
989 EmpathyAccountPriv *priv = GET_PRIV (account);
990 GValue value = {0, };
993 g_value_init (&value, TP_STRUCT_TYPE_SIMPLE_PRESENCE);
994 g_value_take_boxed (&value, dbus_g_type_specialized_construct
995 (TP_STRUCT_TYPE_SIMPLE_PRESENCE));
996 arr = (GValueArray *) g_value_get_boxed (&value);
998 g_value_set_uint (arr->values, type);
999 g_value_set_static_string (arr->values + 1, status);
1000 g_value_set_static_string (arr->values + 2, message);
1002 tp_cli_dbus_properties_call_set (TP_PROXY (priv->account),
1005 "RequestedPresence",
1007 empathy_account_requested_presence_cb,
1010 G_OBJECT (account));
1012 g_value_unset (&value);
1016 empathy_account_updated_cb (TpAccount *proxy,
1017 const gchar **reconnect_required,
1018 const GError *error,
1020 GObject *weak_object)
1022 GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data);
1026 g_simple_async_result_set_from_error (result, (GError *) error);
1029 g_simple_async_result_complete (result);
1030 g_object_unref (G_OBJECT (result));
1034 empathy_account_update_settings_async (EmpathyAccount *account,
1035 GHashTable *parameters, const gchar **unset_parameters,
1036 GAsyncReadyCallback callback, gpointer user_data)
1038 EmpathyAccountPriv *priv = GET_PRIV (account);
1039 GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (account),
1040 callback, user_data, empathy_account_update_settings_finish);
1042 tp_cli_account_call_update_parameters (priv->account,
1046 empathy_account_updated_cb,
1049 G_OBJECT (account));
1053 empathy_account_update_settings_finish (EmpathyAccount *account,
1054 GAsyncResult *result, GError **error)
1056 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
1060 g_return_val_if_fail (g_simple_async_result_is_valid (result,
1061 G_OBJECT (account), empathy_account_update_settings_finish), FALSE);
1067 account_display_name_set_cb (TpProxy *proxy,
1068 const GError *error,
1070 GObject *weak_object)
1072 GSimpleAsyncResult *result = user_data;
1075 g_simple_async_result_set_from_error (result, (GError *) error);
1077 g_simple_async_result_complete (result);
1078 g_object_unref (result);
1082 empathy_account_set_display_name_async (EmpathyAccount *account,
1083 const char *display_name,
1084 GAsyncReadyCallback callback,
1087 GSimpleAsyncResult *result;
1088 GValue value = {0, };
1089 EmpathyAccountPriv *priv = GET_PRIV (account);
1091 if (display_name == NULL)
1093 g_simple_async_report_error_in_idle (G_OBJECT (account),
1094 callback, user_data, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
1095 _("Can't set an empty display name"));
1099 result = g_simple_async_result_new (G_OBJECT (account), callback,
1100 user_data, empathy_account_set_display_name_finish);
1102 g_value_init (&value, G_TYPE_STRING);
1103 g_value_set_string (&value, display_name);
1105 tp_cli_dbus_properties_call_set (priv->account, -1, TP_IFACE_ACCOUNT,
1106 "DisplayName", &value, account_display_name_set_cb, result, NULL,
1107 G_OBJECT (account));
1111 empathy_account_set_display_name_finish (EmpathyAccount *account,
1112 GAsyncResult *result, GError **error)
1114 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
1116 !g_simple_async_result_is_valid (result, G_OBJECT (account),
1117 empathy_account_set_display_name_finish))
1124 empathy_account_remove_cb (TpAccount *proxy,
1125 const GError *error,
1127 GObject *weak_object)
1129 GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data);
1133 g_simple_async_result_set_from_error (result, (GError *) error);
1136 g_simple_async_result_complete (result);
1137 g_object_unref (G_OBJECT (result));
1141 empathy_account_remove_async (EmpathyAccount *account,
1142 GAsyncReadyCallback callback, gpointer user_data)
1144 EmpathyAccountPriv *priv = GET_PRIV (account);
1145 GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (account),
1146 callback, user_data, empathy_account_remove_finish);
1148 tp_cli_account_call_remove (priv->account,
1150 empathy_account_remove_cb,
1153 G_OBJECT (account));
1157 empathy_account_remove_finish (EmpathyAccount *account,
1158 GAsyncResult *result, GError **error)
1160 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
1164 g_return_val_if_fail (g_simple_async_result_is_valid (result,
1165 G_OBJECT (account), empathy_account_update_settings_finish), FALSE);