Index: configure.in
===================================================================
--- configure.in	(revision 34104)
+++ configure.in	(working copy)
@@ -1969,6 +1969,7 @@
 calendar/common/Makefile
 calendar/idl/Makefile
 calendar/conduits/Makefile
+calendar/conduits/common/Makefile
 calendar/conduits/todo/Makefile
 calendar/conduits/calendar/Makefile
 calendar/conduits/memo/Makefile
Index: calendar/conduits/todo/Makefile.am
===================================================================
--- calendar/conduits/todo/Makefile.am	(revision 34104)
+++ calendar/conduits/todo/Makefile.am	(working copy)
@@ -3,6 +3,8 @@
 	-I$(top_builddir)/e-util		\
 	-I$(top_srcdir)/widgets/misc		\
 	-I$(top_builddir)/widgets/misc		\
+	-I$(top_srcdir)/calendar/conduits/common		\
+	-I$(top_builddir)/calendar/conduits/common		\
 	$(EVOLUTION_CALENDAR_CONDUIT_CFLAGS)
 
 # ToDo Conduit
@@ -17,6 +19,7 @@
 	$(top_builddir)/e-util/libeutil.la				\
 	$(top_builddir)/e-util/libeconduit.la				\
 	$(top_builddir)/widgets/misc/libemiscwidgets.la			\
+	$(top_builddir)/calendar/conduits/common/libecalendar_common_conduit.la	\
 	$(EVOLUTION_CALENDAR_CONDUIT_LIBS)
 
 e-todo.conduit: e-todo.conduit.in
Index: calendar/conduits/todo/todo-conduit.c
===================================================================
--- calendar/conduits/todo/todo-conduit.c	(revision 34104)
+++ calendar/conduits/todo/todo-conduit.c	(working copy)
@@ -47,6 +47,7 @@
 #include <e-pilot-settings.h>
 #include <e-pilot-util.h>
 #include <e-config-listener.h>
+#include <libecalendar-common-conduit.h>
 
 GnomePilotConduit * conduit_get_gpilot_conduit (guint32);
 void conduit_destroy_gpilot_conduit (GnomePilotConduit*);
@@ -430,9 +431,9 @@
 		    todo.priority,
 		    todo.complete,
 		    todo.description ?
-		    todo.description : "",
+		    e_pilot_utf8_from_pchar(todo.description) : "",
 		    todo.note ?
-		    todo.note : "",
+		    e_pilot_utf8_from_pchar(todo.note) : "",
 		    remote->category);
 
 	free_ToDo (&todo);
@@ -646,55 +647,6 @@
 }
 
 /*
- * Adds a category to the category app info structure (name and ID),
- * sets category->renamed[i] to true if possible to rename.
- * 
- * This will be packed and written to the app info block during post_sync.
- */
- 
-static int
-add_category_if_possible(char *cat_to_add, struct CategoryAppInfo *category)
-{
-	int i, j;
-	int retval = 0; // 0 is the Unfiled category
-	
-	for(i=0; i<16; i++){
-		// if strlen is 0, then the category is empty
-		// the PalmOS doesn't let 0-length strings for
-		// categories
-		if(strlen(category->name[i]) == 0){
-			int cat_to_add_len = strlen(cat_to_add);
-			retval = i;
-			
-			/* only 15 characters for category, 16th is
-			 * '\0' can't do direct mem transfer due to
-			 * declaration type
-			 */
-			for(j=0; j<cat_to_add_len; j++)
-				category->name[i][j] = cat_to_add[j];
-
-			for(j=cat_to_add_len; j<16; j++)
-				category->name[i][j] = '\0';
-			
-			category->ID[i] = lastDesktopUniqueID;
-			lastDesktopUniqueID++;
-			
-			category->renamed[i] = TRUE;
-			
-			LOG(g_message("*** adding category '%s', ID %d ***",
-				category->name[i], category->ID[i]));
-			break;
-		}
-	}
-	
-	if(retval == 0){
-		LOG(g_message("*** not adding category - category list already full ***"));
-	}
-	
-	return retval;
-}
-
-/*
  * converts a ECalComponent object to a EToDoLocalRecord
  */
 static void
@@ -755,42 +707,8 @@
 #endif
 	}
 	
-	/*
-	 * Grab category from existing category list in ctxt->ai.category
-	 */
-	if(local->local.category == 0){
-		GSList *categ_list_head, *categ_list_cur;
-		int cat = -1;
-		int i;
-		
-		e_cal_component_get_categories_list(comp, &categ_list_head);
-		
-		categ_list_cur = categ_list_head;
-		while (categ_list_cur && cat == -1)
-		{	
-			for(i=0; i<16; i++){
-				if(strcmp((char *)categ_list_cur->data,
-					  ctxt->ai.category.name[i]) == 0){
-					cat = i;
-					break;
-				}
-			}
-			
-			categ_list_cur = g_slist_next(categ_list_cur);
-		}
-		
-		if(cat != -1){
-			local->local.category = cat;
-		}
-		else{
-			if(categ_list_head != NULL){
-				local->local.category =
-					add_category_if_possible(
-						(char *)(categ_list_head->data),
-						&(ctxt->ai.category));
-			}
-		}
-	}
+	/*Category support*/
+	e_pilot_local_category_to_remote(&(local->local.category), comp, &(ctxt->ai.category));
 
 	/* STOP: don't replace these with g_strdup, since free_ToDo
 	   uses free to deallocate */
@@ -907,7 +825,6 @@
 	icaltimezone *utc_zone;
 	int priority;
 	char *txt;
-	char *category;
 #ifdef PILOT_LINK_0_12
 	pi_buffer_t * buffer;
 #endif
@@ -949,6 +866,9 @@
 	e_cal_component_set_summary (comp, &summary);
 	free (txt);
 	
+	/*Category support*/
+	e_pilot_remote_category_to_local(remote->category, comp, &(ai->category));
+	
 	/* The iCal description field */
 	if (!todo.note) {
 		e_cal_component_set_comment_list (comp, NULL);
@@ -990,7 +910,7 @@
 			e_cal_component_set_status (comp, ICAL_STATUS_NEEDSACTION);
 	}
 
-	if (!is_empty_time (todo.due)) {
+	if (!todo.indefinite && !is_empty_time (todo.due)) {
 		due = tm_to_icaltimetype (&todo.due, TRUE);
 		dt.value = &due;
 		e_cal_component_set_due (comp, &dt);
@@ -1020,20 +940,6 @@
 		e_cal_component_set_classification (comp, E_CAL_COMPONENT_CLASS_PRIVATE);
 	else
 		e_cal_component_set_classification (comp, E_CAL_COMPONENT_CLASS_PUBLIC);
-	
-	
-	// set the category properly
-	category = ai->category.name[remote->category];
-	
-	
-	// TODO The Tasks editor page and search bar are not updated until
-	// a restart of the evolution client
-	if(e_categories_exist(category) == FALSE){
-		// add if it doesn't exist
-		e_categories_add(category, NULL, NULL, TRUE);
-	}
-	
-	e_cal_component_set_categories(comp, category);
 
 	e_cal_component_commit_sequence (comp);
 	
@@ -1315,7 +1221,11 @@
 
 			*local = g_new0 (EToDoLocalRecord, 1);
 			local_record_from_comp (*local, comps->data, ctxt);
-			ctxt->locals = g_list_prepend (ctxt->locals, *local);
+
+			/* NOTE: ignore the return value, otherwise ctxt->locals
+			 * gets messed up. The calling function keeps track of
+			 * the *local variable */
+			g_list_prepend (ctxt->locals, *local);
 			
 			iterator = comps;
 		} else {
@@ -1330,7 +1240,11 @@
 
 			*local = g_new0 (EToDoLocalRecord, 1);
 			local_record_from_comp (*local, iterator->data, ctxt);
-			ctxt->locals = g_list_prepend (ctxt->locals, *local);
+			
+			/* NOTE: ignore the return value, otherwise ctxt->locals
+			 * gets messed up. The calling function keeps track of
+			 * the *local variable */
+			g_list_prepend (ctxt->locals, *local);
 		} else {
 			LOG (g_message ( "for_each ending" ));
 
@@ -1369,7 +1283,11 @@
 		
 			*local = g_new0 (EToDoLocalRecord, 1);
 			local_record_from_comp (*local, ccc->comp, ctxt);
-			ctxt->locals = g_list_prepend (ctxt->locals, *local);
+			
+			/* NOTE: ignore the return value, otherwise ctxt->locals
+			 * gets messed up. The calling function keeps track of
+			 * the *local variable */
+			g_list_prepend (ctxt->locals, *local);
 		} else {
 			LOG (g_message ( "no events" ));
 
@@ -1383,7 +1301,11 @@
 			
 			*local = g_new0 (EToDoLocalRecord, 1);
 			local_record_from_comp (*local, ccc->comp, ctxt);			
-			ctxt->locals = g_list_prepend (ctxt->locals, *local);
+			
+			/* NOTE: ignore the return value, otherwise ctxt->locals
+			 * gets messed up. The calling function keeps track of
+			 * the *local variable */
+			g_list_prepend (ctxt->locals, *local);
 		} else {
 			LOG (g_message ( "for_each_modified ending" ));
 
Index: calendar/conduits/common/libecalendar-common-conduit.c
===================================================================
--- calendar/conduits/common/libecalendar-common-conduit.c	(revision 0)
+++ calendar/conduits/common/libecalendar-common-conduit.c	(revision 0)
@@ -0,0 +1,203 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* Evolution calendar - ToDo Conduit
+ *
+ * Copyright (C) 2007 Novell, Inc.
+ *
+ * Authors: Tom Billet <mouse256@ulyssis.org>
+ *          Nathan Owens <pianocomp81@yahoo.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * 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 <string.h>
+
+#include <libedataserver/e-categories.h>
+#include <e-util/e-pilot-util.h>
+#include <pi-appinfo.h>
+#include <glib.h>
+
+#include "libecalendar-common-conduit.h"
+
+/*make debugging possible if it's required for a conduit */
+#define LOG(x)
+#ifdef DEBUG_CALCONDUIT
+#define LOG(x) x
+#endif 
+#ifdef DEBUG_MEMOCONDUIT
+#define LOG(x) x
+#endif
+#ifdef DEBUG_TODOCONDUIT
+#define LOG(x) x
+#endif 
+#ifdef DEBUG_CONDUIT
+#define LOG(x) x
+#endif 
+
+/*
+ * Adds a category to the category app info structure (name and ID),
+ * sets category->renamed[i] to true if possible to rename.
+ * 
+ * This will be packed and written to the app info block during post_sync.
+ * 
+ * NOTE: cat_to_add MUST be in PCHAR format. Evolution stores categories
+ *       in UTF-8 format. A conversion must take place before calling
+ *       this function (see e_pilot_utf8_to_pchar() in e-pilot-util.c)
+ */
+int
+e_pilot_add_category_if_possible(char *cat_to_add, struct CategoryAppInfo *category)
+{
+	int i, j;
+	int retval = 0; /* 0 is the Unfiled category */
+	LOG(g_message("e_pilot_add_category_if_possible\n"));
+	
+	for(i=0; i<PILOT_MAX_CATEGORIES; i++){
+		/* if strlen is 0, then the category is empty
+		   the PalmOS doesn't let 0-length strings for
+		   categories */
+		if(strlen(category->name[i]) == 0){
+			int cat_to_add_len;
+			
+			cat_to_add_len = strlen(cat_to_add);
+			retval = i;
+
+			if(cat_to_add_len > 15){
+				/* Have to truncate the category name */
+				cat_to_add_len = 15;
+			}
+			
+			/* only 15 characters for category, 16th is
+			 * '\0' can't do direct mem transfer due to
+			 * declaration type
+			 */
+			for(j=0; j<cat_to_add_len; j++){
+				category->name[i][j] = cat_to_add[j];
+			}
+
+			for(j=cat_to_add_len; j<16; j++) {
+				category->name[i][j] = '\0';
+			}
+			
+			//find a desktop id that is not in use between 128 and 255
+			int desktopUniqueID;
+			for (desktopUniqueID = 128; desktopUniqueID <= 255; desktopUniqueID++) {
+				int found = 0;
+				for(j=0; j<PILOT_MAX_CATEGORIES; j++){
+					if (category->ID[i] == desktopUniqueID) {
+						found = 1;
+					}
+				}
+				if (found == 0) {
+					break;
+				}
+				if (desktopUniqueID == 255) {
+					LOG(g_warning( _("*** no more categories available on PC ***")));
+				}
+			}
+			category->ID[i] = desktopUniqueID;
+			
+			category->renamed[i] = TRUE;
+			
+			break;
+		}
+	}
+	
+	if(retval == 0){
+		LOG (g_warning( _("*** not adding category - category list already full ***") ));
+	}
+	
+	return retval;
+}
+
+/*
+ *conversion from an evolution category to a palm category
+ */
+void e_pilot_local_category_to_remote(int * pilotCategory, ECalComponent *comp, struct CategoryAppInfo *category)
+{
+	GSList *c_list = NULL;
+	char * category_string;
+	int i;
+	e_cal_component_get_categories_list (comp, &c_list);
+	if (c_list) {
+		//list != 0, so at least 1 category is assigned
+		category_string = e_pilot_utf8_to_pchar((const char *)c_list->data);
+		if (c_list->next != 0) {
+			LOG (g_message ("Note: item has more categories in evolution, first chosen"));
+		}
+		i=1;
+		while (1) {
+			if (strcmp(category_string,category->name[i]) == 0) {
+				*pilotCategory = i;
+				break;
+			}
+			i++;
+			if (i == PILOT_MAX_CATEGORIES) {
+				/* category not available on palm, try to create it */
+				*pilotCategory = e_pilot_add_category_if_possible(category_string,category);
+				break;
+			}
+		}
+		e_cal_component_free_categories_list(c_list);
+		c_list = NULL;
+	} else {
+		*pilotCategory = 0;
+	}
+	/*end category*/
+}
+
+/*
+ *conversion from a palm category to an evolution category
+ */
+void e_pilot_remote_category_to_local(int pilotCategory, ECalComponent *comp, struct CategoryAppInfo *category)
+{
+	char *category_string = NULL;
+
+	if (pilotCategory != 0) {
+		/* pda has category assigned */
+		category_string = e_pilot_utf8_from_pchar(category->name[pilotCategory]);
+
+		LOG(g_message("Category: %s\n", category_string));
+
+		/* TODO The calendar editor page and search bar are not updated until a restart of the evolution client */
+		if(e_categories_exist(category_string) == FALSE){
+			/* add if it doesn't exist */
+			LOG(g_message("Category created on pc\n"));
+			e_categories_add(category_string, NULL, NULL, TRUE);
+		}
+	}
+
+	/* store the data on in evolution */
+	if (category_string == NULL) {
+		/* note: this space is needed to make sure evolution clears the category */
+		e_cal_component_set_categories (comp, " "); 
+	} 
+	else {
+
+		/* Since only the first category is synced with the PDA, add the PDA's
+		 * category to the beginning of the category list */
+		GSList *c_list = NULL;
+		GSList *newcat_in_list;
+		e_cal_component_get_categories_list (comp, &c_list);
+
+		/* remove old item from list so we don't have duplicate entries */		
+		newcat_in_list = g_slist_find_custom(c_list, category_string, (GCompareFunc)strcmp);
+		if(newcat_in_list != NULL)
+		{
+			c_list = g_slist_remove(c_list, newcat_in_list->data);
+		}
+
+		c_list = g_slist_prepend(c_list, category_string);
+		e_cal_component_set_categories_list (comp, c_list);
+		e_cal_component_free_categories_list(c_list);
+	}
+}

Property changes on: calendar/conduits/common/libecalendar-common-conduit.c
___________________________________________________________________
Name: svn:eol-style
   + native

Index: calendar/conduits/common/libecalendar-common-conduit.h
===================================================================
--- calendar/conduits/common/libecalendar-common-conduit.h	(revision 0)
+++ calendar/conduits/common/libecalendar-common-conduit.h	(revision 0)
@@ -0,0 +1,15 @@
+
+
+#include <libedataserver/e-categories.h>
+#include <libecal/e-cal.h>
+#include <pi-appinfo.h>
+
+#define PILOT_MAX_CATEGORIES 16
+
+
+int e_pilot_add_category_if_possible(char *cat_to_add, struct CategoryAppInfo *category);
+void e_pilot_local_category_to_remote(int * pilotCategory, ECalComponent *comp, struct CategoryAppInfo *category);
+void e_pilot_remote_category_to_local(int   pilotCategory, ECalComponent *comp, struct CategoryAppInfo *category);
+
+
+

Property changes on: calendar/conduits/common/libecalendar-common-conduit.h
___________________________________________________________________
Name: svn:eol-style
   + native

Index: calendar/conduits/common/Makefile.am
===================================================================
--- calendar/conduits/common/Makefile.am	(revision 0)
+++ calendar/conduits/common/Makefile.am	(revision 0)
@@ -0,0 +1,19 @@
+INCLUDES = 					\
+	-I$(top_srcdir)/e-util			\
+	-I$(top_builddir)/e-util		\
+	$(EVOLUTION_CALENDAR_CONDUIT_CFLAGS)
+
+# Calendar Conduit library
+privconduit_LTLIBRARIES = libecalendar_common_conduit.la
+
+libecalendar_common_conduit_la_SOURCES = 	\
+	libecalendar-common-conduit.c
+
+libecalendar_common_conduit_la_LDFLAGS = $(pilot_compile)
+libecalendar_common_conduit_la_LIBADD = 						\
+	$(top_builddir)/e-util/libeutil.la				\
+	$(top_builddir)/e-util/libeconduit.la		 		\
+	$(EVOLUTION_CALENDAR_CONDUIT_LIBS)
+
+
+
Index: calendar/conduits/calendar/Makefile.am
===================================================================
--- calendar/conduits/calendar/Makefile.am	(revision 34104)
+++ calendar/conduits/calendar/Makefile.am	(working copy)
@@ -3,6 +3,8 @@
 	-I$(top_builddir)/e-util		\
 	-I$(top_srcdir)/widgets/misc		\
 	-I$(top_builddir)/widgets/misc		\
+	-I$(top_srcdir)/calendar/conduits/common		\
+	-I$(top_builddir)/calendar/conduits/common		\
 	$(EVOLUTION_CALENDAR_CONDUIT_CFLAGS)
 
 # Calendar Conduit
@@ -17,6 +19,7 @@
 	$(top_builddir)/e-util/libeutil.la				\
 	$(top_builddir)/e-util/libeconduit.la				\
 	$(top_builddir)/widgets/misc/libemiscwidgets.la			\
+	$(top_builddir)/calendar/conduits/common/libecalendar_common_conduit.la	\
 	$(EVOLUTION_CALENDAR_CONDUIT_LIBS)
 
 e-calendar.conduit: e-calendar.conduit.in
Index: calendar/conduits/calendar/calendar-conduit.c
===================================================================
--- calendar/conduits/calendar/calendar-conduit.c	(revision 34104)
+++ calendar/conduits/calendar/calendar-conduit.c	(working copy)
@@ -42,6 +42,7 @@
 #include <e-pilot-settings.h>
 #include <e-pilot-util.h>
 #include <e-config-listener.h>
+#include <libecalendar-common-conduit.h>
 
 GnomePilotConduit * conduit_get_gpilot_conduit (guint32);
 void conduit_destroy_gpilot_conduit (GnomePilotConduit*);
@@ -87,7 +88,7 @@
 {
 	g_object_unref (local->comp);
 	free_Appointment (local->appt);
-	g_free (local->appt);	
+	g_free (local->appt);
 	g_free (local);
 }
 
@@ -938,6 +939,9 @@
 		pi_buffer_free (record);
 #endif
 	}
+	
+	/*Category support*/
+	e_pilot_local_category_to_remote(&(local->local.category), comp, &(ctxt->ai.category));
 
 	/* STOP: don't replace these with g_strdup, since free_Appointment
 	   uses free to deallocate */
@@ -1183,7 +1187,8 @@
 			 GnomePilotRecord *remote,
 			 ECalComponent *in_comp,
 			 ECal *client,
-			 icaltimezone *timezone)
+			 icaltimezone *timezone,
+			 struct CategoryAppInfo *category)
 {
 	ECalComponent *comp;
 	struct Appointment appt;
@@ -1229,6 +1234,9 @@
 	summary.value = txt = e_pilot_utf8_from_pchar (appt.description);
 	e_cal_component_set_summary (comp, &summary);
 	free (txt);
+	
+	/*Category support*/
+	e_pilot_remote_category_to_local(remote->category, comp, category);
 
 	/* The iCal description field */
 	if (!appt.note) {
@@ -1621,6 +1629,7 @@
 	pi_buffer_free(buffer);
 #endif
 	unpack_AppointmentAppInfo (&(ctxt->ai), buf, len);
+	//unpack_CategoryAppInfo (&(ctxt->ai.category), buf, len);
 	g_free (buf);
 
 	check_for_slow_setting (conduit, ctxt);
@@ -1638,8 +1647,28 @@
 {
 	GList *changed;
 	gchar *filename, *change_id;
+	unsigned char *buf;
+	int dlpRetVal, len;
 	
 	LOG (g_message ( "post_sync: Calendar Conduit v.%s", CONDUIT_VERSION ));
+	
+	/* Write AppBlock to PDA - updates categories */
+	buf = (unsigned char*)g_malloc (0xffff);
+	
+	len = pack_AppointmentAppInfo (&(ctxt->ai), buf, 0xffff);
+	
+	dlpRetVal = dlp_WriteAppBlock (dbi->pilot_socket, dbi->db_handle, 
+			      (unsigned char *)buf, len);
+	
+	g_free (buf);
+			      
+	if (dlpRetVal < 0) {
+		WARN (_("Could not write pilot's Calendar application block"));
+		WARN ("dlp_WriteAppBlock(...) = %d", dlpRetVal);
+		gnome_pilot_conduit_error (conduit,
+					   _("Could not write pilot's Calendar application block"));
+		return -1;
+	}
 
 	g_free (ctxt->cfg->last_uri);
 	ctxt->cfg->last_uri = g_strdup (e_cal_get_uri (ctxt->client));
@@ -1714,8 +1743,12 @@
 
 			*local = g_new0 (ECalLocalRecord, 1);
 			local_record_from_comp (*local, comps->data, ctxt);
-			ctxt->locals = g_list_prepend (ctxt->locals, *local);
 
+			/* NOTE: ignore the return value, otherwise ctxt->locals
+			 * gets messed up. The calling function keeps track of
+			 * the *local variable */
+			g_list_prepend (ctxt->locals, *local);
+
 			iterator = comps;
 		} else {
 			LOG (g_message ( "no events" ));
@@ -1729,7 +1762,11 @@
 
 			*local = g_new0 (ECalLocalRecord, 1);
 			local_record_from_comp (*local, iterator->data, ctxt);
-			ctxt->locals = g_list_prepend (ctxt->locals, *local);
+
+			/* NOTE: ignore the return value, otherwise ctxt->locals
+			 * gets messed up. The calling function keeps track of
+			 * the *local variable */
+			g_list_prepend (ctxt->locals, *local);
 		} else {
 			LOG (g_message ( "for_each ending" ));
 
@@ -1768,7 +1805,11 @@
 		
 			*local = g_new0 (ECalLocalRecord, 1);
 			local_record_from_comp (*local, ccc->comp, ctxt);
-			ctxt->locals = g_list_prepend (ctxt->locals, *local);
+
+			/* NOTE: ignore the return value, otherwise ctxt->locals
+			 * gets messed up. The calling function keeps track of
+			 * the *local variable */
+			g_list_prepend (ctxt->locals, *local);
 		} else {
 			LOG (g_message ( "no events" ));
 
@@ -1782,7 +1823,11 @@
 			
 			*local = g_new0 (ECalLocalRecord, 1);
 			local_record_from_comp (*local, ccc->comp, ctxt);
-			ctxt->locals = g_list_prepend (ctxt->locals, *local);
+
+			/* NOTE: ignore the return value, otherwise ctxt->locals
+			 * gets messed up. The calling function keeps track of
+			 * the *local variable */
+			g_list_prepend (ctxt->locals, *local);
 		} else {
 			LOG (g_message ( "for_each_modified ending" ));
 
@@ -1837,7 +1882,7 @@
 
 	LOG (g_message ( "add_record: adding %s to desktop\n", print_remote (remote) ));
 
-	comp = comp_from_remote_record (conduit, remote, ctxt->default_comp, ctxt->client, ctxt->timezone);
+	comp = comp_from_remote_record (conduit, remote, ctxt->default_comp, ctxt->client, ctxt->timezone, &(ctxt->ai.category));
 
 	/* Give it a new UID otherwise it will be the uid of the default comp */
 	uid = e_cal_component_gen_uid ();
@@ -1869,7 +1914,7 @@
 	LOG (g_message ("replace_record: replace %s with %s\n",
 			print_local (local), print_remote (remote)));
 
-	new_comp = comp_from_remote_record (conduit, remote, local->comp, ctxt->client, ctxt->timezone);
+	new_comp = comp_from_remote_record (conduit, remote, local->comp, ctxt->client, ctxt->timezone, &(ctxt->ai.category));
 	g_object_unref (local->comp);
 	local->comp = new_comp;
 
Index: calendar/conduits/Makefile.am
===================================================================
--- calendar/conduits/Makefile.am	(revision 34104)
+++ calendar/conduits/Makefile.am	(working copy)
@@ -1 +1,3 @@
-SUBDIRS = calendar memo todo
+SUBDIRS = common calendar memo todo
+
+
Index: calendar/conduits/memo/memo-conduit.c
===================================================================
--- calendar/conduits/memo/memo-conduit.c	(revision 34104)
+++ calendar/conduits/memo/memo-conduit.c	(working copy)
@@ -45,6 +45,7 @@
 #include <e-pilot-settings.h>
 #include <e-pilot-util.h>
 #include <e-config-listener.h>
+#include <libecalendar-common-conduit.h>
 
 GnomePilotConduit * conduit_get_gpilot_conduit (guint32);
 void conduit_destroy_gpilot_conduit (GnomePilotConduit*);
@@ -504,70 +505,6 @@
 }
 
 /*
- * Adds a category to the category app info structure (name and ID),
- * sets category->renamed[i] to true if possible to rename.
- * 
- * This will be packed and written to the app info block during post_sync.
- */
- 
-static int
-add_category_if_possible(char *cat_to_add, struct CategoryAppInfo *category)
-{
-	int i, j;
-	int retval = 0; /* 0 is the Unfiled category */
-	LOG(fprintf(stderr, "add_category_if_possible: called\n"));
-	
-	for(i=0; i<16; i++){
-		/* if strlen is 0, then the category is empty
-		   the PalmOS doesn't let 0-length strings for
-		   categories */
-		LOG(fprintf(stderr, "add_category_if_possible: calling strlen, i==%d\n", i));
-		if(strlen(category->name[i]) == 0){
-			int cat_to_add_len;
-			LOG(fprintf(stderr, "add_category_if_possible: strlen == 0\n"));
-			
-			cat_to_add_len = strlen(cat_to_add);
-			LOG(fprintf(stderr, "add_category_if_possible: cat_to_add_len: %d\n",
-					cat_to_add_len));
-			retval = i;
-			
-			/* only 15 characters for category, 16th is
-			 * '\0' can't do direct mem transfer due to
-			 * declaration type
-			 */
-			LOG(fprintf(stderr, "add_category_if_possible: copying first 15 of category\n"));
-			for(j=0; j<cat_to_add_len; j++){
-				category->name[i][j] = cat_to_add[j];
-			}
-			LOG(fprintf(stderr,
-				"add_category_if_possible: setting from %d to i==15 to \\0\n",
-				cat_to_add_len));
-
-			for(j=cat_to_add_len; j<16; j++)
-				category->name[i][j] = '\0';
-			
-			LOG(fprintf(stderr, "add_category_if_possible: setting ID[%d] to %d\n",
-				category->ID[i], lastDesktopUniqueID));
-			category->ID[i] = lastDesktopUniqueID;
-			lastDesktopUniqueID++;
-			
-			LOG(fprintf(stderr, "add_category_if_possible: setting renamed[%d] to TRUE\n", i));
-			category->renamed[i] = TRUE;
-			
-			LOG(g_message("*** adding category '%s', ID %d ***",
-				category->name[i], category->ID[i]));
-			break;
-		}
-	}
-	
-	if(retval == 0){
-		LOG(g_message("*** not adding category - category list already full ***"));
-	}
-	
-	return retval;
-}
-
-/*
  * converts a ECalComponent object to a EMemoLocalRecord
  */
 static void
@@ -638,51 +575,8 @@
 		LOG(fprintf(stderr, "local_record_from_comp: done calling dlp_ReadRecordById\n"));
 	}
 	
-	/*
-	 * Grab category from existing category list in ctxt->ai.category
-	 */
-	if(local->local.category == 0){
-		GSList *categ_list_head, *categ_list_cur;
-		int cat = -1;
-		int i;
-		
-		LOG(fprintf(stderr, "local_record_from_comp: trying to set category"));
-		LOG(fprintf(stderr, "local_record_from_comp: calling e_cal_component_get_categories_list\n"));
-		
-		e_cal_component_get_categories_list(comp, &categ_list_head);
-		LOG(fprintf(stderr, "local_record_from_comp: got list, setting categ_list_cur to head\n"));
-		
-		categ_list_cur = categ_list_head;
-		while (categ_list_cur && cat == -1)
-		{	
-			LOG(fprintf(stderr, "local_record_from_comp: iterating, data == %s",
-				(char *)categ_list_cur->data));
-			for(i=0; i<16; i++){
-				LOG(fprintf(stderr, "local_record_from_comp: i == %d\n", i));
-				if(strcmp((char *)categ_list_cur->data,
-					  ctxt->ai.category.name[i]) == 0){
-					cat = i;
-					LOG(fprintf(stderr, "local_record_from_comp: found category, name: %s\n",
-							ctxt->ai.category.name[i]));
-					break;
-				}
-			}
-			
-			LOG(fprintf(stderr, "local_record_from_comp: calling g_slist_next\n"));
-			categ_list_cur = g_slist_next(categ_list_cur);
-		}
-		
-		if(cat != -1){
-			LOG(fprintf(stderr, "local_record_from_comp: setting category\n"));
-			local->local.category = cat;
-		}
-		else if(categ_list_head != NULL){
-			local->local.category =
-				add_category_if_possible(
-					(char *)(categ_list_head->data),
-					&(ctxt->ai.category));
-		}
-	}
+	/*Category support*/
+	e_pilot_local_category_to_remote(&(local->local.category), comp, &(ctxt->ai.category));
 
 	/* STOP: don't replace these with g_strdup, since free_Memo
 	   uses free to deallocate */
@@ -759,7 +653,6 @@
 	struct icaltimetype now;
 	icaltimezone *utc_zone;
 	char *txt, *txt2, *txt3;
-	char *category;
 	int i;
 #ifdef PILOT_LINK_0_12
 	pi_buffer_t * buffer;
@@ -797,6 +690,9 @@
 
 	e_cal_component_set_last_modified (comp, &now);
 	
+	/*Category support*/
+	e_pilot_remote_category_to_local(remote->category, comp, &(ai->category));
+	
 	/* The iCal description field */
 	if (!memo.text) {
 		e_cal_component_set_comment_list (comp, NULL);
@@ -851,19 +747,6 @@
 		e_cal_component_set_classification (comp, E_CAL_COMPONENT_CLASS_PRIVATE);
 	else
 		e_cal_component_set_classification (comp, E_CAL_COMPONENT_CLASS_PUBLIC);
-	
-	
-	/* set the category properly */
-	category = ai->category.name[remote->category];
-	
-	/* TODO The Memos editor page and search bar are not updated until
-	  a restart of the evolution client */
-	if(e_categories_exist(category) == FALSE){
-		/* add if it doesn't exist */
-		e_categories_add(category, NULL, NULL, TRUE);
-	}
-	
-	e_cal_component_set_categories(comp, category);
 
 	e_cal_component_commit_sequence (comp);
 	
@@ -1150,11 +1033,12 @@
 			LOG (g_message ( "for_each: iterating over %d records", g_list_length (comps)));
 
 			*local = g_new0 (EMemoLocalRecord, 1);
-			LOG(fprintf(stderr, "for_each: calling local_record_from_comp\n"));
 			local_record_from_comp (*local, comps->data, ctxt);
-			LOG(fprintf(stderr, "for_each: calling g_list_prepend\n"));
-			ctxt->locals = g_list_prepend (ctxt->locals, *local);
-			LOG(fprintf(stderr, "for_each: setting iterator = comps\n"));
+
+			/* NOTE: ignore the return value, otherwise ctxt->locals
+			 * gets messed up. The calling function keeps track of
+			 * the *local variable */
+		        g_list_prepend (ctxt->locals, *local);
 			iterator = comps;
 		} else {
 			LOG (g_message ( "no events" ));
@@ -1163,15 +1047,18 @@
 		}
 	} else {
 		count++;
-		LOG(fprintf(stderr, "for_each: calling g_list_next (else part)\n"));
+
 		if (g_list_next (iterator)) {
 			iterator = g_list_next (iterator);
-			LOG(fprintf(stderr, "for_each: creating EMemoLocalRecord\n"));
+
 			*local = g_new0 (EMemoLocalRecord, 1);
 			LOG(fprintf(stderr, "for_each: calling local_record_from_comp\n"));
 			local_record_from_comp (*local, iterator->data, ctxt);
-			LOG(fprintf(stderr, "for_each: calling g_list_prepend\n"));
-			ctxt->locals = g_list_prepend (ctxt->locals, *local);
+
+			/* NOTE: ignore the return value, otherwise ctxt->locals
+			 * gets messed up. The calling function keeps track of
+			 * the *local variable */
+			g_list_prepend (ctxt->locals, *local);
 		} else {
 			LOG (g_message ( "for_each ending" ));
 
@@ -1207,12 +1094,14 @@
 		iterator = next_changed_item (ctxt, iterator);
 		if (iterator != NULL) {
 			ECalChange *ccc = iterator->data;
-			LOG(fprintf(stderr, "for_each_modified: creating EMemoLocalRecord\n"));
+
 			*local = g_new0 (EMemoLocalRecord, 1);
-			LOG(fprintf(stderr, "for_each_modified: calling local_record_from_comp\n"));
 			local_record_from_comp (*local, ccc->comp, ctxt);
-			LOG(fprintf(stderr, "for_each_modified: calling g_list_prepend\n"));
-			ctxt->locals = g_list_prepend (ctxt->locals, *local);
+
+			/* NOTE: ignore the return value, otherwise ctxt->locals
+			 * gets messed up. The calling function keeps track of
+			 * the *local variable */
+			g_list_prepend (ctxt->locals, *local);
 		} else {
 			LOG (g_message ( "no events" ));
 
@@ -1220,17 +1109,18 @@
 		}
 	} else {
 		count++;
-		LOG(fprintf(stderr, "for_each_modified: calling g_list_next\n"));
+
 		iterator = g_list_next (iterator);
-		LOG(fprintf(stderr, "for_each_modified: calling next_changed_item\n"));
 		if (iterator && (iterator = next_changed_item (ctxt, iterator))) {
 			ECalChange *ccc = iterator->data;
-			LOG(fprintf(stderr, "for_each_modified: calling EMemoLocalRecord\n"));
+
 			*local = g_new0 (EMemoLocalRecord, 1);
-			LOG(fprintf(stderr, "for_each_modified: calling local_record_from_comp\n"));
 			local_record_from_comp (*local, ccc->comp, ctxt);
-			LOG(fprintf(stderr, "for_each_modified: calling g_list_prepend\n"));
-			ctxt->locals = g_list_prepend (ctxt->locals, *local);
+
+			/* NOTE: ignore the return value, otherwise ctxt->locals
+			 * gets messed up. The calling function keeps track of
+			 * the *local variable */
+			g_list_prepend (ctxt->locals, *local);
 		} else {
 			LOG (g_message ( "for_each_modified ending" ));
 
Index: calendar/conduits/memo/Makefile.am
===================================================================
--- calendar/conduits/memo/Makefile.am	(revision 34104)
+++ calendar/conduits/memo/Makefile.am	(working copy)
@@ -3,6 +3,8 @@
 	-I$(top_builddir)/e-util		\
 	-I$(top_srcdir)/widgets/misc		\
 	-I$(top_builddir)/widgets/misc		\
+	-I$(top_srcdir)/calendar/conduits/common		\
+	-I$(top_builddir)/calendar/conduits/common		\
 	$(EVOLUTION_CALENDAR_CONDUIT_CFLAGS)
 
 # Memo Conduit
@@ -17,6 +19,7 @@
 	$(top_builddir)/e-util/libeutil.la				\
 	$(top_builddir)/e-util/libeconduit.la				\
 	$(top_builddir)/widgets/misc/libemiscwidgets.la			\
+	$(top_builddir)/calendar/conduits/common/libecalendar_common_conduit.la	\
 	$(EVOLUTION_CALENDAR_CONDUIT_LIBS)
 
 e-memo.conduit: e-memo.conduit.in
