soylent r285 - in trunk: . libsoylent
- From: svenp svn gnome org
- To: svn-commits-list gnome org
- Subject: soylent r285 - in trunk: . libsoylent
- Date: Mon, 18 Aug 2008 10:13:32 +0000 (UTC)
Author: svenp
Date: Mon Aug 18 10:13:32 2008
New Revision: 285
URL: http://svn.gnome.org/viewvc/soylent?rev=285&view=rev
Log:
fixed: link to parent-storage for entities is now set
associating people with IM-contacts implemented
added function to get online-people
implemented mixing of presences (when one person has more associated IM-contacts)
added utility-methods for IM-information for entities
Modified:
trunk/configure.ac
trunk/libsoylent/sl-attribute-eds.c
trunk/libsoylent/sl-book.c
trunk/libsoylent/sl-book.h
trunk/libsoylent/sl-entity-eds.c
trunk/libsoylent/sl-entity-eds.h
Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Mon Aug 18 10:13:32 2008
@@ -111,18 +111,24 @@
glib-2.0
gobject-2.0
libebook-1.2
+ libmissioncontrol
+ libempathy
])
PKG_CHECK_MODULES(TEST,
[
glib-2.0
+ gobject-2.0
libebook-1.2
+ libempathy
])
PKG_CHECK_MODULES(EXAMPLE,
[
glib-2.0
+ gobject-2.0
libebook-1.2
+ libempathy
])
AC_DEFINE(ENABLE_LIBSOYLENT, 1, [Build libsoylent])
Modified: trunk/libsoylent/sl-attribute-eds.c
==============================================================================
--- trunk/libsoylent/sl-attribute-eds.c (original)
+++ trunk/libsoylent/sl-attribute-eds.c Mon Aug 18 10:13:32 2008
@@ -24,6 +24,7 @@
#include "sl-mutual-inclusion.h"
#include "sl-priv-util.h"
#include "sl-attributes.h"
+#include "soylent.h"
struct _SlAttributePriv
{
@@ -420,6 +421,16 @@
self->priv->values = g_list_append (self->priv->values, value);
self->priv->eattributes = g_list_append (self->priv->eattributes, eattr);
+ /* im stuff */
+ if (self->priv->entity != NULL)
+ {
+ if (sl_im_is_im_attribute (self->priv->name))
+ {
+ sl_entity_associate_imcontacts (self->priv->entity);
+ }
+ }
+ /* /im stuff */
+
if (emit)
{
sl_attribute_emit_modified (self);
@@ -470,6 +481,16 @@
return FALSE;
}
+ /* im stuff */
+ if (self->priv->entity != NULL)
+ {
+ if (sl_im_is_im_attribute (self->priv->name))
+ {
+ sl_entity_associate_imcontacts (self->priv->entity);
+ }
+ }
+ /* /im stuff */
+
sl_attribute_cleanup (self->priv->name, value_nth->data);
value_nth->data = value;
@@ -494,6 +515,16 @@
g_assert (eattr_nth != NULL);
EVCardAttribute *eattr = eattr_nth->data;
+ /* im stuff */
+ if (self->priv->entity != NULL)
+ {
+ if (sl_im_is_im_attribute (self->priv->name))
+ {
+ sl_entity_associate_imcontacts (self->priv->entity);
+ }
+ }
+ /* /im stuff */
+
self->priv->values = g_list_remove (self->priv->values, value);
sl_attribute_cleanup (self->priv->name, value);
Modified: trunk/libsoylent/sl-book.c
==============================================================================
--- trunk/libsoylent/sl-book.c (original)
+++ trunk/libsoylent/sl-book.c Mon Aug 18 10:13:32 2008
@@ -37,6 +37,11 @@
#include "sl-mutual-inclusion.h"
#include "sl-priv-util.h"
#include "sl-marshal.h"
+#include "soylent.h"
+
+#include <libempathy/empathy-contact-manager.h>
+#include <libempathy/empathy-utils.h>
+#include <dbus/dbus-glib.h>
/* private structs and fields */
@@ -70,6 +75,11 @@
static void eview_sequence_complete (EBookView *eview, EBookViewStatus status,
SlBook *self);
+static void empathy_contact_list_members_changed (
+ EmpathyContactList *contactlist, EmpathyContact *contact,
+ EmpathyContact *actor, guint reason, gchar *message, gboolean is_member,
+ SlBook *self);
+
GType
sl_book_get_type (void)
{
@@ -141,6 +151,7 @@
g_signal_new ("person-attribute-added", SL_BOOK_TYPE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, sl_marshal_VOID__OBJECT_OBJECT_BOOLEAN, G_TYPE_NONE, 3, SL_PERSON_TYPE, SL_ATTRIBUTE_TYPE, G_TYPE_BOOLEAN);
g_signal_new ("person-attribute-removed", SL_BOOK_TYPE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, sl_marshal_VOID__OBJECT_OBJECT_BOOLEAN, G_TYPE_NONE, 3, SL_PERSON_TYPE, SL_ATTRIBUTE_TYPE, G_TYPE_BOOLEAN);
g_signal_new ("person-attribute-modified", SL_BOOK_TYPE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, sl_marshal_VOID__OBJECT_OBJECT_POINTER_BOOLEAN, G_TYPE_NONE, 4, SL_PERSON_TYPE, SL_ATTRIBUTE_TYPE, G_TYPE_POINTER, G_TYPE_BOOLEAN);
+ g_signal_new ("person-presence-changed", SL_BOOK_TYPE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, SL_PERSON_TYPE);
}
static void
@@ -192,7 +203,7 @@
gboolean
sl_book_setup (GError **error)
-{
+{
sl_book_default = sl_book_open_default (error);
if (sl_book_default == NULL)
{
@@ -435,6 +446,18 @@
e_book_view_start (self->priv->eview);
g_main_loop_run (self->priv->view_wait_loop);
+ sl_debug_book ("associating loaded people with loaded IM-contacts%s", "");
+
+ GList *people_iter = self->priv->people;
+ for (; people_iter != NULL; people_iter = people_iter->next)
+ {
+ SlPerson *person = people_iter->data;
+ sl_entity_associate_imcontacts (SL_ENTITY (person));
+ }
+
+ EmpathyContactManager *contactmgr = sl_im_get_contact_manager ();
+ g_signal_connect (contactmgr, "members-changed", G_CALLBACK (empathy_contact_list_members_changed), self);
+
return TRUE;
}
@@ -481,7 +504,7 @@
return FALSE;
}
- sl_entity_set_ebook (entity, self->priv->ebook);
+ sl_entity_set_storage (entity, self);
self->priv->people = g_list_append (self->priv->people, person);
@@ -503,6 +526,13 @@
return TRUE;
}
+gboolean
+sl_book_commit_person (SlBook *self, SlPerson *person, GError **error)
+{
+ EContact *econtact = sl_entity_get_econtact (SL_ENTITY (person));
+ return e_book_commit_contact (self->priv->ebook, econtact, error);
+}
+
GList *
sl_book_get_people (SlBook *self)
{
@@ -510,6 +540,31 @@
return self->priv->people;
}
+/**
+ * sl_book_get_online_people:
+ * @self: a #SlBook
+ *
+ * Gets a list of all people from addressbook @self that are online.
+ *
+ * Returns: a #SlPerson list of online people. The list should be freed with
+ * g_list_free().
+ */
+GList *
+sl_book_get_online_people (SlBook *self)
+{
+ GList *online_people = NULL;
+ GList *people = self->priv->people;
+ for (; people != NULL; people = people->next)
+ {
+ SlPerson *person = people->data;
+ if (sl_entity_is_online (SL_ENTITY (person)))
+ {
+ online_people = g_list_append (online_people, person);
+ }
+ }
+ return online_people;
+}
+
SlPerson *
sl_book_get_person (SlBook *self, const gchar *attrname, gpointer value)
{
@@ -544,6 +599,12 @@
}*/
void
+sl_book_emit_person_presence_changed (SlBook *self, SlPerson *person)
+{
+ g_signal_emit_by_name (self, "person-presence-changed", person);
+}
+
+void
sl_book_emit_person_added (SlBook *self, SlPerson *person, gboolean on_purpose)
{
g_signal_emit_by_name (self, "person-added", person, on_purpose);
@@ -596,10 +657,14 @@
{
EContact *econtact = econtacts->data;
SlPerson *person = sl_person_new_with_econtact (econtact);
+ sl_entity_set_storage (SL_ENTITY (person), self);
self->priv->people = g_list_append (self->priv->people, person);
-
+
if (self->priv->view_wait_loop == NULL)
{
+ /* im stuff */
+ sl_entity_associate_imcontacts (SL_ENTITY (person));
+
sl_book_emit_person_added (self, person, FALSE);
}
}
@@ -814,3 +879,25 @@
self->priv->view_wait_loop = NULL;
}
}
+
+static void
+empathy_contact_list_members_changed (EmpathyContactList *contactlist,
+ EmpathyContact *imcontact, EmpathyContact *actor, guint reason, gchar *message,
+ gboolean is_member, SlBook *self)
+{
+ /*g_debug (sl_priv_util_imcontact_to_string (imcontact));*/
+
+ GList *people = self->priv->people;
+ for (; people != NULL; people = people->next)
+ {
+ SlPerson *person = people->data;
+ if (is_member)
+ {
+ sl_entity_associate_imcontact (SL_ENTITY (person), imcontact, TRUE);
+ }
+ else
+ {
+ sl_entity_deassociate_imcontact (SL_ENTITY (person), imcontact);
+ }
+ }
+}
Modified: trunk/libsoylent/sl-book.h
==============================================================================
--- trunk/libsoylent/sl-book.h (original)
+++ trunk/libsoylent/sl-book.h Mon Aug 18 10:13:32 2008
@@ -69,6 +69,8 @@
typedef void (*SlEntityCBAttributeRemoved) (SlEntity *entity, SlAttribute *attr, gboolean on_purpose, gpointer user_data);
typedef void (*SlEntityCBAttributeModified) (SlEntity *entity, SlAttribute *attr, gboolean on_purpose, GList *old_values, gpointer user_data);
+typedef void (*SlBookPersonPresenceChangedCb) (SlBook *book, SlPerson *person, gpointer user_data);
+
enum SlBookProperty
{
SL_BOOK_PROPERTY_EBOOK = 1
@@ -97,7 +99,6 @@
GType sl_book_get_type (void);
GQuark sl_book_error_quark (void);
-
gboolean sl_book_setup (GError **error);
gboolean sl_book_constr (SlBook *self, GError **error);
@@ -111,10 +112,13 @@
gboolean sl_book_add_person (SlBook *self, SlPerson *person, GError **error);
gboolean sl_book_remove_person (SlBook *self, SlPerson *person, GError **error);
+gboolean sl_book_commit_person (SlBook *self, SlPerson *person, GError **error);
/* TODO: more to come, like searching for attributes */
GList *sl_book_get_people (SlBook *self);
+GList *sl_book_get_online_people (SlBook *self);
SlPerson *sl_book_get_person (SlBook *self, const gchar *attrname, gpointer value);
+void sl_book_emit_person_presence_changed (SlBook *self, SlPerson *person);
void sl_book_emit_person_added (SlBook *self, SlPerson *person, gboolean on_purpose);
void sl_book_emit_person_removed (SlBook *self, SlPerson *person, gboolean on_purpose);
void sl_book_emit_person_attribute_added (SlBook *self, SlPerson *person, SlAttribute *attr, gboolean on_purpose);
Modified: trunk/libsoylent/sl-entity-eds.c
==============================================================================
--- trunk/libsoylent/sl-entity-eds.c (original)
+++ trunk/libsoylent/sl-entity-eds.c Mon Aug 18 10:13:32 2008
@@ -28,15 +28,18 @@
#include "sl-priv-util.h"
#include "soylent.h"
+#include <libempathy/empathy-contact.h>
+
/* private structs and fields */
struct _SlEntityPriv
{
SlBook *storage;
- EBook *ebook;
EContact *econtact;
+ GList *imcontacts;
GList *attributes;
GHashTable *attribute_table;
+ McPresence presence;
};
static GObjectClass *parent_class = NULL;
@@ -49,6 +52,10 @@
static void sl_entity_get_property (SlEntity *self, guint property_id,
GValue *value, GParamSpec *pspec);
+static void sl_entity_mix_presences (SlEntity *self);
+static void empathy_contact_notify_presence (EmpathyContact *imcontact,
+ GParamSpec *pspec, SlEntity *self);
+
GType
sl_entity_get_type (void)
{
@@ -142,19 +149,21 @@
sl_entity_constr (SlEntity *self)
{
self->priv->storage = NULL;
- self->priv->ebook = NULL;
self->priv->econtact = e_contact_new ();
+ self->priv->imcontacts = NULL;
self->priv->attribute_table = g_hash_table_new (g_str_hash, g_str_equal);
self->priv->attributes = NULL;
+ self->priv->presence = MC_PRESENCE_UNSET;
}
void
sl_entity_constr_with_econtact (SlEntity *self, EContact *econtact)
{
self->priv->storage = NULL;
- self->priv->ebook = NULL;
+ self->priv->imcontacts = NULL;
self->priv->attribute_table = g_hash_table_new (g_str_hash, g_str_equal);
self->priv->attributes = NULL;
+ self->priv->presence = MC_PRESENCE_UNSET;
self->priv->econtact = g_object_ref (econtact);
sl_debug_entity ("creating entity from econtact%s", "");
@@ -199,28 +208,124 @@
g_list_free (eattributes);
}
+EContact
+*sl_entity_get_econtact (SlEntity *self)
+{
+ return self->priv->econtact;
+}
+
void
-sl_entity_set_ebook (SlEntity *self, EBook *ebook)
+sl_entity_set_econtact (SlEntity *self, EContact *econtact)
{
- self->priv->ebook = ebook;
+ self->priv->econtact = g_object_ref (econtact);
}
-EBook *
-sl_entity_get_ebook (SlEntity *self)
+void
+sl_entity_associate_imcontacts (SlEntity *self)
{
- return self->priv->ebook;
+ sl_debug_entity ("associating imcontacts%s", "");
+ g_list_free (self->priv->imcontacts);
+ self->priv->imcontacts = NULL;
+ EmpathyContactManager *contactmgr = sl_im_get_contact_manager ();
+ GList *imcontacts = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (contactmgr));
+ for (; imcontacts != NULL; imcontacts = imcontacts->next)
+ {
+ sl_entity_associate_imcontact (self, imcontacts->data, FALSE);
+ }
+ sl_entity_mix_presences (self);
}
-EContact
-*sl_entity_get_econtact (SlEntity *self)
+void
+sl_entity_associate_imcontact (SlEntity *self, EmpathyContact *imcontact, gboolean mix_presences)
{
- return self->priv->econtact;
+ McAccount *account = empathy_contact_get_account (imcontact);
+ const gchar *protocol_name = sl_priv_util_get_protocol_name_from_account (account);
+ const gchar *imcontactid = empathy_contact_get_id (imcontact);
+ if (imcontactid == NULL)
+ {
+ /*g_warning ("id of imcontact \"%s\" is NULL", empathy_contact_get_name (imcontact));*/
+ return;
+ }
+
+ GList *ids = sl_entity_get_all (self, protocol_name);
+ for (; ids != NULL; ids = ids->next)
+ {
+ gchar *id = ids->data;
+ if (g_str_equal (id, imcontactid))
+ {
+ self->priv->imcontacts = g_list_append (self->priv->imcontacts, imcontact);
+ g_signal_connect (imcontact, "notify::presence", G_CALLBACK (empathy_contact_notify_presence), self);
+ if (mix_presences)
+ {
+ sl_entity_mix_presences (self);
+ }
+ }
+ }
}
void
-sl_entity_set_econtact (SlEntity *self, EContact *econtact)
+sl_entity_deassociate_imcontact (SlEntity *self, EmpathyContact *imcontact)
{
- self->priv->econtact = g_object_ref (econtact);
+ if (g_list_index (self->priv->imcontacts, imcontact) != -1)
+ {
+ sl_entity_associate_imcontacts (self);
+ }
+}
+
+gboolean sl_entity_has_iminfo (SlEntity *self)
+{
+ return (self->priv->imcontacts != NULL);
+}
+
+gboolean sl_entity_is_online (SlEntity *self)
+{
+ return (self->priv->presence != MC_PRESENCE_UNSET &&
+ self->priv->presence != MC_PRESENCE_OFFLINE &&
+ self->priv->presence != MC_PRESENCE_HIDDEN);
+}
+
+McPresence sl_entity_get_presence (SlEntity *self)
+{
+ return self->priv->presence;
+}
+
+GList *
+sl_entity_get_imcontacts (SlEntity *self)
+{
+ return self->priv->imcontacts;
+}
+
+EmpathyContact *
+sl_entity_get_imcontact_from_id (SlEntity *self, const gchar *id)
+{
+ GList *imcontacts = sl_entity_get_imcontacts (self);
+ for (; imcontacts != NULL; imcontacts = imcontacts->next)
+ {
+ EmpathyContact *imcontact = imcontacts->data;
+ const gchar *imcontact_id = empathy_contact_get_id (imcontact);
+ if (g_str_equal (id, imcontact_id))
+ {
+ return imcontact;
+ }
+ }
+ return NULL;
+}
+
+EmpathyContact *
+sl_entity_get_imcontact_from_account_id (SlEntity *self, const gchar *account_id)
+{
+ GList *imcontacts = sl_entity_get_imcontacts (self);
+ for (; imcontacts != NULL; imcontacts = imcontacts->next)
+ {
+ EmpathyContact *imcontact = imcontacts->data;
+ gchar *imcontact_account_id = sl_priv_util_get_account_id_from_imcontact (imcontact);
+ if (g_str_equal (account_id, imcontact_account_id))
+ {
+ return imcontact;
+ }
+ }
+
+ return NULL;
}
SlBook *
@@ -229,15 +334,21 @@
return self->priv->storage;
}
+void
+sl_entity_set_storage (SlEntity *self, SlBook *storage)
+{
+ self->priv->storage = storage;
+}
+
gboolean
sl_entity_commit (SlEntity *self, GError **error)
{
- if (self->priv->ebook == NULL)
+ if (self->priv->storage == NULL)
{
/* TODO: return error */
return FALSE;
}
- return e_book_commit_contact (self->priv->ebook, self->priv->econtact, error);
+ return sl_book_commit_person (self->priv->storage, SL_PERSON (self), error);
}
void
@@ -247,6 +358,13 @@
self->priv->attributes = g_list_append (self->priv->attributes, g_object_ref (attr));
g_hash_table_insert (self->priv->attribute_table, (const gpointer) sl_attribute_get_name (attr), g_object_ref (attr));
sl_attribute_set_entity (attr, self);
+
+ /* im stuff */
+ if (sl_im_is_im_attribute (sl_attribute_get_name (attr)))
+ {
+ sl_entity_associate_imcontacts (self);
+ }
+ /* /im stuff */
}
void
@@ -257,6 +375,13 @@
sl_attribute_set_entity (attr, NULL);
g_object_unref (attr);
g_object_unref (attr);
+
+ /* im stuff */
+ if (sl_im_is_im_attribute (sl_attribute_get_name (attr)))
+ {
+ sl_entity_associate_imcontacts (self);
+ }
+ /* /im stuff */
}
void
@@ -439,3 +564,79 @@
g_return_val_if_fail (attr != NULL, FALSE);
return sl_attribute_modified_at (attr, index);
}
+
+static gint
+sl_priv_util_presence_to_gint (McPresence presence)
+{
+ switch (presence)
+ {
+ case MC_PRESENCE_UNSET:
+ return 1;
+ case MC_PRESENCE_OFFLINE:
+ return 2;
+ case MC_PRESENCE_HIDDEN:
+ return 3;
+ case MC_PRESENCE_EXTENDED_AWAY:
+ return 4;
+ case MC_PRESENCE_AWAY:
+ return 5;
+ case MC_PRESENCE_DO_NOT_DISTURB:
+ return 6;
+ case MC_PRESENCE_AVAILABLE:
+ return 7;
+ default:
+ g_assert_not_reached ();
+ }
+}
+
+static void
+sl_entity_mix_presences (SlEntity *self)
+{
+ g_return_if_fail (self != NULL && SL_IS_PERSON (self));
+
+ GList *imcontacts_iter = self->priv->imcontacts;
+ EmpathyContact *imcontact = NULL;
+ McPresence old_presence = self->priv->presence;
+
+ if (imcontacts_iter == NULL)
+ {
+ self->priv->presence = MC_PRESENCE_UNSET;
+ }
+ else
+ {
+ imcontact = imcontacts_iter->data;
+ imcontacts_iter = imcontacts_iter->next;
+ self->priv->presence = empathy_contact_get_presence (imcontact);
+ }
+
+ for (; imcontacts_iter != NULL; imcontacts_iter = imcontacts_iter->next)
+ {
+ McPresence presence = MC_PRESENCE_UNSET;
+
+ imcontact = imcontacts_iter->data;
+ presence = empathy_contact_get_presence (imcontact);
+ if (sl_priv_util_presence_to_gint (presence) >
+ sl_priv_util_presence_to_gint (self->priv->presence))
+ {
+ self->priv->presence = presence;
+ }
+ }
+
+ if (old_presence != self->priv->presence)
+ {
+ sl_debug_entity ("presence %d -> %d", sl_priv_util_presence_to_gint (old_presence),
+ sl_priv_util_presence_to_gint (self->priv->presence));
+ if (self->priv->storage != NULL)
+ {
+ sl_book_emit_person_presence_changed (self->priv->storage, SL_PERSON (self));
+ }
+ }
+}
+
+static void
+empathy_contact_notify_presence (EmpathyContact *imcontact, GParamSpec *pspec,
+ SlEntity *self)
+{
+ /* TODO: on account deactivate + active again we get this 3 times, why? */
+ sl_entity_mix_presences (self);
+}
Modified: trunk/libsoylent/sl-entity-eds.h
==============================================================================
--- trunk/libsoylent/sl-entity-eds.h (original)
+++ trunk/libsoylent/sl-entity-eds.h Mon Aug 18 10:13:32 2008
@@ -32,6 +32,7 @@
#include <glib.h>
#include <glib-object.h>
#include <libebook/e-book.h>
+#include <libempathy/empathy-contact.h>
#define SL_ENTITY_TYPE (sl_entity_get_type ())
#define SL_ENTITY(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, \
@@ -73,15 +74,25 @@
/*SlEntityHandler *sl_entity_get_handler (SlEntity *self);*/
void sl_entity_constr (SlEntity *self);
void sl_entity_constr_with_econtact (SlEntity *self, EContact *econtact);
-void sl_entity_set_ebook (SlEntity *self, EBook *ebook);
-EBook *sl_entity_get_ebook (SlEntity *self);
EContact *sl_entity_get_econtact (SlEntity *self);
void sl_entity_set_econtact (SlEntity *self, EContact *econtact);
+void sl_entity_associate_imcontacts (SlEntity *self);
+void sl_entity_associate_imcontact (SlEntity *self, EmpathyContact *imcontact, gboolean mix_presences);
+void sl_entity_deassociate_imcontact (SlEntity *self, EmpathyContact *imcontact);
+
SlBook *sl_entity_get_storage (SlEntity *self);
+void sl_entity_set_storage (SlEntity *self, SlBook *storage);
gboolean sl_entity_commit (SlEntity *self, GError **error);
+gboolean sl_entity_has_iminfo (SlEntity *self);
+gboolean sl_entity_is_online (SlEntity *self);
+McPresence sl_entity_get_presence (SlEntity *self);
+GList *sl_entity_get_imcontacts (SlEntity *self);
+EmpathyContact *sl_entity_get_imcontact_from_id (SlEntity *self, const gchar *id);
+EmpathyContact *sl_entity_get_imcontact_from_account_id (SlEntity *self, const gchar *account_id);
+
void sl_entity_add_attribute_shallow (SlEntity *self, SlAttribute *attr);
void sl_entity_remove_attribute_shallow (SlEntity *self, SlAttribute *attr);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]