#include "empathy-debug.h"
#include "empathy-utils.h"
#include "empathy-contact-manager.h"
+#include "empathy-tp-group.h"
#define DEBUG_DOMAIN "Utils"
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));
return found;
}
-GType
-empathy_dbus_type_to_g_type (const gchar *dbus_type_string)
-{
- if (dbus_type_string == NULL)
- return G_TYPE_NONE;
-
- if (dbus_type_string[0] == 's') {
- return G_TYPE_STRING;
- }
- else if (dbus_type_string[0] == 'b') {
- return G_TYPE_BOOLEAN;
- }
- else if (dbus_type_string[0] == 'q') {
- return G_TYPE_UINT;
- }
- else if (dbus_type_string[0] == 'n') {
- return G_TYPE_INT;
- }
-
- g_assert_not_reached ();
- return G_TYPE_NONE;
-}
-
-const gchar *
-empathy_g_type_to_dbus_type (GType g_type)
-{
- switch (g_type) {
- case G_TYPE_STRING:
- return "s";
- case G_TYPE_BOOLEAN:
- return "b";
- case G_TYPE_UINT:
- return "q";
- case G_TYPE_INT:
- return "n";
- default:
- g_assert_not_reached ();
- }
-
- return NULL;
-}
-
-gchar *
-empathy_g_value_to_string (const GValue *value)
-{
- gchar *return_string = NULL;
- GValue string_g_value = {0, };
-
- g_value_init (&string_g_value, G_TYPE_STRING);
- g_value_transform (value, &string_g_value);
- return_string = g_value_dup_string (&string_g_value);
- g_value_unset (&string_g_value);
-
- return return_string;
-}
-
-GValue *
-empathy_string_to_g_value (const gchar *str, GType type)
-{
- GValue *g_value;
-
- g_value = g_new0 (GValue, 1);
- g_value_init (g_value, type);
-
- switch (type) {
- case G_TYPE_STRING:
- g_value_set_string (g_value, str);
- break;
- case G_TYPE_BOOLEAN:
- g_value_set_boolean (g_value, (str[0] == 'y' || str[0] == 'T'));
- break;
- case G_TYPE_UINT:
- g_value_set_uint (g_value, atoi (str));
- break;
- case G_TYPE_INT:
- g_value_set_int (g_value, atoi (str));
- break;
- default:
- g_assert_not_reached ();
- }
-
- return g_value;
-}
-
-gboolean
-empathy_g_value_equal (const GValue *value1,
- const GValue *value2)
-{
- GType type;
-
- g_return_val_if_fail (value1 != NULL, FALSE);
- g_return_val_if_fail (value2 != NULL, FALSE);
-
- type = G_VALUE_TYPE (value1);
- if (type != G_VALUE_TYPE (value2)) {
- return FALSE;
- }
-
- switch (type)
- {
- case G_TYPE_STRING: {
- const gchar *str1;
- const gchar *str2;
-
- str1 = g_value_get_string (value1);
- str2 = g_value_get_string (value2);
- return (str1 && str2 && strcmp (str1, str2) == 0) ||
- (G_STR_EMPTY (str1) && G_STR_EMPTY (str2));
- }
- case G_TYPE_BOOLEAN:
- return g_value_get_boolean (value1) == g_value_get_boolean (value2);
- case G_TYPE_UINT:
- return g_value_get_uint (value1) == g_value_get_uint (value2);
- case G_TYPE_INT:
- return g_value_get_int (value1) == g_value_get_int (value2);
- default:
- g_warning ("Unsupported GType in value comparaison");
- }
-
- return FALSE;
-}
-
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));
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);
return NULL;
}
+ g_array_free (handles, TRUE);
name = *names;
g_free (names);
g_object_unref (tp_conn);
return name;
}
+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)
+{
+ 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);
+}