aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/pcs/cal-backend-file.c
diff options
context:
space:
mode:
authorJP Rosevear <jpr@ximian.com>2001-02-09 06:34:14 +0800
committerJP Rosevear <jpr@src.gnome.org>2001-02-09 06:34:14 +0800
commitfd277e89cfa040dcd1b79c10840e5afffaad80a4 (patch)
treeb0bb54c23db4e31d508e925052d929adb8b90726 /calendar/pcs/cal-backend-file.c
parentd85e3c92787852430d68b07da7c0398c906f7856 (diff)
downloadgsoc2013-evolution-fd277e89cfa040dcd1b79c10840e5afffaad80a4.tar.gz
gsoc2013-evolution-fd277e89cfa040dcd1b79c10840e5afffaad80a4.tar.zst
gsoc2013-evolution-fd277e89cfa040dcd1b79c10840e5afffaad80a4.zip
Move the get_change code here
2001-02-08 JP Rosevear <jpr@ximian.com> * pcs/cal-backend-file.c: Move the get_change code here * pcs/cal-backend.c: Remove get_changes related stuff and implement by calling the virtual method instead * pcs/cal-backend.h: New virtual method. * pcs/cal-backend-file.c (compute_alarm_range): Use icaldurationtype_as_int (replace _as_timet) (add_alarm_occurrences_cb): ditto svn path=/trunk/; revision=8123
Diffstat (limited to 'calendar/pcs/cal-backend-file.c')
-rw-r--r--calendar/pcs/cal-backend-file.c144
1 files changed, 142 insertions, 2 deletions
diff --git a/calendar/pcs/cal-backend-file.c b/calendar/pcs/cal-backend-file.c
index 87d8ec3891..b3b3196324 100644
--- a/calendar/pcs/cal-backend-file.c
+++ b/calendar/pcs/cal-backend-file.c
@@ -22,6 +22,7 @@
#include <config.h>
#include <gtk/gtksignal.h>
+#include "e-util/e-dbhash.h"
#include "cal-util/cal-recur.h"
#include "cal-backend-file.h"
@@ -75,6 +76,8 @@ static CalObjType cal_backend_file_get_type_by_uid (CalBackend *backend, const c
static GList *cal_backend_file_get_uids (CalBackend *backend, CalObjType type);
static GList *cal_backend_file_get_objects_in_range (CalBackend *backend, CalObjType type,
time_t start, time_t end);
+static GNOME_Evolution_Calendar_CalObjChangeSeq *cal_backend_file_get_changes (
+ CalBackend *backend, CalObjType type, const char *change_id);
static GNOME_Evolution_Calendar_CalComponentAlarmsSeq *cal_backend_file_get_alarms_in_range (
CalBackend *backend, time_t start, time_t end);
@@ -145,6 +148,7 @@ cal_backend_file_class_init (CalBackendFileClass *class)
backend_class->get_type_by_uid = cal_backend_file_get_type_by_uid;
backend_class->get_uids = cal_backend_file_get_uids;
backend_class->get_objects_in_range = cal_backend_file_get_objects_in_range;
+ backend_class->get_changes = cal_backend_file_get_changes;
backend_class->get_alarms_in_range = cal_backend_file_get_alarms_in_range;
backend_class->get_alarms_for_object = cal_backend_file_get_alarms_for_object;
backend_class->update_object = cal_backend_file_update_object;
@@ -947,6 +951,142 @@ cal_backend_file_get_objects_in_range (CalBackend *backend, CalObjType type,
return event_list;
}
+
+typedef struct
+{
+ CalBackend *backend;
+ GList *changes;
+ GList *change_ids;
+} CalBackendFileComputeChangesData;
+
+static void
+cal_backend_file_compute_changes_foreach_key (const char *key, gpointer data)
+{
+ CalBackendFileComputeChangesData *be_data = data;
+ char *calobj = cal_backend_get_object (be_data->backend, key);
+
+ if (calobj == NULL) {
+ CalComponent *comp;
+ GNOME_Evolution_Calendar_CalObjChange *coc;
+
+ comp = cal_component_new ();
+ cal_component_set_new_vtype (comp, CAL_COMPONENT_TODO);
+ cal_component_set_uid (comp, key);
+
+ coc = GNOME_Evolution_Calendar_CalObjChange__alloc ();
+ coc->calobj = CORBA_string_dup (cal_component_get_as_string (comp));
+ coc->type = GNOME_Evolution_Calendar_DELETED;
+ be_data->changes = g_list_prepend (be_data->changes, coc);
+ be_data->change_ids = g_list_prepend (be_data->change_ids, (gpointer) key);
+ }
+}
+
+static GNOME_Evolution_Calendar_CalObjChangeSeq *
+cal_backend_file_compute_changes (CalBackend *backend, CalObjType type, const char *change_id)
+{
+ char *filename;
+ EDbHash *ehash;
+ CalBackendFileComputeChangesData be_data;
+ GNOME_Evolution_Calendar_CalObjChangeSeq *seq;
+ GList *uids, *changes = NULL, *change_ids = NULL;
+ GList *i, *j;
+ int n;
+
+ /* Find the changed ids - FIX ME, path should not be hard coded */
+ if (type == GNOME_Evolution_Calendar_TYPE_TODO)
+ filename = g_strdup_printf ("%s/evolution/local/Tasks/%s.db", g_get_home_dir (), change_id);
+ else
+ filename = g_strdup_printf ("%s/evolution/local/Calendar/%s.db", g_get_home_dir (), change_id);
+ ehash = e_dbhash_new (filename);
+ g_free (filename);
+
+ uids = cal_backend_get_uids (backend, type);
+
+ /* Calculate adds and modifies */
+ for (i = uids; i != NULL; i = i->next) {
+ GNOME_Evolution_Calendar_CalObjChange *coc;
+ char *uid = i->data;
+ char *calobj = cal_backend_get_object (backend, uid);
+
+ g_assert (calobj != NULL);
+
+ /* check what type of change has occurred, if any */
+ switch (e_dbhash_compare (ehash, uid, calobj)) {
+ case E_DBHASH_STATUS_SAME:
+ break;
+ case E_DBHASH_STATUS_NOT_FOUND:
+ coc = GNOME_Evolution_Calendar_CalObjChange__alloc ();
+ coc->calobj = CORBA_string_dup (calobj);
+ coc->type = GNOME_Evolution_Calendar_ADDED;
+ changes = g_list_prepend (changes, coc);
+ change_ids = g_list_prepend (change_ids, uid);
+ break;
+ case E_DBHASH_STATUS_DIFFERENT:
+ coc = GNOME_Evolution_Calendar_CalObjChange__alloc ();
+ coc->calobj = CORBA_string_dup (calobj);
+ coc->type = GNOME_Evolution_Calendar_ADDED;
+ changes = g_list_append (changes, coc);
+ change_ids = g_list_prepend (change_ids, uid);
+ break;
+ }
+ }
+
+ /* Calculate deletions */
+ be_data.backend = backend;
+ be_data.changes = changes;
+ be_data.change_ids = change_ids;
+ e_dbhash_foreach_key (ehash, (EDbHashFunc)cal_backend_file_compute_changes_foreach_key, &be_data);
+ changes = be_data.changes;
+ change_ids = be_data.change_ids;
+
+ /* Build the sequence and update the hash */
+ n = g_list_length (changes);
+
+ seq = GNOME_Evolution_Calendar_CalObjChangeSeq__alloc ();
+ seq->_length = n;
+ seq->_buffer = CORBA_sequence_GNOME_Evolution_Calendar_CalObjChange_allocbuf (n);
+ CORBA_sequence_set_release (seq, TRUE);
+
+ for (i = changes, j = change_ids, n = 0; i != NULL; i = i->next, j = j->next, n++) {
+ GNOME_Evolution_Calendar_CalObjChange *coc = i->data;
+ GNOME_Evolution_Calendar_CalObjChange *seq_coc;
+ char *uid = j->data;
+
+ /* sequence building */
+ seq_coc = &seq->_buffer[n];
+ seq_coc->calobj = CORBA_string_dup (coc->calobj);
+ seq_coc->type = coc->type;
+
+ /* hash updating */
+ if (coc->type == GNOME_Evolution_Calendar_ADDED
+ || coc->type == GNOME_Evolution_Calendar_MODIFIED) {
+ e_dbhash_add (ehash, uid, coc->calobj);
+ } else {
+ e_dbhash_remove (ehash, uid);
+ }
+
+ CORBA_free (coc);
+ }
+ e_dbhash_write (ehash);
+ e_dbhash_destroy (ehash);
+
+ cal_obj_uid_list_free (uids);
+ g_list_free (change_ids);
+ g_list_free (changes);
+
+ return seq;
+}
+
+/* Get_changes handler for the file backend */
+static GNOME_Evolution_Calendar_CalObjChangeSeq *
+cal_backend_file_get_changes (CalBackend *backend, CalObjType type, const char *change_id)
+{
+ g_return_val_if_fail (backend != NULL, NULL);
+ g_return_val_if_fail (IS_CAL_BACKEND (backend), NULL);
+
+ return cal_backend_file_compute_changes (backend, type, change_id);
+}
+
/* Computes the range of time in which recurrences should be generated for a
* component in order to compute alarm trigger times.
*/
@@ -981,7 +1121,7 @@ compute_alarm_range (CalComponent *comp, GList *alarm_uids, time_t start, time_t
case CAL_ALARM_TRIGGER_RELATIVE_START:
case CAL_ALARM_TRIGGER_RELATIVE_END:
dur = &trigger.u.rel_duration;
-/* dur_time = icaldurationtype_as_timet (*dur); */
+ dur_time = icaldurationtype_as_int (*dur);
if (dur->is_neg)
*alarm_end = MAX (*alarm_end, end + dur_time);
@@ -1042,7 +1182,7 @@ add_alarm_occurrences_cb (CalComponent *comp, time_t start, time_t end, gpointer
continue;
dur = &trigger.u.rel_duration;
-/* dur_time = icaldurationtype_as_timet (*dur); */
+ dur_time = icaldurationtype_as_int (*dur);
if (trigger.type == CAL_ALARM_TRIGGER_RELATIVE_START)
occur_time = start;