X-Git-Url: http://git.maemo.org/git/?p=theonering;a=blobdiff_plain;f=src%2Fhandle.py;h=5fc4e98ef6e98131d3232f5d6d6286f270f84b13;hp=9c34ca51199bf733a871399bf8d7a44d53b5da7a;hb=acc26c76a8bdefc25f10450e9cff6d1604b02dd8;hpb=4856262e2c13dcb2d23de4774010800bd084bc7d diff --git a/src/handle.py b/src/handle.py index 9c34ca5..5fc4e98 100644 --- a/src/handle.py +++ b/src/handle.py @@ -3,19 +3,20 @@ import weakref import telepathy +import tp import util.misc as util_misc _moduleLogger = logging.getLogger("handle") -class TheOneRingHandle(telepathy.server.Handle): +class TheOneRingHandle(tp.Handle): """ Instances are memoized """ def __init__(self, connection, id, handleType, name): - telepathy.server.Handle.__init__(self, id, handleType, name) + tp.Handle.__init__(self, id, handleType, name) self._conn = weakref.proxy(connection) def __repr__(self): @@ -23,9 +24,9 @@ class TheOneRingHandle(telepathy.server.Handle): type(self).__name__, self.id, self.name ) - id = property(telepathy.server.Handle.get_id) - type = property(telepathy.server.Handle.get_type) - name = property(telepathy.server.Handle.get_name) + id = property(tp.Handle.get_id) + type = property(tp.Handle.get_type) + name = property(tp.Handle.get_name) class ConnectionHandle(TheOneRingHandle): @@ -40,44 +41,17 @@ class ConnectionHandle(TheOneRingHandle): class ContactHandle(TheOneRingHandle): - def __init__(self, connection, id, contactId, phoneNumber): + def __init__(self, connection, id, phoneNumber): + self._phoneNumber = util_misc.normalize_number(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.strip_number(phoneNumber) - - @staticmethod - def from_handle_name(handleName): - parts = handleName.split("#", 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.strip_number(contactNumber) - return contactId, contactNumber - - @staticmethod - def to_handle_name(contactId, contactNumber): - handleName = "#".join((contactId, util_misc.strip_number(contactNumber))) - return handleName - - @property - def contactID(self): - return self._contactId - @property def phoneNumber(self): return self._phoneNumber - @property - def contactDetails(self): - return self._conn.addressbook.get_contact_details(self._id) - class ListHandle(TheOneRingHandle): @@ -110,9 +84,8 @@ def create_handle_factory(): cache[key] = handle isNewHandle = True connection._handles[handle.get_type(), handle.get_id()] = handle - if False: - handleStatus = "Is New!" if isNewHandle else "From Cache" - _moduleLogger.info("Created Handle: %r (%s)" % (handle, handleStatus)) + handleStatus = "Is New!" if isNewHandle else "From Cache" + _moduleLogger.debug("Created Handle: %r (%s)" % (handle, handleStatus)) return handle return create_handle