Commit c4e000b7 authored by Adrian Georgescu's avatar Adrian Georgescu

Fixed storing and displaying Google contacts

parent ebb07c8e
...@@ -528,7 +528,7 @@ class GoogleContactURI(object): ...@@ -528,7 +528,7 @@ class GoogleContactURI(object):
id = property(lambda self: self.uri) id = property(lambda self: self.uri)
def __init__(self, uri, type, default=False): def __init__(self, uri, type, default=False):
self.uri = uri self.uri = uri.strip() if uri is not None else uri
self.type = type self.type = type
self.default = default self.default = default
...@@ -541,11 +541,11 @@ class GoogleContactURI(object): ...@@ -541,11 +541,11 @@ class GoogleContactURI(object):
@classmethod @classmethod
def from_im(cls, address): def from_im(cls, address):
return cls(re.sub('^sips?:', '', address['username']), address.get('formattedType', 'Other'), False) # for now do not let IM addresses become default URIs -Dan return cls(re.sub('^sips?:', '', address['username']), address.get('formattedType', 'Other'), address['metadata'].get('primary', False))
@classmethod @classmethod
def from_email(cls, address): def from_email(cls, address):
return cls(re.sub('^sips?:', '', address['value']), address.get('formattedType', 'Other'), False) # for now do not let email addresses become default URIs -Dan return cls(re.sub('^sips?:', '', address['value']), address.get('formattedType', 'Other'), address['metadata'].get('primary', False))
class GoogleContactURIList(object): class GoogleContactURIList(object):
...@@ -616,6 +616,9 @@ class GoogleContact(object): ...@@ -616,6 +616,9 @@ class GoogleContact(object):
organization = next((entry.get('name') for entry in contact_data.get('organizations', Null)), None) organization = next((entry.get('name') for entry in contact_data.get('organizations', Null)), None)
icon_url, icon_metadata = next(((entry['url'], entry['metadata']) for entry in contact_data.get('photos', Null)), (None, None)) icon_url, icon_metadata = next(((entry['url'], entry['metadata']) for entry in contact_data.get('photos', Null)), (None, None))
name = name.strip() if name is not None else 'Unknown'
organization = organization.strip() if organization is not None else organization
uris = [GoogleContactURI.from_number(number) for number in contact_data.get('phoneNumbers', Null)] uris = [GoogleContactURI.from_number(number) for number in contact_data.get('phoneNumbers', Null)]
uris.extend(GoogleContactURI.from_im(address) for address in contact_data.get('imClients', Null)) uris.extend(GoogleContactURI.from_im(address) for address in contact_data.get('imClients', Null))
uris.extend(GoogleContactURI.from_email(address) for address in contact_data.get('emailAddresses', Null)) uris.extend(GoogleContactURI.from_email(address) for address in contact_data.get('emailAddresses', Null))
...@@ -637,6 +640,9 @@ class GoogleContact(object): ...@@ -637,6 +640,9 @@ class GoogleContact(object):
organization = next((entry.get('name') for entry in contact_data.get('organizations', Null)), None) organization = next((entry.get('name') for entry in contact_data.get('organizations', Null)), None)
icon_url, icon_metadata = next(((entry['url'], entry['metadata']) for entry in contact_data.get('photos', Null)), (None, None)) icon_url, icon_metadata = next(((entry['url'], entry['metadata']) for entry in contact_data.get('photos', Null)), (None, None))
name = name.strip() if name is not None else 'Unknown'
organization = organization.strip() if organization is not None else organization
uris = [GoogleContactURI.from_number(number) for number in contact_data.get('phoneNumbers', Null)] uris = [GoogleContactURI.from_number(number) for number in contact_data.get('phoneNumbers', Null)]
uris.extend(GoogleContactURI.from_im(address) for address in contact_data.get('imClients', Null)) uris.extend(GoogleContactURI.from_im(address) for address in contact_data.get('imClients', Null))
uris.extend(GoogleContactURI.from_email(address) for address in contact_data.get('emailAddresses', Null)) uris.extend(GoogleContactURI.from_email(address) for address in contact_data.get('emailAddresses', Null))
......
...@@ -134,6 +134,7 @@ class IconManager(object, metaclass=Singleton): ...@@ -134,6 +134,7 @@ class IconManager(object, metaclass=Singleton):
pixmap.save(buffer, 'png') pixmap.save(buffer, 'png')
data = str(buffer.data()) data = str(buffer.data())
with open(filename, 'wb') as f: with open(filename, 'wb') as f:
data = data if isinstance(data, bytes) else data.encode()
f.write(data) f.write(data)
icon = QIcon(pixmap) icon = QIcon(pixmap)
icon.filename = filename icon.filename = filename
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment