Patch for Google contacts and evolution



Hello,

I just downloaded the latest Conduit and tried to sync my gmail contacts
to evolution. My evolution contacts were created with an empty "File As"
parameters (due to a missing N vcard param). I patched my conduit to try
to fill this field anyway.

Additionally, I wanted to sync the IM/Phones entries from google to
evolution. Here is a small patch to add these fields to the vcard.

Note: As this is my first patch to conduit, I kept it small, do not
hesitate to comment.

Benoit

Index: conduit/datatypes/Contact.py
===================================================================
--- conduit/datatypes/Contact.py	(révision 1657)
+++ conduit/datatypes/Contact.py	(copie de travail)
@@ -66,6 +66,16 @@
             self.vcard.add('n')
         if f or g:
             self.vcard.n.value = vobject.vcard.Name(family=f,given=g)
+        elif fn:
+            splitted = fn.split(None, 2)
+            if len(splitted) == 1:
+                (given,extra,family) = ("", "", splitted[0])
+            elif len(splitted) == 2:
+                (given,extra,family) = (splitted[0], "", splitted[1])
+            else:
+                (given,extra,family) = splitted
+            self.vcard.n.value = vobject.vcard.Name(family=family,given=given, additional=extra)
+
 
     def set_emails(self, *args):
         for address in args:
Index: conduit/datatypes/Contact.py
===================================================================
--- conduit/datatypes/Contact.py	(révision 1657)
+++ conduit/datatypes/Contact.py	(copie de travail)
@@ -67,6 +67,17 @@
         if f or g:
             self.vcard.n.value = vobject.vcard.Name(family=f,given=g)
 
+    def set_im(self, *args):
+        for (protocol, address) in args:
+            im = self.vcard.add(protocol)
+	    im.value = address
+
+    def set_phones(self, *args):
+        for (phone, rel) in args:
+            p = self.vcard.add('tel')
+            p.value = phone
+            p.type_param = rel
+
     def set_emails(self, *args):
         for address in args:
             email = self.vcard.add('email')
Index: conduit/modules/GoogleModule/GoogleModule.py
===================================================================
--- conduit/modules/GoogleModule/GoogleModule.py	(révision 1657)
+++ conduit/modules/GoogleModule/GoogleModule.py	(copie de travail)
@@ -856,6 +856,30 @@
         
         emails = [str(e.address) for e in gc.email]
         c.set_emails(*emails)
+
+        # Instant messages (address and protocol)
+        vcard_ims = {gdata.contacts.IM_YAHOO: "X-YAHOO",
+                     gdata.contacts.IM_MSN: "X-MSN",
+                     gdata.contacts.IM_SKYPE: "X-SKYPE",
+                     gdata.contacts.IM_GOOGLE_TALK: "X-GTALK",
+                     gdata.contacts.IM_ICQ: "X-ICQ",
+                     gdata.contacts.IM_JABBER: "X-JABBER"}
+        ims = []
+        for e in gc.im:
+            if e.protocol in vcard_ims:
+               ims.append([vcard_ims[e.protocol], e.address, ])
+        c.set_im(*ims)
+ 
+        # Phones (Phone and type (Work/Home/Other))
+        vcard_rels = {gdata.contacts.REL_HOME:  "HOME",
+    	              gdata.contacts.REL_WORK:  "WORK",
+                      gdata.contacts.REL_OTHER: "OTHER"}
+        phones = []
+        for e in gc.phone_number:
+            if e.rel in vcard_rels:
+               phones.append([e.text, vcard_rels[e.rel], ])
+        c.set_phones(*phones)
+
         
         #ee_names = map(operator.attrgetter('tag'),gc.extension_elements)
         #if len(gc.extension_elements) >0:


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