soylent r271 - trunk/libsoylent
- From: svenp svn gnome org
- To: svn-commits-list gnome org
- Subject: soylent r271 - trunk/libsoylent
- Date: Mon, 11 Aug 2008 21:47:53 +0000 (UTC)
Author: svenp
Date: Mon Aug 11 21:47:53 2008
New Revision: 271
URL: http://svn.gnome.org/viewvc/soylent?rev=271&view=rev
Log:
fixed: adding / removing eattributes to / from econtacts (1 SlAttribute value <-> 1 eattribute)
implemented all convinience attribute methods of SlEntity
Modified:
trunk/libsoylent/sl-entity-eds.c
trunk/libsoylent/sl-entity-eds.h
Modified: trunk/libsoylent/sl-entity-eds.c
==============================================================================
--- trunk/libsoylent/sl-entity-eds.c (original)
+++ trunk/libsoylent/sl-entity-eds.c Mon Aug 11 21:47:53 2008
@@ -24,14 +24,15 @@
/* TODO: will be splitted to SlEntity (interface), SlEntityBase (abstract-
* base class), SlEntityEDS. for now this will be misused as SlEntityEDS */
+#include "sl-mutual-inclusion.h"
+#include "sl-priv-util.h"
#include "soylent.h"
-#include "sl-entity-eds.h"
-#include "sl-person.h"
/* private structs and fields */
struct _SlEntityPriv
{
+ SlBook *storage;
EBook *ebook;
EContact *econtact;
GList *attributes;
@@ -140,6 +141,7 @@
void
sl_entity_constr (SlEntity *self)
{
+ self->priv->storage = NULL;
self->priv->ebook = NULL;
self->priv->econtact = e_contact_new ();
self->priv->attribute_table = g_hash_table_new (g_str_hash, g_str_equal);
@@ -149,31 +151,52 @@
void
sl_entity_constr_with_econtact (SlEntity *self, EContact *econtact)
{
+ self->priv->storage = NULL;
self->priv->ebook = NULL;
self->priv->attribute_table = g_hash_table_new (g_str_hash, g_str_equal);
self->priv->attributes = NULL;
self->priv->econtact = g_object_ref (econtact);
- GList *eattributes = e_vcard_get_attributes (E_VCARD (self->priv->econtact));
- EVCardAttribute *eattr = NULL;
- SlAttribute *attr = NULL;
+ sl_debug_entity ("creating entity from econtact%s", "");
+
+ GList *eattributes = g_list_copy (e_vcard_get_attributes (E_VCARD (self->priv->econtact)));
+ eattributes = g_list_sort (eattributes, (GCompareFunc) sl_priv_util_compare_eattributes);
+
for (; eattributes != NULL; eattributes = eattributes->next)
{
- eattr = eattributes->data;
+ EVCardAttribute *eattr = eattributes->data;
const gchar *eattrname = e_vcard_attribute_get_name (eattr);
if (sl_is_ignored_eattr (eattrname))
{
sl_debug_entity ("ignored eattribute \"%s\"", eattrname);
continue;
}
- attr = sl_attribute_new_with_eattr (eattr);
+
+ SlAttribute *attr = sl_attribute_new_with_eattr (eattr);
g_assert (attr != NULL);
+
/* TODO: make one function for the next two calls */
self->priv->attributes = g_list_append (self->priv->attributes, g_object_ref (attr));
g_hash_table_insert (self->priv->attribute_table, (const gpointer) sl_attribute_get_name (attr), g_object_ref (attr));
+
sl_attribute_set_entity (attr, self);
+
+ while (TRUE)
+ {
+ GList *next = eattributes->next;
+ if (next == NULL || !g_str_equal(e_vcard_attribute_get_name (next->data), eattrname))
+ {
+ break;
+ }
+ eattributes = eattributes->next;
+ eattr = eattributes->data;
+ sl_attribute_add_from_eattr (attr, eattr);
+ }
+
g_object_unref (attr);
}
+
+ g_list_free (eattributes);
}
void
@@ -200,6 +223,12 @@
self->priv->econtact = g_object_ref (econtact);
}
+SlBook *
+sl_entity_get_storage (SlEntity *self)
+{
+ return self->priv->storage;
+}
+
gboolean
sl_entity_commit (SlEntity *self, GError **error)
{
@@ -212,20 +241,48 @@
}
void
-sl_entity_add_attribute (SlEntity *self, SlAttribute *attr)
+sl_entity_add_attribute_shallow (SlEntity *self, SlAttribute *attr)
{
/* 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) sl_attribute_get_name (attr), g_object_ref (attr));
sl_attribute_set_entity (attr, self);
+}
+
+void
+sl_entity_remove_attribute_shallow (SlEntity *self, SlAttribute *attr)
+{
+ self->priv->attributes = g_list_remove (self->priv->attributes, attr);
+ g_hash_table_remove (self->priv->attribute_table, (const gpointer) sl_attribute_get_name (attr));
+ sl_attribute_set_entity (attr, NULL);
+ g_object_unref (attr);
+ g_object_unref (attr);
+}
+
+void
+sl_entity_add_attribute (SlEntity *self, SlAttribute *attr)
+{
+ sl_entity_add_attribute_shallow (self, attr);
- e_vcard_add_attribute (E_VCARD (self->priv->econtact), sl_attribute_get_eattr (attr));
+ GList *eattributes = sl_attribute_get_eattributes (attr);
+ for (; eattributes != NULL; eattributes = eattributes->next)
+ {
+ EVCardAttribute *eattr = eattributes->data;
+ e_vcard_add_attribute (E_VCARD (self->priv->econtact), eattr);
+ }
}
void
sl_entity_remove_attribute (SlEntity *self, SlAttribute *attr)
{
- g_warning("%s not implemented", __FUNCTION__);
+ GList *eattributes = sl_attribute_get_eattributes (attr);
+ for (; eattributes != NULL; eattributes = eattributes->next)
+ {
+ EVCardAttribute *eattr = eattributes->data;
+ e_vcard_remove_attribute (E_VCARD (self->priv->econtact), eattr);
+ }
+
+ sl_entity_remove_attribute_shallow (self, attr);
}
/* ABSTRACT
@@ -254,12 +311,7 @@
SlAttribute *sl_entity_get_attribute (SlEntity *self, const gchar *attrname)
{
- SlAttribute *attr = g_hash_table_lookup (self->priv->attribute_table, attrname);
- if (attr == NULL)
- {
- sl_debug_entity ("entity has no attribute \"%s\"", attrname);
- }
- return attr;
+ return g_hash_table_lookup (self->priv->attribute_table, attrname);
}
SlAttribute *
@@ -275,8 +327,8 @@
return self->priv->attributes;
}
-void
-sl_entity_set (SlEntity *self, const gchar *attrname, gpointer value)
+SlAttribute *
+sl_entity_get_attribute_create (SlEntity *self, const gchar *attrname)
{
SlAttribute *attr = sl_entity_get_attribute (self, attrname);
if (attr == NULL)
@@ -284,14 +336,21 @@
attr = sl_attribute_new_empty (attrname);
sl_entity_add_attribute (self, attr);
}
- sl_attribute_set (attr, value);
+ return attr;
+}
+
+void
+sl_entity_add (SlEntity *self, const gchar *attrname, gpointer value)
+{
+ SlAttribute *attr = sl_entity_get_attribute_create (self, attrname);
+ sl_attribute_add (attr, value);
}
gpointer
sl_entity_get (SlEntity *self, const gchar *attrname)
{
SlAttribute *attr = sl_entity_get_attribute (self, attrname);
- if (attr == NULL)
+ if (attr == NULL)
{
return NULL;
}
@@ -299,45 +358,84 @@
}
void
-sl_entity_remove (SlEntity *self, const gchar *attrname)
+sl_entity_set (SlEntity *self, const gchar *attrname, gpointer value)
{
- g_warning("%s not implemented", __FUNCTION__);
+ SlAttribute *attr = sl_entity_get_attribute_create (self, attrname);
+ sl_attribute_set (attr, value);
}
-void
-sl_entity_set_at (SlEntity *self, const gchar *attrname, gint index, gpointer value)
+gpointer
+sl_entity_get_at (SlEntity *self, const gchar *attrname, gint index)
{
- g_warning("%s not implemented", __FUNCTION__);
+ SlAttribute *attr = sl_entity_get_attribute (self, attrname);
+ if (attr == NULL)
+ {
+ return NULL;
+ }
+ return sl_attribute_get_at (attr, index);
}
-gpointer
-sl_entity_get_at (SlEntity *self, const gchar *attrname, gint index)
+gboolean
+sl_entity_set_at (SlEntity *self, const gchar *attrname, gint index, gpointer value)
{
- g_warning("%s not implemented", __FUNCTION__);
- return NULL;
+ SlAttribute *attr = sl_entity_get_attribute_create (self, attrname);
+ if (attr == NULL)
+ {
+ return FALSE;
+ }
+ return sl_attribute_set_at (attr, index, value);
}
-void
+gboolean
sl_entity_remove_at (SlEntity *self, const gchar *attrname, gint index)
{
- g_warning("%s not implemented", __FUNCTION__);
+ SlAttribute *attr = sl_entity_get_attribute (self, attrname);
+ if (attr == NULL)
+ {
+ return FALSE;
+ }
+ return sl_attribute_remove_at (attr, index);
}
void
-sl_entity_set_values (SlEntity *self, const gchar *attrname, GList *values)
+sl_entity_set_all (SlEntity *self, const gchar *attrname, GList *values)
{
- g_warning("%s not implemented", __FUNCTION__);
+ SlAttribute *attr = sl_entity_get_attribute_create (self, attrname);
+ sl_attribute_set_all (attr, values);
}
GList *
-sl_entity_get_values (SlEntity *self, const gchar *attrname)
+sl_entity_get_all (SlEntity *self, const gchar *attrname)
{
- g_warning("%s not implemented", __FUNCTION__);
- return NULL;
+ SlAttribute *attr = sl_entity_get_attribute (self, attrname);
+ if (attr == NULL)
+ {
+ return NULL;
+ }
+ return sl_attribute_get_all (attr);
}
void
-sl_entity_remove_values (SlEntity *self, const gchar *attrname)
+sl_entity_remove_all (SlEntity *self, const gchar *attrname)
{
- g_warning("%s not implemented", __FUNCTION__);
+ SlAttribute *attr = sl_entity_get_attribute (self, attrname);
+ if (attr == NULL)
+ {
+ return;
+ }
+ sl_attribute_remove_all (attr);
+}
+
+void sl_entity_modified (SlEntity *self, const gchar *attrname)
+{
+ SlAttribute *attr = sl_entity_get_attribute (self, attrname);
+ g_return_if_fail (attr != NULL);
+ sl_attribute_modified (attr);
+}
+
+gboolean sl_entity_modified_at (SlEntity *self, const gchar *attrname, gint index)
+{
+ SlAttribute *attr = sl_entity_get_attribute (self, attrname);
+ g_return_val_if_fail (attr != NULL, FALSE);
+ return sl_attribute_modified_at (attr, index);
}
Modified: trunk/libsoylent/sl-entity-eds.h
==============================================================================
--- trunk/libsoylent/sl-entity-eds.h (original)
+++ trunk/libsoylent/sl-entity-eds.h Mon Aug 11 21:47:53 2008
@@ -27,8 +27,7 @@
#ifndef SL_ENTITY_EDS_H
#define SL_ENTITY_EDS_H
-#include "sl-priv-util.h"
-#include "sl-attribute-eds.h"
+#include "sl-mutual-inclusion.h"
#include <glib.h>
#include <glib-object.h>
@@ -79,26 +78,34 @@
EContact *sl_entity_get_econtact (SlEntity *self);
void sl_entity_set_econtact (SlEntity *self, EContact *econtact);
+SlBook *sl_entity_get_storage (SlEntity *self);
+
gboolean sl_entity_commit (SlEntity *self, GError **error);
+void sl_entity_add_attribute_shallow (SlEntity *self, SlAttribute *attr);
+void sl_entity_remove_attribute_shallow (SlEntity *self, SlAttribute *attr);
+
void sl_entity_add_attribute (SlEntity *self, SlAttribute *attr);
void sl_entity_remove_attribute (SlEntity *self, SlAttribute *attr);
gboolean sl_entity_has_attribute (SlEntity *self, const gchar *attrname);
SlAttribute *sl_entity_get_attribute (SlEntity *self, const gchar *attrname);
-SlAttribute *sl_entity_get_attribute_from_eattr (SlEntity *self, EVCardAttribute *eattr);
GList *sl_entity_get_attributes (SlEntity *self);
-void sl_entity_set (SlEntity *self, const gchar *attrname, gpointer value);
+SlAttribute *sl_entity_get_attribute_from_eattr (SlEntity *self, EVCardAttribute *eattr);
+SlAttribute *sl_entity_get_attribute_create (SlEntity *self, const gchar *attrname);
+
+void sl_entity_add (SlEntity *self, const gchar *attrname, gpointer value);
gpointer sl_entity_get (SlEntity *self, const gchar *attrname);
-void sl_entity_remove (SlEntity *self, const gchar *attrname);
-void sl_entity_set_at (SlEntity *self, const gchar *attrname, gint index,
- gpointer value);
+void sl_entity_set (SlEntity *self, const gchar *attrname, gpointer value);
gpointer sl_entity_get_at (SlEntity *self, const gchar *attrname, gint index);
-void sl_entity_remove_at (SlEntity *self, const gchar *attrname, gint index);
-void sl_entity_set_values (SlEntity *self, const gchar *attrname, GList *values);
-GList *sl_entity_get_values (SlEntity *self, const gchar *attrname);
-void sl_entity_remove_values (SlEntity *self, const gchar *attrname);
-/* TODO: perhaps gboolean instead of void to indicate that an attrname doesn't
- * exist */
+gboolean sl_entity_set_at (SlEntity *self, const gchar *attrname, gint index,
+ gpointer value);
+gboolean sl_entity_remove_at (SlEntity *self, const gchar *attrname,
+ gint index);
+void sl_entity_set_all (SlEntity *self, const gchar *attrname, GList *values);
+GList *sl_entity_get_all (SlEntity *self, const gchar *attrname);
+void sl_entity_remove_all (SlEntity *self, const gchar *attrname);
+void sl_entity_modified (SlEntity *self, const gchar *attrname);
+gboolean sl_entity_modified_at (SlEntity *self, const gchar *attrname, gint index);
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]