soylent r286 - trunk/libsoylent
- From: svenp svn gnome org
- To: svn-commits-list gnome org
- Subject: soylent r286 - trunk/libsoylent
- Date: Mon, 18 Aug 2008 10:14:47 +0000 (UTC)
Author: svenp
Date: Mon Aug 18 10:14:47 2008
New Revision: 286
URL: http://svn.gnome.org/viewvc/soylent?rev=286&view=rev
Log:
implemented methods for launching a chat (sync and async)
Modified:
trunk/libsoylent/sl-person.c
trunk/libsoylent/sl-person.h
Modified: trunk/libsoylent/sl-person.c
==============================================================================
--- trunk/libsoylent/sl-person.c (original)
+++ trunk/libsoylent/sl-person.c Mon Aug 18 10:14:47 2008
@@ -23,10 +23,16 @@
#include "sl-mutual-inclusion.h"
+#include <libempathy/empathy-utils.h>
+
/* private structs and fields */
struct _SlPersonPriv
{
+ gpointer cb_user_data;
+ GCallback cb;
+ GMainLoop *sync_loop;
+ GError *sync_error;
};
static GObjectClass *parent_class = NULL;
@@ -39,6 +45,8 @@
static void sl_person_set_property (GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec);
+static void mc_chat_ready (MissionControl *mc, GError *error, SlPerson *self);
+
GType
sl_person_get_type (void)
{
@@ -153,6 +161,8 @@
sl_person_constr (SlPerson *self, const gchar *name, const gchar *family_name)
{
sl_entity_constr (SL_ENTITY (self));
+ self->priv->sync_loop = NULL;
+ self->priv->sync_error = NULL;
SlName *n = sl_name_new ();
n->names = g_list_append (NULL, (gchar *) name);
n->family_name = (gchar *) family_name;
@@ -163,6 +173,8 @@
sl_person_constr_with_econtact (SlPerson *self, EContact *econtact)
{
sl_entity_constr_with_econtact (SL_ENTITY (self), econtact);
+ self->priv->sync_loop = NULL;
+ self->priv->sync_error = NULL;
}
gchar *
@@ -228,3 +240,154 @@
{
sl_person_set (self, SL_ATTR_NICK, nick);
}
+
+gchar *
+sl_person_get_string (SlPerson *self)
+{
+ gchar *nick = sl_person_get_nick (self);
+ if (g_str_equal (nick, ""))
+ {
+ return "?";
+ }
+ return nick;
+}
+
+static void
+sl_async_init (GCallback *cbp, gpointer *cb_user_datap, GCallback cb, gpointer cb_user_data)
+{
+ g_return_if_fail (cbp != NULL);
+ g_return_if_fail (cb_user_datap != NULL);
+
+ *cbp = cb;
+ *cb_user_datap = cb_user_data;
+}
+
+static void
+sl_sync_ready (GMainLoop **loopp, GError **errorp, GError *error)
+{
+ g_return_if_fail (loopp != NULL);
+ g_return_if_fail (errorp != NULL);
+
+ *errorp = error;
+ g_main_loop_quit (*loopp);
+}
+
+static gboolean
+sl_synchronize (GMainLoop **loopp, GError **errorp, GError **error)
+{
+ g_return_val_if_fail (loopp != NULL, FALSE);
+ g_return_val_if_fail (errorp != NULL, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ *loopp = g_main_loop_new (NULL, FALSE);
+ g_main_loop_run (*loopp);
+ *loopp = NULL;
+ if (*errorp == NULL)
+ {
+ return TRUE;
+ }
+ else
+ {
+ g_propagate_error (error, *errorp);
+ *errorp = NULL;
+ return FALSE;
+ }
+}
+
+static void
+communicate_chat_sync_cb (SlPerson *person, GError *error, gpointer user_data)
+{
+ g_return_if_fail (person != NULL && SL_IS_PERSON (person));
+
+ sl_sync_ready (&person->priv->sync_loop, &person->priv->sync_error, error);
+}
+
+gboolean
+sl_person_communicate_chat (SlPerson *self, GError **error)
+{
+ g_return_val_if_fail (self != NULL && SL_IS_PERSON (self), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ sl_person_communicate_chat_async (self, communicate_chat_sync_cb, NULL);
+ return sl_synchronize (&self->priv->sync_loop, &self->priv->sync_error, error);
+}
+
+void
+sl_person_communicate_chat_async (SlPerson *self, SlPersonCommunicateChatCb callback, gpointer user_data)
+{
+ g_return_if_fail (self != NULL && SL_IS_PERSON (self));
+
+ /* TODO: better algorithm for finding "default" account to use for chat */
+ sl_async_init (&self->priv->cb, &self->priv->cb_user_data, G_CALLBACK (callback), user_data);
+ EmpathyContact *imcontact = sl_entity_get_imcontacts (SL_ENTITY (self))->data;
+ sl_person_launch_chat (self, imcontact);
+}
+
+gboolean
+sl_person_communicate_chat_to (SlPerson *self, const gchar *to_id, GError **error)
+{
+ g_return_val_if_fail (self != NULL && SL_IS_PERSON (self), FALSE);
+ g_return_val_if_fail (to_id != NULL, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ sl_person_communicate_chat_to_async (self, to_id, communicate_chat_sync_cb, NULL);
+ return sl_synchronize (&self->priv->sync_loop, &self->priv->sync_error, error);
+}
+
+void
+sl_person_communicate_chat_to_async (SlPerson *self, const gchar *to_id, SlPersonCommunicateChatCb callback, gpointer user_data)
+{
+ g_return_if_fail (self != NULL && SL_IS_PERSON (self));
+ g_return_if_fail (to_id != NULL);
+
+ sl_async_init (&self->priv->cb, &self->priv->cb_user_data, G_CALLBACK (callback), user_data);
+ EmpathyContact *imcontact = sl_entity_get_imcontact_from_id (SL_ENTITY (self), to_id);
+ sl_person_launch_chat (self, imcontact);
+}
+
+gboolean
+sl_person_communicate_chat_from (SlPerson *self, const gchar *from_id, GError **error)
+{
+ g_return_val_if_fail (self != NULL && SL_IS_PERSON (self), FALSE);
+ g_return_val_if_fail (from_id != NULL, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ sl_person_communicate_chat_from_async (self, from_id, communicate_chat_sync_cb, NULL);
+ return sl_synchronize (&self->priv->sync_loop, &self->priv->sync_error, error);
+}
+
+void
+sl_person_communicate_chat_from_async (SlPerson *self, const gchar *from_id, SlPersonCommunicateChatCb callback, gpointer user_data)
+{
+ g_return_if_fail (self != NULL && SL_IS_PERSON (self));
+ g_return_if_fail (from_id != NULL);
+
+ sl_async_init (&self->priv->cb, &self->priv->cb_user_data, G_CALLBACK (callback), user_data);
+ EmpathyContact *imcontact = sl_entity_get_imcontact_from_account_id (SL_ENTITY (self), from_id);
+ sl_person_launch_chat (self, imcontact);
+}
+
+void
+sl_person_launch_chat (SlPerson *self, EmpathyContact *imcontact)
+{
+ g_return_if_fail (self != NULL && SL_IS_PERSON (self));
+ g_return_if_fail (imcontact != NULL && EMPATHY_IS_CONTACT (imcontact));
+
+ const gchar *id = empathy_contact_get_id (imcontact);
+ McAccount *account = empathy_contact_get_account (imcontact);
+ MissionControl *mc = empathy_mission_control_new ();
+ mission_control_request_channel_with_string_handle (mc, account,
+ TP_IFACE_CHANNEL_TYPE_TEXT, id, TP_HANDLE_TYPE_CONTACT, (McCallback) mc_chat_ready,
+ self);
+
+}
+
+static void
+mc_chat_ready (MissionControl *mc, GError *error, SlPerson *self)
+{
+ if (self->priv->cb != NULL)
+ {
+ SlPersonCommunicateChatCb cb = SL_PERSON_COMMUNICATION_CHAT_CB (self->priv->cb);
+ cb (self, error, self->priv->cb_user_data);
+ }
+}
Modified: trunk/libsoylent/sl-person.h
==============================================================================
--- trunk/libsoylent/sl-person.h (original)
+++ trunk/libsoylent/sl-person.h Mon Aug 18 10:14:47 2008
@@ -284,13 +284,26 @@
(sl_entity_modified (SL_ENTITY (self), attrname))
#define sl_person_modified_at(self, attrname, index) \
(sl_entity_modified_at (SL_ENTITY (self), attrname, index))
+
+#define SL_PERSON_COMMUNICATION_CHAT_CB(cb) ((SlPersonCommunicateChatCb) cb)
+
+typedef void (*SlPersonCommunicateChatCb) (SlPerson *person, GError *error,
+ gpointer user_data);
typedef struct _SlPersonClass SlPersonClass;
typedef struct _SlPersonPriv SlPersonPriv;
typedef struct _SlAddress SlAddress;
typedef struct _SlName SlName;
+
+typedef enum _SlCall SlCall;
+enum _SlCall
+{
+ SL_CALL_AUDIO = 1,
+ SL_CALL_VIDEO
+};
+
struct _SlPerson
{
SlEntity parent;
@@ -350,4 +363,14 @@
gchar *sl_person_get_nick (SlPerson *self);
void sl_person_set_nick (SlPerson *self, gchar *nick);
+gchar *sl_person_get_string (SlPerson *self);
+
+gboolean sl_person_communicate_chat (SlPerson *self, GError **error);
+gboolean sl_person_communicate_chat_to (SlPerson *self, const gchar *to_id, GError **error);
+gboolean sl_person_communicate_chat_from (SlPerson *self, const gchar *from_id, GError **error);
+void sl_person_communicate_chat_async (SlPerson *self, SlPersonCommunicateChatCb callback, gpointer user_data);
+void sl_person_communicate_chat_to_async (SlPerson *self, const gchar *to_id, SlPersonCommunicateChatCb callback, gpointer user_data);
+void sl_person_communicate_chat_from_async (SlPerson *self, const gchar *from_id, SlPersonCommunicateChatCb callback, gpointer user_data);
+void sl_person_launch_chat (SlPerson *self, EmpathyContact *imcontact);
+
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]