baseaccount.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # -*- Python -*-
  2. #
  3. # Copyright (c) Twisted Matrix Laboratories.
  4. # See LICENSE for details.
  5. #
  6. class AccountManager:
  7. """I am responsible for managing a user's accounts.
  8. That is, remembering what accounts are available, their settings,
  9. adding and removal of accounts, etc.
  10. @ivar accounts: A collection of available accounts.
  11. @type accounts: mapping of strings to L{Account<interfaces.IAccount>}s.
  12. """
  13. def __init__(self):
  14. self.accounts = {}
  15. def getSnapShot(self):
  16. """A snapshot of all the accounts and their status.
  17. @returns: A list of tuples, each of the form
  18. (string:accountName, boolean:isOnline,
  19. boolean:autoLogin, string:gatewayType)
  20. """
  21. data = []
  22. for account in self.accounts.values():
  23. data.append((account.accountName, account.isOnline(),
  24. account.autoLogin, account.gatewayType))
  25. return data
  26. def isEmpty(self):
  27. return len(self.accounts) == 0
  28. def getConnectionInfo(self):
  29. connectioninfo = []
  30. for account in self.accounts.values():
  31. connectioninfo.append(account.isOnline())
  32. return connectioninfo
  33. def addAccount(self, account):
  34. self.accounts[account.accountName] = account
  35. def delAccount(self, accountName):
  36. del self.accounts[accountName]
  37. def connect(self, accountName, chatui):
  38. """
  39. @returntype: Deferred L{interfaces.IClient}
  40. """
  41. return self.accounts[accountName].logOn(chatui)
  42. def disconnect(self, accountName):
  43. pass
  44. #self.accounts[accountName].logOff() - not yet implemented
  45. def quit(self):
  46. pass
  47. #for account in self.accounts.values():
  48. # account.logOff() - not yet implemented