[gnome-shell] Wrap tp_connection_get_contacts_by_handle



commit 1938a5bcb00b2c20c8145634adaf1584e865bc78
Author: Morten Mjelva <morten mjelva gmail com>
Date:   Mon Feb 7 16:21:30 2011 +0100

    Wrap tp_connection_get_contacts_by_handle
    
    GArray support is broken in Gjs. This commit wraps
    tp_connection_get_contacts_by_handle so we can retrieve TpContact objects.

 src/shell-global.c |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/shell-global.h |   13 +++++++++++
 2 files changed, 73 insertions(+), 0 deletions(-)
---
diff --git a/src/shell-global.c b/src/shell-global.c
index ec00690..de17526 100644
--- a/src/shell-global.c
+++ b/src/shell-global.c
@@ -1964,3 +1964,63 @@ gboolean _shell_global_check_xdnd_event (ShellGlobal  *global,
 
     return FALSE;
 }
+
+/**
+ * ShellGetTpContactCb:
+ * @connection: The connection
+ * @contacts: (element-type TelepathyGLib.Contact): List of contacts
+ * @failed: Array of failed contacts
+ */
+
+static void
+shell_global_get_tp_contacts_cb (TpConnection *self,
+                                 guint n_contacts,
+                                 TpContact * const *contacts,
+                                 guint n_failed,
+                                 const TpHandle *failed,
+                                 const GError *error,
+                                 gpointer user_data,
+                                 GObject *weak_object)
+{
+  int i;
+  GList *contact_list = NULL;
+  for (i = 0; i < n_contacts; i++) {
+      contact_list = g_list_append(contact_list, contacts[i]);
+  }
+
+  TpHandle *failed_list = g_new0 (TpHandle, n_failed + 1);
+  memcpy(failed_list, failed, n_failed);
+
+  ((ShellGetTpContactCb)user_data)(self, contact_list, failed_list);
+}
+
+
+/**
+ * shell_get_tp_contacts:
+ * @self: A connection, which must be ready
+ * @n_handles: Number of handles in handles
+ * @handles: (array length=n_handles) (element-type uint): Array of handles
+ * @n_features: Number of features in features
+ * @features: (array length=n_features) (allow-none) (element-type uint):
+ *  Array of features
+ * @callback: (scope async): User callback to run when the contacts are ready
+ *
+ * Wrap tp_connection_get_contacts_by_handle so we can transform the array
+ * into a null-terminated one, which gjs can handle.
+ * We send the original callback to tp_connection_get_contacts_by_handle as
+ * user_data, and we have our own function as callback, which does the
+ * transforming.
+ */
+void
+shell_get_tp_contacts (TpConnection *self,
+                       guint n_handles,
+                       const TpHandle *handles,
+                       guint n_features,
+                       const TpContactFeature *features,
+                       ShellGetTpContactCb callback)
+{
+  tp_connection_get_contacts_by_handle(self, n_handles, handles,
+                                       n_features, features,
+                                       shell_global_get_tp_contacts_cb,
+                                       callback, NULL, NULL);
+}
diff --git a/src/shell-global.h b/src/shell-global.h
index 1afbdc4..5d1e13d 100644
--- a/src/shell-global.h
+++ b/src/shell-global.h
@@ -8,6 +8,8 @@
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <gtk/gtk.h>
 
+#include <telepathy-glib/telepathy-glib.h>
+
 G_BEGIN_DECLS
 
 typedef struct _ShellGlobal      ShellGlobal;
@@ -142,6 +144,17 @@ void shell_global_play_theme_sound (ShellGlobal       *global,
 
 void shell_global_init_xdnd (ShellGlobal *global);
 
+typedef void (*ShellGetTpContactCb) (TpConnection *connection,
+                                     GList *contacts,
+                                     TpHandle *failed);
+
+void shell_get_tp_contacts (TpConnection *self,
+                            guint n_handles,
+                            const TpHandle *handles,
+                            guint n_features,
+                            const TpContactFeature *features,
+                            ShellGetTpContactCb callback);
+
 G_END_DECLS
 
 #endif /* __SHELL_GLOBAL_H__ */



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