Mercurial > libervia-web
changeset 20:8f4b1a8914c3
- User status is now updated
- by default, the uniBar target the status
- clicking on user's status unselect the selected widget
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 16 Apr 2011 18:06:02 +0200 |
parents | e8e3704eb97f |
children | 77c2e48efa29 |
files | browser_side/panels.py libervia.py libervia.tac public/libervia.css |
diffstat | 4 files changed, 62 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/browser_side/panels.py Sat Apr 16 01:46:01 2011 +0200 +++ b/browser_side/panels.py Sat Apr 16 18:06:02 2011 +0200 @@ -212,18 +212,26 @@ return True return False -class StatusPanel(HTMLPanel): - def __init__(self, status=''): - self.status = status +class StatusPanel(HTMLPanel, ClickHandler): + def __init__(self, host, status=''): + self.host = host + self.status = status or ' ' HTMLPanel.__init__(self, self.__getContent()) + self.setStyleName('statusPanel') + ClickHandler.__init__(self) + self.addClickListener(self) def __getContent(self): return "<span class='status'>%(status)s</span>" % {'status':self.status} def changeStatus(self, new_status): - self.status = new_status + self.status = new_status or ' ' self.setHTML(self.__getContent()) + def onClick(self, sender, event): + #As status is the default target of uniBar, we don't want to select anything if click on it + self.host.select(None) + class ChatText(HTMLPanel): def __init__(self, timestamp, nick, mymess, msg):
--- a/libervia.py Sat Apr 16 01:46:01 2011 +0200 +++ b/libervia.py Sat Apr 16 18:06:02 2011 +0200 @@ -67,7 +67,7 @@ class BridgeCall(LiberviaJsonProxy): def __init__(self): LiberviaJsonProxy.__init__(self, "/json_api", - ["getContacts", "sendMessage", "sendMblog", "getMblogNodes", "getProfileJid", "getHistory"]) + ["getContacts", "sendMessage", "sendMblog", "getMblogNodes", "getProfileJid", "getHistory", "getPresenceStatus"]) class BridgeSignals(LiberviaJsonProxy): def __init__(self): @@ -90,9 +90,12 @@ if _txt: if _txt.startswith('@'): self.host.bridge.call('sendMblog', None, self.getText()) + elif self.host.selected == None: + print "changement de status pour", _txt + self.host.bridge.call('setStatus', None, _txt) elif isinstance(self.host.selected, ChatPanel): _chat = self.host.selected - self.host.bridge.call('sendMessage', None, str(_chat.target), _txt, '', 'chat') + self.host.bridge.call('sendMessage', None, str(_chat.target), _txt, '', 'chat') self.setText('') def complete(self): @@ -109,7 +112,7 @@ self.selected = None self.uniBox = UniBox(self) self.uniBox.addKey("@@: ") - self.statusPanel = StatusPanel() + self.statusPanel = StatusPanel(self) self.contactPanel = ContactPanel(self) self.panel = MainPanel(self) self.middle_panel = self.panel.middle_panel @@ -168,9 +171,14 @@ self._personalEventCb(*args) elif name == 'newMessage': self._newMessageCb(*args) + elif name == 'presenceUpdate': + self._presenceUpdateCb(*args) def _getProfileJidCB(self, jid): self.whoami = JID(jid) + #we can now ask our status + self.bridge.call('getPresenceStatus', self._getPresenceStatusCB) + ## Signals callbacks ## @@ -202,6 +210,20 @@ if isinstance(panel,ChatPanel) and (panel.target.bare == _from.bare or panel.target.bare == _to.bare): panel.printMessage(_from, msg) + def _presenceUpdateCb(self, entity, show, priority, statuses): + _entity = JID(entity) + #XXX: QnD way to only get our status + if self.whoami and self.whoami.bare == _entity.bare and statuses: + self.statusPanel.changeStatus(statuses.values()[0]) + + def _getPresenceStatusCB(self, presence_data): + #XXX we are only interested in our own presence so far + if self.whoami and presence_data.has_key(self.whoami.bare): + myjid = self.whoami.bare + if presence_data[myjid]: + args = presence_data[myjid].values()[0] + self._presenceUpdateCb(myjid, *args) + if __name__ == '__main__': pyjd.setup("http://localhost:8080/libervia.html") app = SatWebFrontend()
--- a/libervia.tac Sat Apr 16 01:46:01 2011 +0200 +++ b/libervia.tac Sat Apr 16 18:06:02 2011 +0200 @@ -65,6 +65,13 @@ """Return all passed args.""" profile = self.session.sat_profile return self.sat_host.bridge.getContacts(profile) + + def jsonrpc_setStatus(self, status): + """Change the status""" + profile = self.session.sat_profile + print "new status received:", status + self.sat_host.bridge.setPresence('', '', 0, {'':status}, profile) + def jsonrpc_sendMessage(self, to_jid, msg, subject, type): """send message""" @@ -85,6 +92,11 @@ else: return self.sat_host.bridge.sendGroupBlog([recip], text, profile) + def jsonrpc_getPresenceStatus(self): + """Get Presence information for connected contacts""" + profile = self.session.sat_profile + return self.sat_host.bridge.getPresenceStatus(profile) + def jsonrpc_getHistory(self, from_jid, to_jid, size): """Return history for the from_jid/to_jid couple""" #FIXME: this method should definitely be asynchrone, need to fix it !!! @@ -310,7 +322,7 @@ sys.exit(1) self.bridge.register("connected", self.signal_handler.connected) self.bridge.register("connectionError", self.signal_handler.connectionError) - for signal_name in ['presenceUpdate', 'personalEvent', 'newMessage']: + for signal_name in ['presenceUpdate', 'personalEvent', 'newMessage', 'presenceUpdate']: self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name)) root.putChild('json_signal_api', self.signal_handler) root.putChild('json_api', MethodHandler(self))
--- a/public/libervia.css Sat Apr 16 01:46:01 2011 +0200 +++ b/public/libervia.css Sat Apr 16 18:06:02 2011 +0200 @@ -161,6 +161,18 @@ background-color: yellow; } +/* Status */ + +.statusPanel { + margin: auto; + text-align: center; + width: 80%; +} + +.status { + font-style: italic; +} + /* Microblog */ .microblogPanel {