]> git.0d.be Git - empathy.git/blob - libempathy/empathy-utils.c
fix indentation
[empathy.git] / libempathy / empathy-utils.c
1 /*
2  * Copyright (C) 2003-2007 Imendio AB
3  * Copyright (C) 2007-2008 Collabora Ltd.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program 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  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA  02110-1301  USA
19  *
20  * Authors: Richard Hult <richard@imendio.com>
21  *          Martyn Russell <martyn@imendio.com>
22  *          Xavier Claessens <xclaesse@gmail.com>
23  */
24
25 #include "config.h"
26
27 #include <string.h>
28 #include <time.h>
29 #include <sys/types.h>
30
31 #include <glib/gi18n-lib.h>
32
33 #include <libxml/uri.h>
34
35 #include <folks/folks.h>
36 #include <folks/folks-telepathy.h>
37
38 #include <telepathy-glib/account-manager.h>
39 #include <telepathy-glib/connection.h>
40 #include <telepathy-glib/channel.h>
41 #include <telepathy-glib/dbus.h>
42 #include <telepathy-glib/util.h>
43
44 #include "empathy-utils.h"
45 #include "empathy-contact-manager.h"
46 #include "empathy-individual-manager.h"
47 #include "empathy-dispatcher.h"
48 #include "empathy-dispatch-operation.h"
49 #include "empathy-idle.h"
50 #include "empathy-tp-call.h"
51 #include "empathy-tp-contact-factory.h"
52
53 #include <extensions/extensions.h>
54
55 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
56 #include "empathy-debug.h"
57
58 /* Translation between presence types and string */
59 static struct {
60         const gchar *name;
61         TpConnectionPresenceType type;
62 } presence_types[] = {
63         { "available", TP_CONNECTION_PRESENCE_TYPE_AVAILABLE },
64         { "busy",      TP_CONNECTION_PRESENCE_TYPE_BUSY },
65         { "away",      TP_CONNECTION_PRESENCE_TYPE_AWAY },
66         { "ext_away",  TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY },
67         { "hidden",    TP_CONNECTION_PRESENCE_TYPE_HIDDEN },
68         { "offline",   TP_CONNECTION_PRESENCE_TYPE_OFFLINE },
69         { "unset",     TP_CONNECTION_PRESENCE_TYPE_UNSET },
70         { "unknown",   TP_CONNECTION_PRESENCE_TYPE_UNKNOWN },
71         { "error",     TP_CONNECTION_PRESENCE_TYPE_ERROR },
72         /* alternative names */
73         { "dnd",      TP_CONNECTION_PRESENCE_TYPE_BUSY },
74         { "brb",      TP_CONNECTION_PRESENCE_TYPE_AWAY },
75         { "xa",       TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY },
76         { NULL, },
77 };
78
79
80
81 void
82 empathy_init (void)
83 {
84         static gboolean initialized = FALSE;
85
86         if (initialized)
87                 return;
88
89         g_type_init ();
90
91         /* Setup gettext */
92         bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
93         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
94
95         /* Setup debug output for empathy and telepathy-glib */
96         if (g_getenv ("EMPATHY_TIMING") != NULL) {
97                 g_log_set_default_handler (tp_debug_timestamped_log_handler, NULL);
98         }
99         empathy_debug_set_flags (g_getenv ("EMPATHY_DEBUG"));
100         tp_debug_divert_messages (g_getenv ("EMPATHY_LOGFILE"));
101
102         emp_cli_init ();
103
104         initialized = TRUE;
105 }
106
107 gchar *
108 empathy_substring (const gchar *str,
109                   gint         start,
110                   gint         end)
111 {
112         return g_strndup (str + start, end - start);
113 }
114
115 gint
116 empathy_strcasecmp (const gchar *s1,
117                    const gchar *s2)
118 {
119         return empathy_strncasecmp (s1, s2, -1);
120 }
121
122 gint
123 empathy_strncasecmp (const gchar *s1,
124                     const gchar *s2,
125                     gsize        n)
126 {
127         gchar *u1, *u2;
128         gint   ret_val;
129
130         u1 = g_utf8_casefold (s1, n);
131         u2 = g_utf8_casefold (s2, n);
132
133         ret_val = g_utf8_collate (u1, u2);
134         g_free (u1);
135         g_free (u2);
136
137         return ret_val;
138 }
139
140 gboolean
141 empathy_xml_validate (xmlDoc      *doc,
142                      const gchar *dtd_filename)
143 {
144         gchar        *path;
145         xmlChar      *escaped;
146         xmlValidCtxt  cvp;
147         xmlDtd       *dtd;
148         gboolean      ret;
149
150         path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "libempathy",
151                                  dtd_filename, NULL);
152         if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
153                 g_free (path);
154                 path = g_build_filename (DATADIR, "empathy", dtd_filename, NULL);
155         }
156         DEBUG ("Loading dtd file %s", path);
157
158         /* The list of valid chars is taken from libxml. */
159         escaped = xmlURIEscapeStr ((const xmlChar *) path,
160                 (const xmlChar *)":@&=+$,/?;");
161         g_free (path);
162
163         memset (&cvp, 0, sizeof (cvp));
164         dtd = xmlParseDTD (NULL, escaped);
165         ret = xmlValidateDtd (&cvp, doc, dtd);
166
167         xmlFree (escaped);
168         xmlFreeDtd (dtd);
169
170         return ret;
171 }
172
173 xmlNodePtr
174 empathy_xml_node_get_child (xmlNodePtr   node,
175                            const gchar *child_name)
176 {
177         xmlNodePtr l;
178
179         g_return_val_if_fail (node != NULL, NULL);
180         g_return_val_if_fail (child_name != NULL, NULL);
181
182         for (l = node->children; l; l = l->next) {
183                 if (l->name && strcmp ((const gchar *) l->name, child_name) == 0) {
184                         return l;
185                 }
186         }
187
188         return NULL;
189 }
190
191 xmlChar *
192 empathy_xml_node_get_child_content (xmlNodePtr   node,
193                                    const gchar *child_name)
194 {
195         xmlNodePtr l;
196
197         g_return_val_if_fail (node != NULL, NULL);
198         g_return_val_if_fail (child_name != NULL, NULL);
199
200         l = empathy_xml_node_get_child (node, child_name);
201         if (l) {
202                 return xmlNodeGetContent (l);
203         }
204
205         return NULL;
206 }
207
208 xmlNodePtr
209 empathy_xml_node_find_child_prop_value (xmlNodePtr   node,
210                                        const gchar *prop_name,
211                                        const gchar *prop_value)
212 {
213         xmlNodePtr l;
214         xmlNodePtr found = NULL;
215
216         g_return_val_if_fail (node != NULL, NULL);
217         g_return_val_if_fail (prop_name != NULL, NULL);
218         g_return_val_if_fail (prop_value != NULL, NULL);
219
220         for (l = node->children; l && !found; l = l->next) {
221                 xmlChar *prop;
222
223                 if (!xmlHasProp (l, (const xmlChar *) prop_name)) {
224                         continue;
225                 }
226
227                 prop = xmlGetProp (l, (const xmlChar *) prop_name);
228                 if (prop && strcmp ((const gchar *) prop, prop_value) == 0) {
229                         found = l;
230                 }
231
232                 xmlFree (prop);
233         }
234
235         return found;
236 }
237
238 const gchar *
239 empathy_presence_get_default_message (TpConnectionPresenceType presence)
240 {
241         switch (presence) {
242         case TP_CONNECTION_PRESENCE_TYPE_AVAILABLE:
243                 return _("Available");
244         case TP_CONNECTION_PRESENCE_TYPE_BUSY:
245                 return _("Busy");
246         case TP_CONNECTION_PRESENCE_TYPE_AWAY:
247         case TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY:
248                 return _("Away");
249         case TP_CONNECTION_PRESENCE_TYPE_HIDDEN:
250                 return _("Invisible");
251         case TP_CONNECTION_PRESENCE_TYPE_OFFLINE:
252                 return _("Offline");
253         case TP_CONNECTION_PRESENCE_TYPE_UNKNOWN:
254                 return _("Unknown");
255         case TP_CONNECTION_PRESENCE_TYPE_UNSET:
256         case TP_CONNECTION_PRESENCE_TYPE_ERROR:
257         default:
258                 return NULL;
259         }
260
261         return NULL;
262 }
263
264 const gchar *
265 empathy_presence_to_str (TpConnectionPresenceType presence)
266 {
267         int i;
268
269         for (i = 0 ; presence_types[i].name != NULL; i++)
270                 if (presence == presence_types[i].type)
271                         return presence_types[i].name;
272
273         return NULL;
274 }
275
276 TpConnectionPresenceType
277 empathy_presence_from_str (const gchar *str)
278 {
279         int i;
280
281         for (i = 0 ; presence_types[i].name != NULL; i++)
282                 if (!tp_strdiff (str, presence_types[i].name))
283                         return presence_types[i].type;
284
285         return TP_CONNECTION_PRESENCE_TYPE_UNSET;
286 }
287
288 static const gchar *
289 empathy_status_reason_get_default_message (TpConnectionStatusReason reason)
290 {
291         switch (reason) {
292         case TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED:
293                 return _("No reason specified");
294         case TP_CONNECTION_STATUS_REASON_REQUESTED:
295                 return _("Status is set to offline");
296         case TP_CONNECTION_STATUS_REASON_NETWORK_ERROR:
297                 return _("Network error");
298         case TP_CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED:
299                 return _("Authentication failed");
300         case TP_CONNECTION_STATUS_REASON_ENCRYPTION_ERROR:
301                 return _("Encryption error");
302         case TP_CONNECTION_STATUS_REASON_NAME_IN_USE:
303                 return _("Name in use");
304         case TP_CONNECTION_STATUS_REASON_CERT_NOT_PROVIDED:
305                 return _("Certificate not provided");
306         case TP_CONNECTION_STATUS_REASON_CERT_UNTRUSTED:
307                 return _("Certificate untrusted");
308         case TP_CONNECTION_STATUS_REASON_CERT_EXPIRED:
309                 return _("Certificate expired");
310         case TP_CONNECTION_STATUS_REASON_CERT_NOT_ACTIVATED:
311                 return _("Certificate not activated");
312         case TP_CONNECTION_STATUS_REASON_CERT_HOSTNAME_MISMATCH:
313                 return _("Certificate hostname mismatch");
314         case TP_CONNECTION_STATUS_REASON_CERT_FINGERPRINT_MISMATCH:
315                 return _("Certificate fingerprint mismatch");
316         case TP_CONNECTION_STATUS_REASON_CERT_SELF_SIGNED:
317                 return _("Certificate self-signed");
318         case TP_CONNECTION_STATUS_REASON_CERT_OTHER_ERROR:
319                 return _("Certificate error");
320         default:
321                 return _("Unknown reason");
322         }
323 }
324
325 static GHashTable *
326 create_errors_to_message_hash (void)
327 {
328         GHashTable *errors;
329
330         errors = g_hash_table_new (g_str_hash, g_str_equal);
331         g_hash_table_insert (errors, TP_ERROR_STR_NETWORK_ERROR, _("Network error"));
332         g_hash_table_insert (errors, TP_ERROR_STR_AUTHENTICATION_FAILED,
333                 _("Authentication failed"));
334         g_hash_table_insert (errors, TP_ERROR_STR_ENCRYPTION_ERROR,
335                 _("Encryption error"));
336         g_hash_table_insert (errors, TP_ERROR_STR_CERT_NOT_PROVIDED,
337                 _("Certificate not provided"));
338         g_hash_table_insert (errors, TP_ERROR_STR_CERT_UNTRUSTED,
339                 _("Certificate untrusted"));
340         g_hash_table_insert (errors, TP_ERROR_STR_CERT_EXPIRED,
341                 _("Certificate expired"));
342         g_hash_table_insert (errors, TP_ERROR_STR_CERT_NOT_ACTIVATED,
343                 _("Certificate not activated"));
344         g_hash_table_insert (errors, TP_ERROR_STR_CERT_HOSTNAME_MISMATCH,
345                 _("Certificate hostname mismatch"));
346         g_hash_table_insert (errors, TP_ERROR_STR_CERT_FINGERPRINT_MISMATCH,
347                 _("Certificate fingerprint mismatch"));
348         g_hash_table_insert (errors, TP_ERROR_STR_CERT_SELF_SIGNED,
349                 _("Certificate self-signed"));
350         g_hash_table_insert (errors, TP_ERROR_STR_CANCELLED,
351                 _("Status is set to offline"));
352         g_hash_table_insert (errors, TP_ERROR_STR_ENCRYPTION_NOT_AVAILABLE,
353                 _("Encryption is not available"));
354         g_hash_table_insert (errors, TP_ERROR_STR_CERT_INVALID,
355                 _("Certificate is invalid"));
356         g_hash_table_insert (errors, TP_ERROR_STR_CONNECTION_REFUSED,
357                 _("Connection has been refused"));
358         g_hash_table_insert (errors, TP_ERROR_STR_CONNECTION_FAILED,
359                 _("Connection can't be established"));
360         g_hash_table_insert (errors, TP_ERROR_STR_CONNECTION_LOST,
361                 _("Connection has been lost"));
362         g_hash_table_insert (errors, TP_ERROR_STR_ALREADY_CONNECTED,
363                 _("This resource is already connected to the server"));
364         g_hash_table_insert (errors, TP_ERROR_STR_CONNECTION_REPLACED,
365                 _("Connection has been replaced by a new connection using the "
366                 "same resource"));
367         g_hash_table_insert (errors, TP_ERROR_STR_REGISTRATION_EXISTS,
368                 _("The account already exists on the server"));
369         g_hash_table_insert (errors, TP_ERROR_STR_SERVICE_BUSY,
370                 _("Server is currently too busy to handle the connection"));
371
372         return errors;
373 }
374
375 static const gchar *
376 empathy_dbus_error_name_get_default_message  (const gchar *error)
377 {
378         static GHashTable *errors_to_message = NULL;
379
380         if (error == NULL)
381                 return NULL;
382
383         if (G_UNLIKELY (errors_to_message == NULL)) {
384                 errors_to_message = create_errors_to_message_hash ();
385         }
386
387         return g_hash_table_lookup (errors_to_message, error);
388 }
389
390 const gchar *
391 empathy_account_get_error_message (TpAccount *account)
392 {
393         const gchar *dbus_error;
394         const gchar *message;
395         TpConnectionStatusReason reason;
396
397         dbus_error = tp_account_get_detailed_error (account, NULL);
398         message = empathy_dbus_error_name_get_default_message (dbus_error);
399         if (message != NULL)
400                 return message;
401
402         DEBUG ("Don't understand error '%s'; fallback to the status reason (%u)",
403                 dbus_error, reason);
404
405         tp_account_get_connection_status (account, &reason);
406
407         return empathy_status_reason_get_default_message (reason);
408 }
409
410 gchar *
411 empathy_file_lookup (const gchar *filename, const gchar *subdir)
412 {
413         gchar *path;
414
415         if (!subdir) {
416                 subdir = ".";
417         }
418
419         path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), subdir, filename, NULL);
420         if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
421                 g_free (path);
422                 path = g_build_filename (DATADIR, "empathy", filename, NULL);
423         }
424
425         return path;
426 }
427
428 guint
429 empathy_proxy_hash (gconstpointer key)
430 {
431         TpProxy      *proxy = TP_PROXY (key);
432         TpProxyClass *proxy_class = TP_PROXY_GET_CLASS (key);
433
434         g_return_val_if_fail (TP_IS_PROXY (proxy), 0);
435         g_return_val_if_fail (proxy_class->must_have_unique_name, 0);
436
437         return g_str_hash (proxy->object_path) ^ g_str_hash (proxy->bus_name);
438 }
439
440 gboolean
441 empathy_proxy_equal (gconstpointer a,
442                      gconstpointer b)
443 {
444         TpProxy *proxy_a = TP_PROXY (a);
445         TpProxy *proxy_b = TP_PROXY (b);
446         TpProxyClass *proxy_a_class = TP_PROXY_GET_CLASS (a);
447         TpProxyClass *proxy_b_class = TP_PROXY_GET_CLASS (b);
448
449         g_return_val_if_fail (TP_IS_PROXY (proxy_a), FALSE);
450         g_return_val_if_fail (TP_IS_PROXY (proxy_b), FALSE);
451         g_return_val_if_fail (proxy_a_class->must_have_unique_name, 0);
452         g_return_val_if_fail (proxy_b_class->must_have_unique_name, 0);
453
454         return g_str_equal (proxy_a->object_path, proxy_b->object_path) &&
455                g_str_equal (proxy_a->bus_name, proxy_b->bus_name);
456 }
457
458 gboolean
459 empathy_check_available_state (void)
460 {
461         TpConnectionPresenceType presence;
462         EmpathyIdle *idle;
463
464         idle = empathy_idle_dup_singleton ();
465         presence = empathy_idle_get_state (idle);
466         g_object_unref (idle);
467
468         if (presence != TP_CONNECTION_PRESENCE_TYPE_AVAILABLE &&
469                 presence != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
470                 return FALSE;
471         }
472
473         return TRUE;
474 }
475
476 gint
477 empathy_uint_compare (gconstpointer a,
478                       gconstpointer b)
479 {
480         return *(guint *) a - *(guint *) b;
481 }
482
483 gchar *
484 empathy_protocol_icon_name (const gchar *protocol)
485 {
486   if (!tp_strdiff (protocol, "yahoojp"))
487     /* Yahoo Japan uses the same icon as Yahoo */
488     protocol = "yahoo";
489   else if (!tp_strdiff (protocol, "simple"))
490     /* SIMPLE uses the same icon as SIP */
491     protocol = "sip";
492   else if (!tp_strdiff (protocol, "sms"))
493     return g_strdup ("phone");
494
495   return g_strdup_printf ("im-%s", protocol);
496 }
497
498 GType
499 empathy_type_dbus_ao (void)
500 {
501   static GType t = 0;
502
503   if (G_UNLIKELY (t == 0))
504      t = dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH);
505
506   return t;
507 }
508
509 const char *
510 empathy_protocol_name_to_display_name (const gchar *proto_name)
511 {
512   int i;
513   static struct {
514     const gchar *proto;
515     const gchar *display;
516     gboolean translated;
517   } names[] = {
518     { "jabber", "Jabber", FALSE },
519     { "gtalk", "Google Talk", FALSE },
520     { "msn", "MSN", FALSE, },
521     { "local-xmpp", N_("People Nearby"), TRUE },
522     { "irc", "IRC", FALSE },
523     { "icq", "ICQ", FALSE },
524     { "aim", "AIM", FALSE },
525     { "yahoo", "Yahoo!", FALSE },
526     { "yahoojp", N_("Yahoo! Japan"), TRUE },
527     { "facebook", N_("Facebook Chat"), TRUE },
528     { "groupwise", "GroupWise", FALSE },
529     { "sip", "SIP", FALSE },
530     { NULL, NULL }
531   };
532
533   for (i = 0; names[i].proto != NULL; i++)
534     {
535       if (!tp_strdiff (proto_name, names[i].proto))
536         {
537           if (names[i].translated)
538             return _(names[i].display);
539           else
540             return names[i].display;
541         }
542     }
543
544   return NULL;
545 }
546
547 /* Note: this function depends on the account manager having its core feature
548  * prepared. */
549 TpAccount *
550 empathy_get_account_for_connection (TpConnection *connection)
551 {
552   TpAccountManager *manager;
553   TpAccount *account = NULL;
554   GList *accounts, *l;
555
556   manager = tp_account_manager_dup ();
557
558   accounts = tp_account_manager_get_valid_accounts (manager);
559
560   for (l = accounts; l != NULL; l = l->next)
561     {
562       TpAccount *a = l->data;
563
564       if (tp_account_get_connection (a) == connection)
565         {
566           account = a;
567           break;
568         }
569     }
570
571   g_list_free (accounts);
572   g_object_unref (manager);
573
574   return account;
575 }
576
577 gboolean
578 empathy_account_manager_get_accounts_connected (gboolean *connecting)
579 {
580   TpAccountManager *manager;
581   GList *accounts, *l;
582   gboolean out_connecting = FALSE;
583   gboolean out_connected = FALSE;
584
585   manager = tp_account_manager_dup ();
586
587   if (G_UNLIKELY (!tp_account_manager_is_prepared (manager,
588           TP_ACCOUNT_MANAGER_FEATURE_CORE)))
589     g_critical (G_STRLOC ": %s called before AccountManager ready", G_STRFUNC);
590
591   accounts = tp_account_manager_get_valid_accounts (manager);
592
593   for (l = accounts; l != NULL; l = l->next)
594     {
595       TpConnectionStatus s = tp_account_get_connection_status (
596           TP_ACCOUNT (l->data), NULL);
597
598       if (s == TP_CONNECTION_STATUS_CONNECTING)
599         out_connecting = TRUE;
600       else if (s == TP_CONNECTION_STATUS_CONNECTED)
601         out_connected = TRUE;
602
603       if (out_connecting && out_connected)
604         break;
605     }
606
607   g_list_free (accounts);
608   g_object_unref (manager);
609
610   if (connecting != NULL)
611     *connecting = out_connecting;
612
613   return out_connected;
614 }
615
616 /* Change the RequestedPresence of a newly created account to ensure that it
617  * is actually connected. */
618 void
619 empathy_connect_new_account (TpAccount *account,
620     TpAccountManager *account_manager)
621 {
622   TpConnectionPresenceType presence;
623   gchar *status, *message;
624
625   /* only force presence if presence was offline, unknown or unset */
626   presence = tp_account_get_requested_presence (account, NULL, NULL);
627   switch (presence)
628     {
629       case TP_CONNECTION_PRESENCE_TYPE_OFFLINE:
630       case TP_CONNECTION_PRESENCE_TYPE_UNKNOWN:
631       case TP_CONNECTION_PRESENCE_TYPE_UNSET:
632         presence = tp_account_manager_get_most_available_presence (
633             account_manager, &status, &message);
634
635         if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE)
636           /* Global presence is offline; we force it so user doesn't have to
637            * manually change the presence to connect his new account. */
638           presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
639
640         tp_account_request_presence_async (account, presence,
641             status, NULL, NULL, NULL);
642
643         g_free (status);
644         g_free (message);
645         break;
646
647        case TP_CONNECTION_PRESENCE_TYPE_AVAILABLE:
648        case TP_CONNECTION_PRESENCE_TYPE_AWAY:
649        case TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY:
650        case TP_CONNECTION_PRESENCE_TYPE_HIDDEN:
651        case TP_CONNECTION_PRESENCE_TYPE_BUSY:
652        case TP_CONNECTION_PRESENCE_TYPE_ERROR:
653        default:
654         /* do nothing if the presence is not offline */
655         break;
656     }
657 }
658
659 /* Translate Folks' general presence type to the Tp presence type */
660 TpConnectionPresenceType
661 empathy_folks_presence_type_to_tp (FolksPresenceType type)
662 {
663   return (TpConnectionPresenceType) type;
664 }
665
666 /* Returns TRUE if the given Individual contains a TpContact */
667 gboolean
668 empathy_folks_individual_contains_contact (FolksIndividual *individual)
669 {
670   GList *personas, *l;
671
672   g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), FALSE);
673
674   personas = folks_individual_get_personas (individual);
675   for (l = personas; l != NULL; l = l->next)
676     {
677       if (TPF_IS_PERSONA (l->data))
678         return (tpf_persona_get_contact (TPF_PERSONA (l->data)) != NULL);
679     }
680
681   return FALSE;
682 }
683
684 /* TODO: this needs to be eliminated (and replaced in some cases with user
685  * prompts) when we break the assumption that FolksIndividuals are 1:1 with
686  * TpContacts */
687
688 /* Retrieve the EmpathyContact corresponding to the first TpContact contained
689  * within the given Individual. Note that this is a temporary convenience. See
690  * the TODO above. */
691 EmpathyContact *
692 empathy_contact_dup_from_folks_individual (FolksIndividual *individual)
693 {
694   GList *personas, *l;
695   EmpathyContact *contact = NULL;
696
697   g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
698
699   personas = folks_individual_get_personas (individual);
700   for (l = personas; (l != NULL) && (contact == NULL); l = l->next)
701     {
702       TpfPersona *persona = l->data;
703
704       if (TPF_IS_PERSONA (persona))
705         {
706           TpContact *tp_contact;
707
708           tp_contact = tpf_persona_get_contact (persona);
709           contact = empathy_contact_dup_from_tp_contact (tp_contact);
710           empathy_contact_set_persona (contact, FOLKS_PERSONA (persona));
711         }
712     }
713
714   return contact;
715 }
716
717 TpChannelGroupChangeReason
718 tp_chanel_group_change_reason_from_folks_groups_change_reason (
719     FolksGroupsChangeReason reason)
720 {
721   return (TpChannelGroupChangeReason) reason;
722 }