1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
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 <telepathy-glib/util.h>
27 #include <telepathy-glib/gtypes.h>
28 #include <telepathy-glib/dbus.h>
29 #include <telepathy-glib/interfaces.h>
31 #include <extensions/extensions.h>
33 #include "empathy-tp-contact-factory.h"
34 #include "empathy-utils.h"
36 #define DEBUG_FLAG EMPATHY_DEBUG_TP | EMPATHY_DEBUG_CONTACT
37 #include "empathy-debug.h"
39 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyTpContactFactory)
41 TpConnection *connection;
44 gchar **avatar_mime_types;
45 guint avatar_min_width;
46 guint avatar_min_height;
47 guint avatar_max_width;
48 guint avatar_max_height;
49 guint avatar_max_size;
50 } EmpathyTpContactFactoryPriv;
52 G_DEFINE_TYPE (EmpathyTpContactFactory, empathy_tp_contact_factory, G_TYPE_OBJECT);
66 static TpContactFeature contact_features[] = {
67 TP_CONTACT_FEATURE_ALIAS,
68 TP_CONTACT_FEATURE_PRESENCE,
69 TP_CONTACT_FEATURE_LOCATION,
70 TP_CONTACT_FEATURE_CAPABILITIES,
73 static EmpathyContact *
74 tp_contact_factory_find_by_handle (EmpathyTpContactFactory *tp_factory,
77 EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
80 for (l = priv->contacts; l; l = l->next) {
81 if (empathy_contact_get_handle (l->data) == handle) {
89 static EmpathyContact *
90 tp_contact_factory_find_by_tp_contact (EmpathyTpContactFactory *tp_factory,
91 TpContact *tp_contact)
93 EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
96 for (l = priv->contacts; l; l = l->next) {
97 if (empathy_contact_get_tp_contact (l->data) == tp_contact) {
106 tp_contact_factory_weak_notify (gpointer data,
107 GObject *where_the_object_was)
109 EmpathyTpContactFactoryPriv *priv = GET_PRIV (data);
111 DEBUG ("Remove finalized contact %p", where_the_object_was);
113 priv->contacts = g_list_remove (priv->contacts, where_the_object_was);
117 tp_contact_factory_set_aliases_cb (TpConnection *connection,
123 DEBUG ("Error: %s", error->message);
128 tp_contact_factory_avatar_retrieved_cb (TpConnection *connection,
131 const GArray *avatar_data,
132 const gchar *mime_type,
136 EmpathyContact *contact;
138 contact = tp_contact_factory_find_by_handle (EMPATHY_TP_CONTACT_FACTORY (tp_factory),
144 DEBUG ("Avatar retrieved for contact %s (%d)",
145 empathy_contact_get_id (contact),
148 empathy_contact_load_avatar_data (contact,
149 (guchar *) avatar_data->data,
156 tp_contact_factory_request_avatars_cb (TpConnection *connection,
162 DEBUG ("Error: %s", error->message);
167 tp_contact_factory_avatar_maybe_update (EmpathyTpContactFactory *tp_factory,
171 EmpathyContact *contact;
172 EmpathyAvatar *avatar;
174 contact = tp_contact_factory_find_by_handle (tp_factory, handle);
179 /* Check if we have an avatar */
180 if (EMP_STR_EMPTY (token)) {
181 empathy_contact_set_avatar (contact, NULL);
185 /* Check if the avatar changed */
186 avatar = empathy_contact_get_avatar (contact);
187 if (avatar && !tp_strdiff (avatar->token, token)) {
191 /* The avatar changed, search the new one in the cache */
192 if (empathy_contact_load_avatar_cache (contact, token)) {
193 /* Got from cache, use it */
197 /* Avatar is not up-to-date, we have to request it. */
202 tp_contact_factory_got_known_avatar_tokens (TpConnection *connection,
206 GObject *weak_object)
208 EmpathyTpContactFactory *tp_factory = EMPATHY_TP_CONTACT_FACTORY (weak_object);
209 EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
215 DEBUG ("Error: %s", error->message);
219 handles = g_array_new (FALSE, FALSE, sizeof (guint));
221 g_hash_table_iter_init (&iter, tokens);
222 while (g_hash_table_iter_next (&iter, &key, &value)) {
223 guint handle = GPOINTER_TO_UINT (key);
224 const gchar *token = value;
226 if (!tp_contact_factory_avatar_maybe_update (tp_factory,
228 g_array_append_val (handles, handle);
232 DEBUG ("Got %d tokens, need to request %d avatars",
233 g_hash_table_size (tokens), handles->len);
235 /* Request needed avatars */
236 if (handles->len > 0) {
237 tp_cli_connection_interface_avatars_call_request_avatars (priv->connection,
240 tp_contact_factory_request_avatars_cb,
242 G_OBJECT (tp_factory));
245 g_array_free (handles, TRUE);
249 tp_contact_factory_avatar_updated_cb (TpConnection *connection,
251 const gchar *new_token,
257 if (tp_contact_factory_avatar_maybe_update (EMPATHY_TP_CONTACT_FACTORY (tp_factory),
258 handle, new_token)) {
259 /* Avatar was cached, nothing to do */
263 DEBUG ("Need to request avatar for token %s", new_token);
265 handles = g_array_new (FALSE, FALSE, sizeof (guint));
266 g_array_append_val (handles, handle);
268 tp_cli_connection_interface_avatars_call_request_avatars (connection,
271 tp_contact_factory_request_avatars_cb,
274 g_array_free (handles, TRUE);
278 tp_contact_factory_got_avatar_requirements_cb (TpConnection *proxy,
279 const gchar **mime_types,
289 EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
292 DEBUG ("Failed to get avatar requirements: %s", error->message);
293 /* We'll just leave avatar_mime_types as NULL; the
294 * avatar-setting code can use this as a signal that you can't
298 priv->avatar_mime_types = g_strdupv ((gchar **) mime_types);
299 priv->avatar_min_width = min_width;
300 priv->avatar_min_height = min_height;
301 priv->avatar_max_width = max_width;
302 priv->avatar_max_height = max_height;
303 priv->avatar_max_size = max_size;
308 tp_contact_factory_add_contact (EmpathyTpContactFactory *tp_factory,
309 EmpathyContact *contact)
311 EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
312 TpHandle self_handle;
314 GArray handles = {(gchar *) &handle, 1};
316 /* Keep a weak ref to that contact */
317 g_object_weak_ref (G_OBJECT (contact),
318 tp_contact_factory_weak_notify,
320 priv->contacts = g_list_prepend (priv->contacts, contact);
322 /* The contact keeps a ref to its factory */
323 g_object_set_data_full (G_OBJECT (contact), "empathy-factory",
324 g_object_ref (tp_factory),
327 /* Set is-user property. Note that it could still be the handle is
328 * different from the connection's self handle, in the case the handle
329 * comes from a group interface. */
330 self_handle = tp_connection_get_self_handle (priv->connection);
331 handle = empathy_contact_get_handle (contact);
332 empathy_contact_set_is_user (contact, self_handle == handle);
334 /* FIXME: This should be done by TpContact */
335 if (tp_proxy_has_interface_by_id (priv->connection,
336 TP_IFACE_QUARK_CONNECTION_INTERFACE_AVATARS)) {
337 tp_cli_connection_interface_avatars_call_get_known_avatar_tokens (
338 priv->connection, -1, &handles,
339 tp_contact_factory_got_known_avatar_tokens, NULL, NULL,
340 G_OBJECT (tp_factory));
343 DEBUG ("Contact added: %s (%d)",
344 empathy_contact_get_id (contact),
345 empathy_contact_get_handle (contact));
349 EmpathyTpContactFactoryContactsByIdCb ids_cb;
350 EmpathyTpContactFactoryContactsByHandleCb handles_cb;
351 EmpathyTpContactFactoryContactCb contact_cb;
355 EmpathyTpContactFactory *tp_factory;
356 GetContactsCb callback;
358 GDestroyNotify destroy;
362 get_contacts_data_free (gpointer user_data)
364 GetContactsData *data = user_data;
367 data->destroy (data->user_data);
369 g_object_unref (data->tp_factory);
371 g_slice_free (GetContactsData, data);
374 static EmpathyContact *
375 dup_contact_for_tp_contact (EmpathyTpContactFactory *tp_factory,
376 TpContact *tp_contact)
378 EmpathyContact *contact;
380 contact = tp_contact_factory_find_by_tp_contact (tp_factory,
383 if (contact != NULL) {
384 g_object_ref (contact);
386 contact = empathy_contact_new (tp_contact);
387 tp_contact_factory_add_contact (tp_factory, contact);
393 static EmpathyContact **
394 contacts_array_new (EmpathyTpContactFactory *tp_factory,
396 TpContact * const * contacts)
398 EmpathyContact **ret;
401 ret = g_new0 (EmpathyContact *, n_contacts);
402 for (i = 0; i < n_contacts; i++) {
403 ret[i] = dup_contact_for_tp_contact (tp_factory, contacts[i]);
410 contacts_array_free (guint n_contacts,
411 EmpathyContact **contacts)
415 for (i = 0; i < n_contacts; i++) {
416 g_object_unref (contacts[i]);
422 get_contacts_by_id_cb (TpConnection *connection,
424 TpContact * const *contacts,
425 const gchar * const *requested_ids,
426 GHashTable *failed_id_errors,
429 GObject *weak_object)
431 GetContactsData *data = user_data;
432 EmpathyContact **empathy_contacts;
434 empathy_contacts = contacts_array_new (data->tp_factory,
435 n_contacts, contacts);
436 if (data->callback.ids_cb) {
437 data->callback.ids_cb (data->tp_factory,
438 n_contacts, empathy_contacts,
442 data->user_data, weak_object);
445 contacts_array_free (n_contacts, empathy_contacts);
448 /* The callback is NOT given a reference to the EmpathyContact objects */
450 empathy_tp_contact_factory_get_from_ids (EmpathyTpContactFactory *tp_factory,
452 const gchar * const *ids,
453 EmpathyTpContactFactoryContactsByIdCb callback,
455 GDestroyNotify destroy,
456 GObject *weak_object)
458 EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
459 GetContactsData *data;
461 g_return_if_fail (EMPATHY_IS_TP_CONTACT_FACTORY (tp_factory));
462 g_return_if_fail (ids != NULL);
464 data = g_slice_new (GetContactsData);
465 data->callback.ids_cb = callback;
466 data->user_data = user_data;
467 data->destroy = destroy;
468 data->tp_factory = g_object_ref (tp_factory);
469 tp_connection_get_contacts_by_id (priv->connection,
471 G_N_ELEMENTS (contact_features),
473 get_contacts_by_id_cb,
475 (GDestroyNotify) get_contacts_data_free,
480 get_contact_by_id_cb (TpConnection *connection,
482 TpContact * const *contacts,
483 const gchar * const *requested_ids,
484 GHashTable *failed_id_errors,
487 GObject *weak_object)
489 GetContactsData *data = user_data;
490 EmpathyContact *contact = NULL;
492 if (n_contacts == 1) {
493 contact = dup_contact_for_tp_contact (data->tp_factory,
496 else if (error == NULL) {
500 g_hash_table_iter_init (&iter, failed_id_errors);
501 while (g_hash_table_iter_next (&iter, NULL, &value)) {
509 if (data->callback.contact_cb) {
510 data->callback.contact_cb (data->tp_factory,
513 data->user_data, weak_object);
517 g_object_unref (contact);
520 /* The callback is NOT given a reference to the EmpathyContact objects */
522 empathy_tp_contact_factory_get_from_id (EmpathyTpContactFactory *tp_factory,
524 EmpathyTpContactFactoryContactCb callback,
526 GDestroyNotify destroy,
527 GObject *weak_object)
529 EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
530 GetContactsData *data;
532 g_return_if_fail (EMPATHY_IS_TP_CONTACT_FACTORY (tp_factory));
533 g_return_if_fail (id != NULL);
535 data = g_slice_new (GetContactsData);
536 data->callback.contact_cb = callback;
537 data->user_data = user_data;
538 data->destroy = destroy;
539 data->tp_factory = g_object_ref (tp_factory);
540 tp_connection_get_contacts_by_id (priv->connection,
542 G_N_ELEMENTS (contact_features),
544 get_contact_by_id_cb,
546 (GDestroyNotify) get_contacts_data_free,
551 get_contacts_by_handle_cb (TpConnection *connection,
553 TpContact * const *contacts,
555 const TpHandle *failed,
558 GObject *weak_object)
560 GetContactsData *data = user_data;
561 EmpathyContact **empathy_contacts;
563 empathy_contacts = contacts_array_new (data->tp_factory,
564 n_contacts, contacts);
565 if (data->callback.handles_cb) {
566 data->callback.handles_cb (data->tp_factory,
567 n_contacts, empathy_contacts,
570 data->user_data, weak_object);
573 contacts_array_free (n_contacts, empathy_contacts);
576 /* The callback is NOT given a reference to the EmpathyContact objects */
578 empathy_tp_contact_factory_get_from_handles (EmpathyTpContactFactory *tp_factory,
580 const TpHandle *handles,
581 EmpathyTpContactFactoryContactsByHandleCb callback,
583 GDestroyNotify destroy,
584 GObject *weak_object)
586 EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
587 GetContactsData *data;
589 if (n_handles == 0) {
590 callback (tp_factory, 0, NULL, 0, NULL, NULL, user_data, weak_object);
594 g_return_if_fail (EMPATHY_IS_TP_CONTACT_FACTORY (tp_factory));
595 g_return_if_fail (handles != NULL);
597 data = g_slice_new (GetContactsData);
598 data->callback.handles_cb = callback;
599 data->user_data = user_data;
600 data->destroy = destroy;
601 data->tp_factory = g_object_ref (tp_factory);
602 tp_connection_get_contacts_by_handle (priv->connection,
604 G_N_ELEMENTS (contact_features),
606 get_contacts_by_handle_cb,
608 (GDestroyNotify) get_contacts_data_free,
612 /* The callback is NOT given a reference to the EmpathyContact objects */
614 get_contact_by_handle_cb (TpConnection *connection,
616 TpContact * const *contacts,
618 const TpHandle *failed,
621 GObject *weak_object)
623 GetContactsData *data = user_data;
624 EmpathyContact *contact = NULL;
627 if (n_contacts == 1) {
628 contact = dup_contact_for_tp_contact (data->tp_factory,
633 /* tp-glib will provide an error only if the whole operation failed,
634 * but not if, for example, the handle was invalid. We create an error
635 * so the caller of empathy_tp_contact_factory_get_from_handle can
636 * rely on the error to check if the operation succeeded or not. */
638 err = g_error_new_literal (TP_ERRORS, TP_ERROR_INVALID_HANDLE,
639 "handle is invalid");
642 err = g_error_copy (error);
646 if (data->callback.contact_cb) {
647 data->callback.contact_cb (data->tp_factory,
650 data->user_data, weak_object);
653 g_clear_error (&err);
655 g_object_unref (contact);
659 empathy_tp_contact_factory_get_from_handle (EmpathyTpContactFactory *tp_factory,
661 EmpathyTpContactFactoryContactCb callback,
663 GDestroyNotify destroy,
664 GObject *weak_object)
666 EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
667 GetContactsData *data;
669 g_return_if_fail (EMPATHY_IS_TP_CONTACT_FACTORY (tp_factory));
671 data = g_slice_new (GetContactsData);
672 data->callback.contact_cb = callback;
673 data->user_data = user_data;
674 data->destroy = destroy;
675 data->tp_factory = g_object_ref (tp_factory);
676 tp_connection_get_contacts_by_handle (priv->connection,
678 G_N_ELEMENTS (contact_features),
680 get_contact_by_handle_cb,
682 (GDestroyNotify) get_contacts_data_free,
687 empathy_tp_contact_factory_set_alias (EmpathyTpContactFactory *tp_factory,
688 EmpathyContact *contact,
691 EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
692 GHashTable *new_alias;
695 g_return_if_fail (EMPATHY_IS_TP_CONTACT_FACTORY (tp_factory));
696 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
698 handle = empathy_contact_get_handle (contact);
700 DEBUG ("Setting alias for contact %s (%d) to %s",
701 empathy_contact_get_id (contact),
704 new_alias = g_hash_table_new_full (g_direct_hash,
709 g_hash_table_insert (new_alias,
710 GUINT_TO_POINTER (handle),
713 tp_cli_connection_interface_aliasing_call_set_aliases (priv->connection,
716 tp_contact_factory_set_aliases_cb,
718 G_OBJECT (tp_factory));
720 g_hash_table_destroy (new_alias);
724 tp_contact_factory_get_property (GObject *object,
729 EmpathyTpContactFactoryPriv *priv = GET_PRIV (object);
732 case PROP_CONNECTION:
733 g_value_set_object (value, priv->connection);
735 case PROP_MIME_TYPES:
736 g_value_set_boxed (value, priv->avatar_mime_types);
739 g_value_set_uint (value, priv->avatar_min_width);
741 case PROP_MIN_HEIGHT:
742 g_value_set_uint (value, priv->avatar_min_height);
745 g_value_set_uint (value, priv->avatar_max_width);
747 case PROP_MAX_HEIGHT:
748 g_value_set_uint (value, priv->avatar_max_height);
751 g_value_set_uint (value, priv->avatar_max_size);
754 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
760 tp_contact_factory_set_property (GObject *object,
765 EmpathyTpContactFactoryPriv *priv = GET_PRIV (object);
768 case PROP_CONNECTION:
769 priv->connection = g_value_dup_object (value);
772 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
778 tp_contact_factory_finalize (GObject *object)
780 EmpathyTpContactFactoryPriv *priv = GET_PRIV (object);
783 DEBUG ("Finalized: %p", object);
785 for (l = priv->contacts; l; l = l->next) {
786 g_object_weak_unref (G_OBJECT (l->data),
787 tp_contact_factory_weak_notify,
791 g_list_free (priv->contacts);
793 g_object_unref (priv->connection);
795 g_strfreev (priv->avatar_mime_types);
797 G_OBJECT_CLASS (empathy_tp_contact_factory_parent_class)->finalize (object);
801 connection_ready_cb (TpConnection *connection,
805 EmpathyTpContactFactory *tp_factory = EMPATHY_TP_CONTACT_FACTORY (user_data);
806 EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
811 /* FIXME: This should be moved to TpContact */
812 tp_cli_connection_interface_avatars_connect_to_avatar_updated (priv->connection,
813 tp_contact_factory_avatar_updated_cb,
815 G_OBJECT (tp_factory),
817 tp_cli_connection_interface_avatars_connect_to_avatar_retrieved (priv->connection,
818 tp_contact_factory_avatar_retrieved_cb,
820 G_OBJECT (tp_factory),
823 tp_cli_connection_interface_avatars_call_get_avatar_requirements (priv->connection,
825 tp_contact_factory_got_avatar_requirements_cb,
827 G_OBJECT (tp_factory));
830 g_object_unref (tp_factory);
834 tp_contact_factory_constructor (GType type,
836 GObjectConstructParam *props)
839 EmpathyTpContactFactoryPriv *priv;
841 tp_factory = G_OBJECT_CLASS (empathy_tp_contact_factory_parent_class)->constructor (type, n_props, props);
842 priv = GET_PRIV (tp_factory);
844 /* Ensure to keep the self object alive while the call_when_ready is
846 g_object_ref (tp_factory);
847 tp_connection_call_when_ready (priv->connection, connection_ready_cb,
854 empathy_tp_contact_factory_class_init (EmpathyTpContactFactoryClass *klass)
856 GObjectClass *object_class = G_OBJECT_CLASS (klass);
858 object_class->finalize = tp_contact_factory_finalize;
859 object_class->constructor = tp_contact_factory_constructor;
860 object_class->get_property = tp_contact_factory_get_property;
861 object_class->set_property = tp_contact_factory_set_property;
863 g_object_class_install_property (object_class,
865 g_param_spec_object ("connection",
866 "Factory's Connection",
867 "The connection associated with the factory",
870 G_PARAM_CONSTRUCT_ONLY |
871 G_PARAM_STATIC_STRINGS));
872 g_object_class_install_property (object_class,
874 g_param_spec_boxed ("avatar-mime-types",
875 "Supported MIME types for avatars",
876 "Types of images that may be set as "
877 "avatars on this connection.",
880 G_PARAM_STATIC_STRINGS));
881 g_object_class_install_property (object_class,
883 g_param_spec_uint ("avatar-min-width",
884 "Minimum width for avatars",
885 "Minimum width of avatar that may be set.",
890 G_PARAM_STATIC_STRINGS));
891 g_object_class_install_property (object_class,
893 g_param_spec_uint ("avatar-min-height",
894 "Minimum height for avatars",
895 "Minimum height of avatar that may be set.",
900 G_PARAM_STATIC_STRINGS));
901 g_object_class_install_property (object_class,
903 g_param_spec_uint ("avatar-max-width",
904 "Maximum width for avatars",
905 "Maximum width of avatar that may be set "
906 "or 0 if there is no maximum.",
911 G_PARAM_STATIC_STRINGS));
912 g_object_class_install_property (object_class,
914 g_param_spec_uint ("avatar-max-height",
915 "Maximum height for avatars",
916 "Maximum height of avatar that may be set "
917 "or 0 if there is no maximum.",
922 G_PARAM_STATIC_STRINGS));
923 g_object_class_install_property (object_class,
925 g_param_spec_uint ("avatar-max-size",
926 "Maximum size for avatars in bytes",
927 "Maximum file size of avatar that may be "
928 "set or 0 if there is no maximum.",
933 G_PARAM_STATIC_STRINGS));
936 g_type_class_add_private (object_class, sizeof (EmpathyTpContactFactoryPriv));
940 empathy_tp_contact_factory_init (EmpathyTpContactFactory *tp_factory)
942 EmpathyTpContactFactoryPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (tp_factory,
943 EMPATHY_TYPE_TP_CONTACT_FACTORY, EmpathyTpContactFactoryPriv);
945 tp_factory->priv = priv;
948 static GHashTable *factories = NULL;
951 tp_contact_factory_connection_invalidated_cb (TpProxy *connection,
957 DEBUG ("Message: %s", message);
958 g_hash_table_remove (factories, connection);
962 tp_contact_factory_connection_weak_notify_cb (gpointer connection,
963 GObject *where_the_object_was)
965 g_hash_table_remove (factories, connection);
969 tp_contact_factory_remove_connection (gpointer connection)
971 g_signal_handlers_disconnect_by_func (connection,
972 tp_contact_factory_connection_invalidated_cb, NULL);
973 g_object_unref (connection);
976 EmpathyTpContactFactory *
977 empathy_tp_contact_factory_dup_singleton (TpConnection *connection)
979 EmpathyTpContactFactory *tp_factory;
981 g_return_val_if_fail (TP_IS_CONNECTION (connection), NULL);
983 if (factories == NULL) {
984 factories = g_hash_table_new_full (empathy_proxy_hash,
986 tp_contact_factory_remove_connection,
990 tp_factory = g_hash_table_lookup (factories, connection);
991 if (tp_factory == NULL) {
992 tp_factory = g_object_new (EMPATHY_TYPE_TP_CONTACT_FACTORY,
993 "connection", connection,
995 g_hash_table_insert (factories, g_object_ref (connection),
997 g_object_weak_ref (G_OBJECT (tp_factory),
998 tp_contact_factory_connection_weak_notify_cb,
1000 g_signal_connect (connection, "invalidated",
1001 G_CALLBACK (tp_contact_factory_connection_invalidated_cb),
1004 g_object_ref (tp_factory);