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>
29 #include <extensions/extensions.h>
31 #include "empathy-tp-contact-factory.h"
32 #include "empathy-utils.h"
34 #define DEBUG_FLAG EMPATHY_DEBUG_TP | EMPATHY_DEBUG_CONTACT
35 #include "empathy-debug.h"
37 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyTpContactFactory)
39 TpConnection *connection;
42 gchar **avatar_mime_types;
43 guint avatar_min_width;
44 guint avatar_min_height;
45 guint avatar_max_width;
46 guint avatar_max_height;
47 guint avatar_max_size;
48 gboolean can_request_ft;
49 } EmpathyTpContactFactoryPriv;
51 G_DEFINE_TYPE (EmpathyTpContactFactory, empathy_tp_contact_factory, G_TYPE_OBJECT);
65 static TpContactFeature contact_features[] = {
66 TP_CONTACT_FEATURE_ALIAS,
67 TP_CONTACT_FEATURE_PRESENCE,
70 static EmpathyContact *
71 tp_contact_factory_find_by_handle (EmpathyTpContactFactory *tp_factory,
74 EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
77 for (l = priv->contacts; l; l = l->next) {
78 if (empathy_contact_get_handle (l->data) == handle) {
86 static EmpathyContact *
87 tp_contact_factory_find_by_tp_contact (EmpathyTpContactFactory *tp_factory,
88 TpContact *tp_contact)
90 EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
93 for (l = priv->contacts; l; l = l->next) {
94 if (empathy_contact_get_tp_contact (l->data) == tp_contact) {
103 tp_contact_factory_weak_notify (gpointer data,
104 GObject *where_the_object_was)
106 EmpathyTpContactFactoryPriv *priv = GET_PRIV (data);
108 DEBUG ("Remove finalized contact %p", where_the_object_was);
110 priv->contacts = g_list_remove (priv->contacts, where_the_object_was);
114 tp_contact_factory_set_aliases_cb (TpConnection *connection,
120 DEBUG ("Error: %s", error->message);
125 tp_contact_factory_set_avatar_cb (TpConnection *connection,
132 DEBUG ("Error: %s", error->message);
137 tp_contact_factory_clear_avatar_cb (TpConnection *connection,
143 DEBUG ("Error: %s", error->message);
148 tp_contact_factory_avatar_retrieved_cb (TpConnection *connection,
151 const GArray *avatar_data,
152 const gchar *mime_type,
156 EmpathyContact *contact;
158 contact = tp_contact_factory_find_by_handle (EMPATHY_TP_CONTACT_FACTORY (tp_factory),
164 DEBUG ("Avatar retrieved for contact %s (%d)",
165 empathy_contact_get_id (contact),
168 empathy_contact_load_avatar_data (contact,
176 tp_contact_factory_request_avatars_cb (TpConnection *connection,
182 DEBUG ("Error: %s", error->message);
187 tp_contact_factory_avatar_maybe_update (EmpathyTpContactFactory *tp_factory,
191 EmpathyContact *contact;
192 EmpathyAvatar *avatar;
194 contact = tp_contact_factory_find_by_handle (tp_factory, handle);
199 /* Check if we have an avatar */
200 if (EMP_STR_EMPTY (token)) {
201 empathy_contact_set_avatar (contact, NULL);
205 /* Check if the avatar changed */
206 avatar = empathy_contact_get_avatar (contact);
207 if (avatar && !tp_strdiff (avatar->token, token)) {
211 /* The avatar changed, search the new one in the cache */
212 if (empathy_contact_load_avatar_cache (contact, token)) {
213 /* Got from cache, use it */
217 /* Avatar is not up-to-date, we have to request it. */
222 EmpathyTpContactFactory *tp_factory;
227 tp_contact_factory_avatar_tokens_foreach (gpointer key,
231 TokensData *data = user_data;
232 const gchar *token = value;
233 guint handle = GPOINTER_TO_UINT (key);
235 if (!tp_contact_factory_avatar_maybe_update (data->tp_factory,
237 g_array_append_val (data->handles, handle);
242 tp_contact_factory_got_known_avatar_tokens (EmpathyTpContactFactory *tp_factory,
246 EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
250 DEBUG ("Error: %s", error->message);
254 data.tp_factory = tp_factory;
255 data.handles = g_array_new (FALSE, FALSE, sizeof (guint));
256 g_hash_table_foreach (tokens,
257 tp_contact_factory_avatar_tokens_foreach,
260 DEBUG ("Got %d tokens, need to request %d avatars",
261 g_hash_table_size (tokens), data.handles->len);
263 /* Request needed avatars */
264 if (data.handles->len > 0) {
265 tp_cli_connection_interface_avatars_call_request_avatars (priv->connection,
268 tp_contact_factory_request_avatars_cb,
270 G_OBJECT (tp_factory));
273 g_array_free (data.handles, TRUE);
274 g_hash_table_destroy (tokens);
278 tp_contact_factory_avatar_updated_cb (TpConnection *connection,
280 const gchar *new_token,
286 if (tp_contact_factory_avatar_maybe_update (EMPATHY_TP_CONTACT_FACTORY (tp_factory),
287 handle, new_token)) {
288 /* Avatar was cached, nothing to do */
292 DEBUG ("Need to request avatar for token %s", new_token);
294 handles = g_array_new (FALSE, FALSE, sizeof (guint));
295 g_array_append_val (handles, handle);
297 tp_cli_connection_interface_avatars_call_request_avatars (connection,
300 tp_contact_factory_request_avatars_cb,
303 g_array_free (handles, TRUE);
307 tp_contact_factory_update_capabilities (EmpathyTpContactFactory *tp_factory,
309 const gchar *channel_type,
313 EmpathyContact *contact;
314 EmpathyCapabilities capabilities;
316 contact = tp_contact_factory_find_by_handle (tp_factory, handle);
321 capabilities = empathy_contact_get_capabilities (contact);
322 capabilities &= ~EMPATHY_CAPABILITIES_UNKNOWN;
324 if (strcmp (channel_type, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA) == 0) {
325 capabilities &= ~EMPATHY_CAPABILITIES_AUDIO;
326 capabilities &= ~EMPATHY_CAPABILITIES_VIDEO;
327 if (specific & TP_CHANNEL_MEDIA_CAPABILITY_AUDIO) {
328 capabilities |= EMPATHY_CAPABILITIES_AUDIO;
330 if (specific & TP_CHANNEL_MEDIA_CAPABILITY_VIDEO) {
331 capabilities |= EMPATHY_CAPABILITIES_VIDEO;
335 DEBUG ("Changing capabilities for contact %s (%d) to %d",
336 empathy_contact_get_id (contact),
337 empathy_contact_get_handle (contact),
340 empathy_contact_set_capabilities (contact, capabilities);
344 tp_contact_factory_got_capabilities (EmpathyTpContactFactory *tp_factory,
345 GPtrArray *capabilities,
351 DEBUG ("Error: %s", error->message);
352 /* FIXME Should set the capabilities of the contacts for which this request
353 * originated to NONE */
357 for (i = 0; i < capabilities->len; i++) {
360 const gchar *channel_type;
364 values = g_ptr_array_index (capabilities, i);
365 handle = g_value_get_uint (g_value_array_get_nth (values, 0));
366 channel_type = g_value_get_string (g_value_array_get_nth (values, 1));
367 generic = g_value_get_uint (g_value_array_get_nth (values, 2));
368 specific = g_value_get_uint (g_value_array_get_nth (values, 3));
370 tp_contact_factory_update_capabilities (tp_factory,
376 g_value_array_free (values);
379 g_ptr_array_free (capabilities, TRUE);
383 tp_contact_factory_capabilities_changed_cb (TpConnection *connection,
384 const GPtrArray *capabilities,
386 GObject *weak_object)
388 EmpathyTpContactFactory *tp_factory = EMPATHY_TP_CONTACT_FACTORY (weak_object);
391 for (i = 0; i < capabilities->len; i++) {
394 const gchar *channel_type;
398 values = g_ptr_array_index (capabilities, i);
399 handle = g_value_get_uint (g_value_array_get_nth (values, 0));
400 channel_type = g_value_get_string (g_value_array_get_nth (values, 1));
401 generic = g_value_get_uint (g_value_array_get_nth (values, 3));
402 specific = g_value_get_uint (g_value_array_get_nth (values, 5));
404 tp_contact_factory_update_capabilities (tp_factory,
413 get_requestable_channel_classes_cb (TpProxy *connection,
417 GObject *weak_object)
419 EmpathyTpContactFactory *self = EMPATHY_TP_CONTACT_FACTORY (weak_object);
420 EmpathyTpContactFactoryPriv *priv = GET_PRIV (self);
425 DEBUG ("Error: %s", error->message);
429 classes = g_value_get_boxed (value);
430 for (i = 0; i < classes->len; i++) {
431 GValueArray *class_struct;
432 GHashTable *fixed_prop;
433 GValue *chan_type, *handle_type;
436 class_struct = g_ptr_array_index (classes, i);
437 fixed_prop = g_value_get_boxed (g_value_array_get_nth (class_struct, 0));
439 chan_type = g_hash_table_lookup (fixed_prop,
440 TP_IFACE_CHANNEL ".ChannelType");
441 if (chan_type == NULL ||
442 tp_strdiff (g_value_get_string (chan_type),
443 TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER)) {
447 handle_type = g_hash_table_lookup (fixed_prop,
448 TP_IFACE_CHANNEL ".TargetHandleType");
449 if (handle_type == NULL ||
450 g_value_get_uint (handle_type) != TP_HANDLE_TYPE_CONTACT) {
454 /* We can request file transfer channel to contacts. */
455 priv->can_request_ft = TRUE;
457 /* Update the capabilities of all contacts */
458 for (l = priv->contacts; l != NULL; l = g_list_next (l)) {
459 EmpathyContact *contact = l->data;
460 EmpathyCapabilities caps;
462 caps = empathy_contact_get_capabilities (contact);
463 empathy_contact_set_capabilities (contact, caps |
464 EMPATHY_CAPABILITIES_FT);
471 tp_contact_factory_got_avatar_requirements_cb (TpConnection *proxy,
472 const gchar **mime_types,
482 EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
485 DEBUG ("Failed to get avatar requirements: %s", error->message);
486 /* We'll just leave avatar_mime_types as NULL; the
487 * avatar-setting code can use this as a signal that you can't
491 priv->avatar_mime_types = g_strdupv ((gchar **) mime_types);
492 priv->avatar_min_width = min_width;
493 priv->avatar_min_height = min_height;
494 priv->avatar_max_width = max_width;
495 priv->avatar_max_height = max_height;
496 priv->avatar_max_size = max_size;
501 tp_contact_factory_add_contact (EmpathyTpContactFactory *tp_factory,
502 EmpathyContact *contact)
504 EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
506 GArray handles = {(gchar*) &handle, 1};
508 GPtrArray *capabilities;
509 GError *error = NULL;
511 /* Keep a weak ref to that contact */
512 g_object_weak_ref (G_OBJECT (contact),
513 tp_contact_factory_weak_notify,
515 priv->contacts = g_list_prepend (priv->contacts, contact);
517 /* The contact keeps a ref to its factory */
518 g_object_set_data_full (G_OBJECT (contact), "empathy-factory",
519 g_object_ref (tp_factory),
522 /* Set the FT capability */
523 if (priv->can_request_ft) {
524 EmpathyCapabilities caps;
526 caps = empathy_contact_get_capabilities (contact);
527 caps |= EMPATHY_CAPABILITIES_FT;
529 empathy_contact_set_capabilities (contact, caps);
532 /* FIXME: This should be done by TpContact */
533 handle = empathy_contact_get_handle (contact);
534 tp_cli_connection_interface_avatars_run_get_known_avatar_tokens (priv->connection,
540 tp_contact_factory_got_known_avatar_tokens (tp_factory, tokens, error);
541 g_clear_error (&error);
543 tp_cli_connection_interface_capabilities_run_get_capabilities (priv->connection,
549 tp_contact_factory_got_capabilities (tp_factory, capabilities, error);
550 g_clear_error (&error);
552 DEBUG ("Contact added: %s (%d)",
553 empathy_contact_get_id (contact),
554 empathy_contact_get_handle (contact));
558 EmpathyTpContactFactoryContactsByIdCb ids_cb;
559 EmpathyTpContactFactoryContactsByHandleCb handles_cb;
560 EmpathyTpContactFactoryContactCb contact_cb;
564 EmpathyTpContactFactory *tp_factory;
565 GetContactsCb callback;
567 GDestroyNotify destroy;
571 get_contacts_data_free (gpointer user_data)
573 GetContactsData *data = user_data;
576 data->destroy (data->user_data);
578 g_object_unref (data->tp_factory);
580 g_slice_free (GetContactsData, data);
583 static EmpathyContact *
584 dup_contact_for_tp_contact (EmpathyTpContactFactory *tp_factory,
585 TpContact *tp_contact)
587 EmpathyContact *contact;
589 contact = tp_contact_factory_find_by_tp_contact (tp_factory,
592 if (contact != NULL) {
593 g_object_ref (contact);
595 contact = empathy_contact_new (tp_contact);
596 tp_contact_factory_add_contact (tp_factory, contact);
602 static EmpathyContact **
603 contacts_array_new (EmpathyTpContactFactory *tp_factory,
605 TpContact * const * contacts)
607 EmpathyContact **ret;
610 ret = g_new0 (EmpathyContact *, n_contacts);
611 for (i = 0; i < n_contacts; i++) {
612 ret[i] = dup_contact_for_tp_contact (tp_factory, contacts[i]);
619 contacts_array_free (guint n_contacts,
620 EmpathyContact **contacts)
624 for (i = 0; i < n_contacts; i++) {
625 g_object_unref (contacts[i]);
631 get_contacts_by_id_cb (TpConnection *connection,
633 TpContact * const *contacts,
634 const gchar * const *requested_ids,
635 GHashTable *failed_id_errors,
638 GObject *weak_object)
640 GetContactsData *data = user_data;
641 EmpathyContact **empathy_contacts;
643 empathy_contacts = contacts_array_new (data->tp_factory,
644 n_contacts, contacts);
645 if (data->callback.ids_cb) {
646 data->callback.ids_cb (data->tp_factory,
647 n_contacts, empathy_contacts,
651 data->user_data, weak_object);
654 contacts_array_free (n_contacts, empathy_contacts);
658 empathy_tp_contact_factory_get_from_ids (EmpathyTpContactFactory *tp_factory,
660 const gchar * const *ids,
661 EmpathyTpContactFactoryContactsByIdCb 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));
670 g_return_if_fail (ids != NULL);
672 data = g_slice_new (GetContactsData);
673 data->callback.ids_cb = callback;
674 data->user_data = user_data;
675 data->destroy = destroy;
676 data->tp_factory = g_object_ref (tp_factory);
677 tp_connection_get_contacts_by_id (priv->connection,
679 G_N_ELEMENTS (contact_features),
681 get_contacts_by_id_cb,
683 (GDestroyNotify) get_contacts_data_free,
688 get_contact_by_id_cb (TpConnection *connection,
690 TpContact * const *contacts,
691 const gchar * const *requested_ids,
692 GHashTable *failed_id_errors,
695 GObject *weak_object)
697 GetContactsData *data = user_data;
698 EmpathyContact *contact = NULL;
700 if (n_contacts == 1) {
701 contact = dup_contact_for_tp_contact (data->tp_factory,
704 else if (error == NULL) {
708 g_hash_table_iter_init (&iter, failed_id_errors);
709 while (g_hash_table_iter_next (&iter, NULL, &value)) {
717 if (data->callback.contact_cb) {
718 data->callback.contact_cb (data->tp_factory,
721 data->user_data, weak_object);
726 empathy_tp_contact_factory_get_from_id (EmpathyTpContactFactory *tp_factory,
728 EmpathyTpContactFactoryContactCb callback,
730 GDestroyNotify destroy,
731 GObject *weak_object)
733 EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
734 GetContactsData *data;
736 g_return_if_fail (EMPATHY_IS_TP_CONTACT_FACTORY (tp_factory));
737 g_return_if_fail (id != NULL);
739 data = g_slice_new (GetContactsData);
740 data->callback.contact_cb = callback;
741 data->user_data = user_data;
742 data->destroy = destroy;
743 data->tp_factory = g_object_ref (tp_factory);
744 tp_connection_get_contacts_by_id (priv->connection,
746 G_N_ELEMENTS (contact_features),
748 get_contact_by_id_cb,
750 (GDestroyNotify) get_contacts_data_free,
755 get_contacts_by_handle_cb (TpConnection *connection,
757 TpContact * const *contacts,
759 const TpHandle *failed,
762 GObject *weak_object)
764 GetContactsData *data = user_data;
765 EmpathyContact **empathy_contacts;
767 empathy_contacts = contacts_array_new (data->tp_factory,
768 n_contacts, contacts);
769 if (data->callback.handles_cb) {
770 data->callback.handles_cb (data->tp_factory,
771 n_contacts, empathy_contacts,
774 data->user_data, weak_object);
777 contacts_array_free (n_contacts, empathy_contacts);
781 empathy_tp_contact_factory_get_from_handles (EmpathyTpContactFactory *tp_factory,
783 const TpHandle *handles,
784 EmpathyTpContactFactoryContactsByHandleCb callback,
786 GDestroyNotify destroy,
787 GObject *weak_object)
789 EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
790 GetContactsData *data;
792 g_return_if_fail (EMPATHY_IS_TP_CONTACT_FACTORY (tp_factory));
793 g_return_if_fail (handles != NULL);
795 data = g_slice_new (GetContactsData);
796 data->callback.handles_cb = callback;
797 data->user_data = user_data;
798 data->destroy = destroy;
799 data->tp_factory = g_object_ref (tp_factory);
800 tp_connection_get_contacts_by_handle (priv->connection,
802 G_N_ELEMENTS (contact_features),
804 get_contacts_by_handle_cb,
806 (GDestroyNotify) get_contacts_data_free,
811 get_contact_by_handle_cb (TpConnection *connection,
813 TpContact * const *contacts,
815 const TpHandle *failed,
818 GObject *weak_object)
820 GetContactsData *data = user_data;
821 EmpathyContact *contact = NULL;
823 if (n_contacts == 1) {
824 contact = dup_contact_for_tp_contact (data->tp_factory,
828 if (data->callback.contact_cb) {
829 data->callback.contact_cb (data->tp_factory,
832 data->user_data, weak_object);
837 empathy_tp_contact_factory_get_from_handle (EmpathyTpContactFactory *tp_factory,
839 EmpathyTpContactFactoryContactCb callback,
841 GDestroyNotify destroy,
842 GObject *weak_object)
844 EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
845 GetContactsData *data;
847 g_return_if_fail (EMPATHY_IS_TP_CONTACT_FACTORY (tp_factory));
849 data = g_slice_new (GetContactsData);
850 data->callback.contact_cb = callback;
851 data->user_data = user_data;
852 data->destroy = destroy;
853 data->tp_factory = g_object_ref (tp_factory);
854 tp_connection_get_contacts_by_handle (priv->connection,
856 G_N_ELEMENTS (contact_features),
858 get_contact_by_handle_cb,
860 (GDestroyNotify) get_contacts_data_free,
865 empathy_tp_contact_factory_set_alias (EmpathyTpContactFactory *tp_factory,
866 EmpathyContact *contact,
869 EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
870 GHashTable *new_alias;
873 g_return_if_fail (EMPATHY_IS_TP_CONTACT_FACTORY (tp_factory));
874 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
876 handle = empathy_contact_get_handle (contact);
878 DEBUG ("Setting alias for contact %s (%d) to %s",
879 empathy_contact_get_id (contact),
882 new_alias = g_hash_table_new_full (g_direct_hash,
887 g_hash_table_insert (new_alias,
888 GUINT_TO_POINTER (handle),
891 tp_cli_connection_interface_aliasing_call_set_aliases (priv->connection,
894 tp_contact_factory_set_aliases_cb,
896 G_OBJECT (tp_factory));
898 g_hash_table_destroy (new_alias);
902 empathy_tp_contact_factory_set_avatar (EmpathyTpContactFactory *tp_factory,
905 const gchar *mime_type)
907 EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
909 g_return_if_fail (EMPATHY_IS_TP_CONTACT_FACTORY (tp_factory));
911 if (data && size > 0 && size < G_MAXUINT) {
914 avatar.data = (gchar*) data;
917 DEBUG ("Setting avatar on connection %s",
918 tp_proxy_get_object_path (TP_PROXY (priv->connection)));
920 tp_cli_connection_interface_avatars_call_set_avatar (priv->connection,
924 tp_contact_factory_set_avatar_cb,
926 G_OBJECT (tp_factory));
928 DEBUG ("Clearing avatar on connection %s",
929 tp_proxy_get_object_path (TP_PROXY (priv->connection)));
931 tp_cli_connection_interface_avatars_call_clear_avatar (priv->connection,
933 tp_contact_factory_clear_avatar_cb,
935 G_OBJECT (tp_factory));
940 tp_contact_factory_get_property (GObject *object,
945 EmpathyTpContactFactoryPriv *priv = GET_PRIV (object);
948 case PROP_CONNECTION:
949 g_value_set_object (value, priv->connection);
951 case PROP_MIME_TYPES:
952 g_value_set_boxed (value, priv->avatar_mime_types);
955 g_value_set_uint (value, priv->avatar_min_width);
957 case PROP_MIN_HEIGHT:
958 g_value_set_uint (value, priv->avatar_min_height);
961 g_value_set_uint (value, priv->avatar_max_width);
963 case PROP_MAX_HEIGHT:
964 g_value_set_uint (value, priv->avatar_max_height);
967 g_value_set_uint (value, priv->avatar_max_size);
970 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
976 tp_contact_factory_set_property (GObject *object,
981 EmpathyTpContactFactoryPriv *priv = GET_PRIV (object);
984 case PROP_CONNECTION:
985 priv->connection = g_value_dup_object (value);
988 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
994 tp_contact_factory_finalize (GObject *object)
996 EmpathyTpContactFactoryPriv *priv = GET_PRIV (object);
999 DEBUG ("Finalized: %p", object);
1001 for (l = priv->contacts; l; l = l->next) {
1002 g_object_weak_unref (G_OBJECT (l->data),
1003 tp_contact_factory_weak_notify,
1007 g_list_free (priv->contacts);
1009 g_object_unref (priv->connection);
1011 g_strfreev (priv->avatar_mime_types);
1013 G_OBJECT_CLASS (empathy_tp_contact_factory_parent_class)->finalize (object);
1017 tp_contact_factory_constructor (GType type,
1019 GObjectConstructParam *props)
1021 GObject *tp_factory;
1022 EmpathyTpContactFactoryPriv *priv;
1024 tp_factory = G_OBJECT_CLASS (empathy_tp_contact_factory_parent_class)->constructor (type, n_props, props);
1025 priv = GET_PRIV (tp_factory);
1027 /* FIXME: This should be moved to TpContact */
1028 tp_cli_connection_interface_avatars_connect_to_avatar_updated (priv->connection,
1029 tp_contact_factory_avatar_updated_cb,
1033 tp_cli_connection_interface_avatars_connect_to_avatar_retrieved (priv->connection,
1034 tp_contact_factory_avatar_retrieved_cb,
1038 tp_cli_connection_interface_capabilities_connect_to_capabilities_changed (priv->connection,
1039 tp_contact_factory_capabilities_changed_cb,
1045 /* FIXME: This should be moved to TpConnection */
1046 tp_cli_connection_interface_avatars_call_get_avatar_requirements (priv->connection,
1048 tp_contact_factory_got_avatar_requirements_cb,
1051 tp_cli_dbus_properties_call_get (priv->connection, -1,
1052 TP_IFACE_CONNECTION_INTERFACE_REQUESTS,
1053 "RequestableChannelClasses",
1054 get_requestable_channel_classes_cb, NULL, NULL,
1055 G_OBJECT (tp_factory));
1061 empathy_tp_contact_factory_class_init (EmpathyTpContactFactoryClass *klass)
1063 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1065 object_class->finalize = tp_contact_factory_finalize;
1066 object_class->constructor = tp_contact_factory_constructor;
1067 object_class->get_property = tp_contact_factory_get_property;
1068 object_class->set_property = tp_contact_factory_set_property;
1070 g_object_class_install_property (object_class,
1072 g_param_spec_object ("connection",
1073 "Factory's Connection",
1074 "The connection associated with the factory",
1077 G_PARAM_CONSTRUCT_ONLY |
1078 G_PARAM_STATIC_STRINGS));
1079 g_object_class_install_property (object_class,
1081 g_param_spec_boxed ("avatar-mime-types",
1082 "Supported MIME types for avatars",
1083 "Types of images that may be set as "
1084 "avatars on this connection.",
1087 G_PARAM_STATIC_STRINGS));
1088 g_object_class_install_property (object_class,
1090 g_param_spec_uint ("avatar-min-width",
1091 "Minimum width for avatars",
1092 "Minimum width of avatar that may be set.",
1097 G_PARAM_STATIC_STRINGS));
1098 g_object_class_install_property (object_class,
1100 g_param_spec_uint ("avatar-min-height",
1101 "Minimum height for avatars",
1102 "Minimum height of avatar that may be set.",
1107 G_PARAM_STATIC_STRINGS));
1108 g_object_class_install_property (object_class,
1110 g_param_spec_uint ("avatar-max-width",
1111 "Maximum width for avatars",
1112 "Maximum width of avatar that may be set "
1113 "or 0 if there is no maximum.",
1118 G_PARAM_STATIC_STRINGS));
1119 g_object_class_install_property (object_class,
1121 g_param_spec_uint ("avatar-max-height",
1122 "Maximum height for avatars",
1123 "Maximum height of avatar that may be set "
1124 "or 0 if there is no maximum.",
1129 G_PARAM_STATIC_STRINGS));
1130 g_object_class_install_property (object_class,
1132 g_param_spec_uint ("avatar-max-size",
1133 "Maximum size for avatars in bytes",
1134 "Maximum file size of avatar that may be "
1135 "set or 0 if there is no maximum.",
1140 G_PARAM_STATIC_STRINGS));
1143 g_type_class_add_private (object_class, sizeof (EmpathyTpContactFactoryPriv));
1147 empathy_tp_contact_factory_init (EmpathyTpContactFactory *tp_factory)
1149 EmpathyTpContactFactoryPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (tp_factory,
1150 EMPATHY_TYPE_TP_CONTACT_FACTORY, EmpathyTpContactFactoryPriv);
1152 tp_factory->priv = priv;
1153 priv->can_request_ft = FALSE;
1156 static GHashTable *factories = NULL;
1159 tp_contact_factory_connection_invalidated_cb (TpProxy *connection,
1165 DEBUG ("Message: %s", message);
1166 g_hash_table_remove (factories, connection);
1170 tp_contact_factory_connection_weak_notify_cb (gpointer connection,
1171 GObject *where_the_object_was)
1173 g_hash_table_remove (factories, connection);
1177 tp_contact_factory_remove_connection (gpointer connection)
1179 g_signal_handlers_disconnect_by_func (connection,
1180 tp_contact_factory_connection_invalidated_cb, NULL);
1181 g_object_unref (connection);
1184 EmpathyTpContactFactory *
1185 empathy_tp_contact_factory_dup_singleton (TpConnection *connection)
1187 EmpathyTpContactFactory *tp_factory;
1189 g_return_val_if_fail (TP_IS_CONNECTION (connection), NULL);
1191 if (factories == NULL) {
1192 factories = g_hash_table_new_full (empathy_proxy_hash,
1193 empathy_proxy_equal,
1194 tp_contact_factory_remove_connection,
1198 tp_factory = g_hash_table_lookup (factories, connection);
1199 if (tp_factory == NULL) {
1200 tp_factory = g_object_new (EMPATHY_TYPE_TP_CONTACT_FACTORY,
1201 "connection", connection,
1203 g_hash_table_insert (factories, g_object_ref (connection),
1205 g_object_weak_ref (G_OBJECT (tp_factory),
1206 tp_contact_factory_connection_weak_notify_cb,
1208 g_signal_connect (connection, "invalidated",
1209 G_CALLBACK (tp_contact_factory_connection_invalidated_cb),
1212 g_object_ref (tp_factory);