Mercurial > libervia-web
comparison src/browser/libervia_main.py @ 697:b395d1309936
browser_side: clean the code that has been commented or isolated during the refactorisation to base libervia on quick_frontend
author | souliane <souliane@mailoo.org> |
---|---|
date | Mon, 20 Apr 2015 09:14:03 +0200 |
parents | c2f22ca12e23 |
children | be55a782a976 |
comparison
equal
deleted
inserted
replaced
696:c2f22ca12e23 | 697:b395d1309936 |
---|---|
69 unicode = str # FIXME: pyjamas workaround | 69 unicode = str # FIXME: pyjamas workaround |
70 | 70 |
71 | 71 |
72 MAX_MBLOG_CACHE = 500 # Max microblog entries kept in memories | 72 MAX_MBLOG_CACHE = 500 # Max microblog entries kept in memories |
73 | 73 |
74 # Set to true to not create a new LiberviaWidget when a similar one | |
75 # already exist (i.e. a chat panel with the same target). Instead | |
76 # the existing widget will be eventually removed from its parent | |
77 # and added to new libervia_widget.WidgetsPanel, or replaced to the expected | |
78 # position if the previous and the new parent are the same. | |
79 # REUSE_EXISTING_LIBERVIA_WIDGETS = True # FIXME | |
80 | |
81 | 74 |
82 class SatWebFrontend(InputHistory, QuickApp): | 75 class SatWebFrontend(InputHistory, QuickApp): |
83 def onModuleLoad(self): | 76 def onModuleLoad(self): |
84 log.info("============ onModuleLoad ==============") | 77 log.info("============ onModuleLoad ==============") |
85 self.bridge_signals = json.BridgeSignals(self) | 78 self.bridge_signals = json.BridgeSignals(self) |
105 #FIXME: microblog cache should be managed directly in blog module | 98 #FIXME: microblog cache should be managed directly in blog module |
106 self.mblog_cache = [] # used to keep our own blog entries in memory, to show them in new mblog panel | 99 self.mblog_cache = [] # used to keep our own blog entries in memory, to show them in new mblog panel |
107 | 100 |
108 self._versions={} # SàT and Libervia versions cache | 101 self._versions={} # SàT and Libervia versions cache |
109 | 102 |
110 # self._selected_listeners = set() # FIXME: to be done with new listeners mechanism | |
111 | |
112 @property | 103 @property |
113 def whoami(self): | 104 def whoami(self): |
114 # XXX: works because Libervia is mono-profile | 105 # XXX: works because Libervia is mono-profile |
115 # if one day Libervia manage several profiles at once, this must be deleted | 106 # if one day Libervia manage several profiles at once, this must be deleted |
116 return self.profiles[C.PROF_KEY_NONE].whoami | 107 return self.profiles[C.PROF_KEY_NONE].whoami |
180 try: | 171 try: |
181 self.plugins['otr'] = plugin_sec_otr.OTR(self) | 172 self.plugins['otr'] = plugin_sec_otr.OTR(self) |
182 except TypeError: # plugin_sec_otr has not been imported | 173 except TypeError: # plugin_sec_otr has not been imported |
183 pass | 174 pass |
184 | 175 |
185 # def addSelectedListener(self, callback): | |
186 # self._selected_listeners.add(callback) | |
187 | |
188 def getSelected(self): | 176 def getSelected(self): |
189 wid = self.tab_panel.getCurrentPanel() | 177 wid = self.tab_panel.getCurrentPanel() |
190 if not isinstance(wid, libervia_widget.WidgetsPanel): | 178 if not isinstance(wid, libervia_widget.WidgetsPanel): |
191 log.error("Tab widget is not a WidgetsPanel, can't get selected widget") | 179 log.error("Tab widget is not a WidgetsPanel, can't get selected widget") |
192 return None | 180 return None |
211 self.selected_widget = widget | 199 self.selected_widget = widget |
212 | 200 |
213 if widget: | 201 if widget: |
214 widgets_panel.selected.addStyleName('selected_widget') | 202 widgets_panel.selected.addStyleName('selected_widget') |
215 | 203 |
216 # FIXME: | |
217 # for callback in self._selected_listeners: | |
218 # callback(widget) | |
219 | |
220 def resize(self): | 204 def resize(self): |
221 """Resize elements""" | 205 """Resize elements""" |
222 Window.onResize() | 206 Window.onResize() |
223 | 207 |
224 def onBeforeTabSelected(self, sender, tab_index): | 208 def onBeforeTabSelected(self, sender, tab_index): |
225 return True | 209 return True |
226 | 210 |
227 def onTabSelected(self, sender, tab_index): | 211 def onTabSelected(self, sender, tab_index): |
228 pass | 212 pass |
229 # selected = self.getSelected() | |
230 # FIXME: | |
231 # for callback in self._selected_listeners: | |
232 # callback(selected) | |
233 | 213 |
234 def onEventPreview(self, event): | 214 def onEventPreview(self, event): |
235 if event.type in ["keydown", "keypress", "keyup"] and event.keyCode == KEY_ESCAPE: | 215 if event.type in ["keydown", "keypress", "keyup"] and event.keyCode == KEY_ESCAPE: |
236 #needed to prevent request cancellation in Firefox | 216 #needed to prevent request cancellation in Firefox |
237 event.preventDefault() | 217 event.preventDefault() |
357 self.panel.addPresenceStatusPanel(self.presence_status_panel) | 337 self.panel.addPresenceStatusPanel(self.presence_status_panel) |
358 self.panel.tab_panel.getTabBar().setVisible(True) | 338 self.panel.tab_panel.getTabBar().setVisible(True) |
359 | 339 |
360 self.bridge_signals.call('getSignals', self.bridge_signals.signalHandler) | 340 self.bridge_signals.call('getSignals', self.bridge_signals.signalHandler) |
361 | 341 |
362 #it's time to fill the page | |
363 # self.bridge.call('getContacts', self._getContactsCB) | |
364 # self.bridge.call('getParamsUI', self._getParamsUICB) | |
365 # self.bridge_signals.call('getSignals', self._getSignalsCB) | |
366 # #We want to know our own jid | |
367 # self.bridge.call('getProfileJid', self._getProfileJidCB) | |
368 | |
369 def domain_cb(value): | 342 def domain_cb(value): |
370 self._defaultDomain = value | 343 self._defaultDomain = value |
371 log.info(u"new account domain: %s" % value) | 344 log.info(u"new account domain: %s" % value) |
372 | 345 |
373 def domain_eb(value): | 346 def domain_eb(value): |
374 self._defaultDomain = "libervia.org" | 347 self._defaultDomain = "libervia.org" |
375 | 348 |
376 self.bridge.getNewAccountDomain(callback=domain_cb, errback=domain_eb) | 349 self.bridge.getNewAccountDomain(callback=domain_cb, errback=domain_eb) |
377 self.plug_profiles([C.PROF_KEY_NONE]) # XXX: None was used intitially, but pyjamas bug when using variable arguments and None is the only arg. | 350 self.plug_profiles([C.PROF_KEY_NONE]) # XXX: None was used intitially, but pyjamas bug when using variable arguments and None is the only arg. |
378 # self.discuss_panel.addWidget(panel.MicroblogPanel(self, [])) | |
379 | |
380 # # get cached params and refresh the display | |
381 # def param_cb(cat, name, count): | |
382 # count[0] += 1 | |
383 # refresh = count[0] == len(C.CACHED_PARAMS) | |
384 # return lambda value: self._paramUpdate(name, value, cat, refresh) | |
385 | |
386 # count = [0] # used to do something similar to DeferredList | |
387 # for cat, name in C.CACHED_PARAMS: | |
388 # self.bridge.call('asyncGetParamA', param_cb(cat, name, count), name, cat) | |
389 | 351 |
390 def profilePlugged(self, dummy): # FIXME: to be called as a "profilePlugged" listener? | 352 def profilePlugged(self, dummy): # FIXME: to be called as a "profilePlugged" listener? |
391 QuickApp.profilePlugged(self, dummy) | 353 QuickApp.profilePlugged(self, dummy) |
392 | 354 |
393 microblog_widget = self.displayWidget(blog.MicroblogPanel, ()) | 355 microblog_widget = self.displayWidget(blog.MicroblogPanel, ()) |
538 return | 500 return |
539 self.initialised = True # initialisation phase is finished here | 501 self.initialised = True # initialisation phase is finished here |
540 for event_data in self.init_cache: # so we have to send all the cached events | 502 for event_data in self.init_cache: # so we have to send all the cached events |
541 self.personalEventHandler(*event_data) | 503 self.personalEventHandler(*event_data) |
542 del self.init_cache | 504 del self.init_cache |
543 | |
544 def _getProfileJidCB(self, jid_s): | |
545 # FIXME | |
546 raise Exception("should not be here !") | |
547 # self.whoami = jid.JID(jid_s) | |
548 # #we can now ask our status | |
549 # self.bridge.call('getPresenceStatuses', self._getPresenceStatusesCb) | |
550 # #the rooms where we are | |
551 # self.bridge.call('getRoomsJoined', self._getRoomsJoinedCb) | |
552 # #and if there is any subscription request waiting for us | |
553 # self.bridge.call('getWaitingSub', self._getWaitingSubCb) | |
554 # #we fill the panels already here | |
555 # for lib_wid in self.libervia_widgets: | |
556 # if isinstance(lib_wid, panel.MicroblogPanel): | |
557 # if lib_wid.accept_all(): | |
558 # self.bridge.call('getMassiveLastMblogs', lib_wid.massiveInsert, 'ALL', [], 10) | |
559 # else: | |
560 # self.bridge.call('getMassiveLastMblogs', lib_wid.massiveInsert, 'GROUP', lib_wid.accepted_groups, 10) | |
561 | |
562 # #we ask for our own microblogs: | |
563 # self.loadOurMainEntries() | |
564 | |
565 # # initialize plugins which waited for the connection to be done | |
566 # for plugin in self.plugins.values(): | |
567 # if hasattr(plugin, 'profileConnected'): | |
568 # plugin.profileConnected() | |
569 | 505 |
570 def loadOurMainEntries(self, index=0, mblog_panel=None): | 506 def loadOurMainEntries(self, index=0, mblog_panel=None): |
571 """Load a page of our own blogs from the cache or ask them to the | 507 """Load a page of our own blogs from the cache or ask them to the |
572 backend. Then fill the panels with them. | 508 backend. Then fill the panels with them. |
573 | 509 |
648 for lib_wid in self.libervia_widgets: | 584 for lib_wid in self.libervia_widgets: |
649 if isinstance(lib_wid, blog.MicroblogPanel): | 585 if isinstance(lib_wid, blog.MicroblogPanel): |
650 if lib_wid.isJidAccepted(entity): | 586 if lib_wid.isJidAccepted(entity): |
651 self.bridge.call('getMassiveMblogs', lib_wid.massiveInsert, 'JID', [unicode(entity)]) | 587 self.bridge.call('getMassiveMblogs', lib_wid.massiveInsert, 'JID', [unicode(entity)]) |
652 | 588 |
653 # def getLiberviaWidget(self, class_, entity, ignoreOtherTabs=True): | |
654 # """Get the corresponding panel if it exists. | |
655 # @param class_ (class): class of the panel (ChatPanel, MicroblogPanel...) | |
656 # @param entity (dict): dictionnary to define the entity. | |
657 # @param ignoreOtherTabs (bool): if True, the widgets that are not | |
658 # contained by the currently selected tab will be ignored | |
659 # @return: the existing widget that has been found or None.""" | |
660 # selected_tab = self.tab_panel.getCurrentPanel() | |
661 # for lib_wid in self.libervia_widgets: | |
662 # parent = lib_wid.getWidgetsPanel(expect=False) | |
663 # if parent is None or (ignoreOtherTabs and parent != selected_tab): | |
664 # # do not return a widget that is not in the currently selected tab | |
665 # continue | |
666 # if isinstance(lib_wid, class_): | |
667 # try: | |
668 # if lib_wid.matchEntity(*(entity.values())): # XXX: passing **entity bugs! | |
669 # log.debug("existing widget found: %s" % lib_wid.getDebugName()) | |
670 # return lib_wid | |
671 # except AttributeError as e: | |
672 # e.stack_list() | |
673 # return None | |
674 # return None | |
675 | |
676 def displayWidget(self, class_, target, dropped=False, new_tab=None, *args, **kwargs): | 589 def displayWidget(self, class_, target, dropped=False, new_tab=None, *args, **kwargs): |
677 """Get or create a LiberviaWidget and select it. When the user dropped | 590 """Get or create a LiberviaWidget and select it. When the user dropped |
678 something, a new widget is always created, otherwise we look for an | 591 something, a new widget is always created, otherwise we look for an |
679 existing widget and re-use it if it's in the current tab. | 592 existing widget and re-use it if it's in the current tab. |
680 | 593 |
720 wid = self.widgets.getOrCreateWidget(class_, target, *args, **kwargs) | 633 wid = self.widgets.getOrCreateWidget(class_, target, *args, **kwargs) |
721 self.addWidget(wid) | 634 self.addWidget(wid) |
722 self.setSelected(wid) | 635 self.setSelected(wid) |
723 return wid | 636 return wid |
724 | 637 |
725 | |
726 # def getOrCreateLiberviaWidget(self, class_, entity, select=True, new_tab=None): | |
727 # """Get the matching LiberviaWidget if it exists, or create a new one. | |
728 # @param class_ (class): class of the panel (ChatPanel, MicroblogPanel...) | |
729 # @param entity (dict): dictionnary to define the entity. | |
730 # @param select (bool): if True, select the widget that has been found or created | |
731 # @param new_tab (unicode): if not None, a widget which is created is created in | |
732 # a new tab. In that case new_tab is a unicode to label that new tab. | |
733 # If new_tab is not None and a widget is found, no tab is created. | |
734 # @return: the newly created wigdet if REUSE_EXISTING_LIBERVIA_WIDGETS | |
735 # is set to False or if the widget has not been found, the existing | |
736 # widget that has been found otherwise.""" | |
737 # lib_wid = None | |
738 # tab = None | |
739 # if REUSE_EXISTING_LIBERVIA_WIDGETS: | |
740 # lib_wid = self.getLiberviaWidget(class_, entity, new_tab is None) | |
741 # if lib_wid is None: # create a new widget | |
742 # lib_wid = class_.createPanel(self, *(entity.values())) # XXX: passing **entity bugs! | |
743 # if new_tab is None: | |
744 # self.addWidget(lib_wid) | |
745 # else: | |
746 # tab = self.addTab(new_tab, lib_wid, False) | |
747 # else: # reuse existing widget | |
748 # tab = lib_wid.getWidgetsPanel(expect=False) | |
749 # if new_tab is None: | |
750 # if tab is not None: | |
751 # tab.removeWidget(lib_wid) | |
752 # self.addWidget(lib_wid) | |
753 # if select: | |
754 # if new_tab is not None: | |
755 # self.tab_panel.selectTab(tab) | |
756 # # must be done after the widget is added, | |
757 # # for example to scroll to the bottom | |
758 # self.setSelected(lib_wid) | |
759 # lib_wid.refresh() | |
760 # return lib_wid | |
761 | |
762 # def getRoomWidget(self, target): | |
763 # """Get the MUC widget for the given target. | |
764 | |
765 # @param target (jid.JID): BARE jid of the MUC | |
766 # @return: panel.ChatPanel instance or None | |
767 # """ | |
768 # entity = {'item': target, 'type_': 'group'} | |
769 # if target.full() in self.room_list or target in self.room_list: # as JID is a string-based class, we don't know what will please Pyjamas... | |
770 # return self.getLiberviaWidget(panel.ChatPanel, entity, ignoreOtherTabs=False) | |
771 # return None | |
772 | |
773 # def getOrCreateRoomWidget(self, target): | |
774 # """Get the MUC widget for the given target, create it if necessary. | |
775 | |
776 # @param target (jid.JID): BARE jid of the MUC | |
777 # @return: panel.ChatPanel instance | |
778 # """ | |
779 # lib_wid = self.getRoomWidget(target) | |
780 # if lib_wid: | |
781 # return lib_wid | |
782 | |
783 # # XXX: target.node.startwith(...) raises an error "startswith is not a function" | |
784 # # This happens when node a is property defined in the JID class | |
785 # # FIXME: pyjamas doesn't handle the properties well | |
786 # node = target.node | |
787 | |
788 # # XXX: it's not really beautiful, but it works :) | |
789 # if node.startswith('sat_tarot_'): | |
790 # tab_name = "Tarot" | |
791 # elif node.startswith('sat_radiocol_'): | |
792 # tab_name = "Radio collective" | |
793 # else: | |
794 # tab_name = target.node | |
795 | |
796 # self.room_list.append(target) | |
797 # entity = {'item': target, 'type_': 'group'} | |
798 # return self.getOrCreateLiberviaWidget(panel.ChatPanel, entity, new_tab=tab_name) | |
799 | |
800 # def _newMessageCb(self, from_jid_s, msg, msg_type, to_jid_s, extra): | |
801 # from_jid = jid.JID(from_jid_s) | |
802 # to_jid = jid.JID(to_jid_s) | |
803 # for plugin in self.plugins.values(): | |
804 # if hasattr(plugin, 'messageReceivedTrigger'): | |
805 # if not plugin.messageReceivedTrigger(from_jid, msg, msg_type, to_jid, extra): | |
806 # return # plugin returned False to interrupt the process | |
807 # self.newMessageCb(from_jid, msg, msg_type, to_jid, extra) | |
808 | |
809 # def newMessageCb(self, from_jid, msg, msg_type, to_jid, extra): | |
810 # other = to_jid if from_jid.bare == self.whoami.bare else from_jid | |
811 # lib_wid = self.getLiberviaWidget(panel.ChatPanel, {'item': other}, ignoreOtherTabs=False) | |
812 # self.displayNotification(from_jid, msg) | |
813 # if msg_type == 'headline' and from_jid.full() == self._defaultDomain: | |
814 # try: | |
815 # assert extra['subject'] # subject is defined and not empty | |
816 # title = extra['subject'] | |
817 # except (KeyError, AssertionError): | |
818 # title = _('Announcement from %s') % from_jid.full() | |
819 # msg = strings.addURLToText(html_tools.XHTML2Text(msg)) | |
820 # dialog.InfoDialog(title, msg).show() | |
821 # return | |
822 # if lib_wid is not None: | |
823 # if msg_type == C.MESS_TYPE_INFO: | |
824 # lib_wid.printInfo(msg) | |
825 # else: | |
826 # lib_wid.printMessage(from_jid, msg, extra) | |
827 # if 'header_info' in extra: | |
828 # lib_wid.setHeaderInfo(extra['header_info']) | |
829 # else: | |
830 # # FIXME: "info" message and header info will be lost here | |
831 # if not self.contact_panel.isContactInRoster(other.bare): | |
832 # self.contact_panel.updateContact(other.bare, {}, [C.GROUP_NOT_IN_ROSTER]) | |
833 # # The message has not been shown, we must indicate it | |
834 # self.contact_panel.setContactMessageWaiting(other.bare, True) | |
835 | |
836 # def _presenceUpdateCb(self, entity, show, priority, statuses): | |
837 # entity_jid = jid.JID(entity) | |
838 # if self.whoami and self.whoami == entity_jid: # XXX: QnD way to get our presence/status | |
839 # assert(isinstance(self.status_panel, main_panel.PresenceStatusPanel)) | |
840 # self.status_panel.setPresence(show) # pylint: disable=E1103 | |
841 # if statuses: | |
842 # self.status_panel.setStatus(statuses.values()[0]) # pylint: disable=E1103 | |
843 # else: | |
844 # bare_jid = entity_jid.bareJID() | |
845 # if bare_jid.full() in self.room_list or bare_jid in self.room_list: # as JID is a string-based class, we don't know what will please Pyjamas... | |
846 # wid = self.getRoomWidget(bare_jid) | |
847 # else: | |
848 # wid = self.contact_panel | |
849 # if show == 'unavailable': # XXX: save some resources as for now we only need 'unavailable' | |
850 # for plugin in self.plugins.values(): | |
851 # if hasattr(plugin, 'presenceReceivedTrigger'): | |
852 # plugin.presenceReceivedTrigger(entity_jid, show, priority, statuses) | |
853 # if wid: | |
854 # wid.setConnected(entity_jid.bare, entity_jid.resource, show, priority, statuses) | |
855 | |
856 # def _roomJoinedCb(self, room_jid_s, room_nicks, user_nick): | |
857 # chat_panel = self.getOrCreateRoomWidget(jid.JID(room_jid_s)) | |
858 # chat_panel.setUserNick(user_nick) | |
859 # chat_panel.setPresents(room_nicks) | |
860 # chat_panel.refresh() | |
861 | |
862 # def _roomLeftCb(self, room_jid_s, room_nicks, user_nick): | |
863 # try: | |
864 # del self.room_list[room_jid_s] | |
865 # except KeyError: | |
866 # try: # as JID is a string-based class, we don't know what will please Pyjamas... | |
867 # del self.room_list[jid.JID(room_jid_s)] | |
868 # except KeyError: | |
869 # pass | |
870 | |
871 # def _roomUserJoinedCb(self, room_jid_s, user_nick, user_data): | |
872 # lib_wid = self.getOrCreateRoomWidget(jid.JID(room_jid_s)) | |
873 # if lib_wid: | |
874 # lib_wid.userJoined(user_nick, user_data) | |
875 | |
876 # def _roomUserLeftCb(self, room_jid_s, user_nick, user_data): | |
877 # lib_wid = self.getRoomWidget(jid.JID(room_jid_s)) | |
878 # if lib_wid: | |
879 # lib_wid.userLeft(user_nick, user_data) | |
880 | |
881 # def _roomUserChangedNickCb(self, room_jid_s, old_nick, new_nick): | |
882 # """Called when an user joined a MUC room""" | |
883 # lib_wid = self.getRoomWidget(jid.JID(room_jid_s)) | |
884 # if lib_wid: | |
885 # lib_wid.changeUserNick(old_nick, new_nick) | |
886 | |
887 # def _tarotGameStartedCb(self, waiting, room_jid_s, referee, players): | |
888 # lib_wid = self.getRoomWidget(jid.JID(room_jid_s)) | |
889 # if lib_wid: | |
890 # lib_wid.startGame("Tarot", waiting, referee, players) | |
891 | |
892 # def _tarotGameGenericCb(self, event_name, room_jid_s, args): | |
893 # lib_wid = self.getRoomWidget(jid.JID(room_jid_s)) | |
894 # if lib_wid: | |
895 # getattr(lib_wid.getGame("Tarot"), event_name)(*args) | |
896 | |
897 # def _radioColStartedCb(self, waiting, room_jid_s, referee, players, queue_data): | |
898 # lib_wid = self.getRoomWidget(jid.JID(room_jid_s)) | |
899 # if lib_wid: | |
900 # lib_wid.startGame("RadioCol", waiting, referee, players, queue_data) | |
901 | |
902 # def _radioColGenericCb(self, event_name, room_jid_s, args): | |
903 # lib_wid = self.getRoomWidget(jid.JID(room_jid_s)) | |
904 # if lib_wid: | |
905 # getattr(lib_wid.getGame("RadioCol"), event_name)(*args) | |
906 | |
907 def _getPresenceStatusesCb(self, presence_data): | 638 def _getPresenceStatusesCb(self, presence_data): |
908 for entity in presence_data: | 639 for entity in presence_data: |
909 for resource in presence_data[entity]: | 640 for resource in presence_data[entity]: |
910 args = presence_data[entity][resource] | 641 args = presence_data[entity][resource] |
911 full = ('%s/%s' % (jid.JID(entity).bare, resource)) if resource else entity | 642 full = ('%s/%s' % (jid.JID(entity).bare, resource)) if resource else entity |
948 self.contact_panel.removeContactBox(entity) | 679 self.contact_panel.removeContactBox(entity) |
949 | 680 |
950 def _newContactCb(self, contact_jid, attributes, groups): | 681 def _newContactCb(self, contact_jid, attributes, groups): |
951 self.contact_panel.updateContact(contact_jid, attributes, groups) | 682 self.contact_panel.updateContact(contact_jid, attributes, groups) |
952 | 683 |
953 def _entityDataUpdatedCb(self, entity_jid_s, key, value): | |
954 raise Exception # FIXME should not be here | |
955 if key == "avatar": | |
956 avatar = '/' + C.AVATARS_DIR + value | |
957 self.avatars_cache[entity_jid_s] = avatar | |
958 self.contact_panel.updateAvatar(entity_jid_s, avatar) | |
959 | |
960 for lib_wid in self.libervia_widgets: | |
961 if isinstance(lib_wid, blog.MicroblogPanel): | |
962 if lib_wid.isJidAccepted(entity_jid_s) or (self.whoami and entity_jid_s == self.whoami.bare): | |
963 lib_wid.updateValue('avatar', entity_jid_s, avatar) | |
964 | |
965 # def _chatStateReceivedCb(self, from_jid_s, state): | |
966 # """Callback when a new chat state is received. | |
967 # @param from_jid_s: JID of the contact who sent his state, or '@ALL@' | |
968 # @param state (unicode): new state | |
969 # """ | |
970 # if from_jid_s == '@ALL@': | |
971 # for lib_wid in self.libervia_widgets: | |
972 # if isinstance(lib_wid, panel.ChatPanel): | |
973 # lib_wid.setState(state, nick=C.ALL_OCCUPANTS) | |
974 # return | |
975 # from_jid = jid.JID(from_jid_s) | |
976 # lib_wid = self.getLiberviaWidget(panel.ChatPanel, {'item': from_jid}, ignoreOtherTabs=False) | |
977 # lib_wid.setState(state, nick=from_jid.resource) | |
978 | |
979 def askConfirmationHandler(self, confirmation_id, confirmation_type, data): | 684 def askConfirmationHandler(self, confirmation_id, confirmation_type, data): |
980 answer_data = {} | 685 answer_data = {} |
981 | 686 |
982 def confirm_cb(result): | 687 def confirm_cb(result): |
983 self.bridge.call('confirmationAnswer', None, confirmation_id, result, answer_data) | 688 self.bridge.call('confirmationAnswer', None, confirmation_id, result, answer_data) |
1010 | 715 |
1011 def sendError(self, errorData): | 716 def sendError(self, errorData): |
1012 dialog.InfoDialog("Error while sending message", | 717 dialog.InfoDialog("Error while sending message", |
1013 "Your message can't be sent", Width="400px").center() | 718 "Your message can't be sent", Width="400px").center() |
1014 log.error("sendError: %s" % unicode(errorData)) | 719 log.error("sendError: %s" % unicode(errorData)) |
1015 | |
1016 # FIXME: this method is fat too complicated and depend of widget type | |
1017 # must be refactored and moved to each widget instead | |
1018 # def send(self, targets, text, extra={}): | |
1019 # """Send a message to any target type. | |
1020 # @param targets: list of tuples (type, entities, addr) with: | |
1021 # - type in ("PUBLIC", "GROUP", "COMMENT", "STATUS" , "groupchat" , "chat") | |
1022 # - entities could be a JID, a list groups, a node hash... depending the target | |
1023 # - addr in ("To", "Cc", "Bcc") - ignore case | |
1024 # @param text: the message content | |
1025 # @param extra: options | |
1026 # """ | |
1027 # # FIXME: too many magic strings, we should use constants instead | |
1028 # addresses = [] | |
1029 # for target in targets: | |
1030 # type_, entities, addr = target[0], target[1], 'to' if len(target) < 3 else target[2].lower() | |
1031 # if type_ in ("PUBLIC", "GROUP"): | |
1032 # self.bridge.call("sendMblog", None, type_, entities if type_ == "GROUP" else None, text, extra) | |
1033 # elif type_ == "COMMENT": | |
1034 # self.bridge.call("sendMblogComment", None, entities, text, extra) | |
1035 # elif type_ == "STATUS": | |
1036 # assert(isinstance(self.status_panel, main_panel.PresenceStatusPanel)) | |
1037 # self.bridge.call('setStatus', None, self.status_panel.presence, text) # pylint: disable=E1103 | |
1038 # elif type_ in ("groupchat", "chat"): | |
1039 # addresses.append((addr, entities)) | |
1040 # else: | |
1041 # log.error("Unknown target type") | |
1042 # if addresses: | |
1043 # if len(addresses) == 1 and addresses[0][0] == 'to': | |
1044 # to_jid_s = addresses[0][1] | |
1045 # for plugin in self.plugins.values(): | |
1046 # if hasattr(plugin, 'sendMessageTrigger'): | |
1047 # if not plugin.sendMessageTrigger(jid.JID(to_jid_s), text, type_, extra): | |
1048 # return # plugin returned False to interrupt the process | |
1049 # self.bridge.call('sendMessage', (None, self.sendError), to_jid_s, text, '', type_, extra) | |
1050 # else: | |
1051 # extra.update({'address': '\n'.join([('%s:%s' % entry) for entry in addresses])}) | |
1052 # self.bridge.call('sendMessage', (None, self.sendError), self.whoami.domain, text, '', type_, extra) | |
1053 | 720 |
1054 def showWarning(self, type_=None, msg=None): | 721 def showWarning(self, type_=None, msg=None): |
1055 """Display a popup information message, e.g. to notify the recipient of a message being composed. | 722 """Display a popup information message, e.g. to notify the recipient of a message being composed. |
1056 If type_ is None, a popup being currently displayed will be hidden. | 723 If type_ is None, a popup being currently displayed will be hidden. |
1057 @type_: a type determining the CSS style to be applied (see WarningPopup.showWarning) | 724 @type_: a type determining the CSS style to be applied (see WarningPopup.showWarning) |