comparison frontends/quick_frontend/quick_app.py @ 125:8d611eb9ae48

primitivus: contact list enhancement - primitivus: contact list now display groups and sexy name (instead of bare jid) - primitivus: contact list now show an alert when somebody want to contact you, and its chat window is not on the screen - primitivus: cursor is now visible when going to chat window (useful to go back in logs)
author Goffi <goffi@goffi.org>
date Mon, 12 Jul 2010 17:50:00 +0800
parents 961e0898271f
children a86607e5cf38
comparison
equal deleted inserted replaced
124:961e0898271f 125:8d611eb9ae48
65 self.bridge.register("actionResultExt", self.actionResult, "request") 65 self.bridge.register("actionResultExt", self.actionResult, "request")
66 66
67 self.current_action_ids = set() 67 self.current_action_ids = set()
68 self.current_action_ids_cb = {} 68 self.current_action_ids_cb = {}
69 69
70 def __check_profile(self, profile): 70 def check_profile(self, profile):
71 """Tell if the profile is currently followed by the application""" 71 """Tell if the profile is currently followed by the application"""
72 return profile in self.profiles.keys() 72 return profile in self.profiles.keys()
73 73
74 def postInit(self): 74 def postInit(self):
75 """Must be called after __init__, do all automatic task (auto plug profile)""" 75 """Must be called after __init__, do all automatic task (auto plug profile)"""
158 def clear_profile(self): 158 def clear_profile(self):
159 self.profiles.clear() 159 self.profiles.clear()
160 160
161 def connected(self, profile): 161 def connected(self, profile):
162 """called when the connection is made""" 162 """called when the connection is made"""
163 if not self.__check_profile(profile): 163 if not self.check_profile(profile):
164 return 164 return
165 debug(_("Connected")) 165 debug(_("Connected"))
166 self.setStatusOnline(True) 166 self.setStatusOnline(True)
167 #self.bridge.joinMUC('conference.necton2.int', 'test', self.profiles[self.profile]['whoami'].node, self.profile) #gof: 167 #self.bridge.joinMUC('conference.necton2.int', 'test', self.profiles[self.profile]['whoami'].node, self.profile) #gof:
168 168
169 169
170 def disconnected(self, profile): 170 def disconnected(self, profile):
171 """called when the connection is closed""" 171 """called when the connection is closed"""
172 if not self.__check_profile(profile): 172 if not self.check_profile(profile):
173 return 173 return
174 debug(_("Disconnected")) 174 debug(_("Disconnected"))
175 self.CM.clear() 175 self.CM.clear()
176 self.contactList.clear_contacts() 176 self.contactList.clear_contacts()
177 self.setStatusOnline(False) 177 self.setStatusOnline(False)
178 178
179 def newContact(self, JabberId, attributes, groups, profile): 179 def newContact(self, JabberId, attributes, groups, profile):
180 if not self.__check_profile(profile): 180 if not self.check_profile(profile):
181 return 181 return
182 entity=JID(JabberId) 182 entity=JID(JabberId)
183 self.rosterList[entity.short]=(dict(attributes), list(groups)) 183 self.rosterList[entity.short]=(dict(attributes), list(groups))
184 184
185 def newMessage(self, from_jid, msg, type, to_jid, profile): 185 def newMessage(self, from_jid, msg, type, to_jid, profile):
186 if not self.__check_profile(profile): 186 if not self.check_profile(profile):
187 return 187 return
188 sender=JID(from_jid) 188 sender=JID(from_jid)
189 addr=JID(to_jid) 189 addr=JID(to_jid)
190 win = addr if sender.short == self.profiles[profile]['whoami'].short else sender 190 win = addr if sender.short == self.profiles[profile]['whoami'].short else sender
191 self.current_action_ids = set() 191 self.current_action_ids = set()
194 194
195 def setStatusOnline(self, online=True): 195 def setStatusOnline(self, online=True):
196 pass 196 pass
197 197
198 def presenceUpdate(self, jabber_id, show, priority, statuses, profile): 198 def presenceUpdate(self, jabber_id, show, priority, statuses, profile):
199 if not self.__check_profile(profile): 199 if not self.check_profile(profile):
200 return 200 return
201 debug (_("presence update for %(jid)s (show=%(show)s, priority=%(priority)s, statuses=%(statuses)s) [profile:%(profile)s]") % {'jid':jabber_id, 'show':show, 'priority':priority, 'statuses':statuses, 'profile':profile}); 201 debug (_("presence update for %(jid)s (show=%(show)s, priority=%(priority)s, statuses=%(statuses)s) [profile:%(profile)s]") % {'jid':jabber_id, 'show':show, 'priority':priority, 'statuses':statuses, 'profile':profile});
202 from_jid=JID(jabber_id) 202 from_jid=JID(jabber_id)
203 debug ("from_jid.short=%(from_jid)s whoami.short=%(whoami)s" % {'from_jid':from_jid.short, 'whoami':self.profiles[profile]['whoami'].short}) 203 debug ("from_jid.short=%(from_jid)s whoami.short=%(whoami)s" % {'from_jid':from_jid.short, 'whoami':self.profiles[profile]['whoami'].short})
204 204
240 if not self.CM.isConnected(from_jid): 240 if not self.CM.isConnected(from_jid):
241 self.contactList.disconnect(from_jid) 241 self.contactList.disconnect(from_jid)
242 242
243 def roomJoined(self, room_id, room_service, room_nicks, user_nick, profile): 243 def roomJoined(self, room_id, room_service, room_nicks, user_nick, profile):
244 """Called when a MUC room is joined""" 244 """Called when a MUC room is joined"""
245 if not self.__check_profile(profile): 245 if not self.check_profile(profile):
246 return 246 return
247 debug (_("Room [%(room_name)s] joined by %(profile)s, users presents:%(users)s") % {'room_name':room_id+'@'+room_service, 'profile': profile, 'users':room_nicks}) 247 debug (_("Room [%(room_name)s] joined by %(profile)s, users presents:%(users)s") % {'room_name':room_id+'@'+room_service, 'profile': profile, 'users':room_nicks})
248 room_jid=room_id+'@'+room_service 248 room_jid=room_id+'@'+room_service
249 self.chat_wins[room_jid].setUserNick(user_nick) 249 self.chat_wins[room_jid].setUserNick(user_nick)
250 self.chat_wins[room_jid].setType("group") 250 self.chat_wins[room_jid].setType("group")
252 self.chat_wins[room_jid].setPresents(list(set([user_nick]+room_nicks))) 252 self.chat_wins[room_jid].setPresents(list(set([user_nick]+room_nicks)))
253 253
254 254
255 def roomUserJoined(self, room_id, room_service, user_nick, user_data, profile): 255 def roomUserJoined(self, room_id, room_service, user_nick, user_data, profile):
256 """Called when an user joined a MUC room""" 256 """Called when an user joined a MUC room"""
257 if not self.__check_profile(profile): 257 if not self.check_profile(profile):
258 return 258 return
259 room_jid=room_id+'@'+room_service 259 room_jid=room_id+'@'+room_service
260 if self.chat_wins.has_key(room_jid): 260 if self.chat_wins.has_key(room_jid):
261 self.chat_wins[room_jid].replaceUser(user_nick) 261 self.chat_wins[room_jid].replaceUser(user_nick)
262 debug (_("user [%(user_nick)s] joined room [%(room_jid)s]") % {'user_nick':user_nick, 'room_jid':room_jid}) 262 debug (_("user [%(user_nick)s] joined room [%(room_jid)s]") % {'user_nick':user_nick, 'room_jid':room_jid})
263 263
264 def roomUserLeft(self, room_id, room_service, user_nick, user_data, profile): 264 def roomUserLeft(self, room_id, room_service, user_nick, user_data, profile):
265 """Called when an user joined a MUC room""" 265 """Called when an user joined a MUC room"""
266 if not self.__check_profile(profile): 266 if not self.check_profile(profile):
267 return 267 return
268 room_jid=room_id+'@'+room_service 268 room_jid=room_id+'@'+room_service
269 if self.chat_wins.has_key(room_jid): 269 if self.chat_wins.has_key(room_jid):
270 self.chat_wins[room_jid].removeUser(user_nick) 270 self.chat_wins[room_jid].removeUser(user_nick)
271 debug (_("user [%(user_nick)s] left room [%(room_jid)s]") % {'user_nick':user_nick, 'room_jid':room_jid}) 271 debug (_("user [%(user_nick)s] left room [%(room_jid)s]") % {'user_nick':user_nick, 'room_jid':room_jid})
272 272
273 def roomNewSubject(self, room_id, room_service, subject, profile): 273 def roomNewSubject(self, room_id, room_service, subject, profile):
274 """Called when subject of MUC room change""" 274 """Called when subject of MUC room change"""
275 if not self.__check_profile(profile): 275 if not self.check_profile(profile):
276 return 276 return
277 room_jid=room_id+'@'+room_service 277 room_jid=room_id+'@'+room_service
278 if self.chat_wins.has_key(room_jid): 278 if self.chat_wins.has_key(room_jid):
279 self.chat_wins[room_jid].setSubject(subject) 279 self.chat_wins[room_jid].setSubject(subject)
280 debug (_("new subject for room [%(room_jid)s]: %(subject)s") % {'room_jid':room_jid, "subject":subject}) 280 debug (_("new subject for room [%(room_jid)s]: %(subject)s") % {'room_jid':room_jid, "subject":subject})
281 281
282 def tarotGameStarted(self, room_jid, referee, players, profile): 282 def tarotGameStarted(self, room_jid, referee, players, profile):
283 if not self.__check_profile(profile): 283 if not self.check_profile(profile):
284 return 284 return
285 debug (_("Tarot Game Started \o/")) 285 debug (_("Tarot Game Started \o/"))
286 if self.chat_wins.has_key(room_jid): 286 if self.chat_wins.has_key(room_jid):
287 self.chat_wins[room_jid].startGame("Tarot", referee, players) 287 self.chat_wins[room_jid].startGame("Tarot", referee, players)
288 debug (_("new Tarot game started by [%(referee)s] in room [%(room_jid)s] with %(players)s") % {'referee':referee, 'room_jid':room_jid, 'players':[str(player) for player in players]}) 288 debug (_("new Tarot game started by [%(referee)s] in room [%(room_jid)s] with %(players)s") % {'referee':referee, 'room_jid':room_jid, 'players':[str(player) for player in players]})
289 289
290 def tarotGameNew(self, room_jid, hand, profile): 290 def tarotGameNew(self, room_jid, hand, profile):
291 if not self.__check_profile(profile): 291 if not self.check_profile(profile):
292 return 292 return
293 debug (_("New Tarot Game")) 293 debug (_("New Tarot Game"))
294 if self.chat_wins.has_key(room_jid): 294 if self.chat_wins.has_key(room_jid):
295 self.chat_wins[room_jid].getGame("Tarot").newGame(hand) 295 self.chat_wins[room_jid].getGame("Tarot").newGame(hand)
296 296
297 def tarotChooseContrat(self, room_jid, xml_data, profile): 297 def tarotChooseContrat(self, room_jid, xml_data, profile):
298 """Called when the player has too select his contrat""" 298 """Called when the player has too select his contrat"""
299 if not self.__check_profile(profile): 299 if not self.check_profile(profile):
300 return 300 return
301 debug (_("Tarot: need to select a contrat")) 301 debug (_("Tarot: need to select a contrat"))
302 if self.chat_wins.has_key(room_jid): 302 if self.chat_wins.has_key(room_jid):
303 self.chat_wins[room_jid].getGame("Tarot").chooseContrat(xml_data) 303 self.chat_wins[room_jid].getGame("Tarot").chooseContrat(xml_data)
304 304
305 def tarotShowCards(self, room_jid, game_stage, cards, data, profile): 305 def tarotShowCards(self, room_jid, game_stage, cards, data, profile):
306 if not self.__check_profile(profile): 306 if not self.check_profile(profile):
307 return 307 return
308 debug (_("Show cards")) 308 debug (_("Show cards"))
309 if self.chat_wins.has_key(room_jid): 309 if self.chat_wins.has_key(room_jid):
310 self.chat_wins[room_jid].getGame("Tarot").showCards(game_stage, cards, data) 310 self.chat_wins[room_jid].getGame("Tarot").showCards(game_stage, cards, data)
311 311
312 def tarotMyTurn(self, room_jid, profile): 312 def tarotMyTurn(self, room_jid, profile):
313 if not self.__check_profile(profile): 313 if not self.check_profile(profile):
314 return 314 return
315 debug (_("My turn to play")) 315 debug (_("My turn to play"))
316 if self.chat_wins.has_key(room_jid): 316 if self.chat_wins.has_key(room_jid):
317 self.chat_wins[room_jid].getGame("Tarot").MyTurn() 317 self.chat_wins[room_jid].getGame("Tarot").MyTurn()
318 318
319 def tarotScore(self, room_jid, xml_data, winners, loosers, profile): 319 def tarotScore(self, room_jid, xml_data, winners, loosers, profile):
320 """Called when the game is finished and the score are updated""" 320 """Called when the game is finished and the score are updated"""
321 if not self.__check_profile(profile): 321 if not self.check_profile(profile):
322 return 322 return
323 debug (_("Tarot: score received")) 323 debug (_("Tarot: score received"))
324 if self.chat_wins.has_key(room_jid): 324 if self.chat_wins.has_key(room_jid):
325 self.chat_wins[room_jid].getGame("Tarot").showScores(xml_data, winners, loosers) 325 self.chat_wins[room_jid].getGame("Tarot").showScores(xml_data, winners, loosers)
326 326
327 def tarotCardsPlayed(self, room_jid, player, cards, profile): 327 def tarotCardsPlayed(self, room_jid, player, cards, profile):
328 if not self.__check_profile(profile): 328 if not self.check_profile(profile):
329 return 329 return
330 debug (_("Card(s) played (%(player)s): %(cards)s") % {"player":player, "cards":cards}) 330 debug (_("Card(s) played (%(player)s): %(cards)s") % {"player":player, "cards":cards})
331 if self.chat_wins.has_key(room_jid): 331 if self.chat_wins.has_key(room_jid):
332 self.chat_wins[room_jid].getGame("Tarot").cardsPlayed(player, cards) 332 self.chat_wins[room_jid].getGame("Tarot").cardsPlayed(player, cards)
333 333
334 def tarotInvalidCards(self, room_jid, phase, played_cards, invalid_cards, profile): 334 def tarotInvalidCards(self, room_jid, phase, played_cards, invalid_cards, profile):
335 if not self.__check_profile(profile): 335 if not self.check_profile(profile):
336 return 336 return
337 debug (_("Cards played are not valid: %s") % invalid_cards) 337 debug (_("Cards played are not valid: %s") % invalid_cards)
338 if self.chat_wins.has_key(room_jid): 338 if self.chat_wins.has_key(room_jid):
339 self.chat_wins[room_jid].getGame("Tarot").invalidCards(phase, played_cards, invalid_cards) 339 self.chat_wins[room_jid].getGame("Tarot").invalidCards(phase, played_cards, invalid_cards)
340 340
341 def subscribe(self, type, raw_jid, profile): 341 def subscribe(self, type, raw_jid, profile):
342 """Called when a subsciption management signal is received""" 342 """Called when a subsciption management signal is received"""
343 if not self.__check_profile(profile): 343 if not self.check_profile(profile):
344 return 344 return
345 entity = JID(raw_jid) 345 entity = JID(raw_jid)
346 if type=="subscribed": 346 if type=="subscribed":
347 # this is a subscription confirmation, we just have to inform user 347 # this is a subscription confirmation, we just have to inform user
348 self.showDialog(_("The contact %s has accepted your subscription") % entity.short, _('Subscription confirmation')) 348 self.showDialog(_("The contact %s has accepted your subscription") % entity.short, _('Subscription confirmation'))
362 362
363 def showAlert(self, message): 363 def showAlert(self, message):
364 pass #FIXME 364 pass #FIXME
365 365
366 def paramUpdate(self, name, value, namespace, profile): 366 def paramUpdate(self, name, value, namespace, profile):
367 if not self.__check_profile(profile): 367 if not self.check_profile(profile):
368 return 368 return
369 debug(_("param update: [%(namespace)s] %(name)s = %(value)s") % {'namespace':namespace, 'name':name, 'value':value}) 369 debug(_("param update: [%(namespace)s] %(name)s = %(value)s") % {'namespace':namespace, 'name':name, 'value':value})
370 if (namespace,name) == ("Connection", "JabberID"): 370 if (namespace,name) == ("Connection", "JabberID"):
371 debug (_("Changing JID to %s"), value) 371 debug (_("Changing JID to %s"), value)
372 self.profiles[profile]['whoami']=JID(value) 372 self.profiles[profile]['whoami']=JID(value)
373 elif (namespace,name) == ("Misc", "Watched"): 373 elif (namespace,name) == ("Misc", "Watched"):
374 self.profiles[profile]['watched']=value.split() 374 self.profiles[profile]['watched']=value.split()
375 375
376 def contactDeleted(self, jid, profile): 376 def contactDeleted(self, jid, profile):
377 if not self.__check_profile(profile): 377 if not self.check_profile(profile):
378 return 378 return
379 target = JID(jid) 379 target = JID(jid)
380 self.CM.remove(target) 380 self.CM.remove(target)
381 self.contactList.remove(self.CM.get_full(target)) 381 self.contactList.remove(self.CM.get_full(target))
382 try: 382 try: