X-Git-Url: http://git.maemo.org/git/?p=theonering;a=blobdiff_plain;f=src%2Faliasing.py;h=22fa414d1828d3f2b821b900bb94d3db14254bcd;hp=936ff70e8b9dc964ac5b9b2394771e7cf573effd;hb=1c892d1b9bf14b28eb54ce3590ed2ee29d5e3d25;hpb=d079b698c676f1ef3f05d8b553d9e09c32699a7d diff --git a/src/aliasing.py b/src/aliasing.py index 936ff70..22fa414 100644 --- a/src/aliasing.py +++ b/src/aliasing.py @@ -3,8 +3,7 @@ import logging import telepathy import tp -import gtk_toolbox -import util.misc as util_misc +import util.misc as misc_utils import handle @@ -72,7 +71,7 @@ def make_pretty(phonenumber): if phonenumber is None or phonenumber is "": return "" - phonenumber = util_misc.normalize_number(phonenumber) + phonenumber = misc_utils.normalize_number(phonenumber) if phonenumber[0] == "+": prettynumber = _make_pretty_international(phonenumber[1:]) @@ -101,22 +100,29 @@ class AliasingMixin(tp.ConnectionInterfaceAliasing): """ raise NotImplementedError("Abstract property called") - def handle(self, handleType, handleId): + @property + def callbackNumberParameter(self): + """ + @abstract + """ + raise NotImplementedError("Abstract property called") + + def get_handle_by_id(self, handleType, handleId): """ @abstract """ raise NotImplementedError("Abstract function called") - @gtk_toolbox.log_exception(_moduleLogger) + @misc_utils.log_exception(_moduleLogger) def GetAliasFlags(self): return 0 - @gtk_toolbox.log_exception(_moduleLogger) + @misc_utils.log_exception(_moduleLogger) def RequestAliases(self, contactHandleIds): _moduleLogger.debug("Called RequestAliases") return [self._get_alias(handleId) for handleId in contactHandleIds] - @gtk_toolbox.log_exception(_moduleLogger) + @misc_utils.log_exception(_moduleLogger) def GetAliases(self, contactHandleIds): _moduleLogger.debug("Called GetAliases") @@ -126,7 +132,7 @@ class AliasingMixin(tp.ConnectionInterfaceAliasing): ) return idToAlias - @gtk_toolbox.log_exception(_moduleLogger) + @misc_utils.log_exception(_moduleLogger) def SetAliases(self, aliases): _moduleLogger.debug("Called SetAliases") # first validate that no other handle types are included @@ -137,18 +143,18 @@ class AliasingMixin(tp.ConnectionInterfaceAliasing): else: raise telepathy.errors.PermissionDenied("No user customizable aliases") - if len(alias) == 0: + uglyNumber = misc_utils.normalize_number(alias) + if len(uglyNumber) == 0: # Reset to the original from login if one was provided - alias = self.callbackNumberParameter - if not util_misc.is_valid_number(alias): - raise telepathy.errors.InvalidArgument("Invalid phone number %r" % (alias, )) + uglyNumber = self.callbackNumberParameter + if not misc_utils.is_valid_number(uglyNumber): + raise telepathy.errors.InvalidArgument("Invalid phone number %r" % (uglyNumber, )) # Update callback - uglyNumber = util_misc.normalize_number(alias) self.session.backend.set_callback_number(uglyNumber) # Inform of change - userAlias = make_pretty(alias) + userAlias = make_pretty(uglyNumber) changedAliases = ((handleId, userAlias), ) self.AliasesChanged(changedAliases) @@ -159,9 +165,9 @@ class AliasingMixin(tp.ConnectionInterfaceAliasing): userAlias = make_pretty(aliasNumber) return userAlias else: - contactId = h.contactID - if contactId: - contactAlias = self.session.addressbook.get_contact_name(contactId) - else: - contactAlias = make_pretty(h.phoneNumber) + number = h.phoneNumber + try: + contactAlias = self.session.addressbook.get_contact_name(number) + except KeyError: + contactAlias = make_pretty(number) return contactAlias