aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/conduits/todo/todo-conduit.c
diff options
context:
space:
mode:
Diffstat (limited to 'calendar/conduits/todo/todo-conduit.c')
-rw-r--r--calendar/conduits/todo/todo-conduit.c92
1 files changed, 51 insertions, 41 deletions
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);
@@ -326,6 +329,19 @@ status_to_string (gint status)
}
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)
{
local->local.archived = FALSE;
@@ -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;
}