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;
56 static void contact_finalize (GObject *object);
57 static void contact_get_property (GObject *object, guint param_id,
58 GValue *value, GParamSpec *pspec);
59 static void contact_set_property (GObject *object, guint param_id,
60 const GValue *value, GParamSpec *pspec);
62 G_DEFINE_TYPE (EmpathyContact, empathy_contact, G_TYPE_OBJECT);
73 PROP_PRESENCE_MESSAGE,
85 static guint signals[LAST_SIGNAL];
88 tp_contact_notify_cb (TpContact *tp_contact,
92 EmpathyContactPriv *priv = GET_PRIV (contact);
94 /* Forward property notifications */
95 if (!tp_strdiff (param->name, "alias"))
96 g_object_notify (contact, "name");
97 else if (!tp_strdiff (param->name, "presence-type")) {
100 presence = empathy_contact_get_presence (EMPATHY_CONTACT (contact));
101 g_signal_emit (contact, signals[PRESENCE_CHANGED], 0, presence, priv->presence);
102 priv->presence = presence;
103 g_object_notify (contact, "presence");
105 else if (!tp_strdiff (param->name, "presence-message"))
106 g_object_notify (contact, "presence-message");
107 else if (!tp_strdiff (param->name, "identifier"))
108 g_object_notify (contact, "id");
109 else if (!tp_strdiff (param->name, "handle"))
110 g_object_notify (contact, "handle");
114 contact_dispose (GObject *object)
116 EmpathyContactPriv *priv = GET_PRIV (object);
118 if (priv->tp_contact)
120 g_signal_handlers_disconnect_by_func (priv->tp_contact,
121 tp_contact_notify_cb, object);
122 g_object_unref (priv->tp_contact);
124 priv->tp_contact = NULL;
127 g_object_unref (priv->account);
128 priv->account = NULL;
130 G_OBJECT_CLASS (empathy_contact_parent_class)->dispose (object);
134 empathy_contact_class_init (EmpathyContactClass *class)
136 GObjectClass *object_class;
138 object_class = G_OBJECT_CLASS (class);
140 object_class->finalize = contact_finalize;
141 object_class->dispose = contact_dispose;
142 object_class->get_property = contact_get_property;
143 object_class->set_property = contact_set_property;
145 g_object_class_install_property (object_class,
147 g_param_spec_object ("tp-contact",
149 "The TpContact associated with the contact",
151 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
153 g_object_class_install_property (object_class,
155 g_param_spec_object ("account",
157 "The account associated with the contact",
159 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
161 g_object_class_install_property (object_class,
163 g_param_spec_string ("id",
165 "String identifying contact",
167 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
169 g_object_class_install_property (object_class,
171 g_param_spec_string ("name",
173 "The name of the contact",
175 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
177 g_object_class_install_property (object_class,
179 g_param_spec_boxed ("avatar",
183 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
185 g_object_class_install_property (object_class,
187 g_param_spec_uint ("presence",
189 "Presence of contact",
193 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
195 g_object_class_install_property (object_class,
196 PROP_PRESENCE_MESSAGE,
197 g_param_spec_string ("presence-message",
198 "Contact presence message",
199 "Presence message of contact",
201 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
203 g_object_class_install_property (object_class,
205 g_param_spec_uint ("handle",
207 "The handle of the contact",
211 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
213 g_object_class_install_property (object_class,
215 g_param_spec_flags ("capabilities",
216 "Contact Capabilities",
217 "Capabilities of the contact",
218 EMPATHY_TYPE_CAPABILITIES,
219 EMPATHY_CAPABILITIES_UNKNOWN,
220 G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
222 g_object_class_install_property (object_class,
224 g_param_spec_boolean ("is-user",
226 "Is contact the user",
228 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
231 g_object_class_install_property (object_class,
233 g_param_spec_boxed ("location",
235 "Physical location of the contact",
239 signals[PRESENCE_CHANGED] =
240 g_signal_new ("presence-changed",
241 G_TYPE_FROM_CLASS (class),
245 _empathy_marshal_VOID__ENUM_ENUM,
250 g_type_class_add_private (object_class, sizeof (EmpathyContactPriv));
254 empathy_contact_init (EmpathyContact *contact)
256 EmpathyContactPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (contact,
257 EMPATHY_TYPE_CONTACT, EmpathyContactPriv);
259 contact->priv = priv;
261 priv->location = g_hash_table_new_full (g_str_hash, g_str_equal,
262 (GDestroyNotify) g_free,
263 (GDestroyNotify) tp_g_value_slice_free);
267 contact_finalize (GObject *object)
269 EmpathyContactPriv *priv;
271 priv = GET_PRIV (object);
273 DEBUG ("finalize: %p", object);
277 g_free (priv->presence_message);
280 empathy_avatar_unref (priv->avatar);
282 G_OBJECT_CLASS (empathy_contact_parent_class)->finalize (object);
286 set_tp_contact (EmpathyContact *contact,
287 TpContact *tp_contact)
289 EmpathyContactPriv *priv = GET_PRIV (contact);
291 if (tp_contact == NULL)
294 g_assert (priv->tp_contact == NULL);
295 priv->tp_contact = g_object_ref (tp_contact);
296 priv->presence = empathy_contact_get_presence (contact);
298 g_signal_connect (priv->tp_contact, "notify",
299 G_CALLBACK (tp_contact_notify_cb), contact);
303 contact_get_property (GObject *object,
308 EmpathyContact *contact = EMPATHY_CONTACT (object);
312 case PROP_TP_CONTACT:
313 g_value_set_object (value, empathy_contact_get_tp_contact (contact));
316 g_value_set_object (value, empathy_contact_get_account (contact));
319 g_value_set_string (value, empathy_contact_get_id (contact));
322 g_value_set_string (value, empathy_contact_get_name (contact));
325 g_value_set_boxed (value, empathy_contact_get_avatar (contact));
328 g_value_set_uint (value, empathy_contact_get_presence (contact));
330 case PROP_PRESENCE_MESSAGE:
331 g_value_set_string (value, empathy_contact_get_presence_message (contact));
334 g_value_set_uint (value, empathy_contact_get_handle (contact));
336 case PROP_CAPABILITIES:
337 g_value_set_flags (value, empathy_contact_get_capabilities (contact));
340 g_value_set_boolean (value, empathy_contact_is_user (contact));
343 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
349 contact_set_property (GObject *object,
354 EmpathyContact *contact = EMPATHY_CONTACT (object);
355 EmpathyContactPriv *priv = GET_PRIV (object);
359 case PROP_TP_CONTACT:
360 set_tp_contact (contact, g_value_get_object (value));
363 g_assert (priv->account == NULL);
364 priv->account = g_value_dup_object (value);
367 empathy_contact_set_id (contact, g_value_get_string (value));
370 empathy_contact_set_name (contact, g_value_get_string (value));
373 empathy_contact_set_avatar (contact, g_value_get_boxed (value));
376 empathy_contact_set_presence (contact, g_value_get_uint (value));
378 case PROP_PRESENCE_MESSAGE:
379 empathy_contact_set_presence_message (contact, g_value_get_string (value));
382 empathy_contact_set_handle (contact, g_value_get_uint (value));
384 case PROP_CAPABILITIES:
385 empathy_contact_set_capabilities (contact, g_value_get_flags (value));
388 empathy_contact_set_is_user (contact, g_value_get_boolean (value));
391 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
397 empathy_contact_new (TpContact *tp_contact)
399 g_return_val_if_fail (TP_IS_CONTACT (tp_contact), NULL);
401 return g_object_new (EMPATHY_TYPE_CONTACT,
402 "tp-contact", tp_contact,
407 empathy_contact_new_for_log (McAccount *account,
412 g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
413 g_return_val_if_fail (id != NULL, NULL);
415 return g_object_new (EMPATHY_TYPE_CONTACT,
424 empathy_contact_get_tp_contact (EmpathyContact *contact)
426 EmpathyContactPriv *priv;
428 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
430 priv = GET_PRIV (contact);
432 return priv->tp_contact;
436 empathy_contact_get_id (EmpathyContact *contact)
438 EmpathyContactPriv *priv;
440 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
442 priv = GET_PRIV (contact);
444 if (priv->tp_contact != NULL)
445 return tp_contact_get_identifier (priv->tp_contact);
451 empathy_contact_set_id (EmpathyContact *contact,
454 EmpathyContactPriv *priv;
456 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
457 g_return_if_fail (id != NULL);
459 priv = GET_PRIV (contact);
461 /* We temporally ref the contact because it could be destroyed
462 * during the signal emition */
463 g_object_ref (contact);
464 if (tp_strdiff (id, priv->id))
467 priv->id = g_strdup (id);
469 g_object_notify (G_OBJECT (contact), "id");
470 if (EMP_STR_EMPTY (priv->name))
471 g_object_notify (G_OBJECT (contact), "name");
474 g_object_unref (contact);
478 empathy_contact_get_name (EmpathyContact *contact)
480 EmpathyContactPriv *priv;
482 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
484 priv = GET_PRIV (contact);
486 if (priv->tp_contact != NULL)
487 return tp_contact_get_alias (priv->tp_contact);
489 if (EMP_STR_EMPTY (priv->name))
490 return empathy_contact_get_id (contact);
496 empathy_contact_set_name (EmpathyContact *contact,
499 EmpathyContactPriv *priv;
501 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
503 priv = GET_PRIV (contact);
505 g_object_ref (contact);
506 if (tp_strdiff (name, priv->name))
509 priv->name = g_strdup (name);
510 g_object_notify (G_OBJECT (contact), "name");
512 g_object_unref (contact);
516 empathy_contact_get_avatar (EmpathyContact *contact)
518 EmpathyContactPriv *priv;
520 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
522 priv = GET_PRIV (contact);
528 empathy_contact_set_avatar (EmpathyContact *contact,
529 EmpathyAvatar *avatar)
531 EmpathyContactPriv *priv;
533 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
535 priv = GET_PRIV (contact);
537 if (priv->avatar == avatar)
542 empathy_avatar_unref (priv->avatar);
547 priv->avatar = empathy_avatar_ref (avatar);
549 g_object_notify (G_OBJECT (contact), "avatar");
553 empathy_contact_get_account (EmpathyContact *contact)
555 EmpathyContactPriv *priv;
557 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
559 priv = GET_PRIV (contact);
561 if (priv->account == NULL && priv->tp_contact != NULL)
563 EmpathyAccountManager *manager;
564 TpConnection *connection;
566 /* FIXME: This assume the account manager already exists */
567 manager = empathy_account_manager_dup_singleton ();
568 connection = tp_contact_get_connection (priv->tp_contact);
569 priv->account = empathy_account_manager_get_account (manager, connection);
570 g_object_ref (priv->account);
571 g_object_unref (manager);
574 return priv->account;
578 empathy_contact_get_connection (EmpathyContact *contact)
580 EmpathyContactPriv *priv;
582 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
584 priv = GET_PRIV (contact);
586 if (priv->tp_contact != NULL)
587 return tp_contact_get_connection (priv->tp_contact);
593 presence_type_to_mc_presence (TpConnectionPresenceType type)
597 case TP_CONNECTION_PRESENCE_TYPE_UNSET:
598 case TP_CONNECTION_PRESENCE_TYPE_UNKNOWN:
599 case TP_CONNECTION_PRESENCE_TYPE_ERROR:
600 return MC_PRESENCE_UNSET;
601 case TP_CONNECTION_PRESENCE_TYPE_OFFLINE:
602 return MC_PRESENCE_OFFLINE;
603 case TP_CONNECTION_PRESENCE_TYPE_AVAILABLE:
604 return MC_PRESENCE_AVAILABLE;
605 case TP_CONNECTION_PRESENCE_TYPE_AWAY:
606 return MC_PRESENCE_AWAY;
607 case TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY:
608 return MC_PRESENCE_EXTENDED_AWAY;
609 case TP_CONNECTION_PRESENCE_TYPE_HIDDEN:
610 return MC_PRESENCE_HIDDEN;
611 case TP_CONNECTION_PRESENCE_TYPE_BUSY:
612 return MC_PRESENCE_DO_NOT_DISTURB;
615 return MC_PRESENCE_UNSET;
619 empathy_contact_get_presence (EmpathyContact *contact)
621 EmpathyContactPriv *priv;
623 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), MC_PRESENCE_UNSET);
625 priv = GET_PRIV (contact);
627 if (priv->tp_contact != NULL)
628 return presence_type_to_mc_presence (tp_contact_get_presence_type (
631 return priv->presence;
635 empathy_contact_set_presence (EmpathyContact *contact,
638 EmpathyContactPriv *priv;
639 McPresence old_presence;
641 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
643 priv = GET_PRIV (contact);
645 if (presence == priv->presence)
648 old_presence = priv->presence;
649 priv->presence = presence;
651 g_signal_emit (contact, signals[PRESENCE_CHANGED], 0, presence, old_presence);
653 g_object_notify (G_OBJECT (contact), "presence");
657 empathy_contact_get_presence_message (EmpathyContact *contact)
659 EmpathyContactPriv *priv;
661 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
663 priv = GET_PRIV (contact);
665 if (priv->tp_contact != NULL)
666 return tp_contact_get_presence_message (priv->tp_contact);
668 return priv->presence_message;
672 empathy_contact_set_presence_message (EmpathyContact *contact,
673 const gchar *message)
675 EmpathyContactPriv *priv = GET_PRIV (contact);
677 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
679 if (!tp_strdiff (message, priv->presence_message))
682 g_free (priv->presence_message);
683 priv->presence_message = g_strdup (message);
685 g_object_notify (G_OBJECT (contact), "presence-message");
689 empathy_contact_get_handle (EmpathyContact *contact)
691 EmpathyContactPriv *priv;
693 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), 0);
695 priv = GET_PRIV (contact);
697 if (priv->tp_contact != NULL)
698 return tp_contact_get_handle (priv->tp_contact);
704 empathy_contact_set_handle (EmpathyContact *contact,
707 EmpathyContactPriv *priv;
709 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
711 priv = GET_PRIV (contact);
713 g_object_ref (contact);
714 if (handle != priv->handle)
716 priv->handle = handle;
717 g_object_notify (G_OBJECT (contact), "handle");
719 g_object_unref (contact);
723 empathy_contact_get_capabilities (EmpathyContact *contact)
725 EmpathyContactPriv *priv;
727 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), 0);
729 priv = GET_PRIV (contact);
731 return priv->capabilities;
735 empathy_contact_set_capabilities (EmpathyContact *contact,
736 EmpathyCapabilities capabilities)
738 EmpathyContactPriv *priv;
740 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
742 priv = GET_PRIV (contact);
744 if (priv->capabilities == capabilities)
747 priv->capabilities = capabilities;
749 g_object_notify (G_OBJECT (contact), "capabilities");
753 empathy_contact_is_user (EmpathyContact *contact)
755 EmpathyContactPriv *priv;
757 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
759 priv = GET_PRIV (contact);
761 return priv->is_user;
765 empathy_contact_set_is_user (EmpathyContact *contact,
768 EmpathyContactPriv *priv;
770 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
772 priv = GET_PRIV (contact);
774 if (priv->is_user == is_user)
777 priv->is_user = is_user;
779 g_object_notify (G_OBJECT (contact), "is-user");
783 empathy_contact_is_online (EmpathyContact *contact)
785 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
787 return (empathy_contact_get_presence (contact) > MC_PRESENCE_OFFLINE);
791 empathy_contact_get_status (EmpathyContact *contact)
793 const gchar *message;
795 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), "");
797 message = empathy_contact_get_presence_message (contact);
798 if (!EMP_STR_EMPTY (message))
801 return empathy_presence_get_default_message (
802 empathy_contact_get_presence (contact));
806 empathy_contact_can_voip (EmpathyContact *contact)
808 EmpathyContactPriv *priv;
810 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
812 priv = GET_PRIV (contact);
814 return priv->capabilities & (EMPATHY_CAPABILITIES_AUDIO |
815 EMPATHY_CAPABILITIES_VIDEO);
819 empathy_contact_can_send_files (EmpathyContact *contact)
821 EmpathyContactPriv *priv;
823 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
825 priv = GET_PRIV (contact);
827 return priv->capabilities & EMPATHY_CAPABILITIES_FT;
831 contact_get_avatar_filename (EmpathyContact *contact,
834 EmpathyContactPriv *priv = GET_PRIV (contact);
838 gchar *token_escaped;
839 gchar *contact_escaped;
841 if (EMP_STR_EMPTY (priv->id))
844 contact_escaped = tp_escape_as_identifier (priv->id);
845 token_escaped = tp_escape_as_identifier (token);
846 account = empathy_contact_get_account (contact);
848 /* FIXME: Do not use the account, but proto/cm instead */
849 avatar_path = g_build_filename (g_get_user_cache_dir (),
852 mc_account_get_unique_name (account),
855 g_mkdir_with_parents (avatar_path, 0700);
857 avatar_file = g_build_filename (avatar_path, token_escaped, NULL);
859 g_free (contact_escaped);
860 g_free (token_escaped);
861 g_free (avatar_path);
867 empathy_contact_load_avatar_data (EmpathyContact *contact,
873 EmpathyAvatar *avatar;
875 GError *error = NULL;
877 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
878 g_return_if_fail (data != NULL);
879 g_return_if_fail (len > 0);
880 g_return_if_fail (format != NULL);
881 g_return_if_fail (!EMP_STR_EMPTY (token));
883 /* Load and set the avatar */
884 avatar = empathy_avatar_new (g_memdup (data, len), len, g_strdup (format),
886 empathy_contact_set_avatar (contact, avatar);
887 empathy_avatar_unref (avatar);
889 /* Save to cache if not yet in it */
890 filename = contact_get_avatar_filename (contact, token);
891 if (filename && !g_file_test (filename, G_FILE_TEST_EXISTS))
893 if (!empathy_avatar_save_to_file (avatar, filename, &error))
895 DEBUG ("Failed to save avatar in cache: %s",
896 error ? error->message : "No error given");
897 g_clear_error (&error);
900 DEBUG ("Avatar saved to %s", filename);
906 empathy_contact_load_avatar_cache (EmpathyContact *contact,
909 EmpathyAvatar *avatar = NULL;
913 GError *error = NULL;
915 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
916 g_return_val_if_fail (!EMP_STR_EMPTY (token), FALSE);
918 /* Load the avatar from file if it exists */
919 filename = contact_get_avatar_filename (contact, token);
920 if (filename && g_file_test (filename, G_FILE_TEST_EXISTS))
922 if (!g_file_get_contents (filename, &data, &len, &error))
924 DEBUG ("Failed to load avatar from cache: %s",
925 error ? error->message : "No error given");
926 g_clear_error (&error);
932 DEBUG ("Avatar loaded from %s", filename);
933 avatar = empathy_avatar_new (data, len, NULL, g_strdup (token));
934 empathy_contact_set_avatar (contact, avatar);
935 empathy_avatar_unref (avatar);
944 empathy_avatar_get_type (void)
946 static GType type_id = 0;
950 type_id = g_boxed_type_register_static ("EmpathyAvatar",
951 (GBoxedCopyFunc) empathy_avatar_ref,
952 (GBoxedFreeFunc) empathy_avatar_unref);
959 empathy_avatar_new (guchar *data,
964 EmpathyAvatar *avatar;
966 avatar = g_slice_new0 (EmpathyAvatar);
969 avatar->format = format;
970 avatar->token = token;
971 avatar->refcount = 1;
977 empathy_avatar_unref (EmpathyAvatar *avatar)
979 g_return_if_fail (avatar != NULL);
982 if (avatar->refcount == 0)
984 g_free (avatar->data);
985 g_free (avatar->format);
986 g_free (avatar->token);
987 g_slice_free (EmpathyAvatar, avatar);
992 empathy_avatar_ref (EmpathyAvatar *avatar)
994 g_return_val_if_fail (avatar != NULL, NULL);
1002 * empathy_avatar_save_to_file:
1003 * @avatar: the avatar
1004 * @filename: name of a file to write avatar to
1005 * @error: return location for a GError, or NULL
1007 * Save the avatar to a file named filename
1009 * Returns: %TRUE on success, %FALSE if an error occurred
1012 empathy_avatar_save_to_file (EmpathyAvatar *self,
1013 const gchar *filename,
1016 return g_file_set_contents (filename, self->data, self->len, error);
1020 * empathy_contact_get_location:
1021 * @contact: the contact
1023 * Returns the user's location if available. The keys are defined in
1024 * empathy-location.h. If the contact doesn't have location
1025 * information, the GHashTable will be empthy.
1027 * Returns: a #GHashTable of location values
1030 empathy_contact_get_location (EmpathyContact *contact)
1032 EmpathyContactPriv *priv;
1034 g_return_val_if_fail (EMPATHY_CONTACT (contact), NULL);
1036 priv = GET_PRIV (contact);
1038 return priv->location;
1042 * empathy_contact_set_location:
1043 * @contact: the contact
1044 * @location: the location
1046 * Sets the user's location based on the location #GHashTable passed.
1049 empathy_contact_set_location (EmpathyContact *contact,
1050 GHashTable *location)
1052 EmpathyContactPriv *priv;
1054 g_return_if_fail (EMPATHY_CONTACT (contact));
1055 g_return_if_fail (location != NULL);
1057 priv = GET_PRIV (contact);
1059 g_hash_table_unref (priv->location);
1061 priv->location = g_hash_table_ref (location);
1062 g_object_notify (G_OBJECT (contact), "location");