[evolution-patches] [Addressbook] Fix for #66368



When constructing a new contact, tries to generate a file_as field if
it's not present after vcard construction.

-- 
Hans Petter
? 66368.patch
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/addressbook/ChangeLog,v
retrieving revision 1.196.2.6
diff -u -p -r1.196.2.6 ChangeLog
--- ChangeLog	28 Sep 2004 21:10:10 -0000	1.196.2.6
+++ ChangeLog	29 Sep 2004 23:11:13 -0000
@@ -1,3 +1,10 @@
+2004-09-29  Hans Petter Jansson  <hpj ximian com>
+
+	Fixes bug #66368.
+
+	* libebook/e-contact.c (e_contact_new_from_vcard): If the constructed
+	vcard does not have a file_as attribute, try to generate one.
+
 2004-09-22  Diego Gonzalez <diego pemas net>
 
 	Fixes #66574.
Index: libebook/e-contact.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/addressbook/libebook/e-contact.c,v
retrieving revision 1.37
diff -u -p -r1.37 e-contact.c
--- libebook/e-contact.c	22 Jun 2004 01:27:53 -0000	1.37
+++ libebook/e-contact.c	29 Sep 2004 23:11:13 -0000
@@ -1278,11 +1278,48 @@ EContact*
 e_contact_new_from_vcard  (const char *vcard)
 {
 	EContact *contact;
+	const gchar *file_as;
 
 	g_return_val_if_fail (vcard != NULL, NULL);
 
 	contact = g_object_new (E_TYPE_CONTACT, NULL);
 	e_vcard_construct (E_VCARD (contact), vcard);
+
+	/* Generate a FILE_AS field if needed */
+
+	file_as = e_contact_get_const (contact, E_CONTACT_FILE_AS);
+	if (!file_as || !*file_as) {
+		EContactName *name;
+		const gchar *org;
+		gchar *file_as_new = NULL;
+		gchar *strings [4];
+		gchar **strings_p = strings;
+
+		name = e_contact_get (contact, E_CONTACT_NAME);
+		org = e_contact_get_const (contact, E_CONTACT_ORG);
+
+		if (name) {
+			if (name->family && *name->family)
+				*(strings_p++) = name->family;
+			if (name->given && *name->given)
+				*(strings_p++) = name->given;
+
+			if (strings_p != strings) {
+				*strings_p = NULL;
+				file_as_new = g_strjoinv (", ", strings);
+			}
+
+			e_contact_name_free (name);
+		}
+
+		if (!file_as_new && org && *org)
+			file_as_new = g_strdup (org);
+
+		if (file_as_new) {
+			e_contact_set (contact, E_CONTACT_FILE_AS, file_as_new);
+			g_free (file_as_new);
+		}
+	}
 
 	return contact;
 }


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