X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=package%2Fsrc%2Fcontacts.py;h=38b46248c439843a52b9319457736797cd7ee618;hb=26e33a55215635ed21d81ac83b22b53397380486;hp=4963191a5f656e7168e6e5a1753de040bc6a22e2;hpb=565e60b454b2d6c8405f075dce10ad617869eaf1;p=hermes diff --git a/package/src/contacts.py b/package/src/contacts.py index 4963191..38b4624 100644 --- a/package/src/contacts.py +++ b/package/src/contacts.py @@ -5,6 +5,7 @@ import Image import ImageOps import StringIO import datetime +import re from pygobject import * from ctypes import * @@ -103,10 +104,21 @@ class ContactStore: # ----------------------------------------------------------------------- - def add_url(self, contact, url, unique = ''): + def add_url(self, contact, str, unique = ''): """Add a new URL to the set of URLs for the given contact.""" - unique = unique or url + urls = re.findall('(?:(?:ftp|https?):\/\/|\\bwww\.|\\bftp\.)[,\w\.\-\/@:%?&=%+#~_$\*]+[\w=\/&=+#]', str, re.I | re.S) + updated = False + for url in urls: + updated = self._add_url(contact, url, unique or url) or updated + + return updated + + + # ----------------------------------------------------------------------- + def _add_url(self, contact, url, unique): + """Do the work of adding a unique URL to a contact.""" + url_attr = None ai = GList.new(ebook.e_contact_get_attributes(hash(contact), E_CONTACT_HOMEPAGE_URL)) while ai.has_next(): @@ -117,13 +129,13 @@ class ContactStore: elif existing.find(unique) > -1: url_attr = attr break - + if not url_attr: ai.add() url_attr = EVCardAttribute() url_attr.group = '' url_attr.name = 'URL' - + val = GList() print "Setting URL for [%s] to [%s]" % (contact.get_name(), url) val.set(create_string_buffer(url))