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>
30 #include "empathy-contact.h"
31 #include "empathy-account-manager.h"
32 #include "empathy-utils.h"
33 #include "empathy-enum-types.h"
34 #include "empathy-marshal.h"
36 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
37 #include "empathy-debug.h"
39 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyContact)
41 TpContact *tp_contact;
42 EmpathyAccount *account;
45 EmpathyAvatar *avatar;
46 TpConnectionPresenceType presence;
47 gchar *presence_message;
49 EmpathyCapabilities capabilities;
52 /* Location is composed of string keys and GValues.
53 * Example: a "city" key would have "Helsinki" as string GValue,
54 * a "latitude" would have 65.0 as double GValue.
59 static void contact_finalize (GObject *object);
60 static void contact_get_property (GObject *object, guint param_id,
61 GValue *value, GParamSpec *pspec);
62 static void contact_set_property (GObject *object, guint param_id,
63 const GValue *value, GParamSpec *pspec);
65 G_DEFINE_TYPE (EmpathyContact, empathy_contact, G_TYPE_OBJECT);
76 PROP_PRESENCE_MESSAGE,
88 static guint signals[LAST_SIGNAL];
91 tp_contact_notify_cb (TpContact *tp_contact,
95 EmpathyContactPriv *priv = GET_PRIV (contact);
97 /* Forward property notifications */
98 if (!tp_strdiff (param->name, "alias"))
99 g_object_notify (contact, "name");
100 else if (!tp_strdiff (param->name, "presence-type")) {
101 TpConnectionPresenceType presence;
103 presence = empathy_contact_get_presence (EMPATHY_CONTACT (contact));
104 g_signal_emit (contact, signals[PRESENCE_CHANGED], 0, 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",
162 EMPATHY_TYPE_ACCOUNT,
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",
194 TP_CONNECTION_PRESENCE_TYPE_UNSET,
195 NUM_TP_CONNECTION_PRESENCE_TYPES,
196 TP_CONNECTION_PRESENCE_TYPE_UNSET,
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__UINT_UINT,
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 = NULL;
269 contact_finalize (GObject *object)
271 EmpathyContactPriv *priv;
273 priv = GET_PRIV (object);
275 DEBUG ("finalize: %p", object);
279 g_free (priv->presence_message);
282 empathy_avatar_unref (priv->avatar);
284 if (priv->location != NULL)
285 g_hash_table_unref (priv->location);
287 G_OBJECT_CLASS (empathy_contact_parent_class)->finalize (object);
291 set_tp_contact (EmpathyContact *contact,
292 TpContact *tp_contact)
294 EmpathyContactPriv *priv = GET_PRIV (contact);
296 if (tp_contact == NULL)
299 g_assert (priv->tp_contact == NULL);
300 priv->tp_contact = g_object_ref (tp_contact);
301 priv->presence = empathy_contact_get_presence (contact);
303 g_signal_connect (priv->tp_contact, "notify",
304 G_CALLBACK (tp_contact_notify_cb), contact);
308 contact_get_property (GObject *object,
313 EmpathyContact *contact = EMPATHY_CONTACT (object);
317 case PROP_TP_CONTACT:
318 g_value_set_object (value, empathy_contact_get_tp_contact (contact));
321 g_value_set_object (value, empathy_contact_get_account (contact));
324 g_value_set_string (value, empathy_contact_get_id (contact));
327 g_value_set_string (value, empathy_contact_get_name (contact));
330 g_value_set_boxed (value, empathy_contact_get_avatar (contact));
333 g_value_set_uint (value, empathy_contact_get_presence (contact));
335 case PROP_PRESENCE_MESSAGE:
336 g_value_set_string (value, empathy_contact_get_presence_message (contact));
339 g_value_set_uint (value, empathy_contact_get_handle (contact));
341 case PROP_CAPABILITIES:
342 g_value_set_flags (value, empathy_contact_get_capabilities (contact));
345 g_value_set_boolean (value, empathy_contact_is_user (contact));
348 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
354 contact_set_property (GObject *object,
359 EmpathyContact *contact = EMPATHY_CONTACT (object);
360 EmpathyContactPriv *priv = GET_PRIV (object);
364 case PROP_TP_CONTACT:
365 set_tp_contact (contact, g_value_get_object (value));
368 g_assert (priv->account == NULL);
369 priv->account = g_value_dup_object (value);
372 empathy_contact_set_id (contact, g_value_get_string (value));
375 empathy_contact_set_name (contact, g_value_get_string (value));
378 empathy_contact_set_avatar (contact, g_value_get_boxed (value));
381 empathy_contact_set_presence (contact, g_value_get_uint (value));
383 case PROP_PRESENCE_MESSAGE:
384 empathy_contact_set_presence_message (contact, g_value_get_string (value));
387 empathy_contact_set_handle (contact, g_value_get_uint (value));
389 case PROP_CAPABILITIES:
390 empathy_contact_set_capabilities (contact, g_value_get_flags (value));
393 empathy_contact_set_is_user (contact, g_value_get_boolean (value));
396 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
402 empathy_contact_new (TpContact *tp_contact)
404 g_return_val_if_fail (TP_IS_CONTACT (tp_contact), NULL);
406 return g_object_new (EMPATHY_TYPE_CONTACT,
407 "tp-contact", tp_contact,
412 empathy_contact_new_for_log (EmpathyAccount *account,
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_for_connection (
574 manager, connection);
575 g_object_ref (priv->account);
576 g_object_unref (manager);
579 return priv->account;
583 empathy_contact_get_connection (EmpathyContact *contact)
585 EmpathyContactPriv *priv;
587 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
589 priv = GET_PRIV (contact);
591 if (priv->tp_contact != NULL)
592 return tp_contact_get_connection (priv->tp_contact);
597 TpConnectionPresenceType
598 empathy_contact_get_presence (EmpathyContact *contact)
600 EmpathyContactPriv *priv;
602 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact),
603 TP_CONNECTION_PRESENCE_TYPE_UNSET);
605 priv = GET_PRIV (contact);
607 if (priv->tp_contact != NULL)
608 return tp_contact_get_presence_type (priv->tp_contact);
610 return priv->presence;
614 empathy_contact_set_presence (EmpathyContact *contact,
615 TpConnectionPresenceType presence)
617 EmpathyContactPriv *priv;
618 TpConnectionPresenceType old_presence;
620 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
622 priv = GET_PRIV (contact);
624 if (presence == priv->presence)
627 old_presence = priv->presence;
628 priv->presence = presence;
630 g_signal_emit (contact, signals[PRESENCE_CHANGED], 0, presence, old_presence);
632 g_object_notify (G_OBJECT (contact), "presence");
636 empathy_contact_get_presence_message (EmpathyContact *contact)
638 EmpathyContactPriv *priv;
640 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
642 priv = GET_PRIV (contact);
644 if (priv->tp_contact != NULL)
645 return tp_contact_get_presence_message (priv->tp_contact);
647 return priv->presence_message;
651 empathy_contact_set_presence_message (EmpathyContact *contact,
652 const gchar *message)
654 EmpathyContactPriv *priv = GET_PRIV (contact);
656 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
658 if (!tp_strdiff (message, priv->presence_message))
661 g_free (priv->presence_message);
662 priv->presence_message = g_strdup (message);
664 g_object_notify (G_OBJECT (contact), "presence-message");
668 empathy_contact_get_handle (EmpathyContact *contact)
670 EmpathyContactPriv *priv;
672 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), 0);
674 priv = GET_PRIV (contact);
676 if (priv->tp_contact != NULL)
677 return tp_contact_get_handle (priv->tp_contact);
683 empathy_contact_set_handle (EmpathyContact *contact,
686 EmpathyContactPriv *priv;
688 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
690 priv = GET_PRIV (contact);
692 g_object_ref (contact);
693 if (handle != priv->handle)
695 priv->handle = handle;
696 g_object_notify (G_OBJECT (contact), "handle");
698 g_object_unref (contact);
702 empathy_contact_get_capabilities (EmpathyContact *contact)
704 EmpathyContactPriv *priv;
706 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), 0);
708 priv = GET_PRIV (contact);
710 return priv->capabilities;
714 empathy_contact_set_capabilities (EmpathyContact *contact,
715 EmpathyCapabilities capabilities)
717 EmpathyContactPriv *priv;
719 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
721 priv = GET_PRIV (contact);
723 if (priv->capabilities == capabilities)
726 priv->capabilities = capabilities;
728 g_object_notify (G_OBJECT (contact), "capabilities");
732 empathy_contact_is_user (EmpathyContact *contact)
734 EmpathyContactPriv *priv;
736 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
738 priv = GET_PRIV (contact);
740 return priv->is_user;
744 empathy_contact_set_is_user (EmpathyContact *contact,
747 EmpathyContactPriv *priv;
749 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
751 priv = GET_PRIV (contact);
753 if (priv->is_user == is_user)
756 priv->is_user = is_user;
758 g_object_notify (G_OBJECT (contact), "is-user");
762 empathy_contact_is_online (EmpathyContact *contact)
764 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
766 switch (empathy_contact_get_presence (contact))
768 case TP_CONNECTION_PRESENCE_TYPE_OFFLINE:
769 case TP_CONNECTION_PRESENCE_TYPE_UNKNOWN:
770 case TP_CONNECTION_PRESENCE_TYPE_ERROR:
778 empathy_contact_get_status (EmpathyContact *contact)
780 const gchar *message;
782 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), "");
784 message = empathy_contact_get_presence_message (contact);
785 if (!EMP_STR_EMPTY (message))
788 return empathy_presence_get_default_message (
789 empathy_contact_get_presence (contact));
793 empathy_contact_can_voip (EmpathyContact *contact)
795 EmpathyContactPriv *priv;
797 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
799 priv = GET_PRIV (contact);
801 return priv->capabilities & (EMPATHY_CAPABILITIES_AUDIO |
802 EMPATHY_CAPABILITIES_VIDEO);
806 empathy_contact_can_voip_audio (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;
818 empathy_contact_can_voip_video (EmpathyContact *contact)
820 EmpathyContactPriv *priv;
822 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
824 priv = GET_PRIV (contact);
826 return priv->capabilities & EMPATHY_CAPABILITIES_VIDEO;
830 empathy_contact_can_send_files (EmpathyContact *contact)
832 EmpathyContactPriv *priv;
834 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
836 priv = GET_PRIV (contact);
838 return priv->capabilities & EMPATHY_CAPABILITIES_FT;
842 empathy_contact_can_use_stream_tube (EmpathyContact *contact)
844 EmpathyContactPriv *priv;
846 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
848 priv = GET_PRIV (contact);
850 return priv->capabilities & EMPATHY_CAPABILITIES_STREAM_TUBE;
854 contact_get_avatar_filename (EmpathyContact *contact,
857 EmpathyAccount *account;
860 gchar *token_escaped;
861 gchar *contact_escaped;
863 if (EMP_STR_EMPTY (empathy_contact_get_id (contact)))
866 contact_escaped = tp_escape_as_identifier (empathy_contact_get_id (contact));
867 token_escaped = tp_escape_as_identifier (token);
868 account = empathy_contact_get_account (contact);
870 /* FIXME: Do not use the account, but proto/cm instead */
871 avatar_path = g_build_filename (g_get_user_cache_dir (),
874 empathy_account_get_unique_name (account),
877 g_mkdir_with_parents (avatar_path, 0700);
879 avatar_file = g_build_filename (avatar_path, token_escaped, NULL);
881 g_free (contact_escaped);
882 g_free (token_escaped);
883 g_free (avatar_path);
889 empathy_contact_load_avatar_data (EmpathyContact *contact,
895 EmpathyAvatar *avatar;
897 GError *error = NULL;
899 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
900 g_return_if_fail (data != NULL);
901 g_return_if_fail (len > 0);
902 g_return_if_fail (format != NULL);
903 g_return_if_fail (!EMP_STR_EMPTY (token));
905 /* Load and set the avatar */
906 filename = contact_get_avatar_filename (contact, token);
907 avatar = empathy_avatar_new (g_memdup (data, len), len, g_strdup (format),
908 g_strdup (token), filename);
909 empathy_contact_set_avatar (contact, avatar);
910 empathy_avatar_unref (avatar);
912 /* Save to cache if not yet in it */
913 if (filename && !g_file_test (filename, G_FILE_TEST_EXISTS))
915 if (!empathy_avatar_save_to_file (avatar, filename, &error))
917 DEBUG ("Failed to save avatar in cache: %s",
918 error ? error->message : "No error given");
919 g_clear_error (&error);
922 DEBUG ("Avatar saved to %s", filename);
927 empathy_contact_load_avatar_cache (EmpathyContact *contact,
930 EmpathyAvatar *avatar = NULL;
934 GError *error = NULL;
936 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
937 g_return_val_if_fail (!EMP_STR_EMPTY (token), FALSE);
939 /* Load the avatar from file if it exists */
940 filename = contact_get_avatar_filename (contact, token);
941 if (filename && g_file_test (filename, G_FILE_TEST_EXISTS))
943 if (!g_file_get_contents (filename, &data, &len, &error))
945 DEBUG ("Failed to load avatar from cache: %s",
946 error ? error->message : "No error given");
947 g_clear_error (&error);
953 DEBUG ("Avatar loaded from %s", filename);
954 avatar = empathy_avatar_new (data, len, NULL, g_strdup (token), filename);
955 empathy_contact_set_avatar (contact, avatar);
956 empathy_avatar_unref (avatar);
963 empathy_avatar_get_type (void)
965 static GType type_id = 0;
969 type_id = g_boxed_type_register_static ("EmpathyAvatar",
970 (GBoxedCopyFunc) empathy_avatar_ref,
971 (GBoxedFreeFunc) empathy_avatar_unref);
978 * empathy_avatar_new:
979 * @data: the avatar data
980 * @len: the size of avatar data
981 * @format: the mime type of the avatar image
982 * @token: the token of the avatar
983 * @filename: the filename where the avatar is stored in cache
985 * Create a #EmpathyAvatar from the provided data. This function takes the
986 * ownership of @data, @format, @token and @filename.
988 * Returns: a new #EmpathyAvatar
991 empathy_avatar_new (guchar *data,
997 EmpathyAvatar *avatar;
999 avatar = g_slice_new0 (EmpathyAvatar);
1000 avatar->data = data;
1002 avatar->format = format;
1003 avatar->token = token;
1004 avatar->filename = filename;
1005 avatar->refcount = 1;
1011 empathy_avatar_unref (EmpathyAvatar *avatar)
1013 g_return_if_fail (avatar != NULL);
1016 if (avatar->refcount == 0)
1018 g_free (avatar->data);
1019 g_free (avatar->format);
1020 g_free (avatar->token);
1021 g_slice_free (EmpathyAvatar, avatar);
1026 empathy_avatar_ref (EmpathyAvatar *avatar)
1028 g_return_val_if_fail (avatar != NULL, NULL);
1036 * empathy_avatar_save_to_file:
1037 * @avatar: the avatar
1038 * @filename: name of a file to write avatar to
1039 * @error: return location for a GError, or NULL
1041 * Save the avatar to a file named filename
1043 * Returns: %TRUE on success, %FALSE if an error occurred
1046 empathy_avatar_save_to_file (EmpathyAvatar *self,
1047 const gchar *filename,
1050 return g_file_set_contents (filename, self->data, self->len, error);
1054 * empathy_contact_get_location:
1055 * @contact: an #EmpathyContact
1057 * Returns the user's location if available. The keys are defined in
1058 * empathy-location.h. If the contact doesn't have location
1059 * information, the GHashTable will be empthy. Use #g_hash_table_unref when
1060 * you are done with the #GHashTable.
1062 * It is composed of string keys and GValues. Keys are
1063 * defined in empathy-location.h such as #EMPATHY_LOCATION_COUNTRY.
1064 * Example: a "city" key would have "Helsinki" as string GValue,
1065 * a "latitude" would have 65.0 as double GValue.
1067 * Returns: a #GHashTable of location values
1070 empathy_contact_get_location (EmpathyContact *contact)
1072 EmpathyContactPriv *priv;
1074 g_return_val_if_fail (EMPATHY_CONTACT (contact), NULL);
1076 priv = GET_PRIV (contact);
1078 return priv->location;
1082 * empathy_contact_set_location:
1083 * @contact: an #EmpathyContact
1084 * @location: a #GHashTable of the location
1086 * Sets the user's location based on the location #GHashTable passed.
1087 * It is composed of string keys and GValues. Keys are
1088 * defined in empathy-location.h such as #EMPATHY_LOCATION_COUNTRY.
1089 * Example: a "city" key would have "Helsinki" as string GValue,
1090 * a "latitude" would have 65.0 as double GValue.
1093 empathy_contact_set_location (EmpathyContact *contact,
1094 GHashTable *location)
1096 EmpathyContactPriv *priv;
1098 g_return_if_fail (EMPATHY_CONTACT (contact));
1099 g_return_if_fail (location != NULL);
1101 priv = GET_PRIV (contact);
1103 if (priv->location != NULL)
1104 g_hash_table_unref (priv->location);
1106 priv->location = g_hash_table_ref (location);
1107 g_object_notify (G_OBJECT (contact), "location");
1111 * empathy_contact_equal:
1112 * @contact1: an #EmpathyContact
1113 * @contact2: an #EmpathyContact
1115 * Returns FALSE if one of the contacts is NULL but the other is not.
1116 * Otherwise returns TRUE if both pointer are equal or if they bith
1117 * refer to the same id.
1118 * It's only necessary to call this function if your contact objects
1119 * come from logs where contacts are created dynamically and comparing
1120 * pointers is not enough.
1123 empathy_contact_equal (gconstpointer contact1,
1124 gconstpointer contact2)
1131 if ((contact1 == NULL) != (contact2 == NULL)) {
1134 if (contact1 == contact2) {
1137 c1 = EMPATHY_CONTACT (contact1);
1138 c2 = EMPATHY_CONTACT (contact2);
1139 id1 = empathy_contact_get_id (c1);
1140 id2 = empathy_contact_get_id (c2);
1141 if (!tp_strdiff (id1, id2)) {