baseaccount.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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(
  24. (
  25. account.accountName,
  26. account.isOnline(),
  27. account.autoLogin,
  28. account.gatewayType,
  29. )
  30. )
  31. return data
  32. def isEmpty(self):
  33. return len(self.accounts) == 0
  34. def getConnectionInfo(self):
  35. connectioninfo = []
  36. for account in self.accounts.values():
  37. connectioninfo.append(account.isOnline())
  38. return connectioninfo
  39. def addAccount(self, account):
  40. self.accounts[account.accountName] = account
  41. def delAccount(self, accountName):
  42. del self.accounts[accountName]
  43. def connect(self, accountName, chatui):
  44. """
  45. @returntype: Deferred L{interfaces.IClient}
  46. """
  47. return self.accounts[accountName].logOn(chatui)
  48. def disconnect(self, accountName):
  49. pass
  50. # self.accounts[accountName].logOff() - not yet implemented
  51. def quit(self):
  52. pass
  53. # for account in self.accounts.values():
  54. # account.logOff() - not yet implemented