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