interfaces.py 8.5 KB

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