class ContactHandle(TheOneRingHandle):
- _DELIMETER = "|"
+ def __init__(self, connection, id, phoneNumber):
+ self._phoneNumber = util_misc.normalize_number(phoneNumber)
- def __init__(self, connection, id, contactId, phoneNumber):
handleType = telepathy.HANDLE_TYPE_CONTACT
- handleName = self.to_handle_name(contactId, phoneNumber)
+ handleName = self._phoneNumber
TheOneRingHandle.__init__(self, connection, id, handleType, handleName)
- self._contactId = contactId
- self._phoneNumber = util_misc.normalize_number(phoneNumber)
-
- @classmethod
- def from_handle_name(cls, handleName):
- """
- >>> ContactHandle.from_handle_name("+1 555 123-1234")
- ('', '+15551231234')
- >>> ContactHandle.from_handle_name("+15551231234")
- ('', '+15551231234')
- >>> ContactHandle.from_handle_name("123456|+15551231234")
- ('123456', '+15551231234')
- """
- parts = handleName.split(cls._DELIMETER, 1)
- if len(parts) == 2:
- contactId, contactNumber = parts[0:2]
- elif len(parts) == 1:
- contactId, contactNumber = "", handleName
- else:
- raise RuntimeError("Invalid handle: %s" % handleName)
-
- contactNumber = util_misc.normalize_number(contactNumber)
- return contactId, contactNumber
-
- @classmethod
- def to_handle_name(cls, contactId, contactNumber):
- """
- >>> ContactHandle.to_handle_name('', "+1 555 123-1234")
- '+15551231234'
- >>> ContactHandle.to_handle_name('', "+15551231234")
- '+15551231234'
- >>> ContactHandle.to_handle_name('123456', "+15551231234")
- '123456|+15551231234'
- """
- contactNumber = util_misc.normalize_number(contactNumber)
- if contactId:
- handleName = cls._DELIMETER.join((contactId, contactNumber))
- else:
- handleName = contactNumber
- return handleName
-
- @property
- def contactID(self):
- return self._contactId
-
@property
def phoneNumber(self):
return self._phoneNumber
@property
+ def contact_name(self):
+ return self._conn.session.addressbook.get_contact_name(self.phoneNumber)
+
+ @property
def contactDetails(self):
- return self._conn.addressbook.get_contact_details(self._id)
+ return self._conn.session.addressbook.get_phone_type(self.phoneNumber)
class ListHandle(TheOneRingHandle):