2012-07-03 [mir] 0.6.0cvs87
authorMichael Rasmussen <mir@datanom.net>
Tue, 3 Jul 2012 00:15:15 +0000 (00:15 +0000)
committerMichael Rasmussen <mir@datanom.net>
Tue, 3 Jul 2012 00:15:15 +0000 (00:15 +0000)
* 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.

ChangeLog
PATCHSETS
configure.ac
libversit/vcard-utils.c

index d0710c284536cc626991a02069868d31cdfcfe05..b05b049d13460f2e859fe673ed9621c57f8e0775 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+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.
+
 2012-07-03 [mir]       0.6.0cvs86
 
        * libversit/vobject.c
index de90376ff8ad2806b5acdc316fe8444ee07f33eb..7fecca3addc5333d8495e29f3b7d2acc1af2f97a 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
@@ -84,3 +84,4 @@
 ( cvs diff -u -r 1.11 -r 1.12 plugins/xml/xml-plugin.c;  ) > 0.6.0cvs84.patchset
 ( cvs diff -u -r 1.15 -r 1.16 src/contactwindow.c;  cvs diff -u -r 1.9 -r 1.10 src/mainwindow.c;  ) > 0.6.0cvs85.patchset
 ( cvs diff -u -r 1.1 -r 1.2 libversit/vobject.c;  ) > 0.6.0cvs86.patchset
+( cvs diff -u -r 1.2 -r 1.3 libversit/vcard-utils.c;  ) > 0.6.0cvs87.patchset
index 8551898327ebdd0e6033e8b601e1732be06994ca..64723df06d1130f0ac2834ccedeb018603e34444 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=6
 MICRO_VERSION=0
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=86
+EXTRA_VERSION=87
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 89981f610f0a8f66f1dcde9b934b0b33358307c6..0cdd893eddaa69cbf2db3eff7189891894bea346 100644 (file)
@@ -154,7 +154,7 @@ static long data_size(VObject* o) {
        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 @@ static gchar* vcard2native(VObject* v, gchar* version, const gchar* plugin_type)
                        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 @@ Contact* vcard2contact(VObject* vcard, Plugin* plugin, gchar** error) {
        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 @@ static void set_prop(VObject* o, Plugin* p, AttribType type, gchar* key, void* v
        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 hash_iter(gpointer k, gpointer v, gpointer u) {
 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 @@ GSList* contacts2vcard(GList* contacts, Plugin* plugin, gchar** error) {
                        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 @@ static void save_vcard(struct DData* d_data) {
                                }
                                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;