[Commits] vcard-utils.c 1.2 1.3

miras at claws-mail.org miras at claws-mail.org
Tue Jul 3 02:15:17 CEST 2012


Update of /home/claws-mail/contacts/libversit
In directory srv:/tmp/cvs-serv18961/libversit

Modified Files:
	vcard-utils.c 
Log Message:
2012-07-03 [mir]	0.6.0cvs87

	* libversit/vcard-utils.c
	    - Fix bug. Do not use properties 'G' and 'F'
	    since they are not defined in the vCard 2.1
	    specification. Use 'N' instead.
	    - Added details 'WORK,HOME,INTERNET' to email property.
	    Details are taken from email alias -> work, home and
	    everything else is labeled 'INTERNET'.
	    - Fix some compile time warnings.

Index: vcard-utils.c
===================================================================
RCS file: /home/claws-mail/contacts/libversit/vcard-utils.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- vcard-utils.c	25 Mar 2012 22:55:13 -0000	1.2
+++ vcard-utils.c	3 Jul 2012 00:15:15 -0000	1.3
@@ -154,7 +154,7 @@
 	initPropIterator(&iter,o);
 	while (moreIteration(&iter)) {
 		prop = nextVObject(&iter);
-		gchar* name = vObjectName(prop);
+		const gchar* name = vObjectName(prop);
 		if (name && strcmp(name, VCDataSizeProp) == 0)
 			return vObjectLongValue(prop);
 	}
@@ -237,7 +237,7 @@
 			initPropIterator(&iter,v);
     		while (moreIteration(&iter) && !attr) {
 				VObject *prop = nextVObject(&iter);
-				gchar* value = vObjectName(prop);
+				const gchar* value = vObjectName(prop);
 				if (value) {
 					if (g_str_has_prefix(plugin_type, "LDAP")) {
 						if (g_strstr_len(value, strlen(value), "CELL"))
@@ -439,16 +439,37 @@
 	return contact;
 }
 
-static void set_prop(VObject* o, Plugin* p, AttribType type, gchar* key, void* value) {
+static void create_VObject(VObject* o, gchar* propname, AttribType type, void* value) {
 	VObject* prop;
+
+	prop = newVObject(propname);
+	addVObjectProp(o, prop);
+	switch (type) {
+		case ATTRIB_TYPE_BOOLEAN:
+		case ATTRIB_TYPE_INT: {
+			int i = *(gint *) value;
+			setVObjectIntegerValue(prop, i);
+		}
+		case ATTRIB_TYPE_CHAR: {
+			char c = *(char *) value;
+			setVObjectStringZValue(prop, &c);
+		}
+		case ATTRIB_TYPE_STRING: {
+			gchar* s = (gchar *) value;
+			setVObjectStringZValue(prop, s);
+		}
+	}
+}
+
+static void set_prop(VObject* o, Plugin* p, AttribType type, gchar* key, void* value) {
 	gchar* name = NULL;
 
 	if (strcasecmp("cn", key) == 0)
 		name = g_strdup(VCFullNameProp);
 	else if (strcasecmp("first-name", key) == 0)
-		name = g_strdup(VCGivenNameProp);
+		return;
 	else if (strcasecmp("last-name", key) == 0)
-		name = g_strdup(VCFamilyNameProp);
+		return;
 	else if (strcasecmp("nick-name", key) == 0)
 		name = g_strdup("NICKNAME");
 	else if (strcasecmp("image", key) == 0) {
@@ -467,24 +488,33 @@
 	if (! name)
 		return;
 	
-	prop = newVObject(name);
+	create_VObject(o, name, type, value);
 	g_free(name);
-	addVObjectProp(o, prop);
-	switch (type) {
-		case ATTRIB_TYPE_BOOLEAN:
-		case ATTRIB_TYPE_INT: {
-			int i = *(gint *) value;
-			setVObjectIntegerValue(prop, i);
-		}
-		case ATTRIB_TYPE_CHAR: {
-			char c = *(char *) value;
-			setVObjectStringZValue(prop, &c);
-		}
-		case ATTRIB_TYPE_STRING: {
-			gchar* s = (gchar *) value;
-			setVObjectStringZValue(prop, s);
-		}
+}
+
+static gchar* get_name(GHashTable* data) {
+	gchar *name, *firstname, *lastname;
+	
+	extract_data(data, "first-name", (void **) &firstname);
+	extract_data(data, "last-name", (void **) &lastname);
+
+	if (firstname && lastname) {
+		name = g_strconcat(lastname, ";", firstname, ";;;", NULL);
+		g_free(firstname);
+		g_free(lastname);
+	}
+	else if (firstname) {
+		name = g_strconcat(";", firstname, ";;;", NULL);
+		g_free(firstname);
+	}
+	else if (lastname) {
+		name = g_strconcat(lastname, ";;;;", NULL);
+		g_free(lastname);
 	}
+	else
+		name = NULL;
+	
+	return name;
 }
 
 static void hash_iter(gpointer k, gpointer v, gpointer u) {
@@ -501,14 +531,28 @@
 static void slist_iter(gpointer d, gpointer u) {
 	Email* e = (Email *) d;
 	VObject* o = (VObject *) u;
-
-	addPropValue(o, VCEmailAddressProp, e->email);			
+	gchar* attr;
+	
+	if (e->alias) {
+		if (strcasecmp(e->alias, "work") == 0)
+			attr = g_strconcat(VCEmailAddressProp, ";WORK", NULL);
+		else if (strcasecmp(e->alias, "home") == 0)
+			attr = g_strconcat(VCEmailAddressProp, ";HOME", NULL);
+		else
+			attr = g_strconcat(VCEmailAddressProp, ";INTERNET", NULL);
+	}
+	else
+		attr = g_strconcat(VCEmailAddressProp, ";INTERNET", NULL);
+		
+	addPropValue(o, attr, e->email);
+	g_free(attr);		
 }
 
 GSList* contacts2vcard(GList* contacts, Plugin* plugin, gchar** error) {
 	GSList* vcards = NULL;
 	GList* cur;
 	struct CBData cb_data;
+	gchar* name;
 
 	cm_return_val_if_fail(plugin != NULL, NULL);
 	cm_return_val_if_fail(contacts != NULL, NULL);
@@ -519,6 +563,11 @@
 			cb_data.o = newVObject(VCCardProp);
 			cb_data.p = plugin;
 			addPropValue(cb_data.o, VCVersionProp, "2.1");
+			name = get_name(c->data);
+			if (name) {
+				create_VObject(cb_data.o, VCNameProp, ATTRIB_TYPE_STRING, (void *) name);
+				g_free(name);
+			}
 			g_hash_table_foreach(c->data, hash_iter, &cb_data);
 			g_slist_foreach(c->emails, slist_iter, cb_data.o);
 			vcards = g_slist_prepend(vcards, cb_data.o);
@@ -1018,7 +1067,7 @@
 				}
 				break;
 			default:
-				buffer = hbox_get_entry_text(d_data->items[i]->widget);
+				buffer = (gchar *) hbox_get_entry_text(d_data->items[i]->widget);
 				if (buffer && strlen(buffer) > 0)
 					addPropValue(o, d_data->items[i]->prop, buffer);
 				break;



More information about the Commits mailing list