On Friday 02 July 2010 10:20:24 Jörgen Scheibengruber wrote:
> Which is exactly what e_contact_new_from_vcard, does. 

How does e_contact_new_from_vcard get told what charset the string is in?  Or 
does it require it to be in UTF-8?

> It's as easy as: 
>
> char *contents;
> if (g_file_get_contents ("file.vcf", &contents, NULL, NULL)) {
>       EContact *contact;
>       contact = e_contact_new_from_vcard (contents);
>       g_free (contents).
> }

It's not really that easy.  Character sets are one of the hardest problems 
when importing and exporting v-format data as files do not have metadata to 
tell you the charset.

I don't recommend using g_file_get_contents to read the file unless you are 
prepared to write code to handle the charset conversions.  I use 
g_io_channel_new_file and g_io_channel_set_encoding to read a file I want to 
import so I can control the charset.

In GPE, I employ a heuristic to guess the charset:

1. I try to read the file using UTF-8 and then try to import the data.
2. If that fails, I try again using the user's default charset (using 
g_get_charset).
3. If that fails, I try again using ISO-8859-15.
4. If that fails, I give up.

When exporting I always use UTF-8.  But I have discovered that most other 
programs do not.  ISO-8859-15 is quite common but you have to allow some way 
for the user to control what is used, which is why the second step is to use 
the user's default charset.

Graham
_______________________________________________
maemo-developers mailing list
maemo-developers@maemo.org
https://lists.maemo.org/mailman/listinfo/maemo-developers

Reply via email to