diff options
Diffstat (limited to 'calendar/pcs')
-rw-r--r-- | calendar/pcs/cal-backend.c | 73 | ||||
-rw-r--r-- | calendar/pcs/cal-backend.h | 2 | ||||
-rw-r--r-- | calendar/pcs/cal.c | 38 |
3 files changed, 47 insertions, 66 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); } diff --git a/calendar/pcs/cal-backend.h b/calendar/pcs/cal-backend.h index 25a60a859f..e2d5c6c880 100644 --- a/calendar/pcs/cal-backend.h +++ b/calendar/pcs/cal-backend.h @@ -96,7 +96,7 @@ char *cal_backend_get_object (CalBackend *backend, const char *uid); GList *cal_backend_get_uids (CalBackend *backend, CalObjType type); -GList *cal_backend_get_changes (CalBackend *backend, CalObjType type, const char *change_id); +GNOME_Evolution_Calendar_CalObjChangeSeq * cal_backend_get_changes (CalBackend *backend, CalObjType type, const char *change_id); GList *cal_backend_get_objects_in_range (CalBackend *backend, CalObjType type, time_t start, time_t end); diff --git a/calendar/pcs/cal.c b/calendar/pcs/cal.c index a7f0c5dfce..179c850475 100644 --- a/calendar/pcs/cal.c +++ b/calendar/pcs/cal.c @@ -278,35 +278,6 @@ Cal_get_uids (PortableServer_Servant servant, return seq; } -static GNOME_Evolution_Calendar_CalObjChangeSeq * -build_change_seq (GList *changes) -{ - GList *l; - int n, i; - GNOME_Evolution_Calendar_CalObjChangeSeq *seq; - - n = g_list_length (changes); - - seq = GNOME_Evolution_Calendar_CalObjChangeSeq__alloc (); - CORBA_sequence_set_release (seq, TRUE); - seq->_length = n; - seq->_buffer = CORBA_sequence_GNOME_Evolution_Calendar_CalObjChange_allocbuf (n); - - /* Fill the sequence */ - for (i = 0, l = changes; l; i++, l = l->next) { - CalObjChange *c; - GNOME_Evolution_Calendar_CalObjChange *corba_c; - - c = l->data; - corba_c = &seq->_buffer[i]; - - corba_c->calobj = CORBA_string_dup (c->calobj); - corba_c->type = c->type; - } - - return seq; -} - /* Cal::get_changes method */ static GNOME_Evolution_Calendar_CalObjChangeSeq * Cal_get_changes (PortableServer_Servant servant, @@ -316,8 +287,6 @@ Cal_get_changes (PortableServer_Servant servant, { Cal *cal; CalPrivate *priv; - GList *changes; - GNOME_Evolution_Calendar_CalObjChangeSeq *seq; int t; cal = CAL (bonobo_object_from_servant (servant)); @@ -325,12 +294,7 @@ Cal_get_changes (PortableServer_Servant servant, t = uncorba_obj_type (type); - changes = cal_backend_get_changes (priv->backend, t, change_id); - seq = build_change_seq (changes); - - cal_obj_change_list_free (changes); - - return seq; + return cal_backend_get_changes (priv->backend, t, change_id); } /* Cal::get_objects_in_range method */ |