1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
3 * Copyright (C) 2007-2009 Collabora Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Authors: Xavier Claessens <xclaesse@gmail.com>
26 #include <glib/gi18n-lib.h>
28 #include <telepathy-glib/account-manager.h>
29 #include <telepathy-glib/util.h>
31 #include <telepathy-logger/contact.h>
32 #endif /* ENABLE_TPL */
34 #include "empathy-contact.h"
35 #include "empathy-utils.h"
36 #include "empathy-enum-types.h"
37 #include "empathy-marshal.h"
39 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
40 #include "empathy-debug.h"
42 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyContact)
44 TpContact *tp_contact;
48 EmpathyAvatar *avatar;
49 TpConnectionPresenceType presence;
50 gchar *presence_message;
52 EmpathyCapabilities capabilities;
55 /* Location is composed of string keys and GValues.
56 * Example: a "city" key would have "Helsinki" as string GValue,
57 * a "latitude" would have 65.0 as double GValue.
62 static void contact_finalize (GObject *object);
63 static void contact_get_property (GObject *object, guint param_id,
64 GValue *value, GParamSpec *pspec);
65 static void contact_set_property (GObject *object, guint param_id,
66 const GValue *value, GParamSpec *pspec);
68 G_DEFINE_TYPE (EmpathyContact, empathy_contact, G_TYPE_OBJECT);
79 PROP_PRESENCE_MESSAGE,
91 static guint signals[LAST_SIGNAL];
94 tp_contact_notify_cb (TpContact *tp_contact,
98 EmpathyContactPriv *priv = GET_PRIV (contact);
100 /* Forward property notifications */
101 if (!tp_strdiff (param->name, "alias"))
102 g_object_notify (contact, "name");
103 else if (!tp_strdiff (param->name, "presence-type")) {
104 TpConnectionPresenceType presence;
106 presence = empathy_contact_get_presence (EMPATHY_CONTACT (contact));
107 g_signal_emit (contact, signals[PRESENCE_CHANGED], 0, presence,
109 priv->presence = presence;
110 g_object_notify (contact, "presence");
112 else if (!tp_strdiff (param->name, "presence-message"))
113 g_object_notify (contact, "presence-message");
114 else if (!tp_strdiff (param->name, "identifier"))
115 g_object_notify (contact, "id");
116 else if (!tp_strdiff (param->name, "handle"))
117 g_object_notify (contact, "handle");
121 contact_dispose (GObject *object)
123 EmpathyContactPriv *priv = GET_PRIV (object);
125 if (priv->tp_contact)
127 g_signal_handlers_disconnect_by_func (priv->tp_contact,
128 tp_contact_notify_cb, object);
129 g_object_unref (priv->tp_contact);
131 priv->tp_contact = NULL;
134 g_object_unref (priv->account);
135 priv->account = NULL;
137 G_OBJECT_CLASS (empathy_contact_parent_class)->dispose (object);
141 empathy_contact_class_init (EmpathyContactClass *class)
143 GObjectClass *object_class;
145 object_class = G_OBJECT_CLASS (class);
147 object_class->finalize = contact_finalize;
148 object_class->dispose = contact_dispose;
149 object_class->get_property = contact_get_property;
150 object_class->set_property = contact_set_property;
152 g_object_class_install_property (object_class,
154 g_param_spec_object ("tp-contact",
156 "The TpContact associated with the contact",
158 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
160 g_object_class_install_property (object_class,
162 g_param_spec_object ("account",
164 "The account associated with the contact",
166 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
168 g_object_class_install_property (object_class,
170 g_param_spec_string ("id",
172 "String identifying contact",
174 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
176 g_object_class_install_property (object_class,
178 g_param_spec_string ("name",
180 "The name of the contact",
182 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
184 g_object_class_install_property (object_class,
186 g_param_spec_boxed ("avatar",
190 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
192 g_object_class_install_property (object_class,
194 g_param_spec_uint ("presence",
196 "Presence of contact",
197 TP_CONNECTION_PRESENCE_TYPE_UNSET,
198 NUM_TP_CONNECTION_PRESENCE_TYPES,
199 TP_CONNECTION_PRESENCE_TYPE_UNSET,
200 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
202 g_object_class_install_property (object_class,
203 PROP_PRESENCE_MESSAGE,
204 g_param_spec_string ("presence-message",
205 "Contact presence message",
206 "Presence message of contact",
208 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
210 g_object_class_install_property (object_class,
212 g_param_spec_uint ("handle",
214 "The handle of the contact",
218 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
220 g_object_class_install_property (object_class,
222 g_param_spec_flags ("capabilities",
223 "Contact Capabilities",
224 "Capabilities of the contact",
225 EMPATHY_TYPE_CAPABILITIES,
226 EMPATHY_CAPABILITIES_UNKNOWN,
227 G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
229 g_object_class_install_property (object_class,
231 g_param_spec_boolean ("is-user",
233 "Is contact the user",
235 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
238 g_object_class_install_property (object_class,
240 g_param_spec_boxed ("location",
242 "Physical location of the contact",
244 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
246 signals[PRESENCE_CHANGED] =
247 g_signal_new ("presence-changed",
248 G_TYPE_FROM_CLASS (class),
252 _empathy_marshal_VOID__UINT_UINT,
257 g_type_class_add_private (object_class, sizeof (EmpathyContactPriv));
261 empathy_contact_init (EmpathyContact *contact)
263 EmpathyContactPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (contact,
264 EMPATHY_TYPE_CONTACT, EmpathyContactPriv);
266 contact->priv = priv;
268 priv->location = NULL;
272 contact_finalize (GObject *object)
274 EmpathyContactPriv *priv;
276 priv = GET_PRIV (object);
278 DEBUG ("finalize: %p", object);
282 g_free (priv->presence_message);
285 empathy_avatar_unref (priv->avatar);
287 if (priv->location != NULL)
288 g_hash_table_unref (priv->location);
290 G_OBJECT_CLASS (empathy_contact_parent_class)->finalize (object);
294 set_tp_contact (EmpathyContact *contact,
295 TpContact *tp_contact)
297 EmpathyContactPriv *priv = GET_PRIV (contact);
299 if (tp_contact == NULL)
302 g_assert (priv->tp_contact == NULL);
303 priv->tp_contact = g_object_ref (tp_contact);
304 priv->presence = empathy_contact_get_presence (contact);
306 g_signal_connect (priv->tp_contact, "notify",
307 G_CALLBACK (tp_contact_notify_cb), contact);
311 contact_get_property (GObject *object,
316 EmpathyContact *contact = EMPATHY_CONTACT (object);
320 case PROP_TP_CONTACT:
321 g_value_set_object (value, empathy_contact_get_tp_contact (contact));
324 g_value_set_object (value, empathy_contact_get_account (contact));
327 g_value_set_string (value, empathy_contact_get_id (contact));
330 g_value_set_string (value, empathy_contact_get_name (contact));
333 g_value_set_boxed (value, empathy_contact_get_avatar (contact));
336 g_value_set_uint (value, empathy_contact_get_presence (contact));
338 case PROP_PRESENCE_MESSAGE:
339 g_value_set_string (value, empathy_contact_get_presence_message (contact));
342 g_value_set_uint (value, empathy_contact_get_handle (contact));
344 case PROP_CAPABILITIES:
345 g_value_set_flags (value, empathy_contact_get_capabilities (contact));
348 g_value_set_boolean (value, empathy_contact_is_user (contact));
351 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
357 contact_set_property (GObject *object,
362 EmpathyContact *contact = EMPATHY_CONTACT (object);
363 EmpathyContactPriv *priv = GET_PRIV (object);
367 case PROP_TP_CONTACT:
368 set_tp_contact (contact, g_value_get_object (value));
371 g_assert (priv->account == NULL);
372 priv->account = g_value_dup_object (value);
375 empathy_contact_set_id (contact, g_value_get_string (value));
378 empathy_contact_set_name (contact, g_value_get_string (value));
381 empathy_contact_set_avatar (contact, g_value_get_boxed (value));
384 empathy_contact_set_presence (contact, g_value_get_uint (value));
386 case PROP_PRESENCE_MESSAGE:
387 empathy_contact_set_presence_message (contact, g_value_get_string (value));
390 empathy_contact_set_handle (contact, g_value_get_uint (value));
392 case PROP_CAPABILITIES:
393 empathy_contact_set_capabilities (contact, g_value_get_flags (value));
396 empathy_contact_set_is_user (contact, g_value_get_boolean (value));
399 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
405 empathy_contact_new (TpContact *tp_contact)
407 g_return_val_if_fail (TP_IS_CONTACT (tp_contact), NULL);
409 return g_object_new (EMPATHY_TYPE_CONTACT,
410 "tp-contact", tp_contact,
416 empathy_contact_from_tpl_contact (TpAccount *account,
417 TplContact *tpl_contact)
419 EmpathyContact *retval;
422 g_return_val_if_fail (TPL_IS_CONTACT (tpl_contact), NULL);
424 is_user = (TPL_CONTACT_USER == tpl_contact_get_contact_type (tpl_contact));
426 retval = g_object_new (EMPATHY_TYPE_CONTACT,
427 "id", tpl_contact_get_alias (tpl_contact),
428 "name", tpl_contact_get_identifier (tpl_contact),
433 if (!EMP_STR_EMPTY (tpl_contact_get_avatar_token (tpl_contact)))
434 empathy_contact_load_avatar_cache (retval,
435 tpl_contact_get_avatar_token (tpl_contact));
439 #endif /* ENABLE_TPL */
442 empathy_contact_new_for_log (TpAccount *account,
447 g_return_val_if_fail (id != NULL, NULL);
448 g_assert (account != NULL);
450 return g_object_new (EMPATHY_TYPE_CONTACT,
459 empathy_contact_get_tp_contact (EmpathyContact *contact)
461 EmpathyContactPriv *priv;
463 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
465 priv = GET_PRIV (contact);
467 return priv->tp_contact;
471 empathy_contact_get_id (EmpathyContact *contact)
473 EmpathyContactPriv *priv;
475 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
477 priv = GET_PRIV (contact);
479 if (priv->tp_contact != NULL)
480 return tp_contact_get_identifier (priv->tp_contact);
486 empathy_contact_set_id (EmpathyContact *contact,
489 EmpathyContactPriv *priv;
491 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
492 g_return_if_fail (id != NULL);
494 priv = GET_PRIV (contact);
496 /* We temporally ref the contact because it could be destroyed
497 * during the signal emition */
498 g_object_ref (contact);
499 if (tp_strdiff (id, priv->id))
502 priv->id = g_strdup (id);
504 g_object_notify (G_OBJECT (contact), "id");
505 if (EMP_STR_EMPTY (priv->name))
506 g_object_notify (G_OBJECT (contact), "name");
509 g_object_unref (contact);
513 empathy_contact_get_name (EmpathyContact *contact)
515 EmpathyContactPriv *priv;
518 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
520 priv = GET_PRIV (contact);
522 if (priv->tp_contact != NULL)
523 alias = tp_contact_get_alias (priv->tp_contact);
527 if (!EMP_STR_EMPTY (alias))
530 return empathy_contact_get_id (contact);
534 empathy_contact_set_name (EmpathyContact *contact,
537 EmpathyContactPriv *priv;
539 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
541 priv = GET_PRIV (contact);
543 g_object_ref (contact);
544 if (tp_strdiff (name, priv->name))
547 priv->name = g_strdup (name);
548 g_object_notify (G_OBJECT (contact), "name");
550 g_object_unref (contact);
554 empathy_contact_get_avatar (EmpathyContact *contact)
556 EmpathyContactPriv *priv;
558 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
560 priv = GET_PRIV (contact);
566 empathy_contact_set_avatar (EmpathyContact *contact,
567 EmpathyAvatar *avatar)
569 EmpathyContactPriv *priv;
571 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
573 priv = GET_PRIV (contact);
575 if (priv->avatar == avatar)
580 empathy_avatar_unref (priv->avatar);
585 priv->avatar = empathy_avatar_ref (avatar);
587 g_object_notify (G_OBJECT (contact), "avatar");
591 empathy_contact_get_account (EmpathyContact *contact)
593 EmpathyContactPriv *priv;
595 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
597 priv = GET_PRIV (contact);
599 if (priv->account == NULL && priv->tp_contact != NULL)
601 TpConnection *connection;
603 /* FIXME: This assume the account manager already exists */
604 connection = tp_contact_get_connection (priv->tp_contact);
606 g_object_ref (empathy_get_account_for_connection (connection));
609 return priv->account;
613 empathy_contact_get_connection (EmpathyContact *contact)
615 EmpathyContactPriv *priv;
617 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
619 priv = GET_PRIV (contact);
621 if (priv->tp_contact != NULL)
622 return tp_contact_get_connection (priv->tp_contact);
627 TpConnectionPresenceType
628 empathy_contact_get_presence (EmpathyContact *contact)
630 EmpathyContactPriv *priv;
632 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact),
633 TP_CONNECTION_PRESENCE_TYPE_UNSET);
635 priv = GET_PRIV (contact);
637 if (priv->tp_contact != NULL)
638 return tp_contact_get_presence_type (priv->tp_contact);
640 return priv->presence;
644 empathy_contact_set_presence (EmpathyContact *contact,
645 TpConnectionPresenceType presence)
647 EmpathyContactPriv *priv;
648 TpConnectionPresenceType old_presence;
650 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
652 priv = GET_PRIV (contact);
654 if (presence == priv->presence)
657 old_presence = priv->presence;
658 priv->presence = presence;
660 g_signal_emit (contact, signals[PRESENCE_CHANGED], 0, presence, old_presence);
662 g_object_notify (G_OBJECT (contact), "presence");
666 empathy_contact_get_presence_message (EmpathyContact *contact)
668 EmpathyContactPriv *priv;
670 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
672 priv = GET_PRIV (contact);
674 if (priv->tp_contact != NULL)
675 return tp_contact_get_presence_message (priv->tp_contact);
677 return priv->presence_message;
681 empathy_contact_set_presence_message (EmpathyContact *contact,
682 const gchar *message)
684 EmpathyContactPriv *priv = GET_PRIV (contact);
686 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
688 if (!tp_strdiff (message, priv->presence_message))
691 g_free (priv->presence_message);
692 priv->presence_message = g_strdup (message);
694 g_object_notify (G_OBJECT (contact), "presence-message");
698 empathy_contact_get_handle (EmpathyContact *contact)
700 EmpathyContactPriv *priv;
702 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), 0);
704 priv = GET_PRIV (contact);
706 if (priv->tp_contact != NULL)
707 return tp_contact_get_handle (priv->tp_contact);
713 empathy_contact_set_handle (EmpathyContact *contact,
716 EmpathyContactPriv *priv;
718 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
720 priv = GET_PRIV (contact);
722 g_object_ref (contact);
723 if (handle != priv->handle)
725 priv->handle = handle;
726 g_object_notify (G_OBJECT (contact), "handle");
728 g_object_unref (contact);
732 empathy_contact_get_capabilities (EmpathyContact *contact)
734 EmpathyContactPriv *priv;
736 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), 0);
738 priv = GET_PRIV (contact);
740 return priv->capabilities;
744 empathy_contact_set_capabilities (EmpathyContact *contact,
745 EmpathyCapabilities capabilities)
747 EmpathyContactPriv *priv;
749 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
751 priv = GET_PRIV (contact);
753 if (priv->capabilities == capabilities)
756 priv->capabilities = capabilities;
758 g_object_notify (G_OBJECT (contact), "capabilities");
762 empathy_contact_is_user (EmpathyContact *contact)
764 EmpathyContactPriv *priv;
766 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
768 priv = GET_PRIV (contact);
770 return priv->is_user;
774 empathy_contact_set_is_user (EmpathyContact *contact,
777 EmpathyContactPriv *priv;
779 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
781 priv = GET_PRIV (contact);
783 if (priv->is_user == is_user)
786 priv->is_user = is_user;
788 g_object_notify (G_OBJECT (contact), "is-user");
792 empathy_contact_is_online (EmpathyContact *contact)
794 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
796 switch (empathy_contact_get_presence (contact))
798 case TP_CONNECTION_PRESENCE_TYPE_OFFLINE:
799 case TP_CONNECTION_PRESENCE_TYPE_UNKNOWN:
800 case TP_CONNECTION_PRESENCE_TYPE_ERROR:
808 empathy_contact_get_status (EmpathyContact *contact)
810 const gchar *message;
812 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), "");
814 message = empathy_contact_get_presence_message (contact);
815 if (!EMP_STR_EMPTY (message))
818 return empathy_presence_get_default_message (
819 empathy_contact_get_presence (contact));
823 empathy_contact_can_voip (EmpathyContact *contact)
825 EmpathyContactPriv *priv;
827 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
829 priv = GET_PRIV (contact);
831 return priv->capabilities & (EMPATHY_CAPABILITIES_AUDIO |
832 EMPATHY_CAPABILITIES_VIDEO);
836 empathy_contact_can_voip_audio (EmpathyContact *contact)
838 EmpathyContactPriv *priv;
840 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
842 priv = GET_PRIV (contact);
844 return priv->capabilities & EMPATHY_CAPABILITIES_AUDIO;
848 empathy_contact_can_voip_video (EmpathyContact *contact)
850 EmpathyContactPriv *priv;
852 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
854 priv = GET_PRIV (contact);
856 return priv->capabilities & EMPATHY_CAPABILITIES_VIDEO;
860 empathy_contact_can_send_files (EmpathyContact *contact)
862 EmpathyContactPriv *priv;
864 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
866 priv = GET_PRIV (contact);
868 return priv->capabilities & EMPATHY_CAPABILITIES_FT;
872 empathy_contact_can_use_stream_tube (EmpathyContact *contact)
874 EmpathyContactPriv *priv;
876 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
878 priv = GET_PRIV (contact);
880 return priv->capabilities & EMPATHY_CAPABILITIES_STREAM_TUBE;
884 contact_get_avatar_filename (EmpathyContact *contact,
890 gchar *token_escaped;
892 if (EMP_STR_EMPTY (empathy_contact_get_id (contact)))
895 token_escaped = tp_escape_as_identifier (token);
896 account = empathy_contact_get_account (contact);
898 avatar_path = g_build_filename (g_get_user_cache_dir (),
901 tp_account_get_connection_manager (account),
902 tp_account_get_protocol (account),
904 g_mkdir_with_parents (avatar_path, 0700);
906 avatar_file = g_build_filename (avatar_path, token_escaped, NULL);
908 g_free (token_escaped);
909 g_free (avatar_path);
915 empathy_contact_load_avatar_data (EmpathyContact *contact,
921 EmpathyAvatar *avatar;
923 GError *error = NULL;
925 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
926 g_return_if_fail (data != NULL);
927 g_return_if_fail (len > 0);
928 g_return_if_fail (format != NULL);
929 g_return_if_fail (!EMP_STR_EMPTY (token));
931 /* Load and set the avatar */
932 filename = contact_get_avatar_filename (contact, token);
933 avatar = empathy_avatar_new (g_memdup (data, len), len, g_strdup (format),
934 g_strdup (token), filename);
935 empathy_contact_set_avatar (contact, avatar);
936 empathy_avatar_unref (avatar);
938 /* Save to cache if not yet in it */
939 if (filename && !g_file_test (filename, G_FILE_TEST_EXISTS))
941 if (!empathy_avatar_save_to_file (avatar, filename, &error))
943 DEBUG ("Failed to save avatar in cache: %s",
944 error ? error->message : "No error given");
945 g_clear_error (&error);
948 DEBUG ("Avatar saved to %s", filename);
953 empathy_contact_load_avatar_cache (EmpathyContact *contact,
956 EmpathyAvatar *avatar = NULL;
960 GError *error = NULL;
962 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
963 g_return_val_if_fail (!EMP_STR_EMPTY (token), FALSE);
965 /* Load the avatar from file if it exists */
966 filename = contact_get_avatar_filename (contact, token);
967 if (filename && g_file_test (filename, G_FILE_TEST_EXISTS))
969 if (!g_file_get_contents (filename, &data, &len, &error))
971 DEBUG ("Failed to load avatar from cache: %s",
972 error ? error->message : "No error given");
973 g_clear_error (&error);
979 DEBUG ("Avatar loaded from %s", filename);
980 avatar = empathy_avatar_new ((guchar *) data, len, NULL, g_strdup (token),
982 empathy_contact_set_avatar (contact, avatar);
983 empathy_avatar_unref (avatar);
994 empathy_avatar_get_type (void)
996 static GType type_id = 0;
1000 type_id = g_boxed_type_register_static ("EmpathyAvatar",
1001 (GBoxedCopyFunc) empathy_avatar_ref,
1002 (GBoxedFreeFunc) empathy_avatar_unref);
1009 * empathy_avatar_new:
1010 * @data: the avatar data
1011 * @len: the size of avatar data
1012 * @format: the mime type of the avatar image
1013 * @token: the token of the avatar
1014 * @filename: the filename where the avatar is stored in cache
1016 * Create a #EmpathyAvatar from the provided data. This function takes the
1017 * ownership of @data, @format, @token and @filename.
1019 * Returns: a new #EmpathyAvatar
1022 empathy_avatar_new (guchar *data,
1028 EmpathyAvatar *avatar;
1030 avatar = g_slice_new0 (EmpathyAvatar);
1031 avatar->data = data;
1033 avatar->format = format;
1034 avatar->token = token;
1035 avatar->filename = filename;
1036 avatar->refcount = 1;
1042 empathy_avatar_unref (EmpathyAvatar *avatar)
1044 g_return_if_fail (avatar != NULL);
1047 if (avatar->refcount == 0)
1049 g_free (avatar->data);
1050 g_free (avatar->format);
1051 g_free (avatar->token);
1052 g_slice_free (EmpathyAvatar, avatar);
1057 empathy_avatar_ref (EmpathyAvatar *avatar)
1059 g_return_val_if_fail (avatar != NULL, NULL);
1067 * empathy_avatar_save_to_file:
1068 * @avatar: the avatar
1069 * @filename: name of a file to write avatar to
1070 * @error: return location for a GError, or NULL
1072 * Save the avatar to a file named filename
1074 * Returns: %TRUE on success, %FALSE if an error occurred
1077 empathy_avatar_save_to_file (EmpathyAvatar *self,
1078 const gchar *filename,
1081 return g_file_set_contents (filename, (const gchar *) self->data, self->len,
1086 * empathy_contact_get_location:
1087 * @contact: an #EmpathyContact
1089 * Returns the user's location if available. The keys are defined in
1090 * empathy-location.h. If the contact doesn't have location
1091 * information, the GHashTable will be empthy. Use #g_hash_table_unref when
1092 * you are done with the #GHashTable.
1094 * It is composed of string keys and GValues. Keys are
1095 * defined in empathy-location.h such as #EMPATHY_LOCATION_COUNTRY.
1096 * Example: a "city" key would have "Helsinki" as string GValue,
1097 * a "latitude" would have 65.0 as double GValue.
1099 * Returns: a #GHashTable of location values
1102 empathy_contact_get_location (EmpathyContact *contact)
1104 EmpathyContactPriv *priv;
1106 g_return_val_if_fail (EMPATHY_CONTACT (contact), NULL);
1108 priv = GET_PRIV (contact);
1110 return priv->location;
1114 * empathy_contact_set_location:
1115 * @contact: an #EmpathyContact
1116 * @location: a #GHashTable of the location
1118 * Sets the user's location based on the location #GHashTable passed.
1119 * It is composed of string keys and GValues. Keys are
1120 * defined in empathy-location.h such as #EMPATHY_LOCATION_COUNTRY.
1121 * Example: a "city" key would have "Helsinki" as string GValue,
1122 * a "latitude" would have 65.0 as double GValue.
1125 empathy_contact_set_location (EmpathyContact *contact,
1126 GHashTable *location)
1128 EmpathyContactPriv *priv;
1130 g_return_if_fail (EMPATHY_CONTACT (contact));
1131 g_return_if_fail (location != NULL);
1133 priv = GET_PRIV (contact);
1135 if (priv->location != NULL)
1136 g_hash_table_unref (priv->location);
1138 priv->location = g_hash_table_ref (location);
1139 g_object_notify (G_OBJECT (contact), "location");
1143 * empathy_contact_equal:
1144 * @contact1: an #EmpathyContact
1145 * @contact2: an #EmpathyContact
1147 * Returns FALSE if one of the contacts is NULL but the other is not.
1148 * Otherwise returns TRUE if both pointer are equal or if they bith
1149 * refer to the same id.
1150 * It's only necessary to call this function if your contact objects
1151 * come from logs where contacts are created dynamically and comparing
1152 * pointers is not enough.
1155 empathy_contact_equal (gconstpointer contact1,
1156 gconstpointer contact2)
1163 if ((contact1 == NULL) != (contact2 == NULL)) {
1166 if (contact1 == contact2) {
1169 c1 = EMPATHY_CONTACT (contact1);
1170 c2 = EMPATHY_CONTACT (contact2);
1171 id1 = empathy_contact_get_id (c1);
1172 id2 = empathy_contact_get_id (c2);
1173 if (!tp_strdiff (id1, id2)) {