soylent r266 - trunk/libsoylent



Author: svenp
Date: Mon Aug  4 17:42:33 2008
New Revision: 266
URL: http://svn.gnome.org/viewvc/soylent?rev=266&view=rev

Log:
added signals to book
added simple search for people by a attribute
added more debug-information
implemented diff-algorithm for econtacts (so modified attributes can be reported via signal)
all signals are correctly emitted now
added list of eattributes to ignore
fixed: get attributes failed sometimes because the hash-table equal-function was incorrect

Modified:
   trunk/libsoylent/sl-attribute-eds.c
   trunk/libsoylent/sl-attribute-eds.h
   trunk/libsoylent/sl-book.c
   trunk/libsoylent/sl-book.h
   trunk/libsoylent/sl-entity-eds.c
   trunk/libsoylent/sl-entity-eds.h

Modified: trunk/libsoylent/sl-attribute-eds.c
==============================================================================
--- trunk/libsoylent/sl-attribute-eds.c	(original)
+++ trunk/libsoylent/sl-attribute-eds.c	Mon Aug  4 17:42:33 2008
@@ -21,6 +21,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "soylent.h"
 #include "sl-attribute-eds.h"
 #include "sl-person.h"
 #include "sl-attributes.h"
@@ -43,9 +44,6 @@
 static void sl_attribute_get_property (GObject *object, guint property_id,
   GValue *value, GParamSpec *pspec);
 
-static const gchar *sl_attribute_name_to_eattrname (const gchar *name);
-static const gchar *sl_attribute_eattrname_to_name (const gchar *eattrname);
-
 GType
 sl_attribute_get_type (void)
 {
@@ -119,7 +117,19 @@
   g_warning("%s not implemented", __FUNCTION__);
 }
 
-static const gchar *
+gboolean sl_is_ignored_eattr (const gchar *eattrname)
+{
+  static GList *ignored = NULL;
+  if (ignored == NULL)
+    {
+      ignored = g_list_append (ignored, EVC_VERSION);
+      ignored = g_list_append (ignored, EVC_REV);
+      ignored = g_list_append (ignored, EVC_LABEL);
+    }
+  return sl_priv_util_list_contains (ignored, (gpointer) eattrname, g_str_equal);
+}
+
+const gchar *
 sl_attribute_name_to_eattrname (const gchar *name)
 {
   static GHashTable *name_to_eattrname_map = NULL;
@@ -156,7 +166,7 @@
   return eattrname;
 }
 
-static const gchar *
+const gchar *
 sl_attribute_eattrname_to_name (const gchar *eattrname)
 {
   static GHashTable *eattrname_to_name_map = NULL;
@@ -227,35 +237,9 @@
   self->priv->values = NULL;
   self->priv->name = sl_attribute_eattrname_to_name (e_vcard_attribute_get_name (eattr));
 
-  GList *evalues = e_vcard_attribute_get_values (eattr);
-  gpointer evalue = NULL;
-  for (; evalues != NULL; evalues = evalues->next)
-    {
-      evalue = evalues->data;
-      gpointer value = NULL;
-      
-      /* TODO: install attribute-definition if attribute is unknown? would
-       * solve the problem that reading is done in bytes while reading is still
-       * done with strings 
-      
-      GList* encodings = e_vcard_attribute_get_param (eattr, EVC_ENCODING);
-      if (encodings != NULL)
-        {
-          g_debug ("now I'm decoding some base64 stuff!");*/
-          /* TODO: handle other encodings 
-          GByteArray *bytes = g_byte_array_new ();
-          bytes->data = g_base64_decode (evalue, &bytes->len);
-          value = sl_attribute_mapper_read (self->priv->name, bytes, SL_ATTRIBUTE_SYS_TYPE_BYTE);*/
-          /* TODO: Free bytes here. For the moment the bytes are just passed
-           * through the mapper, so they are still needed later 
-        }
-      else
-        {*/
-          value = sl_attribute_mapper_read (self->priv->name, evalue);
-        /*}*/
-      
-      self->priv->values = g_list_append (self->priv->values, value);
-    }
+  sl_debug_attribute ("creating attribute \"%s\" from eattribute", self->priv->name);
+
+  sl_attribute_set_all_from_eattr (self, eattr);
 }
 
 SlAttribute *
@@ -290,6 +274,42 @@
   return self;
 }
 
+void
+sl_attribute_set_all_from_eattr (SlAttribute *self, EVCardAttribute *eattr)
+{
+  self->priv->values = NULL;
+  
+  GList *evalues = e_vcard_attribute_get_values (eattr);
+  gpointer evalue = NULL;
+  for (; evalues != NULL; evalues = evalues->next)
+    {
+      evalue = evalues->data;
+      gpointer value = NULL;
+      
+      /* TODO: install attribute-definition if attribute is unknown? would
+       * solve the problem that reading is done in bytes while reading is still
+       * done with strings 
+      
+      GList* encodings = e_vcard_attribute_get_param (eattr, EVC_ENCODING);
+      if (encodings != NULL)
+        {
+          g_debug ("now I'm decoding some base64 stuff!");*/
+          /* TODO: handle other encodings 
+          GByteArray *bytes = g_byte_array_new ();
+          bytes->data = g_base64_decode (evalue, &bytes->len);
+          value = sl_attribute_mapper_read (self->priv->name, bytes, SL_ATTRIBUTE_SYS_TYPE_BYTE);*/
+          /* TODO: Free bytes here. For the moment the bytes are just passed
+           * through the mapper, so they are still needed later 
+        }
+      else
+        {*/
+          value = sl_attribute_mapper_read (self->priv->name, evalue);
+        /*}*/
+      
+      self->priv->values = g_list_append (self->priv->values, value);
+    }
+}
+
 SlEntity *
 sl_attribute_get_entity (SlAttribute *self)
 {
@@ -317,6 +337,7 @@
 {
   if (self->priv->values == NULL)
     {
+      sl_debug_attribute ("attribute \"%s\" has no value", sl_attribute_get_name (self));
       return NULL;
     }
   return self->priv->values->data;

Modified: trunk/libsoylent/sl-attribute-eds.h
==============================================================================
--- trunk/libsoylent/sl-attribute-eds.h	(original)
+++ trunk/libsoylent/sl-attribute-eds.h	Mon Aug  4 17:42:33 2008
@@ -60,6 +60,8 @@
 
 GType sl_attribute_get_type (void);
 
+gboolean sl_is_ignored_eattr (const gchar *eattrname);
+
 void sl_attribute_constr (SlAttribute *self, const gchar *name, gpointer value);
 void sl_attribute_constr_with_values (SlAttribute *self, const gchar *name,
                                       GList *values);
@@ -68,11 +70,15 @@
 SlAttribute *sl_attribute_new_empty (const gchar *name);
 SlAttribute *sl_attribute_new_with_values (const gchar *name, GList *values);
 SlAttribute *sl_attribute_new_with_eattr (EVCardAttribute *eattr);
+void sl_attribute_set_all_from_eattr (SlAttribute *self, EVCardAttribute *eattr);
 
 SlEntity *sl_attribute_get_entity (SlAttribute *self);
 void sl_attribute_set_entity (SlAttribute *self, SlEntity *entity);
 EVCardAttribute *sl_attribute_get_eattr (SlAttribute *self);
 
+const gchar *sl_attribute_name_to_eattrname (const gchar *name);
+const gchar *sl_attribute_eattrname_to_name (const gchar *eattrname);
+
 void sl_attribute_set (SlAttribute *self, gpointer value);
 gpointer sl_attribute_get (SlAttribute *self);
 gboolean sl_attribute_set_at (SlAttribute *self, gint index, gpointer value);

Modified: trunk/libsoylent/sl-book.c
==============================================================================
--- trunk/libsoylent/sl-book.c	(original)
+++ trunk/libsoylent/sl-book.c	Mon Aug  4 17:42:33 2008
@@ -34,9 +34,11 @@
  * functions to create, open and delete addressbooks.
  */
 
+#include "soylent.h"
 #include "sl-book.h"
 #include "sl-priv-util.h"
 #include "sl-entity.h"
+#include "sl-marshal.h"
 
 /* private structs and fields */
 
@@ -132,6 +134,15 @@
    *
    * Emitted when a person is added to the addressbook.
    */
+  
+  
+  g_signal_new ("modified", SL_BOOK_TYPE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN, G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+  g_signal_new ("person-added", SL_BOOK_TYPE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, sl_marshal_VOID__OBJECT_BOOLEAN, G_TYPE_NONE, 2, SL_PERSON_TYPE, G_TYPE_BOOLEAN);
+  g_signal_new ("person-removed", SL_BOOK_TYPE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, sl_marshal_VOID__OBJECT_BOOLEAN, G_TYPE_NONE, 2, SL_PERSON_TYPE, G_TYPE_BOOLEAN);
+  g_signal_new ("person-modified", SL_BOOK_TYPE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, sl_marshal_VOID__OBJECT_BOOLEAN, G_TYPE_NONE, 2, SL_PERSON_TYPE, G_TYPE_BOOLEAN);
+  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);
 }
 
 static void
@@ -393,6 +404,8 @@
   self->priv->eview = NULL;
   self->priv->view_wait_loop = g_main_loop_new (NULL, FALSE);
   
+  sl_debug_book ("starting to load people from book%s", "");
+  
   /* this will query all contacts */
   EBookQuery *query = e_book_query_any_field_contains ("");
   
@@ -494,35 +507,190 @@
 }
 
 SlPerson *
-sl_book_get_person(SlBook *self, gchar *attrname, gpointer value)
+sl_book_get_person (SlBook *self, const gchar *attrname, gpointer value)
 {
-  g_warning("%s not implemented", __FUNCTION__);
+  /* TODO: this works only for strings atm */
+  GList *people = self->priv->people;
+  for (; people != NULL; people = people->next)
+    {
+      SlPerson *person = people->data;
+      if (g_str_equal ((gchar *) value, (gchar *) sl_person_get (person, attrname)))
+        {
+          return person;
+        }
+    }
+  
   return NULL;
 }
 
+/*static SlPerson *
+sl_book_get_person_from_econtact (SlBook *self, EContact *econtact)
+{
+  GList *people = self->priv->people;
+  for (; people != NULL; people = people->next)
+    {
+      SlPerson *person = people->data;
+      if (sl_entity_get_econtact (SL_ENTITY (person)) == econtact)
+        {
+          return person;
+        }
+    }
+  
+  return NULL;
+}*/
+
+void
+sl_book_emit_person_added (SlBook *self, SlPerson *person, gboolean on_purpose)
+{
+  g_signal_emit_by_name (self, "person-added", person, on_purpose);
+  g_signal_emit_by_name (self, "modified", on_purpose);
+}
+
+void
+sl_book_emit_person_removed (SlBook *self, SlPerson *person, gboolean on_purpose)
+{
+  g_signal_emit_by_name (self, "person-removed", person, on_purpose);
+  g_signal_emit_by_name (self, "modified", on_purpose);
+}
+
+void
+sl_book_emit_person_attribute_added (SlBook *self, SlPerson *person, SlAttribute *attr, gboolean on_purpose)
+{
+  g_signal_emit_by_name (self, "person-attribute-added", person, attr, on_purpose);
+  g_signal_emit_by_name (self, "person-modified", person, on_purpose);
+  g_signal_emit_by_name (self, "modified", on_purpose);
+}
+
+void
+sl_book_emit_person_attribute_removed (SlBook *self, SlPerson *person, SlAttribute *attr, gboolean on_purpose)
+{
+  g_signal_emit_by_name (self, "person-attribute-removed", person, attr, on_purpose);
+  g_signal_emit_by_name (self, "person-modified", person, on_purpose);
+  g_signal_emit_by_name (self, "modified", on_purpose);
+}
+
+void
+sl_book_emit_person_attribute_modified (SlBook *self, SlPerson *person, SlAttribute *attr, GList *old_values, gboolean on_purpose)
+{
+  g_signal_emit_by_name (self, "person-attribute-modified", person, attr, old_values, on_purpose);
+  g_signal_emit_by_name (self, "person-modified", person, on_purpose);
+  g_signal_emit_by_name (self, "modified", on_purpose);
+}
+
 static void
 eview_contacts_added (EBookView *eview, GList *econtacts, SlBook *self)
 {
   /* TODO: consider to forget econtact here again */
+  if (self->priv->view_wait_loop != NULL)
+    {
+      sl_debug_book ("loading %d person / people", g_list_length (econtacts));
+    }
+  
   for (; econtacts != NULL; econtacts = econtacts->next)
     {
       EContact *econtact = econtacts->data;
       SlPerson *person = sl_person_new_with_econtact (econtact);
       self->priv->people = g_list_append (self->priv->people, person);
+      
+      if (self->priv->view_wait_loop == NULL)
+        {
+          sl_book_emit_person_added (self, person, FALSE);
+        }
     }
-  /* TODO: generate signal if view_wait_loop == NULL */
 }
 
 static void
 eview_contacts_changed (EBookView *eview, GList *econtacts, SlBook *self)
 {
-  g_warning("%s not implemented", __FUNCTION__);
+  sl_debug_book ("examining %d econtact(s) for modifications", g_list_length (econtacts));
+  for (; econtacts != NULL; econtacts = econtacts->next)
+    {
+      EContact *econtact = econtacts->data;
+      SlPerson *person = sl_book_get_person (self, SL_ATTR_ID, e_contact_get (econtact, E_CONTACT_UID));
+      g_assert (person != NULL);
+      SlEntity *entity = SL_ENTITY (person);
+      EContact *econtact_old = sl_entity_get_econtact (entity);
+
+      sl_entity_set_econtact (entity, econtact);
+      
+      GList *eattributes = e_vcard_get_attributes (E_VCARD (econtact));
+      GList *eattributes_old = g_list_copy (e_vcard_get_attributes (E_VCARD (econtact_old)));
+      
+      sl_priv_util_eattribute_list_print (eattributes, "eattributes");
+      
+      sl_debug_book ("examining %d eattribute(s)", g_list_length (eattributes));
+      for (; eattributes != NULL; eattributes = eattributes->next)
+        {
+          
+          
+          EVCardAttribute *eattr = eattributes->data;
+          const gchar *eattrname = e_vcard_attribute_get_name (eattr);
+          if (sl_is_ignored_eattr (eattrname))
+            {
+              sl_debug_book ("ignoring eattribute \"%s\"", eattrname);
+              continue;
+            }
+
+          EVCardAttribute *eattr_old = e_vcard_get_attribute (E_VCARD (econtact_old), eattrname);
+          
+          if (eattr_old == NULL)
+            {
+              sl_debug_book ("found new eattribute \"%s\"", eattrname);
+              SlAttribute *attr = sl_attribute_new_with_eattr (eattr);
+              sl_person_add_attribute (person, attr);
+              sl_book_emit_person_attribute_added (self, person, attr, FALSE);
+              g_object_unref (attr);
+            }
+          else
+            {
+              GList *evalues = e_vcard_attribute_get_values (eattr);
+              GList *evalues_old = e_vcard_attribute_get_values (eattr_old);
+              if (!sl_priv_util_lists_equal (evalues, evalues_old, g_str_equal))
+                {
+                  sl_debug_book ("found modified eattribute \"%s\"", eattrname);
+                  SlAttribute *attr = sl_entity_get_attribute_from_eattr (entity, eattr_old);
+                  g_assert (attr != NULL);
+                  GList *old_values = sl_attribute_get_all (attr);
+                  sl_attribute_set_all_from_eattr (attr, eattr);
+                  sl_book_emit_person_attribute_modified (self, person, attr, old_values, FALSE);
+                }
+              eattributes_old = g_list_remove (eattributes_old, eattr_old);
+            }
+        }
+      
+      for (; eattributes_old != NULL; eattributes_old = eattributes_old->next)
+        {
+          EVCardAttribute *eattr_old = eattributes_old->data;
+          const gchar *eattrname_old = e_vcard_attribute_get_name (eattr_old);
+          if (sl_is_ignored_eattr (eattrname_old))
+            {
+              sl_debug_book ("ignoring eattribute \"%s\"", eattrname_old);
+              continue;
+            }
+          sl_debug_book ("eattribute \"%s\" doesn't exist anymore", e_vcard_attribute_get_name (eattr_old));
+          SlAttribute *attr = sl_entity_get_attribute_from_eattr (entity, eattr_old);
+          g_assert (attr != NULL);
+          sl_book_emit_person_attribute_removed (self, person, attr, FALSE);
+        }
+      
+      g_object_unref (econtact_old);
+    }
 }
 
 static void
-eview_contacts_removed (EBookView *eview, GList *econtact_ids, SlBook *self)
+eview_contacts_removed (EBookView *eview, GList *ids, SlBook *self)
 {
-  g_warning("%s not implemented", __FUNCTION__);
+  for (; ids != NULL; ids = ids->next)
+    {
+      SlPerson *person = sl_book_get_person (self, SL_ATTR_ID, ids->data);
+      g_assert (person != NULL);
+      
+      self->priv->people = g_list_remove (self->priv->people, person);
+      
+      sl_book_emit_person_removed (self, person, FALSE);
+      
+      g_object_unref (person);
+    }
 }
 
 static void
@@ -530,11 +698,12 @@
   if (status != E_BOOK_VIEW_STATUS_OK)
     {
       g_critical ("eview status is: %d", status);
-      return;
     }
   
   if (self->priv->view_wait_loop != NULL)
     {
+      sl_debug_book ("loading people from book done%s", "");
+
       g_main_loop_quit (self->priv->view_wait_loop);
       g_main_loop_unref (self->priv->view_wait_loop);
       self->priv->view_wait_loop = NULL;

Modified: trunk/libsoylent/sl-book.h
==============================================================================
--- trunk/libsoylent/sl-book.h	(original)
+++ trunk/libsoylent/sl-book.h	Mon Aug  4 17:42:33 2008
@@ -32,7 +32,6 @@
 
 #include <glib.h>
 #include <glib-object.h>
-//#include <libebook/e-book.h>
 
 #define SL_BOOK_TYPE            (sl_book_get_type ())
 #define SL_BOOK(obj)            (G_TYPE_CHECK_INSTANCE_CAST (obj, \
@@ -54,6 +53,23 @@
 typedef enum _SlBookProperty  SlBookProperty;
 typedef enum _SlBookError     SlBookError;
 
+/* TODO: how does evolution do this? implement book_manager */
+typedef void (*SlBookCBBookCreated)   (SlBook *book_manager, gchar *book_name, gpointer user_data);
+typedef void (*SlBookCBBookDeleted)   (SlBook *book_manager, gchar *book_name, gpointer user_data);
+
+typedef void (*SlBookCBModified)                (SlBook *book, gboolean on_purpose, gpointer user_data); /* means entity -added, -removed, -modified */
+typedef void (*SlBookCBPersonAdded)             (SlBook *book, SlPerson *person, gboolean on_purpose, gpointer user_data);
+typedef void (*SlBookCBPersonRemoved)           (SlBook *book, SlPerson *person, gboolean on_purpose, gpointer user_data);
+typedef void (*SlBookCBPersonModified)          (SlBook *book, SlPerson *person, gboolean on_purpose, gpointer user_data);
+typedef void (*SlBookCBPersonAttributeAdded)    (SlBook *book, SlPerson *person, SlAttribute *attr, gboolean on_purpose, gpointer user_data);
+typedef void (*SlBookCBPersonAttributeRemoved)  (SlBook *book, SlPerson *person, SlAttribute *attr, gboolean on_purpose, gpointer user_data);
+typedef void (*SlBookCBPersonAttributeModified) (SlBook *book, SlPerson *person, SlAttribute *attr, GList *old_values, gboolean on_purpose, gpointer user_data);
+
+typedef void (*SlEntityCBModified)          (SlEntity *entity, gboolean on_purpose, gpointer user_data);
+typedef void (*SlEntityCBAttributeAdded)    (SlEntity *entity, SlAttribute *attr, gboolean on_purpose, gpointer user_data);
+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);
+
 enum SlBookProperty
 {
   SL_BOOK_PROPERTY_EBOOK = 1
@@ -98,6 +114,12 @@
 gboolean sl_book_remove_person (SlBook *self, SlPerson *person, GError **error);
 /* TODO: more to come, like searching for attributes */
 GList *sl_book_get_people (SlBook *self);
-SlPerson *sl_book_get_person(SlBook *self, gchar *attrname, gpointer value);
+SlPerson *sl_book_get_person (SlBook *self, const gchar *attrname, gpointer value);
+
+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);
+void sl_book_emit_person_attribute_removed (SlBook *self, SlPerson *person, SlAttribute *attr, gboolean on_purpose);
+void sl_book_emit_person_attribute_modified (SlBook *self, SlPerson *person, SlAttribute *attr, GList *old_values, gboolean on_purpose);
 
 #endif

Modified: trunk/libsoylent/sl-entity-eds.c
==============================================================================
--- trunk/libsoylent/sl-entity-eds.c	(original)
+++ trunk/libsoylent/sl-entity-eds.c	Mon Aug  4 17:42:33 2008
@@ -24,6 +24,7 @@
 /* TODO: will be splitted to SlEntity (interface), SlEntityBase (abstract-
  * base class), SlEntityEDS. for now this will be misused as SlEntityEDS */
 
+#include "soylent.h"
 #include "sl-entity-eds.h"
 #include "sl-person.h"
 
@@ -141,7 +142,7 @@
 {
   self->priv->ebook = NULL;
   self->priv->econtact = e_contact_new ();
-  self->priv->attribute_table = g_hash_table_new (NULL, NULL);
+  self->priv->attribute_table = g_hash_table_new (g_str_hash, g_str_equal);
   self->priv->attributes = NULL;
 }
 
@@ -149,7 +150,7 @@
 sl_entity_constr_with_econtact (SlEntity *self, EContact *econtact)
 {
   self->priv->ebook = NULL;
-  self->priv->attribute_table = g_hash_table_new (NULL, NULL);
+  self->priv->attribute_table = g_hash_table_new (g_str_hash, g_str_equal);
   self->priv->attributes = NULL;
   self->priv->econtact = g_object_ref (econtact);
   
@@ -160,15 +161,17 @@
     {
       eattr = eattributes->data;
       const gchar *eattrname = e_vcard_attribute_get_name (eattr);
-      if (g_str_equal (eattrname, EVC_VERSION) ||
-          g_str_equal (eattrname, EVC_REV))
+      if (sl_is_ignored_eattr (eattrname))
         {
+          sl_debug_entity ("ignored eattribute \"%s\"", eattrname);
           continue;
         }
       attr = sl_attribute_new_with_eattr (eattr);
+      g_assert (attr != NULL);
       /* TODO: make one function for the next two calls */
       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);
       g_object_unref (attr);
     }
 }
@@ -191,6 +194,12 @@
   return self->priv->econtact;
 }
 
+void
+sl_entity_set_econtact (SlEntity *self, EContact *econtact)
+{
+  self->priv->econtact = g_object_ref (econtact);
+}
+
 gboolean
 sl_entity_commit (SlEntity *self, GError **error)
 {
@@ -238,9 +247,27 @@
   return self->priv->entity_handler;
 }*/
 
-SlAttribute *sl_entity_get_attribute (SlEntity *self, gchar *attrname)
+gboolean sl_entity_has_attribute (SlEntity *self, const gchar *attrname)
+{
+  return (sl_entity_get_attribute (self, attrname) != NULL);
+}
+
+SlAttribute *sl_entity_get_attribute (SlEntity *self, const gchar *attrname)
+{
+  SlAttribute *attr = g_hash_table_lookup (self->priv->attribute_table, attrname);
+  if (attr == NULL) 
+    {
+      sl_debug_entity ("entity has no attribute \"%s\"", attrname);
+    }
+  return attr;
+}
+
+SlAttribute *
+sl_entity_get_attribute_from_eattr (SlEntity *self, EVCardAttribute *eattr)
 {
-  return g_hash_table_lookup (self->priv->attribute_table, attrname);
+  const gchar *eattrname = e_vcard_attribute_get_name (eattr);
+  const gchar *attrname = sl_attribute_eattrname_to_name (eattrname);
+  return sl_entity_get_attribute (self, attrname);
 }
 
 GList *sl_entity_get_attributes (SlEntity *self)
@@ -249,7 +276,7 @@
 }
 
 void
-sl_entity_set (SlEntity *self, gchar *attrname, gpointer value)
+sl_entity_set (SlEntity *self, const gchar *attrname, gpointer value)
 {
   SlAttribute *attr = sl_entity_get_attribute (self, attrname);
   if (attr == NULL) 
@@ -261,7 +288,7 @@
 }
 
 gpointer
-sl_entity_get (SlEntity *self, gchar *attrname)
+sl_entity_get (SlEntity *self, const gchar *attrname)
 {
   SlAttribute *attr = sl_entity_get_attribute (self, attrname);
   if (attr == NULL) 
@@ -272,45 +299,45 @@
 }
 
 void
-sl_entity_remove (SlEntity *self, gchar *attrname)
+sl_entity_remove (SlEntity *self, const gchar *attrname)
 {
   g_warning("%s not implemented", __FUNCTION__);
 }
 
 void
-sl_entity_set_at (SlEntity *self, gchar *attrname, gint index, gpointer value)
+sl_entity_set_at (SlEntity *self, const gchar *attrname, gint index, gpointer value)
 {
   g_warning("%s not implemented", __FUNCTION__);
 }
 
 gpointer
-sl_entity_get_at (SlEntity *self, gchar *attrname, gint index)
+sl_entity_get_at (SlEntity *self, const gchar *attrname, gint index)
 {
   g_warning("%s not implemented", __FUNCTION__);
   return NULL;
 }
 
 void
-sl_entity_remove_at (SlEntity *self, gchar *attrname, gint index)
+sl_entity_remove_at (SlEntity *self, const gchar *attrname, gint index)
 {
   g_warning("%s not implemented", __FUNCTION__);
 }
 
 void
-sl_entity_set_values (SlEntity *self, gchar *attrname, GList *values)
+sl_entity_set_values (SlEntity *self, const gchar *attrname, GList *values)
 {
   g_warning("%s not implemented", __FUNCTION__);
 }
 
 GList *
-sl_entity_get_values (SlEntity *self, gchar *attrname)
+sl_entity_get_values (SlEntity *self, const gchar *attrname)
 {
   g_warning("%s not implemented", __FUNCTION__);
   return NULL;
 }
 
 void
-sl_entity_remove_values (SlEntity *self, gchar *attrname)
+sl_entity_remove_values (SlEntity *self, const gchar *attrname)
 {
   g_warning("%s not implemented", __FUNCTION__);
 }

Modified: trunk/libsoylent/sl-entity-eds.h
==============================================================================
--- trunk/libsoylent/sl-entity-eds.h	(original)
+++ trunk/libsoylent/sl-entity-eds.h	Mon Aug  4 17:42:33 2008
@@ -77,24 +77,27 @@
 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);
 
 gboolean sl_entity_commit (SlEntity *self, GError **error);
 
 void sl_entity_add_attribute (SlEntity *self, SlAttribute *attr);
 void sl_entity_remove_attribute (SlEntity *self, SlAttribute *attr);
-SlAttribute *sl_entity_get_attribute (SlEntity *self, gchar *attrname);
+gboolean sl_entity_has_attribute (SlEntity *self, const gchar *attrname);
+SlAttribute *sl_entity_get_attribute (SlEntity *self, const gchar *attrname);
+SlAttribute *sl_entity_get_attribute_from_eattr (SlEntity *self, EVCardAttribute *eattr);
 GList *sl_entity_get_attributes (SlEntity *self);
 
-void sl_entity_set (SlEntity *self, gchar *attrname, gpointer value);
-gpointer sl_entity_get (SlEntity *self, gchar *attrname);
-void sl_entity_remove (SlEntity *self, gchar *attrname);
-void sl_entity_set_at (SlEntity *self, gchar *attrname, gint index,
+void sl_entity_set (SlEntity *self, const gchar *attrname, gpointer value);
+gpointer sl_entity_get (SlEntity *self, const gchar *attrname);
+void sl_entity_remove (SlEntity *self, const gchar *attrname);
+void sl_entity_set_at (SlEntity *self, const gchar *attrname, gint index,
   gpointer value);
-gpointer sl_entity_get_at (SlEntity *self, gchar *attrname, gint index);
-void sl_entity_remove_at (SlEntity *self, gchar *attrname, gint index);
-void sl_entity_set_values (SlEntity *self, gchar *attrname, GList *values);
-GList *sl_entity_get_values (SlEntity *self, gchar *attrname);
-void sl_entity_remove_values (SlEntity *self, gchar *attrname);
+gpointer sl_entity_get_at (SlEntity *self, const gchar *attrname, gint index);
+void sl_entity_remove_at (SlEntity *self, const gchar *attrname, gint index);
+void sl_entity_set_values (SlEntity *self, const gchar *attrname, GList *values);
+GList *sl_entity_get_values (SlEntity *self, const gchar *attrname);
+void sl_entity_remove_values (SlEntity *self, const gchar *attrname);
 /* TODO: perhaps gboolean instead of void to indicate that an attrname doesn't
  * exist */
 



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