[evolution-data-server/openismus-work-master: 1/2] Bug #652177 - Add "revision" property to calendar file backend
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/openismus-work-master: 1/2] Bug #652177 - Add "revision" property to calendar file backend
- Date: Tue, 22 Nov 2011 09:48:15 +0000 (UTC)
commit 0c4285ba3e97137bef93e7a03d9cb655f5351ea6
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Tue Nov 22 17:58:30 2011 +0900
Bug #652177 - Add "revision" property to calendar file backend
Added "revision" property also now as a common property definition
in e-client.h. revisions are guarunteed to remain the same until there
is a modification to the calendar.
calendar/backends/file/e-cal-backend-file.c | 100 +++++++++++++++++++++++++++
calendar/libecal/e-cal-client.h | 11 +++
calendar/libedata-cal/e-cal-backend.h | 11 +++
libedataserver/e-client.h | 11 +++
4 files changed, 133 insertions(+), 0 deletions(-)
---
diff --git a/calendar/backends/file/e-cal-backend-file.c b/calendar/backends/file/e-cal-backend-file.c
index 5e7d060..f0aa6e5 100644
--- a/calendar/backends/file/e-cal-backend-file.c
+++ b/calendar/backends/file/e-cal-backend-file.c
@@ -52,6 +52,8 @@
#define EDC_ERROR(_code) e_data_cal_create_error (_code, NULL)
#define EDC_ERROR_NO_URI() e_data_cal_create_error (OtherError, "Cannot get URI")
+#define ECAL_REVISION_X_PROP "revision"
+
G_DEFINE_TYPE (ECalBackendFile, e_cal_backend_file, E_TYPE_CAL_BACKEND_SYNC)
/* Placeholder for each component and its recurrences */
@@ -112,6 +114,9 @@ struct _ECalBackendFilePrivate {
/* timeour id for refresh type "2" */
guint refresh_timeout_id;
+
+ /* Just an incremental number to ensure uniqueness across revisions */
+ guint revision_counter;
};
@@ -393,6 +398,82 @@ uid_in_use (ECalBackendFile *cbfile,
+static icalproperty *
+get_revision_property (ECalBackendFile *cbfile)
+{
+ ECalBackendFilePrivate *priv;
+ icalproperty *prop;
+
+ priv = cbfile->priv;
+ prop = icalcomponent_get_first_property (priv->icalcomp, ICAL_X_PROPERTY);
+
+ while (prop != NULL) {
+ const gchar *name = icalproperty_get_x_name (prop);
+
+ if (name && strcmp (name, ECAL_REVISION_X_PROP) == 0)
+ return prop;
+
+ prop = icalcomponent_get_next_property (priv->icalcomp, ICAL_X_PROPERTY);
+ }
+
+ return NULL;
+}
+
+static gchar *
+make_revision_string (ECalBackendFile *cbfile)
+{
+ GTimeVal timeval;
+ gchar *datestr;
+ gchar *revision;
+
+ g_get_current_time (&timeval);
+
+ datestr = g_time_val_to_iso8601 (&timeval);
+ revision = g_strdup_printf ("%s(%d)", datestr, cbfile->priv->revision_counter++);
+
+ g_free (datestr);
+ return revision;
+}
+
+static icalproperty *
+ensure_revision (ECalBackendFile *cbfile)
+{
+ icalproperty* prop;
+
+ prop = get_revision_property (cbfile);
+
+ if (!prop) {
+ gchar *revision = make_revision_string (cbfile);
+
+ prop = icalproperty_new (ICAL_X_COMPONENT);
+
+ icalproperty_set_x_name (prop, ECAL_REVISION_X_PROP);
+ icalproperty_set_x (prop, revision);
+
+ icalcomponent_add_property (cbfile->priv->icalcomp, prop);
+
+ g_free (revision);
+ }
+
+ return prop;
+}
+
+static void
+bump_revision (ECalBackendFile *cbfile)
+{
+ /* Update the revision string */
+ icalproperty *prop = ensure_revision (cbfile);
+ gchar *revision = make_revision_string (cbfile);
+
+ icalproperty_set_x (prop, revision);
+
+ e_cal_backend_notify_property_changed (E_CAL_BACKEND (cbfile),
+ CAL_BACKEND_PROPERTY_REVISION,
+ revision);
+
+ g_free (revision);
+}
+
/* Calendar backend methods */
/* Get_email_address handler for the file backend */
@@ -444,6 +525,14 @@ e_cal_backend_file_get_backend_property (ECalBackendSync *backend,
*prop_value = e_cal_component_get_as_string (comp);
g_object_unref (comp);
+ } else if (g_str_equal (prop_name, CAL_BACKEND_PROPERTY_REVISION)) {
+ icalproperty *prop;
+ const gchar *revision;
+
+ prop = ensure_revision (E_CAL_BACKEND_FILE (backend));
+ revision = icalproperty_get_x (prop);
+
+ *prop_value = g_strdup (revision);
} else {
processed = FALSE;
}
@@ -737,6 +826,7 @@ remove_component (ECalBackendFile *cbfile,
g_hash_table_remove (priv->comp_uid_hash, uid);
+ bump_revision (cbfile);
save (cbfile);
}
@@ -1224,6 +1314,7 @@ create_cal (ECalBackendFile *cbfile,
priv->path = uri_to_path (E_CAL_BACKEND (cbfile));
+ bump_revision (cbfile);
save (cbfile);
g_free (priv->custom_file);
@@ -1573,6 +1664,8 @@ e_cal_backend_file_add_timezone (ECalBackendSync *backend,
if (!icalcomponent_get_timezone (priv->icalcomp,
icaltimezone_get_tzid (zone))) {
icalcomponent_add_component (priv->icalcomp, tz_comp);
+
+ bump_revision (cbfile);
save (cbfile);
}
g_static_rec_mutex_unlock (&priv->idle_save_rmutex);
@@ -2272,6 +2365,9 @@ e_cal_backend_file_create_object (ECalBackendSync *backend,
/* Add the object */
add_component (cbfile, comp, TRUE);
+ /* Bump the overall revision */
+ bump_revision (cbfile);
+
/* Save the file */
save (cbfile);
@@ -2423,6 +2519,7 @@ e_cal_backend_file_modify_object (ECalBackendSync *backend,
e_cal_component_get_icalcomponent (obj_data->full_object));
priv->comp = g_list_prepend (priv->comp, obj_data->full_object);
+ bump_revision (cbfile);
save (cbfile);
if (new_component) {
@@ -2584,6 +2681,7 @@ e_cal_backend_file_modify_object (ECalBackendSync *backend,
break;
}
+ bump_revision (cbfile);
save (cbfile);
g_free (rid);
@@ -2920,6 +3018,7 @@ e_cal_backend_file_remove_object (ECalBackendSync *backend,
break;
}
+ bump_revision (cbfile);
save (cbfile);
g_static_rec_mutex_unlock (&priv->idle_save_rmutex);
@@ -3335,6 +3434,7 @@ e_cal_backend_file_receive_objects (ECalBackendSync *backend,
* resolving any conflicting TZIDs. */
icalcomponent_merge_component (priv->icalcomp, toplevel_comp);
+ bump_revision (cbfile);
save (cbfile);
error:
diff --git a/calendar/libecal/e-cal-client.h b/calendar/libecal/e-cal-client.h
index 3e77baf..ae1da0d 100644
--- a/calendar/libecal/e-cal-client.h
+++ b/calendar/libecal/e-cal-client.h
@@ -66,6 +66,17 @@ G_BEGIN_DECLS
#define CAL_BACKEND_PROPERTY_DEFAULT_OBJECT "default-object"
/**
+ * CAL_BACKEND_PROPERTY_REVISION:
+ *
+ * The current overall revision string, this can be used as
+ * a quick check to see if data has changed at all since the
+ * last time the calendar revision was observed.
+ *
+ * Since: 3.4
+ **/
+#define CAL_BACKEND_PROPERTY_REVISION "revision"
+
+/**
* ECalClientSourceType:
*
* FIXME: Document me.
diff --git a/calendar/libedata-cal/e-cal-backend.h b/calendar/libedata-cal/e-cal-backend.h
index a50c1fc..6c064da 100644
--- a/calendar/libedata-cal/e-cal-backend.h
+++ b/calendar/libedata-cal/e-cal-backend.h
@@ -125,6 +125,17 @@ G_BEGIN_DECLS
**/
#define CAL_BACKEND_PROPERTY_DEFAULT_OBJECT "default-object"
+/**
+ * CAL_BACKEND_PROPERTY_REVISION:
+ *
+ * The current overall revision string, this can be used as
+ * a quick check to see if data has changed at all since the
+ * last time the calendar revision was observed.
+ *
+ * Since: 3.4
+ **/
+#define CAL_BACKEND_PROPERTY_REVISION "revision"
+
struct _ECalBackendCache;
typedef struct _ECalBackendPrivate ECalBackendPrivate;
diff --git a/libedataserver/e-client.h b/libedataserver/e-client.h
index df3338f..fced505 100644
--- a/libedataserver/e-client.h
+++ b/libedataserver/e-client.h
@@ -99,6 +99,17 @@
#define CLIENT_BACKEND_PROPERTY_CAPABILITIES "capabilities"
/**
+ * CLIENT_BACKEND_PROPERTY_REVISION:
+ *
+ * The current overall revision string, this can be used as
+ * a quick check to see if data has changed at all since the
+ * last time the revision was observed.
+ *
+ * Since: 3.4
+ **/
+#define CLIENT_BACKEND_PROPERTY_REVISION "revision"
+
+/**
* E_CLIENT_ERROR:
*
* Error domain for #EClient operations. Errors in this domain will be
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]