Commit 15a6f098 authored by Dan Pascu's avatar Dan Pascu

Added type property to contacts

parent d82735fa
...@@ -995,11 +995,11 @@ class Contact(object): ...@@ -995,11 +995,11 @@ class Contact(object):
size_hint = QSize(200, 36) size_hint = QSize(200, 36)
native = property(lambda self: isinstance(self.settings, addressbook.Contact)) native = property(lambda self: self.type == 'addressbook')
movable = property(lambda self: isinstance(self.settings, addressbook.Contact)) movable = property(lambda self: self.type == 'addressbook')
editable = property(lambda self: isinstance(self.settings, addressbook.Contact)) editable = property(lambda self: self.type == 'addressbook')
deletable = property(lambda self: isinstance(self.settings, addressbook.Contact)) deletable = property(lambda self: self.type == 'addressbook')
default_user_icon = ContactIconDescriptor(Resources.get('icons/default-avatar.png')) default_user_icon = ContactIconDescriptor(Resources.get('icons/default-avatar.png'))
...@@ -1053,18 +1053,35 @@ class Contact(object): ...@@ -1053,18 +1053,35 @@ class Contact(object):
def __unicode__(self): def __unicode__(self):
return self.name or u'' return self.name or u''
@property
def type(self):
try:
return self.__dict__['type']
except KeyError:
if isinstance(self.settings, addressbook.Contact):
type = 'addressbook'
elif isinstance(self.settings, BonjourNeighbour):
type = 'bonjour'
elif isinstance(self.settings, GoogleContact):
type = 'google'
elif isinstance(self.settings, DummyContact):
type = 'dummy'
else:
type = 'unknown'
return self.__dict__.setdefault('type', type)
@property @property
def name(self): def name(self):
if isinstance(self.settings, BonjourNeighbour): if self.type == 'bonjour':
return '%s (%s)' % (self.settings.name, self.settings.hostname) return '%s (%s)' % (self.settings.name, self.settings.hostname)
elif isinstance(self.settings, GoogleContact): elif self.type == 'google':
return self.settings.name or self.settings.company or u'' return self.settings.name or self.settings.company or u''
else: else:
return self.settings.name return self.settings.name
@property @property
def location(self): def location(self):
if isinstance(self.settings, BonjourNeighbour): if self.type == 'bonjour':
return self.settings.hostname return self.settings.hostname
else: else:
return None return None
...@@ -1072,7 +1089,7 @@ class Contact(object): ...@@ -1072,7 +1089,7 @@ class Contact(object):
@property @property
def info(self): def info(self):
try: try:
return self.note or ('@' + self.uri.uri.host if isinstance(self.settings, BonjourNeighbour) else self.uri.uri) return self.note or ('@' + self.uri.uri.host if self.type == 'bonjour' else self.uri.uri)
except AttributeError: except AttributeError:
return u'' return u''
...@@ -1104,10 +1121,10 @@ class Contact(object): ...@@ -1104,10 +1121,10 @@ class Contact(object):
try: try:
return self.__dict__['icon'] return self.__dict__['icon']
except KeyError: except KeyError:
if isinstance(self.settings, addressbook.Contact): if self.type == 'addressbook':
icon_manager = IconManager() icon_manager = IconManager()
icon = icon_manager.get(self.settings.id + '_alt') or icon_manager.get(self.settings.id) or self.default_user_icon icon = icon_manager.get(self.settings.id + '_alt') or icon_manager.get(self.settings.id) or self.default_user_icon
elif isinstance(self.settings, GoogleContact): elif self.type == 'google':
pixmap = QPixmap() pixmap = QPixmap()
if pixmap.loadFromData(self.settings.icon.data): if pixmap.loadFromData(self.settings.icon.data):
icon = QIcon(pixmap) icon = QIcon(pixmap)
...@@ -1160,10 +1177,10 @@ class ContactDetail(object): ...@@ -1160,10 +1177,10 @@ class ContactDetail(object):
size_hint = QSize(200, 36) size_hint = QSize(200, 36)
native = property(lambda self: isinstance(self.settings, addressbook.Contact)) native = property(lambda self: self.type == 'addressbook')
editable = property(lambda self: isinstance(self.settings, addressbook.Contact)) editable = property(lambda self: self.type == 'addressbook')
deletable = property(lambda self: isinstance(self.settings, addressbook.Contact)) deletable = property(lambda self: self.type == 'addressbook')
default_user_icon = ContactIconDescriptor(Resources.get('icons/default-avatar.png')) default_user_icon = ContactIconDescriptor(Resources.get('icons/default-avatar.png'))
...@@ -1196,18 +1213,35 @@ class ContactDetail(object): ...@@ -1196,18 +1213,35 @@ class ContactDetail(object):
def __unicode__(self): def __unicode__(self):
return self.name or u'' return self.name or u''
@property
def type(self):
try:
return self.__dict__['type']
except KeyError:
if isinstance(self.settings, addressbook.Contact):
type = 'addressbook'
elif isinstance(self.settings, BonjourNeighbour):
type = 'bonjour'
elif isinstance(self.settings, GoogleContact):
type = 'google'
elif isinstance(self.settings, DummyContact):
type = 'dummy'
else:
type = 'unknown'
return self.__dict__.setdefault('type', type)
@property @property
def name(self): def name(self):
if isinstance(self.settings, BonjourNeighbour): if self.type == 'bonjour':
return '%s (%s)' % (self.settings.name, self.settings.hostname) return '%s (%s)' % (self.settings.name, self.settings.hostname)
elif isinstance(self.settings, GoogleContact): elif self.type == 'google':
return self.settings.name or self.settings.company return self.settings.name or self.settings.company
else: else:
return self.settings.name return self.settings.name
@property @property
def location(self): def location(self):
if isinstance(self.settings, BonjourNeighbour): if self.type == 'bonjour':
return self.settings.hostname return self.settings.hostname
else: else:
return None return None
...@@ -1215,7 +1249,7 @@ class ContactDetail(object): ...@@ -1215,7 +1249,7 @@ class ContactDetail(object):
@property @property
def info(self): def info(self):
try: try:
return self.note or ('@' + self.uri.uri.host if isinstance(self.settings, BonjourNeighbour) else self.uri.uri) return self.note or ('@' + self.uri.uri.host if self.type == 'bonjour' else self.uri.uri)
except AttributeError: except AttributeError:
return u'' return u''
...@@ -1247,10 +1281,10 @@ class ContactDetail(object): ...@@ -1247,10 +1281,10 @@ class ContactDetail(object):
try: try:
return self.__dict__['icon'] return self.__dict__['icon']
except KeyError: except KeyError:
if isinstance(self.settings, addressbook.Contact): if self.type == 'addressbook':
icon_manager = IconManager() icon_manager = IconManager()
icon = icon_manager.get(self.settings.id + '_alt') or icon_manager.get(self.settings.id) or self.default_user_icon icon = icon_manager.get(self.settings.id + '_alt') or icon_manager.get(self.settings.id) or self.default_user_icon
elif isinstance(self.settings, GoogleContact): elif self.type == 'google':
pixmap = QPixmap() pixmap = QPixmap()
if pixmap.loadFromData(self.settings.icon.data): if pixmap.loadFromData(self.settings.icon.data):
icon = QIcon(pixmap) icon = QIcon(pixmap)
......
...@@ -3165,10 +3165,8 @@ class SessionManager(object): ...@@ -3165,10 +3165,8 @@ class SessionManager(object):
notification_center.add_observer(self, name='BlinkSessionListSelectionChanged') notification_center.add_observer(self, name='BlinkSessionListSelectionChanged')
def create_session(self, contact, contact_uri, streams, account=None, connect=True, sibling=None): def create_session(self, contact, contact_uri, streams, account=None, connect=True, sibling=None):
from blink.contacts import BonjourNeighbour
if account is None: if account is None:
if isinstance(contact.settings, BonjourNeighbour): if contact.type == 'bonjour':
account = BonjourAccount() account = BonjourAccount()
else: else:
account = AccountManager().default_account account = AccountManager().default_account
......
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