soylent r270 - trunk/libsoylent



Author: svenp
Date: Mon Aug 11 21:44:57 2008
New Revision: 270
URL: http://svn.gnome.org/viewvc/soylent?rev=270&view=rev

Log:
reimplemented attribute / value diff for signals (works better with eattributes now)

Modified:
   trunk/libsoylent/sl-book.c
   trunk/libsoylent/sl-book.h

Modified: trunk/libsoylent/sl-book.c
==============================================================================
--- trunk/libsoylent/sl-book.c	(original)
+++ trunk/libsoylent/sl-book.c	Mon Aug 11 21:44:57 2008
@@ -34,10 +34,8 @@
  * functions to create, open and delete addressbooks.
  */
 
-#include "soylent.h"
-#include "sl-book.h"
+#include "sl-mutual-inclusion.h"
 #include "sl-priv-util.h"
-#include "sl-entity.h"
 #include "sl-marshal.h"
 
 /* private structs and fields */
@@ -280,6 +278,8 @@
 SlBook *
 sl_book_create (const gchar *name, GError **error)
 {
+  g_error ("%s disabled because of addressbook-bug", __FUNCTION__);
+  
   g_return_val_if_fail (name != NULL, NULL);
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
   
@@ -319,6 +319,8 @@
 
 SlBook *sl_book_open (const gchar *name, GError **error)
 {
+  g_error ("%s disabled because of addressbook-bug", __FUNCTION__);
+  
   ESourceList *source_tree = NULL;
   if (!e_book_get_addressbooks (&source_tree, error))
     {
@@ -353,6 +355,8 @@
 gboolean
 sl_book_delete (const gchar *name, GError **error)
 {
+  g_error ("%s disabled because of addressbook-bug", __FUNCTION__);
+  
   /* TODO: forbid to delete default addressbook */
   
   g_return_val_if_fail (name != NULL, FALSE);
@@ -586,6 +590,8 @@
       sl_debug_book ("loading %d person / people", g_list_length (econtacts));
     }
   
+  sl_debug_book ("%d econtact(s) added", g_list_length (econtacts));
+  
   for (; econtacts != NULL; econtacts = econtacts->next)
     {
       EContact *econtact = econtacts->data;
@@ -602,9 +608,12 @@
 static void
 eview_contacts_changed (EBookView *eview, GList *econtacts, SlBook *self)
 {
+  g_assert (econtacts != NULL);
   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);
@@ -613,9 +622,101 @@
 
       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)));
+      GList *eattributes = sl_priv_util_eattribute_flat_to_deep_list (e_vcard_get_attributes (E_VCARD (econtact)));
+      GList *eattributes_old = sl_priv_util_eattribute_flat_to_deep_list (e_vcard_get_attributes (E_VCARD (econtact_old)));
+      
+      GList *added = NULL;
+      GList *removed = NULL;
+      GList *modified = NULL;
+      GList *rest = NULL;
+      sl_priv_util_list_set_diff_full (eattributes, eattributes_old,
+                                      (GEqualFunc) sl_priv_util_eattrlist_name_equal,
+                                      (GEqualFunc) sl_priv_util_eattrlist_modified,
+                                      &added, &removed, &modified, &rest);
+      
+      sl_debug_book ("processing added eattributes%s", "");
+      for (; added != NULL; added = added->next)
+        {
+          GList *eattrlist = added->data;
+          EVCardAttribute *eattr = eattrlist->data;
+          const gchar *eattrname = e_vcard_attribute_get_name (eattr);
+          if (sl_is_ignored_eattr (eattrname))
+            {
+              sl_debug_book ("ignoring eattribute \"%s\"", eattrname);
+              continue;
+            }
+          
+          sl_debug_book ("found new eattribute \"%s\"", eattrname);
+          SlAttribute *attr = sl_attribute_new_with_eattributes (eattrlist);
+          sl_entity_add_attribute_shallow (entity, attr);
+          sl_book_emit_person_attribute_added (self, person, attr, FALSE);
+          g_object_unref (attr);
+        }
+      
+      sl_debug_book ("processing removed eattributes%s", "");
+      for (; removed != NULL; removed = removed->next)
+        {
+          GList *eattrlist = removed->data;
+          EVCardAttribute *eattr = eattrlist->data;
+          const gchar *eattrname = e_vcard_attribute_get_name (eattr);
+          if (sl_is_ignored_eattr (eattrname))
+            {
+              sl_debug_book ("ignoring eattribute \"%s\"", eattrname);
+              continue;
+            }
+          
+          sl_debug_book ("eattribute \"%s\" doesn't exist anymore", eattrname);
+          SlAttribute *attr = g_object_ref (sl_entity_get_attribute_from_eattr (entity, eattr));
+          g_assert (attr != NULL);
+          sl_entity_remove_attribute_shallow (entity, attr);
+          sl_book_emit_person_attribute_removed (self, person, attr, FALSE);
+          g_object_unref (attr);
+        }
+      
+      sl_debug_book ("processing modified eattributes%s", "");
+      for (; modified != NULL; modified = modified->next)
+        {
+          GList *eattrlist = modified->data;
+          EVCardAttribute *eattr = eattrlist->data;
+          const gchar *eattrname = e_vcard_attribute_get_name (eattr);
+          if (sl_is_ignored_eattr (eattrname))
+            {
+              sl_debug_book ("ignoring eattribute \"%s\"", eattrname);
+              continue;
+            }
+
+          sl_debug_book ("found modified eattribute \"%s\"", eattrname);
+          SlAttribute *attr = sl_entity_get_attribute_from_eattr (entity, eattr);
+          g_assert (attr != NULL);
+          GList *old_values = sl_attribute_get_all (attr);
+          sl_attribute_set_all_from_eattributes (attr, eattrlist);
+          sl_book_emit_person_attribute_modified (self, person, attr, old_values, FALSE);
+        }
       
+      sl_debug_book ("processing rest of eattributes%s", "");
+      for (; rest != NULL; rest = rest->next)
+        {
+          GList *eattrlist = rest->data;
+          EVCardAttribute *eattr = eattrlist->data;
+          const gchar *eattrname = e_vcard_attribute_get_name (eattr);
+          if (sl_is_ignored_eattr (eattrname))
+            {
+              sl_debug_book ("ignoring eattribute \"%s\"", eattrname);
+              continue;
+            }
+          
+          SlAttribute *attr = sl_entity_get_attribute_from_eattr (entity, eattr);
+          g_assert (attr != NULL);
+          sl_attribute_update_eattributes (attr, eattrlist);
+        }
+      
+      g_list_free (g_list_first (added));
+      g_list_free (g_list_first (removed));
+      g_list_free (g_list_first (modified));
+      sl_priv_util_eattribute_deep_list_free (eattributes);
+      sl_priv_util_eattribute_deep_list_free (eattributes_old);
+      
+      /*
       sl_priv_util_eattribute_list_print (eattributes, "eattributes");
       
       sl_debug_book ("examining %d eattribute(s)", g_list_length (eattributes));
@@ -672,14 +773,18 @@
           g_assert (attr != NULL);
           sl_book_emit_person_attribute_removed (self, person, attr, FALSE);
         }
+      */
+      
       
-      g_object_unref (econtact_old);
+      //g_object_unref (econtact_old);
     }
 }
 
 static void
 eview_contacts_removed (EBookView *eview, GList *ids, SlBook *self)
 {
+  sl_debug_book ("%d econtacts removed", g_list_length (ids));
+  
   for (; ids != NULL; ids = ids->next)
     {
       SlPerson *person = sl_book_get_person (self, SL_ATTR_ID, ids->data);

Modified: trunk/libsoylent/sl-book.h
==============================================================================
--- trunk/libsoylent/sl-book.h	(original)
+++ trunk/libsoylent/sl-book.h	Mon Aug 11 21:44:57 2008
@@ -28,7 +28,7 @@
 #ifndef SL_BOOK_H
 #define SL_BOOK_H
 
-#include "sl-person.h"
+#include "sl-mutual-inclusion.h"
 
 #include <glib.h>
 #include <glib-object.h>
@@ -46,7 +46,6 @@
 
 #define SL_BOOK_DEFAULT sl_book_default
 
-typedef struct _SlBook      SlBook;
 typedef struct _SlBookClass SlBookClass;
 typedef struct _SlBookPriv  SlBookPriv;
 



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