diff options
author | JP Rosevear <jpr@helixcode.com> | 2000-10-24 02:27:21 +0800 |
---|---|---|
committer | JP Rosevear <jpr@src.gnome.org> | 2000-10-24 02:27:21 +0800 |
commit | 61008a12e175494276ed24de4b3d214f66041cd1 (patch) | |
tree | 08de7600f576b1aa6c5d44be4c781e3b3c416c43 | |
parent | 3da02acd535f898c2669d06da92c22d3e14d62a2 (diff) | |
download | gsoc2013-evolution-61008a12e175494276ed24de4b3d214f66041cd1.tar.gz gsoc2013-evolution-61008a12e175494276ed24de4b3d214f66041cd1.tar.zst gsoc2013-evolution-61008a12e175494276ed24de4b3d214f66041cd1.zip |
Pilot map functions grabbed from existing conduits
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
2000-10-23 JP Rosevear <jpr@helixcode.com>
* conduits/todo/Makefile.am: Add libeconduit-static.la
* conduits/todo/todo-conduit.c (post_sync): Use e_pilot_map_write
(pre_sync): Use e_pilot_map_read
svn path=/trunk/; revision=6116
-rw-r--r-- | calendar/ChangeLog | 7 | ||||
-rw-r--r-- | calendar/conduits/todo/Makefile.am | 2 | ||||
-rw-r--r-- | calendar/conduits/todo/todo-conduit.c | 137 | ||||
-rw-r--r-- | e-util/ChangeLog | 6 | ||||
-rw-r--r-- | e-util/Makefile.am | 13 | ||||
-rw-r--r-- | e-util/e-pilot-map.c | 162 | ||||
-rw-r--r-- | e-util/e-pilot-map.h | 29 |
7 files changed, 231 insertions, 125 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog index 6950b626ca..626d14c515 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,10 @@ +2000-10-23 JP Rosevear <jpr@helixcode.com> + + * conduits/todo/Makefile.am: Add libeconduit-static.la + + * conduits/todo/todo-conduit.c (post_sync): Use e_pilot_map_write + (pre_sync): Use e_pilot_map_read + 2000-10-21 Damon Chaplin <damon@helixcode.com> * gui/dialogs/cal-prefs-dialog.c (cal_prefs_dialog_use_24_hour_toggled): removed debug message. diff --git a/calendar/conduits/todo/Makefile.am b/calendar/conduits/todo/Makefile.am index 73c9dc203b..765c9a3742 100644 --- a/calendar/conduits/todo/Makefile.am +++ b/calendar/conduits/todo/Makefile.am @@ -3,6 +3,7 @@ INCLUDES = \ -I$(top_srcdir)/calendar \ -I$(top_srcdir)/libical/src/libical \ -I$(top_builddir)/libical/src/libical \ + -I$(top_builddir)/e-util \ $(BONOBO_VFS_GNOME_CFLAGS) \ $(GNOME_PILOT_CFLAGS) @@ -36,6 +37,7 @@ libetodo_conduit_la_LIBADD = \ $(top_builddir)/calendar/cal-util/libcal-util-static.la \ $(top_builddir)/libversit/libversit.la \ $(top_builddir)/libical/src/libical/libical-static.la \ + $(top_builddir)/e-util/libeconduit-static.la \ $(BONOBO_VFS_GNOME_LIBS) \ $(PISOCK_LIBDIR) $(PISOCK_LIBS) \ $(UNICODE_LIBS) \ diff --git a/calendar/conduits/todo/todo-conduit.c b/calendar/conduits/todo/todo-conduit.c index d3ea9dbd63..992f36eb0d 100644 --- a/calendar/conduits/todo/todo-conduit.c +++ b/calendar/conduits/todo/todo-conduit.c @@ -41,6 +41,7 @@ #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 @@ -148,120 +149,6 @@ e_todo_context_destroy (EToDoConduitContext **ctxt) *ctxt = NULL; } -/* Map routines */ -static char * -map_name (EToDoConduitContext *ctxt) -{ - char *filename; - - filename = g_strdup_printf ("%s/evolution/local/Calendar/pilot-map-%d.xml", g_get_home_dir (), ctxt->cfg->pilot_id); - - return filename; -} - -static void -map_set_node_timet (xmlNodePtr node, const char *name, time_t t) -{ - char *tstring; - - tstring = g_strdup_printf ("%ld", t); - xmlSetProp (node, name, tstring); -} - -static void -map_sax_start_element (void *data, const xmlChar *name, - const xmlChar **attrs) -{ - EToDoConduitContext *ctxt = (EToDoConduitContext *)data; - - if (!strcmp (name, "PilotMap")) { - while (attrs && *attrs != NULL) { - const xmlChar **val = attrs; - - val++; - if (!strcmp (*attrs, "timestamp")) - ctxt->since = (time_t)strtoul (*val, NULL, 0); - - attrs = ++val; - } - } - - if (!strcmp (name, "map")) { - char *uid = NULL; - guint32 *pid = g_new (guint32, 1); - - *pid = 0; - - while (attrs && *attrs != NULL) { - const xmlChar **val = attrs; - - val++; - if (!strcmp (*attrs, "uid")) - uid = g_strdup (*val); - - if (!strcmp (*attrs, "pilot_id")) - *pid = strtoul (*val, NULL, 0); - - attrs = ++val; - } - - 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); - } - } -} - -static void -map_write_foreach (gpointer key, gpointer value, gpointer data) -{ - xmlNodePtr root = data; - xmlNodePtr mnode; - unsigned long *pid = key; - const char *uid = value; - char *pidstr; - - mnode = xmlNewChild (root, NULL, "map", NULL); - xmlSetProp (mnode, "uid", uid); - pidstr = g_strdup_printf ("%lu", *pid); - xmlSetProp (mnode, "pilot_id", pidstr); - g_free (pidstr); -} - -static int -map_write (EToDoConduitContext *ctxt, char *filename) -{ - xmlDocPtr doc; - int ret; - - if (ctxt->pid_map == NULL) - return 0; - - doc = xmlNewDoc ("1.0"); - if (doc == NULL) { - WARN ("Pilot map file could not be created\n"); - return -1; - } - doc->root = xmlNewDocNode(doc, NULL, "PilotMap", NULL); - map_set_node_timet (doc->root, "timestamp", time (NULL)); - - g_hash_table_foreach (ctxt->pid_map, map_write_foreach, doc->root); - - /* Write the file */ - xmlSetDocCompressMode (doc, 0); - ret = xmlSaveFile (filename, doc); - if (ret < 0) { - g_warning ("Pilot map file '%s' could not be saved\n", filename); - return -1; - } - - xmlFreeDoc (doc); - - return 0; -} - /* Calendar Server routines */ static void start_calendar_server_cb (GtkWidget *cal_client, @@ -318,6 +205,16 @@ start_calendar_server (EToDoConduitContext *ctxt) } /* Utility routines */ +static char * +map_name (EToDoConduitContext *ctxt) +{ + char *filename; + + filename = g_strdup_printf ("%s/evolution/local/Calendar/pilot-map-%d.xml", g_get_home_dir (), ctxt->cfg->pilot_id); + + return filename; +} + static void compute_pid (EToDoConduitContext *ctxt, EToDoLocalRecord *local, const char *uid) { @@ -597,7 +494,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); @@ -622,14 +518,7 @@ pre_sync (GnomePilotConduit *conduit, ctxt->uid_map = g_hash_table_new (g_str_hash, g_str_equal); filename = map_name (ctxt); - if (g_file_exists (filename)) { - memset (&handler, 0, sizeof (xmlSAXHandler)); - handler.startElement = map_sax_start_element; - - if (xmlSAXUserParseFile (&handler, ctxt, filename) < 0) - return -1; - } - + e_pilot_map_read (filename, ctxt->pid_map, ctxt->uid_map, &ctxt->since); g_free (filename); /* Find the added, modified and deleted items */ @@ -698,7 +587,7 @@ post_sync (GnomePilotConduit *conduit, LOG ("---------------------------------------------------------\n"); filename = map_name (ctxt); - map_write (ctxt, filename); + e_pilot_map_write (filename, ctxt->pid_map); g_free (filename); return 0; diff --git a/e-util/ChangeLog b/e-util/ChangeLog index 404b1a331f..cb82b98e94 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,9 @@ +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 + 2000-10-18 Dan Winship <danw@helixcode.com> * e-html-utils.c (e_text_to_html): If unicode_get_utf8 returns -1, diff --git a/e-util/Makefile.am b/e-util/Makefile.am index 1c5846f40c..a1d28e812d 100644 --- a/e-util/Makefile.am +++ b/e-util/Makefile.am @@ -11,7 +11,8 @@ INCLUDES = \ -DG_LOG_DOMAIN=\"e-utils\" \ $(UNICODE_CFLAGS) -noinst_LTLIBRARIES = libeutil.la libeutil-static.la +noinst_LTLIBRARIES = libeutil.la libeutil-static.la \ + libeconduit.la libeconduit-static.la libeutil_la_SOURCES = \ e-dialog-widgets.c \ @@ -35,3 +36,13 @@ libeutil_la_LIBADD = $(UNICODE_LIBS) libeutil_static_la_SOURCES = $(libeutil_la_SOURCES) libeutil_static_la_LDFLAGS = --all-static + +libeconduit_la_SOURCES = \ + e-pilot-map.c \ + e-pilot-map.h + +libeconduit_static_la_SOURCES = $(libeconduit_la_SOURCES) +libeconduit_static_la_LDFLAGS = --all-static + + + diff --git a/e-util/e-pilot-map.c b/e-util/e-pilot-map.c new file mode 100644 index 0000000000..b04a65a2e8 --- /dev/null +++ b/e-util/e-pilot-map.c @@ -0,0 +1,162 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* Evolution Conduits - Pilot Map routines + * + * Copyright (C) 2000 Helix Code, Inc. + * + * Authors: JP Rosevear <jpr@helixcode.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <stdlib.h> +#include <time.h> +#include <glib.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) +{ + char *tstring; + + tstring = g_strdup_printf ("%ld", t); + xmlSetProp (node, name, tstring); +} + +static void +map_sax_start_element (void *data, const xmlChar *name, + const xmlChar **attrs) +{ + struct map_sax_closure *closure = (struct map_sax_closure *)data; + + if (!strcmp (name, "PilotMap")) { + while (attrs && *attrs != NULL) { + const xmlChar **val = attrs; + + val++; + if (!strcmp (*attrs, "timestamp")) + *closure->since = (time_t)strtoul (*val, NULL, 0); + + attrs = ++val; + } + } + + if (!strcmp (name, "map")) { + char *uid = NULL; + guint32 *pid = g_new (guint32, 1); + + *pid = 0; + + while (attrs && *attrs != NULL) { + const xmlChar **val = attrs; + + val++; + if (!strcmp (*attrs, "uid")) + uid = g_strdup (*val); + + if (!strcmp (*attrs, "pilot_id")) + *pid = strtoul (*val, NULL, 0); + + attrs = ++val; + } + + if (uid && *pid != 0) { + g_hash_table_insert (closure->pid_map, pid, uid); + g_hash_table_insert (closure->uid_map, uid, pid); + } else { + g_free (pid); + } + } +} + +static void +map_write_foreach (gpointer key, gpointer value, gpointer data) +{ + xmlNodePtr root = data; + xmlNodePtr mnode; + unsigned long *pid = key; + const char *uid = value; + char *pidstr; + + mnode = xmlNewChild (root, NULL, "map", NULL); + xmlSetProp (mnode, "uid", uid); + pidstr = g_strdup_printf ("%lu", *pid); + xmlSetProp (mnode, "pilot_id", pidstr); + g_free (pidstr); +} + +int +e_pilot_map_write (const char *filename, GHashTable *pid_map) +{ + xmlDocPtr doc; + int ret; + + g_return_val_if_fail (pid_map != NULL, -1); + + doc = xmlNewDoc ("1.0"); + if (doc == NULL) { + g_warning ("Pilot map file could not be created\n"); + return -1; + } + doc->root = xmlNewDocNode(doc, NULL, "PilotMap", NULL); + map_set_node_timet (doc->root, "timestamp", time (NULL)); + + g_hash_table_foreach (pid_map, map_write_foreach, doc->root); + + /* Write the file */ + xmlSetDocCompressMode (doc, 0); + ret = xmlSaveFile (filename, doc); + if (ret < 0) { + g_warning ("Pilot map file '%s' could not be saved\n", filename); + return -1; + } + + xmlFreeDoc (doc); + + return 0; +} + +int +e_pilot_map_read (const char *filename, GHashTable *pid_map, + GHashTable *uid_map, time_t *since) +{ + 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; +} + + + + + + + diff --git a/e-util/e-pilot-map.h b/e-util/e-pilot-map.h new file mode 100644 index 0000000000..87d983b292 --- /dev/null +++ b/e-util/e-pilot-map.h @@ -0,0 +1,29 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* Evolution Conduits - Pilot Map routines + * + * Copyright (C) 2000 Helix Code, Inc. + * + * Authors: JP Rosevear <jpr@helixcode.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +#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); + +#endif /* E_PILOT_MAP_H */ |