soylent r272 - trunk/libsoylent



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

Log:
added attribute-types name and address
added more convinience methods to SlPerson
documented all well-known attributes

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

Modified: trunk/libsoylent/sl-person.c
==============================================================================
--- trunk/libsoylent/sl-person.c	(original)
+++ trunk/libsoylent/sl-person.c	Mon Aug 11 21:50:12 2008
@@ -21,8 +21,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "sl-person.h"
-#include "sl-entity-eds.h"
+#include "sl-mutual-inclusion.h"
 
 /* private structs and fields */
 
@@ -111,11 +110,34 @@
   g_warning("%s not implemented", __FUNCTION__);
 }
 
+SlName *sl_name_new (void)
+{
+  SlName *name = g_new (SlName, 1);
+  name->names = NULL;
+  name->family_name = "";
+  name->honoric_prefixes = NULL;
+  name->honoric_suffixes = NULL;
+  return name;
+}
+
+SlAddress *sl_address_new (void)
+{
+  SlAddress *address = g_new (SlAddress, 1);
+  address->country = "";
+  address->region = "";
+  address->city = "";
+  address->street = "";
+  address->postal_code = "";
+  address->addition = "";
+  address->po_box = "";
+  return address;
+}
+
 SlPerson *
-sl_person_new (const gchar *name)
+sl_person_new (const gchar *name, const gchar *family_name)
 {
   SlPerson *self = g_object_new (SL_PERSON_TYPE, NULL);
-  sl_person_constr (self, name);
+  sl_person_constr (self, name, family_name);
   return self;
 }
 
@@ -128,10 +150,13 @@
 }
 
 void
-sl_person_constr (SlPerson *self, const gchar *name)
+sl_person_constr (SlPerson *self, const gchar *name, const gchar *family_name)
 {
   sl_entity_constr (SL_ENTITY (self));
-  sl_person_set_nick (self, (gchar *) name);
+  SlName *n = sl_name_new ();
+  n->names = g_list_append (NULL, (gchar *) name);
+  n->family_name = (gchar *) family_name;
+  sl_person_set (self, SL_ATTR_NAME, n);
 }
 
 void
@@ -141,9 +166,60 @@
 }
 
 gchar *
+sl_person_get_name (SlPerson *self)
+{
+  SlName *name = sl_person_get (self, SL_ATTR_NAME);
+  return g_list_nth_data (name->names, 0);
+}
+
+void
+sl_person_set_name (SlPerson *self, gchar *name)
+{
+  SlAttribute *attr_name = sl_person_get_attribute (self, SL_ATTR_NAME);
+  SlName *n = sl_attribute_get (attr_name);
+  if (n->names == NULL)
+    {
+      n->names = g_list_append (n->names, name);
+    }
+  else
+    {
+      /* TODO: does this leak? */
+      n->names->data = name;
+    }
+  sl_attribute_modified (attr_name);
+}
+
+gchar *
+sl_person_get_family_name (SlPerson *self)
+{
+  SlName *name = sl_person_get (self, SL_ATTR_NAME);
+  return name->family_name;
+}
+
+void
+sl_person_set_family_name (SlPerson *self, gchar *family_name)
+{
+  SlAttribute *attr_name = sl_person_get_attribute (self, SL_ATTR_NAME);
+  SlName *n = sl_attribute_get (attr_name);
+  n->family_name = family_name;
+  sl_attribute_modified (attr_name);
+}
+
+gchar *
+sl_person_get_full_name (SlPerson *self)
+{
+  return sl_person_get (self, SL_ATTR_FULL_NAME);
+}
+
+void
+sl_person_set_full_name (SlPerson *self, gchar *fullname)
+{
+  sl_person_set (self, SL_ATTR_FULL_NAME, fullname);
+}
+
+gchar *
 sl_person_get_nick (SlPerson *self)
 {
-  /* TODO: create attrname -> internal_attrname mapping */
   return sl_person_get (self, SL_ATTR_NICK);
 }
 

Modified: trunk/libsoylent/sl-person.h
==============================================================================
--- trunk/libsoylent/sl-person.h	(original)
+++ trunk/libsoylent/sl-person.h	Mon Aug 11 21:50:12 2008
@@ -24,7 +24,7 @@
 #ifndef SL_PERSON_H
 #define SL_PERSON_H
 
-#include "sl-entity-eds.h"
+#include "sl-mutual-inclusion.h"
 
 #include <glib.h>
 #include <glib-object.h>
@@ -42,22 +42,153 @@
   SL_PERSON_TYPE))
 
 /* well-known attributes */
-#define SL_ATTR_ID            "id"
-#define SL_ATTR_NAME          "name"
-#define SL_ATTR_FAMILY_NAME   "family-name"
-#define SL_ATTR_NICK          "nick"
-#define SL_ATTR_GROUP         "group"
-#define SL_ATTR_ADDRESS       "address"
-#define SL_ATTR_EMAIL         "email"
-#define SL_ATTR_TELEPHONE     "telephone"
-#define SL_ATTR_BIRTHDAY      "birthday"
-#define SL_ATTR_URL           "url"
-#define SL_ATTR_BLOG          "blog"
-#define SL_ATTR_CALENDAR_URL  "calendar-url"
+
+/**
+ * SL_ATTR_ID:
+ *
+ * Unique ID of a person.
+ *
+ * type: <type>string</type>
+ */
+#define SL_ATTR_ID "id"
+
+/**
+ * SL_ATTR_NAME:
+ *
+ * A structured name of a person (names, family-name etc.). For a
+ * more convinient way to handle a persons name see the sl_person_get/set_name*
+ * methods.
+ *
+ * type: #SlName
+ */
+#define SL_ATTR_NAME "name"
+
+/**
+ * SL_ATTR_FULL_NAME:
+ *
+ * A string representing the full, printable name of a person.
+ *
+ * type: <type>string</type>
+ */
+#define SL_ATTR_FULL_NAME "full-name"
+
+/**
+ * SL_ATTR_NICK:
+ *
+ * The nickname of a person.
+ *
+ * type: <type>string</type>
+ */
+#define SL_ATTR_NICK "nick"
+
+/**
+ * SL_ATTR_GROUP:
+ *
+ * A list of groups a person is in.
+ *
+ * type: #GList <type>(string)</type>
+ */
+#define SL_ATTR_GROUP "group"
+
+/**
+ * SL_ATTR_ADDRESS:
+ *
+ * An (postal) address of a person.
+ *
+ * type: #SlAddress
+ */
+#define SL_ATTR_ADDRESS "address"
+
+/**
+ * SL_ATTR_EMAIL:
+ *
+ * An email-address of a person.
+ *
+ * type: <type>string</type>
+ */
+#define SL_ATTR_EMAIL "email"
+
+/**
+ * SL_ATTR_TELEPHONE:
+ *
+ * A telephone-number of a person.
+ *
+ * type: <type>string</type>
+ */
+#define SL_ATTR_TELEPHONE "telephone"
+
+/**
+ * SL_ATTR_BIRTHDAY:
+ *
+ * The birthday of a person.
+ *
+ * type: #GDate
+ */
+#define SL_ATTR_BIRTHDAY "birthday"
+
+/**
+ * SL_ATTR_URL:
+ *
+ * An URL of a person. This typically represents something like a homepage.
+ *
+ * type: <type>string</type>
+ */
+#define SL_ATTR_URL "url"
+
+/**
+ * SL_ATTR_BLOG:
+ *
+ * The blog-URL of a person.
+ *
+ * type: <type>string</type>
+ */
+#define SL_ATTR_BLOG "blog"
+
+/**
+ * SL_ATTR_CALENDAR_URL:
+ *
+ * An URL pointing to where a calendar of a person is located.
+ *
+ * type: <type>string</type>
+ */
+#define SL_ATTR_CALENDAR_URL "calendar-url"
+
+/**
+ * SL_ATTR_FREE_BUSY_URL:
+ *
+ * An URL pointing to where free-busy-information of a person is located.
+ *
+ * type: <type>string</type>
+ */
 #define SL_ATTR_FREE_BUSY_URL "free-busy-url"
-#define SL_ATTR_NOTE          "note"
-#define SL_ATTR_PHOTO         "photo"
-#define SL_ATTR_ICON          "icon"
+
+/**
+ * SL_ATTR_NOTE:
+ *
+ * A note attached to a person.
+ *
+ * type: <type>string</type>
+ */
+#define SL_ATTR_NOTE "note"
+
+/**
+ * SL_ATTR_PHOTO:
+ *
+ * A photo of a person.
+ *
+ * type: #GByteArray
+ */
+#define SL_ATTR_PHOTO "photo"
+
+/**
+ * SL_ATTR_ICON:
+ *
+ * An icon of a person.
+ *
+ * type: #GByteArray
+ */
+#define SL_ATTR_ICON "icon"
+
 /* TODO: job struct? */
 #define SL_ATTR_JOB_ROLE      "job-role"
 #define SL_ATTR_JOB_TITLE     "job-title"
@@ -108,29 +239,57 @@
 #define EVC_X_VIDEO_URL     	"X-EVOLUTION-VIDEO-URL"*/
 
 
+  
+void sl_entity_add_attribute (SlEntity *self, SlAttribute *attr);
+void sl_entity_remove_attribute (SlEntity *self, SlAttribute *attr);
 
-#define sl_person_get(self, attrname)         (sl_entity_get ( \
-                                               SL_ENTITY (self), attrname))
-#define sl_person_set(self, attrname, value)  (sl_entity_set ( \
-  SL_ENTITY (self), attrname, value))
-
-#define sl_person_commit(self, error)         (sl_entity_commit ( \
-                                               SL_ENTITY (self), error))
-
-#define sl_person_add_attribute(self, attr)     (sl_entity_add_attribute ( \
-  SL_ENTITY (self), attr))
-#define sl_person_remove_attribute(self, attr)  (sl_entity_remove_attribute ( \
-  SL_ENTITY (self), attr))
-#define sl_person_get_attribute(self, attrname) (sl_entity_get_attribute ( \
-  SL_ENTITY (self), attrname))
-#define sl_person_get_attributes(self)          (sl_entity_get_attributes ( \
-  SL_ENTITY (self)))
+SlAttribute *sl_entity_get_attribute (SlEntity *self, const gchar *attrname);
+GList *sl_entity_get_attributes (SlEntity *self);
+  
+#define sl_person_get_book(self) \
+  (sl_entity_get_storage (SL_ENTITY (self)))
+#define sl_person_commit(self, error) \
+  (sl_entity_commit (SL_ENTITY (self), error))
+
+#define sl_person_add_attribute(self, attr) \
+  (sl_entity_add_attribute (SL_ENTITY (self), attr))
+#define sl_person_remove_attribute(self, attr)  \
+  (sl_entity_remove_attribute (SL_ENTITY (self), attr))
+#define sl_person_has_attribute(self, attrname) \
+  (sl_entity_has_attribute (SL_ENTITY (self), attrname))
+#define sl_person_get_attribute(self, attrname) \
+  (sl_entity_get_attribute (SL_ENTITY (self), attrname))
+#define sl_person_get_attributes(self) \
+  (sl_entity_get_attributes (SL_ENTITY (self)))
   
-typedef struct _SlPerson      SlPerson;
+#define sl_person_add(self, attrname, value) \
+  (sl_entity_add (SL_ENTITY (self), attrname, value))
+#define sl_person_get(self, attrname) \
+  (sl_entity_get (SL_ENTITY (self), attrname))
+#define sl_person_set(self, attrname, value) \
+  (sl_entity_set (SL_ENTITY (self), attrname, value))
+#define sl_person_get_at(self, attrname, index) \
+  (gpointer sl_entity_get_at (SL_ENTITY (self) attrname, index))
+#define sl_person_set_at(self, attrname, index, value) \
+  (sl_entity_set_at (SL_ENTITY (self), attrname, index, value))
+#define sl_person_remove_at(self, attrname, index) \
+  (sl_entity_remove_at (SL_ENTITY (self), attrname, index))
+#define sl_person_set_all(self, attrname, values) \
+  (sl_entity_set_all (SL_ENTITY (self), attrname, values))
+#define sl_person_get_all(self, attrname) \
+  (sl_entity_get_all (SL_ENTITY (self), attrname))
+#define sl_person_remove_all(self, attrname) \
+  (sl_entity_remove_all (SL_ENTITY (self), attrname))
+#define sl_person_modified(self, attrname) \
+  (sl_entity_modified (SL_ENTITY (self), attrname))
+#define sl_person_modified_at(self, attrname, index) \
+  (sl_entity_modified_at (SL_ENTITY (self), attrname, index))
+
 typedef struct _SlPersonClass SlPersonClass;
 typedef struct _SlPersonPriv  SlPersonPriv;
   
 typedef struct _SlAddress SlAddress;
+typedef struct _SlName    SlName;
 
 struct _SlPerson
 {
@@ -154,13 +313,40 @@
   gchar *po_box;
 };
 
+/**
+ * SlName:
+ * @names: string-list of given names
+ * @family_name: the family name
+ * @honoric_prefixes: string-list of honoric prefixes (e.g. Dr.)
+ * @honoric_suffixes: string-list of honoric suffixes (e.g. Jr.)
+ *
+ * A structured representation of a name.
+ */
+struct _SlName
+{
+  GList *names;
+  gchar *family_name;
+  GList *honoric_prefixes;
+  GList *honoric_suffixes;
+};
+
 GType sl_person_get_type (void);
 
-SlPerson *sl_person_new (const gchar *name);
+SlAddress *sl_address_new (void);
+SlName *sl_name_new (void);
+
+SlPerson *sl_person_new (const gchar *name, const gchar *family_name);
 SlPerson *sl_person_new_with_econtact (EContact *econtact);
-void sl_person_constr (SlPerson *self, const gchar *name);
+void sl_person_constr (SlPerson *self, const gchar *name, const gchar *family_name);
 void sl_person_constr_with_econtact (SlPerson *self, EContact *econtact);
 
+gchar *sl_person_get_name (SlPerson *self);
+void sl_person_set_name (SlPerson *self, gchar *name);
+gchar *sl_person_get_family_name (SlPerson *self);
+void sl_person_set_family_name (SlPerson *self, gchar *family_name);
+gchar *sl_person_get_full_name (SlPerson *self);
+void sl_person_set_full_name (SlPerson *self, gchar *fullname);
+
 gchar *sl_person_get_nick (SlPerson *self);
 void sl_person_set_nick (SlPerson *self, gchar *nick);
 



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