]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-utils.c
Try to load dtd and glade files from the srcdir first to aboid having to install...
[empathy.git] / libempathy / empathy-utils.c
index f33d83e48b122232ab52a275c580dbf5b27971ee..4050f46738924c0e6c782e1c379f5449626792ad 100644 (file)
@@ -199,82 +199,6 @@ empathy_strncasecmp (const gchar *s1,
        return ret_val;
 }
 
-/* Stolen from telepathy-glib */
-gboolean
-empathy_strdiff (const gchar *left, const gchar *right)
-{
-  if ((NULL == left) != (NULL == right))
-    return TRUE;
-
-  else if (left == right)
-    return FALSE;
-
-  else
-    return (0 != strcmp (left, right));
-}
-
-/* Stolen from telepathy-glib */
-static inline gboolean
-_esc_ident_bad (gchar c, gboolean is_first)
-{
-  return ((c < 'a' || c > 'z') &&
-          (c < 'A' || c > 'Z') &&
-          (c < '0' || c > '9' || is_first));
-}
-
-/* Stolen from telepathy-glib */
-gchar *
-empathy_escape_as_identifier (const gchar *name)
-{
-  gboolean bad = FALSE;
-  size_t len = 0;
-  GString *op;
-  const gchar *ptr, *first_ok;
-
-  g_return_val_if_fail (name != NULL, NULL);
-
-  for (ptr = name; *ptr; ptr++)
-    {
-      if (_esc_ident_bad (*ptr, ptr == name))
-        {
-          bad = TRUE;
-          len += 3;
-        }
-      else
-        len++;
-    }
-
-  /* fast path if it's clean */
-  if (!bad)
-    return g_strdup (name);
-
-  /* If strictly less than ptr, first_ok is the first uncopied safe character.
-   */
-  first_ok = name;
-  op = g_string_sized_new (len);
-  for (ptr = name; *ptr; ptr++)
-    {
-      if (_esc_ident_bad (*ptr, ptr == name))
-        {
-          /* copy preceding safe characters if any */
-          if (first_ok < ptr)
-            {
-              g_string_append_len (op, first_ok, ptr - first_ok);
-            }
-          /* escape the unsafe character */
-          g_string_append_printf (op, "_%02x", (unsigned char)(*ptr));
-          /* restart after it */
-          first_ok = ptr + 1;
-        }
-    }
-  /* copy trailing safe characters if any */
-  if (first_ok < ptr)
-    {
-      g_string_append_len (op, first_ok, ptr - first_ok);
-    }
-  return g_string_free (op, FALSE);
-}
-
 gboolean
 empathy_xml_validate (xmlDoc      *doc,
                     const gchar *dtd_filename)
@@ -284,11 +208,15 @@ empathy_xml_validate (xmlDoc      *doc,
        xmlDtd       *dtd;
        gboolean      ret;
 
-       path = g_build_filename (DATADIR, "empathy", dtd_filename, NULL);
+       path = g_build_filename (UNINSTALLED_DTD_DIR, dtd_filename, NULL);
+       if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
+               g_free (path);
+               path = g_build_filename (DATADIR, "empathy", dtd_filename, NULL);
+       }
+       empathy_debug (DEBUG_DOMAIN, "Loading dtd file %s", path);
 
        /* The list of valid chars is taken from libxml. */
        escaped = xmlURIEscapeStr (path, ":@&=+$,/?;");
-
        g_free (path);
 
        memset (&cvp, 0, sizeof (cvp));
@@ -369,16 +297,21 @@ empathy_xml_node_find_child_prop_value (xmlNodePtr   node,
 guint
 empathy_account_hash (gconstpointer key)
 {
+       g_return_val_if_fail (MC_IS_ACCOUNT (key), 0);
+
        return g_str_hash (mc_account_get_unique_name (MC_ACCOUNT (key)));
 }
 
 gboolean
 empathy_account_equal (gconstpointer a,
-                     gconstpointer b)
+                      gconstpointer b)
 {
        const gchar *name_a;
        const gchar *name_b;
 
+       g_return_val_if_fail (MC_IS_ACCOUNT (a), FALSE);
+       g_return_val_if_fail (MC_IS_ACCOUNT (b), FALSE);
+
        name_a = mc_account_get_unique_name (MC_ACCOUNT (a));
        name_b = mc_account_get_unique_name (MC_ACCOUNT (b));
 
@@ -422,7 +355,7 @@ empathy_inspect_handle (McAccount *account,
        GArray          *handles;
        gchar          **names;
        gchar           *name;
-       GError          *error;
+       GError          *error = NULL;
 
        g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
        g_return_val_if_fail (handle != 0, NULL);
@@ -474,7 +407,9 @@ empathy_call_contact (EmpathyContact *contact)
        const gchar    *bus_name;
        TpChan         *new_chan;
        EmpathyTpGroup *group;
-       GError         *error;
+       GError         *error = NULL;
+
+       g_return_if_fail (EMPATHY_IS_CONTACT (contact));
 
        /* StreamedMedia channels must have handle=0 and handle_type=none.
         * To call a contact we have to add him in the group interface of the
@@ -509,14 +444,10 @@ empathy_call_contact (EmpathyContact *contact)
                                TP_HANDLE_TYPE_NONE,
                                0);
 
-       /* FIXME: group is leaked, we can't unref it directly because
-        * _add_member is async so we have to wait for it to return before
-        * finalizing the group. I think EmpathyTpGroup should ref itself
-        * when it does async calls to avoid finalizing when there is calls
-        * in fligth like that we could unref it here. */
        group = empathy_tp_group_new (account, new_chan);
        empathy_tp_group_add_member (group, contact, "");
 
+       g_object_unref (group);
        g_object_unref (mc);
        g_object_unref (tp_conn);
        g_object_unref (new_chan);
@@ -524,3 +455,33 @@ empathy_call_contact (EmpathyContact *contact)
 #endif
 }
 
+void
+empathy_chat_with_contact (EmpathyContact  *contact)
+{
+       MissionControl *mc;
+
+       mc = empathy_mission_control_new ();
+       mission_control_request_channel (mc,
+                                        empathy_contact_get_account (contact),
+                                        TP_IFACE_CHANNEL_TYPE_TEXT,
+                                        empathy_contact_get_handle (contact),
+                                        TP_HANDLE_TYPE_CONTACT,
+                                        NULL, NULL);
+       g_object_unref (mc);
+}
+
+void
+empathy_chat_with_contact_id (McAccount *account, const gchar *contact_id)
+{
+       MissionControl *mc;
+
+       mc = empathy_mission_control_new ();
+       mission_control_request_channel_with_string_handle (mc,
+                                                           account,
+                                                           TP_IFACE_CHANNEL_TYPE_TEXT,
+                                                           contact_id,
+                                                           TP_HANDLE_TYPE_CONTACT,
+                                                           NULL, NULL);
+       g_object_unref (mc);
+}
+