interfaces.py 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. # -*- Python -*-
  2. # Copyright (c) Twisted Matrix Laboratories.
  3. # See LICENSE for details.
  4. """
  5. Pan-protocol chat client.
  6. """
  7. from zope.interface import Attribute, Interface
  8. # (Random musings, may not reflect on current state of code:)
  9. #
  10. # Accounts have Protocol components (clients)
  11. # Persons have Conversation components
  12. # Groups have GroupConversation components
  13. # Persons and Groups are associated with specific Accounts
  14. # At run-time, Clients/Accounts are slaved to a User Interface
  15. # (Note: User may be a bot, so don't assume all UIs are built on gui toolkits)
  16. class IAccount(Interface):
  17. """
  18. I represent a user's account with a chat service.
  19. """
  20. client = Attribute("The L{IClient} currently connecting to this account, if any.")
  21. gatewayType = Attribute(
  22. "A C{str} that identifies the protocol used by this account."
  23. )
  24. def __init__(accountName, autoLogin, username, password, host, port):
  25. """
  26. @type accountName: string
  27. @param accountName: A name to refer to the account by locally.
  28. @type autoLogin: boolean
  29. @type username: string
  30. @type password: string
  31. @type host: string
  32. @type port: integer
  33. """
  34. def isOnline():
  35. """
  36. Am I online?
  37. @rtype: boolean
  38. """
  39. def logOn(chatui):
  40. """
  41. Go on-line.
  42. @type chatui: Implementor of C{IChatUI}
  43. @rtype: L{Deferred} with an eventual L{IClient} result.
  44. """
  45. def logOff():
  46. """
  47. Sign off.
  48. """
  49. def getGroup(groupName):
  50. """
  51. @rtype: L{Group<IGroup>}
  52. """
  53. def getPerson(personName):
  54. """
  55. @rtype: L{Person<IPerson>}
  56. """
  57. class IClient(Interface):
  58. account = Attribute("The L{IAccount} I am a Client for")
  59. def __init__(account, chatui, logonDeferred):
  60. """
  61. @type account: L{IAccount}
  62. @type chatui: L{IChatUI}
  63. @param logonDeferred: Will be called back once I am logged on.
  64. @type logonDeferred: L{Deferred<twisted.internet.defer.Deferred>}
  65. """
  66. def joinGroup(groupName):
  67. """
  68. @param groupName: The name of the group to join.
  69. @type groupName: string
  70. """
  71. def leaveGroup(groupName):
  72. """
  73. @param groupName: The name of the group to leave.
  74. @type groupName: string
  75. """
  76. def getGroupConversation(name, hide=0):
  77. pass
  78. def getPerson(name):
  79. pass
  80. class IPerson(Interface):
  81. def __init__(name, account):
  82. """
  83. Initialize me.
  84. @param name: My name, as the server knows me.
  85. @type name: string
  86. @param account: The account I am accessed through.
  87. @type account: I{Account}
  88. """
  89. def isOnline():
  90. """
  91. Am I online right now?
  92. @rtype: boolean
  93. """
  94. def getStatus():
  95. """
  96. What is my on-line status?
  97. @return: L{locals.StatusEnum}
  98. """
  99. def getIdleTime():
  100. """
  101. @rtype: string (XXX: How about a scalar?)
  102. """
  103. def sendMessage(text, metadata=None):
  104. """
  105. Send a message to this person.
  106. @type text: string
  107. @type metadata: dict
  108. """
  109. class IGroup(Interface):
  110. """
  111. A group which you may have a conversation with.
  112. Groups generally have a loosely-defined set of members, who may
  113. leave and join at any time.
  114. """
  115. name = Attribute("My C{str} name, as the server knows me.")
  116. account = Attribute("The L{Account<IAccount>} I am accessed through.")
  117. def __init__(name, account):
  118. """
  119. Initialize me.
  120. @param name: My name, as the server knows me.
  121. @type name: str
  122. @param account: The account I am accessed through.
  123. @type account: L{Account<IAccount>}
  124. """
  125. def setTopic(text):
  126. """
  127. Set this Groups topic on the server.
  128. @type text: string
  129. """
  130. def sendGroupMessage(text, metadata=None):
  131. """
  132. Send a message to this group.
  133. @type text: str
  134. @type metadata: dict
  135. @param metadata: Valid keys for this dictionary include:
  136. - C{'style'}: associated with one of:
  137. - C{'emote'}: indicates this is an action
  138. """
  139. def join():
  140. """
  141. Join this group.
  142. """
  143. def leave():
  144. """
  145. Depart this group.
  146. """
  147. class IConversation(Interface):
  148. """
  149. A conversation with a specific person.
  150. """
  151. def __init__(person, chatui):
  152. """
  153. @type person: L{IPerson}
  154. """
  155. def show():
  156. """
  157. doesn't seem like it belongs in this interface.
  158. """
  159. def hide():
  160. """
  161. nor this neither.
  162. """
  163. def sendText(text, metadata):
  164. pass
  165. def showMessage(text, metadata):
  166. pass
  167. def changedNick(person, newnick):
  168. """
  169. @param person: XXX Shouldn't this always be Conversation.person?
  170. """
  171. class IGroupConversation(Interface):
  172. def show():
  173. """
  174. doesn't seem like it belongs in this interface.
  175. """
  176. def hide():
  177. """
  178. nor this neither.
  179. """
  180. def sendText(text, metadata):
  181. pass
  182. def showGroupMessage(sender, text, metadata):
  183. pass
  184. def setGroupMembers(members):
  185. """
  186. Sets the list of members in the group and displays it to the user.
  187. """
  188. def setTopic(topic, author):
  189. """
  190. Displays the topic (from the server) for the group conversation window.
  191. @type topic: string
  192. @type author: string (XXX: Not Person?)
  193. """
  194. def memberJoined(member):
  195. """
  196. Adds the given member to the list of members in the group conversation
  197. and displays this to the user,
  198. @type member: string (XXX: Not Person?)
  199. """
  200. def memberChangedNick(oldnick, newnick):
  201. """
  202. Changes the oldnick in the list of members to C{newnick} and displays this
  203. change to the user,
  204. @type oldnick: string (XXX: Not Person?)
  205. @type newnick: string
  206. """
  207. def memberLeft(member):
  208. """
  209. Deletes the given member from the list of members in the group
  210. conversation and displays the change to the user.
  211. @type member: string (XXX: Not Person?)
  212. """
  213. class IChatUI(Interface):
  214. def registerAccountClient(client):
  215. """
  216. Notifies user that an account has been signed on to.
  217. @type client: L{Client<IClient>}
  218. """
  219. def unregisterAccountClient(client):
  220. """
  221. Notifies user that an account has been signed off or disconnected.
  222. @type client: L{Client<IClient>}
  223. """
  224. def getContactsList():
  225. """
  226. @rtype: L{ContactsList}
  227. """
  228. # WARNING: You'll want to be polymorphed into something with
  229. # intrinsic stoning resistance before continuing.
  230. def getConversation(person, Class, stayHidden=0):
  231. """
  232. For the given person object, returns the conversation window
  233. or creates and returns a new conversation window if one does not exist.
  234. @type person: L{Person<IPerson>}
  235. @type Class: L{Conversation<IConversation>} class
  236. @type stayHidden: boolean
  237. @rtype: L{Conversation<IConversation>}
  238. """
  239. def getGroupConversation(group, Class, stayHidden=0):
  240. """
  241. For the given group object, returns the group conversation window or
  242. creates and returns a new group conversation window if it doesn't exist.
  243. @type group: L{Group<interfaces.IGroup>}
  244. @type Class: L{Conversation<interfaces.IConversation>} class
  245. @type stayHidden: boolean
  246. @rtype: L{GroupConversation<interfaces.IGroupConversation>}
  247. """
  248. def getPerson(name, client):
  249. """
  250. Get a Person for a client.
  251. Duplicates L{IAccount.getPerson}.
  252. @type name: string
  253. @type client: L{Client<IClient>}
  254. @rtype: L{Person<IPerson>}
  255. """
  256. def getGroup(name, client):
  257. """
  258. Get a Group for a client.
  259. Duplicates L{IAccount.getGroup}.
  260. @type name: string
  261. @type client: L{Client<IClient>}
  262. @rtype: L{Group<IGroup>}
  263. """
  264. def contactChangedNick(oldnick, newnick):
  265. """
  266. For the given person, changes the person's name to newnick, and
  267. tells the contact list and any conversation windows with that person
  268. to change as well.
  269. @type oldnick: string
  270. @type newnick: string
  271. """