comparison libervia.py @ 328:835a8ae799e7

Add notifications support, fixes bug 7.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 23 Feb 2013 16:27:32 +0100
parents 36927be51481
children 629c99bbd031
comparison
equal deleted inserted replaced
327:6126bd24e7dd 328:835a8ae799e7
33 from browser_side.panels import MicroblogItem 33 from browser_side.panels import MicroblogItem
34 from browser_side import panels, dialog 34 from browser_side import panels, dialog
35 from browser_side.jid import JID 35 from browser_side.jid import JID
36 from browser_side.xmlui import XMLUI 36 from browser_side.xmlui import XMLUI
37 from browser_side.tools import html_sanitize 37 from browser_side.tools import html_sanitize
38 from browser_side.notification import Notification
38 39
39 from sat_frontends.tools.misc import InputHistory 40 from sat_frontends.tools.misc import InputHistory
40 from sat_frontends.tools.strings import getURLParams 41 from sat_frontends.tools.strings import getURLParams
41 from constants import Const 42 from constants import Const
42 from sat.core.i18n import _ 43 from sat.core.i18n import _
178 self.room_list = [] # list of rooms 179 self.room_list = [] # list of rooms
179 self.mblog_cache = [] # used to keep our own blog entries in memory, to show them in new mblog panel 180 self.mblog_cache = [] # used to keep our own blog entries in memory, to show them in new mblog panel
180 self.avatars_cache = {} # keep track of jid's avatar hash (key=jid, value=file) 181 self.avatars_cache = {} # keep track of jid's avatar hash (key=jid, value=file)
181 self._register_box = None 182 self._register_box = None
182 RootPanel().add(self.panel) 183 RootPanel().add(self.panel)
184 self.notification = Notification()
183 DOM.addEventPreview(self) 185 DOM.addEventPreview(self)
184 self._register = RegisterCall() 186 self._register = RegisterCall()
185 self._register.call('registerParams', None) 187 self._register.call('registerParams', None)
186 self._register.call('isRegistered', self._isRegisteredCB) 188 self._register.call('isRegistered', self._isRegisteredCB)
187 self.initialised = False 189 self.initialised = False
302 if tab_index is None or tab_index < 0 or tab_index >= self.tab_panel.getWidgetCount(): 304 if tab_index is None or tab_index < 0 or tab_index >= self.tab_panel.getWidgetCount():
303 panel = self.tab_panel.getCurrentPanel() 305 panel = self.tab_panel.getCurrentPanel()
304 else: 306 else:
305 panel = self.tab_panel.tabBar.getTabWidget(tab_index) 307 panel = self.tab_panel.tabBar.getTabWidget(tab_index)
306 panel.addWidget(wid) 308 panel.addWidget(wid)
309
310 def displayNotification(self, title, body):
311 self.notification.notify(title, body)
307 312
308 def _isRegisteredCB(self, registered): 313 def _isRegisteredCB(self, registered):
309 if not registered: 314 if not registered:
310 self._register_box = RegisterBox(self.logged) 315 self._register_box = RegisterBox(self.logged)
311 self._register_box.centerBox() 316 self._register_box.centerBox()
646 def _newMessageCb(self, from_jid, msg, msg_type, to_jid, extra): 651 def _newMessageCb(self, from_jid, msg, msg_type, to_jid, extra):
647 _from = JID(from_jid) 652 _from = JID(from_jid)
648 _to = JID(to_jid) 653 _to = JID(to_jid)
649 other = _to if _from.bare == self.whoami.bare else _from 654 other = _to if _from.bare == self.whoami.bare else _from
650 lib_wid = self.getLiberviaWidget(panels.ChatPanel, other, ignoreOtherTabs=False) 655 lib_wid = self.getLiberviaWidget(panels.ChatPanel, other, ignoreOtherTabs=False)
656 self.displayNotification(_from, msg)
651 if lib_wid is not None: 657 if lib_wid is not None:
652 lib_wid.printMessage(_from, msg, extra) 658 lib_wid.printMessage(_from, msg, extra)
653 else: 659 else:
654 # The message has not been showed, we must indicate it 660 # The message has not been shown, we must indicate it
655 self.contact_panel.setContactMessageWaiting(other.bare, True) 661 self.contact_panel.setContactMessageWaiting(other.bare, True)
656 662
657 def _presenceUpdateCb(self, entity, show, priority, statuses): 663 def _presenceUpdateCb(self, entity, show, priority, statuses):
658 entity_jid = JID(entity) 664 entity_jid = JID(entity)
659 if self.whoami and self.whoami == entity_jid: # XXX: QnD way to get our presence/status 665 if self.whoami and self.whoami == entity_jid: # XXX: QnD way to get our presence/status