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-account-manager.h"
40 #include "empathy-utils.h"
41 #include "empathy-marshal.h"
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,
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_async (account,
137 g_value_get_boolean (value), NULL, NULL);
139 case PROP_UNIQUE_NAME:
140 priv->unique_name = g_value_dup_string (value);
142 case PROP_DBUS_DAEMON:
143 priv->dbus = g_value_get_object (value);
146 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
152 empathy_account_get_property (GObject *object,
157 EmpathyAccount *account = EMPATHY_ACCOUNT (object);
158 EmpathyAccountPriv *priv = GET_PRIV (account);
163 g_value_set_boolean (value, priv->enabled);
166 g_value_set_boolean (value, priv->ready);
169 g_value_set_uint (value, priv->presence);
172 g_value_set_string (value, priv->status);
174 case PROP_STATUS_MESSAGE:
175 g_value_set_string (value, priv->message);
177 case PROP_CONNECTION_STATUS:
178 g_value_set_uint (value, priv->connection_status);
180 case PROP_CONNECTION_STATUS_REASON:
181 g_value_set_uint (value, priv->reason);
183 case PROP_CONNECTION:
184 g_value_set_object (value,
185 empathy_account_get_connection (account));
187 case PROP_UNIQUE_NAME:
188 g_value_set_string (value,
189 empathy_account_get_unique_name (account));
191 case PROP_DISPLAY_NAME:
192 g_value_set_string (value,
193 empathy_account_get_display_name (account));
195 case PROP_DBUS_DAEMON:
196 g_value_set_object (value, priv->dbus);
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);
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_free (priv->display_name);
239 g_strdup (tp_asv_get_string (properties, "DisplayName"));
240 g_object_notify (G_OBJECT (account), "display-name");
243 if (g_hash_table_lookup (properties, "Icon") != NULL)
245 const gchar *icon_name;
247 icon_name = tp_asv_get_string (properties, "Icon");
249 g_free (priv->icon_name);
251 if (EMP_STR_EMPTY (icon_name))
252 priv->icon_name = empathy_protocol_icon_name (priv->proto_name);
254 priv->icon_name = g_strdup (icon_name);
257 if (g_hash_table_lookup (properties, "Enabled") != NULL)
259 gboolean enabled = tp_asv_get_boolean (properties, "Enabled", NULL);
260 if (priv->enabled != enabled)
262 priv->enabled = enabled;
263 g_object_notify (G_OBJECT (account), "enabled");
267 if (g_hash_table_lookup (properties, "Valid") != NULL)
268 priv->valid = tp_asv_get_boolean (properties, "Valid", NULL);
270 if (g_hash_table_lookup (properties, "Parameters") != NULL)
272 GHashTable *parameters;
274 parameters = tp_asv_get_boxed (properties, "Parameters",
275 TP_HASH_TYPE_STRING_VARIANT_MAP);
277 if (priv->parameters != NULL)
278 g_hash_table_unref (priv->parameters);
280 priv->parameters = g_boxed_copy (TP_HASH_TYPE_STRING_VARIANT_MAP,
287 g_object_notify (G_OBJECT (account), "ready");
290 if (priv->connection_status != old_s)
292 if (priv->connection_status == TP_CONNECTION_STATUS_CONNECTED)
295 g_get_current_time (&val);
297 priv->connect_time = val.tv_sec;
300 g_signal_emit (account, signals[STATUS_CHANGED], 0,
301 old_s, priv->connection_status, priv->reason);
303 g_object_notify (G_OBJECT (account), "connection-status");
304 g_object_notify (G_OBJECT (account), "connection-status-reason");
307 if (presence_changed)
309 g_signal_emit (account, signals[PRESENCE_CHANGED], 0,
310 priv->presence, priv->status, priv->message);
311 g_object_notify (G_OBJECT (account), "presence");
312 g_object_notify (G_OBJECT (account), "status");
313 g_object_notify (G_OBJECT (account), "status-message");
316 if (g_hash_table_lookup (properties, "Connection") != NULL)
318 const gchar *conn_path =
319 tp_asv_get_object_path (properties, "Connection");
321 _empathy_account_set_connection (account, conn_path);
326 empathy_account_properties_changed (TpAccount *proxy,
327 GHashTable *properties,
329 GObject *weak_object)
331 EmpathyAccount *account = EMPATHY_ACCOUNT (weak_object);
332 EmpathyAccountPriv *priv = GET_PRIV (account);
337 empathy_account_update (account, properties);
341 empathy_account_removed_cb (TpAccount *proxy,
343 GObject *weak_object)
345 EmpathyAccount *account = EMPATHY_ACCOUNT (weak_object);
346 EmpathyAccountPriv *priv = GET_PRIV (account);
351 priv->removed = TRUE;
353 g_signal_emit (account, signals[REMOVED], 0);
357 empathy_account_got_all_cb (TpProxy *proxy,
358 GHashTable *properties,
361 GObject *weak_object)
363 EmpathyAccount *account = EMPATHY_ACCOUNT (weak_object);
365 DEBUG ("Got whole set of properties for %s",
366 empathy_account_get_unique_name (account));
370 DEBUG ("Failed to get the initial set of account properties: %s",
375 empathy_account_update (account, properties);
379 empathy_account_unescape_protocol (const gchar *protocol, gssize len)
381 gchar *result, *escape;
382 /* Bad implementation might accidentally use tp_escape_as_identifier,
383 * which escapes - in the wrong way... */
384 if ((escape = g_strstr_len (protocol, len, "_2d")) != NULL)
389 str = g_string_new ("");
392 g_string_append_len (str, input, escape - input);
393 g_string_append_c (str, '-');
395 len -= escape - input + 3;
397 } while ((escape = g_strstr_len (input, len, "_2d")) != NULL);
399 g_string_append_len (str, input, len);
401 result = g_string_free (str, FALSE);
405 result = g_strndup (protocol, len);
408 g_strdelimit (result, "_", '-');
414 empathy_account_parse_unique_name (const gchar *bus_name,
415 gchar **protocol, gchar **manager)
417 const gchar *proto, *proto_end;
418 const gchar *cm, *cm_end;
420 g_return_val_if_fail (
421 g_str_has_prefix (bus_name, TP_ACCOUNT_OBJECT_PATH_BASE), FALSE);
423 cm = bus_name + strlen (TP_ACCOUNT_OBJECT_PATH_BASE);
425 for (cm_end = cm; *cm_end != '/' && *cm_end != '\0'; cm_end++)
436 for (proto_end = proto; *proto_end != '/' && *proto_end != '\0'; proto_end++)
439 if (*proto_end == '\0')
442 if (protocol != NULL)
444 *protocol = empathy_account_unescape_protocol (proto, proto_end - proto);
448 *manager = g_strndup (cm, cm_end - cm);
454 account_invalidated_cb (TpProxy *proxy, guint domain, gint code,
455 gchar *message, gpointer user_data)
457 EmpathyAccount *account = EMPATHY_ACCOUNT (user_data);
458 EmpathyAccountPriv *priv = GET_PRIV (account);
463 priv->removed = TRUE;
465 g_signal_emit (account, signals[REMOVED], 0);
469 empathy_account_constructed (GObject *object)
471 EmpathyAccount *account = EMPATHY_ACCOUNT (object);
472 EmpathyAccountPriv *priv = GET_PRIV (account);
474 priv->account = tp_account_new (priv->dbus, priv->unique_name, NULL);
476 g_signal_connect (priv->account, "invalidated",
477 G_CALLBACK (account_invalidated_cb), object);
479 empathy_account_parse_unique_name (priv->unique_name,
480 &(priv->proto_name), &(priv->cm_name));
482 priv->icon_name = empathy_protocol_icon_name (priv->proto_name);
484 tp_cli_account_connect_to_account_property_changed (priv->account,
485 empathy_account_properties_changed,
486 NULL, NULL, object, NULL);
488 tp_cli_account_connect_to_removed (priv->account,
489 empathy_account_removed_cb,
490 NULL, NULL, object, NULL);
492 empathy_account_refresh_properties (account);
495 static void empathy_account_dispose (GObject *object);
496 static void empathy_account_finalize (GObject *object);
499 empathy_account_class_init (EmpathyAccountClass *empathy_account_class)
501 GObjectClass *object_class = G_OBJECT_CLASS (empathy_account_class);
503 g_type_class_add_private (empathy_account_class,
504 sizeof (EmpathyAccountPriv));
506 object_class->set_property = empathy_account_set_property;
507 object_class->get_property = empathy_account_get_property;
508 object_class->dispose = empathy_account_dispose;
509 object_class->finalize = empathy_account_finalize;
510 object_class->constructed = empathy_account_constructed;
512 g_object_class_install_property (object_class, PROP_ENABLED,
513 g_param_spec_boolean ("enabled",
515 "Whether this account is enabled or not",
517 G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE));
519 g_object_class_install_property (object_class, PROP_READY,
520 g_param_spec_boolean ("ready",
522 "Whether this account is ready to be used",
524 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
526 g_object_class_install_property (object_class, PROP_PRESENCE,
527 g_param_spec_uint ("presence",
529 "The account connections presence type",
531 NUM_TP_CONNECTION_PRESENCE_TYPES,
532 TP_CONNECTION_PRESENCE_TYPE_UNSET,
533 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
535 g_object_class_install_property (object_class, PROP_STATUS,
536 g_param_spec_string ("status",
538 "The Status string of the account",
540 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
542 g_object_class_install_property (object_class, PROP_STATUS_MESSAGE,
543 g_param_spec_string ("status-message",
545 "The Status message string of the account",
547 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
549 g_object_class_install_property (object_class, PROP_CONNECTION_STATUS,
550 g_param_spec_uint ("connection-status",
552 "The accounts connections status type",
554 NUM_TP_CONNECTION_STATUSES,
555 TP_CONNECTION_STATUS_DISCONNECTED,
556 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
558 g_object_class_install_property (object_class, PROP_CONNECTION_STATUS_REASON,
559 g_param_spec_uint ("connection-status-reason",
560 "ConnectionStatusReason",
561 "The account connections status reason",
563 NUM_TP_CONNECTION_STATUS_REASONS,
564 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
565 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
567 g_object_class_install_property (object_class, PROP_CONNECTION,
568 g_param_spec_object ("connection",
570 "The accounts connection",
572 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
574 g_object_class_install_property (object_class, PROP_UNIQUE_NAME,
575 g_param_spec_string ("unique-name",
577 "The accounts unique name",
579 G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
581 g_object_class_install_property (object_class, PROP_DBUS_DAEMON,
582 g_param_spec_object ("dbus-daemon",
584 "The Tp Dbus daemon on which this account exists",
586 G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
588 g_object_class_install_property (object_class, PROP_DISPLAY_NAME,
589 g_param_spec_string ("display-name",
591 "The accounts display name",
593 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
595 signals[STATUS_CHANGED] = g_signal_new ("status-changed",
596 G_TYPE_FROM_CLASS (object_class),
599 _empathy_marshal_VOID__UINT_UINT_UINT,
600 G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT);
602 signals[PRESENCE_CHANGED] = g_signal_new ("presence-changed",
603 G_TYPE_FROM_CLASS (object_class),
606 _empathy_marshal_VOID__UINT_STRING_STRING,
607 G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING);
609 signals[REMOVED] = g_signal_new ("removed",
610 G_TYPE_FROM_CLASS (object_class),
613 g_cclosure_marshal_VOID__VOID,
618 empathy_account_free_connection (EmpathyAccount *account)
620 EmpathyAccountPriv *priv = GET_PRIV (account);
623 if (priv->connection == NULL)
626 conn = priv->connection;
627 priv->connection = NULL;
629 if (priv->connection_invalidated_id != 0)
630 g_signal_handler_disconnect (conn, priv->connection_invalidated_id);
631 priv->connection_invalidated_id = 0;
633 g_object_unref (conn);
637 empathy_account_dispose (GObject *object)
639 EmpathyAccount *self = EMPATHY_ACCOUNT (object);
640 EmpathyAccountPriv *priv = GET_PRIV (self);
642 if (priv->dispose_has_run)
645 priv->dispose_has_run = TRUE;
647 empathy_account_free_connection (self);
649 /* release any references held by the object here */
650 if (G_OBJECT_CLASS (empathy_account_parent_class)->dispose != NULL)
651 G_OBJECT_CLASS (empathy_account_parent_class)->dispose (object);
655 empathy_account_finalize (GObject *object)
657 EmpathyAccountPriv *priv = GET_PRIV (object);
659 g_free (priv->status);
660 g_free (priv->message);
662 g_free (priv->cm_name);
663 g_free (priv->proto_name);
664 g_free (priv->icon_name);
665 g_free (priv->display_name);
667 /* free any data held directly by the object here */
668 if (G_OBJECT_CLASS (empathy_account_parent_class)->finalize != NULL)
669 G_OBJECT_CLASS (empathy_account_parent_class)->finalize (object);
673 empathy_account_is_just_connected (EmpathyAccount *account)
675 EmpathyAccountPriv *priv = GET_PRIV (account);
678 if (priv->connection_status != TP_CONNECTION_STATUS_CONNECTED)
681 g_get_current_time (&val);
683 return (val.tv_sec - priv->connect_time) < 10;
687 * empathy_account_get_connection:
688 * @account: a #EmpathyAccount
690 * Get the connection of the account, or NULL if account is offline or the
691 * connection is not yet ready. This function does not return a new ref.
693 * Returns: the connection of the account.
696 empathy_account_get_connection (EmpathyAccount *account)
698 EmpathyAccountPriv *priv = GET_PRIV (account);
700 if (priv->connection != NULL &&
701 tp_connection_is_ready (priv->connection))
702 return priv->connection;
708 * empathy_account_get_connection_for_path:
709 * @account: a #EmpathyAccount
710 * @patch: the path to connection object for #EmpathyAccount
712 * Get the connection of the account on path. This function does not return a
713 * new ref. It is not guaranteed that the returned connection object is ready
715 * Returns: the connection of the account.
718 empathy_account_get_connection_for_path (EmpathyAccount *account,
721 EmpathyAccountPriv *priv = GET_PRIV (account);
723 /* double-check that the object path is valid */
724 if (!tp_dbus_check_valid_object_path (path, NULL))
727 /* Should be a full object path, not the special "/" value */
728 if (strlen (path) == 1)
731 _empathy_account_set_connection (account, path);
733 return priv->connection;
737 * empathy_account_get_unique_name:
738 * @account: a #EmpathyAccount
740 * Returns: the unique name of the account.
743 empathy_account_get_unique_name (EmpathyAccount *account)
745 EmpathyAccountPriv *priv = GET_PRIV (account);
747 return priv->unique_name;
751 * empathy_account_get_display_name:
752 * @account: a #EmpathyAccount
754 * Returns: the display name of the account.
757 empathy_account_get_display_name (EmpathyAccount *account)
759 EmpathyAccountPriv *priv = GET_PRIV (account);
761 return priv->display_name;
765 empathy_account_is_valid (EmpathyAccount *account)
767 EmpathyAccountPriv *priv = GET_PRIV (account);
773 empathy_account_get_connection_manager (EmpathyAccount *account)
775 EmpathyAccountPriv *priv = GET_PRIV (account);
777 return priv->cm_name;
781 empathy_account_get_protocol (EmpathyAccount *account)
783 EmpathyAccountPriv *priv = GET_PRIV (account);
785 return priv->proto_name;
789 empathy_account_get_icon_name (EmpathyAccount *account)
791 EmpathyAccountPriv *priv = GET_PRIV (account);
793 return priv->icon_name;
797 empathy_account_get_parameters (EmpathyAccount *account)
799 EmpathyAccountPriv *priv = GET_PRIV (account);
801 return priv->parameters;
805 empathy_account_is_enabled (EmpathyAccount *account)
807 EmpathyAccountPriv *priv = GET_PRIV (account);
809 return priv->enabled;
813 empathy_account_is_ready (EmpathyAccount *account)
815 EmpathyAccountPriv *priv = GET_PRIV (account);
822 empathy_account_new (TpDBusDaemon *dbus,
823 const gchar *unique_name)
825 return EMPATHY_ACCOUNT (g_object_new (EMPATHY_TYPE_ACCOUNT,
827 "unique-name", unique_name,
832 empathy_account_connection_ready_cb (TpConnection *connection,
836 EmpathyAccount *account = EMPATHY_ACCOUNT (user_data);
840 DEBUG ("(%s) Connection failed to become ready: %s",
841 empathy_account_get_unique_name (account), error->message);
842 empathy_account_free_connection (account);
846 DEBUG ("(%s) Connection ready",
847 empathy_account_get_unique_name (account));
848 g_object_notify (G_OBJECT (account), "connection");
853 _empathy_account_connection_invalidated_cb (TpProxy *self,
859 EmpathyAccount *account = EMPATHY_ACCOUNT (user_data);
860 EmpathyAccountPriv *priv = GET_PRIV (account);
862 if (priv->connection == NULL)
865 DEBUG ("(%s) Connection invalidated",
866 empathy_account_get_unique_name (account));
868 g_assert (priv->connection == TP_CONNECTION (self));
870 empathy_account_free_connection (account);
872 g_object_notify (G_OBJECT (account), "connection");
876 _empathy_account_set_connection (EmpathyAccount *account,
879 EmpathyAccountPriv *priv = GET_PRIV (account);
881 if (priv->connection != NULL)
883 const gchar *current;
885 current = tp_proxy_get_object_path (priv->connection);
886 if (!tp_strdiff (current, path))
890 empathy_account_free_connection (account);
892 if (tp_strdiff ("/", path))
894 GError *error = NULL;
895 priv->connection = tp_connection_new (priv->dbus, NULL, path, &error);
897 if (priv->connection == NULL)
899 DEBUG ("Failed to create a new TpConnection: %s",
901 g_error_free (error);
905 priv->connection_invalidated_id = g_signal_connect (priv->connection,
907 G_CALLBACK (_empathy_account_connection_invalidated_cb), account);
909 DEBUG ("Readying connection for %s", priv->unique_name);
910 /* notify a change in the connection property when it's ready */
911 tp_connection_call_when_ready (priv->connection,
912 empathy_account_connection_ready_cb, account);
916 g_object_notify (G_OBJECT (account), "connection");
920 account_enabled_set_cb (TpProxy *proxy,
923 GObject *weak_object)
925 GSimpleAsyncResult *result = user_data;
928 g_simple_async_result_set_from_error (result, (GError *) error);
930 g_simple_async_result_complete (result);
931 g_object_unref (result);
935 empathy_account_set_enabled_finish (EmpathyAccount *account,
936 GAsyncResult *result,
939 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
941 !g_simple_async_result_is_valid (result, G_OBJECT (account),
942 empathy_account_set_enabled_finish))
949 empathy_account_set_enabled_async (EmpathyAccount *account,
951 GAsyncReadyCallback callback,
954 EmpathyAccountPriv *priv = GET_PRIV (account);
955 EmpathyAccountManager *acc_manager;
956 GValue value = {0, };
957 GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (account),
958 callback, user_data, empathy_account_set_enabled_finish);
960 char *status_message = NULL;
961 TpConnectionPresenceType presence;
963 if (priv->enabled == enabled)
965 g_simple_async_result_complete_in_idle (result);
971 acc_manager = empathy_account_manager_dup_singleton ();
972 presence = empathy_account_manager_get_requested_global_presence
973 (acc_manager, &status, &status_message);
975 if (presence != TP_CONNECTION_PRESENCE_TYPE_UNSET)
976 empathy_account_request_presence (account, presence, status,
979 g_object_unref (acc_manager);
981 g_free (status_message);
984 g_value_init (&value, G_TYPE_BOOLEAN);
985 g_value_set_boolean (&value, enabled);
987 tp_cli_dbus_properties_call_set (TP_PROXY (priv->account),
988 -1, TP_IFACE_ACCOUNT, "Enabled", &value,
989 account_enabled_set_cb, result, NULL, G_OBJECT (account));
993 account_reconnected_cb (TpAccount *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_reconnect_finish (EmpathyAccount *account,
1009 GAsyncResult *result,
1012 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
1014 !g_simple_async_result_is_valid (result, G_OBJECT (account),
1015 empathy_account_reconnect_finish))
1022 empathy_account_reconnect_async (EmpathyAccount *account,
1023 GAsyncReadyCallback callback,
1026 EmpathyAccountPriv *priv = GET_PRIV (account);
1028 GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (account),
1029 callback, user_data, empathy_account_reconnect_finish);
1031 tp_cli_account_call_reconnect (priv->account,
1032 -1, account_reconnected_cb, result, NULL, G_OBJECT (account));
1036 empathy_account_requested_presence_cb (TpProxy *proxy,
1037 const GError *error,
1039 GObject *weak_object)
1042 DEBUG ("Failed to set the requested presence: %s", error->message);
1047 empathy_account_request_presence (EmpathyAccount *account,
1048 TpConnectionPresenceType type,
1049 const gchar *status,
1050 const gchar *message)
1052 EmpathyAccountPriv *priv = GET_PRIV (account);
1053 GValue value = {0, };
1056 g_value_init (&value, TP_STRUCT_TYPE_SIMPLE_PRESENCE);
1057 g_value_take_boxed (&value, dbus_g_type_specialized_construct
1058 (TP_STRUCT_TYPE_SIMPLE_PRESENCE));
1059 arr = (GValueArray *) g_value_get_boxed (&value);
1061 g_value_set_uint (arr->values, type);
1062 g_value_set_static_string (arr->values + 1, status);
1063 g_value_set_static_string (arr->values + 2, message);
1065 tp_cli_dbus_properties_call_set (TP_PROXY (priv->account),
1068 "RequestedPresence",
1070 empathy_account_requested_presence_cb,
1073 G_OBJECT (account));
1075 g_value_unset (&value);
1079 empathy_account_updated_cb (TpAccount *proxy,
1080 const gchar **reconnect_required,
1081 const GError *error,
1083 GObject *weak_object)
1085 GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data);
1089 g_simple_async_result_set_from_error (result, (GError *) error);
1092 g_simple_async_result_complete (result);
1093 g_object_unref (G_OBJECT (result));
1097 empathy_account_update_settings_async (EmpathyAccount *account,
1098 GHashTable *parameters, const gchar **unset_parameters,
1099 GAsyncReadyCallback callback, gpointer user_data)
1101 EmpathyAccountPriv *priv = GET_PRIV (account);
1102 GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (account),
1103 callback, user_data, empathy_account_update_settings_finish);
1105 tp_cli_account_call_update_parameters (priv->account,
1109 empathy_account_updated_cb,
1112 G_OBJECT (account));
1116 empathy_account_update_settings_finish (EmpathyAccount *account,
1117 GAsyncResult *result, GError **error)
1119 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
1123 g_return_val_if_fail (g_simple_async_result_is_valid (result,
1124 G_OBJECT (account), empathy_account_update_settings_finish), FALSE);
1130 account_display_name_set_cb (TpProxy *proxy,
1131 const GError *error,
1133 GObject *weak_object)
1135 GSimpleAsyncResult *result = user_data;
1138 g_simple_async_result_set_from_error (result, (GError *) error);
1140 g_simple_async_result_complete (result);
1141 g_object_unref (result);
1145 empathy_account_set_display_name_async (EmpathyAccount *account,
1146 const char *display_name,
1147 GAsyncReadyCallback callback,
1150 GSimpleAsyncResult *result;
1151 GValue value = {0, };
1152 EmpathyAccountPriv *priv = GET_PRIV (account);
1154 if (display_name == NULL)
1156 g_simple_async_report_error_in_idle (G_OBJECT (account),
1157 callback, user_data, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
1158 _("Can't set an empty display name"));
1162 result = g_simple_async_result_new (G_OBJECT (account), callback,
1163 user_data, empathy_account_set_display_name_finish);
1165 g_value_init (&value, G_TYPE_STRING);
1166 g_value_set_string (&value, display_name);
1168 tp_cli_dbus_properties_call_set (priv->account, -1, TP_IFACE_ACCOUNT,
1169 "DisplayName", &value, account_display_name_set_cb, result, NULL,
1170 G_OBJECT (account));
1174 empathy_account_set_display_name_finish (EmpathyAccount *account,
1175 GAsyncResult *result, GError **error)
1177 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
1179 !g_simple_async_result_is_valid (result, G_OBJECT (account),
1180 empathy_account_set_display_name_finish))
1187 account_icon_name_set_cb (TpProxy *proxy,
1188 const GError *error,
1190 GObject *weak_object)
1192 GSimpleAsyncResult *result = user_data;
1195 g_simple_async_result_set_from_error (result, (GError *) error);
1197 g_simple_async_result_complete (result);
1198 g_object_unref (result);
1202 empathy_account_set_icon_name_async (EmpathyAccount *account,
1203 const char *icon_name,
1204 GAsyncReadyCallback callback,
1207 GSimpleAsyncResult *result;
1208 GValue value = {0, };
1209 EmpathyAccountPriv *priv = GET_PRIV (account);
1210 const char *icon_name_set;
1212 if (icon_name == NULL)
1213 /* settings an empty icon name is allowed */
1216 icon_name_set = icon_name;
1218 result = g_simple_async_result_new (G_OBJECT (account), callback,
1219 user_data, empathy_account_set_icon_name_finish);
1221 g_value_init (&value, G_TYPE_STRING);
1222 g_value_set_string (&value, icon_name_set);
1224 tp_cli_dbus_properties_call_set (priv->account, -1, TP_IFACE_ACCOUNT,
1225 "Icon", &value, account_icon_name_set_cb, result, NULL,
1226 G_OBJECT (account));
1230 empathy_account_set_icon_name_finish (EmpathyAccount *account,
1231 GAsyncResult *result, GError **error)
1233 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
1235 !g_simple_async_result_is_valid (result, G_OBJECT (account),
1236 empathy_account_set_icon_name_finish))
1243 empathy_account_remove_cb (TpAccount *proxy,
1244 const GError *error,
1246 GObject *weak_object)
1248 GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data);
1252 g_simple_async_result_set_from_error (result, (GError *) error);
1255 g_simple_async_result_complete (result);
1256 g_object_unref (G_OBJECT (result));
1260 empathy_account_remove_async (EmpathyAccount *account,
1261 GAsyncReadyCallback callback, gpointer user_data)
1263 EmpathyAccountPriv *priv = GET_PRIV (account);
1264 GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (account),
1265 callback, user_data, empathy_account_remove_finish);
1267 tp_cli_account_call_remove (priv->account,
1269 empathy_account_remove_cb,
1272 G_OBJECT (account));
1276 empathy_account_remove_finish (EmpathyAccount *account,
1277 GAsyncResult *result, GError **error)
1279 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
1283 g_return_val_if_fail (g_simple_async_result_is_valid (result,
1284 G_OBJECT (account), empathy_account_update_settings_finish), FALSE);
1290 empathy_account_refresh_properties (EmpathyAccount *account)
1292 EmpathyAccountPriv *priv;
1294 g_return_if_fail (EMPATHY_IS_ACCOUNT (account));
1296 priv = GET_PRIV (account);
1298 tp_cli_dbus_properties_call_get_all (priv->account, -1,
1300 empathy_account_got_all_cb,
1303 G_OBJECT (account));