empathy r2143 - trunk/libempathy



Author: xclaesse
Date: Fri Jan  9 16:12:57 2009
New Revision: 2143
URL: http://svn.gnome.org/viewvc/empathy?rev=2143&view=rev

Log:
Add request muc channels to the dispatcher

Signed-off-by: Sjoerd Simons <sjoerd simons collabora co uk>

Modified:
   trunk/libempathy/empathy-dispatcher.c
   trunk/libempathy/empathy-dispatcher.h

Modified: trunk/libempathy/empathy-dispatcher.c
==============================================================================
--- trunk/libempathy/empathy-dispatcher.c	(original)
+++ trunk/libempathy/empathy-dispatcher.c	Fri Jan  9 16:12:57 2009
@@ -1401,7 +1401,6 @@
 out:
   dispatcher_flush_outstanding_operations (request_data->dispatcher,
     conn_data);
-
 }
 
 static void
@@ -1432,12 +1431,8 @@
 }
 
 static void
-dispatcher_chat_with_contact_cb (EmpathyContact *contact, gpointer user_data)
+dispatcher_request_channel (DispatcherRequestData *request_data)
 {
-  DispatcherRequestData *request_data = (DispatcherRequestData *) user_data;
-
-  request_data->handle = empathy_contact_get_handle (contact);
-
   tp_cli_connection_call_request_channel (request_data->connection, -1,
     request_data->channel_type,
     request_data->handle_type,
@@ -1446,6 +1441,16 @@
     request_data, NULL, G_OBJECT (request_data->dispatcher));
 }
 
+static void
+dispatcher_chat_with_contact_cb (EmpathyContact *contact, gpointer user_data)
+{
+  DispatcherRequestData *request_data = (DispatcherRequestData *) user_data;
+
+  request_data->handle = empathy_contact_get_handle (contact);
+
+  dispatcher_request_channel (request_data);
+}
+
 void
 empathy_dispatcher_chat_with_contact (EmpathyContact *contact,
   EmpathyDispatcherRequestCb *callback, gpointer user_data)
@@ -1491,6 +1496,66 @@
   g_object_unref (dispatcher);
 }
 
+
+static void
+dispatcher_request_handles_cb (TpConnection *connection,
+   const GArray *handles, const GError *error, gpointer user_data,
+   GObject *object)
+{
+  DispatcherRequestData *request_data = (DispatcherRequestData *) user_data;
+
+  if (error != NULL)
+    {
+      EmpathyDispatcher *dispatcher = EMPATHY_DISPATCHER (object);
+      EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
+      ConnectionData *cd;
+
+      cd = g_hash_table_lookup (priv->connections, request_data->connection);
+
+      if (request_data->cb)
+        request_data->cb (NULL, error, request_data->user_data);
+
+      cd->outstanding_requests = g_list_remove (cd->outstanding_requests,
+        request_data);
+
+      free_dispatcher_request_data (request_data);
+
+      dispatcher_flush_outstanding_operations (dispatcher, cd);
+      return;
+    }
+
+  request_data->handle = g_array_index (handles, guint, 0);
+  dispatcher_request_channel (request_data);
+}
+
+void
+empathy_dispatcher_join_muc (McAccount *account, const gchar *roomname,
+  EmpathyDispatcherRequestCb *callback, gpointer user_data)
+{
+  EmpathyDispatcher *dispatcher = empathy_get_dispatcher();
+  EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
+  DispatcherRequestData *request_data;
+  TpConnection *connection = g_hash_table_lookup (priv->accounts, account);
+  ConnectionData *connection_data =
+    g_hash_table_lookup (priv->connections, connection);
+  const gchar *names[] = { roomname, NULL };
+
+  /* Don't know the room handle yet */
+  request_data  = new_dispatcher_request_data (dispatcher, connection,
+    TP_IFACE_CHANNEL_TYPE_TEXT, TP_HANDLE_TYPE_ROOM, 0, NULL,
+    NULL, callback, user_data);
+
+  connection_data->outstanding_requests = g_list_prepend
+    (connection_data->outstanding_requests, request_data);
+
+  tp_cli_connection_call_request_handles (connection, -1,
+    TP_HANDLE_TYPE_ROOM, names,
+    dispatcher_request_handles_cb, request_data, NULL,
+    G_OBJECT (dispatcher));
+
+  g_object_unref (dispatcher);
+}
+
 #if 0
 typedef struct {
 	GFile *gfile;

Modified: trunk/libempathy/empathy-dispatcher.h
==============================================================================
--- trunk/libempathy/empathy-dispatcher.h	(original)
+++ trunk/libempathy/empathy-dispatcher.h	Fri Jan  9 16:12:57 2009
@@ -68,35 +68,35 @@
 
 GType empathy_dispatcher_get_type             (void) G_GNUC_CONST;
 
+/* Requesting 1 to 1 stream media channels */
 void empathy_dispatcher_call_with_contact (EmpathyContact *contact,
   EmpathyDispatcherRequestCb *callback, gpointer user_data);
 void empathy_dispatcher_call_with_contact_id (McAccount *account,
   const gchar           *contact_id, EmpathyDispatcherRequestCb *callback,
   gpointer user_data);
 
+/* Requesting 1 to 1 text channels */
 void empathy_dispatcher_chat_with_contact_id (McAccount *account,
   const gchar *contact_id, EmpathyDispatcherRequestCb *callback,
   gpointer user_data);
 void  empathy_dispatcher_chat_with_contact (EmpathyContact *contact,
   EmpathyDispatcherRequestCb *callback, gpointer user_data);
 
-void empathy_dispatcher_chat_with_contact_id (McAccount *account,
-  const gchar *contact_id, EmpathyDispatcherRequestCb *callback,
-  gpointer user_data);
-void  empathy_dispatcher_chat_with_contact (EmpathyContact *contact,
-  EmpathyDispatcherRequestCb *callback, gpointer user_data);
-
+/* Request a file channel to a specific contact */
 void empathy_dispatcher_send_file_to_contact (EmpathyContact *contact,
   const gchar *filename, guint64 size, guint64 date,
   const gchar *content_type, EmpathyDispatcherRequestCb *callback,
   gpointer user_data);
 
+/* Request a muc channel */
+void empathy_dispatcher_join_muc (McAccount *account,
+  const gchar *roomname, EmpathyDispatcherRequestCb *callback,
+  gpointer user_data);
 
 /* Get the dispatcher singleton */
 EmpathyDispatcher *    empathy_get_dispatcher (void);
 GType                  empathy_dispatcher_tube_get_type        (void);
 
-
 /* tube stuff */
 EmpathyDispatcherTube *empathy_dispatcher_tube_ref             (EmpathyDispatcherTube *tube);
 void                   empathy_dispatcher_tube_unref           (EmpathyDispatcherTube *tube);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]