soylent r257 - in trunk/libsoylent: . example
- From: svenp svn gnome org
- To: svn-commits-list gnome org
- Subject: soylent r257 - in trunk/libsoylent: . example
- Date: Thu, 31 Jul 2008 11:20:52 +0000 (UTC)
Author: svenp
Date: Thu Jul 31 11:20:52 2008
New Revision: 257
URL: http://svn.gnome.org/viewvc/soylent?rev=257&view=rev
Log:
adjusted code to new (simplified) architecture (basically that means sl-entity-eds was splitted in sl-entity-eds, sl-attribute and sl-attributes)
Modified:
trunk/libsoylent/example/example.c
trunk/libsoylent/sl-attribute-eds.c
trunk/libsoylent/sl-attribute-eds.h
trunk/libsoylent/sl-attribute.c
trunk/libsoylent/sl-attribute.h
trunk/libsoylent/sl-attributes.c
trunk/libsoylent/sl-attributes.h
trunk/libsoylent/sl-book.c
trunk/libsoylent/sl-entity-eds.c
trunk/libsoylent/sl-entity-eds.h
trunk/libsoylent/sl-entity.c
trunk/libsoylent/sl-entity.h
trunk/libsoylent/sl-group.h
trunk/libsoylent/sl-person.c
trunk/libsoylent/sl-person.h
trunk/libsoylent/sl-priv-util.h
trunk/libsoylent/soylent.h
Modified: trunk/libsoylent/example/example.c
==============================================================================
--- trunk/libsoylent/example/example.c (original)
+++ trunk/libsoylent/example/example.c Thu Jul 31 11:20:52 2008
@@ -40,9 +40,9 @@
* one function at once. Be aware that the examples modify the default
* addressbook. */
- /*list ();*/
+ list ();
- create_person ();
+ /*create_person ();*/
return EXIT_SUCCESS;
}
Modified: trunk/libsoylent/sl-attribute-eds.c
==============================================================================
--- trunk/libsoylent/sl-attribute-eds.c (original)
+++ trunk/libsoylent/sl-attribute-eds.c Thu Jul 31 11:20:52 2008
@@ -20,3 +20,362 @@
* 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-attribute-eds.h"
+#include "sl-person.h"
+#include "sl-attributes.h"
+
+struct _SlAttributePriv
+{
+ SlEntity *entity;
+ const gchar *name;
+ GList *values;
+ EVCardAttribute *eattr;
+};
+
+static GObjectClass *attribute_parent_class = NULL;
+
+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);
+
+static const gchar *sl_attribute_name_to_eattrname (const gchar *name);
+static const gchar *sl_attribute_eattrname_to_name (const gchar *eattrname);
+
+GType
+sl_attribute_get_type (void)
+{
+ 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;
+}
+
+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__);
+}
+
+static const gchar *
+sl_attribute_name_to_eattrname (const gchar *name)
+{
+ static GHashTable *name_to_eattrname_map = NULL;
+ if (name_to_eattrname_map == NULL)
+ {
+ name_to_eattrname_map = g_hash_table_new (g_str_hash, g_str_equal);
+ g_hash_table_insert (name_to_eattrname_map, SL_ATTR_ID, EVC_UID);
+ g_hash_table_insert (name_to_eattrname_map, SL_ATTR_NAME, EVC_N);
+ g_hash_table_insert (name_to_eattrname_map, SL_ATTR_FAMILY_NAME, EVC_FN);
+ g_hash_table_insert (name_to_eattrname_map, SL_ATTR_NICK, EVC_NICKNAME);
+ g_hash_table_insert (name_to_eattrname_map, SL_ATTR_GROUP, EVC_CATEGORIES);
+ g_hash_table_insert (name_to_eattrname_map, SL_ATTR_ADDRESS, EVC_ADR);
+ g_hash_table_insert (name_to_eattrname_map, SL_ATTR_EMAIL, EVC_EMAIL);
+ g_hash_table_insert (name_to_eattrname_map, SL_ATTR_TELEPHONE, EVC_TEL);
+ g_hash_table_insert (name_to_eattrname_map, SL_ATTR_BIRTHDAY, EVC_BDAY);
+ g_hash_table_insert (name_to_eattrname_map, SL_ATTR_URL, EVC_URL);
+ g_hash_table_insert (name_to_eattrname_map, SL_ATTR_BLOG, EVC_X_BLOG_URL);
+ g_hash_table_insert (name_to_eattrname_map, SL_ATTR_CALENDAR_URL, EVC_CALURI);
+ g_hash_table_insert (name_to_eattrname_map, SL_ATTR_FREE_BUSY_URL, EVC_FBURL);
+ g_hash_table_insert (name_to_eattrname_map, SL_ATTR_NOTE, EVC_NOTE);
+ g_hash_table_insert (name_to_eattrname_map, SL_ATTR_PHOTO, EVC_PHOTO);
+ g_hash_table_insert (name_to_eattrname_map, SL_ATTR_ICON, EVC_LOGO);
+ g_hash_table_insert (name_to_eattrname_map, SL_ATTR_JOB_ROLE, EVC_ROLE);
+ g_hash_table_insert (name_to_eattrname_map, SL_ATTR_JOB_TITLE, EVC_TITLE);
+ }
+
+ const gchar *eattrname = g_hash_table_lookup (name_to_eattrname_map, name);
+ if (eattrname == NULL)
+ {
+ GString *str = g_string_new (NULL);
+ g_string_printf (str, "X-%s", name);
+ eattrname = str->str;
+ }
+ return eattrname;
+}
+
+static const gchar *
+sl_attribute_eattrname_to_name (const gchar *eattrname)
+{
+ static GHashTable *eattrname_to_name_map = NULL;
+ if (eattrname_to_name_map == NULL)
+ {
+ eattrname_to_name_map = g_hash_table_new (g_str_hash, g_str_equal);
+ g_hash_table_insert (eattrname_to_name_map, EVC_UID, SL_ATTR_ID);
+ g_hash_table_insert (eattrname_to_name_map, EVC_N, SL_ATTR_NAME);
+ g_hash_table_insert (eattrname_to_name_map, EVC_FN, SL_ATTR_FAMILY_NAME);
+ g_hash_table_insert (eattrname_to_name_map, EVC_NICKNAME, SL_ATTR_NICK);
+ g_hash_table_insert (eattrname_to_name_map, EVC_CATEGORIES, SL_ATTR_GROUP);
+ g_hash_table_insert (eattrname_to_name_map, EVC_ADR, SL_ATTR_ADDRESS);
+ g_hash_table_insert (eattrname_to_name_map, EVC_EMAIL, SL_ATTR_EMAIL);
+ g_hash_table_insert (eattrname_to_name_map, EVC_TEL, SL_ATTR_TELEPHONE);
+ g_hash_table_insert (eattrname_to_name_map, EVC_BDAY, SL_ATTR_BIRTHDAY);
+ g_hash_table_insert (eattrname_to_name_map, EVC_URL, SL_ATTR_URL);
+ g_hash_table_insert (eattrname_to_name_map, EVC_X_BLOG_URL, SL_ATTR_BLOG);
+ g_hash_table_insert (eattrname_to_name_map, EVC_CALURI, SL_ATTR_CALENDAR_URL);
+ g_hash_table_insert (eattrname_to_name_map, EVC_FBURL, SL_ATTR_FREE_BUSY_URL);
+ g_hash_table_insert (eattrname_to_name_map, EVC_NOTE, SL_ATTR_NOTE);
+ g_hash_table_insert (eattrname_to_name_map, EVC_PHOTO, SL_ATTR_PHOTO);
+ g_hash_table_insert (eattrname_to_name_map, EVC_LOGO, SL_ATTR_ICON);
+ g_hash_table_insert (eattrname_to_name_map, EVC_ROLE, SL_ATTR_JOB_ROLE);
+ g_hash_table_insert (eattrname_to_name_map, EVC_TITLE, SL_ATTR_JOB_TITLE);
+ }
+
+ const gchar *name = g_hash_table_lookup (eattrname_to_name_map, eattrname);
+ if (name == NULL)
+ {
+ /* TODO: this leaks, cause name must be freed somehow */
+ g_assert (g_str_has_prefix (eattrname, "X-"));
+ name = g_utf8_strdown (&eattrname[2], -1);
+ }
+ return name;
+}
+
+void
+sl_attribute_constr (SlAttribute *self, const gchar *name, gpointer value)
+{
+ self->priv->entity = NULL;
+ self->priv->name = name;
+ self->priv->eattr = e_vcard_attribute_new (NULL, sl_attribute_name_to_eattrname (name));
+ self->priv->values = NULL;
+ if (value != NULL)
+ {
+ self->priv->values = g_list_append (self->priv->values, value);
+ }
+}
+
+void
+sl_attribute_constr_with_values (SlAttribute *self, const gchar *name,
+ GList *values)
+{
+ sl_attribute_constr (self, name, NULL);
+ self->priv->values = values;
+}
+
+void
+sl_attribute_constr_with_eattr (SlAttribute *self, EVCardAttribute *eattr)
+{
+ /* TODO: all attributes twice in memory, once in their "vcard form" and once
+ * in their "runtime form". This is clearly not optimal. */
+ self->priv->entity = NULL;
+ self->priv->eattr = eattr;
+ self->priv->values = NULL;
+ self->priv->name = sl_attribute_eattrname_to_name (e_vcard_attribute_get_name (eattr));
+
+ GList *evalues = e_vcard_attribute_get_values (eattr);
+ gpointer evalue = NULL;
+ for (; evalues != NULL; evalues = evalues->next)
+ {
+ evalue = evalues->data;
+ gpointer value = sl_attribute_handler_read (self->priv->name, evalue, NULL);
+ self->priv->values = g_list_append (self->priv->values, value);
+ }
+}
+
+SlAttribute *
+sl_attribute_new (const gchar *name, gpointer value)
+{
+ SlAttribute *self = g_object_new (SL_ATTRIBUTE_TYPE, NULL);
+ sl_attribute_constr (self, name, value);
+ return self;
+}
+
+SlAttribute *
+sl_attribute_new_empty (const gchar *name)
+{
+ SlAttribute *self = g_object_new (SL_ATTRIBUTE_TYPE, NULL);
+ sl_attribute_constr (self, name, NULL);
+ return self;
+}
+
+SlAttribute *
+sl_attribute_new_with_values (const gchar *name, GList *values)
+{
+ SlAttribute *self = g_object_new (SL_ATTRIBUTE_TYPE, NULL);
+ sl_attribute_constr_with_values (self, name, values);
+ return self;
+}
+
+SlAttribute *
+sl_attribute_new_with_eattr (EVCardAttribute *eattr)
+{
+ SlAttribute *self = g_object_new (SL_ATTRIBUTE_TYPE, NULL);
+ sl_attribute_constr_with_eattr (self, eattr);
+ return self;
+}
+
+SlEntity *
+sl_attribute_get_entity (SlAttribute *self)
+{
+ return self->priv->entity;
+}
+
+void
+sl_attribute_set_entity (SlAttribute *self, SlEntity *entity)
+{
+ self->priv->entity = g_object_ref (entity);
+}
+
+EVCardAttribute *sl_attribute_get_eattr (SlAttribute *self)
+{
+ return self->priv->eattr;
+}
+
+void sl_attribute_set (SlAttribute *self, gpointer value)
+{
+ /* TODO: temporary add, but should be set_at (0) */
+ sl_attribute_add (self, value);
+}
+
+gpointer sl_attribute_get (SlAttribute *self)
+{
+ if (self->priv->values == NULL)
+ {
+ return NULL;
+ }
+ return self->priv->values->data;
+}
+
+void sl_attribute_add (SlAttribute *self, gpointer value)
+{
+ SlAttributeHandlerType type = 0;
+ gpointer evalue = sl_attribute_handler_write (self->priv->name, value, &type);
+
+ /* TODO: encode value if binary */
+ self->priv->values = g_list_append (self->priv->values, value);
+ e_vcard_attribute_add_value (self->priv->eattr, evalue);
+}
+
+gboolean sl_attribute_set_at (SlAttribute *self, gint index, gpointer value)
+{
+ SlAttributeHandlerType type = 0;
+ gpointer result = sl_attribute_handler_write (self->priv->name, value, &type);
+
+ GList *evalues = e_vcard_attribute_get_values (self->priv->eattr);
+ GList *evalue_nth = g_list_nth (evalues, index);
+ GList *value_nth = g_list_nth (self->priv->values, index);
+ if (evalue_nth == NULL)
+ {
+ return FALSE;
+ }
+ g_assert (value_nth != NULL);
+ /* TODO: can I always free this? */
+ g_free (evalue_nth->data);
+ /* TODO: user has to free value, I don't know how */
+
+ value_nth->data = value;
+ switch (type)
+ {
+ case SL_ATTRIBUTE_HANDLER_TYPE_STRING:
+ evalue_nth->data = result;
+ break;
+ case SL_ATTRIBUTE_HANDLER_TYPE_BIN:
+ /* TODO: encode in base64 */
+ g_warning ("binary encoding not implemented yet");
+ evalue_nth->data = result;
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
+ return TRUE;
+}
+
+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_all (SlAttribute *self, GList *values)
+{
+ g_warning("%s not implemented", __FUNCTION__);
+}
+
+GList *sl_attribute_get_all (SlAttribute *self)
+{
+ return self->priv->values;
+}
+
+void sl_attribute_remove_all (SlAttribute *self)
+{
+ g_warning("%s not implemented", __FUNCTION__);
+}
+
+gint
+sl_attribute_get_value_count (SlAttribute *self)
+{
+ return g_list_length (self->priv->values);
+}
+
+const gchar *sl_attribute_get_name (SlAttribute *self)
+{
+ return self->priv->name;
+}
Modified: trunk/libsoylent/sl-attribute-eds.h
==============================================================================
--- trunk/libsoylent/sl-attribute-eds.h (original)
+++ trunk/libsoylent/sl-attribute-eds.h Thu Jul 31 11:20:52 2008
@@ -20,3 +20,71 @@
* 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_ATTRIBUTE_EDS_H
+#define SL_ATTRIBUTE_EDS_H
+
+#include "sl-priv-util.h"
+#include "sl-entity-eds.h"
+
+#include <glib.h>
+#include <glib-object.h>
+#include <libebook/e-book.h>
+
+#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 _SlAttributeClass SlAttributeClass;
+typedef struct _SlAttributePriv SlAttributePriv;
+
+struct _SlAttribute
+{
+ GObject parent;
+ gboolean disposed;
+ SlAttributePriv *priv;
+};
+
+struct _SlAttributeClass
+{
+ GObjectClass parent;
+};
+
+GType sl_attribute_get_type (void);
+
+void sl_attribute_constr (SlAttribute *self, const gchar *name, gpointer value);
+void sl_attribute_constr_with_values (SlAttribute *self, const gchar *name,
+ GList *values);
+void sl_attribute_constr_with_eattr (SlAttribute *self, EVCardAttribute *eattr);
+SlAttribute *sl_attribute_new (const gchar *name, gpointer value);
+SlAttribute *sl_attribute_new_empty (const gchar *name);
+SlAttribute *sl_attribute_new_with_values (const gchar *name, GList *values);
+SlAttribute *sl_attribute_new_with_eattr (EVCardAttribute *eattr);
+
+SlEntity *sl_attribute_get_entity (SlAttribute *self);
+void sl_attribute_set_entity (SlAttribute *self, SlEntity *entity);
+EVCardAttribute *sl_attribute_get_eattr (SlAttribute *self);
+
+void sl_attribute_set (SlAttribute *self, gpointer value);
+gpointer sl_attribute_get (SlAttribute *self);
+gboolean sl_attribute_set_at (SlAttribute *self, gint index, gpointer value);
+gpointer sl_attribute_get_at (SlAttribute *self, gint index);
+void sl_attribute_remove_at (SlAttribute *self, gint index);
+void sl_attribute_add (SlAttribute *self, gpointer value);
+void sl_attribute_set_all (SlAttribute *self, GList *values);
+GList *sl_attribute_get_all (SlAttribute *self);
+void sl_attribute_remove_all (SlAttribute *self);
+
+gint sl_attribute_get_value_count (SlAttribute *self);
+
+const gchar *sl_attribute_get_name (SlAttribute *self);
+
+#endif
Modified: trunk/libsoylent/sl-attribute.c
==============================================================================
--- trunk/libsoylent/sl-attribute.c (original)
+++ trunk/libsoylent/sl-attribute.c Thu Jul 31 11:20:52 2008
@@ -20,3 +20,5 @@
* 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: define interface and let SlAttributeEDS inherit it */
Modified: trunk/libsoylent/sl-attribute.h
==============================================================================
--- trunk/libsoylent/sl-attribute.h (original)
+++ trunk/libsoylent/sl-attribute.h Thu Jul 31 11:20:52 2008
@@ -20,3 +20,10 @@
* 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_ATTRIBUTE_H
+#define SL_ATTRIBUTE_H
+
+/* TODO: define interface and let SlAttributeEDS inherit it */
+
+#endif
Modified: trunk/libsoylent/sl-attributes.c
==============================================================================
--- trunk/libsoylent/sl-attributes.c (original)
+++ trunk/libsoylent/sl-attributes.c Thu Jul 31 11:20:52 2008
@@ -20,3 +20,121 @@
* 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-attributes.h"
+
+#include <stdlib.h>
+
+/**
+ * SlAttributeHandler:
+ * @type: the type of the handler
+ * @writer: attribute writer function
+ * @reader: attribute reader function
+ *
+ * An attribute-handler is responsible for reading and writing attributes (i.e.
+ * converting them from their runtime-types to a string / binary form and back).
+ */
+struct _SlAttributeHandler
+{
+ SlAttributeHandlerType type;
+ SlAttributeWriterFunc writer;
+ SlAttributeReaderFunc reader;
+};
+
+static GHashTable *attribute_handlers = NULL;
+static SlAttributeHandler *attrhandler_default = NULL;
+
+void
+sl_attribute_handler_init (void)
+{
+ attribute_handlers = g_hash_table_new_full (NULL, NULL, NULL, g_free);
+ attrhandler_default = g_new (SlAttributeHandler, 1);
+ attrhandler_default->type = SL_ATTRIBUTE_HANDLER_TYPE_STRING;
+ attrhandler_default->writer = (SlAttributeWriterFunc) sl_attribute_writer_string;
+ attrhandler_default->reader = (SlAttributeReaderFunc) sl_attribute_reader_string;
+}
+
+void
+sl_attribute_handler_cleanup (void)
+{
+ g_hash_table_remove_all (attribute_handlers);
+ g_hash_table_unref (attribute_handlers);
+ g_free (attrhandler_default);
+}
+
+void
+sl_entity_install_attribute_handler (const gchar *attrname,
+ SlAttributeHandlerType type, SlAttributeWriterFunc writer,
+ SlAttributeReaderFunc reader)
+{
+ SlAttributeHandler *attrhandler = g_new (SlAttributeHandler, 1);
+ attrhandler->type = type;
+ attrhandler->writer = writer;
+ attrhandler->reader = reader;
+
+ /* if the key already exists the old handler will automatically be freed by
+ * GHashTable */
+ g_hash_table_insert (attribute_handlers, (gpointer) attrname, attrhandler);
+}
+
+gboolean
+sl_entity_remove_attribute_handler (const gchar *attrname)
+{
+ return g_hash_table_remove (attribute_handlers, attrname);
+}
+
+gpointer
+sl_attribute_handler_write (const gchar *attrname, gpointer value,
+ SlAttributeHandlerType *type)
+{
+ SlAttributeHandler *attrhandler = g_hash_table_lookup (attribute_handlers,
+ attrname);
+ if (attrhandler == NULL)
+ {
+ attrhandler = attrhandler_default;
+ }
+ *type = attrhandler->type;
+ return attrhandler->writer (attrname, value);
+}
+
+gpointer
+sl_attribute_handler_read (const gchar *attrname, gpointer value,
+ SlAttributeHandlerType *type)
+{
+ SlAttributeHandler *attrhandler = g_hash_table_lookup (attribute_handlers,
+ attrname);
+ if (attrhandler == NULL)
+ {
+ attrhandler = attrhandler_default;
+ }
+ if (type != NULL)
+ {
+ *type = attrhandler->type;
+ }
+ return attrhandler->reader (attrname, value);
+}
+
+gchar *sl_attribute_writer_string (const gchar *attrname, gchar *value)
+{
+ return value;
+}
+
+gchar *sl_attribute_reader_string (const gchar *attrname, gchar *value)
+{
+ return value;
+}
+
+gchar *sl_attribute_writer_int (const gchar *attrname, GValue *value)
+{
+ GString *str = g_string_new (NULL);
+ g_string_printf (str, "%d", g_value_get_int (value));
+ return str->str;
+}
+
+GValue *sl_attribute_reader_int (const gchar *attrname, gchar *value)
+{
+ GValue *gvalue = g_new (GValue, 1);
+ g_value_init (gvalue, G_TYPE_INT);
+ g_value_set_int (gvalue, strtol(value, NULL, 10));
+ return gvalue;
+}
Modified: trunk/libsoylent/sl-attributes.h
==============================================================================
--- trunk/libsoylent/sl-attributes.h (original)
+++ trunk/libsoylent/sl-attributes.h Thu Jul 31 11:20:52 2008
@@ -20,3 +20,45 @@
* 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_ATTRIBUTES_H
+#define SL_ATTRIBUTES_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+#define SL_ATTRIBUTE_WRITER_FUNC(func) ((SlAttributeWriterFunc) (func))
+#define SL_ATTRIBUTE_READER_FUNC(func) ((SlAttributeReaderFunc) (func))
+
+typedef struct _SlAttributeHandler SlAttributeHandler;
+
+typedef enum _SlAttributeHandlerType SlAttributeHandlerType;
+
+typedef gpointer (*SlAttributeWriterFunc)(const gchar *attrname,
+ const gpointer value);
+typedef gpointer (*SlAttributeReaderFunc)(const gchar *attrname,
+ const gpointer value);
+
+enum _SlAttributeHandlerType
+{
+ SL_ATTRIBUTE_HANDLER_TYPE_STRING,
+ SL_ATTRIBUTE_HANDLER_TYPE_BIN
+};
+
+void sl_attribute_handler_init (void);
+void sl_attribute_handler_cleanup (void);
+void sl_entity_install_attribute_handler (const gchar *attrname,
+ SlAttributeHandlerType type, SlAttributeWriterFunc writer,
+ SlAttributeReaderFunc reader);
+gboolean sl_entity_remove_attribute_handler (const gchar *attrname);
+gpointer sl_attribute_handler_write (const gchar *attrname, gpointer value,
+ SlAttributeHandlerType *type);
+gpointer sl_attribute_handler_read (const gchar *attrname, gpointer value,
+ SlAttributeHandlerType *type);
+
+gchar *sl_attribute_writer_string (const gchar *attrname, gchar *value);
+gchar *sl_attribute_reader_string (const gchar *attrname, gchar *value);
+gchar *sl_attribute_writer_int (const gchar *attrname, GValue *value);
+GValue *sl_attribute_reader_int (const gchar *attrname, gchar *value);
+
+#endif
Modified: trunk/libsoylent/sl-book.c
==============================================================================
--- trunk/libsoylent/sl-book.c (original)
+++ trunk/libsoylent/sl-book.c Thu Jul 31 11:20:52 2008
@@ -37,7 +37,6 @@
#include "sl-book.h"
#include "sl-priv-util.h"
#include "sl-entity.h"
-#include "sl-entity-handler-eds.h"
/* private structs and fields */
Modified: trunk/libsoylent/sl-entity-eds.c
==============================================================================
--- trunk/libsoylent/sl-entity-eds.c (original)
+++ trunk/libsoylent/sl-entity-eds.c Thu Jul 31 11:20:52 2008
@@ -24,51 +24,21 @@
/* TODO: will be splitted to SlEntity (interface), SlEntityBase (abstract-
* base class), SlEntityEDS. for now this will be misused as SlEntityEDS */
-#include "sl-entity.h"
+#include "sl-entity-eds.h"
#include "sl-person.h"
/* private structs and fields */
struct _SlEntityPriv
{
- SlEntityHandler *entity_handler;
EBook *ebook;
EContact *econtact;
GList *attributes;
GHashTable *attribute_table;
};
-struct _SlAttributePriv
-{
- SlEntity *entity;
- const gchar *name;
- GList *values;
- EVCardAttribute *eattr;
-};
-
-/**
- * SlAttributeHandler:
- * @type: the type of the handler
- * @writer: attribute writer function
- * @reader: attribute reader function
- *
- * An attribute-handler is responsible for reading and writing attributes (i.e.
- * converting them from their runtime-types to a string / binary form and back).
- */
-struct _SlAttributeHandler
-{
- SlAttributeHandlerType type;
- SlAttributeWriterFunc writer;
- SlAttributeReaderFunc reader;
-};
-
-static GHashTable *attribute_handlers = NULL;
-static SlAttributeHandler *attrhandler_default = NULL;
-
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);
@@ -77,17 +47,6 @@
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);
-
-static const gchar *sl_attribute_name_to_eattrname (const gchar *name);
-static const gchar *sl_attribute_eattrname_to_name (const gchar *eattrname);
-
GType
sl_entity_get_type (void)
{
@@ -113,126 +72,6 @@
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_attribute_handler_init (void)
-{
- attribute_handlers = g_hash_table_new_full (NULL, NULL, NULL, g_free);
- attrhandler_default = g_new (SlAttributeHandler, 1);
- attrhandler_default->type = SL_ATTRIBUTE_HANDLER_TYPE_STRING;
- attrhandler_default->writer = (SlAttributeWriterFunc) sl_attribute_writer_string;
- attrhandler_default->reader = (SlAttributeReaderFunc) sl_attribute_reader_string;
-}
-
-void
-sl_attribute_handler_cleanup (void)
-{
- g_hash_table_remove_all (attribute_handlers);
- g_hash_table_unref (attribute_handlers);
- g_free (attrhandler_default);
-}
-
-void
-sl_entity_install_attribute_handler (const gchar *attrname,
- SlAttributeHandlerType type, SlAttributeWriterFunc writer,
- SlAttributeReaderFunc reader)
-{
- SlAttributeHandler *attrhandler = g_new (SlAttributeHandler, 1);
- attrhandler->type = type;
- attrhandler->writer = writer;
- attrhandler->reader = reader;
-
- /* if the key already exists the old handler will automatically be freed by
- * GHashTable */
- g_hash_table_insert (attribute_handlers, (gpointer) attrname, attrhandler);
-}
-
-gboolean
-sl_entity_remove_attribute_handler (const gchar *attrname)
-{
- return g_hash_table_remove (attribute_handlers, attrname);
-}
-
-gpointer
-sl_attribute_handler_write (const gchar *attrname, gpointer value,
- SlAttributeHandlerType *type)
-{
- SlAttributeHandler *attrhandler = g_hash_table_lookup (attribute_handlers,
- attrname);
- if (attrhandler == NULL)
- {
- attrhandler = attrhandler_default;
- }
- *type = attrhandler->type;
- return attrhandler->writer (attrname, value);
-}
-
-gpointer
-sl_attribute_handler_read (const gchar *attrname, gpointer value,
- SlAttributeHandlerType *type)
-{
- SlAttributeHandler *attrhandler = g_hash_table_lookup (attribute_handlers,
- attrname);
- if (attrhandler == NULL)
- {
- attrhandler = attrhandler_default;
- }
- if (type != NULL)
- {
- *type = attrhandler->type;
- }
- return attrhandler->reader (attrname, value);
-}
-
-gchar *sl_attribute_writer_string (const gchar *attrname, gchar *value)
-{
- return value;
-}
-
-gchar *sl_attribute_reader_string (const gchar *attrname, gchar *value)
-{
- return value;
-}
-
-gchar *sl_attribute_writer_int (const gchar *attrname, GValue *value)
-{
- GString *str = g_string_new (NULL);
- g_string_printf (str, "%d", g_value_get_int (value));
- return str->str;
-}
-
-GValue *sl_attribute_reader_int (const gchar *attrname, gchar *value)
-{
- GValue *gvalue = g_new (GValue, 1);
- g_value_init (gvalue, G_TYPE_INT);
- g_value_set_int (gvalue, strtol(value, NULL, 10));
- return gvalue;
-}
-
static void
sl_entity_class_init (gpointer g_class, gpointer class_data)
{
@@ -329,7 +168,7 @@
attr = sl_attribute_new_with_eattr (eattr);
/* TODO: make one function for the next two calls */
self->priv->attributes = g_list_append (self->priv->attributes, g_object_ref (attr));
- g_hash_table_insert (self->priv->attribute_table, (const gpointer) attr->priv->name, g_object_ref (attr));
+ g_hash_table_insert (self->priv->attribute_table, (const gpointer) sl_attribute_get_name (attr), g_object_ref (attr));
g_object_unref (attr);
}
}
@@ -368,10 +207,10 @@
{
/* TODO: what if attribute already exists? add values?*/
self->priv->attributes = g_list_append (self->priv->attributes, g_object_ref (attr));
- g_hash_table_insert (self->priv->attribute_table, (const gpointer) attr->priv->name, g_object_ref (attr));
- attr->priv->entity = self;
+ g_hash_table_insert (self->priv->attribute_table, (const gpointer) sl_attribute_get_name (attr), g_object_ref (attr));
+ sl_attribute_set_entity (attr, self);
- e_vcard_add_attribute (E_VCARD (self->priv->econtact), attr->priv->eattr);
+ e_vcard_add_attribute (E_VCARD (self->priv->econtact), sl_attribute_get_eattr (attr));
}
void
@@ -475,295 +314,3 @@
{
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__);
-}
-
-static const gchar *
-sl_attribute_name_to_eattrname (const gchar *name)
-{
- static GHashTable *name_to_eattrname_map = NULL;
- if (name_to_eattrname_map == NULL)
- {
- name_to_eattrname_map = g_hash_table_new (g_str_hash, g_str_equal);
- g_hash_table_insert (name_to_eattrname_map, SL_ATTR_ID, EVC_UID);
- g_hash_table_insert (name_to_eattrname_map, SL_ATTR_NAME, EVC_N);
- g_hash_table_insert (name_to_eattrname_map, SL_ATTR_FAMILY_NAME, EVC_FN);
- g_hash_table_insert (name_to_eattrname_map, SL_ATTR_NICK, EVC_NICKNAME);
- g_hash_table_insert (name_to_eattrname_map, SL_ATTR_GROUP, EVC_CATEGORIES);
- g_hash_table_insert (name_to_eattrname_map, SL_ATTR_ADDRESS, EVC_ADR);
- g_hash_table_insert (name_to_eattrname_map, SL_ATTR_EMAIL, EVC_EMAIL);
- g_hash_table_insert (name_to_eattrname_map, SL_ATTR_TELEPHONE, EVC_TEL);
- g_hash_table_insert (name_to_eattrname_map, SL_ATTR_BIRTHDAY, EVC_BDAY);
- g_hash_table_insert (name_to_eattrname_map, SL_ATTR_URL, EVC_URL);
- g_hash_table_insert (name_to_eattrname_map, SL_ATTR_BLOG, EVC_X_BLOG_URL);
- g_hash_table_insert (name_to_eattrname_map, SL_ATTR_CALENDAR_URL, EVC_CALURI);
- g_hash_table_insert (name_to_eattrname_map, SL_ATTR_FREE_BUSY_URL, EVC_FBURL);
- g_hash_table_insert (name_to_eattrname_map, SL_ATTR_NOTE, EVC_NOTE);
- g_hash_table_insert (name_to_eattrname_map, SL_ATTR_PHOTO, EVC_PHOTO);
- g_hash_table_insert (name_to_eattrname_map, SL_ATTR_ICON, EVC_LOGO);
- g_hash_table_insert (name_to_eattrname_map, SL_ATTR_JOB_ROLE, EVC_ROLE);
- g_hash_table_insert (name_to_eattrname_map, SL_ATTR_JOB_TITLE, EVC_TITLE);
- }
-
- const gchar *eattrname = g_hash_table_lookup (name_to_eattrname_map, name);
- if (eattrname == NULL)
- {
- GString *str = g_string_new (NULL);
- g_string_printf (str, "X-%s", name);
- eattrname = str->str;
- }
- return eattrname;
-}
-
-static const gchar *
-sl_attribute_eattrname_to_name (const gchar *eattrname)
-{
- static GHashTable *eattrname_to_name_map = NULL;
- if (eattrname_to_name_map == NULL)
- {
- eattrname_to_name_map = g_hash_table_new (g_str_hash, g_str_equal);
- g_hash_table_insert (eattrname_to_name_map, EVC_UID, SL_ATTR_ID);
- g_hash_table_insert (eattrname_to_name_map, EVC_N, SL_ATTR_NAME);
- g_hash_table_insert (eattrname_to_name_map, EVC_FN, SL_ATTR_FAMILY_NAME);
- g_hash_table_insert (eattrname_to_name_map, EVC_NICKNAME, SL_ATTR_NICK);
- g_hash_table_insert (eattrname_to_name_map, EVC_CATEGORIES, SL_ATTR_GROUP);
- g_hash_table_insert (eattrname_to_name_map, EVC_ADR, SL_ATTR_ADDRESS);
- g_hash_table_insert (eattrname_to_name_map, EVC_EMAIL, SL_ATTR_EMAIL);
- g_hash_table_insert (eattrname_to_name_map, EVC_TEL, SL_ATTR_TELEPHONE);
- g_hash_table_insert (eattrname_to_name_map, EVC_BDAY, SL_ATTR_BIRTHDAY);
- g_hash_table_insert (eattrname_to_name_map, EVC_URL, SL_ATTR_URL);
- g_hash_table_insert (eattrname_to_name_map, EVC_X_BLOG_URL, SL_ATTR_BLOG);
- g_hash_table_insert (eattrname_to_name_map, EVC_CALURI, SL_ATTR_CALENDAR_URL);
- g_hash_table_insert (eattrname_to_name_map, EVC_FBURL, SL_ATTR_FREE_BUSY_URL);
- g_hash_table_insert (eattrname_to_name_map, EVC_NOTE, SL_ATTR_NOTE);
- g_hash_table_insert (eattrname_to_name_map, EVC_PHOTO, SL_ATTR_PHOTO);
- g_hash_table_insert (eattrname_to_name_map, EVC_LOGO, SL_ATTR_ICON);
- g_hash_table_insert (eattrname_to_name_map, EVC_ROLE, SL_ATTR_JOB_ROLE);
- g_hash_table_insert (eattrname_to_name_map, EVC_TITLE, SL_ATTR_JOB_TITLE);
- }
-
- const gchar *name = g_hash_table_lookup (eattrname_to_name_map, eattrname);
- if (name == NULL)
- {
- /* TODO: this leaks, cause name must be freed somehow */
- g_assert (g_str_has_prefix (eattrname, "X-"));
- name = g_utf8_strdown (&eattrname[2], -1);
- }
- return name;
-}
-
-void
-sl_attribute_constr (SlAttribute *self, const gchar *name, gpointer value)
-{
- self->priv->entity = NULL;
- self->priv->name = name;
- self->priv->eattr = e_vcard_attribute_new (NULL, sl_attribute_name_to_eattrname (name));
- self->priv->values = NULL;
- if (value != NULL)
- {
- self->priv->values = g_list_append (self->priv->values, value);
- }
-}
-
-void
-sl_attribute_constr_with_values (SlAttribute *self, const gchar *name,
- GList *values)
-{
- sl_attribute_constr (self, name, NULL);
- self->priv->values = values;
-}
-
-void
-sl_attribute_constr_with_eattr (SlAttribute *self, EVCardAttribute *eattr)
-{
- /* TODO: all attributes twice in memory, once in their "vcard form" and once
- * in their "runtime form". This is clearly not optimal. */
- self->priv->entity = NULL;
- self->priv->eattr = eattr;
- self->priv->values = NULL;
- self->priv->name = sl_attribute_eattrname_to_name (e_vcard_attribute_get_name (eattr));
-
- GList *evalues = e_vcard_attribute_get_values (eattr);
- gpointer evalue = NULL;
- for (; evalues != NULL; evalues = evalues->next)
- {
- evalue = evalues->data;
- gpointer value = sl_attribute_handler_read (self->priv->name, evalue, NULL);
- self->priv->values = g_list_append (self->priv->values, value);
- }
-}
-
-SlAttribute *
-sl_attribute_new (const gchar *name, gpointer value)
-{
- SlAttribute *self = g_object_new (SL_ATTRIBUTE_TYPE, NULL);
- sl_attribute_constr (self, name, value);
- return self;
-}
-
-SlAttribute *
-sl_attribute_new_empty (const gchar *name)
-{
- SlAttribute *self = g_object_new (SL_ATTRIBUTE_TYPE, NULL);
- sl_attribute_constr (self, name, NULL);
- return self;
-}
-
-SlAttribute *
-sl_attribute_new_with_values (const gchar *name, GList *values)
-{
- SlAttribute *self = g_object_new (SL_ATTRIBUTE_TYPE, NULL);
- sl_attribute_constr_with_values (self, name, values);
- return self;
-}
-
-SlAttribute *
-sl_attribute_new_with_eattr (EVCardAttribute *eattr)
-{
- SlAttribute *self = g_object_new (SL_ATTRIBUTE_TYPE, NULL);
- sl_attribute_constr_with_eattr (self, eattr);
- return self;
-}
-
-void sl_attribute_set (SlAttribute *self, gpointer value)
-{
- /* TODO: temporary add, but should be set_at (0) */
- sl_attribute_add (self, value);
-}
-
-gpointer sl_attribute_get (SlAttribute *self)
-{
- if (self->priv->values == NULL)
- {
- return NULL;
- }
- return self->priv->values->data;
-}
-
-void sl_attribute_add (SlAttribute *self, gpointer value)
-{
- SlAttributeHandlerType type = 0;
- gpointer evalue = sl_attribute_handler_write (self->priv->name, value, &type);
-
- /* TODO: encode value if binary */
- self->priv->values = g_list_append (self->priv->values, value);
- e_vcard_attribute_add_value (self->priv->eattr, evalue);
-}
-
-gboolean sl_attribute_set_at (SlAttribute *self, gint index, gpointer value)
-{
- SlAttributeHandlerType type = 0;
- gpointer result = sl_attribute_handler_write (self->priv->name, value, &type);
-
- GList *evalues = e_vcard_attribute_get_values (self->priv->eattr);
- GList *evalue_nth = g_list_nth (evalues, index);
- GList *value_nth = g_list_nth (self->priv->values, index);
- if (evalue_nth == NULL)
- {
- return FALSE;
- }
- g_assert (value_nth != NULL);
- /* TODO: can I always free this? */
- g_free (evalue_nth->data);
- /* TODO: user has to free value, I don't know how */
-
- value_nth->data = value;
- switch (type)
- {
- case SL_ATTRIBUTE_HANDLER_TYPE_STRING:
- evalue_nth->data = result;
- break;
- case SL_ATTRIBUTE_HANDLER_TYPE_BIN:
- /* TODO: encode in base64 */
- g_warning ("binary encoding not implemented yet");
- evalue_nth->data = result;
- break;
- default:
- g_assert_not_reached ();
- }
-
- return TRUE;
-}
-
-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_all (SlAttribute *self, GList *values)
-{
- g_warning("%s not implemented", __FUNCTION__);
-}
-
-GList *sl_attribute_get_all (SlAttribute *self)
-{
- return self->priv->values;
-}
-
-void sl_attribute_remove_all (SlAttribute *self)
-{
- g_warning("%s not implemented", __FUNCTION__);
-}
-
-gint
-sl_attribute_get_value_count (SlAttribute *self)
-{
- return g_list_length (self->priv->values);
-}
-
-const gchar *sl_attribute_get_name (SlAttribute *self)
-{
- return self->priv->name;
-}
Modified: trunk/libsoylent/sl-entity-eds.h
==============================================================================
--- trunk/libsoylent/sl-entity-eds.h (original)
+++ trunk/libsoylent/sl-entity-eds.h Thu Jul 31 11:20:52 2008
@@ -24,10 +24,11 @@
/* 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
+#ifndef SL_ENTITY_EDS_H
+#define SL_ENTITY_EDS_H
-#include "sl-entity-handler.h"
+#include "sl-priv-util.h"
+#include "sl-attribute-eds.h"
#include <glib.h>
#include <glib-object.h>
@@ -45,51 +46,16 @@
#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))
-
-#define SL_ATTRIBUTE_WRITER_FUNC(func) ((SlAttributeWriterFunc) (func))
-#define SL_ATTRIBUTE_READER_FUNC(func) ((SlAttributeReaderFunc) (func))
-
-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;
-
-typedef gpointer (*SlAttributeWriterFunc)(const gchar *attrname,
- const gpointer value);
-typedef gpointer (*SlAttributeReaderFunc)(const gchar *attrname,
- const gpointer value);
-
enum _SlEntityProperty
{
SL_ENTITY_PROPERTY_ENTITY_HANDLER = 1
};
-enum _SlAttributeHandlerType
-{
- SL_ATTRIBUTE_HANDLER_TYPE_STRING,
- SL_ATTRIBUTE_HANDLER_TYPE_BIN
-};
-
struct _SlEntity
{
GObject parent;
@@ -102,36 +68,7 @@
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);
-
-void sl_attribute_handler_init (void);
-void sl_attribute_handler_cleanup (void);
-void sl_entity_install_attribute_handler (const gchar *attrname,
- SlAttributeHandlerType type, SlAttributeWriterFunc writer,
- SlAttributeReaderFunc reader);
-gboolean sl_entity_remove_attribute_handler (const gchar *attrname);
-gpointer sl_attribute_handler_write (const gchar *attrname, gpointer value,
- SlAttributeHandlerType *type);
-gpointer sl_attribute_handler_read (const gchar *attrname, gpointer value,
- SlAttributeHandlerType *type);
-
-gchar *sl_attribute_writer_string (const gchar *attrname, gchar *value);
-gchar *sl_attribute_reader_string (const gchar *attrname, gchar *value);
-gchar *sl_attribute_writer_int (const gchar *attrname, GValue *value);
-GValue *sl_attribute_reader_int (const gchar *attrname, gchar *value);
/*SlEntity *sl_entity_new (SlEntityHandler *entity_handler);*/
/*SlEntityHandler *sl_entity_get_handler (SlEntity *self);*/
@@ -161,27 +98,4 @@
/* TODO: perhaps gboolean instead of void to indicate that an attrname doesn't
* exist */
-void sl_attribute_constr (SlAttribute *self, const gchar *name, gpointer value);
-void sl_attribute_constr_with_values (SlAttribute *self, const gchar *name,
- GList *values);
-void sl_attribute_constr_with_eattr (SlAttribute *self, EVCardAttribute *eattr);
-SlAttribute *sl_attribute_new (const gchar *name, gpointer value);
-SlAttribute *sl_attribute_new_empty (const gchar *name);
-SlAttribute *sl_attribute_new_with_values (const gchar *name, GList *values);
-SlAttribute *sl_attribute_new_with_eattr (EVCardAttribute *eattr);
-
-void sl_attribute_set (SlAttribute *self, gpointer value);
-gpointer sl_attribute_get (SlAttribute *self);
-gboolean 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_add (SlAttribute *self, gpointer value);
-void sl_attribute_set_all (SlAttribute *self, GList *values);
-GList *sl_attribute_get_all (SlAttribute *self);
-void sl_attribute_remove_all (SlAttribute *self);
-
-gint sl_attribute_get_value_count (SlAttribute *self);
-
-const gchar *sl_attribute_get_name (SlAttribute *self);
-
#endif
Modified: trunk/libsoylent/sl-entity.c
==============================================================================
--- trunk/libsoylent/sl-entity.c (original)
+++ trunk/libsoylent/sl-entity.c Thu Jul 31 11:20:52 2008
@@ -20,3 +20,5 @@
* 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: define interface and let SlEntityEDS inherit it */
Modified: trunk/libsoylent/sl-entity.h
==============================================================================
--- trunk/libsoylent/sl-entity.h (original)
+++ trunk/libsoylent/sl-entity.h Thu Jul 31 11:20:52 2008
@@ -20,3 +20,10 @@
* 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_ENTITY_H
+#define SL_ENTITY_H
+
+/* TODO: define interface and let SlEntityEDS inherit it */
+
+#endif
Modified: trunk/libsoylent/sl-group.h
==============================================================================
--- trunk/libsoylent/sl-group.h (original)
+++ trunk/libsoylent/sl-group.h Thu Jul 31 11:20:52 2008
@@ -26,7 +26,7 @@
#ifndef SL_GROUP_H
#define SL_GROUP_H
-#include "sl-entity.h"
+#include "sl-entity-eds.h"
#include <glib.h>
#include <glib-object.h>
Modified: trunk/libsoylent/sl-person.c
==============================================================================
--- trunk/libsoylent/sl-person.c (original)
+++ trunk/libsoylent/sl-person.c Thu Jul 31 11:20:52 2008
@@ -22,7 +22,7 @@
*/
#include "sl-person.h"
-#include "sl-entity-handler-eds.h"
+#include "sl-entity-eds.h"
/* private structs and fields */
Modified: trunk/libsoylent/sl-person.h
==============================================================================
--- trunk/libsoylent/sl-person.h (original)
+++ trunk/libsoylent/sl-person.h Thu Jul 31 11:20:52 2008
@@ -24,7 +24,7 @@
#ifndef SL_PERSON_H
#define SL_PERSON_H
-#include "sl-entity.h"
+#include "sl-entity-eds.h"
#include <glib.h>
#include <glib-object.h>
Modified: trunk/libsoylent/sl-priv-util.h
==============================================================================
--- trunk/libsoylent/sl-priv-util.h (original)
+++ trunk/libsoylent/sl-priv-util.h Thu Jul 31 11:20:52 2008
@@ -21,11 +21,15 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef SL_PRIVUTIL_H
-#define SL_PRIVUTIL_H
+#ifndef SL_PRIV_UTIL_H
+#define SL_PRIV_UTIL_H
#include <libebook/e-book.h>
+/* solve mutual inclusion */
+typedef struct _SlEntity SlEntity;
+typedef struct _SlAttribute SlAttribute;
+
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: trunk/libsoylent/soylent.h
==============================================================================
--- trunk/libsoylent/soylent.h (original)
+++ trunk/libsoylent/soylent.h Thu Jul 31 11:20:52 2008
@@ -25,9 +25,10 @@
#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-entity-eds.h"
+#include "sl-attribute.h"
+#include "sl-attribute-eds.h"
+#include "sl-attributes.h"
#include "sl-person.h"
#include "sl-group.h"
#include "sl-book.h"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]