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