]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-request-util.c
EmpathySmileyManager: use the proper Unicode characters
[empathy.git] / libempathy / empathy-request-util.c
index c912cc1a23cf201a383cc1d5c5d8cf2b92768ed5..4eb83348f4a40f41aca1f9e559c9ae2a33da72a0 100644 (file)
  *          Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
  */
 
-#include <config.h>
-
-#include <string.h>
-
-#include <glib/gi18n-lib.h>
-
-#include <telepathy-glib/telepathy-glib.h>
-
+#include "config.h"
 #include "empathy-request-util.h"
-#include "empathy-utils.h"
-#include "empathy-utils.h"
+
+#include <telepathy-glib/telepathy-glib-dbus.h>
 
 #define DEBUG_FLAG EMPATHY_DEBUG_DISPATCHER
-#include <libempathy/empathy-debug.h>
+#include "empathy-debug.h"
 
 void
 empathy_chat_with_contact (EmpathyContact *contact,
@@ -40,7 +33,7 @@ empathy_chat_with_contact (EmpathyContact *contact,
 {
   empathy_chat_with_contact_id (
       empathy_contact_get_account (contact), empathy_contact_get_id (contact),
-      timestamp);
+      timestamp, NULL, NULL);
 }
 
 static void
@@ -58,50 +51,62 @@ ensure_text_channel_cb (GObject *source,
     }
 }
 
-void
-empathy_chat_with_contact_id (TpAccount *account,
-    const gchar *contact_id,
-    gint64 timestamp)
+static void
+create_text_channel (TpAccount *account,
+    TpHandleType target_handle_type,
+    const gchar *target_id,
+    gboolean sms_channel,
+    gint64 timestamp,
+    GAsyncReadyCallback callback,
+    gpointer user_data)
 {
-  GHashTable *request;
   TpAccountChannelRequest *req;
 
-  request = tp_asv_new (
-      TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
-        TP_IFACE_CHANNEL_TYPE_TEXT,
-      TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
-      TP_PROP_CHANNEL_TARGET_ID, G_TYPE_STRING, contact_id,
-      NULL);
+  req = tp_account_channel_request_new_text (account, timestamp);
+  tp_account_channel_request_set_target_id (req, target_handle_type, target_id);
+  tp_account_channel_request_set_delegate_to_preferred_handler (req, TRUE);
 
-  req = tp_account_channel_request_new (account, request, timestamp);
+  if (sms_channel)
+    tp_account_channel_request_set_sms_channel (req, TRUE);
 
-  tp_account_channel_request_ensure_channel_async (req, NULL, NULL,
-      ensure_text_channel_cb, NULL);
+  tp_account_channel_request_ensure_channel_async (req,
+      EMPATHY_CHAT_TP_BUS_NAME, NULL,
+      callback ? callback : ensure_text_channel_cb, user_data);
 
-  g_hash_table_unref (request);
   g_object_unref (req);
 }
 
+/* @callback is optional, but if it's provided, it should call the right
+ * _finish() func that we call in ensure_text_channel_cb() */
+void
+empathy_chat_with_contact_id (TpAccount *account,
+    const gchar *contact_id,
+    gint64 timestamp,
+    GAsyncReadyCallback callback,
+    gpointer user_data)
+{
+  create_text_channel (account, TP_HANDLE_TYPE_CONTACT,
+      contact_id, FALSE, timestamp, callback, user_data);
+}
+
 void
 empathy_join_muc (TpAccount *account,
     const gchar *room_name,
     gint64 timestamp)
 {
-  GHashTable *request;
-  TpAccountChannelRequest *req;
-
-  request = tp_asv_new (
-      TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
-        TP_IFACE_CHANNEL_TYPE_TEXT,
-      TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_ROOM,
-      TP_PROP_CHANNEL_TARGET_ID, G_TYPE_STRING, room_name,
-      NULL);
-
-  req = tp_account_channel_request_new (account, request, timestamp);
-
-  tp_account_channel_request_ensure_channel_async (req, NULL, NULL,
-      ensure_text_channel_cb, NULL);
+  create_text_channel (account, TP_HANDLE_TYPE_ROOM,
+      room_name, FALSE, timestamp, NULL, NULL);
+}
 
-  g_hash_table_unref (request);
-  g_object_unref (req);
+/* @callback is optional, but if it's provided, it should call the right
+ * _finish() func that we call in ensure_text_channel_cb() */
+void
+empathy_sms_contact_id (TpAccount *account,
+    const gchar *contact_id,
+    gint64 timestamp,
+    GAsyncReadyCallback callback,
+    gpointer user_data)
+{
+  create_text_channel (account, TP_HANDLE_TYPE_CONTACT,
+      contact_id, TRUE, timestamp, callback, user_data);
 }