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/util.h>
29 #include <libmissioncontrol/mc-enum-types.h>
31 #include "empathy-contact.h"
32 #include "empathy-account-manager.h"
33 #include "empathy-utils.h"
34 #include "empathy-enum-types.h"
35 #include "empathy-marshal.h"
37 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
38 #include "empathy-debug.h"
40 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyContact)
42 TpContact *tp_contact;
46 EmpathyAvatar *avatar;
48 gchar *presence_message;
50 EmpathyCapabilities capabilities;
53 /* Location is composed of string keys and GValues.
54 * Example: a "city" key would have "Helsinki" as string GValue,
55 * a "latitude" would have 65.0 as double GValue.
60 static void contact_finalize (GObject *object);
61 static void contact_get_property (GObject *object, guint param_id,
62 GValue *value, GParamSpec *pspec);
63 static void contact_set_property (GObject *object, guint param_id,
64 const GValue *value, GParamSpec *pspec);
66 G_DEFINE_TYPE (EmpathyContact, empathy_contact, G_TYPE_OBJECT);
77 PROP_PRESENCE_MESSAGE,
89 static guint signals[LAST_SIGNAL];
92 tp_contact_notify_cb (TpContact *tp_contact,
96 EmpathyContactPriv *priv = GET_PRIV (contact);
98 /* Forward property notifications */
99 if (!tp_strdiff (param->name, "alias"))
100 g_object_notify (contact, "name");
101 else if (!tp_strdiff (param->name, "presence-type")) {
104 presence = empathy_contact_get_presence (EMPATHY_CONTACT (contact));
105 g_signal_emit (contact, signals[PRESENCE_CHANGED], 0, presence, priv->presence);
106 priv->presence = presence;
107 g_object_notify (contact, "presence");
109 else if (!tp_strdiff (param->name, "presence-message"))
110 g_object_notify (contact, "presence-message");
111 else if (!tp_strdiff (param->name, "identifier"))
112 g_object_notify (contact, "id");
113 else if (!tp_strdiff (param->name, "handle"))
114 g_object_notify (contact, "handle");
118 contact_dispose (GObject *object)
120 EmpathyContactPriv *priv = GET_PRIV (object);
122 if (priv->tp_contact)
124 g_signal_handlers_disconnect_by_func (priv->tp_contact,
125 tp_contact_notify_cb, object);
126 g_object_unref (priv->tp_contact);
128 priv->tp_contact = NULL;
131 g_object_unref (priv->account);
132 priv->account = NULL;
134 G_OBJECT_CLASS (empathy_contact_parent_class)->dispose (object);
138 empathy_contact_class_init (EmpathyContactClass *class)
140 GObjectClass *object_class;
142 object_class = G_OBJECT_CLASS (class);
144 object_class->finalize = contact_finalize;
145 object_class->dispose = contact_dispose;
146 object_class->get_property = contact_get_property;
147 object_class->set_property = contact_set_property;
149 g_object_class_install_property (object_class,
151 g_param_spec_object ("tp-contact",
153 "The TpContact associated with the contact",
155 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
157 g_object_class_install_property (object_class,
159 g_param_spec_object ("account",
161 "The account associated with the contact",
163 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
165 g_object_class_install_property (object_class,
167 g_param_spec_string ("id",
169 "String identifying contact",
171 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
173 g_object_class_install_property (object_class,
175 g_param_spec_string ("name",
177 "The name of the contact",
179 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
181 g_object_class_install_property (object_class,
183 g_param_spec_boxed ("avatar",
187 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
189 g_object_class_install_property (object_class,
191 g_param_spec_uint ("presence",
193 "Presence of contact",
197 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
199 g_object_class_install_property (object_class,
200 PROP_PRESENCE_MESSAGE,
201 g_param_spec_string ("presence-message",
202 "Contact presence message",
203 "Presence message of contact",
205 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
207 g_object_class_install_property (object_class,
209 g_param_spec_uint ("handle",
211 "The handle of the contact",
215 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
217 g_object_class_install_property (object_class,
219 g_param_spec_flags ("capabilities",
220 "Contact Capabilities",
221 "Capabilities of the contact",
222 EMPATHY_TYPE_CAPABILITIES,
223 EMPATHY_CAPABILITIES_UNKNOWN,
224 G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
226 g_object_class_install_property (object_class,
228 g_param_spec_boolean ("is-user",
230 "Is contact the user",
232 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
235 g_object_class_install_property (object_class,
237 g_param_spec_boxed ("location",
239 "Physical location of the contact",
241 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
243 signals[PRESENCE_CHANGED] =
244 g_signal_new ("presence-changed",
245 G_TYPE_FROM_CLASS (class),
249 _empathy_marshal_VOID__ENUM_ENUM,
254 g_type_class_add_private (object_class, sizeof (EmpathyContactPriv));
258 empathy_contact_init (EmpathyContact *contact)
260 EmpathyContactPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (contact,
261 EMPATHY_TYPE_CONTACT, EmpathyContactPriv);
263 contact->priv = priv;
265 priv->location = g_hash_table_new_full (g_str_hash, g_str_equal,
266 (GDestroyNotify) g_free,
267 (GDestroyNotify) tp_g_value_slice_free);
271 contact_finalize (GObject *object)
273 EmpathyContactPriv *priv;
275 priv = GET_PRIV (object);
277 DEBUG ("finalize: %p", object);
281 g_free (priv->presence_message);
284 empathy_avatar_unref (priv->avatar);
286 G_OBJECT_CLASS (empathy_contact_parent_class)->finalize (object);
290 set_tp_contact (EmpathyContact *contact,
291 TpContact *tp_contact)
293 EmpathyContactPriv *priv = GET_PRIV (contact);
295 if (tp_contact == NULL)
298 g_assert (priv->tp_contact == NULL);
299 priv->tp_contact = g_object_ref (tp_contact);
300 priv->presence = empathy_contact_get_presence (contact);
302 g_signal_connect (priv->tp_contact, "notify",
303 G_CALLBACK (tp_contact_notify_cb), contact);
307 contact_get_property (GObject *object,
312 EmpathyContact *contact = EMPATHY_CONTACT (object);
316 case PROP_TP_CONTACT:
317 g_value_set_object (value, empathy_contact_get_tp_contact (contact));
320 g_value_set_object (value, empathy_contact_get_account (contact));
323 g_value_set_string (value, empathy_contact_get_id (contact));
326 g_value_set_string (value, empathy_contact_get_name (contact));
329 g_value_set_boxed (value, empathy_contact_get_avatar (contact));
332 g_value_set_uint (value, empathy_contact_get_presence (contact));
334 case PROP_PRESENCE_MESSAGE:
335 g_value_set_string (value, empathy_contact_get_presence_message (contact));
338 g_value_set_uint (value, empathy_contact_get_handle (contact));
340 case PROP_CAPABILITIES:
341 g_value_set_flags (value, empathy_contact_get_capabilities (contact));
344 g_value_set_boolean (value, empathy_contact_is_user (contact));
347 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
353 contact_set_property (GObject *object,
358 EmpathyContact *contact = EMPATHY_CONTACT (object);
359 EmpathyContactPriv *priv = GET_PRIV (object);
363 case PROP_TP_CONTACT:
364 set_tp_contact (contact, g_value_get_object (value));
367 g_assert (priv->account == NULL);
368 priv->account = g_value_dup_object (value);
371 empathy_contact_set_id (contact, g_value_get_string (value));
374 empathy_contact_set_name (contact, g_value_get_string (value));
377 empathy_contact_set_avatar (contact, g_value_get_boxed (value));
380 empathy_contact_set_presence (contact, g_value_get_uint (value));
382 case PROP_PRESENCE_MESSAGE:
383 empathy_contact_set_presence_message (contact, g_value_get_string (value));
386 empathy_contact_set_handle (contact, g_value_get_uint (value));
388 case PROP_CAPABILITIES:
389 empathy_contact_set_capabilities (contact, g_value_get_flags (value));
392 empathy_contact_set_is_user (contact, g_value_get_boolean (value));
395 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
401 empathy_contact_new (TpContact *tp_contact)
403 g_return_val_if_fail (TP_IS_CONTACT (tp_contact), NULL);
405 return g_object_new (EMPATHY_TYPE_CONTACT,
406 "tp-contact", tp_contact,
411 empathy_contact_new_for_log (McAccount *account,
416 g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
417 g_return_val_if_fail (id != NULL, NULL);
419 return g_object_new (EMPATHY_TYPE_CONTACT,
428 empathy_contact_get_tp_contact (EmpathyContact *contact)
430 EmpathyContactPriv *priv;
432 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
434 priv = GET_PRIV (contact);
436 return priv->tp_contact;
440 empathy_contact_get_id (EmpathyContact *contact)
442 EmpathyContactPriv *priv;
444 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
446 priv = GET_PRIV (contact);
448 if (priv->tp_contact != NULL)
449 return tp_contact_get_identifier (priv->tp_contact);
455 empathy_contact_set_id (EmpathyContact *contact,
458 EmpathyContactPriv *priv;
460 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
461 g_return_if_fail (id != NULL);
463 priv = GET_PRIV (contact);
465 /* We temporally ref the contact because it could be destroyed
466 * during the signal emition */
467 g_object_ref (contact);
468 if (tp_strdiff (id, priv->id))
471 priv->id = g_strdup (id);
473 g_object_notify (G_OBJECT (contact), "id");
474 if (EMP_STR_EMPTY (priv->name))
475 g_object_notify (G_OBJECT (contact), "name");
478 g_object_unref (contact);
482 empathy_contact_get_name (EmpathyContact *contact)
484 EmpathyContactPriv *priv;
486 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
488 priv = GET_PRIV (contact);
490 if (priv->tp_contact != NULL)
491 return tp_contact_get_alias (priv->tp_contact);
493 if (EMP_STR_EMPTY (priv->name))
494 return empathy_contact_get_id (contact);
500 empathy_contact_set_name (EmpathyContact *contact,
503 EmpathyContactPriv *priv;
505 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
507 priv = GET_PRIV (contact);
509 g_object_ref (contact);
510 if (tp_strdiff (name, priv->name))
513 priv->name = g_strdup (name);
514 g_object_notify (G_OBJECT (contact), "name");
516 g_object_unref (contact);
520 empathy_contact_get_avatar (EmpathyContact *contact)
522 EmpathyContactPriv *priv;
524 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
526 priv = GET_PRIV (contact);
532 empathy_contact_set_avatar (EmpathyContact *contact,
533 EmpathyAvatar *avatar)
535 EmpathyContactPriv *priv;
537 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
539 priv = GET_PRIV (contact);
541 if (priv->avatar == avatar)
546 empathy_avatar_unref (priv->avatar);
551 priv->avatar = empathy_avatar_ref (avatar);
553 g_object_notify (G_OBJECT (contact), "avatar");
557 empathy_contact_get_account (EmpathyContact *contact)
559 EmpathyContactPriv *priv;
561 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
563 priv = GET_PRIV (contact);
565 if (priv->account == NULL && priv->tp_contact != NULL)
567 EmpathyAccountManager *manager;
568 TpConnection *connection;
570 /* FIXME: This assume the account manager already exists */
571 manager = empathy_account_manager_dup_singleton ();
572 connection = tp_contact_get_connection (priv->tp_contact);
573 priv->account = empathy_account_manager_get_account (manager, connection);
574 g_object_ref (priv->account);
575 g_object_unref (manager);
578 return priv->account;
582 empathy_contact_get_connection (EmpathyContact *contact)
584 EmpathyContactPriv *priv;
586 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
588 priv = GET_PRIV (contact);
590 if (priv->tp_contact != NULL)
591 return tp_contact_get_connection (priv->tp_contact);
597 presence_type_to_mc_presence (TpConnectionPresenceType type)
601 case TP_CONNECTION_PRESENCE_TYPE_UNSET:
602 case TP_CONNECTION_PRESENCE_TYPE_UNKNOWN:
603 case TP_CONNECTION_PRESENCE_TYPE_ERROR:
604 return MC_PRESENCE_UNSET;
605 case TP_CONNECTION_PRESENCE_TYPE_OFFLINE:
606 return MC_PRESENCE_OFFLINE;
607 case TP_CONNECTION_PRESENCE_TYPE_AVAILABLE:
608 return MC_PRESENCE_AVAILABLE;
609 case TP_CONNECTION_PRESENCE_TYPE_AWAY:
610 return MC_PRESENCE_AWAY;
611 case TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY:
612 return MC_PRESENCE_EXTENDED_AWAY;
613 case TP_CONNECTION_PRESENCE_TYPE_HIDDEN:
614 return MC_PRESENCE_HIDDEN;
615 case TP_CONNECTION_PRESENCE_TYPE_BUSY:
616 return MC_PRESENCE_DO_NOT_DISTURB;
619 return MC_PRESENCE_UNSET;
623 empathy_contact_get_presence (EmpathyContact *contact)
625 EmpathyContactPriv *priv;
627 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), MC_PRESENCE_UNSET);
629 priv = GET_PRIV (contact);
631 if (priv->tp_contact != NULL)
632 return presence_type_to_mc_presence (tp_contact_get_presence_type (
635 return priv->presence;
639 empathy_contact_set_presence (EmpathyContact *contact,
642 EmpathyContactPriv *priv;
643 McPresence old_presence;
645 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
647 priv = GET_PRIV (contact);
649 if (presence == priv->presence)
652 old_presence = priv->presence;
653 priv->presence = presence;
655 g_signal_emit (contact, signals[PRESENCE_CHANGED], 0, presence, old_presence);
657 g_object_notify (G_OBJECT (contact), "presence");
661 empathy_contact_get_presence_message (EmpathyContact *contact)
663 EmpathyContactPriv *priv;
665 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
667 priv = GET_PRIV (contact);
669 if (priv->tp_contact != NULL)
670 return tp_contact_get_presence_message (priv->tp_contact);
672 return priv->presence_message;
676 empathy_contact_set_presence_message (EmpathyContact *contact,
677 const gchar *message)
679 EmpathyContactPriv *priv = GET_PRIV (contact);
681 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
683 if (!tp_strdiff (message, priv->presence_message))
686 g_free (priv->presence_message);
687 priv->presence_message = g_strdup (message);
689 g_object_notify (G_OBJECT (contact), "presence-message");
693 empathy_contact_get_handle (EmpathyContact *contact)
695 EmpathyContactPriv *priv;
697 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), 0);
699 priv = GET_PRIV (contact);
701 if (priv->tp_contact != NULL)
702 return tp_contact_get_handle (priv->tp_contact);
708 empathy_contact_set_handle (EmpathyContact *contact,
711 EmpathyContactPriv *priv;
713 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
715 priv = GET_PRIV (contact);
717 g_object_ref (contact);
718 if (handle != priv->handle)
720 priv->handle = handle;
721 g_object_notify (G_OBJECT (contact), "handle");
723 g_object_unref (contact);
727 empathy_contact_get_capabilities (EmpathyContact *contact)
729 EmpathyContactPriv *priv;
731 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), 0);
733 priv = GET_PRIV (contact);
735 return priv->capabilities;
739 empathy_contact_set_capabilities (EmpathyContact *contact,
740 EmpathyCapabilities capabilities)
742 EmpathyContactPriv *priv;
744 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
746 priv = GET_PRIV (contact);
748 if (priv->capabilities == capabilities)
751 priv->capabilities = capabilities;
753 g_object_notify (G_OBJECT (contact), "capabilities");
757 empathy_contact_is_user (EmpathyContact *contact)
759 EmpathyContactPriv *priv;
761 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
763 priv = GET_PRIV (contact);
765 return priv->is_user;
769 empathy_contact_set_is_user (EmpathyContact *contact,
772 EmpathyContactPriv *priv;
774 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
776 priv = GET_PRIV (contact);
778 if (priv->is_user == is_user)
781 priv->is_user = is_user;
783 g_object_notify (G_OBJECT (contact), "is-user");
787 empathy_contact_is_online (EmpathyContact *contact)
789 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
791 return (empathy_contact_get_presence (contact) > MC_PRESENCE_OFFLINE);
795 empathy_contact_get_status (EmpathyContact *contact)
797 const gchar *message;
799 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), "");
801 message = empathy_contact_get_presence_message (contact);
802 if (!EMP_STR_EMPTY (message))
805 return empathy_presence_get_default_message (
806 empathy_contact_get_presence (contact));
810 empathy_contact_can_voip (EmpathyContact *contact)
812 EmpathyContactPriv *priv;
814 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
816 priv = GET_PRIV (contact);
818 return priv->capabilities & (EMPATHY_CAPABILITIES_AUDIO |
819 EMPATHY_CAPABILITIES_VIDEO);
823 empathy_contact_can_send_files (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_FT;
835 contact_get_avatar_filename (EmpathyContact *contact,
838 EmpathyContactPriv *priv = GET_PRIV (contact);
842 gchar *token_escaped;
843 gchar *contact_escaped;
845 if (EMP_STR_EMPTY (priv->id))
848 contact_escaped = tp_escape_as_identifier (priv->id);
849 token_escaped = tp_escape_as_identifier (token);
850 account = empathy_contact_get_account (contact);
852 /* FIXME: Do not use the account, but proto/cm instead */
853 avatar_path = g_build_filename (g_get_user_cache_dir (),
856 mc_account_get_unique_name (account),
859 g_mkdir_with_parents (avatar_path, 0700);
861 avatar_file = g_build_filename (avatar_path, token_escaped, NULL);
863 g_free (contact_escaped);
864 g_free (token_escaped);
865 g_free (avatar_path);
871 empathy_contact_load_avatar_data (EmpathyContact *contact,
877 EmpathyAvatar *avatar;
879 GError *error = NULL;
881 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
882 g_return_if_fail (data != NULL);
883 g_return_if_fail (len > 0);
884 g_return_if_fail (format != NULL);
885 g_return_if_fail (!EMP_STR_EMPTY (token));
887 /* Load and set the avatar */
888 avatar = empathy_avatar_new (g_memdup (data, len), len, g_strdup (format),
890 empathy_contact_set_avatar (contact, avatar);
891 empathy_avatar_unref (avatar);
893 /* Save to cache if not yet in it */
894 filename = contact_get_avatar_filename (contact, token);
895 if (filename && !g_file_test (filename, G_FILE_TEST_EXISTS))
897 if (!empathy_avatar_save_to_file (avatar, filename, &error))
899 DEBUG ("Failed to save avatar in cache: %s",
900 error ? error->message : "No error given");
901 g_clear_error (&error);
904 DEBUG ("Avatar saved to %s", filename);
910 empathy_contact_load_avatar_cache (EmpathyContact *contact,
913 EmpathyAvatar *avatar = NULL;
917 GError *error = NULL;
919 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
920 g_return_val_if_fail (!EMP_STR_EMPTY (token), FALSE);
922 /* Load the avatar from file if it exists */
923 filename = contact_get_avatar_filename (contact, token);
924 if (filename && g_file_test (filename, G_FILE_TEST_EXISTS))
926 if (!g_file_get_contents (filename, &data, &len, &error))
928 DEBUG ("Failed to load avatar from cache: %s",
929 error ? error->message : "No error given");
930 g_clear_error (&error);
936 DEBUG ("Avatar loaded from %s", filename);
937 avatar = empathy_avatar_new (data, len, NULL, g_strdup (token));
938 empathy_contact_set_avatar (contact, avatar);
939 empathy_avatar_unref (avatar);
948 empathy_avatar_get_type (void)
950 static GType type_id = 0;
954 type_id = g_boxed_type_register_static ("EmpathyAvatar",
955 (GBoxedCopyFunc) empathy_avatar_ref,
956 (GBoxedFreeFunc) empathy_avatar_unref);
963 empathy_avatar_new (guchar *data,
968 EmpathyAvatar *avatar;
970 avatar = g_slice_new0 (EmpathyAvatar);
973 avatar->format = format;
974 avatar->token = token;
975 avatar->refcount = 1;
981 empathy_avatar_unref (EmpathyAvatar *avatar)
983 g_return_if_fail (avatar != NULL);
986 if (avatar->refcount == 0)
988 g_free (avatar->data);
989 g_free (avatar->format);
990 g_free (avatar->token);
991 g_slice_free (EmpathyAvatar, avatar);
996 empathy_avatar_ref (EmpathyAvatar *avatar)
998 g_return_val_if_fail (avatar != NULL, NULL);
1006 * empathy_avatar_save_to_file:
1007 * @avatar: the avatar
1008 * @filename: name of a file to write avatar to
1009 * @error: return location for a GError, or NULL
1011 * Save the avatar to a file named filename
1013 * Returns: %TRUE on success, %FALSE if an error occurred
1016 empathy_avatar_save_to_file (EmpathyAvatar *self,
1017 const gchar *filename,
1020 return g_file_set_contents (filename, self->data, self->len, error);
1024 * empathy_contact_get_location:
1025 * @contact: an #EmpathyContact
1027 * Returns the user's location if available. The keys are defined in
1028 * empathy-location.h. If the contact doesn't have location
1029 * information, the GHashTable will be empthy. Use #g_hash_table_unref when
1030 * you are done with the #GHashTable.
1032 * It is composed of string keys and GValues. Keys are
1033 * defined in empathy-location.h such as #EMPATHY_LOCATION_COUNTRY.
1034 * Example: a "city" key would have "Helsinki" as string GValue,
1035 * a "latitude" would have 65.0 as double GValue.
1037 * Returns: a #GHashTable of location values
1040 empathy_contact_get_location (EmpathyContact *contact)
1042 EmpathyContactPriv *priv;
1044 g_return_val_if_fail (EMPATHY_CONTACT (contact), NULL);
1046 priv = GET_PRIV (contact);
1048 return g_hash_table_ref (priv->location);
1052 * empathy_contact_set_location:
1053 * @contact: the contact
1054 * @location: the location
1056 * Sets the user's location based on the location #GHashTable passed.
1057 * It is composed of string keys and GValues. Keys are
1058 * defined in empathy-location.h such as #EMPATHY_LOCATION_COUNTRY.
1059 * Example: a "city" key would have "Helsinki" as string GValue,
1060 * a "latitude" would have 65.0 as double GValue.
1063 empathy_contact_set_location (EmpathyContact *contact,
1064 GHashTable *location)
1066 EmpathyContactPriv *priv;
1068 g_return_if_fail (EMPATHY_CONTACT (contact));
1069 g_return_if_fail (location != NULL);
1071 priv = GET_PRIV (contact);
1073 g_hash_table_unref (priv->location);
1075 priv->location = g_hash_table_ref (location);
1076 g_object_notify (G_OBJECT (contact), "location");