aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Rosevear <jpr@helixcode.com>2000-10-24 06:18:44 +0800
committerJP Rosevear <jpr@src.gnome.org>2000-10-24 06:18:44 +0800
commitecb43703f84f5ec6b43b8f5b1ee7fa363e144af8 (patch)
treeaea6396dcb01489f88f47e7fa7e58deedd04a6c8
parent50a68e6b6b60eb6fbf35129867002ef722182ce2 (diff)
downloadgsoc2013-evolution-ecb43703f84f5ec6b43b8f5b1ee7fa363e144af8.tar.gz
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
-rw-r--r--addressbook/ChangeLog7
-rw-r--r--addressbook/conduit/address-conduit.c29
-rw-r--r--addressbook/conduit/address-conduit.h7
-rw-r--r--calendar/ChangeLog9
-rw-r--r--calendar/conduits/calendar/calendar-conduit.c34
-rw-r--r--calendar/conduits/calendar/calendar-conduit.h7
-rw-r--r--calendar/conduits/todo/todo-conduit.c36
-rw-r--r--calendar/conduits/todo/todo-conduit.h8
-rw-r--r--e-util/ChangeLog11
-rw-r--r--e-util/e-pilot-map.c99
-rw-r--r--e-util/e-pilot-map.h24
11 files changed, 153 insertions, 118 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog
index 96d46af7fc..5d5aeff406 100644
--- a/addressbook/ChangeLog
+++ b/addressbook/ChangeLog
@@ -1,5 +1,12 @@
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>
+
* conduit/address-conduit.c (pre_sync): Use e_pilot_map_read
(post_sync): Use e_pilot_map_write
diff --git a/addressbook/conduit/address-conduit.c b/addressbook/conduit/address-conduit.c
index a0b327e977..94d48179a6 100644
--- a/addressbook/conduit/address-conduit.c
+++ b/addressbook/conduit/address-conduit.c
@@ -42,7 +42,6 @@
#include <ebook/e-card-cursor.h>
#include <ebook/e-card.h>
#include <ebook/e-card-simple.h>
-#include <e-pilot-map.h>
#define ADDR_CONFIG_LOAD 1
#define ADDR_CONFIG_DESTROY 1
@@ -255,7 +254,7 @@ compute_pid (EAddrConduitContext *ctxt, EAddrLocalRecord *local, const char *uid
{
/* guint32 *pid; */
-/* pid = g_hash_table_lookup (ctxt->uid_map, uid); */
+/* pid = g_hash_table_lookup (ctxt->map->uid_map, uid); */
/* if (pid) */
/* local->local.ID = *pid; */
@@ -601,7 +600,7 @@ check_for_slow_setting (GnomePilotConduit *c, EAddrConduitContext *ctxt)
/* count = g_list_length (ctxt->uids); */
count = 0;
- map_count = g_hash_table_size (ctxt->pid_map);
+ map_count = g_hash_table_size (ctxt->map->pid_map);
/* If there are no objects or objects but no log */
if ((count == 0) || (count > 0 && map_count == 0)) {
@@ -642,11 +641,8 @@ pre_sync (GnomePilotConduit *conduit,
}
/* 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);
- e_pilot_map_read (filename, ctxt->pid_map, ctxt->uid_map, &ctxt->since);
+ e_pilot_map_read (filename, &ctxt->map);
g_free (filename);
/* Set the count information */
@@ -691,7 +687,7 @@ post_sync (GnomePilotConduit *conduit,
LOG ("---------------------------------------------------------\n");
filename = map_name (ctxt);
- e_pilot_map_write (filename, ctxt->pid_map);
+ e_pilot_map_write (filename, ctxt->map);
g_free (filename);
return 0;
@@ -703,15 +699,9 @@ set_pilot_id (GnomePilotConduitSyncAbs *conduit,
guint32 ID,
EAddrConduitContext *ctxt)
{
- char *new_uid;
- guint32 *pid = g_new (guint32, 1);
-
LOG ("set_pilot_id: setting to %d\n", ID);
- *pid = ID;
- new_uid = g_strdup (local->ecard->id);
- g_hash_table_insert (ctxt->pid_map, pid, new_uid);
- g_hash_table_insert (ctxt->uid_map, new_uid, pid);
+ e_pilot_map_insert (ctxt->map, ID, local->ecard->id, FALSE);
return 0;
}
@@ -858,8 +848,6 @@ add_record (GnomePilotConduitSyncAbs *conduit,
EAddrConduitContext *ctxt)
{
ECard *ecard;
- char *new_uid;
- guint32 *pid = g_new (guint32, 1);
add_card_cons cons;
int retval = 0;
@@ -883,10 +871,7 @@ add_record (GnomePilotConduitSyncAbs *conduit,
e_book_get_card (ctxt->ebook, cons.id));
g_free (cons.id);
- *pid = remote->ID;
- new_uid = g_strdup (ecard->id);
- g_hash_table_insert (ctxt->pid_map, pid, new_uid);
- g_hash_table_insert (ctxt->uid_map, new_uid, pid);
+ e_pilot_map_insert (ctxt->map, remote->ID, ecard->id, FALSE);
return retval;
}
@@ -987,7 +972,7 @@ match (GnomePilotConduitSyncAbs *conduit,
g_return_val_if_fail (remote != NULL, -1);
/* *local = NULL; */
-/* uid = g_hash_table_lookup (ctxt->pid_map, &remote->ID); */
+/* uid = g_hash_table_lookup (ctxt->map->pid_map, &remote->ID); */
/* if (!uid) */
/* return 0; */
diff --git a/addressbook/conduit/address-conduit.h b/addressbook/conduit/address-conduit.h
index 55142d08c2..141ec1b53c 100644
--- a/addressbook/conduit/address-conduit.h
+++ b/addressbook/conduit/address-conduit.h
@@ -32,7 +32,7 @@
#include <pi-address.h>
#include <gpilotd/gnome-pilot-conduit.h>
#include <gpilotd/gnome-pilot-conduit-sync-abs.h>
-
+#include <e-pilot-map.h>
/* This is the local record structure for the Evolution ToDo conduit. */
typedef struct _EAddrLocalRecord EAddrLocalRecord;
@@ -63,10 +63,7 @@ struct _EAddrConduitContext {
gboolean address_load_tried;
gboolean address_load_success;
- time_t since;
-
- GHashTable *uid_map;
- GHashTable *pid_map;
+ EPilotMap *map;
};
#endif __ADDR_CONDUIT_H__
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index 67b5d22cb8..9e8438f2da 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -1,5 +1,14 @@
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
diff --git a/calendar/conduits/calendar/calendar-conduit.c b/calendar/conduits/calendar/calendar-conduit.c
index 945c384b21..f5ef766648 100644
--- a/calendar/conduits/calendar/calendar-conduit.c
+++ b/calendar/conduits/calendar/calendar-conduit.c
@@ -41,7 +41,6 @@
#include <pi-dlp.h>
#include <pi-version.h>
#include <libical/src/libical/icaltypes.h>
-#include <e-pilot-map.h>
#define CAL_CONFIG_LOAD 1
#define CAL_CONFIG_DESTROY 1
@@ -241,7 +240,7 @@ compute_pid (ECalConduitContext *ctxt, ECalLocalRecord *local, const char *uid)
{
guint32 *pid;
- pid = g_hash_table_lookup (ctxt->uid_map, uid);
+ pid = g_hash_table_lookup (ctxt->map->uid_map, uid);
if (pid)
local->local.ID = *pid;
@@ -591,7 +590,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->pid_map);
+ map_count = g_hash_table_size (ctxt->map->pid_map);
/* If there are no objects or objects but no log */
if ((count == 0) || (count > 0 && map_count == 0)) {
@@ -615,7 +614,6 @@ pre_sync (GnomePilotConduit *conduit,
int len;
unsigned char *buf;
char *filename;
- xmlSAXHandler handler;
gint num_records;
abs_conduit = GNOME_PILOT_CONDUIT_SYNC_ABS (conduit);
@@ -636,11 +634,8 @@ pre_sync (GnomePilotConduit *conduit,
ctxt->uids = cal_client_get_uids (ctxt->client, CALOBJ_TYPE_EVENT);
/* Load the uid <--> pilot id mapping */
- 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);
- e_pilot_map_read (filename, ctxt->pid_map, ctxt->uid_map, &ctxt->since);
+ e_pilot_map_read (filename, &ctxt->map);
g_free (filename);
/* Find the added, modified and deleted items */
@@ -650,13 +645,13 @@ pre_sync (GnomePilotConduit *conduit,
ctxt->changed = cal_client_get_changed_uids (ctxt->client,
CALOBJ_TYPE_EVENT,
- ctxt->since + 1);
+ ctxt->map->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->uid_map, coc->uid))
+ if (g_hash_table_lookup (ctxt->map->uid_map, coc->uid))
g_hash_table_insert (ctxt->modified, coc->uid, coc);
else
g_hash_table_insert (ctxt->added, coc->uid, coc);
@@ -709,7 +704,7 @@ post_sync (GnomePilotConduit *conduit,
LOG ("---------------------------------------------------------\n");
filename = map_name (ctxt);
- e_pilot_map_write (filename, ctxt->pid_map);
+ e_pilot_map_write (filename, ctxt->map);
g_free (filename);
return 0;
@@ -722,16 +717,11 @@ set_pilot_id (GnomePilotConduitSyncAbs *conduit,
ECalConduitContext *ctxt)
{
const char *uid;
- char *new_uid;
- guint32 *pid = g_new (guint32, 1);
LOG ("set_pilot_id: setting to %d\n", ID);
cal_component_get_uid (local->comp, &uid);
- *pid = ID;
- new_uid = g_strdup (uid);
- g_hash_table_insert (ctxt->pid_map, pid, new_uid);
- g_hash_table_insert (ctxt->uid_map, new_uid, pid);
+ e_pilot_map_insert (ctxt->map, ID, uid, FALSE);
return 0;
}
@@ -879,8 +869,6 @@ add_record (GnomePilotConduitSyncAbs *conduit,
{
CalComponent *comp;
const char *uid;
- char *new_uid;
- guint32 *pid = g_new (guint32, 1);
int retval = 0;
g_return_val_if_fail (remote != NULL, -1);
@@ -890,11 +878,9 @@ add_record (GnomePilotConduitSyncAbs *conduit,
comp = comp_from_remote_record (conduit, remote, NULL);
update_comp (conduit, comp, ctxt);
- *pid = remote->ID;
cal_component_get_uid (comp, &uid);
- new_uid = g_strdup (uid);
- g_hash_table_insert (ctxt->pid_map, pid, new_uid);
- g_hash_table_insert (ctxt->uid_map, new_uid, pid);
+
+ e_pilot_map_insert (ctxt->map, remote->ID, uid, FALSE);
return retval;
}
@@ -988,7 +974,7 @@ match (GnomePilotConduitSyncAbs *conduit,
g_return_val_if_fail (remote != NULL, -1);
*local = NULL;
- uid = g_hash_table_lookup (ctxt->pid_map, &remote->ID);
+ uid = g_hash_table_lookup (ctxt->map->pid_map, &remote->ID);
if (!uid)
return 0;
diff --git a/calendar/conduits/calendar/calendar-conduit.h b/calendar/conduits/calendar/calendar-conduit.h
index b0065610fb..91900fcb90 100644
--- a/calendar/conduits/calendar/calendar-conduit.h
+++ b/calendar/conduits/calendar/calendar-conduit.h
@@ -33,7 +33,7 @@
#include <gpilotd/gnome-pilot-conduit.h>
#include <gpilotd/gnome-pilot-conduit-sync-abs.h>
#include <cal-client/cal-client.h>
-
+#include <e-pilot-map.h>
/* This is the local record structure for the Evolution Calendar conduit. */
typedef struct _ECalLocalRecord ECalLocalRecord;
@@ -67,12 +67,11 @@ struct _ECalConduitContext {
GList *uids;
GList *changed;
+ EPilotMap *map;
+
GHashTable *added;
GHashTable *modified;
GHashTable *deleted;
-
- 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 992f36eb0d..9158f55c30 100644
--- a/calendar/conduits/todo/todo-conduit.c
+++ b/calendar/conduits/todo/todo-conduit.c
@@ -41,7 +41,6 @@
#include <pi-dlp.h>
#include <pi-version.h>
#include <libical/src/libical/icaltypes.h>
-#include <e-pilot-map.h>
#define TODO_CONFIG_LOAD 1
#define TODO_CONFIG_DESTROY 1
@@ -220,7 +219,7 @@ compute_pid (EToDoConduitContext *ctxt, EToDoLocalRecord *local, const char *uid
{
guint32 *pid;
- pid = g_hash_table_lookup (ctxt->uid_map, uid);
+ pid = g_hash_table_lookup (ctxt->map->uid_map, uid);
if (pid)
local->local.ID = *pid;
@@ -470,7 +469,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->pid_map);
+ map_count = g_hash_table_size (ctxt->map->pid_map);
/* If there are no objects or objects but no log */
if ((count == 0) || (count > 0 && map_count == 0)) {
@@ -513,12 +512,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 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);
-
+ /* Load the uid <--> pilot id map */
filename = map_name (ctxt);
- e_pilot_map_read (filename, ctxt->pid_map, ctxt->uid_map, &ctxt->since);
+ e_pilot_map_read (filename, &ctxt->map);
g_free (filename);
/* Find the added, modified and deleted items */
@@ -528,13 +524,13 @@ pre_sync (GnomePilotConduit *conduit,
ctxt->changed = cal_client_get_changed_uids (ctxt->client,
CALOBJ_TYPE_TODO,
- ctxt->since + 1);
+ ctxt->map->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->uid_map, coc->uid))
+ if (g_hash_table_lookup (ctxt->map->uid_map, coc->uid))
g_hash_table_insert (ctxt->modified, coc->uid, coc);
else
g_hash_table_insert (ctxt->added, coc->uid, coc);
@@ -587,7 +583,8 @@ post_sync (GnomePilotConduit *conduit,
LOG ("---------------------------------------------------------\n");
filename = map_name (ctxt);
- e_pilot_map_write (filename, ctxt->pid_map);
+ e_pilot_map_write (filename, ctxt->map);
+ e_pilot_map_destroy (ctxt->map);
g_free (filename);
return 0;
@@ -600,16 +597,11 @@ set_pilot_id (GnomePilotConduitSyncAbs *conduit,
EToDoConduitContext *ctxt)
{
const char *uid;
- char *new_uid;
- guint32 *pid = g_new (guint32, 1);
LOG ("set_pilot_id: setting to %d\n", ID);
cal_component_get_uid (local->comp, &uid);
- *pid = ID;
- new_uid = g_strdup (uid);
- g_hash_table_insert (ctxt->pid_map, pid, new_uid);
- g_hash_table_insert (ctxt->uid_map, new_uid, pid);
+ e_pilot_map_insert (ctxt->map, ID, uid, FALSE);
return 0;
}
@@ -757,8 +749,6 @@ add_record (GnomePilotConduitSyncAbs *conduit,
{
CalComponent *comp;
const char *uid;
- char *new_uid;
- guint32 *pid = g_new (guint32, 1);
int retval = 0;
g_return_val_if_fail (remote != NULL, -1);
@@ -768,11 +758,9 @@ add_record (GnomePilotConduitSyncAbs *conduit,
comp = comp_from_remote_record (conduit, remote, NULL);
update_comp (conduit, comp, ctxt);
- *pid = remote->ID;
cal_component_get_uid (comp, &uid);
- new_uid = g_strdup (uid);
- g_hash_table_insert (ctxt->pid_map, pid, new_uid);
- g_hash_table_insert (ctxt->uid_map, new_uid, pid);
+
+ e_pilot_map_insert (ctxt->map, remote->ID, uid, FALSE);
return retval;
}
@@ -866,7 +854,7 @@ match (GnomePilotConduitSyncAbs *conduit,
g_return_val_if_fail (remote != NULL, -1);
*local = NULL;
- uid = g_hash_table_lookup (ctxt->pid_map, &remote->ID);
+ uid = g_hash_table_lookup (ctxt->map->pid_map, &remote->ID);
if (!uid)
return 0;
diff --git a/calendar/conduits/todo/todo-conduit.h b/calendar/conduits/todo/todo-conduit.h
index ecec89c35a..6e1f109a87 100644
--- a/calendar/conduits/todo/todo-conduit.h
+++ b/calendar/conduits/todo/todo-conduit.h
@@ -33,7 +33,7 @@
#include <gpilotd/gnome-pilot-conduit.h>
#include <gpilotd/gnome-pilot-conduit-sync-abs.h>
#include <cal-client/cal-client.h>
-
+#include <e-pilot-map.h>
/* This is the local record structure for the Evolution ToDo conduit. */
typedef struct _EToDoLocalRecord EToDoLocalRecord;
@@ -63,16 +63,14 @@ struct _EToDoConduitContext {
gboolean calendar_load_tried;
gboolean calendar_load_success;
- time_t since;
GList *uids;
GList *changed;
+ EPilotMap *map;
+
GHashTable *added;
GHashTable *modified;
GHashTable *deleted;
-
- GHashTable *uid_map;
- GHashTable *pid_map;
};
#endif __TODO_CONDUIT_H__
diff --git a/e-util/ChangeLog b/e-util/ChangeLog
index cb82b98e94..be4a0fd10e 100644
--- a/e-util/ChangeLog
+++ b/e-util/ChangeLog
@@ -1,5 +1,16 @@
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
+
+2000-10-23 JP Rosevear <jpr@helixcode.com>
+
* e-pilot-map.c: Pilot map functions grabbed from existing conduits
* e-pilot-map.h (e_pilot_map_write): Header
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,
+
diff --git a/e-util/e-pilot-map.h b/e-util/e-pilot-map.h
index 87d983b292..e910f43317 100644
--- a/e-util/e-pilot-map.h
+++ b/e-util/e-pilot-map.h
@@ -23,7 +23,27 @@
#ifndef E_PILOT_MAP_H
#define E_PILOT_MAP_H
-int e_pilot_map_read (const char *filename, GHashTable *pid_map, GHashTable *uid_map, time_t *since);
-int e_pilot_map_write (const char *filename, GHashTable *pid_map);
+#include <glib.h>
+#include <time.h>
+
+typedef struct _EPilotMap EPilotMap;
+
+struct _EPilotMap
+{
+ GHashTable *pid_map;
+ GHashTable *uid_map;
+
+ time_t since;
+};
+
+gboolean e_pilot_map_pid_is_archived (EPilotMap *map, guint32 pilot_id);
+gboolean 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);
+
+int e_pilot_map_read (const char *filename, EPilotMap **map);
+int e_pilot_map_write (const char *filename, EPilotMap *map);
+
+void e_pilot_map_destroy (EPilotMap *map);
#endif /* E_PILOT_MAP_H */