import telepathy
import gtk_toolbox
+import util.misc as util_misc
import handle
-USER_ALIAS_ACCOUNT = "account"
-USER_ALIAS_CALLBACK = "callback"
-
-USER_ALIAS = USER_ALIAS_ACCOUNT
-
-
_moduleLogger = logging.getLogger('aliasing')
if phonenumber is None or phonenumber is "":
return ""
- phonenumber = handle.strip_number(phonenumber)
+ phonenumber = util_misc.strip_number(phonenumber)
if len(phonenumber) < 3:
return phonenumber
class AliasingMixin(telepathy.server.ConnectionInterfaceAliasing):
+ USER_ALIAS_ACCOUNT = "account"
+ USER_ALIAS_CALLBACK = "callback"
+
def __init__(self):
telepathy.server.ConnectionInterfaceAliasing.__init__(self)
"""
raise NotImplementedError("Abstract property called")
+ @property
+ def userAliasType(self):
+ """
+ @abstract
+ """
+ raise NotImplementedError("Abstract property called")
+
def handle(self, handleType, handleId):
"""
@abstract
@gtk_toolbox.log_exception(_moduleLogger)
def SetAliases(self, aliases):
_moduleLogger.debug("Called SetAliases")
- if USER_ALIAS == USER_ALIAS_ACCOUNT:
+ if self.userAliasType == self.USER_ALIAS_ACCOUNT:
raise telepathy.errors.PermissionDenied("No user customizable aliases")
- elif USER_ALIAS != USER_ALIAS_CALLBACK:
- raise RuntimeError("Invalid alias type: %r" % USER_ALIAS)
+ elif self.userAliasType != self.USER_ALIAS_CALLBACK:
+ raise RuntimeError("Invalid alias type: %r" % self.userAliasType)
# first validate that no other handle types are included
userHandleAndAlias = None
return
# Update callback
- uglyNumber = handle.strip_number(userHandleAndAlias[1])
+ uglyNumber = util_misc.strip_number(userHandleAndAlias[1])
self.session.backend.set_callback_number(uglyNumber)
# Inform of change
def _get_alias(self, handleId):
h = self.handle(telepathy.HANDLE_TYPE_CONTACT, handleId)
if isinstance(h, handle.ConnectionHandle):
- if USER_ALIAS == USER_ALIAS_CALLBACK:
+ if self.userAliasType == self.USER_ALIAS_CALLBACK:
aliasNumber = self.session.backend.get_callback_number()
- elif USER_ALIAS == USER_ALIAS_ACCOUNT:
+ elif self.userAliasType == self.USER_ALIAS_ACCOUNT:
aliasNumber = self.session.backend.get_account_number()
else:
- raise RuntimeError("Invalid alias type: %r" % USER_ALIAS)
+ raise RuntimeError("Invalid alias type: %r" % self.userAliasType)
userAlias = make_pretty(aliasNumber)
return userAlias
else: