soylent r236 - in branches/libsoylent-v0.2.0: . libsoylent libsoylent/test



Author: svenp
Date: Wed Jul 23 09:44:35 2008
New Revision: 236
URL: http://svn.gnome.org/viewvc/soylent?rev=236&view=rev

Log:
merged with newest version of libsoylent

Added:
   branches/libsoylent-v0.2.0/libsoylent/AUTHORS
      - copied unchanged from r235, /trunk/libsoylent/AUTHORS
   branches/libsoylent-v0.2.0/libsoylent/COPYING
      - copied unchanged from r235, /trunk/libsoylent/COPYING
   branches/libsoylent-v0.2.0/libsoylent/MAINTAINERS
      - copied unchanged from r235, /trunk/libsoylent/MAINTAINERS
   branches/libsoylent-v0.2.0/libsoylent/NEWS
      - copied unchanged from r235, /trunk/libsoylent/NEWS
   branches/libsoylent-v0.2.0/libsoylent/README
      - copied unchanged from r235, /trunk/libsoylent/README
   branches/libsoylent-v0.2.0/libsoylent/header.txt
      - copied unchanged from r235, /trunk/libsoylent/header.txt
   branches/libsoylent-v0.2.0/libsoylent/mail-blog-template.txt
      - copied unchanged from r235, /trunk/libsoylent/mail-blog-template.txt
   branches/libsoylent-v0.2.0/libsoylent/newsdraft.txt
      - copied unchanged from r235, /trunk/libsoylent/newsdraft.txt
   branches/libsoylent-v0.2.0/libsoylent/sl-entity-handler-eds.c
      - copied unchanged from r235, /trunk/libsoylent/sl-entity-handler-eds.c
   branches/libsoylent-v0.2.0/libsoylent/sl-entity-handler-eds.h
      - copied unchanged from r235, /trunk/libsoylent/sl-entity-handler-eds.h
   branches/libsoylent-v0.2.0/libsoylent/sl-entity-handler-file.c
      - copied unchanged from r235, /trunk/libsoylent/sl-entity-handler-file.c
   branches/libsoylent-v0.2.0/libsoylent/sl-entity-handler-file.h
      - copied unchanged from r235, /trunk/libsoylent/sl-entity-handler-file.h
   branches/libsoylent-v0.2.0/libsoylent/sl-entity-handler.c
      - copied unchanged from r235, /trunk/libsoylent/sl-entity-handler.c
   branches/libsoylent-v0.2.0/libsoylent/sl-entity-handler.h
      - copied unchanged from r235, /trunk/libsoylent/sl-entity-handler.h
Modified:
   branches/libsoylent-v0.2.0/configure.ac
   branches/libsoylent-v0.2.0/libsoylent/Makefile.am
   branches/libsoylent-v0.2.0/libsoylent/sl-book.c
   branches/libsoylent-v0.2.0/libsoylent/sl-book.h
   branches/libsoylent-v0.2.0/libsoylent/sl-entity.c
   branches/libsoylent-v0.2.0/libsoylent/sl-entity.h
   branches/libsoylent-v0.2.0/libsoylent/sl-group.c
   branches/libsoylent-v0.2.0/libsoylent/sl-group.h
   branches/libsoylent-v0.2.0/libsoylent/sl-person.c
   branches/libsoylent-v0.2.0/libsoylent/sl-person.h
   branches/libsoylent-v0.2.0/libsoylent/sl-priv-util.c
   branches/libsoylent-v0.2.0/libsoylent/sl-priv-util.h
   branches/libsoylent-v0.2.0/libsoylent/soylent.c
   branches/libsoylent-v0.2.0/libsoylent/soylent.h
   branches/libsoylent-v0.2.0/libsoylent/test/init.c
   branches/libsoylent-v0.2.0/libsoylent/test/test-book.c
   branches/libsoylent-v0.2.0/libsoylent/test/test-playground.c
   branches/libsoylent-v0.2.0/libsoylent/test/test.c
   branches/libsoylent-v0.2.0/libsoylent/test/test.h

Modified: branches/libsoylent-v0.2.0/configure.ac
==============================================================================
--- branches/libsoylent-v0.2.0/configure.ac	(original)
+++ branches/libsoylent-v0.2.0/configure.ac	Wed Jul 23 09:44:35 2008
@@ -7,8 +7,8 @@
 m4_define(soylent_major_minor, soylent_major_version.soylent_minor_version)
 
 m4_define(libsoylent_major_version, 0)
-m4_define(libsoylent_minor_version, 0)
-m4_define(libsoylent_micro_version, 1)
+m4_define(libsoylent_minor_version, 2)
+m4_define(libsoylent_micro_version, 0)
 m4_define(libsoylent_version, libsoylent_major_version.libsoylent_minor_version.libsoylent_micro_version)
 
 AC_INIT(soylent, soylent_version)
@@ -114,6 +114,7 @@
 	PKG_CHECK_MODULES(TEST,
 	[
 		glib-2.0
+		libebook-1.2
 	])
 	
 	AC_DEFINE(ENABLE_LIBSOYLENT, 1, [Build libsoylent])

Modified: branches/libsoylent-v0.2.0/libsoylent/Makefile.am
==============================================================================
--- branches/libsoylent-v0.2.0/libsoylent/Makefile.am	(original)
+++ branches/libsoylent-v0.2.0/libsoylent/Makefile.am	Wed Jul 23 09:44:35 2008
@@ -4,14 +4,23 @@
 
 lib_LTLIBRARIES = libsoylent.la
 
+# TODO: do not install sl-priv-util.h
+
 libsoylent_la_SOURCES = \
 	soylent.h \
 	sl-entity.h \
+	sl-entity-handler.h \
+	sl-entity-handler-eds.h \
+	sl-entity-handler-file.h \
 	sl-book.h \
 	sl-group.h \
 	sl-person.h \
+	sl-priv-util.h \
 	soylent.c \
 	sl-entity.c \
+	sl-entity-handler.c \
+	sl-entity-handler-eds.c \
+	sl-entity-handler-file.c \
 	sl-book.c \
 	sl-group.c \
 	sl-person.c \

Modified: branches/libsoylent-v0.2.0/libsoylent/sl-book.c
==============================================================================
--- branches/libsoylent-v0.2.0/libsoylent/sl-book.c	(original)
+++ branches/libsoylent-v0.2.0/libsoylent/sl-book.c	Wed Jul 23 09:44:35 2008
@@ -1,9 +1,30 @@
-/**/
+/*
+ * libsoylent - people management
+ * 
+ * Copyright (C) 2008 Sven Pfaller, Noya <kalterregen gmx net>
+ * Copyright (C) 2008 Travis Reitter <treitter-dev netdrain com>
+ * Copyright (C) 2008 Rob Taylor <rob taylor codethink co uk>
+ * Copyright (C) 2008 Chris Lord <chris o-hand com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
 
 #include "sl-book.h"
 #include "sl-priv-util.h"
-
-#include <libebook/e-book.h>
+#include "sl-entity.h"
+#include "sl-entity-handler-eds.h"
 
 /* private structs and fields */
 
@@ -14,16 +35,16 @@
 };
 
 static GObjectClass *parent_class = NULL;
-static SlBook *sl_book_default = NULL;
 
 static void sl_book_class_init (gpointer g_class, gpointer class_data);
 static void sl_book_init (GTypeInstance *instance, gpointer g_class);
 static void sl_book_dispose (GObject *object);
-static void sl_book_set_property (GObject *object, guint property_id,
+static void sl_book_set_property (SlBook *self, guint property_id,
   const GValue *value, GParamSpec *pspec);
 static void sl_book_get_property (GObject *object, guint property_id,
   GValue *value, GParamSpec *pspec);
 static SlBook *sl_book_new (EBook *ebook);
+static SlBook *sl_book_new_from_source (ESource *source, GError **error);
 
 GType
 sl_book_get_type (void)
@@ -56,238 +77,324 @@
   return g_quark_from_static_string ("sl-book-error");
 }
 
-void
-sl_book_setup (void)
+static void
+sl_book_class_init (gpointer g_class, gpointer class_data)
+{
+  parent_class = g_type_class_peek (g_type_parent (SL_BOOK_TYPE));
+  g_assert (parent_class != NULL);
+  
+  GObjectClass *obj_class = G_OBJECT_CLASS (g_class);
+  obj_class->dispose = sl_book_dispose;
+  obj_class->get_property = (void (*)(GObject *, guint, GValue *, GParamSpec *))
+                              sl_book_get_property;
+  obj_class->set_property = (void (*)(GObject *, guint, const GValue *,
+                              GParamSpec *)) sl_book_set_property;
+  
+  GParamSpec *pspec = NULL;
+  pspec = g_param_spec_pointer ("ebook", "ebook", "EBook backend", 
+            G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE);
+  
+  g_object_class_install_property (obj_class, SL_BOOK_PROPERTY_EBOOK, pspec);
+}
+
+static void
+sl_book_init (GTypeInstance *instance, gpointer g_class)
+{
+  SlBook *self = SL_BOOK (instance);
+  SlBookPriv *priv = g_new (SlBookPriv, 1);
+  self->priv = priv;
+  self->priv->ebook = NULL;
+  self->priv->error = NULL;
+  self->disposed = FALSE;
+}
+
+static void
+sl_book_dispose (GObject *object)
+{
+  SlBook *self = SL_BOOK (object);
+  g_return_if_fail (!self->disposed);
+  
+  g_error_free (self->priv->error);
+  g_object_unref (self->priv->ebook);
+  g_free (self->priv);
+  self->disposed = TRUE;
+  
+  parent_class->dispose (object);
+}
+
+static void
+sl_book_set_property (SlBook *self, guint property_id, const GValue *value,
+  GParamSpec *pspec)
 {
-  sl_book_default = sl_book_new (NULL);
-  sl_book_set_current (sl_book_default);
+  switch (property_id)
+    {
+      case SL_BOOK_PROPERTY_EBOOK:
+        self->priv->ebook = g_object_ref (g_value_get_pointer (value));
+        break;
+      default:
+        g_assert_not_reached ();
+        break;
+    }
 }
 
-void
-sl_book_set_current (SlBook *book)
+static void
+sl_book_get_property (GObject *object, guint property_id, GValue *value,
+  GParamSpec *pspec)
 {
-  sl_book_current = book;
+  g_warning("%s not implemented", __FUNCTION__);
+}
+
+gboolean
+sl_book_setup (GError **error)
+{
+  sl_book_default = sl_book_open_default (error);
+  if (sl_book_default == NULL)
+    {
+      return FALSE;
+    }
+  return TRUE;
 }
 
 GList *
 sl_book_get_books (void)
 {
-  /* TODO: get all books: as objects? or as strings? */
+  GList *books = NULL;
+  
   GError *error = NULL;
   ESourceList *source_tree = NULL;
-  
-  e_book_get_addressbooks (&source_tree, &error);
-  if (error != NULL)
+  if (!e_book_get_addressbooks (&source_tree, &error))
     {
-      g_critical ("failed to list books");
+      g_critical ("failed get source tree: %s", error->message);
       return NULL;
     }
   
-  ESourceGroup *default_group = NULL;
   GSList *groups = e_source_list_peek_groups (source_tree);
   for (; groups != NULL; groups = groups->next)
     {
       ESourceGroup *group = groups->data;
-      if (!default_group)
-        {
-          default_group = group;
-        }
-      const char *group_name = e_source_group_peek_name (group);
       GSList *sources = e_source_group_peek_sources (group);
+      
+      /* debug
+      const char *group_name = e_source_group_peek_name (group); */
+      
       for (; sources != NULL; sources = sources->next)
         {
           ESource *source = sources->data;
           const gchar *name = e_source_peek_name (source);
+          books = g_list_append (books, (gpointer) name);
+          
+          /* debug
           const gchar *reluri = e_source_peek_relative_uri(source);
           const gchar *absuri = e_source_peek_absolute_uri(source);
-          g_print (" * %s.%s [%s, %s]\n", group_name, name, reluri, absuri);
+          g_debug ("%s.%s [%s, %s]", group_name, name, reluri, absuri); */
         }
     }
-  
-  return NULL;
+    
+  g_object_unref (source_tree);  
+  return books;
 }
 
-static gboolean
+gboolean
 sl_book_exists (const gchar *name)
 {
   GError *error = NULL;
   ESourceList *source_tree = NULL;
   if (!e_book_get_addressbooks (&source_tree, &error))
     {
-      g_critical ("failed to get source tree: %s", error->message);
+      g_critical ("failed to get source-tree: %s", error->message);
+      return FALSE;
     }
-    
-  /* TODO: check for address book */
-    
-  return FALSE;
+  
+  ESource *source = sl_priv_util_get_source (source_tree, name);
+  g_object_unref (source_tree);
+  return (source != NULL);
 }
 
 SlBook *
 sl_book_create (const gchar *name, GError **error)
 {
-  ESourceList *source_tree = NULL;
-  
-  g_return_val_if_fail (name != NULL, FALSE);
-  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+  g_return_val_if_fail (name != NULL, NULL);
+  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
   
   if (sl_book_exists (name))
     {
       g_set_error (error, SL_BOOK_ERROR, SL_BOOK_ERROR_ALREADY_EXISTS,
-        "The book %s already exists.", (gchar *) name);
-      return FALSE;
+        "The book \"%s\" already exists.", (gchar *) name);
+      return NULL;
     }
   
+  ESourceList *source_tree = NULL;
   if (!e_book_get_addressbooks (&source_tree, error))
     {
-      g_critical ("failed to get source tree");
-      return FALSE;
+      return NULL;
     }
   ESourceGroup *default_group = sl_priv_util_source_tree_get_default_group
-                                (source_tree);
+                                  (source_tree);
   
   ESource *source = e_source_new (name, "");
-  e_source_set_group (source, default_group); /* workaround */
   e_source_group_add_source (default_group, source, -1);
   if (!e_source_list_sync (source_tree, error))
     {
-      g_critical ("failed to store source tree");
-      return FALSE;
+      return NULL;
     }
   
-  EBook *ebook = e_book_new (source, error);
-  if (!ebook)
-    {
-      g_critical ("failed to load ebook");
-      return FALSE;
-    }
-  if (!e_book_open (ebook, FALSE, error))
+  SlBook *book = sl_book_new_from_source (source, error);
+  if (!book)
     {
-      g_critical ("failed to open ebook");
-      return FALSE;
+      return NULL;
     }
+  
+  /* we don't need the source-tree anymore _after_ the book has been created */
+  g_object_unref (source_tree);
     
-  //return sl_book_new (ebook);
-  return NULL;
+  return book;
 }
 
-static void
-sl_book_class_init (gpointer g_class, gpointer class_data)
+SlBook *sl_book_open (const gchar *name, GError **error)
 {
-  parent_class = g_type_class_peek (g_type_parent (SL_BOOK_TYPE));
-  g_assert (parent_class != NULL);
+  ESourceList *source_tree = NULL;
+  if (!e_book_get_addressbooks (&source_tree, error))
+    {
+      return NULL;
+    }
+  ESource *source = sl_priv_util_get_source (source_tree, name);
+  if (source == NULL)
+    {
+      g_set_error (error, SL_BOOK_ERROR, SL_BOOK_ERROR_NOT_EXISTING,
+        "There is no book \"%s\".", (gchar *) name);
+      return NULL;
+    }
   
-  GObjectClass *obj_class = G_OBJECT_CLASS (g_class);
-  obj_class->dispose = sl_book_dispose;
-  obj_class->get_property = sl_book_get_property;
-  obj_class->set_property = sl_book_set_property;
+  return sl_book_new_from_source (source, error);
 }
 
-static void
-sl_book_init (GTypeInstance *instance, gpointer g_class)
+SlBook *sl_book_open_default (GError **error)
 {
-  SlBook *self = SL_BOOK (instance);
-  SlBookPriv *priv = g_new (SlBookPriv, 1);
-  self->priv = priv;
-  self->priv->error = NULL;
-  
-  /* TODO: ebook should be depending on sl_book_new call, but for now we just
-   * use the default addressbook */
-  self->priv->ebook = e_book_new_system_addressbook (&self->priv->error);
-  if (self->priv->error)
-    {
-      g_critical ("failed to get system addressbook");
-      return;
-    }
-  /* TODO: is it a good idea to open the book here? */
-  e_book_open (self->priv->ebook, FALSE, &self->priv->error);
-  if (self->priv->error)
+  EBook *ebook = e_book_new_system_addressbook (error);
+  if (ebook == NULL)
+    {
+      return NULL;
+    }
+  if (!e_book_open (ebook, FALSE, error))
     {
-      g_critical ("failed to open addressbook");
-      return;
+      return NULL;
     }
   
-  self->disposed = FALSE;
+  return sl_book_new (ebook);
 }
 
-static void
-sl_book_dispose (GObject *object)
+gboolean
+sl_book_delete (const gchar *name, GError **error)
 {
-  SlBook *self = SL_BOOK (object);
-  g_return_if_fail (!self->disposed);
+  /* TODO: forbid to delete default addressbook */
   
-  g_error_free (self->priv->error);
-  g_object_unref (self->priv->ebook);
-  g_free (self->priv);
-  self->disposed = TRUE;
+  g_return_val_if_fail (name != NULL, FALSE);
+  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
   
-  parent_class->dispose (object);
+  ESourceList *source_tree = NULL;
+  if (!e_book_get_addressbooks (&source_tree, error))
+    {
+      return FALSE;
+    }
+  
+  ESource *source = sl_priv_util_get_source (source_tree, name);
+  if (source == NULL)
+    {
+      g_set_error (error, SL_BOOK_ERROR, SL_BOOK_ERROR_NOT_EXISTING,
+        "There is no book \"%s\".", (gchar *) name);
+      return FALSE;
+    }
+  
+  /* get ebook and delete its related data */
+  EBook *ebook = e_book_new (source, error);
+  if (ebook == NULL)
+    {
+      return FALSE;
+    }
+  gboolean removed = e_book_remove (ebook, error);
+  g_object_unref (ebook);
+  if (!removed)
+    {
+      return FALSE;
+    }
+  
+  /* remove the source from the source-tree */
+  ESourceGroup *group = e_source_peek_group (source);
+  e_source_group_remove_source (group, source);
+  if (!e_source_list_sync (source_tree, error))
+    {
+      return FALSE;
+    }
+  g_object_unref (source_tree);
+  
+  return TRUE;
 }
 
-static void
-sl_book_set_property (GObject *object, guint property_id, const GValue *value,
-  GParamSpec *pspec)
+static SlBook *
+sl_book_new (EBook *ebook)
 {
-  g_warning("%s not implemented", __FUNCTION__);
+  g_return_val_if_fail (ebook != NULL && E_IS_BOOK (ebook), NULL);
+  SlBook *self = g_object_new (SL_BOOK_TYPE, "ebook", ebook, NULL);
+  return self;
 }
 
-static void
-sl_book_get_property (GObject *object, guint property_id, GValue *value,
-  GParamSpec *pspec)
+static SlBook *
+sl_book_new_from_source (ESource *source, GError **error)
 {
-  g_warning("%s not implemented", __FUNCTION__);
+  g_return_val_if_fail (source != NULL && E_IS_SOURCE (source), NULL);
+  
+  EBook *ebook = e_book_new (source, error);
+  if (!ebook)
+    {
+      return NULL;
+    }
+  if (!e_book_open (ebook, FALSE, error))
+    {
+      g_object_unref (ebook);
+      return NULL;
+    }
+  
+  SlBook *self = sl_book_new (ebook);
+  g_object_unref (ebook);
+  return self;
 }
 
-void
-sl_book_delete (SlBook *book) {
-  g_warning("%s not implemented", __FUNCTION__);
-  /*
-  AddressbookView *view = data;
-  AddressbookViewPrivate *priv = view->priv;
-  ESource *selected_source;
-  EBook  *book;
-  GError *error = NULL;
-  GtkWindow *toplevel;
-
-  selected_source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (priv->selector));
-  if (!selected_source)
-    return;
-
-  toplevel = (GtkWindow *)gtk_widget_get_toplevel(ep->target->widget);
-
-  if (e_error_run(toplevel, "addressbook:ask-delete-addressbook", e_source_peek_name(selected_source)) != GTK_RESPONSE_YES)
-    return;
-
-  Remove local data
-  book = e_book_new (selected_source, &error);
-  if (book) {
-    BookRemovedClosure *closure = g_new (BookRemovedClosure, 1);
-
-    closure->toplevel = (GtkWidget *)toplevel;
-    closure->view = view;
-    closure->selected_source = selected_source;
-
-    if (e_book_async_remove (book, book_removed, closure)) {
-      e_error_run (toplevel, "addressbook:remove-addressbook", NULL);
-      g_free (closure);
-      g_object_unref (book);
+gboolean
+sl_book_add_person (SlBook *self, SlPerson *person, GError **error)
+{
+  /* TODO: adding a contact to a self-created addressbook kills E-D-S and hangs
+     here... */
+  
+  SlEntity *entity = SL_ENTITY (person);
+  if (!e_book_add_contact (self->priv->ebook, sl_entity_get_econtact (entity),
+    error))
+    {
+      return FALSE;
     }
-  }*/
+  
+  return TRUE;
 }
 
-static SlBook *
-sl_book_new (EBook *ebook)
+gboolean
+sl_book_remove_person (SlBook *self, SlPerson *person, GError **error)
 {
-  /* TODO: create new EBook with ESource, howto? */
-  SlBook *self = g_object_new(SL_BOOK_TYPE, NULL);
-  if (self->priv->error != NULL)
+  EContact *econtact = sl_entity_get_econtact (SL_ENTITY (person));
+  const char* id = e_contact_get (econtact, E_CONTACT_UID);
+  if (!e_book_remove_contact (self->priv->ebook, id, error))
     {
-      g_object_unref (self);
-      self = NULL;
+      return FALSE;
     }
-  return self;
+  return TRUE;
+}
+
+GList *
+sl_book_get_people (SlBook *self)
+{
+  g_warning("%s not implemented", __FUNCTION__);
+  return NULL;
 }
 
-SlEntity *
+SlPerson *
 sl_book_get_person(SlBook *self, gchar *attrname, gpointer value)
 {
   g_warning("%s not implemented", __FUNCTION__);

Modified: branches/libsoylent-v0.2.0/libsoylent/sl-book.h
==============================================================================
--- branches/libsoylent-v0.2.0/libsoylent/sl-book.h	(original)
+++ branches/libsoylent-v0.2.0/libsoylent/sl-book.h	Wed Jul 23 09:44:35 2008
@@ -1,12 +1,38 @@
-/**/
+/*
+ * libsoylent - people management
+ * 
+ * Copyright (C) 2008 Sven Pfaller, Noya <kalterregen gmx net>
+ * Copyright (C) 2008 Travis Reitter <treitter-dev netdrain com>
+ * Copyright (C) 2008 Rob Taylor <rob taylor codethink co uk>
+ * Copyright (C) 2008 Chris Lord <chris o-hand com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ * TODO: architecture should be: SlStorage -> (SlStorageBase) -> SlBook
+ */
 
 #ifndef SL_BOOK_H
 #define SL_BOOK_H
 
-#include "sl-entity.h"
+#include "sl-person.h"
 
 #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, \
@@ -19,18 +45,27 @@
 
 #define SL_BOOK_ERROR sl_book_error_quark ()
 
-#define SL_BOOK_STD sl_book_current;
+#define SL_BOOK_DEFAULT sl_book_default
+
+typedef struct _SlBook      SlBook;
+typedef struct _SlBookClass SlBookClass;
+typedef struct _SlBookPriv  SlBookPriv;
+
+typedef enum _SlBookProperty  SlBookProperty;
+typedef enum _SlBookError     SlBookError;
+
+enum SlBookProperty
+{
+  SL_BOOK_PROPERTY_EBOOK = 1
+};
 
 enum SlBookError
 {
   SL_BOOK_ERROR_ALREADY_EXISTS,
+  SL_BOOK_ERROR_NOT_EXISTING,
   SL_BOOK_ERROR_FAILED
 };
 
-typedef struct _SlBook      SlBook;
-typedef struct _SlBookClass SlBookClass;
-typedef struct _SlBookPriv  SlBookPriv;
-
 struct _SlBook
 {
   GObject parent;
@@ -43,20 +78,24 @@
   GObjectClass parent;
 };
 
-SlBook *sl_book_current;
+SlBook *sl_book_default;
 
 GType sl_book_get_type (void);
 GQuark sl_book_error_quark (void);
 
-void sl_book_setup (void);
-void sl_book_set_current (SlBook *book);
+gboolean sl_book_setup (GError **error);
 
 GList *sl_book_get_books (void);
+gboolean sl_book_exists (const gchar *name);
 SlBook *sl_book_create (const gchar *name, GError **error);
-SlBook *sl_book_open (const gchar *name);
-SlBook *sl_book_open_default (void);
-void sl_book_delete (SlBook *book);
-
-SlEntity *sl_book_get_person(SlBook *self, gchar *attrname, gpointer value);
+SlBook *sl_book_open (const gchar *name, GError **error);
+SlBook *sl_book_open_default (GError **error);
+gboolean sl_book_delete (const gchar *name, GError **error);
+
+gboolean sl_book_add_person (SlBook *self, SlPerson *person, GError **error);
+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);
 
 #endif

Modified: branches/libsoylent-v0.2.0/libsoylent/sl-entity.c
==============================================================================
--- branches/libsoylent-v0.2.0/libsoylent/sl-entity.c	(original)
+++ branches/libsoylent-v0.2.0/libsoylent/sl-entity.c	Wed Jul 23 09:44:35 2008
@@ -1,4 +1,28 @@
-/**/
+/*
+ * libsoylent - people management
+ * 
+ * Copyright (C) 2008 Sven Pfaller, Noya <kalterregen gmx net>
+ * Copyright (C) 2008 Travis Reitter <treitter-dev netdrain com>
+ * Copyright (C) 2008 Rob Taylor <rob taylor codethink co uk>
+ * Copyright (C) 2008 Chris Lord <chris o-hand com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/* TODO: will be splitted to SlEntity (interface), SlEntityBase (abstract-
+ * base class), SlEntityEDS. for now this will be misused as SlEntityEDS */
 
 #include "sl-entity.h"
 
@@ -6,42 +30,107 @@
 
 struct _SlEntityPriv
 {
-	gchar *foo;
+  SlEntityHandler *entity_handler;
+  EContact *econtact;
+  GList *attributes;
+};
+
+struct _SlAttributePriv
+{
+  SlEntity *entity;
+  gchar *name;
+  GList *values;
+};
+
+struct _SlAttributeHandler
+{
+  SlAttributeHandlerType type;
+  gpointer (*writer)(const gchar *attrname, gpointer value);
+  gpointer (*reader)(const gchar *attrname, gpointer value);
 };
 
 static GObjectClass *parent_class = NULL;
 
+static GObjectClass *attribute_parent_class = NULL;
+
 static void sl_entity_class_init (gpointer g_class, gpointer class_data);
 static void sl_entity_init (GTypeInstance *instance, gpointer g_class);
 static void sl_entity_dispose (GObject *object);
-static void sl_entity_set_property (GObject *object, guint property_id,
+static void sl_entity_set_property (SlEntity *self, guint property_id,
 	const GValue *value, GParamSpec *pspec);
-static void sl_entity_get_property (GObject *object, guint property_id,
+static void sl_entity_get_property (SlEntity *self, guint property_id,
 	GValue *value, GParamSpec *pspec);
 
+static void sl_attribute_class_init (gpointer g_class, gpointer class_data);
+static void sl_attribute_init (GTypeInstance *instance, gpointer g_class);
+static void sl_attribute_dispose (GObject *object);
+static void sl_attribute_set_property (GObject *object, guint property_id,
+  const GValue *value, GParamSpec *pspec);
+static void sl_attribute_get_property (GObject *object, guint property_id,
+  GValue *value, GParamSpec *pspec);
+
 GType
 sl_entity_get_type (void)
 {
-	static GType type = 0;
-	static const GTypeInfo info =
+  static GType type = 0;
+  static const GTypeInfo info =
     {
-  		sizeof (SlEntityClass),
-  		NULL,
-  		NULL,
-  		sl_entity_class_init,
-  		NULL,
-  		NULL,
-  		sizeof (SlEntity),
-  		0,
-  		sl_entity_init,
-  		NULL
-	 };
-	
-	if (type == 0)
+      sizeof (SlEntityClass),
+      NULL,
+      NULL,
+      sl_entity_class_init,
+      NULL,
+      NULL,
+      sizeof (SlEntity),
+      0,
+      sl_entity_init,
+      NULL
+   };
+  
+  if (type == 0)
     {
-		  type = g_type_register_static(G_TYPE_OBJECT, "SlEntity", &info, 0);
+      type = g_type_register_static(G_TYPE_OBJECT, "SlEntity", &info, 0);
     }
-	return type;
+  return type;
+}
+
+GType
+sl_attribute_get_type (void)
+{
+  static GType type = 0;
+  static const GTypeInfo info =
+    {
+      sizeof (SlAttributeClass),
+      NULL,
+      NULL,
+      sl_attribute_class_init,
+      NULL,
+      NULL,
+      sizeof (SlAttribute),
+      0,
+      sl_attribute_init,
+      NULL
+   };
+  
+  if (type == 0)
+    {
+      type = g_type_register_static(G_TYPE_OBJECT, "SlAttribute", &info, 0);
+    }
+  return type;
+}
+
+void
+sl_entity_install_attribute_handler (const gchar *attrname,
+  SlAttributeHandlerType type, gpointer (*writer)(const gchar *attrname,
+   gpointer value), gpointer (*reader)(const gchar *attrname, gpointer value))
+{
+  g_warning ("%s not implemented", __FUNCTION__);
+}
+
+void
+sl_entity_remove_attribute_handler (const gchar *attrname)
+{
+  g_warning ("%s not implemented", __FUNCTION__);
 }
 
 static void
@@ -52,8 +141,17 @@
 	
   GObjectClass *obj_class = G_OBJECT_CLASS (g_class);
   obj_class->dispose = sl_entity_dispose;
-  obj_class->get_property = sl_entity_get_property;
-  obj_class->set_property = sl_entity_set_property;
+  obj_class->set_property = (void (*)(GObject *, guint, const GValue *,
+                              GParamSpec *)) sl_entity_set_property;
+  obj_class->get_property = (void (*)(GObject *, guint, GValue *, GParamSpec *))
+                              sl_entity_get_property;
+  
+  /*GParamSpec *pspec = NULL;
+  pspec = g_param_spec_pointer ("entity-handler", "entity-handler",
+            "Entity handler", G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE);
+  
+  g_object_class_install_property (obj_class, SL_ENTITY_PROPERTY_ENTITY_HANDLER,
+    pspec);*/
 }
 
 static void
@@ -62,7 +160,7 @@
 	SlEntity *self = SL_ENTITY (instance);
 	SlEntityPriv *priv = g_new (SlEntityPriv, 1);
 	self->priv = priv;
-	self->priv->foo = "FOO";
+	self->priv->attributes = NULL;
 	self->disposed = FALSE;
 }
 
@@ -71,6 +169,7 @@
 	SlEntity *self = SL_ENTITY (object);
 	g_return_if_fail (!self->disposed);
 	
+  g_list_free (self->priv->attributes);
 	g_free (self->priv);
 	self->disposed = TRUE;
   
@@ -78,28 +177,258 @@
 }
 
 static void
-sl_entity_set_property (GObject *object, guint property_id, const GValue *value,
+sl_entity_set_property (SlEntity *self, guint property_id, const GValue *value,
   GParamSpec *pspec)
 {
-	g_warning ("%s not implemented", __FUNCTION__);
+  switch (property_id)
+    {
+      //case SL_ENTITY_PROPERTY_ENTITY_HANDLER:
+        //self->priv->entity_handler = g_object_ref (g_value_get_pointer (value));
+        //break;
+      default:
+        g_assert_not_reached();
+    }
 }
 
 static void
-sl_entity_get_property (GObject *object, guint property_id, GValue *value,
+sl_entity_get_property (SlEntity *self, guint property_id, GValue *value,
   GParamSpec *pspec)
 {
 	g_warning("%s not implemented", __FUNCTION__);
 }
 
+void
+sl_entity_constr (SlEntity *self)
+{
+  self->priv->econtact = e_contact_new ();
+}
+
+void
+sl_entity_constr_with_econtact (SlEntity *self, EContact *econtact)
+{
+  self->priv->econtact = g_object_ref (econtact);
+}
+
+EContact
+*sl_entity_get_econtact (SlEntity *self)
+{
+  return self->priv->econtact;
+}
+
+/* ABSTRACT
 SlEntity *
-sl_entity_new (void)
+sl_entity_new (SlEntityHandler *entity_handler)
+{
+  g_return_val_if_fail (entity_handler != NULL &&
+    SL_IS_ENTITY_HANDLER (entity_handler), NULL);
+  
+	SlEntity *self = g_object_new (SL_ENTITY_TYPE, "entity-handler",
+                      entity_handler, NULL);
+  self->priv->econtact = e_contact_new ();
+  
+	return self;
+}*/
+
+/*SlEntityHandler *sl_entity_get_handler (SlEntity *self)
 {
-	SlEntity *entity = g_object_new (SL_ENTITY_TYPE, NULL);
-	return entity;
+  return self->priv->entity_handler;
+}*/
+
+SlAttribute *sl_entity_get_attribute (SlEntity *self, gchar *attrname)
+{
+  /* TODO: use hashtable? I think yes... */
+  GList *iter = self->priv->attributes;
+  for (; iter != NULL; iter = iter->next)
+    {
+      SlAttribute *attr = iter->data;
+      if (g_str_equal (sl_attribute_get_name (attr), attrname))
+        {
+          return attr;
+        }
+    }
+  return NULL;
+}
+
+GList *sl_entity_get_attributes (SlEntity *self)
+{
+  g_warning("%s not implemented", __FUNCTION__);
+  return NULL;
+}
+
+void
+sl_entity_set (SlEntity *self, gchar *attrname, gpointer value)
+{
+  SlAttribute *attr = sl_entity_get_attribute (self, attrname);
+  if (!attr) return;
+  sl_attribute_set (attr, value);
+}
+
+gpointer
+sl_entity_get (SlEntity *self, gchar *attrname)
+{
+  SlAttribute *attr = sl_entity_get_attribute (self, attrname);
+  if (!attr) return NULL;
+  return sl_attribute_get (attr);
+}
+
+void
+sl_entity_remove (SlEntity *self, gchar *attrname)
+{
+  g_warning("%s not implemented", __FUNCTION__);
+}
+
+void
+sl_entity_set_at (SlEntity *self, gchar *attrname, gint index, gpointer value)
+{
+  g_warning("%s not implemented", __FUNCTION__);
 }
 
 gpointer
-sl_entity_get (SlEntity *self, const gchar *attrname)
+sl_entity_get_at (SlEntity *self, gchar *attrname, gint index)
+{
+  g_warning("%s not implemented", __FUNCTION__);
+  return NULL;
+}
+
+void
+sl_entity_remove_at (SlEntity *self, gchar *attrname, gint index)
+{
+  g_warning("%s not implemented", __FUNCTION__);
+}
+
+void
+sl_entity_set_values (SlEntity *self, gchar *attrname, GList *values)
+{
+  g_warning("%s not implemented", __FUNCTION__);
+}
+
+GList *
+sl_entity_get_values (SlEntity *self, gchar *attrname)
+{
+  g_warning("%s not implemented", __FUNCTION__);
+  return NULL;
+}
+
+void
+sl_entity_remove_values (SlEntity *self, gchar *attrname)
+{
+  g_warning("%s not implemented", __FUNCTION__);
+}
+
+static void
+sl_attribute_class_init (gpointer g_class, gpointer class_data)
+{
+  attribute_parent_class = g_type_class_peek (g_type_parent
+    (SL_ATTRIBUTE_TYPE));
+  g_assert (attribute_parent_class != NULL);
+  
+  GObjectClass *obj_class = G_OBJECT_CLASS (g_class);
+  obj_class->dispose = sl_attribute_dispose;
+  obj_class->get_property = sl_attribute_get_property;
+  obj_class->set_property = sl_attribute_set_property;
+}
+
+static void
+sl_attribute_init (GTypeInstance *instance, gpointer g_class)
+{
+  SlAttribute *self = SL_ATTRIBUTE (instance);
+  SlAttributePriv *priv = g_new (SlAttributePriv, 1);
+  self->priv = priv;
+  self->disposed = FALSE;
+}
+
+static void
+sl_attribute_dispose (GObject *object)
+{
+  SlAttribute *self = SL_ATTRIBUTE (object);
+  g_return_if_fail (!self->disposed);
+  
+  g_free (self->priv);
+  self->disposed = TRUE;
+  
+  attribute_parent_class->dispose (object);
+}
+
+static void
+sl_attribute_set_property (GObject *object, guint property_id,
+  const GValue *value, GParamSpec *pspec)
+{
+  g_warning("%s not implemented", __FUNCTION__);
+}
+
+static void
+sl_attribute_get_property (GObject *object, guint property_id,
+  GValue *value, GParamSpec *pspec)
+{
+  g_warning("%s not implemented", __FUNCTION__);
+}
+
+SlAttribute *
+sl_attribute_new (const gchar *name)
+{
+  /* TODO: add constr-param name and values */
+  SlAttribute *self = g_object_new (SL_ATTRIBUTE_TYPE, NULL);
+  return self;
+}
+
+void sl_attribute_set (SlAttribute *self, gpointer value)
+{
+  g_warning("%s not implemented", __FUNCTION__);
+}
+
+gpointer sl_attribute_get (SlAttribute *self)
+{
+  g_warning("%s not implemented", __FUNCTION__);
+  return NULL;
+}
+
+void sl_attribute_remove (SlAttribute *self)
+{
+  g_warning("%s not implemented", __FUNCTION__);
+}
+
+void sl_attribute_set_at (SlAttribute *self, gint index, gpointer value)
+{
+  /*SlEntityHandler *entity_handler = sl_entity_get_handler (self->priv->entity);
+   *sl_entity_handler_set_at (entity_handler, self->name, index, value);
+   * TODO: behind the scenes in EDS-handler:
+   * GList *values = vcard_attribute_get_values (attrname);
+   * for (... look for value
+   * modify value in list
+   * if direct list manipulation is not possible: set_at not possible at the
+   * moment */
+  g_warning("%s not implemented", __FUNCTION__);
+}
+
+gpointer sl_attribute_get_at (SlAttribute *self, gint index)
+{
+  g_warning("%s not implemented", __FUNCTION__);
+  return NULL;
+}
+
+void sl_attribute_remove_at (SlAttribute *self, gint index)
+{
+  g_warning("%s not implemented", __FUNCTION__);
+}
+
+void sl_attribute_set_values (SlAttribute *self, GList *values)
+{
+  g_warning("%s not implemented", __FUNCTION__);
+}
+
+GList *sl_attribute_get_values (SlAttribute *self)
+{
+  g_warning("%s not implemented", __FUNCTION__);
+  return NULL;
+}
+
+void sl_attribute_remove_values (SlAttribute *self)
+{
+  g_warning("%s not implemented", __FUNCTION__);
+}
+
+const gchar *sl_attribute_get_name (SlAttribute *self)
 {
-	return self->priv->foo;
+  g_warning("%s not implemented", __FUNCTION__);
+  return NULL;
 }

Modified: branches/libsoylent-v0.2.0/libsoylent/sl-entity.h
==============================================================================
--- branches/libsoylent-v0.2.0/libsoylent/sl-entity.h	(original)
+++ branches/libsoylent-v0.2.0/libsoylent/sl-entity.h	Wed Jul 23 09:44:35 2008
@@ -1,41 +1,150 @@
-/**/
+/*
+ * libsoylent - people management
+ * 
+ * Copyright (C) 2008 Sven Pfaller, Noya <kalterregen gmx net>
+ * Copyright (C) 2008 Travis Reitter <treitter-dev netdrain com>
+ * Copyright (C) 2008 Rob Taylor <rob taylor codethink co uk>
+ * Copyright (C) 2008 Chris Lord <chris o-hand com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/* TODO: will be splitted to SlEntity (interface), SlEntityBase (abstract-
+ * base class), SlEntityEDS. for now this will be misused as SlEntityEDS */
 
 #ifndef SL_ENTITY_H
 #define SL_ENTITY_H
 
+#include "sl-entity-handler.h"
+
 #include <glib.h>
 #include <glib-object.h>
+#include <libebook/e-book.h>
 
 #define SL_ENTITY_TYPE			 	    (sl_entity_get_type ())
-#define SL_ENTITY(obj)				    (G_TYPE_CHECK_INSTANCE_CAST(obj, \
+#define SL_ENTITY(obj)				    (G_TYPE_CHECK_INSTANCE_CAST (obj, \
 	SL_ENTITY_TYPE, SlEntity))
-#define SL_ENTITY_CLASS(cls)		  (G_TYPE_CHECK_CLASS_CAST(cls, \
+#define SL_ENTITY_CLASS(cls)		  (G_TYPE_CHECK_CLASS_CAST (cls, \
 	SL_ENTITY_TYPE, SlEntityClass))
-#define SL_IS_ENTITY(obj)         (G_TYPE_CHECK_INSTANCE_TYPE(obj, \
+#define SL_IS_ENTITY(obj)         (G_TYPE_CHECK_INSTANCE_TYPE (obj, \
 	SL_ENTITY_TYPE))
-#define SL_IS_ENTITY_CLASS(cls)	  (G_TYPE_CHECK_CLASS_TYPE(cls, SL_ENTITY_TYPE))
+#define SL_IS_ENTITY_CLASS(cls)	  (G_TYPE_CHECK_CLASS_TYPE (cls, \
+  SL_ENTITY_TYPE))
 #define SL_ENTITY_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS(obj, \
 	SL_ENTITY_TYPE))
 
+#define SL_ATTRIBUTE_TYPE           (sl_attribute_get_type ())
+#define SL_ATTRIBUTE(obj)           (G_TYPE_CHECK_INSTANCE_CAST (obj, \
+  SL_ATTRIBUTE_TYPE, SlAttribute))
+#define SL_ATTRIBUTE_CLASS(cls)     (G_TYPE_CHECK_CLASS_CAST (cls, \
+  SL_ATTRIBUTE_TYPE, SlAttributeClass))
+#define SL_IS_ATTRIBUTE(obj)        (G_TYPE_CHECK_INSTANCE_TYPE (obj, \
+  SL_ATTRIBUTE_TYPE))
+#define SL_IS_ATTRIBUTE_CLASS(cls)  (G_TYPE_CHECK_CLASS_TYPE (cls, \
+  SL_ATTRIBUTE_TYPE))
+#define SL_ATTRIBUTE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS(obj, \
+  SL_ATTRIBUTE_TYPE))
+
 typedef struct _SlEntity      SlEntity;
 typedef struct _SlEntityClass SlEntityClass;
 typedef struct _SlEntityPriv  SlEntityPriv;
 
+typedef struct _SlAttribute      SlAttribute;
+typedef struct _SlAttributeClass SlAttributeClass;
+typedef struct _SlAttributePriv  SlAttributePriv;
+
+typedef struct _SlAttributeHandler SlAttributeHandler;
+
+typedef enum _SlEntityProperty SlEntityProperty;
+
+typedef enum _SlAttributeHandlerType SlAttributeHandlerType;
+
+enum _SlEntityProperty
+{
+  SL_ENTITY_PROPERTY_ENTITY_HANDLER = 1
+};
+
+enum _SlAttributeHandlerType
+{
+  SL_ATTRIBUTE_HANDLER_TYPE_STRING,
+  SL_ATTRIBUTE_HANDLER_TYPE_BIN
+};
+
 struct _SlEntity
 {
-	GObject parent;
-	gboolean disposed;
-	SlEntityPriv *priv;
+  GObject parent;
+  gboolean disposed;
+  SlEntityPriv *priv;
 };
 
 struct _SlEntityClass
 {
-	GObjectClass parent;
+  GObjectClass parent;
+};
+
+struct _SlAttribute
+{
+  GObject parent;
+  gboolean disposed;
+  SlAttributePriv *priv;
+};
+
+struct _SlAttributeClass
+{
+  GObjectClass parent;
 };
 
 GType sl_entity_get_type (void);
+GType sl_attribute_get_type (void);
 
-SlEntity *sl_entity_new (void);
-gpointer sl_entity_get (SlEntity *self, const gchar *attrname);
+void sl_entity_install_attribute_handler (const gchar *attrname,
+  SlAttributeHandlerType type, gpointer (*writer)(const gchar *attrname,
+  gpointer value), gpointer (*reader)(const gchar *attrname, gpointer value));
+void sl_entity_remove_attribute_handler (const gchar *attrname);
+
+/*SlEntity *sl_entity_new (SlEntityHandler *entity_handler);*/
+/*SlEntityHandler *sl_entity_get_handler (SlEntity *self);*/
+void sl_entity_constr (SlEntity *self);
+void sl_entity_constr_with_econtact (SlEntity *self, EContact *econtact);
+EContact *sl_entity_get_econtact (SlEntity *self);
+SlAttribute *sl_entity_get_attribute (SlEntity *self, gchar *attrname);
+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,
+  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);
+/* TODO: perhaps gboolean instead of void to indicate that an attrname doesn't
+ * exist */
+
+SlAttribute *sl_attribute_new (const gchar *name);
+void sl_attribute_set (SlAttribute *self, gpointer value);
+gpointer sl_attribute_get (SlAttribute *self);
+void sl_attribute_remove (SlAttribute *self);
+void sl_attribute_set_at (SlAttribute *self, gint index, gpointer value);
+gpointer sl_attribute_get_at (SlAttribute *self, gint index);
+void sl_attribute_remove_at (SlAttribute *self, gint index);
+void sl_attribute_set_values (SlAttribute *self, GList *values);
+GList *sl_attribute_get_values (SlAttribute *self);
+void sl_attribute_remove_values (SlAttribute *self);
+const gchar *sl_attribute_get_name (SlAttribute *self);
 
 #endif

Modified: branches/libsoylent-v0.2.0/libsoylent/sl-group.c
==============================================================================
--- branches/libsoylent-v0.2.0/libsoylent/sl-group.c	(original)
+++ branches/libsoylent-v0.2.0/libsoylent/sl-group.c	Wed Jul 23 09:44:35 2008
@@ -1,4 +1,27 @@
-/**/
+/*
+ * libsoylent - people management
+ * 
+ * Copyright (C) 2008 Sven Pfaller, Noya <kalterregen gmx net>
+ * Copyright (C) 2008 Travis Reitter <treitter-dev netdrain com>
+ * Copyright (C) 2008 Rob Taylor <rob taylor codethink co uk>
+ * Copyright (C) 2008 Chris Lord <chris o-hand com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/* TODO: groups are be ignored atm */
 
 #include "sl-group.h"
 
@@ -9,7 +32,7 @@
   gpointer foo;
 };
 
-GObjectClass *parent_class = NULL;
+static GObjectClass *parent_class = NULL;
 
 static void sl_group_class_init (gpointer g_class, gpointer class_data);
 static void sl_group_init (GTypeInstance *instance, gpointer g_class);

Modified: branches/libsoylent-v0.2.0/libsoylent/sl-group.h
==============================================================================
--- branches/libsoylent-v0.2.0/libsoylent/sl-group.h	(original)
+++ branches/libsoylent-v0.2.0/libsoylent/sl-group.h	Wed Jul 23 09:44:35 2008
@@ -1,4 +1,27 @@
-/**/
+/*
+ * libsoylent - people management
+ * 
+ * Copyright (C) 2008 Sven Pfaller, Noya <kalterregen gmx net>
+ * Copyright (C) 2008 Travis Reitter <treitter-dev netdrain com>
+ * Copyright (C) 2008 Rob Taylor <rob taylor codethink co uk>
+ * Copyright (C) 2008 Chris Lord <chris o-hand com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/* TODO: groups are be ignored atm */
 
 #ifndef SL_GROUP_H
 #define SL_GROUP_H
@@ -9,13 +32,14 @@
 #include <glib-object.h>
 
 #define SL_GROUP_TYPE           (sl_group_get_type ())
-#define SL_GROUP(obj)           (G_TYPE_CHECK_INSTANCE_CAST(obj, \
+#define SL_GROUP(obj)           (G_TYPE_CHECK_INSTANCE_CAST (obj, \
   SL_GROUP_TYPE, SlGroup))
-#define SL_GROUP_CLASS(cls)     (G_TPYE_CHECK_CLASS_CAST(cls, SL_GROUP_TYPE, \
+#define SL_GROUP_CLASS(cls)     (G_TPYE_CHECK_CLASS_CAST (cls, SL_GROUP_TYPE, \
   SlGroupClass))
-#define SL_IS_GROUP(obj)        (G_TYPE_CHECK_INSTANCE_TYPE(obj, SL_GROUP_TYPE))
-#define SL_IS_GROUP_CLASS(cls)  (G_TYPE_CHECK_CLASS_TYPE(cls, SL_GROUP_TYPE))
-#define SL_GROUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS(obj, SL_GROUP_TYPE))
+#define SL_IS_GROUP(obj)        (G_TYPE_CHECK_INSTANCE_TYPE (obj, \
+  SL_GROUP_TYPE))
+#define SL_IS_GROUP_CLASS(cls)  (G_TYPE_CHECK_CLASS_TYPE (cls, SL_GROUP_TYPE))
+#define SL_GROUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS (obj, SL_GROUP_TYPE))
 
 typedef struct _SlGroup       SlGroup;
 typedef struct _SlGroupClass  SlGroupClass;

Modified: branches/libsoylent-v0.2.0/libsoylent/sl-person.c
==============================================================================
--- branches/libsoylent-v0.2.0/libsoylent/sl-person.c	(original)
+++ branches/libsoylent-v0.2.0/libsoylent/sl-person.c	Wed Jul 23 09:44:35 2008
@@ -1,11 +1,129 @@
-//
+/*
+ * libsoylent - people management
+ * 
+ * Copyright (C) 2008 Sven Pfaller, Noya <kalterregen gmx net>
+ * Copyright (C) 2008 Travis Reitter <treitter-dev netdrain com>
+ * Copyright (C) 2008 Rob Taylor <rob taylor codethink co uk>
+ * Copyright (C) 2008 Chris Lord <chris o-hand com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
 
 #include "sl-person.h"
+#include "sl-entity-handler-eds.h"
 
-gint
-sl_person_foo (const gchar *bar)
+/* private structs and fields */
+
+struct _SlPersonPriv
+{
+};
+
+static GObjectClass *parent_class = NULL;
+
+static void sl_person_class_init (gpointer g_class, gpointer class_data);
+static void sl_person_init (GTypeInstance *instance, gpointer g_class);
+static void sl_person_dispose (GObject *object);
+static void sl_person_get_property (GObject *object, guint property_id,
+  GValue *value, GParamSpec *pspec);
+static void sl_person_set_property (GObject *object, guint property_id,
+  const GValue *value, GParamSpec *pspec);
+
+GType
+sl_person_get_type (void)
+{
+  static GType type = 0;
+  static const GTypeInfo info =
+    {
+      sizeof (SlPersonClass),
+      NULL,
+      NULL,
+      sl_person_class_init,
+      NULL,
+      NULL,
+      sizeof (SlPerson),
+      0,
+      sl_person_init,
+      NULL
+    };
+  
+  if (type == 0)
+    {
+      type = g_type_register_static (SL_ENTITY_TYPE, "SlPerson", &info, 0);
+    }
+  return type;
+}
+
+static void
+sl_person_class_init (gpointer g_class, gpointer class_data)
+{
+  parent_class = g_type_class_peek (g_type_parent (SL_PERSON_TYPE));
+  g_assert (parent_class != NULL);
+  
+  GObjectClass *obj_class = G_OBJECT_CLASS (g_class);
+  obj_class->dispose = sl_person_dispose;
+  obj_class->get_property = sl_person_get_property;
+  obj_class->set_property = sl_person_set_property;
+}
+
+static void
+sl_person_init (GTypeInstance *instance, gpointer g_class)
+{
+  SlPerson *self = SL_PERSON (instance);
+  SlPersonPriv *priv = g_new (SlPersonPriv, 1);
+  self->priv = priv;
+  SL_ENTITY (self)->disposed = FALSE;
+}
+
+static void
+sl_person_dispose (GObject *object)
+{
+  SlPerson *self = SL_PERSON (object);
+  g_return_if_fail (!SL_ENTITY (self)->disposed);
+  
+  g_free (self->priv);
+  
+  parent_class->dispose (object);
+}
+
+static void
+sl_person_get_property (GObject *object, guint property_id, GValue *value,
+  GParamSpec *pspec)
+{
+  g_warning("%s not implemented", __FUNCTION__);
+}
+
+static void
+sl_person_set_property (GObject *object, guint property_id, const GValue *value,
+  GParamSpec *pspec)
+{
+  g_warning("%s not implemented", __FUNCTION__);
+}
+
+SlPerson *
+sl_person_new (const gchar *name)
+{
+  SlPerson *self = g_object_new (SL_PERSON_TYPE, NULL);
+  sl_person_constr (self, name);
+  return self;
+}
+
+void
+sl_person_constr (SlPerson *self, const gchar *name)
 {
-	g_return_val_if_fail (bar != NULL, -1);
-	
-	return g_str_hash (bar);
+  sl_entity_constr (SL_ENTITY (self));
+  /* temporary, this will be moved to SlAttributes */
+  EContact *econtact = sl_entity_get_econtact (SL_ENTITY (self));
+  e_contact_set (econtact, E_CONTACT_NICKNAME, (const gpointer) name);
 }

Modified: branches/libsoylent-v0.2.0/libsoylent/sl-person.h
==============================================================================
--- branches/libsoylent-v0.2.0/libsoylent/sl-person.h	(original)
+++ branches/libsoylent-v0.2.0/libsoylent/sl-person.h	Wed Jul 23 09:44:35 2008
@@ -1,11 +1,64 @@
-//
+/*
+ * libsoylent - people management
+ * 
+ * Copyright (C) 2008 Sven Pfaller, Noya <kalterregen gmx net>
+ * Copyright (C) 2008 Travis Reitter <treitter-dev netdrain com>
+ * Copyright (C) 2008 Rob Taylor <rob taylor codethink co uk>
+ * Copyright (C) 2008 Chris Lord <chris o-hand com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
 
 #ifndef SL_PERSON_H
 #define SL_PERSON_H
 
+#include "sl-entity.h"
+
 #include <glib.h>
 #include <glib-object.h>
 
-gint sl_person_foo (const gchar *bar);
+#define SL_PERSON_TYPE            (sl_person_get_type ())
+#define SL_PERSON(obj)            (G_TYPE_CHECK_INSTANCE_CAST (obj, \
+  SL_PERSON_TYPE, SlPerson))
+#define SL_PERSON_CLASS(cls)      (G_TPYE_CHECK_CLASS_CAST (cls, \
+  SL_PERSON_TYPE, SlPersonClass))
+#define SL_IS_PERSON(obj)         (G_TYPE_CHECK_INSTANCE_TYPE (obj, \
+  SL_PERSON_TYPE))
+#define SL_IS_PERSON_CLASS(cls)   (G_TYPE_CHECK_CLASS_TYPE (cls, \
+  SL_PERSON_TYPE))
+#define SL_PERSON_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS (obj, \
+  SL_PERSON_TYPE))
+
+typedef struct _SlPerson      SlPerson;
+typedef struct _SlPersonClass SlPersonClass;
+typedef struct _SlPersonPriv  SlPersonPriv;
+
+struct _SlPerson
+{
+  SlEntity parent;
+  SlPersonPriv *priv;
+};
+
+struct _SlPersonClass
+{
+  SlEntityClass parent;
+};
+
+GType sl_person_get_type (void);
+
+SlPerson *sl_person_new (const gchar *name);
+void sl_person_constr (SlPerson *self, const gchar *name);
 
 #endif

Modified: branches/libsoylent-v0.2.0/libsoylent/sl-priv-util.c
==============================================================================
--- branches/libsoylent-v0.2.0/libsoylent/sl-priv-util.c	(original)
+++ branches/libsoylent-v0.2.0/libsoylent/sl-priv-util.c	Wed Jul 23 09:44:35 2008
@@ -1,7 +1,52 @@
-/**/
+/*
+ * libsoylent - people management
+ * 
+ * Copyright (C) 2008 Sven Pfaller, Noya <kalterregen gmx net>
+ * Copyright (C) 2008 Travis Reitter <treitter-dev netdrain com>
+ * Copyright (C) 2008 Rob Taylor <rob taylor codethink co uk>
+ * Copyright (C) 2008 Chris Lord <chris o-hand com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
 
 #include "sl-priv-util.h"
 
+ESource *
+sl_priv_util_get_source (ESourceList *source_tree, const gchar *name)
+{
+  g_return_val_if_fail (name != NULL, FALSE);
+  
+  GSList *groups = e_source_list_peek_groups (source_tree);
+  for (; groups != NULL; groups = groups->next)
+    {
+      ESourceGroup *group = groups->data;
+      GSList *sources = e_source_group_peek_sources (group);
+      for (; sources != NULL; sources = sources->next)
+        {
+          ESource *source = sources->data;
+          const gchar *source_name = e_source_peek_name (source);
+          if (g_str_equal (name, source_name))
+            {
+              return source;
+            }
+        }
+    }
+    
+  return NULL;
+}
+
 ESourceGroup *
 sl_priv_util_source_tree_get_default_group (ESourceList *source_tree)
 {

Modified: branches/libsoylent-v0.2.0/libsoylent/sl-priv-util.h
==============================================================================
--- branches/libsoylent-v0.2.0/libsoylent/sl-priv-util.h	(original)
+++ branches/libsoylent-v0.2.0/libsoylent/sl-priv-util.h	Wed Jul 23 09:44:35 2008
@@ -1,10 +1,32 @@
-/**/
+/*
+ * libsoylent - people management
+ * 
+ * Copyright (C) 2008 Sven Pfaller, Noya <kalterregen gmx net>
+ * Copyright (C) 2008 Travis Reitter <treitter-dev netdrain com>
+ * Copyright (C) 2008 Rob Taylor <rob taylor codethink co uk>
+ * Copyright (C) 2008 Chris Lord <chris o-hand com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
 
 #ifndef SL_PRIVUTIL_H
 #define SL_PRIVUTIL_H
 
 #include <libebook/e-book.h>
 
+ESource *sl_priv_util_get_source (ESourceList *source_tree, const gchar *name);
 ESourceGroup *sl_priv_util_source_tree_get_default_group
   (ESourceList *source_tree);
 

Modified: branches/libsoylent-v0.2.0/libsoylent/soylent.c
==============================================================================
--- branches/libsoylent-v0.2.0/libsoylent/soylent.c	(original)
+++ branches/libsoylent-v0.2.0/libsoylent/soylent.c	Wed Jul 23 09:44:35 2008
@@ -1,13 +1,34 @@
-/**/
+/*
+ * libsoylent - people management
+ * 
+ * Copyright (C) 2008 Sven Pfaller, Noya <kalterregen gmx net>
+ * Copyright (C) 2008 Travis Reitter <treitter-dev netdrain com>
+ * Copyright (C) 2008 Rob Taylor <rob taylor codethink co uk>
+ * Copyright (C) 2008 Chris Lord <chris o-hand com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
 
 #include "config.h"
 #include "soylent.h"
 
 #include <glib-object.h>
 
-void
-sl_init (void)
+gboolean
+sl_init (GError **error)
 {
 	g_type_init ();
-	sl_book_setup ();
+	return sl_book_setup (error);
 }

Modified: branches/libsoylent-v0.2.0/libsoylent/soylent.h
==============================================================================
--- branches/libsoylent-v0.2.0/libsoylent/soylent.h	(original)
+++ branches/libsoylent-v0.2.0/libsoylent/soylent.h	Wed Jul 23 09:44:35 2008
@@ -1,12 +1,37 @@
-/**/
+/*
+ * libsoylent - people management
+ * 
+ * Copyright (C) 2008 Sven Pfaller, Noya <kalterregen gmx net>
+ * Copyright (C) 2008 Travis Reitter <treitter-dev netdrain com>
+ * Copyright (C) 2008 Rob Taylor <rob taylor codethink co uk>
+ * Copyright (C) 2008 Chris Lord <chris o-hand com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
 
 #ifndef SOYLENT_H
 #define SOYLENT_H
 
 #include "sl-entity.h"
+#include "sl-entity-handler.h"
+#include "sl-entity-handler-eds.h"
+#include "sl-entity-handler-file.h"
 #include "sl-person.h"
+#include "sl-group.h"
 #include "sl-book.h"
 
-void sl_init (void);
+gboolean sl_init (GError **error);
 
 #endif

Modified: branches/libsoylent-v0.2.0/libsoylent/test/init.c
==============================================================================
--- branches/libsoylent-v0.2.0/libsoylent/test/init.c	(original)
+++ branches/libsoylent-v0.2.0/libsoylent/test/init.c	Wed Jul 23 09:44:35 2008
@@ -1,4 +1,25 @@
-/**/
+/*
+ * libsoylent - people management
+ * 
+ * Copyright (C) 2008 Sven Pfaller, Noya <kalterregen gmx net>
+ * Copyright (C) 2008 Travis Reitter <treitter-dev netdrain com>
+ * Copyright (C) 2008 Rob Taylor <rob taylor codethink co uk>
+ * Copyright (C) 2008 Chris Lord <chris o-hand com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
 
 #include "test.h"
 

Modified: branches/libsoylent-v0.2.0/libsoylent/test/test-book.c
==============================================================================
--- branches/libsoylent-v0.2.0/libsoylent/test/test-book.c	(original)
+++ branches/libsoylent-v0.2.0/libsoylent/test/test-book.c	Wed Jul 23 09:44:35 2008
@@ -1,22 +1,50 @@
-/**/
+/*
+ * libsoylent - people management
+ * 
+ * Copyright (C) 2008 Sven Pfaller, Noya <kalterregen gmx net>
+ * Copyright (C) 2008 Travis Reitter <treitter-dev netdrain com>
+ * Copyright (C) 2008 Rob Taylor <rob taylor codethink co uk>
+ * Copyright (C) 2008 Chris Lord <chris o-hand com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
 
 #include "test.h"
 
+static void print_books (GList *books);
+
 int
 main (int argc, char **argv)
 {
   GError *error = NULL;
+  const gchar *testbookname = "testbook";
+  const gchar *testbookname_wrong = "testbook23";
   
   test_init ("Book");
   
-  sl_book_get_books ();
-  
-  test_print ("creating addressbook krank\n");
-  if (!sl_book_create ("krank", &error)) {
-    test_fail("%s", error->message);
+  GList *books = sl_book_get_books ();
+  gint book_count = g_list_length (books);
+  test_print ("%d book(s) already exist(s)", book_count);
+  g_list_free (books);
+  
+  test_print ("creating addressbook \"%s\"", testbookname);
+  if (!sl_book_create (testbookname, &error)) {
+    test_fail("couldn't create addressbook: %s", error->message);
   }
   
-  SlBook *book = sl_book_create ("krank", &error);
+  SlBook *book = sl_book_create (testbookname, &error);
   if (book)
     {
       test_fail("created book with same name twice");
@@ -25,11 +53,103 @@
     {
       if (error->code != SL_BOOK_ERROR_ALREADY_EXISTS)
         {
-          test_fail("unexpected error: %s", error->message);
+          test_fail ("unexpected error: %s", error->message);
         }
+      g_clear_error (&error);
     }
   
-  sl_book_get_books ();
+  if (!sl_book_exists (testbookname))
+    {
+      test_fail ("created addressbook, but it doesn't seem to exist");
+    }
+  
+  books = sl_book_get_books ();
+  print_books (books);
+  if (g_list_length (books) != book_count + 1)
+    {
+      test_fail ("new addressbook not in list of addressbooks");
+    }
+  book_count = g_list_length (books);
+  g_list_free (books);
+  
+  test_print ("opening addressbook");
+  if (!sl_book_open (testbookname, &error))
+    {
+      test_fail ("couldn't open addressbook: %s", error->message);
+    }
+  
+  if (!sl_book_open (testbookname_wrong, &error))
+    {
+      if (error->code != SL_BOOK_ERROR_NOT_EXISTING)
+        {
+          test_fail ("unexpected error: %s", error->message);
+        }
+      g_clear_error (&error);
+    }
+  else
+    {
+      test_fail ("opening a non-existant addressbook succeded");
+    }
+  
+  test_print ("deleting addressbook again");
+  if (!sl_book_delete (testbookname, &error))
+    {
+      test_fail ("couldn't delete addressbook: %s", error->message);
+    }
+    
+  books = sl_book_get_books ();
+  print_books (books);
+  if (g_list_length (books) != book_count - 1)
+    {
+      /* TODO:
+       * there seems to be a synchronizing problem here: sometimes the list
+       * still contains the deleted addressbook, sometimes it does not...
+       * needs further investigation
+       */
+      /* test_fail ("deleted addressbook is still in list of addressbooks"); */
+      g_warning ("deleted addressbook is still in list of addressbooks");
+    }
+  book_count = g_list_length (books);
+  g_list_free (books);
+  
+  if (sl_book_exists (testbookname))
+    {
+      /*test_fail ("addressbook deleted, but it seems to still exist");*/
+      g_warning ("addressbook deleted, but it seems to still exist");
+    }
+  
+  if (!sl_book_exists (testbookname_wrong))
+    {
+      if (!sl_book_delete (testbookname_wrong, &error))
+        {
+          if (error->code != SL_BOOK_ERROR_NOT_EXISTING)
+            {
+              test_print ("unexpected error: %s", error->message);
+            }
+          g_clear_error (&error);
+        }
+      else
+        {
+          test_fail ("deleting a non-existant addressbook succeded");
+        }
+    }
+  else
+    {
+      test_print ("skipping addressbook-deletion-error-test because an \
+addressbook \"%s\" exists", testbookname_wrong);
+    }
   
   test_success ();
 }
+
+static
+void print_books (GList *books)
+{
+  test_print ("addressbooks:");
+  GList *books_iter = books;
+  for (; books_iter != NULL; books_iter = books_iter->next)
+    {
+      gchar *book = books_iter->data;
+      test_print (" * %s", book);
+    }
+}

Modified: branches/libsoylent-v0.2.0/libsoylent/test/test-playground.c
==============================================================================
--- branches/libsoylent-v0.2.0/libsoylent/test/test-playground.c	(original)
+++ branches/libsoylent-v0.2.0/libsoylent/test/test-playground.c	Wed Jul 23 09:44:35 2008
@@ -1,17 +1,71 @@
-/**/
+/*
+ * libsoylent - people management
+ * 
+ * Copyright (C) 2008 Sven Pfaller, Noya <kalterregen gmx net>
+ * Copyright (C) 2008 Travis Reitter <treitter-dev netdrain com>
+ * Copyright (C) 2008 Rob Taylor <rob taylor codethink co uk>
+ * Copyright (C) 2008 Chris Lord <chris o-hand com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
 
 #include "test.h"
 
 int
 main (int argc, char **argv)
 {
-  test_init ("Playground");
+  GError *error = NULL;
   
+  test_init ("Playground");
   test_soylent_init ();
   
-  test_print ("foo\n");
+  /* known bug 3 forces us to use the system-addressbook, but we don't want
+   to modify it, so just skip this test */
+  test_success ();
+  
+  SlBook *testbook = test_setup_testbook ();
+  
+  test_print ("creating some people");
+  SlPerson *person_tim = sl_person_new ("Tim");
+  SlPerson *person_joe = sl_person_new ("Joe");
+  
+  test_print ("adding \"Tim\" and \"Joe\" to the addressbook");
+  if (!sl_book_add_person (testbook, person_tim, &error) ||
+      !sl_book_add_person (testbook, person_joe, &error))
+    {
+      test_fail ("couldn't add person to addressbook: %s", error->message);
+    }
+  
+  test_print ("removing \"Tim\" from the addressbook again");
+  if (!sl_book_remove_person (testbook, person_tim, &error))
+    {
+      test_fail ("couldn't remove person from addressbook: %s", error->message);
+    }
+  
+  g_object_unref (person_tim);
+  g_object_unref (person_joe);
+  
+  test_clean_testbook (testbook);
+  
+  /*test_print ("foo\n");
   SlEntity *entity = sl_entity_new ();
-  g_print ("%s\n", (gchar *) sl_entity_get (entity, "x"));
+  test_print ("%s\n", (gchar *) sl_entity_get (entity, "x"));
+  
+  SlEntityHandlerEDS *entity_handler = sl_entity_handler_eds_new ();
+  sl_entity_handler_eds_get (entity_handler, "foo");
+  sl_entity_handler_get (SL_ENTITY_HANDLER (entity_handler), "foo");*/
   
   test_success ();
 }

Modified: branches/libsoylent-v0.2.0/libsoylent/test/test.c
==============================================================================
--- branches/libsoylent-v0.2.0/libsoylent/test/test.c	(original)
+++ branches/libsoylent-v0.2.0/libsoylent/test/test.c	Wed Jul 23 09:44:35 2008
@@ -1,4 +1,25 @@
-/**/
+/*
+ * libsoylent - people management
+ * 
+ * Copyright (C) 2008 Sven Pfaller, Noya <kalterregen gmx net>
+ * Copyright (C) 2008 Travis Reitter <treitter-dev netdrain com>
+ * Copyright (C) 2008 Rob Taylor <rob taylor codethink co uk>
+ * Copyright (C) 2008 Chris Lord <chris o-hand com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
 
 #include "config.h"
 #include "test.h"
@@ -6,5 +27,40 @@
 void
 test_soylent_init (void)
 {
-  sl_init ();
+  GError *error = NULL;
+  if (!sl_init (&error))
+    {
+      /* TODO: quit test here... */
+      g_warning ("failed to initialize libsoylent");
+    }
+}
+
+SlBook *
+test_setup_testbook (void)
+{
+  GError *error = NULL;
+  /*const gchar *testbookname = "testbook";
+  SlBook *testbook = sl_book_create (testbookname, &error);*/
+  /* workaround for known bug 3 */
+  SlBook *testbook = sl_book_open_default (&error);
+  if (testbook == NULL)
+    {
+      /* TODO: quit test here...*/
+      g_warning ("couldn't create addressbook: %s", error->message);
+    }
+  return testbook;
+}
+
+void 
+test_clean_testbook (SlBook *testbook)
+{
+  /* workaround for known bug 3: do nothing */
+  return;
+  GError *error = NULL;
+  if (!sl_book_delete ("testbook", &error))
+    {
+      /* TODO: quit test here...*/
+      g_warning ("couldn't delete addressbook: %s", error->message);
+    }
+  g_object_unref (testbook);
 }

Modified: branches/libsoylent-v0.2.0/libsoylent/test/test.h
==============================================================================
--- branches/libsoylent-v0.2.0/libsoylent/test/test.h	(original)
+++ branches/libsoylent-v0.2.0/libsoylent/test/test.h	Wed Jul 23 09:44:35 2008
@@ -1,4 +1,25 @@
-/**/
+/*
+ * libsoylent - people management
+ * 
+ * Copyright (C) 2008 Sven Pfaller, Noya <kalterregen gmx net>
+ * Copyright (C) 2008 Travis Reitter <treitter-dev netdrain com>
+ * Copyright (C) 2008 Rob Taylor <rob taylor codethink co uk>
+ * Copyright (C) 2008 Chris Lord <chris o-hand com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
 
 #ifndef TEST_H
 #define TEST_H
@@ -7,6 +28,7 @@
 #include <stdlib.h>
 #include <libsoylent/soylent.h>
 
+/* TODO: would this work without multiple g_prints? */
 #define test_init(name) test_name = name; \
                         g_print ("running test %s...\n", test_name)
 #define test_success()  g_print ("test %s succeded\n", test_name); \
@@ -16,10 +38,13 @@
                         g_print ("\n"); \
                         return EXIT_FAILURE
 #define test_print(...) g_print ("  "); \
-                        g_print (__VA_ARGS__)
+                        g_print (__VA_ARGS__); \
+                        g_print ("\n")
 
 const gchar *test_name;
 
 void test_soylent_init (void);
+SlBook *test_setup_testbook (void);
+void test_clean_testbook (SlBook *testbook);
 
 #endif



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