Re: [evolution-patches] Patch for 43790 [Contacts : LDIF Importer improvement]



On Wed, 2003-05-28 at 01:35, Sean Gao wrote:
> Hi  Toshok,
>     I just met some problem with ldif importer and draw up this patch, 
> please help to have a look.
>  
> Cheers
> -Sean
> 
> ______________________________________________________________________
> Index: addressbook/backend/ebook/evolution-ldif-importer.c
> ===================================================================
> RCS file: /cvs/gnome/evolution/addressbook/backend/ebook/evolution-ldif-importer.c,v
> retrieving revision 1.12
> diff -u -r1.12 evolution-ldif-importer.c
> --- addressbook/backend/ebook/evolution-ldif-importer.c	2 Apr 2003 16:34:32 -0000	1.12
> +++ addressbook/backend/ebook/evolution-ldif-importer.c	28 May 2003 08:14:49 -0000
> @@ -45,33 +45,55 @@
>  static struct {
>  	char *ldif_attribute;
>  	ECardSimpleField simple_field;
> -#define FLAG_ADDRESS 0x01
> +#define FLAG_ADDRESS_WORK 0x01
> +#define FLAG_ADDRESS_HOME 0x02
>  	int flags;
>  }
>  ldif_fields[] = {
>  	{ "cn", E_CARD_SIMPLE_FIELD_FULL_NAME },
>  	{ "mail", E_CARD_SIMPLE_FIELD_EMAIL },
> +	{ "mozillasecondemail", E_CARD_SIMPLE_FIELD_EMAIL_2 },
>  #if 0
>  	{ "givenname", E_CARD_SIMPLE_FIELD_GIVEN_NAME },
>  #endif

don't include #if 0'd regions in patches, please.  why is this #if 0'ed
anyway?  i don't see it handled anywhere else.  should leave it in.

>  	{ "sn", E_CARD_SIMPLE_FIELD_FAMILY_NAME },
>  	{ "xmozillanickname", E_CARD_SIMPLE_FIELD_NICKNAME },
>  	{ "o", E_CARD_SIMPLE_FIELD_ORG },
> +	{ "homepostaladdress", 0, FLAG_ADDRESS_HOME },
> +	{ "mozillahomepostaladdress2", 0, FLAG_ADDRESS_HOME },
> +	{ "mozillahomelocalityname", 0, FLAG_ADDRESS_HOME },
> +	{ "mozillahomestate", 0, FLAG_ADDRESS_HOME },
> +	{ "mozillahomepostalcode", 0, FLAG_ADDRESS_HOME },
> +	{ "mozillahomecountryname", 0, FLAG_ADDRESS_HOME },
> +	{ "postaladdress", 0, FLAG_ADDRESS_WORK },
> +	{ "mozillapostaladdress2", 0, FLAG_ADDRESS_WORK },
> +#if 0
>  	{ "locality", 0, FLAG_ADDRESS},
> -	{ "st", 0, FLAG_ADDRESS },
> +#endif

just remove this if you're going to replace it with the stuff below. 
actually, strike that.  put the locality line back in.  It's used in the
code below, it needs to be in this array.

> +	{ "l", 0, FLAG_ADDRESS_WORK},
> +	{ "st", 0, FLAG_ADDRESS_WORK },
> +#if 0
>  	{ "streetaddress", 0, FLAG_ADDRESS },
> +#endif 

should leave the "streetaddress" in and make it FLAG_ADDRESS_WORK.

>  	{ "title", E_CARD_SIMPLE_FIELD_TITLE },
> -	{ "postalcode", 0, FLAG_ADDRESS },
> +	{ "postalcode", 0, FLAG_ADDRESS_WORK },
> +#if 0
>  	{ "countryname", 0, FLAG_ADDRESS },
> +#endif

same here.

> +	{ "c", 0, FLAG_ADDRESS_WORK },
>  	{ "telephonenumber", E_CARD_SIMPLE_FIELD_PHONE_BUSINESS},
>  	{ "homephone", E_CARD_SIMPLE_FIELD_PHONE_HOME },
>  	{ "facsimiletelephonenumber", E_CARD_SIMPLE_FIELD_PHONE_BUSINESS_FAX },
>  	{ "ou", E_CARD_SIMPLE_FIELD_ORG_UNIT },
> +#if 0
>  	{ "pagerphone", E_CARD_SIMPLE_FIELD_PHONE_PAGER },
>  	{ "cellphone", E_CARD_SIMPLE_FIELD_PHONE_MOBILE },
> +#endif

these should stay in too.

> +	{ "pager", E_CARD_SIMPLE_FIELD_PHONE_PAGER },
> +	{ "mobile", E_CARD_SIMPLE_FIELD_PHONE_MOBILE },
>  	{ "homeurl", E_CARD_SIMPLE_FIELD_URL },
>  	{ "description", E_CARD_SIMPLE_FIELD_NOTE },
> -	{ "xmozillausehtmlmail", E_CARD_SIMPLE_FIELD_WANTS_HTML }
> +	{ "xmozillausehtmlmail", E_CARD_SIMPLE_FIELD_WANTS_HTML },
>  };

> +					else if (!g_ascii_strcasecmp (ptr, "locality"))
> +						address_work->city = g_strdup (ldif_value->str);
> +					else if (!g_ascii_strcasecmp (ptr, "l"))
> +						address_work->city = g_strdup (ldif_value->str);

i'd rather see:

... else if (!g_ascii_strcasecmp (ptr, "locality")
             || !g_ascii_strcasecmp (ptr, "l"))
      address_work->city = g_strdup (ldif_value->str);

>  					else if (!g_ascii_strcasecmp (ptr, "countryname"))
> -						address->country = g_strdup (ldif_value->str);
> +						address_work->country = g_strdup (ldif_value->str);
> +					else if (!g_ascii_strcasecmp (ptr, "c"))
> +						address_work->country = g_strdup (ldif_value->str);
>  					else if (!g_ascii_strcasecmp (ptr, "postalcode"))
> -						address->code = g_strdup (ldif_value->str);
> +						address_work->code = g_strdup (ldif_value->str);
>  					else if (!g_ascii_strcasecmp (ptr, "st"))
> -						address->region = g_strdup (ldif_value->str);
> +						address_work->region = g_strdup (ldif_value->str);
>  					else if (!g_ascii_strcasecmp (ptr, "streetaddress"))
> -						address->street = g_strdup (ldif_value->str);
> +						address_work->street = g_strdup (ldif_value->str);
> +				}
> +				else if (ldif_fields[i].flags & FLAG_ADDRESS_HOME) {
> +					if (!g_ascii_strcasecmp (ptr, "homepostaladdress"))
> +						address_home->po = g_strdup (ldif_value->str);
> +					else if (!g_ascii_strcasecmp (ptr, "mozillahomepostaladdress2"))
> +						address_home->ext = g_strdup (ldif_value->str);
> +					else if (!g_ascii_strcasecmp (ptr, "mozillahomelocalityname"))
> +						address_home->city = g_strdup (ldif_value->str);
> +					else if (!g_ascii_strcasecmp (ptr, "mozillahomestate"))
> +						address_home->region = g_strdup (ldif_value->str);
> +					else if (!g_ascii_strcasecmp (ptr, "mozillahomecountryname"))
> +						address_home->country = g_strdup (ldif_value->str);
> +					else if (!g_ascii_strcasecmp (ptr, "mozillahomepostalcode"))
> +						address_home->code = g_strdup (ldif_value->str);
>  				}
>  				else {
>  					e_card_simple_set (simple, ldif_fields[i].simple_field, ldif_value->str);
> @@ -299,7 +343,8 @@
>  	ECard *card;
>  	ECardAddrLabel *label;
>  	ECardSimple *simple;
> -	ECardDeliveryAddress *address;
> +	ECardDeliveryAddress *address_work;
> +	ECardDeliveryAddress *address_home;
>  	GString *str;
>  	char line[1024];
>  	char *buf;
> @@ -322,24 +367,39 @@
>  	/* now parse that entry */
>  	card = e_card_new ("");
>  	simple = e_card_simple_new (card);
> -	address = e_card_delivery_address_new ();
> +	address_work = e_card_delivery_address_new ();
> +	address_home = e_card_delivery_address_new ();
>  
>  	buf = str->str;
>  	while (buf) {
> -		if (!parseLine (simple, address, &buf)) {
> +		if (!parseLine (simple, address_work, address_home, &buf)) {
>  			/* parsing error */
>  			g_object_unref (simple);
> -			e_card_delivery_address_unref (address);
> +			e_card_delivery_address_unref (address_work);
> +			e_card_delivery_address_unref (address_home);
>  			return NULL;
>  		}
>  	}
>  
> 
>  	/* fill in the address */
> -	address->flags = E_CARD_ADDR_HOME;
> +	address_work->flags = E_CARD_ADDR_WORK;
> +
> +	label = e_card_delivery_address_to_label (address_work);
> +	e_card_delivery_address_unref (address_work);
> +
> +	e_card_simple_set_address (simple, E_CARD_SIMPLE_ADDRESS_ID_BUSINESS, label);
> +
> +	e_card_address_label_unref (label);
> +
> +/*	
> +	e_card_simple_sync_card (simple);
> + */

leave out the commented sync.

> +
> +	address_home->flags = E_CARD_ADDR_HOME;
>  
> -	label = e_card_delivery_address_to_label (address);
> -	e_card_delivery_address_unref (address);
> +	label = e_card_delivery_address_to_label (address_home);
> +	e_card_delivery_address_unref (address_home);
>  
>  	e_card_simple_set_address (simple, E_CARD_SIMPLE_ADDRESS_ID_HOME, label);

also with this last section you should be using
e_card_simple_set_delivery_address instead of e_card_simple_set_address,
since the former doesn't require unparsing the delivery address then
reparsing it (the parsing has problems).

Chris



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