From c0f20d73a5e0d6c4af91fff32a53fe5c4ee96e47 Mon Sep 17 00:00:00 2001 From: JP Rosevear Date: Wed, 11 Oct 2000 08:04:27 +0000 Subject: The element is "pilot_id" not "pilotid". Update both maps (compute_pid): 2000-10-11 JP Rosevear * conduits/todo/todo-conduit.c (map_sax_start_element): The element is "pilot_id" not "pilotid". Update both maps (compute_pid): Utility function to set a local records pid (local_record_from_comp): Compute the pid and status here, no longer use the old cal_component pilot interfaces (free_match): Its a *local not a **local * conduits/calendar/calendar-conduit.c: same as above * conduits/todo/todo-conduit.h: Have both a uid and pid map * conduits/todo/calendar-conduit.h: same as above svn path=/trunk/; revision=5836 --- calendar/ChangeLog | 15 +++++ calendar/conduits/calendar/calendar-conduit.c | 87 +++++++++++++------------ calendar/conduits/calendar/calendar-conduit.h | 3 +- calendar/conduits/todo/todo-conduit.c | 92 +++++++++++++++------------ calendar/conduits/todo/todo-conduit.h | 3 +- calendar/pcs/cal-backend.c | 7 +- 6 files changed, 124 insertions(+), 83 deletions(-) diff --git a/calendar/ChangeLog b/calendar/ChangeLog index 94d3bb2e41..78c960378a 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,18 @@ +2000-10-11 JP Rosevear + + * conduits/todo/todo-conduit.c (map_sax_start_element): The + element is "pilot_id" not "pilotid". Update both maps + (compute_pid): Utility function to set a local records pid + (local_record_from_comp): Compute the pid and status here, + no longer use the old cal_component pilot interfaces + (free_match): Its a *local not a **local + + * conduits/calendar/calendar-conduit.c: same as above + + * conduits/todo/todo-conduit.h: Have both a uid and pid map + + * conduits/todo/calendar-conduit.h: same as above + 2000-10-09 JP Rosevear * conduits/*: Adjust to using gnome-pilot-sync-abs conduit which diff --git a/calendar/conduits/calendar/calendar-conduit.c b/calendar/conduits/calendar/calendar-conduit.c index 351526e24d..2a694187ef 100644 --- a/calendar/conduits/calendar/calendar-conduit.c +++ b/calendar/conduits/calendar/calendar-conduit.c @@ -67,7 +67,8 @@ void conduit_destroy_gpilot_conduit (GnomePilotConduit*); #define INFO(e...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, e) /* debug spew DELETE ME */ -static char *print_local (ECalLocalRecord *local) +static char * +print_local (ECalLocalRecord *local) { static char buff[ 4096 ]; @@ -191,16 +192,18 @@ map_sax_start_element (void *data, const xmlChar *name, if (!strcmp (*attrs, "uid")) uid = g_strdup (*val); - if (!strcmp (*attrs, "pilotid")) + if (!strcmp (*attrs, "pilot_id")) *pid = strtoul (*val, NULL, 0); attrs = ++val; } - if (uid && *pid != 0) - g_hash_table_insert (ctxt->map, pid, uid); - else + if (uid && *pid != 0) { + g_hash_table_insert (ctxt->pid_map, pid, uid); + g_hash_table_insert (ctxt->uid_map, uid, pid); + } else { g_free (pid); + } } } @@ -226,7 +229,7 @@ map_write (ECalConduitContext *ctxt, char *filename) xmlDocPtr doc; int ret; - if (ctxt->map == NULL) + if (ctxt->pid_map == NULL) return 0; doc = xmlNewDoc ("1.0"); @@ -237,7 +240,7 @@ map_write (ECalConduitContext *ctxt, char *filename) doc->root = xmlNewDocNode(doc, NULL, "PilotMap", NULL); map_set_node_timet (doc->root, "timestamp", time (NULL)); - g_hash_table_foreach (ctxt->map, map_write_foreach, doc->root); + g_hash_table_foreach (ctxt->pid_map, map_write_foreach, doc->root); /* Write the file */ xmlSetDocCompressMode (doc, 0); @@ -321,6 +324,19 @@ status_to_string (gint status) return "Unknown"; } +static void +compute_pid (ECalConduitContext *ctxt, ECalLocalRecord *local, const char *uid) +{ + guint32 *pid; + + pid = g_hash_table_lookup (ctxt->uid_map, uid); + + if (pid) + local->local.ID = *pid; + else + local->local.ID = 0; +} + static void compute_status (ECalConduitContext *ctxt, ECalLocalRecord *local, const char *uid) { @@ -332,9 +348,9 @@ compute_status (ECalConduitContext *ctxt, ECalLocalRecord *local, const char *ui else if (g_hash_table_lookup (ctxt->modified, uid)) local->local.attr = GnomePilotRecordModified; else if (g_hash_table_lookup (ctxt->deleted, uid)) - local->local.attr = GnomePilotRecordNew; - else local->local.attr = GnomePilotRecordDeleted; + else + local->local.attr = GnomePilotRecordNothing; } static GnomePilotRecord * @@ -368,16 +384,15 @@ local_record_to_pilot_record (ECalLocalRecord *local, * converts a CalComponent object to a ECalLocalRecord */ static void -local_record_from_comp (ECalLocalRecord *local, CalComponent *comp) +local_record_from_comp (ECalLocalRecord *local, CalComponent *comp, ECalConduitContext *ctxt) { + const char *uid; CalComponentText summary; GSList *d_list = NULL; CalComponentText *description; CalComponentDateTime dt; time_t dt_time; CalComponentClassification classif; - unsigned long *pilot_id; - unsigned long *pilot_status; LOG ("local_record_from_comp\n"); @@ -386,6 +401,10 @@ local_record_from_comp (ECalLocalRecord *local, CalComponent *comp) local->comp = comp; + cal_component_get_uid (local->comp, &uid); + compute_pid (ctxt, local, uid); + compute_status (ctxt, local, uid); + local->appt = g_new0 (struct Appointment,1); /* STOP: don't replace these with g_strdup, since free_Appointment @@ -422,17 +441,6 @@ local_record_from_comp (ECalLocalRecord *local, CalComponent *comp) local->appt->event = 1; } - cal_component_get_pilot_id (comp, &pilot_id); - cal_component_get_pilot_status (comp, &pilot_status); - - /* Records without a pilot_id are new */ - if (!pilot_id) { - local->local.attr = GnomePilotRecordNew; - } else { - local->local.ID = *pilot_id; - local->local.attr = *pilot_status; - } - cal_component_get_classification (comp, &classif); if (classif == CAL_COMPONENT_CLASS_PRIVATE) @@ -456,8 +464,7 @@ local_record_from_uid (ECalLocalRecord *local, status = cal_client_get_object (ctxt->client, uid, &comp); if (status == CAL_CLIENT_GET_SUCCESS) { - local_record_from_comp (local, comp); - compute_status (ctxt, local, uid); + local_record_from_comp (local, comp, ctxt); } else { INFO ("Object did not exist"); } @@ -560,7 +567,7 @@ check_for_slow_setting (GnomePilotConduit *c, ECalConduitContext *ctxt) int count, map_count; count = g_list_length (ctxt->uids); - map_count = g_hash_table_size (ctxt->map); + map_count = g_hash_table_size (ctxt->pid_map); /* If there are no objects or objects but no log */ if ((count == 0) || (count > 0 && map_count == 0)) { @@ -590,7 +597,7 @@ update_record (GnomePilotConduitSyncAbs *conduit, memset (&appt, 0, sizeof (struct Appointment)); unpack_Appointment (&appt, remote->record, remote->length); - uid = g_hash_table_lookup (ctxt->map, &remote->ID); + uid = g_hash_table_lookup (ctxt->pid_map, &remote->ID); if (uid) status = cal_client_get_object (ctxt->client, uid, &comp); @@ -614,10 +621,13 @@ update_record (GnomePilotConduitSyncAbs *conduit, if (!uid) { guint32 *pid = g_new (guint32, 1); - + char *new_uid; + *pid = remote->ID; cal_component_get_uid (comp, &uid); - g_hash_table_insert (ctxt->map, pid, g_strdup (uid)); + new_uid = g_strdup (uid); + g_hash_table_insert (ctxt->pid_map, pid, new_uid); + g_hash_table_insert (ctxt->pid_map, new_uid, pid); } gtk_object_unref (GTK_OBJECT (comp)); @@ -658,7 +668,8 @@ pre_sync (GnomePilotConduit *conduit, ctxt->uids = cal_client_get_uids (ctxt->client, CALOBJ_TYPE_EVENT); /* Load the uid <--> pilot id mapping */ - ctxt->map = g_hash_table_new (g_int_hash, g_int_equal); + ctxt->pid_map = g_hash_table_new (g_int_hash, g_int_equal); + ctxt->uid_map = g_hash_table_new (g_str_hash, g_str_equal); filename = map_name (ctxt); if (g_file_exists (filename)) { @@ -678,13 +689,13 @@ pre_sync (GnomePilotConduit *conduit, ctxt->changed = cal_client_get_changed_uids (ctxt->client, CALOBJ_TYPE_EVENT, - ctxt->since); + ctxt->since + 1); for (l = ctxt->changed; l != NULL; l = l->next) { CalObjChange *coc = l->data; switch (coc->type) { case CALOBJ_UPDATED: - if (g_hash_table_lookup (ctxt->map, coc->uid)) + if (g_hash_table_lookup (ctxt->uid_map, coc->uid)) g_hash_table_insert (ctxt->modified, coc->uid, coc); else g_hash_table_insert (ctxt->added, coc->uid, coc); @@ -754,7 +765,7 @@ set_pilot_id (GnomePilotConduitSyncAbs *conduit, cal_component_get_uid (local->comp, &uid); *pid = ID; - g_hash_table_insert (ctxt->map, pid, g_strdup (uid)); + g_hash_table_insert (ctxt->pid_map, pid, g_strdup (uid)); return 0; } @@ -972,7 +983,7 @@ match (GnomePilotConduitSyncAbs *conduit, g_return_val_if_fail (remote != NULL, -1); *local = NULL; - uid = g_hash_table_lookup (ctxt->map, &remote->ID); + uid = g_hash_table_lookup (ctxt->pid_map, &remote->ID); if (!uid) return 0; @@ -987,18 +998,16 @@ match (GnomePilotConduitSyncAbs *conduit, static gint free_match (GnomePilotConduitSyncAbs *conduit, - ECalLocalRecord **local, + ECalLocalRecord *local, ECalConduitContext *ctxt) { LOG ("free_match: freeing\n"); g_return_val_if_fail (local != NULL, -1); - g_return_val_if_fail (*local != NULL, -1); - gtk_object_unref (GTK_OBJECT ((*local)->comp)); - g_free (*local); + gtk_object_unref (GTK_OBJECT (local->comp)); + g_free (local); - *local = NULL; return 0; } diff --git a/calendar/conduits/calendar/calendar-conduit.h b/calendar/conduits/calendar/calendar-conduit.h index 8ce007ae99..b0065610fb 100644 --- a/calendar/conduits/calendar/calendar-conduit.h +++ b/calendar/conduits/calendar/calendar-conduit.h @@ -71,7 +71,8 @@ struct _ECalConduitContext { GHashTable *modified; GHashTable *deleted; - GHashTable *map; + GHashTable *uid_map; + GHashTable *pid_map; }; #endif __CALENDAR_CONDUIT_H__ diff --git a/calendar/conduits/todo/todo-conduit.c b/calendar/conduits/todo/todo-conduit.c index 427e50d8dc..525d85de51 100644 --- a/calendar/conduits/todo/todo-conduit.c +++ b/calendar/conduits/todo/todo-conduit.c @@ -67,7 +67,8 @@ void conduit_destroy_gpilot_conduit (GnomePilotConduit*); #define INFO(e...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, e) /* debug spew DELETE ME */ -static char *print_local (EToDoLocalRecord *local) +static char * +print_local (EToDoLocalRecord *local) { static char buff[ 4096 ]; @@ -195,16 +196,18 @@ map_sax_start_element (void *data, const xmlChar *name, if (!strcmp (*attrs, "uid")) uid = g_strdup (*val); - if (!strcmp (*attrs, "pilotid")) + if (!strcmp (*attrs, "pilot_id")) *pid = strtoul (*val, NULL, 0); attrs = ++val; } - if (uid && *pid != 0) - g_hash_table_insert (ctxt->map, pid, uid); - else + if (uid && *pid != 0) { + g_hash_table_insert (ctxt->pid_map, pid, uid); + g_hash_table_insert (ctxt->uid_map, uid, pid); + } else { g_free (pid); + } } } @@ -230,7 +233,7 @@ map_write (EToDoConduitContext *ctxt, char *filename) xmlDocPtr doc; int ret; - if (ctxt->map == NULL) + if (ctxt->pid_map == NULL) return 0; doc = xmlNewDoc ("1.0"); @@ -241,7 +244,7 @@ map_write (EToDoConduitContext *ctxt, char *filename) doc->root = xmlNewDocNode(doc, NULL, "PilotMap", NULL); map_set_node_timet (doc->root, "timestamp", time (NULL)); - g_hash_table_foreach (ctxt->map, map_write_foreach, doc->root); + g_hash_table_foreach (ctxt->pid_map, map_write_foreach, doc->root); /* Write the file */ xmlSetDocCompressMode (doc, 0); @@ -325,6 +328,19 @@ status_to_string (gint status) return "Unknown"; } +static void +compute_pid (EToDoConduitContext *ctxt, EToDoLocalRecord *local, const char *uid) +{ + guint32 *pid; + + pid = g_hash_table_lookup (ctxt->uid_map, uid); + + if (pid) + local->local.ID = *pid; + else + local->local.ID = 0; +} + static void compute_status (EToDoConduitContext *ctxt, EToDoLocalRecord *local, const char *uid) { @@ -336,9 +352,9 @@ compute_status (EToDoConduitContext *ctxt, EToDoLocalRecord *local, const char * else if (g_hash_table_lookup (ctxt->modified, uid)) local->local.attr = GnomePilotRecordModified; else if (g_hash_table_lookup (ctxt->deleted, uid)) - local->local.attr = GnomePilotRecordNew; - else local->local.attr = GnomePilotRecordDeleted; + else + local->local.attr = GnomePilotRecordNothing; } static GnomePilotRecord * @@ -372,8 +388,9 @@ local_record_to_pilot_record (EToDoLocalRecord *local, * converts a CalComponent object to a EToDoLocalRecord */ static void -local_record_from_comp (EToDoLocalRecord *local, CalComponent *comp) +local_record_from_comp (EToDoLocalRecord *local, CalComponent *comp, EToDoConduitContext *ctxt) { + const char *uid; int *priority; struct icaltimetype *completed; CalComponentText summary; @@ -392,6 +409,10 @@ local_record_from_comp (EToDoLocalRecord *local, CalComponent *comp) local->comp = comp; + cal_component_get_uid (local->comp, &uid); + compute_pid (ctxt, local, uid); + compute_status (ctxt, local, uid); + local->todo = g_new0 (struct ToDo,1); /* STOP: don't replace these with g_strdup, since free_ToDo @@ -433,17 +454,6 @@ local_record_from_comp (EToDoLocalRecord *local, CalComponent *comp) cal_component_free_priority (priority); } - cal_component_get_pilot_id (comp, &pilot_id); - cal_component_get_pilot_status (comp, &pilot_status); - - /* Records without a pilot_id are new */ - if (!pilot_id) { - local->local.attr = GnomePilotRecordNew; - } else { - local->local.ID = *pilot_id; - local->local.attr = *pilot_status; - } - cal_component_get_classification (comp, &classif); if (classif == CAL_COMPONENT_CLASS_PRIVATE) @@ -451,7 +461,7 @@ local_record_from_comp (EToDoLocalRecord *local, CalComponent *comp) else local->local.secret = 0; - local->local.archived = 0; + local->local.archived = 0; } static void @@ -467,8 +477,7 @@ local_record_from_uid (EToDoLocalRecord *local, status = cal_client_get_object (ctxt->client, uid, &comp); if (status == CAL_CLIENT_GET_SUCCESS) { - local_record_from_comp (local, comp); - compute_status (ctxt, local, uid); + local_record_from_comp (local, comp, ctxt); } else { INFO ("Object did not exist"); } @@ -483,7 +492,6 @@ comp_from_remote_record (GnomePilotConduitSyncAbs *conduit, CalComponent *comp; struct ToDo todo; struct icaltimetype now = icaltime_from_timet (time (NULL), FALSE, FALSE); - unsigned long pilot_status = GnomePilotRecordNothing; CalComponentText summary = {NULL, NULL}; CalComponentText description = {NULL, NULL}; CalComponentDateTime dt = {NULL, NULL}; @@ -572,7 +580,7 @@ check_for_slow_setting (GnomePilotConduit *c, EToDoConduitContext *ctxt) int count, map_count; count = g_list_length (ctxt->uids); - map_count = g_hash_table_size (ctxt->map); + map_count = g_hash_table_size (ctxt->pid_map); /* If there are no objects or objects but no log */ if ((count == 0) || (count > 0 && map_count == 0)) { @@ -602,7 +610,7 @@ update_record (GnomePilotConduitSyncAbs *conduit, memset (&todo, 0, sizeof (struct ToDo)); unpack_ToDo (&todo, remote->record, remote->length); - uid = g_hash_table_lookup (ctxt->map, &remote->ID); + uid = g_hash_table_lookup (ctxt->pid_map, &remote->ID); if (uid) status = cal_client_get_object (ctxt->client, uid, &comp); @@ -626,10 +634,13 @@ update_record (GnomePilotConduitSyncAbs *conduit, if (!uid) { guint32 *pid = g_new (guint32, 1); - + char *new_uid; + *pid = remote->ID; cal_component_get_uid (comp, &uid); - g_hash_table_insert (ctxt->map, pid, g_strdup (uid)); + new_uid = g_strdup (uid); + g_hash_table_insert (ctxt->pid_map, pid, new_uid); + g_hash_table_insert (ctxt->pid_map, new_uid, pid); } gtk_object_unref (GTK_OBJECT (comp)); @@ -669,8 +680,9 @@ pre_sync (GnomePilotConduit *conduit, /* Get the local database */ ctxt->uids = cal_client_get_uids (ctxt->client, CALOBJ_TYPE_TODO); - /* Load the uid <--> pilot id mapping */ - ctxt->map = g_hash_table_new (g_int_hash, g_int_equal); + /* Load the uid <--> pilot id mappings */ + ctxt->pid_map = g_hash_table_new (g_int_hash, g_int_equal); + ctxt->uid_map = g_hash_table_new (g_str_hash, g_str_equal); filename = map_name (ctxt); if (g_file_exists (filename)) { @@ -690,13 +702,13 @@ pre_sync (GnomePilotConduit *conduit, ctxt->changed = cal_client_get_changed_uids (ctxt->client, CALOBJ_TYPE_TODO, - ctxt->since); + ctxt->since + 1); for (l = ctxt->changed; l != NULL; l = l->next) { CalObjChange *coc = l->data; switch (coc->type) { case CALOBJ_UPDATED: - if (g_hash_table_lookup (ctxt->map, coc->uid)) + if (g_hash_table_lookup (ctxt->uid_map, coc->uid)) g_hash_table_insert (ctxt->modified, coc->uid, coc); else g_hash_table_insert (ctxt->added, coc->uid, coc); @@ -766,7 +778,7 @@ set_pilot_id (GnomePilotConduitSyncAbs *conduit, cal_component_get_uid (local->comp, &uid); *pid = ID; - g_hash_table_insert (ctxt->map, pid, g_strdup (uid)); + g_hash_table_insert (ctxt->pid_map, pid, g_strdup (uid)); return 0; } @@ -884,7 +896,7 @@ compare (GnomePilotConduitSyncAbs *conduit, int retval = 0; LOG ("compare: local=%s remote=%s...\n", - print_local (local), print_remote (remote)); + print_local (local), print_remote (remote)); g_return_val_if_fail (local!=NULL,-1); g_return_val_if_fail (remote!=NULL,-1); @@ -984,7 +996,7 @@ match (GnomePilotConduitSyncAbs *conduit, g_return_val_if_fail (remote != NULL, -1); *local = NULL; - uid = g_hash_table_lookup (ctxt->map, &remote->ID); + uid = g_hash_table_lookup (ctxt->pid_map, &remote->ID); if (!uid) return 0; @@ -999,18 +1011,16 @@ match (GnomePilotConduitSyncAbs *conduit, static gint free_match (GnomePilotConduitSyncAbs *conduit, - EToDoLocalRecord **local, + EToDoLocalRecord *local, EToDoConduitContext *ctxt) { LOG ("free_match: freeing\n"); g_return_val_if_fail (local != NULL, -1); - g_return_val_if_fail (*local != NULL, -1); - gtk_object_unref (GTK_OBJECT ((*local)->comp)); - g_free (*local); + gtk_object_unref (GTK_OBJECT (local->comp)); + g_free (local); - *local = NULL; return 0; } diff --git a/calendar/conduits/todo/todo-conduit.h b/calendar/conduits/todo/todo-conduit.h index 7b5ec6e43e..ecec89c35a 100644 --- a/calendar/conduits/todo/todo-conduit.h +++ b/calendar/conduits/todo/todo-conduit.h @@ -71,7 +71,8 @@ struct _EToDoConduitContext { GHashTable *modified; GHashTable *deleted; - GHashTable *map; + GHashTable *uid_map; + GHashTable *pid_map; }; #endif __TODO_CONDUIT_H__ diff --git a/calendar/pcs/cal-backend.c b/calendar/pcs/cal-backend.c index d5609d59f1..f07b975413 100644 --- a/calendar/pcs/cal-backend.c +++ b/calendar/pcs/cal-backend.c @@ -498,6 +498,7 @@ cal_backend_log_sync (CalBackend *backend) GSList *l; int ret; time_t start_time = (time_t) - 1; + time_t end_time = (time_t) - 1; g_return_val_if_fail (backend->uri != NULL, FALSE); @@ -552,10 +553,14 @@ cal_backend_log_sync (CalBackend *backend) || entry->time_stamp < start_time) start_time = entry->time_stamp; + if (end_time == (time_t) - 1 + || entry->time_stamp > end_time) + end_time = entry->time_stamp; + g_free (entry); } cal_backend_set_node_timet (tnode, "start", start_time); - cal_backend_set_node_timet (tnode, "end", time (NULL)); + cal_backend_set_node_timet (tnode, "end", end_time); g_slist_free (backend->entries); backend->entries = NULL; -- cgit