]> 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 a1404f4036eac53506551ac9380081421dcc9b92..4050f46738924c0e6c782e1c379f5449626792ad 100644 (file)
@@ -38,6 +38,7 @@
 #include "empathy-debug.h"
 #include "empathy-utils.h"
 #include "empathy-contact-manager.h"
+#include "empathy-tp-group.h"
 
 #define DEBUG_DOMAIN "Utils"
 
@@ -207,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));
@@ -292,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));
 
@@ -345,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);
@@ -378,6 +388,7 @@ empathy_inspect_handle (McAccount *account,
                return NULL;
        }
 
+       g_array_free (handles, TRUE);
        name = *names;
        g_free (names);
        g_object_unref (tp_conn);
@@ -385,17 +396,92 @@ empathy_inspect_handle (McAccount *account,
        return name;
 }
 
-/* Stolen from telepathy-glib */
-gboolean
-empathy_strdiff (const gchar *left, const gchar *right)
+void
+empathy_call_contact (EmpathyContact *contact)
+{
+#ifdef HAVE_VOIP
+       MissionControl *mc;
+       McAccount      *account;
+       TpConn         *tp_conn;
+       gchar          *object_path;
+       const gchar    *bus_name;
+       TpChan         *new_chan;
+       EmpathyTpGroup *group;
+       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
+        * channel. MissionControl will detect the channel creation and 
+        * dispatch it to the VoIP chandler automatically. */
+
+       mc = empathy_mission_control_new ();
+       account = empathy_contact_get_account (contact);
+       tp_conn = mission_control_get_connection (mc, account, NULL);
+       /* FIXME: Should be async */
+       if (!tp_conn_request_channel (DBUS_G_PROXY (tp_conn),
+                                     TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
+                                     TP_HANDLE_TYPE_NONE,
+                                     0,
+                                     FALSE,
+                                     &object_path,
+                                     &error)) {
+               empathy_debug (DEBUG_DOMAIN, 
+                             "Couldn't request channel: %s",
+                             error ? error->message : "No error given");
+               g_clear_error (&error);
+               g_object_unref (mc);
+               g_object_unref (tp_conn);
+               return;
+       }
+
+       bus_name = dbus_g_proxy_get_bus_name (DBUS_G_PROXY (tp_conn));
+       new_chan = tp_chan_new (tp_get_bus (),
+                               bus_name,
+                               object_path,
+                               TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
+                               TP_HANDLE_TYPE_NONE,
+                               0);
+
+       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);
+       g_free (object_path);
+#endif
+}
+
+void
+empathy_chat_with_contact (EmpathyContact  *contact)
 {
-  if ((NULL == left) != (NULL == right))
-    return TRUE;
+       MissionControl *mc;
 
-  else if (left == right)
-    return FALSE;
+       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);
+}
 
-  else
-    return (0 != strcmp (left, right));
+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);
 }