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, "Enabled") != NULL)
245 gboolean enabled = tp_asv_get_boolean (properties, "Enabled", NULL);
246 if (priv->enabled != enabled)
248 priv->enabled = enabled;
249 g_object_notify (G_OBJECT (account), "enabled");
253 if (g_hash_table_lookup (properties, "Valid") != NULL)
254 priv->valid = tp_asv_get_boolean (properties, "Valid", NULL);
256 if (g_hash_table_lookup (properties, "Parameters") != NULL)
258 GHashTable *parameters;
260 parameters = tp_asv_get_boxed (properties, "Parameters",
261 TP_HASH_TYPE_STRING_VARIANT_MAP);
263 if (priv->parameters != NULL)
264 g_hash_table_unref (priv->parameters);
266 priv->parameters = g_boxed_copy (TP_HASH_TYPE_STRING_VARIANT_MAP,
273 g_object_notify (G_OBJECT (account), "ready");
276 if (priv->connection_status != old_s)
278 if (priv->connection_status == TP_CONNECTION_STATUS_CONNECTED)
281 g_get_current_time (&val);
283 priv->connect_time = val.tv_sec;
286 g_signal_emit (account, signals[STATUS_CHANGED], 0,
287 old_s, priv->connection_status, priv->reason);
289 g_object_notify (G_OBJECT (account), "connection-status");
290 g_object_notify (G_OBJECT (account), "connection-status-reason");
293 if (presence_changed)
295 g_signal_emit (account, signals[PRESENCE_CHANGED], 0,
296 priv->presence, priv->status, priv->message);
297 g_object_notify (G_OBJECT (account), "presence");
298 g_object_notify (G_OBJECT (account), "status");
299 g_object_notify (G_OBJECT (account), "status-message");
302 if (g_hash_table_lookup (properties, "Connection") != NULL)
304 const gchar *conn_path =
305 tp_asv_get_object_path (properties, "Connection");
307 _empathy_account_set_connection (account, conn_path);
312 empathy_account_properties_changed (TpAccount *proxy,
313 GHashTable *properties,
315 GObject *weak_object)
317 EmpathyAccount *account = EMPATHY_ACCOUNT (weak_object);
318 EmpathyAccountPriv *priv = GET_PRIV (account);
323 empathy_account_update (account, properties);
327 empathy_account_removed_cb (TpAccount *proxy,
329 GObject *weak_object)
331 EmpathyAccount *account = EMPATHY_ACCOUNT (weak_object);
332 EmpathyAccountPriv *priv = GET_PRIV (account);
337 priv->removed = TRUE;
339 g_signal_emit (account, signals[REMOVED], 0);
343 empathy_account_got_all_cb (TpProxy *proxy,
344 GHashTable *properties,
347 GObject *weak_object)
349 EmpathyAccount *account = EMPATHY_ACCOUNT (weak_object);
351 DEBUG ("Got whole set of properties for %s",
352 empathy_account_get_unique_name (account));
356 DEBUG ("Failed to get the initial set of account properties: %s",
361 empathy_account_update (account, properties);
365 empathy_account_unescape_protocol (const gchar *protocol, gssize len)
367 gchar *result, *escape;
368 /* Bad implementation might accidentally use tp_escape_as_identifier,
369 * which escapes - in the wrong way... */
370 if ((escape = g_strstr_len (protocol, len, "_2d")) != NULL)
375 str = g_string_new ("");
378 g_string_append_len (str, input, escape - input);
379 g_string_append_c (str, '-');
381 len -= escape - input + 3;
383 } while ((escape = g_strstr_len (input, len, "_2d")) != NULL);
385 g_string_append_len (str, input, len);
387 result = g_string_free (str, FALSE);
391 result = g_strndup (protocol, len);
394 g_strdelimit (result, "_", '-');
400 empathy_account_parse_unique_name (const gchar *bus_name,
401 gchar **protocol, gchar **manager)
403 const gchar *proto, *proto_end;
404 const gchar *cm, *cm_end;
406 g_return_val_if_fail (
407 g_str_has_prefix (bus_name, TP_ACCOUNT_OBJECT_PATH_BASE), FALSE);
409 cm = bus_name + strlen (TP_ACCOUNT_OBJECT_PATH_BASE);
411 for (cm_end = cm; *cm_end != '/' && *cm_end != '\0'; cm_end++)
422 for (proto_end = proto; *proto_end != '/' && *proto_end != '\0'; proto_end++)
425 if (*proto_end == '\0')
428 if (protocol != NULL)
430 *protocol = empathy_account_unescape_protocol (proto, proto_end - proto);
434 *manager = g_strndup (cm, cm_end - cm);
440 account_invalidated_cb (TpProxy *proxy, guint domain, gint code,
441 gchar *message, gpointer user_data)
443 EmpathyAccount *account = EMPATHY_ACCOUNT (user_data);
444 EmpathyAccountPriv *priv = GET_PRIV (account);
449 priv->removed = TRUE;
451 g_signal_emit (account, signals[REMOVED], 0);
455 empathy_account_constructed (GObject *object)
457 EmpathyAccount *account = EMPATHY_ACCOUNT (object);
458 EmpathyAccountPriv *priv = GET_PRIV (account);
460 priv->account = tp_account_new (priv->dbus, priv->unique_name, NULL);
462 g_signal_connect (priv->account, "invalidated",
463 G_CALLBACK (account_invalidated_cb), object);
465 empathy_account_parse_unique_name (priv->unique_name,
466 &(priv->proto_name), &(priv->cm_name));
468 priv->icon_name = empathy_protocol_icon_name (priv->proto_name);
470 tp_cli_account_connect_to_account_property_changed (priv->account,
471 empathy_account_properties_changed,
472 NULL, NULL, object, NULL);
474 tp_cli_account_connect_to_removed (priv->account,
475 empathy_account_removed_cb,
476 NULL, NULL, object, NULL);
478 empathy_account_refresh_properties (account);
481 static void empathy_account_dispose (GObject *object);
482 static void empathy_account_finalize (GObject *object);
485 empathy_account_class_init (EmpathyAccountClass *empathy_account_class)
487 GObjectClass *object_class = G_OBJECT_CLASS (empathy_account_class);
489 g_type_class_add_private (empathy_account_class,
490 sizeof (EmpathyAccountPriv));
492 object_class->set_property = empathy_account_set_property;
493 object_class->get_property = empathy_account_get_property;
494 object_class->dispose = empathy_account_dispose;
495 object_class->finalize = empathy_account_finalize;
496 object_class->constructed = empathy_account_constructed;
498 g_object_class_install_property (object_class, PROP_ENABLED,
499 g_param_spec_boolean ("enabled",
501 "Whether this account is enabled or not",
503 G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE));
505 g_object_class_install_property (object_class, PROP_READY,
506 g_param_spec_boolean ("ready",
508 "Whether this account is ready to be used",
510 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
512 g_object_class_install_property (object_class, PROP_PRESENCE,
513 g_param_spec_uint ("presence",
515 "The account connections presence type",
517 NUM_TP_CONNECTION_PRESENCE_TYPES,
518 TP_CONNECTION_PRESENCE_TYPE_UNSET,
519 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
521 g_object_class_install_property (object_class, PROP_STATUS,
522 g_param_spec_string ("status",
524 "The Status string of the account",
526 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
528 g_object_class_install_property (object_class, PROP_STATUS_MESSAGE,
529 g_param_spec_string ("status-message",
531 "The Status message string of the account",
533 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
535 g_object_class_install_property (object_class, PROP_CONNECTION_STATUS,
536 g_param_spec_uint ("connection-status",
538 "The accounts connections status type",
540 NUM_TP_CONNECTION_STATUSES,
541 TP_CONNECTION_STATUS_DISCONNECTED,
542 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
544 g_object_class_install_property (object_class, PROP_CONNECTION_STATUS_REASON,
545 g_param_spec_uint ("connection-status-reason",
546 "ConnectionStatusReason",
547 "The account connections status reason",
549 NUM_TP_CONNECTION_STATUS_REASONS,
550 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
551 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
553 g_object_class_install_property (object_class, PROP_CONNECTION,
554 g_param_spec_object ("connection",
556 "The accounts connection",
558 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
560 g_object_class_install_property (object_class, PROP_UNIQUE_NAME,
561 g_param_spec_string ("unique-name",
563 "The accounts unique name",
565 G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
567 g_object_class_install_property (object_class, PROP_DBUS_DAEMON,
568 g_param_spec_object ("dbus-daemon",
570 "The Tp Dbus daemon on which this account exists",
572 G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
574 g_object_class_install_property (object_class, PROP_DISPLAY_NAME,
575 g_param_spec_string ("display-name",
577 "The accounts display name",
579 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
581 signals[STATUS_CHANGED] = g_signal_new ("status-changed",
582 G_TYPE_FROM_CLASS (object_class),
585 _empathy_marshal_VOID__UINT_UINT_UINT,
586 G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT);
588 signals[PRESENCE_CHANGED] = g_signal_new ("presence-changed",
589 G_TYPE_FROM_CLASS (object_class),
592 _empathy_marshal_VOID__UINT_STRING_STRING,
593 G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING);
595 signals[REMOVED] = g_signal_new ("removed",
596 G_TYPE_FROM_CLASS (object_class),
599 g_cclosure_marshal_VOID__VOID,
604 empathy_account_free_connection (EmpathyAccount *account)
606 EmpathyAccountPriv *priv = GET_PRIV (account);
609 if (priv->connection == NULL)
612 conn = priv->connection;
613 priv->connection = NULL;
615 if (priv->connection_invalidated_id != 0)
616 g_signal_handler_disconnect (conn, priv->connection_invalidated_id);
617 priv->connection_invalidated_id = 0;
619 g_object_unref (conn);
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 empathy_account_free_connection (account);
858 g_object_notify (G_OBJECT (account), "connection");
862 _empathy_account_set_connection (EmpathyAccount *account,
865 EmpathyAccountPriv *priv = GET_PRIV (account);
867 if (priv->connection != NULL)
869 const gchar *current;
871 current = tp_proxy_get_object_path (priv->connection);
872 if (!tp_strdiff (current, path))
876 empathy_account_free_connection (account);
878 if (tp_strdiff ("/", path))
880 GError *error = NULL;
881 priv->connection = tp_connection_new (priv->dbus, NULL, path, &error);
883 if (priv->connection == NULL)
885 DEBUG ("Failed to create a new TpConnection: %s",
887 g_error_free (error);
891 priv->connection_invalidated_id = g_signal_connect (priv->connection,
893 G_CALLBACK (_empathy_account_connection_invalidated_cb), account);
895 DEBUG ("Readying connection for %s", priv->unique_name);
896 /* notify a change in the connection property when it's ready */
897 tp_connection_call_when_ready (priv->connection,
898 empathy_account_connection_ready_cb, account);
902 g_object_notify (G_OBJECT (account), "connection");
906 account_enabled_set_cb (TpProxy *proxy,
909 GObject *weak_object)
911 GSimpleAsyncResult *result = user_data;
914 g_simple_async_result_set_from_error (result, (GError *) error);
916 g_simple_async_result_complete (result);
917 g_object_unref (result);
921 empathy_account_set_enabled_finish (EmpathyAccount *account,
922 GAsyncResult *result,
925 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
927 !g_simple_async_result_is_valid (result, G_OBJECT (account),
928 empathy_account_set_enabled_finish))
935 empathy_account_set_enabled_async (EmpathyAccount *account,
937 GAsyncReadyCallback callback,
940 EmpathyAccountPriv *priv = GET_PRIV (account);
941 EmpathyAccountManager *acc_manager;
942 GValue value = {0, };
943 GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (account),
944 callback, user_data, empathy_account_set_enabled_finish);
946 char *status_message = NULL;
947 TpConnectionPresenceType presence;
949 if (priv->enabled == enabled)
951 g_simple_async_result_complete_in_idle (result);
957 acc_manager = empathy_account_manager_dup_singleton ();
958 presence = empathy_account_manager_get_requested_global_presence
959 (acc_manager, &status, &status_message);
961 if (presence != TP_CONNECTION_PRESENCE_TYPE_UNSET)
962 empathy_account_request_presence (account, presence, status,
965 g_object_unref (acc_manager);
967 g_free (status_message);
970 g_value_init (&value, G_TYPE_BOOLEAN);
971 g_value_set_boolean (&value, enabled);
973 tp_cli_dbus_properties_call_set (TP_PROXY (priv->account),
974 -1, TP_IFACE_ACCOUNT, "Enabled", &value,
975 account_enabled_set_cb, result, NULL, G_OBJECT (account));
979 account_reconnected_cb (TpAccount *proxy,
982 GObject *weak_object)
984 GSimpleAsyncResult *result = user_data;
987 g_simple_async_result_set_from_error (result, (GError *) error);
989 g_simple_async_result_complete (result);
990 g_object_unref (result);
994 empathy_account_reconnect_finish (EmpathyAccount *account,
995 GAsyncResult *result,
998 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
1000 !g_simple_async_result_is_valid (result, G_OBJECT (account),
1001 empathy_account_reconnect_finish))
1008 empathy_account_reconnect_async (EmpathyAccount *account,
1009 GAsyncReadyCallback callback,
1012 EmpathyAccountPriv *priv = GET_PRIV (account);
1014 GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (account),
1015 callback, user_data, empathy_account_reconnect_finish);
1017 tp_cli_account_call_reconnect (priv->account,
1018 -1, account_reconnected_cb, result, NULL, G_OBJECT (account));
1022 empathy_account_requested_presence_cb (TpProxy *proxy,
1023 const GError *error,
1025 GObject *weak_object)
1028 DEBUG ("Failed to set the requested presence: %s", error->message);
1033 empathy_account_request_presence (EmpathyAccount *account,
1034 TpConnectionPresenceType type,
1035 const gchar *status,
1036 const gchar *message)
1038 EmpathyAccountPriv *priv = GET_PRIV (account);
1039 GValue value = {0, };
1042 g_value_init (&value, TP_STRUCT_TYPE_SIMPLE_PRESENCE);
1043 g_value_take_boxed (&value, dbus_g_type_specialized_construct
1044 (TP_STRUCT_TYPE_SIMPLE_PRESENCE));
1045 arr = (GValueArray *) g_value_get_boxed (&value);
1047 g_value_set_uint (arr->values, type);
1048 g_value_set_static_string (arr->values + 1, status);
1049 g_value_set_static_string (arr->values + 2, message);
1051 tp_cli_dbus_properties_call_set (TP_PROXY (priv->account),
1054 "RequestedPresence",
1056 empathy_account_requested_presence_cb,
1059 G_OBJECT (account));
1061 g_value_unset (&value);
1065 empathy_account_updated_cb (TpAccount *proxy,
1066 const gchar **reconnect_required,
1067 const GError *error,
1069 GObject *weak_object)
1071 GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data);
1075 g_simple_async_result_set_from_error (result, (GError *) error);
1078 g_simple_async_result_complete (result);
1079 g_object_unref (G_OBJECT (result));
1083 empathy_account_update_settings_async (EmpathyAccount *account,
1084 GHashTable *parameters, const gchar **unset_parameters,
1085 GAsyncReadyCallback callback, gpointer user_data)
1087 EmpathyAccountPriv *priv = GET_PRIV (account);
1088 GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (account),
1089 callback, user_data, empathy_account_update_settings_finish);
1091 tp_cli_account_call_update_parameters (priv->account,
1095 empathy_account_updated_cb,
1098 G_OBJECT (account));
1102 empathy_account_update_settings_finish (EmpathyAccount *account,
1103 GAsyncResult *result, GError **error)
1105 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
1109 g_return_val_if_fail (g_simple_async_result_is_valid (result,
1110 G_OBJECT (account), empathy_account_update_settings_finish), FALSE);
1116 account_display_name_set_cb (TpProxy *proxy,
1117 const GError *error,
1119 GObject *weak_object)
1121 GSimpleAsyncResult *result = user_data;
1124 g_simple_async_result_set_from_error (result, (GError *) error);
1126 g_simple_async_result_complete (result);
1127 g_object_unref (result);
1131 empathy_account_set_display_name_async (EmpathyAccount *account,
1132 const char *display_name,
1133 GAsyncReadyCallback callback,
1136 GSimpleAsyncResult *result;
1137 GValue value = {0, };
1138 EmpathyAccountPriv *priv = GET_PRIV (account);
1140 if (display_name == NULL)
1142 g_simple_async_report_error_in_idle (G_OBJECT (account),
1143 callback, user_data, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
1144 _("Can't set an empty display name"));
1148 result = g_simple_async_result_new (G_OBJECT (account), callback,
1149 user_data, empathy_account_set_display_name_finish);
1151 g_value_init (&value, G_TYPE_STRING);
1152 g_value_set_string (&value, display_name);
1154 tp_cli_dbus_properties_call_set (priv->account, -1, TP_IFACE_ACCOUNT,
1155 "DisplayName", &value, account_display_name_set_cb, result, NULL,
1156 G_OBJECT (account));
1160 empathy_account_set_display_name_finish (EmpathyAccount *account,
1161 GAsyncResult *result, GError **error)
1163 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
1165 !g_simple_async_result_is_valid (result, G_OBJECT (account),
1166 empathy_account_set_display_name_finish))
1173 empathy_account_remove_cb (TpAccount *proxy,
1174 const GError *error,
1176 GObject *weak_object)
1178 GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data);
1182 g_simple_async_result_set_from_error (result, (GError *) error);
1185 g_simple_async_result_complete (result);
1186 g_object_unref (G_OBJECT (result));
1190 empathy_account_remove_async (EmpathyAccount *account,
1191 GAsyncReadyCallback callback, gpointer user_data)
1193 EmpathyAccountPriv *priv = GET_PRIV (account);
1194 GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (account),
1195 callback, user_data, empathy_account_remove_finish);
1197 tp_cli_account_call_remove (priv->account,
1199 empathy_account_remove_cb,
1202 G_OBJECT (account));
1206 empathy_account_remove_finish (EmpathyAccount *account,
1207 GAsyncResult *result, GError **error)
1209 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
1213 g_return_val_if_fail (g_simple_async_result_is_valid (result,
1214 G_OBJECT (account), empathy_account_update_settings_finish), FALSE);
1220 empathy_account_refresh_properties (EmpathyAccount *account)
1222 EmpathyAccountPriv *priv;
1224 g_return_if_fail (EMPATHY_IS_ACCOUNT (account));
1226 priv = GET_PRIV (account);
1228 tp_cli_dbus_properties_call_get_all (priv->account, -1,
1230 empathy_account_got_all_cb,
1233 G_OBJECT (account));