aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/pcs/cal-backend.c
diff options
context:
space:
mode:
Diffstat (limited to 'calendar/pcs/cal-backend.c')
-rw-r--r--calendar/pcs/cal-backend.c73
1 files changed, 45 insertions, 28 deletions
diff --git a/calendar/pcs/cal-backend.c b/calendar/pcs/cal-backend.c
index b17b036c27..5b95f2b80a 100644
--- a/calendar/pcs/cal-backend.c
+++ b/calendar/pcs/cal-backend.c
@@ -305,24 +305,27 @@ cal_backend_compute_changes_foreach_key (const char *key, gpointer data)
char *calobj = cal_backend_get_object (be_data->backend, key);
if (calobj == NULL) {
- CalObjChange *coc = g_new0 (CalObjChange, 1);
+ GNOME_Evolution_Calendar_CalObjChange *coc;
- coc->calobj = g_strdup (calobj);
- coc->type = CALOBJ_DELETED;
+ coc = GNOME_Evolution_Calendar_CalObjChange__alloc ();
+ coc->calobj = CORBA_string_dup (calobj);
+ 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 GList *
+static GNOME_Evolution_Calendar_CalObjChangeSeq *
cal_backend_compute_changes (CalBackend *backend, CalObjType type, const char *change_id)
{
char *filename;
EDbHash *ehash;
CalBackendComputeChangesData 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 */
filename = g_strdup_printf ("%s/evolution/local/Calendar/%s.db", g_get_home_dir (), change_id);
ehash = e_dbhash_new (filename);
@@ -332,10 +335,10 @@ cal_backend_compute_changes (CalBackend *backend, CalObjType type, const char *c
/* Calculate adds and modifies */
for (i = uids; i != NULL; i = i->next) {
- CalObjChange *coc;
+ 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 */
@@ -343,16 +346,16 @@ cal_backend_compute_changes (CalBackend *backend, CalObjType type, const char *c
case E_DBHASH_STATUS_SAME:
break;
case E_DBHASH_STATUS_NOT_FOUND:
- coc = g_new0 (CalObjChange, 1);
- coc->calobj = g_strdup (calobj);
- coc->type = CALOBJ_ADDED;
+ 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 = g_new0 (CalObjChange, 1);
- coc->calobj = g_strdup (calobj);
- coc->type = CALOBJ_MODIFIED;
+ 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;
@@ -367,24 +370,42 @@ cal_backend_compute_changes (CalBackend *backend, CalObjType type, const char *c
changes = be_data.changes;
change_ids = be_data.change_ids;
- /* Update the hash */
- for (i = changes, j = change_ids; i != NULL; i = i->next, j = j->next) {
- CalObjChange *coc = i->data;
+ /* 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;
-
- if (coc->type == CALOBJ_ADDED || coc->type == CALOBJ_MODIFIED) {
+
+ /* 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);
-
- return changes;
+ g_list_free (changes);
+
+ return seq;
}
/**
@@ -397,17 +418,13 @@ cal_backend_compute_changes (CalBackend *backend, CalObjType type, const char *c
*
* Return value:
**/
-GList *
+GNOME_Evolution_Calendar_CalObjChangeSeq *
cal_backend_get_changes (CalBackend *backend, CalObjType type, const char *change_id)
{
- GList *changes = NULL;
-
g_return_val_if_fail (backend != NULL, NULL);
g_return_val_if_fail (IS_CAL_BACKEND (backend), NULL);
- changes = cal_backend_compute_changes (backend, type, change_id);
-
- return changes;
+ return cal_backend_compute_changes (backend, type, change_id);
}