[evolution] Fixed bug 364618, solve the chinese character issue.



commit 9cd8dede8bd6eac41f7486d95336909051d9b4c2
Author: Jeff Cai <jeff cai sun com>
Date:   Mon Nov 30 18:04:18 2009 +0800

    Fixed bug 364618, solve the chinese character issue.

 addressbook/conduit/address-conduit.c              |   86 +++++++++++--------
 calendar/conduits/calendar/calendar-conduit.c      |   30 +++++--
 .../conduits/common/libecalendar-common-conduit.c  |    8 +-
 .../conduits/common/libecalendar-common-conduit.h  |    4 +-
 calendar/conduits/memo/memo-conduit.c              |   29 +++++--
 calendar/conduits/todo/todo-conduit.c              |   45 +++++++----
 e-util/e-pilot-util.c                              |   18 +++-
 e-util/e-pilot-util.h                              |    4 +-
 8 files changed, 141 insertions(+), 83 deletions(-)
---
diff --git a/addressbook/conduit/address-conduit.c b/addressbook/conduit/address-conduit.c
index 2b0317e..aeb8a1e 100644
--- a/addressbook/conduit/address-conduit.c
+++ b/addressbook/conduit/address-conduit.c
@@ -256,7 +256,8 @@ e_pilot_add_category_if_possible(gchar *cat_to_add, struct CategoryAppInfo *cate
  */
 static
 void e_pilot_local_category_to_remote(gint * pilotCategory,
-    EContact *contact, struct CategoryAppInfo *category)
+    EContact *contact, struct CategoryAppInfo *category,
+	const gchar *pilot_charset)
 {
 	GList *c_list = NULL, *l;
 	gchar * category_string, *first_category = NULL;
@@ -265,12 +266,12 @@ void e_pilot_local_category_to_remote(gint * pilotCategory,
 	c_list = e_contact_get (contact, E_CONTACT_CATEGORY_LIST);
 	if (c_list) {
 		/* remember the first category */
-		first_category = e_pilot_utf8_to_pchar((const gchar *)c_list->data);
+		first_category = e_pilot_utf8_to_pchar((const gchar *)c_list->data, pilot_charset);
 	}
 	l = c_list;
 	while (l && *pilotCategory == 0) {
 		/* list != 0, so at least 1 category is assigned */
-		category_string = e_pilot_utf8_to_pchar((const gchar *)l->data);
+		category_string = e_pilot_utf8_to_pchar((const gchar *)l->data, pilot_charset);
 		for (i=0; i < PILOT_MAX_CATEGORIES; i++) {
 			/* only 15 chars + nul in palm category name */
 			if (strncmp(category_string,category->name[i], 15) == 0) {
@@ -301,14 +302,15 @@ void e_pilot_local_category_to_remote(gint * pilotCategory,
  */
 static
 void e_pilot_remote_category_to_local(gint pilotCategory,
-    EContact *contact, struct CategoryAppInfo *category)
+    EContact *contact, struct CategoryAppInfo *category,
+	const gchar *pilot_charset)
 {
 	gchar *category_string = NULL;
 
 	if (pilotCategory != 0) {
 		/* pda has category assigned */
 		category_string = e_pilot_utf8_from_pchar(
-		    category->name[pilotCategory]);
+		    category->name[pilotCategory], pilot_charset);
 
 		LOG(g_message("PDA Category: %s\n", category_string));
 
@@ -658,6 +660,8 @@ struct _EAddrConduitContext {
 	GList *locals;
 
 	EPilotMap *map;
+
+	gchar * pilot_charset;
 };
 
 static EAddrConduitContext *
@@ -675,6 +679,7 @@ e_addr_context_new (guint32 pilot_id)
 	ctxt->changed = NULL;
 	ctxt->locals = NULL;
 	ctxt->map = NULL;
+	ctxt->pilot_charset = NULL;
 
 	return ctxt;
 }
@@ -1032,12 +1037,13 @@ is_syncable (EAddrConduitContext *ctxt, EAddrLocalRecord *local)
 }
 
 static void
-set_contact_text (EContact *contact, EContactField field, struct Address address, gint entry)
+set_contact_text (EContact *contact, EContactField field, struct Address address, 
+	gint entry, const gchar *pilot_charset)
 {
 	gchar *text = NULL;
 
 	if (address.entry[entry])
-		text = e_pilot_utf8_from_pchar (address.entry[entry]);
+		text = e_pilot_utf8_from_pchar (address.entry[entry], pilot_charset);
 
 	e_contact_set (contact, field, text);
 
@@ -1045,10 +1051,10 @@ set_contact_text (EContact *contact, EContactField field, struct Address address
 }
 
 static gchar *
-get_entry_text (struct Address address, gint entry)
+get_entry_text (struct Address address, gint entry, const gchar *pilot_charset)
 {
 	if (address.entry[entry])
-		return e_pilot_utf8_from_pchar (address.entry[entry]);
+		return e_pilot_utf8_from_pchar (address.entry[entry], pilot_charset);
 
 	return NULL;
 }
@@ -1208,12 +1214,12 @@ local_record_from_ecard (EAddrLocalRecord *local, EContact *contact, EAddrCondui
 	}
 
 	/*Category support*/
-	e_pilot_local_category_to_remote(&(local->local.category), contact, &(ctxt->ai.category));
+	e_pilot_local_category_to_remote(&(local->local.category), contact, &(ctxt->ai.category), ctxt->pilot_charset);
 
-	local->addr->entry[entryFirstname] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_GIVEN_NAME));
-	local->addr->entry[entryLastname] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_FAMILY_NAME));
-	local->addr->entry[entryCompany] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_ORG));
-	local->addr->entry[entryTitle] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_TITLE));
+	local->addr->entry[entryFirstname] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_GIVEN_NAME), ctxt->pilot_charset);
+	local->addr->entry[entryLastname] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_FAMILY_NAME), ctxt->pilot_charset);
+	local->addr->entry[entryCompany] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_ORG), ctxt->pilot_charset);
+	local->addr->entry[entryTitle] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_TITLE), ctxt->pilot_charset);
 
 	/* See if the default has something in it */
 	if ((address = e_contact_get (contact, ctxt->cfg->default_address))) {
@@ -1239,13 +1245,13 @@ local_record_from_ecard (EAddrLocalRecord *local, EContact *contact, EAddrCondui
 			add = g_strdup (address->street);
 			LOG (g_warning ("Address has only one line: [%s]\n", add));
 		}
-		local->addr->entry[entryAddress] = e_pilot_utf8_to_pchar (add);
+		local->addr->entry[entryAddress] = e_pilot_utf8_to_pchar (add, ctxt->pilot_charset);
 		g_free (add);
 
-		local->addr->entry[entryCity] = e_pilot_utf8_to_pchar (address->locality);
-		local->addr->entry[entryState] = e_pilot_utf8_to_pchar (address->region);
-		local->addr->entry[entryZip] = e_pilot_utf8_to_pchar (address->code);
-		local->addr->entry[entryCountry] = e_pilot_utf8_to_pchar (address->country);
+		local->addr->entry[entryCity] = e_pilot_utf8_to_pchar (address->locality, ctxt->pilot_charset);
+		local->addr->entry[entryState] = e_pilot_utf8_to_pchar (address->region, ctxt->pilot_charset);
+		local->addr->entry[entryZip] = e_pilot_utf8_to_pchar (address->code, ctxt->pilot_charset);
+		local->addr->entry[entryCountry] = e_pilot_utf8_to_pchar (address->country, ctxt->pilot_charset);
 
 		e_contact_address_free (address);
 	}
@@ -1266,7 +1272,7 @@ local_record_from_ecard (EAddrLocalRecord *local, EContact *contact, EAddrCondui
 			phone_str = e_contact_get_const (contact, priority[i]);
 			if (phone_str && *phone_str) {
 				clear_entry_text (*local->addr, phone);
-				local->addr->entry[phone] = e_pilot_utf8_to_pchar (phone_str);
+				local->addr->entry[phone] = e_pilot_utf8_to_pchar (phone_str, ctxt->pilot_charset);
 				local->addr->phoneLabel[phone - entryPhone1] = priority_label[i];
 				phone++;
 			}
@@ -1315,13 +1321,13 @@ local_record_from_ecard (EAddrLocalRecord *local, EContact *contact, EAddrCondui
 
 			if (phone_str && *phone_str) {
 				clear_entry_text (*local->addr, i);
-				local->addr->entry[i] = e_pilot_utf8_to_pchar (phone_str);
+				local->addr->entry[i] = e_pilot_utf8_to_pchar (phone_str, ctxt->pilot_charset);
 			}
 		}
 	}
 
 	/* Note */
-	local->addr->entry[entryNote] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_NOTE));
+	local->addr->entry[entryNote] = e_pilot_utf8_to_pchar (e_contact_get_const (contact, E_CONTACT_NOTE), ctxt->pilot_charset);
 }
 
 static void
@@ -1396,12 +1402,12 @@ ecard_from_remote_record(EAddrConduitContext *ctxt,
 		contact = e_contact_duplicate (in_contact);
 
 	/*Category support*/
-	e_pilot_remote_category_to_local(remote->category, contact, &(ctxt->ai.category));
+	e_pilot_remote_category_to_local(remote->category, contact, &(ctxt->ai.category), ctxt->pilot_charset);
 
 	/* Name */
 	name = e_contact_name_new ();
-	name->given = get_entry_text (address, entryFirstname);
-	name->family = get_entry_text (address, entryLastname);
+	name->given = get_entry_text (address, entryFirstname, ctxt->pilot_charset);
+	name->family = get_entry_text (address, entryLastname, ctxt->pilot_charset);
 
 	/* set the name, respecting the pilot's given/family names */
 	e_contact_set (contact, E_CONTACT_NAME, name);
@@ -1412,13 +1418,13 @@ ecard_from_remote_record(EAddrConduitContext *ctxt,
 
 	/* File As */
 	if (!full_name || !*full_name)
-		set_contact_text (contact, E_CONTACT_FILE_AS, address, entryCompany);
+		set_contact_text (contact, E_CONTACT_FILE_AS, address, entryCompany, ctxt->pilot_charset);
 
 	g_free (full_name);
 
 	/* Title and Company */
-	set_contact_text (contact, E_CONTACT_TITLE, address, entryTitle);
-	set_contact_text (contact, E_CONTACT_ORG, address, entryCompany);
+	set_contact_text (contact, E_CONTACT_TITLE, address, entryTitle, ctxt->pilot_charset);
+	set_contact_text (contact, E_CONTACT_ORG, address, entryCompany, ctxt->pilot_charset);
 
 	/* Address */
 	mailing_address = -1;
@@ -1440,7 +1446,7 @@ ecard_from_remote_record(EAddrConduitContext *ctxt,
 
 	eaddress = g_new0 (EContactAddress, 1);
 
-	txt = get_entry_text (address, entryAddress);
+	txt = get_entry_text (address, entryAddress, ctxt->pilot_charset);
 	if (txt && (find = strchr (txt, '\n')) != NULL) {
 		*find = '\0';
 		find++;
@@ -1450,10 +1456,10 @@ ecard_from_remote_record(EAddrConduitContext *ctxt,
 
 	eaddress->street = txt;
 	eaddress->ext = find != NULL ? g_strdup (find) : g_strdup ("");
-	eaddress->locality = get_entry_text (address, entryCity);
-	eaddress->region = get_entry_text (address, entryState);
-	eaddress->country = get_entry_text (address, entryCountry);
-	eaddress->code = get_entry_text (address, entryZip);
+	eaddress->locality = get_entry_text (address, entryCity, ctxt->pilot_charset);
+	eaddress->region = get_entry_text (address, entryState, ctxt->pilot_charset);
+	eaddress->country = get_entry_text (address, entryCountry, ctxt->pilot_charset);
+	eaddress->code = get_entry_text (address, entryZip, ctxt->pilot_charset);
 
 	e_contact_set (contact, mailing_address, eaddress);
 	e_contact_address_free (eaddress);
@@ -1464,7 +1470,7 @@ ecard_from_remote_record(EAddrConduitContext *ctxt,
 
 	for (i = entryPhone1; i <= entryPhone5; i++) {
 		gint phonelabel = address.phoneLabel[i - entryPhone1];
-		gchar *phonenum = get_entry_text (address, i);
+		gchar *phonenum = get_entry_text (address, i, ctxt->pilot_charset);
 
 		if (phonelabel == LABEL_EMAIL && !is_next_done (next_mail)) {
 			e_contact_set (contact, next_mail, phonenum);
@@ -1496,7 +1502,7 @@ ecard_from_remote_record(EAddrConduitContext *ctxt,
 	}
 
 	/* Note */
-	set_contact_text (contact, E_CONTACT_NOTE, address, entryNote);
+	set_contact_text (contact, E_CONTACT_NOTE, address, entryNote, ctxt->pilot_charset);
 
 	free_Address(&address);
 
@@ -1603,6 +1609,13 @@ pre_sync (GnomePilotConduit *conduit,
 
 	ctxt->dbi = dbi;
 
+#ifdef PILOT_LINK_0_12
+	if(NULL == dbi->pilotInfo->pilot_charset)
+		ctxt->pilot_charset = NULL;
+	else
+		ctxt->pilot_charset = g_strdup(dbi->pilotInfo->pilot_charset);
+#endif
+
 	if (ctxt->cfg->source) {
 		ctxt->ebook = e_book_new (ctxt->cfg->source, NULL);
 	} else {
@@ -1759,7 +1772,8 @@ post_sync (GnomePilotConduit *conduit,
 	if (e_book_get_changes (ctxt->ebook, change_id, &changed, NULL))
 		e_book_free_change_list (changed);
 	g_free (change_id);
-
+	if (ctxt->pilot_charset)
+		g_free (ctxt->pilot_charset);
 	LOG (g_message ( "---------------------------------------------------------\n" ));
 
 	return 0;
diff --git a/calendar/conduits/calendar/calendar-conduit.c b/calendar/conduits/calendar/calendar-conduit.c
index 677c234..6aa8838 100644
--- a/calendar/conduits/calendar/calendar-conduit.c
+++ b/calendar/conduits/calendar/calendar-conduit.c
@@ -305,6 +305,8 @@ struct _ECalConduitContext {
 	GList *locals;
 
 	EPilotMap *map;
+
+	gchar *pilot_charset;
 };
 
 static ECalConduitContext *
@@ -947,19 +949,19 @@ local_record_from_comp (ECalLocalRecord *local, ECalComponent *comp, ECalConduit
 	}
 
 	/*Category support*/
-	e_pilot_local_category_to_remote(&(local->local.category), comp, &(ctxt->ai.category));
+	e_pilot_local_category_to_remote(&(local->local.category), comp, &(ctxt->ai.category), ctxt->pilot_charset);
 
 	/* STOP: don't replace these with g_strdup, since free_Appointment
 	   uses free to deallocate */
 	e_cal_component_get_summary (comp, &summary);
 	if (summary.value)
-		local->appt->description = e_pilot_utf8_to_pchar (summary.value);
+		local->appt->description = e_pilot_utf8_to_pchar (summary.value, ctxt->pilot_charset);
 
 	e_cal_component_get_description_list (comp, &d_list);
 	if (d_list) {
 		description = (ECalComponentText *) d_list->data;
 		if (description && description->value)
-			local->appt->note = e_pilot_utf8_to_pchar (description->value);
+			local->appt->note = e_pilot_utf8_to_pchar (description->value, ctxt->pilot_charset);
 		else
 			local->appt->note = NULL;
 	} else {
@@ -1200,7 +1202,8 @@ comp_from_remote_record (GnomePilotConduitSyncAbs *conduit,
 			 ECalComponent *in_comp,
 			 ECal *client,
 			 icaltimezone *timezone,
-			 struct CategoryAppInfo *category)
+			 struct CategoryAppInfo *category,
+			 const gchar *pilot_charset)
 {
 	ECalComponent *comp;
 	struct Appointment appt;
@@ -1243,12 +1246,12 @@ comp_from_remote_record (GnomePilotConduitSyncAbs *conduit,
 
 	e_cal_component_set_last_modified (comp, &now);
 
-	summary.value = txt = e_pilot_utf8_from_pchar (appt.description);
+	summary.value = txt = e_pilot_utf8_from_pchar (appt.description, pilot_charset);
 	e_cal_component_set_summary (comp, &summary);
 	free (txt);
 
 	/*Category support*/
-	e_pilot_remote_category_to_local(remote->category, comp, category);
+	e_pilot_remote_category_to_local(remote->category, comp, category, pilot_charset);
 
 	/* The iCal description field */
 	if (!appt.note) {
@@ -1257,7 +1260,7 @@ comp_from_remote_record (GnomePilotConduitSyncAbs *conduit,
 		GSList l;
 		ECalComponentText text;
 
-		text.value = txt = e_pilot_utf8_from_pchar (appt.note);
+		text.value = txt = e_pilot_utf8_from_pchar (appt.note, pilot_charset);
 		text.altrep = NULL;
 		l.data = &text;
 		l.next = NULL;
@@ -1511,6 +1514,12 @@ pre_sync (GnomePilotConduit *conduit,
 	LOG (g_message ( "pre_sync: Calendar Conduit v.%s", CONDUIT_VERSION ));
 
 	ctxt->dbi = dbi;
+#ifdef PILOT_LINK_0_12
+	if(NULL == dbi->pilotInfo->pilot_charset)
+		ctxt->pilot_charset = NULL;
+	else
+		 ctxt->pilot_charset = g_strdup(dbi->pilotInfo->pilot_charset);
+#endif
 	ctxt->client = NULL;
 
 	/* Get the timezone */
@@ -1696,6 +1705,8 @@ post_sync (GnomePilotConduit *conduit,
 	if (e_cal_get_changes (ctxt->client, change_id, &changed, NULL))
 		e_cal_free_change_list (changed);
 	g_free (change_id);
+	if (ctxt->pilot_charset)
+		g_free (ctxt->pilot_charset);
 
 	LOG (g_message ( "---------------------------------------------------------\n" ));
 
@@ -1895,7 +1906,7 @@ add_record (GnomePilotConduitSyncAbs *conduit,
 
 	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, &(ctxt->ai.category));
+	comp = comp_from_remote_record (conduit, remote, ctxt->default_comp, ctxt->client, ctxt->timezone, &(ctxt->ai.category), ctxt->pilot_charset);
 
 	/* Give it a new UID otherwise it will be the uid of the default comp */
 	uid = e_cal_component_gen_uid ();
@@ -1927,7 +1938,8 @@ replace_record (GnomePilotConduitSyncAbs *conduit,
 	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, &(ctxt->ai.category));
+	new_comp = comp_from_remote_record (conduit, remote, local->comp, ctxt->client, ctxt->timezone, &(ctxt->ai.category),
+ctxt->pilot_charset);
 	g_object_unref (local->comp);
 	local->comp = new_comp;
 
diff --git a/calendar/conduits/common/libecalendar-common-conduit.c b/calendar/conduits/common/libecalendar-common-conduit.c
index eee54e7..5a08246 100644
--- a/calendar/conduits/common/libecalendar-common-conduit.c
+++ b/calendar/conduits/common/libecalendar-common-conduit.c
@@ -126,7 +126,7 @@ e_pilot_add_category_if_possible(gchar *cat_to_add, struct CategoryAppInfo *cate
 /*
  *conversion from an evolution category to a palm category
  */
-void e_pilot_local_category_to_remote(gint * pilotCategory, ECalComponent *comp, struct CategoryAppInfo *category)
+void e_pilot_local_category_to_remote(gint * pilotCategory, ECalComponent *comp, struct CategoryAppInfo *category, const gchar *pilot_charset)
 {
 	GSList *c_list = NULL;
 	gchar * category_string;
@@ -134,7 +134,7 @@ void e_pilot_local_category_to_remote(gint * pilotCategory, ECalComponent *comp,
 	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 gchar *)c_list->data);
+		category_string = e_pilot_utf8_to_pchar((const gchar *)c_list->data, pilot_charset);
 		if (c_list->next != 0) {
 			LOG (g_message ("Note: item has more categories in evolution, first chosen"));
 		}
@@ -162,13 +162,13 @@ void e_pilot_local_category_to_remote(gint * pilotCategory, ECalComponent *comp,
 /*
  *conversion from a palm category to an evolution category
  */
-void e_pilot_remote_category_to_local(gint pilotCategory, ECalComponent *comp, struct CategoryAppInfo *category)
+void e_pilot_remote_category_to_local(gint pilotCategory, ECalComponent *comp, struct CategoryAppInfo *category, const gchar *pilot_charset)
 {
 	gchar *category_string = NULL;
 
 	if (pilotCategory != 0) {
 		/* pda has category assigned */
-		category_string = e_pilot_utf8_from_pchar(category->name[pilotCategory]);
+		category_string = e_pilot_utf8_from_pchar(category->name[pilotCategory], pilot_charset);
 
 		LOG(g_message("Category: %s\n", category_string));
 
diff --git a/calendar/conduits/common/libecalendar-common-conduit.h b/calendar/conduits/common/libecalendar-common-conduit.h
index 2eeb8b2..071403a 100644
--- a/calendar/conduits/common/libecalendar-common-conduit.h
+++ b/calendar/conduits/common/libecalendar-common-conduit.h
@@ -25,8 +25,8 @@
 #define PILOT_MAX_CATEGORIES 16
 
 gint e_pilot_add_category_if_possible(gchar *cat_to_add, struct CategoryAppInfo *category);
-void e_pilot_local_category_to_remote(gint * pilotCategory, ECalComponent *comp, struct CategoryAppInfo *category);
-void e_pilot_remote_category_to_local(gint   pilotCategory, ECalComponent *comp, struct CategoryAppInfo *category);
+void e_pilot_local_category_to_remote(gint * pilotCategory, ECalComponent *comp, struct CategoryAppInfo *category, const gchar *pilot_charset);
+void e_pilot_remote_category_to_local(gint   pilotCategory, ECalComponent *comp, struct CategoryAppInfo *category, const gchar *pilot_charset);
 
 gboolean e_pilot_setup_get_bool (const gchar *path, const gchar *key, gboolean def);
 void e_pilot_setup_set_bool (const gchar *path, const gchar *key, gboolean value);
diff --git a/calendar/conduits/memo/memo-conduit.c b/calendar/conduits/memo/memo-conduit.c
index 2a1b190..5b25ca6 100644
--- a/calendar/conduits/memo/memo-conduit.c
+++ b/calendar/conduits/memo/memo-conduit.c
@@ -225,6 +225,7 @@ struct _EMemoConduitContext {
 	GList *locals;
 
 	EPilotMap *map;
+	gchar *pilot_charset;
 };
 
 static EMemoConduitContext *
@@ -243,6 +244,7 @@ e_memo_context_new (guint32 pilot_id)
 	ctxt->changed = NULL;
 	ctxt->locals = NULL;
 	ctxt->map = NULL;
+	ctxt->pilot_charset = NULL;
 
 	return ctxt;
 }
@@ -576,7 +578,7 @@ local_record_from_comp (EMemoLocalRecord *local, ECalComponent *comp, EMemoCondu
 	}
 
 	/*Category support*/
-	e_pilot_local_category_to_remote(&(local->local.category), comp, &(ctxt->ai.category));
+	e_pilot_local_category_to_remote(&(local->local.category), comp, &(ctxt->ai.category), ctxt->pilot_charset);
 
 	/* STOP: don't replace these with g_strdup, since free_Memo
 	   uses free to deallocate */
@@ -585,7 +587,7 @@ local_record_from_comp (EMemoLocalRecord *local, ECalComponent *comp, EMemoCondu
 	if (d_list) {
 		description = (ECalComponentText *) d_list->data;
 		if (description && description->value) {
-			local->memo->text = e_pilot_utf8_to_pchar (description->value);
+			local->memo->text = e_pilot_utf8_to_pchar (description->value, ctxt->pilot_charset);
 		}
 		else{
 			local->memo->text = NULL;
@@ -645,7 +647,8 @@ comp_from_remote_record (GnomePilotConduitSyncAbs *conduit,
 			 GnomePilotRecord *remote,
 			 ECalComponent *in_comp,
 			 icaltimezone *timezone,
-			 struct MemoAppInfo *ai)
+			 struct MemoAppInfo *ai,
+			 const gchar *pilot_charset)
 {
 	ECalComponent *comp;
 	struct Memo memo;
@@ -690,7 +693,7 @@ comp_from_remote_record (GnomePilotConduitSyncAbs *conduit,
 	e_cal_component_set_last_modified (comp, &now);
 
 	/*Category support*/
-	e_pilot_remote_category_to_local(remote->category, comp, &(ai->category));
+	e_pilot_remote_category_to_local(remote->category, comp, &(ai->category), pilot_charset);
 
 	/* The iCal description field */
 	if (!memo.text) {
@@ -724,10 +727,10 @@ comp_from_remote_record (GnomePilotConduitSyncAbs *conduit,
 
 		}
 
-		sumText.value = txt3 = e_pilot_utf8_from_pchar(txt2);
+		sumText.value = txt3 = e_pilot_utf8_from_pchar(txt2, pilot_charset);
 		sumText.altrep = NULL;
 
-		text.value = txt = e_pilot_utf8_from_pchar (memo.text);
+		text.value = txt = e_pilot_utf8_from_pchar (memo.text, pilot_charset);
 		text.altrep = NULL;
 		l.data = &text;
 		l.next = NULL;
@@ -807,6 +810,13 @@ pre_sync (GnomePilotConduit *conduit,
 	ctxt->dbi = dbi;
 	ctxt->client = NULL;
 
+#ifdef PILOT_LINK_0_12
+	if(NULL == dbi->pilotInfo->pilot_charset)
+		ctxt->pilot_charset = NULL;
+	else
+		ctxt->pilot_charset = g_strdup(dbi->pilotInfo->pilot_charset);
+#endif
+
 	if (start_calendar_server (ctxt) != 0) {
 		WARN(_("Could not start evolution-data-server"));
 		gnome_pilot_conduit_error (conduit, _("Could not start evolution-data-server"));
@@ -973,7 +983,8 @@ post_sync (GnomePilotConduit *conduit,
 	if (e_cal_get_changes (ctxt->client, change_id, &changed, NULL))
 		e_cal_free_change_list (changed);
 	g_free (change_id);
-
+	if (ctxt->pilot_charset)
+		g_free (ctxt->pilot_charset);
 	LOG (g_message ( "---------------------------------------------------------\n" ));
 
 	return 0;
@@ -1174,7 +1185,7 @@ add_record (GnomePilotConduitSyncAbs *conduit,
 
 	LOG (g_message ( "add_record: adding %s to desktop\n", print_remote (remote) ));
 
-	comp = comp_from_remote_record (conduit, remote, ctxt->default_comp, ctxt->timezone, &(ctxt->ai));
+	comp = comp_from_remote_record (conduit, remote, ctxt->default_comp, ctxt->timezone, &(ctxt->ai), ctxt->pilot_charset);
 
 	/* Give it a new UID otherwise it will be the uid of the default comp */
 	uid = e_cal_component_gen_uid ();
@@ -1204,7 +1215,7 @@ replace_record (GnomePilotConduitSyncAbs *conduit,
 	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->timezone, &(ctxt->ai));
+	new_comp = comp_from_remote_record (conduit, remote, local->comp, ctxt->timezone, &(ctxt->ai), ctxt->pilot_charset);
 	g_object_unref (local->comp);
 	local->comp = new_comp;
 
diff --git a/calendar/conduits/todo/todo-conduit.c b/calendar/conduits/todo/todo-conduit.c
index fd1e906..3620582 100644
--- a/calendar/conduits/todo/todo-conduit.c
+++ b/calendar/conduits/todo/todo-conduit.c
@@ -286,6 +286,7 @@ struct _EToDoConduitContext {
 	GList *locals;
 
 	EPilotMap *map;
+	gchar *pilot_charset;
 };
 
 static EToDoConduitContext *
@@ -305,6 +306,7 @@ e_todo_context_new (guint32 pilot_id)
 	ctxt->changed = NULL;
 	ctxt->locals = NULL;
 	ctxt->map = NULL;
+	ctxt->pilot_charset = NULL;
 
 	return ctxt;
 }
@@ -391,7 +393,7 @@ print_local (EToDoLocalRecord *local)
 	return buff;
 }
 
-static gchar *print_remote (GnomePilotRecord *remote)
+static gchar *print_remote (GnomePilotRecord *remote, const gchar *pilot_charset)
 {
 	static gchar buff[ 4096 ];
 	struct ToDo todo;
@@ -425,9 +427,9 @@ static gchar *print_remote (GnomePilotRecord *remote)
 		    todo.priority,
 		    todo.complete,
 		    todo.description ?
-		    e_pilot_utf8_from_pchar(todo.description) : "",
+		    e_pilot_utf8_from_pchar(todo.description, pilot_charset) : "",
 		    todo.note ?
-		    e_pilot_utf8_from_pchar(todo.note) : "",
+		    e_pilot_utf8_from_pchar(todo.note, pilot_charset) : "",
 		    remote->category);
 
 	free_ToDo (&todo);
@@ -707,19 +709,19 @@ local_record_from_comp (EToDoLocalRecord *local, ECalComponent *comp, EToDoCondu
 	}
 
 	/*Category support*/
-	e_pilot_local_category_to_remote(&(local->local.category), comp, &(ctxt->ai.category));
+	e_pilot_local_category_to_remote(&(local->local.category), comp, &(ctxt->ai.category), ctxt->pilot_charset);
 
 	/* STOP: don't replace these with g_strdup, since free_ToDo
 	   uses free to deallocate */
 	e_cal_component_get_summary (comp, &summary);
 	if (summary.value)
-		local->todo->description = e_pilot_utf8_to_pchar (summary.value);
+		local->todo->description = e_pilot_utf8_to_pchar (summary.value, ctxt->pilot_charset);
 
 	e_cal_component_get_description_list (comp, &d_list);
 	if (d_list) {
 		description = (ECalComponentText *) d_list->data;
 		if (description && description->value)
-			local->todo->note = e_pilot_utf8_to_pchar (description->value);
+			local->todo->note = e_pilot_utf8_to_pchar (description->value, ctxt->pilot_charset);
 		else
 			local->todo->note = NULL;
 	} else {
@@ -814,7 +816,8 @@ comp_from_remote_record (GnomePilotConduitSyncAbs *conduit,
 			 GnomePilotRecord *remote,
 			 ECalComponent *in_comp,
 			 icaltimezone *timezone,
-			 struct ToDoAppInfo *ai)
+			 struct ToDoAppInfo *ai,
+			 const gchar *pilot_charset)
 {
 	ECalComponent *comp;
 	struct ToDo todo;
@@ -861,12 +864,12 @@ comp_from_remote_record (GnomePilotConduitSyncAbs *conduit,
 
 	e_cal_component_set_last_modified (comp, &now);
 
-	summary.value = txt = e_pilot_utf8_from_pchar (todo.description);
+	summary.value = txt = e_pilot_utf8_from_pchar (todo.description, pilot_charset);
 	e_cal_component_set_summary (comp, &summary);
 	free (txt);
 
 	/*Category support*/
-	e_pilot_remote_category_to_local(remote->category, comp, &(ai->category));
+	e_pilot_remote_category_to_local(remote->category, comp, &(ai->category), pilot_charset);
 
 	/* The iCal description field */
 	if (!todo.note) {
@@ -875,7 +878,7 @@ comp_from_remote_record (GnomePilotConduitSyncAbs *conduit,
 		GSList l;
 		ECalComponentText text;
 
-		text.value = txt = e_pilot_utf8_from_pchar (todo.note);
+		text.value = txt = e_pilot_utf8_from_pchar (todo.note, pilot_charset);
 		text.altrep = NULL;
 		l.data = &text;
 		l.next = NULL;
@@ -1002,6 +1005,13 @@ pre_sync (GnomePilotConduit *conduit,
 	ctxt->dbi = dbi;
 	ctxt->client = NULL;
 
+#ifdef PILOT_LINK_0_12
+	if(NULL == dbi->pilotInfo->pilot_charset)
+		ctxt->pilot_charset = NULL;
+	else
+		ctxt->pilot_charset = g_strdup(dbi->pilotInfo->pilot_charset);
+#endif
+
 	/* Get the timezone */
 	ctxt->timezone = get_default_timezone ();
 	if (ctxt->timezone == NULL)
@@ -1162,7 +1172,8 @@ post_sync (GnomePilotConduit *conduit,
 	if (e_cal_get_changes (ctxt->client, change_id, &changed, NULL))
 		e_cal_free_change_list (changed);
 	g_free (change_id);
-
+	if (ctxt->pilot_charset)
+		g_free (ctxt->pilot_charset);	
 	LOG (g_message ( "---------------------------------------------------------\n" ));
 
 	return 0;
@@ -1329,7 +1340,7 @@ compare (GnomePilotConduitSyncAbs *conduit,
 	gint retval = 0;
 
 	LOG (g_message ("compare: local=%s remote=%s...\n",
-			print_local (local), print_remote (remote)));
+			print_local (local), print_remote (remote, ctxt->pilot_charset)));
 
 	g_return_val_if_fail (local!=NULL,-1);
 	g_return_val_if_fail (remote!=NULL,-1);
@@ -1359,9 +1370,9 @@ add_record (GnomePilotConduitSyncAbs *conduit,
 
 	g_return_val_if_fail (remote != NULL, -1);
 
-	LOG (g_message ( "add_record: adding %s to desktop\n", print_remote (remote) ));
+	LOG (g_message ( "add_record: adding %s to desktop\n", print_remote (remote, ctxt->pilot_charset) ));
 
-	comp = comp_from_remote_record (conduit, remote, ctxt->default_comp, ctxt->timezone, &(ctxt->ai));
+	comp = comp_from_remote_record (conduit, remote, ctxt->default_comp, ctxt->timezone, &(ctxt->ai), ctxt->pilot_charset);
 
 	/* Give it a new UID otherwise it will be the uid of the default comp */
 	uid = e_cal_component_gen_uid ();
@@ -1390,9 +1401,9 @@ replace_record (GnomePilotConduitSyncAbs *conduit,
 	g_return_val_if_fail (remote != NULL, -1);
 
 	LOG (g_message ("replace_record: replace %s with %s\n",
-			print_local (local), print_remote (remote)));
+			print_local (local), print_remote (remote, ctxt->pilot_charset)));
 
-	new_comp = comp_from_remote_record (conduit, remote, local->comp, ctxt->timezone, &(ctxt->ai));
+	new_comp = comp_from_remote_record (conduit, remote, local->comp, ctxt->timezone, &(ctxt->ai), ctxt->pilot_charset);
 	g_object_unref (local->comp);
 	local->comp = new_comp;
 
@@ -1452,7 +1463,7 @@ match (GnomePilotConduitSyncAbs *conduit,
 	const gchar *uid;
 
 	LOG (g_message ("match: looking for local copy of %s\n",
-			print_remote (remote)));
+			print_remote (remote, ctxt->pilot_charset)));
 
 	g_return_val_if_fail (local != NULL, -1);
 	g_return_val_if_fail (remote != NULL, -1);
diff --git a/e-util/e-pilot-util.c b/e-util/e-pilot-util.c
index 94c86a1..3ce67c8 100644
--- a/e-util/e-pilot-util.c
+++ b/e-util/e-pilot-util.c
@@ -31,7 +31,7 @@
 #include "e-pilot-util.h"
 
 gchar *
-e_pilot_utf8_to_pchar (const gchar *string)
+e_pilot_utf8_to_pchar (const gchar *string, const gchar *pilot_charset)
 {
 	gchar *pstring = NULL;
 	gint res;
@@ -39,7 +39,12 @@ e_pilot_utf8_to_pchar (const gchar *string)
 	if (!string)
 		return NULL;
 
-	res = convert_ToPilotChar ("UTF-8", string, strlen (string), &pstring);
+#ifdef PILOT_LINK_0_12
+    res = convert_ToPilotChar_WithCharset ("UTF-8", string, strlen (string), 
+          &pstring, pilot_charset);
+#else
+    res = convert_ToPilotChar ("UTF-8", string, strlen (string), &pstring);
+#endif
 
 	if (res != 0)
 		pstring = strdup (string);
@@ -48,7 +53,7 @@ e_pilot_utf8_to_pchar (const gchar *string)
 }
 
 gchar *
-e_pilot_utf8_from_pchar (const gchar *string)
+e_pilot_utf8_from_pchar (const gchar *string, const gchar *pilot_charset)
 {
 	gchar *ustring = NULL;
 	gint res;
@@ -56,7 +61,12 @@ e_pilot_utf8_from_pchar (const gchar *string)
 	if (!string)
 		return NULL;
 
-	res = convert_FromPilotChar ("UTF-8", string, strlen (string), &ustring);
+#ifdef PILOT_LINK_0_12
+    res = convert_FromPilotChar_WithCharset ("UTF-8", string, strlen (string), 
+          &ustring, pilot_charset);
+#else
+    res = convert_FromPilotChar ("UTF-8", string, strlen (string), &ustring);
+#endif
 
 	if (res != 0)
 		ustring = strdup (string);
diff --git a/e-util/e-pilot-util.h b/e-util/e-pilot-util.h
index 6b9b0ad..9def45a 100644
--- a/e-util/e-pilot-util.h
+++ b/e-util/e-pilot-util.h
@@ -29,8 +29,8 @@
 #ifndef E_PILOT_UTIL_H
 #define E_PILOT_UTIL_H
 
-gchar *e_pilot_utf8_to_pchar (const gchar *string);
-gchar *e_pilot_utf8_from_pchar (const gchar *string);
+gchar *e_pilot_utf8_to_pchar (const gchar *string, const gchar *pilot_charset);
+gchar *e_pilot_utf8_from_pchar (const gchar *string, const gchar *pilot_charset);
 
 ESource *e_pilot_get_sync_source (ESourceList *source_list);
 void e_pilot_set_sync_source (ESourceList *source_list, ESource *source);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]