diff options
Diffstat (limited to 'e-util')
-rw-r--r-- | e-util/ChangeLog | 12 | ||||
-rw-r--r-- | e-util/e-pilot-map.c | 108 | ||||
-rw-r--r-- | e-util/e-pilot-map.h | 2 |
3 files changed, 81 insertions, 41 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog index 072e9bab22..c30b28cbac 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,5 +1,17 @@ 2001-10-26 JP Rosevear <jpr@ximian.com> + * e-pilot-map.c (real_e_pilot_map_insert): take an extra param on + whether to mark touched + (map_sax_start_element): use above + (e_pilot_map_insert): ditto + (e_pilot_map_write): pass in extra info to foreach call + (map_write_foreach): if we are in touched only mode, write out the + map only if its been touched + + * e-pilot-map.h: add new member + +2001-10-26 JP Rosevear <jpr@ximian.com> + * e-pilot-map.c (map_sax_start_element): add archived records with pilot id of 0 (map_write_foreach): use the uid map for writing diff --git a/e-util/e-pilot-map.c b/e-util/e-pilot-map.c index 48f2b7193d..92daa01637 100644 --- a/e-util/e-pilot-map.c +++ b/e-util/e-pilot-map.c @@ -33,14 +33,65 @@ typedef struct { char *uid; gboolean archived; + gboolean touched; } EPilotMapPidNode; typedef struct { guint32 pid; gboolean archived; + gboolean touched; } EPilotMapUidNode; +typedef struct +{ + gboolean touched_only; + xmlNodePtr root; +} EPilotMapWriteData; + +static void +real_e_pilot_map_insert (EPilotMap *map, guint32 pid, const char *uid, gboolean archived, gboolean touch) +{ + char *new_uid; + guint32 *new_pid; + EPilotMapPidNode *pnode; + EPilotMapUidNode *unode; + gpointer key, value; + + g_return_if_fail (map != NULL); + g_return_if_fail (uid != NULL); + + new_pid = g_new (guint32, 1); + *new_pid = pid; + + new_uid = g_strdup (uid); + + pnode = g_new0 (EPilotMapPidNode, 1); + pnode->uid = new_uid; + pnode->archived = archived; + if (touch) + pnode->touched = TRUE; + + unode = g_new0 (EPilotMapUidNode, 1); + unode->pid = pid; + unode->archived = archived; + if (touch) + unode->touched = TRUE; + + if (g_hash_table_lookup_extended (map->pid_map, new_pid, &key, &value)) { + g_hash_table_remove (map->pid_map, new_pid); + g_free (key); + g_free (value); + } + if (g_hash_table_lookup_extended (map->uid_map, new_uid, &key, &value)) { + g_hash_table_remove (map->uid_map, new_uid); + g_free (key); + g_free (value); + } + + g_hash_table_insert (map->pid_map, new_pid, pnode); + g_hash_table_insert (map->uid_map, new_uid, unode); +} static void map_set_node_timet (xmlNodePtr node, const char *name, time_t t) @@ -94,26 +145,30 @@ map_sax_start_element (void *data, const xmlChar *name, g_assert (uid != NULL); g_assert (pid != 0 || archived); - e_pilot_map_insert (map, pid, uid, archived); + real_e_pilot_map_insert (map, pid, uid, archived, FALSE); } } static void map_write_foreach (gpointer key, gpointer value, gpointer data) { - xmlNodePtr root = data; - xmlNodePtr mnode; + EPilotMapWriteData *wd = data; + xmlNodePtr root = wd->root; char *uid = key; EPilotMapUidNode *unode = value; - char *pidstr; + xmlNodePtr mnode; + if (wd->touched_only && !unode->touched) + return; + mnode = xmlNewChild (root, NULL, "map", NULL); - xmlSetProp (mnode, "uid", uid); if (unode->archived) { xmlSetProp (mnode, "archived", "1"); } else { + char *pidstr; + pidstr = g_strdup_printf ("%d", unode->pid); xmlSetProp (mnode, "pilot_id", pidstr); g_free (pidstr); @@ -155,41 +210,7 @@ e_pilot_map_uid_is_archived (EPilotMap *map, const char *uid) void e_pilot_map_insert (EPilotMap *map, guint32 pid, const char *uid, gboolean archived) { - char *new_uid; - guint32 *new_pid; - EPilotMapPidNode *pnode; - EPilotMapUidNode *unode; - gpointer key, value; - - g_return_if_fail (map != NULL); - g_return_if_fail (uid != NULL); - - new_pid = g_new (guint32, 1); - *new_pid = pid; - - new_uid = g_strdup (uid); - - pnode = g_new0 (EPilotMapPidNode, 1); - pnode->uid = new_uid; - pnode->archived = archived; - - unode = g_new0 (EPilotMapUidNode, 1); - unode->pid = pid; - unode->archived = archived; - - if (g_hash_table_lookup_extended (map->pid_map, new_pid, &key, &value)) { - g_hash_table_remove (map->pid_map, new_pid); - g_free (key); - g_free (value); - } - if (g_hash_table_lookup_extended (map->uid_map, new_uid, &key, &value)) { - g_hash_table_remove (map->uid_map, new_uid); - g_free (key); - g_free (value); - } - - g_hash_table_insert (map->pid_map, new_pid, pnode); - g_hash_table_insert (map->uid_map, new_uid, unode); + real_e_pilot_map_insert (map, pid, uid, archived, TRUE); } void @@ -291,6 +312,8 @@ e_pilot_map_read (const char *filename, EPilotMap **map) return -1; } } + + new_map->write_touched_only = FALSE; *map = new_map; @@ -300,6 +323,7 @@ e_pilot_map_read (const char *filename, EPilotMap **map) int e_pilot_map_write (const char *filename, EPilotMap *map) { + EPilotMapWriteData wd; xmlDocPtr doc; int ret; @@ -315,7 +339,9 @@ e_pilot_map_write (const char *filename, EPilotMap *map) map->since = time (NULL); map_set_node_timet (doc->root, "timestamp", map->since); - g_hash_table_foreach (map->uid_map, map_write_foreach, doc->root); + wd.touched_only = map->write_touched_only; + wd.root = doc->root; + g_hash_table_foreach (map->uid_map, map_write_foreach, &wd); /* Write the file */ xmlSetDocCompressMode (doc, 0); diff --git a/e-util/e-pilot-map.h b/e-util/e-pilot-map.h index 51039e3ca0..28f9223070 100644 --- a/e-util/e-pilot-map.h +++ b/e-util/e-pilot-map.h @@ -34,6 +34,8 @@ struct _EPilotMap GHashTable *uid_map; time_t since; + + gboolean write_touched_only; }; gboolean e_pilot_map_pid_is_archived (EPilotMap *map, guint32 pid); |