Mercurial > libervia-backend
diff frontends/quick_frontend/quick_app.py @ 51:8c67ea98ab91
frontend improved to take into account new SàT features
- quick_frontend: better use of contact management, it now manages nicks, avatars, and connected status
- quick_frontend: disconnect and remove are now 2 separate methods for contact list
- wix: new contact list using HTML items, and showing avatars. Groups are not showed for now
- wix: contact status now use tuples, to keep order, human readable status and color of contact
- wix: contact list is updated when avatar or nick is found
- wix: fixed 'question' dialog, which is renamed in 'yes/no'
- wix: action result are now ignored for unkwnown id
- sortilege refactored to work again
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 07 Jan 2010 00:17:27 +1100 |
parents | c2b131e4e262 |
children | 6455fb62ff83 |
line wrap: on
line diff
--- a/frontends/quick_frontend/quick_app.py Thu Jan 07 00:05:15 2010 +1100 +++ b/frontends/quick_frontend/quick_app.py Thu Jan 07 00:17:27 2010 +1100 @@ -22,23 +22,23 @@ from logging import debug, info, error from tools.jid import JID from sat_bridge_frontend.DBus import DBusBridgeFrontend -from quick_frontend.quick_contact_management import QuickContactManagement - +import pdb class QuickApp(): """This class contain the main methods needed for the frontend""" def __init__(self): self.rosterList = {} - self.CM = QuickContactManagement() #a short name if more handy ## bridge ## self.bridge=DBusBridgeFrontend() self.bridge.register("newContact", self.newContact) self.bridge.register("newMessage", self.newMessage) self.bridge.register("presenceUpdate", self.presenceUpdate) + self.bridge.register("subscribe", self.subscribe) self.bridge.register("paramUpdate", self.paramUpdate) self.bridge.register("contactDeleted", self.contactDeleted) + self.bridge.register("updatedValue", self.updatedValue, "request") self.bridge.register("askConfirmation", self.askConfirmation, "request") self.bridge.register("actionResult", self.actionResult, "request") self.bridge.register("actionResultExt", self.actionResult, "request") @@ -59,13 +59,23 @@ for contact in self.bridge.getContacts(): self.newContact(contact[0], contact[1], contact[2]) - for status in self.bridge.getPresenceStatus(): - self.presenceUpdate(status[0], status[1], status[2], status[3], status[4]) + presences = self.bridge.getPresenceStatus() + for contact in presences: + for res in presences[contact]: + jabber_id = contact+('/'+res if res else '') + show = presences[contact][res][0] + priority = presences[contact][res][1] + statuses = presences[contact][res][2] + self.presenceUpdate(jabber_id, show, priority, statuses) + + waitingSub = self.bridge.getWaitingSub() + for sub in waitingSub: + self.subscribe(waitingSub[sub], sub) def newContact(self, JabberId, attributes, groups): - jid=JID(JabberId) - self.rosterList[jid.short]=(dict(attributes), list(groups)) + entity=JID(JabberId) + self.rosterList[entity.short]=(dict(attributes), list(groups)) def newMessage(self, from_jid, msg, type, to_jid): sender=JID(from_jid) @@ -76,64 +86,66 @@ def setStatusOnline(self, online=True): pass - def presenceUpdate(self, jabber_id, type, show, status, priority): - debug ("presence update for %s (type=%s, show=%s, status=%s)", jabber_id, type, show, status); - jid=JID(jabber_id) - debug ("jid.short=%s whoami.short=%s", jid.short, self.whoami.short) + def presenceUpdate(self, jabber_id, show, priority, statuses): + debug ("presence update for %s (show=%s, statuses=%s)", jabber_id, show, statuses); + from_jid=JID(jabber_id) + debug ("from_jid.short=%s whoami.short=%s", from_jid.short, self.whoami.short) - ### subscription management ### - if type=="subscribed": - # this is a subscription confirmation, we just have to inform user - self.showDialog("The contact %s has accepted your subscription" % jid.short, 'Subscription confirmation') - return - elif type=="unsubscribed": - # this is a subscription refusal, we just have to inform user - self.showDialog("The contact %s has refused your subscription" % jid.short, 'Subscription refusal', 'error') - return - elif type=="subscribe": - # this is a subscrition request, we have to ask for user confirmation - answer = self.showDialog("The contact %s wants to subscribe to your presence.\nDo you accept ?" % jid.short, 'Subscription confirmation', 'question') - if answer: - self.bridge.setPresence(type="subscribed", to=jid.short) - else: - self.bridge.setPresence(type="unsubscribed", to=jid.short) - return - ### subscription management end ### - - if jid.short==self.whoami.short: + if from_jid.short==self.whoami.short: if not type: self.setStatusOnline(True) elif type=="unavailable": self.setStatusOnline(False) return - if not type: + if show != 'unavailable': name="" group="" - if self.rosterList.has_key(jid.short): - if self.rosterList[jid.short][0].has_key("name"): - name=self.rosterList[jid.short][0]["name"] - if self.rosterList[jid.short][0].has_key("show"): - name=self.rosterList[jid.short][0]["show"] - if self.rosterList[jid.short][0].has_key("status"): - name=self.rosterList[jid.short][0]["status"] - if len(self.rosterList[jid.short][1]): - group=self.rosterList[jid.short][1][0] + if self.rosterList.has_key(from_jid.short): + if self.rosterList[from_jid.short][0].has_key("name"): + name=self.rosterList[from_jid.short][0]["name"] + if len(self.rosterList[from_jid.short][1]): + group=self.rosterList[from_jid.short][1][0] #FIXME: must be moved in a plugin - if jid.short in self.watched and not jid.short in self.onlineContact: - self.showAlert("Watched jid [%s] is connected !" % jid.short) + if from_jid.short in self.watched and not from_jid.short in self.onlineContact: + self.showAlert("Watched jid [%s] is connected !" % from_jid.short) - self.onlineContact.add(jid) #FIXME onlineContact is useless with CM, must be removed - self.CM.add(jid) - self.contactList.replace(jid, show=show, status=status, name=name, group=group) + self.onlineContact.add(from_jid) #FIXME onlineContact is useless with CM, must be removed + self.CM.add(from_jid) + self.CM.update(from_jid, 'name', name) + self.CM.update(from_jid, 'show', show) + self.CM.update(from_jid, 'statuses', statuses) + self.CM.update(from_jid, 'group', group) + cache = self.bridge.getProfileCache(from_jid) + if cache.has_key('nick'): + self.CM.update(from_jid, 'nick', cache['nick']) + if cache.has_key('avatar'): + self.CM.update(from_jid, 'avatar', self.bridge.getAvatarFile(cache['avatar'])) + self.contactList.replace(from_jid) + if show=="unavailable" and from_jid in self.onlineContact: + self.onlineContact.remove(from_jid) + self.CM.remove(from_jid) + if not self.CM.isConnected(from_jid): + self.contactList.disconnect(from_jid) - if type=="unavailable" and jid in self.onlineContact: - self.onlineContact.remove(jid) - self.CM.remove(jid) - self.contactList.remove(jid) - + def subscribe(self, type, raw_jid): + """Called when a subsciption maangement signal is received""" + entity = JID(raw_jid) + if type=="subscribed": + # this is a subscription confirmation, we just have to inform user + self.showDialog("The contact %s has accepted your subscription" % entity.short, 'Subscription confirmation') + elif type=="unsubscribed": + # this is a subscription refusal, we just have to inform user + self.showDialog("The contact %s has refused your subscription" % entity.short, 'Subscription refusal', 'error') + elif type=="subscribe": + # this is a subscriptionn request, we have to ask for user confirmation + answer = self.showDialog("The contact %s wants to subscribe to your presence.\nDo you accept ?" % entity.short, 'Subscription confirmation', 'yes/no') + if answer: + self.bridge.subscription("subscribed", entity.short) + else: + self.bridge.subscribed("unsubscribed", entity.short) def showDialog(self, message, title, type="info"): raise NotImplementedError @@ -151,13 +163,26 @@ def contactDeleted(self, jid): target = JID(jid) + self.CM.remove(target) + self.contactList.remove(self.CM.get_full(target)) try: self.onlineContact.remove(target.short) except KeyError: pass - self.contactList.remove(self.CM.get_full(jid)) - self.CM.remove(target) - + + def updatedValue(self, name, data): + print "toto" + print "updatedValue", name, data + if name == "profile_nick": + target = JID(data['jid']) + self.CM.update(target, 'nick', data['nick']) + self.contactList.replace(target) + elif name == "profile_avatar": + target = JID(data['jid']) + filename = self.bridge.getAvatarFile(data['avatar']) + self.CM.update(target, 'avatar', filename) + self.contactList.replace(target) + def askConfirmation(self, type, id, data): raise NotImplementedError