diff options
author | JP Rosevear <jpr@helixcode.com> | 2000-10-24 06:18:44 +0800 |
---|---|---|
committer | JP Rosevear <jpr@src.gnome.org> | 2000-10-24 06:18:44 +0800 |
commit | ecb43703f84f5ec6b43b8f5b1ee7fa363e144af8 (patch) | |
tree | aea6396dcb01489f88f47e7fa7e58deedd04a6c8 /e-util/e-pilot-map.c | |
parent | 50a68e6b6b60eb6fbf35129867002ef722182ce2 (diff) | |
download | gsoc2013-evolution-ecb43703f84f5ec6b43b8f5b1ee7fa363e144af8.tar gsoc2013-evolution-ecb43703f84f5ec6b43b8f5b1ee7fa363e144af8.tar.gz gsoc2013-evolution-ecb43703f84f5ec6b43b8f5b1ee7fa363e144af8.tar.bz2 gsoc2013-evolution-ecb43703f84f5ec6b43b8f5b1ee7fa363e144af8.tar.lz gsoc2013-evolution-ecb43703f84f5ec6b43b8f5b1ee7fa363e144af8.tar.xz gsoc2013-evolution-ecb43703f84f5ec6b43b8f5b1ee7fa363e144af8.tar.zst gsoc2013-evolution-ecb43703f84f5ec6b43b8f5b1ee7fa363e144af8.zip |
Use new libeconduit calls and abstraction
2000-10-23 JP Rosevear <jpr@helixcode.com>
* conduit/address-conduit.h: Use new libeconduit calls and
abstraction
* conduit/address-conduit.c: ditto
2000-10-23 JP Rosevear <jpr@helixcode.com>
* conduits/todo/todo-conduit.h: Use new libeconduit calls and
abstraction
* conduits/calendar/calendar-conduit.c: ditto
* conduits/calendar/calendar-conduit.h: ditto
* conduits/todo/todo-conduit.c: ditto
* conduits/calendar/Makefile.am: Add libeconduit-static.la
* conduits/calendar/calendar-conduit.c (post_sync): Use e_pilot_map_write
(pre_sync): Use e_pilot_map_read
2000-10-23 JP Rosevear <jpr@helixcode.com>
* e-pilot-map.c: Operate with EPilotMap structure so things are
abstract to the caller
(e_pilot_map_pid_is_archived): Infrastructure for marking records
as archived
(e_pilot_map_uid_is_archived): ditto
* e-pilot-map.h: Add more to public interface, including EPilotMap
structure
svn path=/trunk/; revision=6134
Diffstat (limited to 'e-util/e-pilot-map.c')
-rw-r--r-- | e-util/e-pilot-map.c | 99 |
1 files changed, 67 insertions, 32 deletions
diff --git a/e-util/e-pilot-map.c b/e-util/e-pilot-map.c index b04a65a2e8..4b364f39bd 100644 --- a/e-util/e-pilot-map.c +++ b/e-util/e-pilot-map.c @@ -22,17 +22,10 @@ #include <stdlib.h> #include <time.h> -#include <glib.h> +#include <gnome.h> #include <gnome-xml/parser.h> #include <e-pilot-map.h> -struct map_sax_closure -{ - GHashTable *pid_map; - GHashTable *uid_map; - time_t *since; -}; - static void map_set_node_timet (xmlNodePtr node, const char *name, time_t t) { @@ -46,7 +39,7 @@ static void map_sax_start_element (void *data, const xmlChar *name, const xmlChar **attrs) { - struct map_sax_closure *closure = (struct map_sax_closure *)data; + EPilotMap *map = (EPilotMap *)data; if (!strcmp (name, "PilotMap")) { while (attrs && *attrs != NULL) { @@ -54,7 +47,7 @@ map_sax_start_element (void *data, const xmlChar *name, val++; if (!strcmp (*attrs, "timestamp")) - *closure->since = (time_t)strtoul (*val, NULL, 0); + map->since = (time_t)strtoul (*val, NULL, 0); attrs = ++val; } @@ -80,8 +73,8 @@ map_sax_start_element (void *data, const xmlChar *name, } if (uid && *pid != 0) { - g_hash_table_insert (closure->pid_map, pid, uid); - g_hash_table_insert (closure->uid_map, uid, pid); + g_hash_table_insert (map->pid_map, pid, uid); + g_hash_table_insert (map->uid_map, uid, pid); } else { g_free (pid); } @@ -103,14 +96,65 @@ map_write_foreach (gpointer key, gpointer value, gpointer data) xmlSetProp (mnode, "pilot_id", pidstr); g_free (pidstr); } + +gboolean +e_pilot_map_pid_is_archived (EPilotMap *map, guint32 pilot_id) +{ + return FALSE; +} + +gboolean +e_pilot_map_uid_is_archived (EPilotMap *map, const char *uid) +{ + return FALSE; +} + +void +e_pilot_map_insert (EPilotMap *map, guint32 pid, const char *uid, gboolean archived) +{ + char *new_uid; + guint32 *new_pid = g_new (guint32, 1); + + *new_pid = pid; + new_uid = g_strdup (uid); + + g_hash_table_insert (map->pid_map, new_pid, new_uid); + g_hash_table_insert (map->uid_map, new_uid, new_pid); +} + +int +e_pilot_map_read (const char *filename, EPilotMap **map) +{ + xmlSAXHandler handler; + EPilotMap *new_map = g_new0 (EPilotMap, 1); + + *map = NULL; + + memset (&handler, 0, sizeof (xmlSAXHandler)); + handler.startElement = map_sax_start_element; + + new_map->pid_map = g_hash_table_new (g_int_hash, g_int_equal); + new_map->uid_map = g_hash_table_new (g_str_hash, g_str_equal); + + if (g_file_exists (filename)) { + if (xmlSAXUserParseFile (&handler, new_map, filename) < 0) { + g_free (new_map); + return -1; + } + } + + *map = new_map; + + return 0; +} int -e_pilot_map_write (const char *filename, GHashTable *pid_map) +e_pilot_map_write (const char *filename, EPilotMap *map) { xmlDocPtr doc; int ret; - g_return_val_if_fail (pid_map != NULL, -1); + g_return_val_if_fail (map != NULL, -1); doc = xmlNewDoc ("1.0"); if (doc == NULL) { @@ -118,9 +162,10 @@ e_pilot_map_write (const char *filename, GHashTable *pid_map) return -1; } doc->root = xmlNewDocNode(doc, NULL, "PilotMap", NULL); - map_set_node_timet (doc->root, "timestamp", time (NULL)); + map->since = time (NULL); + map_set_node_timet (doc->root, "timestamp", map->since); - g_hash_table_foreach (pid_map, map_write_foreach, doc->root); + g_hash_table_foreach (map->pid_map, map_write_foreach, doc->root); /* Write the file */ xmlSetDocCompressMode (doc, 0); @@ -135,23 +180,12 @@ e_pilot_map_write (const char *filename, GHashTable *pid_map) return 0; } -int -e_pilot_map_read (const char *filename, GHashTable *pid_map, - GHashTable *uid_map, time_t *since) +void +e_pilot_map_destroy (EPilotMap *map) { - xmlSAXHandler handler; - struct map_sax_closure closure; - - memset (&handler, 0, sizeof (xmlSAXHandler)); - handler.startElement = map_sax_start_element; - - closure.pid_map = pid_map; - closure.uid_map = uid_map; - - if (xmlSAXUserParseFile (&handler, &closure, filename) < 0) - return -1; - - return 0; + g_hash_table_destroy (map->pid_map); + g_hash_table_destroy (map->uid_map); + g_free (map); } @@ -160,3 +194,4 @@ e_pilot_map_read (const char *filename, GHashTable *pid_map, + |