[evolution-data-server] Implemented store_remove and get_component_ids api. Fixes a bug



commit 67e8e525d9cef0757d811272bab09f6c4af6170e
Author: Chenthill Palanisamy <pchenthill novell com>
Date:   Mon Jul 20 18:08:53 2009 +0530

    Implemented store_remove and get_component_ids api. Fixes a bug
    in remove_component and removed icaltimezone_copy api usage as
    its does do whats intended.

 calendar/libedata-cal/e-cal-backend-file-store.c |  115 ++++++++++++++++++++--
 calendar/libedata-cal/e-cal-backend-store.c      |   32 +++++--
 calendar/libedata-cal/e-cal-backend-store.h      |   13 ++-
 3 files changed, 142 insertions(+), 18 deletions(-)
---
diff --git a/calendar/libedata-cal/e-cal-backend-file-store.c b/calendar/libedata-cal/e-cal-backend-file-store.c
index 509e416..1790d32 100644
--- a/calendar/libedata-cal/e-cal-backend-file-store.c
+++ b/calendar/libedata-cal/e-cal-backend-file-store.c
@@ -85,6 +85,19 @@ destroy_full_object (FullCompObject *obj)
 	obj = NULL;
 }
 
+static icaltimezone *
+copy_timezone (icaltimezone *zone)
+{
+	icaltimezone *copy;
+	icalcomponent *icalcomp;
+
+	copy = icaltimezone_new ();
+	icalcomp = icaltimezone_get_component (zone);
+	icaltimezone_set_component (copy, icalcomponent_new_clone (icalcomp));
+
+	return copy;
+}
+
 static gboolean
 put_component (ECalBackendFileStore *fstore, ECalComponent *comp)
 {
@@ -147,7 +160,7 @@ remove_component (ECalBackendFileStore *fstore, const gchar *uid, const gchar *r
 		goto end;
 	}
 
-	if (rid != NULL) {
+	if (rid != NULL && *rid) {
 		ret_val = g_hash_table_remove (obj->recurrences, rid);
 
 		if (ret_val && g_hash_table_size (obj->recurrences) == 0 && !obj->comp)
@@ -178,7 +191,7 @@ get_component (ECalBackendFileStore *fstore, const gchar *uid, const gchar *rid)
 	if (obj == NULL)
 		goto end;
 
-	if (rid != NULL)
+	if (rid != NULL && *rid)
 		comp = g_hash_table_lookup (obj->recurrences, rid);
 	else
 		comp = obj->comp;
@@ -203,6 +216,36 @@ e_cal_backend_file_store_get_component (ECalBackendStore *store, const gchar *ui
 }
 
 static gboolean
+e_cal_backend_file_store_has_component (ECalBackendStore *store, const gchar *uid, const gchar *rid)
+{
+	ECalBackendFileStore *fstore = E_CAL_BACKEND_FILE_STORE (store);
+	ECalBackendFileStorePrivate *priv;
+	gboolean ret_val = FALSE;
+	FullCompObject *obj = NULL;
+
+	priv = GET_PRIVATE (fstore);
+
+	g_static_rw_lock_reader_lock (&priv->lock);
+
+	obj = g_hash_table_lookup (priv->comp_uid_hash, uid);
+	if (obj == NULL) {
+		goto end;
+	}
+
+	if (rid != NULL) {
+		ECalComponent *comp = g_hash_table_lookup (obj->recurrences, rid);
+
+		if (comp != NULL)
+			ret_val = TRUE;
+	} else
+		ret_val = TRUE;
+
+end:	
+	g_static_rw_lock_reader_unlock (&priv->lock);
+	return ret_val;
+}
+
+static gboolean
 e_cal_backend_file_store_put_component (ECalBackendStore *store, ECalComponent *comp)
 {
 	ECalBackendFileStore *fstore = E_CAL_BACKEND_FILE_STORE (store);
@@ -271,7 +314,7 @@ e_cal_backend_file_store_put_timezone (ECalBackendStore *store, const icaltimezo
 	priv = GET_PRIVATE (fstore);
 
 	g_static_rw_lock_writer_lock (&priv->lock);
-	copy = icaltimezone_copy ((icaltimezone *) zone);
+	copy = copy_timezone ((icaltimezone *) zone);
 	g_hash_table_insert (priv->timezones, g_strdup (icaltimezone_get_tzid ((icaltimezone *) zone)), copy);
 	g_static_rw_lock_writer_unlock (&priv->lock);
 
@@ -381,7 +424,7 @@ e_cal_backend_file_store_set_default_timezone (ECalBackendStore *store, const ic
 	g_static_rw_lock_writer_lock (&priv->lock);
 
 	tzid = icaltimezone_get_tzid ((icaltimezone*) zone);
-	copy = icaltimezone_copy ((icaltimezone *) zone);
+	copy = copy_timezone ((icaltimezone *) zone);
 	g_hash_table_insert (priv->timezones, g_strdup (tzid), copy);
 
 	if (e_file_cache_get_object (priv->keys_cache, key))
@@ -492,6 +535,48 @@ e_cal_backend_file_store_get_components (ECalBackendStore *store)
 }
 
 static void
+add_instance_ids_to_slist (gpointer key, gpointer value, gpointer user_data)
+{
+	GSList **slist = (GSList **) user_data;
+	ECalComponent *comp = (ECalComponent *) value;
+	ECalComponentId *id = e_cal_component_get_id (comp);
+
+	*slist = g_slist_prepend (*slist, id);
+}
+
+static void
+add_comp_ids_to_slist (gpointer key, gpointer value, gpointer user_data)
+{
+	GSList **slist = (GSList **) user_data;
+	FullCompObject *obj = NULL;
+	
+	obj = value;
+	if (obj->comp) {
+		ECalComponentId *id = e_cal_component_get_id (obj->comp);
+
+		*slist = g_slist_prepend (*slist, id);
+	}
+
+	g_hash_table_foreach (obj->recurrences, (GHFunc) add_instance_ids_to_slist, slist);
+}
+
+static GSList *
+e_cal_backend_file_store_get_component_ids (ECalBackendStore *store)
+{
+	ECalBackendFileStore *fstore = E_CAL_BACKEND_FILE_STORE (store);
+	ECalBackendFileStorePrivate *priv;
+	GSList *comp_ids = NULL;
+	
+	priv = GET_PRIVATE (fstore);
+
+	g_static_rw_lock_reader_lock (&priv->lock);
+	g_hash_table_foreach (priv->comp_uid_hash, (GHFunc) add_comp_ids_to_slist, &comp_ids);
+	g_static_rw_lock_reader_unlock (&priv->lock);
+
+	return comp_ids;
+}
+
+static void
 add_timezone (ECalBackendFileStore *fstore, icalcomponent *vtzcomp)
 {
 	ECalBackendFileStorePrivate *priv;
@@ -594,7 +679,21 @@ e_cal_backend_file_store_load (ECalBackendStore *store)
 static gboolean
 e_cal_backend_file_store_remove (ECalBackendStore *store)
 {
-	
+	ECalBackendFileStore *fstore = E_CAL_BACKEND_FILE_STORE (store);
+	ECalBackendFileStorePrivate *priv;
+
+	priv = GET_PRIVATE (store);
+
+	/* This will remove all the contents in the directory */
+	e_file_cache_remove (priv->keys_cache);
+
+	g_hash_table_destroy (priv->timezones);
+	priv->timezones = NULL;
+
+	g_hash_table_destroy (priv->comp_uid_hash);
+	priv->comp_uid_hash = NULL;
+
+	return TRUE;
 }
 
 static void
@@ -778,17 +877,19 @@ e_cal_backend_file_store_class_init (ECalBackendFileStoreClass *klass)
 	store_class->get_component = e_cal_backend_file_store_get_component;
 	store_class->put_component = e_cal_backend_file_store_put_component;
 	store_class->remove_component = e_cal_backend_file_store_remove_component;
+	store_class->has_component = e_cal_backend_file_store_has_component;
 	store_class->get_timezone = e_cal_backend_file_store_get_timezone;
 	store_class->put_timezone = e_cal_backend_file_store_put_timezone;
 	store_class->remove_timezone = e_cal_backend_file_store_remove_timezone;
 	store_class->get_default_timezone = e_cal_backend_file_store_get_default_timezone;
 	store_class->set_default_timezone = e_cal_backend_file_store_set_default_timezone;
 	store_class->get_components_by_uid = e_cal_backend_file_store_get_components_by_uid;
-	store_class->get_key = e_cal_backend_file_store_get_key_value;
-	store_class->put_key = e_cal_backend_file_store_put_key_value;
+	store_class->get_key_value = e_cal_backend_file_store_get_key_value;
+	store_class->put_key_value = e_cal_backend_file_store_put_key_value;
 	store_class->thaw_changes = e_cal_backend_file_store_thaw_changes;
 	store_class->freeze_changes = e_cal_backend_file_store_freeze_changes;
 	store_class->get_components = e_cal_backend_file_store_get_components;
+	store_class->get_component_ids = e_cal_backend_file_store_get_component_ids;
 }
 
 static void
diff --git a/calendar/libedata-cal/e-cal-backend-store.c b/calendar/libedata-cal/e-cal-backend-store.c
index 1380399..fbdef34 100644
--- a/calendar/libedata-cal/e-cal-backend-store.c
+++ b/calendar/libedata-cal/e-cal-backend-store.c
@@ -185,8 +185,8 @@ e_cal_backend_store_class_init (ECalBackendStoreClass *klass)
 	klass->get_default_timezone = NULL;
 	klass->set_default_timezone = NULL;
 	klass->get_components_by_uid = NULL;
-	klass->get_key = NULL;
-	klass->put_key = NULL;
+	klass->get_key_value = NULL;
+	klass->put_key_value = NULL;
 
 	g_object_class_install_property (object_class, PROP_SOURCE_TYPE,
 		  		g_param_spec_enum ("source_type", NULL, NULL,
@@ -249,12 +249,21 @@ e_cal_backend_store_get_component (ECalBackendStore *store, const gchar *uid, co
 	g_return_val_if_fail (store != NULL, NULL);
 	g_return_val_if_fail (E_IS_CAL_BACKEND_STORE (store), NULL);
 	g_return_val_if_fail (uid != NULL, NULL);
-	g_return_val_if_fail (rid != NULL, NULL);
 
 	return (E_CAL_BACKEND_STORE_GET_CLASS (store))->get_component (store, uid, rid);
 }
 
 gboolean
+e_cal_backend_store_has_component (ECalBackendStore *store, const gchar *uid, const gchar *rid)
+{
+	g_return_val_if_fail (store != NULL, FALSE);
+	g_return_val_if_fail (E_IS_CAL_BACKEND_STORE (store), FALSE);
+	g_return_val_if_fail (uid != NULL, FALSE);
+
+	return (E_CAL_BACKEND_STORE_GET_CLASS (store))->has_component (store, uid, rid);
+}
+
+gboolean
 e_cal_backend_store_put_component (ECalBackendStore *store, ECalComponent *comp)
 {
 	g_return_val_if_fail (store != NULL, FALSE);
@@ -344,24 +353,33 @@ e_cal_backend_store_get_components (ECalBackendStore *store)
 	return (E_CAL_BACKEND_STORE_GET_CLASS (store))->get_components (store);
 }
 
+GSList *
+e_cal_backend_store_get_component_ids (ECalBackendStore *store)
+{
+	g_return_val_if_fail (store != NULL, NULL);
+	g_return_val_if_fail (E_IS_CAL_BACKEND_STORE (store), NULL);
+
+	return (E_CAL_BACKEND_STORE_GET_CLASS (store))->get_component_ids (store);
+}
+
 const gchar *
-e_cal_backend_store_get_key (ECalBackendStore *store, const gchar *key)
+e_cal_backend_store_get_key_value (ECalBackendStore *store, const gchar *key)
 {
 	g_return_val_if_fail (store != NULL, NULL);
 	g_return_val_if_fail (E_IS_CAL_BACKEND_STORE (store), NULL);
 	g_return_val_if_fail (key != NULL, NULL);
 
-	return (E_CAL_BACKEND_STORE_GET_CLASS (store))->get_key (store, key);
+	return (E_CAL_BACKEND_STORE_GET_CLASS (store))->get_key_value (store, key);
 }
 
 gboolean
-e_cal_backend_store_put_key (ECalBackendStore *store, const gchar *key, const gchar *value)
+e_cal_backend_store_put_key_value (ECalBackendStore *store, const gchar *key, const gchar *value)
 {
 	g_return_val_if_fail (store != NULL, FALSE);
 	g_return_val_if_fail (E_IS_CAL_BACKEND_STORE (store), FALSE);
 	g_return_val_if_fail (key != NULL, FALSE);
 
-	return (E_CAL_BACKEND_STORE_GET_CLASS (store))->put_key (store, key, value);
+	return (E_CAL_BACKEND_STORE_GET_CLASS (store))->put_key_value (store, key, value);
 }
 
 void
diff --git a/calendar/libedata-cal/e-cal-backend-store.h b/calendar/libedata-cal/e-cal-backend-store.h
index 6b4f5bd..8cef0f2 100644
--- a/calendar/libedata-cal/e-cal-backend-store.h
+++ b/calendar/libedata-cal/e-cal-backend-store.h
@@ -62,8 +62,11 @@ typedef struct {
 	ECalComponent *	(*get_component) (ECalBackendStore *store, const gchar *uid, const gchar *rid);
 	gboolean 	(*put_component) (ECalBackendStore *store, ECalComponent *comp);
 	gboolean 	(*remove_component) (ECalBackendStore *store, const gchar *uid, const gchar *rid);
+	gboolean	(*has_component) (ECalBackendStore *store, const char *uid, const char *rid);
+	
 	GSList *	(*get_components_by_uid) (ECalBackendStore *store, const gchar *uid);
 	GSList *	(*get_components) (ECalBackendStore *store);
+	GSList *	(*get_component_ids) (ECalBackendStore *store);
 
 	const icaltimezone *	(*get_timezone) (ECalBackendStore *store, const gchar *tzid);
 	gboolean	(*put_timezone) (ECalBackendStore *store, const icaltimezone *zone);
@@ -75,8 +78,8 @@ typedef struct {
 	void	(*thaw_changes) (ECalBackendStore *store);
 	void	(*freeze_changes) (ECalBackendStore *store);
 
-	const gchar *(*get_key) (ECalBackendStore *store, const gchar *key);
-	gboolean (*put_key) (ECalBackendStore *store, const gchar *key, const gchar *value);
+	const gchar *(*get_key_value) (ECalBackendStore *store, const gchar *key);
+	gboolean (*put_key_value) (ECalBackendStore *store, const gchar *key, const gchar *value);
 
 } ECalBackendStoreClass;
 
@@ -89,6 +92,7 @@ gboolean		e_cal_backend_store_remove (ECalBackendStore *store);
 ECalComponent *		e_cal_backend_store_get_component (ECalBackendStore *store, const gchar *uid, const gchar *rid);
 gboolean 		e_cal_backend_store_put_component (ECalBackendStore *store, ECalComponent *comp);
 gboolean 		e_cal_backend_store_remove_component (ECalBackendStore *store, const gchar *uid, const gchar *rid);
+gboolean		e_cal_backend_store_has_component (ECalBackendStore *store, const gchar *uid, const gchar *rid);
 const icaltimezone *	e_cal_backend_store_get_timezone (ECalBackendStore *store, const gchar *tzid);
 gboolean 		e_cal_backend_store_put_timezone (ECalBackendStore *store, const icaltimezone *zone);
 gboolean 		e_cal_backend_store_remove_timezone (ECalBackendStore *store, const gchar *tzid);
@@ -96,8 +100,9 @@ const icaltimezone *	e_cal_backend_store_get_default_timezone (ECalBackendStore
 gboolean 		e_cal_backend_store_set_default_timezone (ECalBackendStore *store, const icaltimezone *zone);
 GSList *		e_cal_backend_store_get_components_by_uid (ECalBackendStore *store, const gchar *uid);
 GSList *		e_cal_backend_store_get_components (ECalBackendStore *store);
-const gchar *		e_cal_backend_store_get_key (ECalBackendStore *store, const gchar *key);
-gboolean 		e_cal_backend_store_put_key (ECalBackendStore *store, const gchar *key, const gchar *value);
+GSList *		e_cal_backend_store_get_component_ids (ECalBackendStore *store);
+const gchar *		e_cal_backend_store_get_key_value (ECalBackendStore *store, const gchar *key);
+gboolean 		e_cal_backend_store_put_key_value (ECalBackendStore *store, const gchar *key, const gchar *value);
 void			e_cal_backend_store_thaw_changes (ECalBackendStore *store);
 void			e_cal_backend_store_freeze_changes (ECalBackendStore *store);
 



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