]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-utils.c
Merge branch 'gnome-3-8'
[empathy.git] / libempathy / empathy-utils.c
index c73f6514e2d407f712ea6d0d0d8d8c2cfa22417e..c9eb5ca6f9b9a2d016fa1bc6f1390516723fcae9 100644 (file)
  */
 
 #include "config.h"
-
-#include <string.h>
-#include <math.h>
-#include <time.h>
-#include <sys/types.h>
+#include "empathy-utils.h"
 
 #include <glib/gi18n-lib.h>
-
-#include <libxml/uri.h>
-
-#include <folks/folks.h>
-#include <folks/folks-telepathy.h>
-
 #include <dbus/dbus-protocol.h>
 
-#include <telepathy-glib/account-manager.h>
-#include <telepathy-glib/connection.h>
-#include <telepathy-glib/channel.h>
-#include <telepathy-glib/dbus.h>
-#include <telepathy-glib/util.h>
-
 #include "empathy-client-factory.h"
-#include "empathy-utils.h"
-#include "empathy-individual-manager.h"
 #include "empathy-presence-manager.h"
-#include "empathy-request-util.h"
-
-#include <extensions/extensions.h>
+#include "extensions.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
 #include "empathy-debug.h"
@@ -126,36 +106,36 @@ empathy_init (void)
 }
 
 gboolean
-empathy_xml_validate (xmlDoc      *doc,
-    const gchar *dtd_filename)
+empathy_xml_validate_from_resource (xmlDoc *doc,
+    const gchar *dtd_resourcename)
 {
-  gchar *path;
-  xmlChar *escaped;
+  GBytes *resourcecontents;
+  gconstpointer resourcedata;
+  gsize resourcesize;
+  xmlParserInputBufferPtr buffer;
   xmlValidCtxt  cvp;
   xmlDtd *dtd;
+  GError *error = NULL;
   gboolean ret;
 
-  path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "libempathy",
-         dtd_filename, NULL);
-  if (!g_file_test (path, G_FILE_TEST_EXISTS))
+  DEBUG ("Loading dtd resource %s", dtd_resourcename);
+
+  resourcecontents = g_resources_lookup_data (dtd_resourcename, G_RESOURCE_LOOKUP_FLAGS_NONE, &error);
+  if (error != NULL)
     {
-      g_free (path);
-      path = g_build_filename (DATADIR, "empathy", dtd_filename, NULL);
+      g_warning ("Unable to load dtd resource '%s': %s", dtd_resourcename, error->message);
+      g_error_free (error);
+      return FALSE;
     }
-
-  DEBUG ("Loading dtd file %s", path);
-
-  /* The list of valid chars is taken from libxml. */
-  escaped = xmlURIEscapeStr ((const xmlChar *) path,
-    (const xmlChar *)":@&=+$,/?;");
-  g_free (path);
+  resourcedata = g_bytes_get_data (resourcecontents, &resourcesize);
+  buffer = xmlParserInputBufferCreateStatic (resourcedata, resourcesize, XML_CHAR_ENCODING_UTF8);
 
   memset (&cvp, 0, sizeof (cvp));
-  dtd = xmlParseDTD (NULL, escaped);
+  dtd = xmlIOParseDTD (NULL, buffer, XML_CHAR_ENCODING_UTF8);
   ret = xmlValidateDtd (&cvp, doc, dtd);
 
-  xmlFree (escaped);
   xmlFreeDtd (dtd);
+  g_bytes_unref (resourcecontents);
 
   return ret;
 }
@@ -439,36 +419,6 @@ empathy_file_lookup (const gchar *filename, const gchar *subdir)
   return path;
 }
 
-guint
-empathy_proxy_hash (gconstpointer key)
-{
-  TpProxy *proxy = TP_PROXY (key);
-  TpProxyClass *proxy_class = TP_PROXY_GET_CLASS (key);
-
-  g_return_val_if_fail (TP_IS_PROXY (proxy), 0);
-  g_return_val_if_fail (proxy_class->must_have_unique_name, 0);
-
-  return g_str_hash (proxy->object_path) ^ g_str_hash (proxy->bus_name);
-}
-
-gboolean
-empathy_proxy_equal (gconstpointer a,
-    gconstpointer b)
-{
-  TpProxy *proxy_a = TP_PROXY (a);
-  TpProxy *proxy_b = TP_PROXY (b);
-  TpProxyClass *proxy_a_class = TP_PROXY_GET_CLASS (a);
-  TpProxyClass *proxy_b_class = TP_PROXY_GET_CLASS (b);
-
-  g_return_val_if_fail (TP_IS_PROXY (proxy_a), FALSE);
-  g_return_val_if_fail (TP_IS_PROXY (proxy_b), FALSE);
-  g_return_val_if_fail (proxy_a_class->must_have_unique_name, 0);
-  g_return_val_if_fail (proxy_b_class->must_have_unique_name, 0);
-
-  return g_str_equal (proxy_a->object_path, proxy_b->object_path) &&
-         g_str_equal (proxy_a->bus_name, proxy_b->bus_name);
-}
-
 gboolean
 empathy_check_available_state (void)
 {
@@ -538,6 +488,13 @@ empathy_protocol_name_to_display_name (const gchar *proto_name)
     { "yahoojp", N_("Yahoo! Japan"), TRUE },
     { "groupwise", "GroupWise", FALSE },
     { "sip", "SIP", FALSE },
+    { "gadugadu", "Gadu-Gadu", FALSE },
+    { "mxit", "Mxit", FALSE },
+    { "myspace", "Myspace", FALSE },
+    { "sametime", "Sametime", FALSE },
+    { "skype-dbus", "Skype (D-BUS)", FALSE },
+    { "skype-x11", "Skype (X11)", FALSE },
+    { "zephyr", "Zephyr", FALSE },
     { NULL, NULL }
   };
 
@@ -597,7 +554,7 @@ empathy_account_manager_get_accounts_connected (gboolean *connecting)
           TP_ACCOUNT_MANAGER_FEATURE_CORE)))
     g_critical (G_STRLOC ": %s called before AccountManager ready", G_STRFUNC);
 
-  accounts = tp_account_manager_get_valid_accounts (manager);
+  accounts = tp_account_manager_dup_valid_accounts (manager);
 
   for (l = accounts; l != NULL; l = l->next)
     {
@@ -613,7 +570,7 @@ empathy_account_manager_get_accounts_connected (gboolean *connecting)
         break;
     }
 
-  g_list_free (accounts);
+  g_list_free_full (accounts, g_object_unref);
   g_object_unref (manager);
 
   if (connecting != NULL)
@@ -1152,18 +1109,17 @@ while_finish:
 }
 
 gboolean
-empathy_sasl_channel_supports_mechanism (TpChannel *channel,
-    const gchar *mechanism)
-{
-  GHashTable *props;
-  const gchar * const *available_mechanisms;
+empathy_client_types_contains_mobile_device (const GStrv types) {
+  int i;
 
-  props = tp_channel_borrow_immutable_properties (channel);
-  available_mechanisms = tp_asv_get_boxed (props,
-      TP_PROP_CHANNEL_INTERFACE_SASL_AUTHENTICATION_AVAILABLE_MECHANISMS,
-      G_TYPE_STRV);
+  if (types == NULL)
+    return FALSE;
+
+  for (i = 0; types[i] != NULL; i++)
+    if (!tp_strdiff (types[i], "phone") || !tp_strdiff (types[i], "handheld"))
+        return TRUE;
 
-  return tp_strv_contains (available_mechanisms, mechanism);
+  return FALSE;
 }
 
 static FolksIndividual *
@@ -1174,7 +1130,7 @@ create_individual_from_persona (FolksPersona *persona)
 
   personas = GEE_SET (
       gee_hash_set_new (FOLKS_TYPE_PERSONA, g_object_ref, g_object_unref,
-      g_direct_hash, g_direct_equal));
+      NULL, NULL, NULL, NULL, NULL, NULL));
 
   gee_collection_add (GEE_COLLECTION (personas), persona);
 
@@ -1231,3 +1187,74 @@ empathy_ensure_individual_from_tp_contact (TpContact *contact)
   g_object_unref (persona);
   return individual;
 }
+
+const gchar * const *
+empathy_individual_get_client_types (FolksIndividual *individual)
+{
+  GeeSet *personas;
+  GeeIterator *iter;
+  const gchar * const *types = NULL;
+  FolksPresenceType presence_type = FOLKS_PRESENCE_TYPE_UNSET;
+
+  personas = folks_individual_get_personas (individual);
+  iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+  while (gee_iterator_next (iter))
+    {
+      FolksPresenceDetails *presence;
+      FolksPersona *persona = gee_iterator_get (iter);
+
+      /* We only want personas which have presence and a TpContact */
+      if (!empathy_folks_persona_is_interesting (persona))
+        goto while_finish;
+
+      presence = FOLKS_PRESENCE_DETAILS (persona);
+
+      if (folks_presence_details_typecmp (
+              folks_presence_details_get_presence_type (presence),
+              presence_type) > 0)
+        {
+          TpContact *tp_contact;
+
+          presence_type = folks_presence_details_get_presence_type (presence);
+
+          tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
+          if (tp_contact != NULL)
+            types = tp_contact_get_client_types (tp_contact);
+        }
+
+while_finish:
+      g_clear_object (&persona);
+    }
+  g_clear_object (&iter);
+
+  return types;
+}
+
+GVariant *
+empathy_asv_to_vardict (const GHashTable *asv)
+{
+  return empathy_boxed_to_variant (TP_HASH_TYPE_STRING_VARIANT_MAP, "a{sv}",
+      (gpointer) asv);
+}
+
+GVariant *
+empathy_boxed_to_variant (GType gtype,
+    const gchar *variant_type,
+    gpointer boxed)
+{
+  GValue v = G_VALUE_INIT;
+  GVariant *ret;
+
+  g_return_val_if_fail (boxed != NULL, NULL);
+
+  g_value_init (&v, gtype);
+  g_value_set_boxed (&v, boxed);
+
+  ret = dbus_g_value_build_g_variant (&v);
+  g_return_val_if_fail (!tp_strdiff (g_variant_get_type_string (ret),
+        variant_type), NULL);
+
+  g_value_unset (&v);
+
+  return g_variant_ref_sink (ret);
+}