Mercurial > libervia-web
changeset 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 | f1271f769ffd |
files | src/browser/libervia_main.py src/browser/sat_browser/chat.py src/browser/sat_browser/contact_list.py src/browser/sat_browser/json.py src/browser/sat_browser/libervia_widget.py |
diffstat | 5 files changed, 1 insertions(+), 408 deletions(-) [+] |
line wrap: on
line diff
--- a/src/browser/libervia_main.py Mon Apr 20 08:51:25 2015 +0200 +++ b/src/browser/libervia_main.py Mon Apr 20 09:14:03 2015 +0200 @@ -71,13 +71,6 @@ MAX_MBLOG_CACHE = 500 # Max microblog entries kept in memories -# Set to true to not create a new LiberviaWidget when a similar one -# already exist (i.e. a chat panel with the same target). Instead -# the existing widget will be eventually removed from its parent -# and added to new libervia_widget.WidgetsPanel, or replaced to the expected -# position if the previous and the new parent are the same. -# REUSE_EXISTING_LIBERVIA_WIDGETS = True # FIXME - class SatWebFrontend(InputHistory, QuickApp): def onModuleLoad(self): @@ -107,8 +100,6 @@ self._versions={} # SàT and Libervia versions cache - # self._selected_listeners = set() # FIXME: to be done with new listeners mechanism - @property def whoami(self): # XXX: works because Libervia is mono-profile @@ -182,9 +173,6 @@ except TypeError: # plugin_sec_otr has not been imported pass - # def addSelectedListener(self, callback): - # self._selected_listeners.add(callback) - def getSelected(self): wid = self.tab_panel.getCurrentPanel() if not isinstance(wid, libervia_widget.WidgetsPanel): @@ -213,10 +201,6 @@ if widget: widgets_panel.selected.addStyleName('selected_widget') - # FIXME: - # for callback in self._selected_listeners: - # callback(widget) - def resize(self): """Resize elements""" Window.onResize() @@ -226,10 +210,6 @@ def onTabSelected(self, sender, tab_index): pass - # selected = self.getSelected() - # FIXME: - # for callback in self._selected_listeners: - # callback(selected) def onEventPreview(self, event): if event.type in ["keydown", "keypress", "keyup"] and event.keyCode == KEY_ESCAPE: @@ -359,13 +339,6 @@ self.bridge_signals.call('getSignals', self.bridge_signals.signalHandler) - #it's time to fill the page - # self.bridge.call('getContacts', self._getContactsCB) - # self.bridge.call('getParamsUI', self._getParamsUICB) - # self.bridge_signals.call('getSignals', self._getSignalsCB) - # #We want to know our own jid - # self.bridge.call('getProfileJid', self._getProfileJidCB) - def domain_cb(value): self._defaultDomain = value log.info(u"new account domain: %s" % value) @@ -375,17 +348,6 @@ self.bridge.getNewAccountDomain(callback=domain_cb, errback=domain_eb) 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. - # self.discuss_panel.addWidget(panel.MicroblogPanel(self, [])) - - # # get cached params and refresh the display - # def param_cb(cat, name, count): - # count[0] += 1 - # refresh = count[0] == len(C.CACHED_PARAMS) - # return lambda value: self._paramUpdate(name, value, cat, refresh) - - # count = [0] # used to do something similar to DeferredList - # for cat, name in C.CACHED_PARAMS: - # self.bridge.call('asyncGetParamA', param_cb(cat, name, count), name, cat) def profilePlugged(self, dummy): # FIXME: to be called as a "profilePlugged" listener? QuickApp.profilePlugged(self, dummy) @@ -541,32 +503,6 @@ self.personalEventHandler(*event_data) del self.init_cache - def _getProfileJidCB(self, jid_s): - # FIXME - raise Exception("should not be here !") - # self.whoami = jid.JID(jid_s) - # #we can now ask our status - # self.bridge.call('getPresenceStatuses', self._getPresenceStatusesCb) - # #the rooms where we are - # self.bridge.call('getRoomsJoined', self._getRoomsJoinedCb) - # #and if there is any subscription request waiting for us - # self.bridge.call('getWaitingSub', self._getWaitingSubCb) - # #we fill the panels already here - # for lib_wid in self.libervia_widgets: - # if isinstance(lib_wid, panel.MicroblogPanel): - # if lib_wid.accept_all(): - # self.bridge.call('getMassiveLastMblogs', lib_wid.massiveInsert, 'ALL', [], 10) - # else: - # self.bridge.call('getMassiveLastMblogs', lib_wid.massiveInsert, 'GROUP', lib_wid.accepted_groups, 10) - - # #we ask for our own microblogs: - # self.loadOurMainEntries() - - # # initialize plugins which waited for the connection to be done - # for plugin in self.plugins.values(): - # if hasattr(plugin, 'profileConnected'): - # plugin.profileConnected() - def loadOurMainEntries(self, index=0, mblog_panel=None): """Load a page of our own blogs from the cache or ask them to the backend. Then fill the panels with them. @@ -650,29 +586,6 @@ if lib_wid.isJidAccepted(entity): self.bridge.call('getMassiveMblogs', lib_wid.massiveInsert, 'JID', [unicode(entity)]) - # def getLiberviaWidget(self, class_, entity, ignoreOtherTabs=True): - # """Get the corresponding panel if it exists. - # @param class_ (class): class of the panel (ChatPanel, MicroblogPanel...) - # @param entity (dict): dictionnary to define the entity. - # @param ignoreOtherTabs (bool): if True, the widgets that are not - # contained by the currently selected tab will be ignored - # @return: the existing widget that has been found or None.""" - # selected_tab = self.tab_panel.getCurrentPanel() - # for lib_wid in self.libervia_widgets: - # parent = lib_wid.getWidgetsPanel(expect=False) - # if parent is None or (ignoreOtherTabs and parent != selected_tab): - # # do not return a widget that is not in the currently selected tab - # continue - # if isinstance(lib_wid, class_): - # try: - # if lib_wid.matchEntity(*(entity.values())): # XXX: passing **entity bugs! - # log.debug("existing widget found: %s" % lib_wid.getDebugName()) - # return lib_wid - # except AttributeError as e: - # e.stack_list() - # return None - # return None - def displayWidget(self, class_, target, dropped=False, new_tab=None, *args, **kwargs): """Get or create a LiberviaWidget and select it. When the user dropped something, a new widget is always created, otherwise we look for an @@ -722,188 +635,6 @@ self.setSelected(wid) return wid - - # def getOrCreateLiberviaWidget(self, class_, entity, select=True, new_tab=None): - # """Get the matching LiberviaWidget if it exists, or create a new one. - # @param class_ (class): class of the panel (ChatPanel, MicroblogPanel...) - # @param entity (dict): dictionnary to define the entity. - # @param select (bool): if True, select the widget that has been found or created - # @param new_tab (unicode): if not None, a widget which is created is created in - # a new tab. In that case new_tab is a unicode to label that new tab. - # If new_tab is not None and a widget is found, no tab is created. - # @return: the newly created wigdet if REUSE_EXISTING_LIBERVIA_WIDGETS - # is set to False or if the widget has not been found, the existing - # widget that has been found otherwise.""" - # lib_wid = None - # tab = None - # if REUSE_EXISTING_LIBERVIA_WIDGETS: - # lib_wid = self.getLiberviaWidget(class_, entity, new_tab is None) - # if lib_wid is None: # create a new widget - # lib_wid = class_.createPanel(self, *(entity.values())) # XXX: passing **entity bugs! - # if new_tab is None: - # self.addWidget(lib_wid) - # else: - # tab = self.addTab(new_tab, lib_wid, False) - # else: # reuse existing widget - # tab = lib_wid.getWidgetsPanel(expect=False) - # if new_tab is None: - # if tab is not None: - # tab.removeWidget(lib_wid) - # self.addWidget(lib_wid) - # if select: - # if new_tab is not None: - # self.tab_panel.selectTab(tab) - # # must be done after the widget is added, - # # for example to scroll to the bottom - # self.setSelected(lib_wid) - # lib_wid.refresh() - # return lib_wid - - # def getRoomWidget(self, target): - # """Get the MUC widget for the given target. - - # @param target (jid.JID): BARE jid of the MUC - # @return: panel.ChatPanel instance or None - # """ - # entity = {'item': target, 'type_': 'group'} - # 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... - # return self.getLiberviaWidget(panel.ChatPanel, entity, ignoreOtherTabs=False) - # return None - - # def getOrCreateRoomWidget(self, target): - # """Get the MUC widget for the given target, create it if necessary. - - # @param target (jid.JID): BARE jid of the MUC - # @return: panel.ChatPanel instance - # """ - # lib_wid = self.getRoomWidget(target) - # if lib_wid: - # return lib_wid - - # # XXX: target.node.startwith(...) raises an error "startswith is not a function" - # # This happens when node a is property defined in the JID class - # # FIXME: pyjamas doesn't handle the properties well - # node = target.node - - # # XXX: it's not really beautiful, but it works :) - # if node.startswith('sat_tarot_'): - # tab_name = "Tarot" - # elif node.startswith('sat_radiocol_'): - # tab_name = "Radio collective" - # else: - # tab_name = target.node - - # self.room_list.append(target) - # entity = {'item': target, 'type_': 'group'} - # return self.getOrCreateLiberviaWidget(panel.ChatPanel, entity, new_tab=tab_name) - - # def _newMessageCb(self, from_jid_s, msg, msg_type, to_jid_s, extra): - # from_jid = jid.JID(from_jid_s) - # to_jid = jid.JID(to_jid_s) - # for plugin in self.plugins.values(): - # if hasattr(plugin, 'messageReceivedTrigger'): - # if not plugin.messageReceivedTrigger(from_jid, msg, msg_type, to_jid, extra): - # return # plugin returned False to interrupt the process - # self.newMessageCb(from_jid, msg, msg_type, to_jid, extra) - - # def newMessageCb(self, from_jid, msg, msg_type, to_jid, extra): - # other = to_jid if from_jid.bare == self.whoami.bare else from_jid - # lib_wid = self.getLiberviaWidget(panel.ChatPanel, {'item': other}, ignoreOtherTabs=False) - # self.displayNotification(from_jid, msg) - # if msg_type == 'headline' and from_jid.full() == self._defaultDomain: - # try: - # assert extra['subject'] # subject is defined and not empty - # title = extra['subject'] - # except (KeyError, AssertionError): - # title = _('Announcement from %s') % from_jid.full() - # msg = strings.addURLToText(html_tools.XHTML2Text(msg)) - # dialog.InfoDialog(title, msg).show() - # return - # if lib_wid is not None: - # if msg_type == C.MESS_TYPE_INFO: - # lib_wid.printInfo(msg) - # else: - # lib_wid.printMessage(from_jid, msg, extra) - # if 'header_info' in extra: - # lib_wid.setHeaderInfo(extra['header_info']) - # else: - # # FIXME: "info" message and header info will be lost here - # if not self.contact_panel.isContactInRoster(other.bare): - # self.contact_panel.updateContact(other.bare, {}, [C.GROUP_NOT_IN_ROSTER]) - # # The message has not been shown, we must indicate it - # self.contact_panel.setContactMessageWaiting(other.bare, True) - - # def _presenceUpdateCb(self, entity, show, priority, statuses): - # entity_jid = jid.JID(entity) - # if self.whoami and self.whoami == entity_jid: # XXX: QnD way to get our presence/status - # assert(isinstance(self.status_panel, main_panel.PresenceStatusPanel)) - # self.status_panel.setPresence(show) # pylint: disable=E1103 - # if statuses: - # self.status_panel.setStatus(statuses.values()[0]) # pylint: disable=E1103 - # else: - # bare_jid = entity_jid.bareJID() - # 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... - # wid = self.getRoomWidget(bare_jid) - # else: - # wid = self.contact_panel - # if show == 'unavailable': # XXX: save some resources as for now we only need 'unavailable' - # for plugin in self.plugins.values(): - # if hasattr(plugin, 'presenceReceivedTrigger'): - # plugin.presenceReceivedTrigger(entity_jid, show, priority, statuses) - # if wid: - # wid.setConnected(entity_jid.bare, entity_jid.resource, show, priority, statuses) - - # def _roomJoinedCb(self, room_jid_s, room_nicks, user_nick): - # chat_panel = self.getOrCreateRoomWidget(jid.JID(room_jid_s)) - # chat_panel.setUserNick(user_nick) - # chat_panel.setPresents(room_nicks) - # chat_panel.refresh() - - # def _roomLeftCb(self, room_jid_s, room_nicks, user_nick): - # try: - # del self.room_list[room_jid_s] - # except KeyError: - # try: # as JID is a string-based class, we don't know what will please Pyjamas... - # del self.room_list[jid.JID(room_jid_s)] - # except KeyError: - # pass - - # def _roomUserJoinedCb(self, room_jid_s, user_nick, user_data): - # lib_wid = self.getOrCreateRoomWidget(jid.JID(room_jid_s)) - # if lib_wid: - # lib_wid.userJoined(user_nick, user_data) - - # def _roomUserLeftCb(self, room_jid_s, user_nick, user_data): - # lib_wid = self.getRoomWidget(jid.JID(room_jid_s)) - # if lib_wid: - # lib_wid.userLeft(user_nick, user_data) - - # def _roomUserChangedNickCb(self, room_jid_s, old_nick, new_nick): - # """Called when an user joined a MUC room""" - # lib_wid = self.getRoomWidget(jid.JID(room_jid_s)) - # if lib_wid: - # lib_wid.changeUserNick(old_nick, new_nick) - - # def _tarotGameStartedCb(self, waiting, room_jid_s, referee, players): - # lib_wid = self.getRoomWidget(jid.JID(room_jid_s)) - # if lib_wid: - # lib_wid.startGame("Tarot", waiting, referee, players) - - # def _tarotGameGenericCb(self, event_name, room_jid_s, args): - # lib_wid = self.getRoomWidget(jid.JID(room_jid_s)) - # if lib_wid: - # getattr(lib_wid.getGame("Tarot"), event_name)(*args) - - # def _radioColStartedCb(self, waiting, room_jid_s, referee, players, queue_data): - # lib_wid = self.getRoomWidget(jid.JID(room_jid_s)) - # if lib_wid: - # lib_wid.startGame("RadioCol", waiting, referee, players, queue_data) - - # def _radioColGenericCb(self, event_name, room_jid_s, args): - # lib_wid = self.getRoomWidget(jid.JID(room_jid_s)) - # if lib_wid: - # getattr(lib_wid.getGame("RadioCol"), event_name)(*args) - def _getPresenceStatusesCb(self, presence_data): for entity in presence_data: for resource in presence_data[entity]: @@ -950,32 +681,6 @@ def _newContactCb(self, contact_jid, attributes, groups): self.contact_panel.updateContact(contact_jid, attributes, groups) - def _entityDataUpdatedCb(self, entity_jid_s, key, value): - raise Exception # FIXME should not be here - if key == "avatar": - avatar = '/' + C.AVATARS_DIR + value - self.avatars_cache[entity_jid_s] = avatar - self.contact_panel.updateAvatar(entity_jid_s, avatar) - - for lib_wid in self.libervia_widgets: - if isinstance(lib_wid, blog.MicroblogPanel): - if lib_wid.isJidAccepted(entity_jid_s) or (self.whoami and entity_jid_s == self.whoami.bare): - lib_wid.updateValue('avatar', entity_jid_s, avatar) - - # def _chatStateReceivedCb(self, from_jid_s, state): - # """Callback when a new chat state is received. - # @param from_jid_s: JID of the contact who sent his state, or '@ALL@' - # @param state (unicode): new state - # """ - # if from_jid_s == '@ALL@': - # for lib_wid in self.libervia_widgets: - # if isinstance(lib_wid, panel.ChatPanel): - # lib_wid.setState(state, nick=C.ALL_OCCUPANTS) - # return - # from_jid = jid.JID(from_jid_s) - # lib_wid = self.getLiberviaWidget(panel.ChatPanel, {'item': from_jid}, ignoreOtherTabs=False) - # lib_wid.setState(state, nick=from_jid.resource) - def askConfirmationHandler(self, confirmation_id, confirmation_type, data): answer_data = {} @@ -1013,44 +718,6 @@ "Your message can't be sent", Width="400px").center() log.error("sendError: %s" % unicode(errorData)) - # FIXME: this method is fat too complicated and depend of widget type - # must be refactored and moved to each widget instead - # def send(self, targets, text, extra={}): - # """Send a message to any target type. - # @param targets: list of tuples (type, entities, addr) with: - # - type in ("PUBLIC", "GROUP", "COMMENT", "STATUS" , "groupchat" , "chat") - # - entities could be a JID, a list groups, a node hash... depending the target - # - addr in ("To", "Cc", "Bcc") - ignore case - # @param text: the message content - # @param extra: options - # """ - # # FIXME: too many magic strings, we should use constants instead - # addresses = [] - # for target in targets: - # type_, entities, addr = target[0], target[1], 'to' if len(target) < 3 else target[2].lower() - # if type_ in ("PUBLIC", "GROUP"): - # self.bridge.call("sendMblog", None, type_, entities if type_ == "GROUP" else None, text, extra) - # elif type_ == "COMMENT": - # self.bridge.call("sendMblogComment", None, entities, text, extra) - # elif type_ == "STATUS": - # assert(isinstance(self.status_panel, main_panel.PresenceStatusPanel)) - # self.bridge.call('setStatus', None, self.status_panel.presence, text) # pylint: disable=E1103 - # elif type_ in ("groupchat", "chat"): - # addresses.append((addr, entities)) - # else: - # log.error("Unknown target type") - # if addresses: - # if len(addresses) == 1 and addresses[0][0] == 'to': - # to_jid_s = addresses[0][1] - # for plugin in self.plugins.values(): - # if hasattr(plugin, 'sendMessageTrigger'): - # if not plugin.sendMessageTrigger(jid.JID(to_jid_s), text, type_, extra): - # return # plugin returned False to interrupt the process - # self.bridge.call('sendMessage', (None, self.sendError), to_jid_s, text, '', type_, extra) - # else: - # extra.update({'address': '\n'.join([('%s:%s' % entry) for entry in addresses])}) - # self.bridge.call('sendMessage', (None, self.sendError), self.whoami.domain, text, '', type_, extra) - def showWarning(self, type_=None, msg=None): """Display a popup information message, e.g. to notify the recipient of a message being composed. If type_ is None, a popup being currently displayed will be hidden.
--- a/src/browser/sat_browser/chat.py Mon Apr 20 08:51:25 2015 +0200 +++ b/src/browser/sat_browser/chat.py Mon Apr 20 09:14:03 2015 +0200 @@ -147,17 +147,6 @@ def plugin_menu_context(self): return (C.MENU_ROOM,) if self.type == C.CHAT_GROUP else (C.MENU_SINGLE,) - # @classmethod - # def createPanel(cls, host, item, type_=C.CHAT_ONE2ONE): - # assert(item) - # _contact = item if isinstance(item, jid.JID) else jid.JID(item) - # host.contact_panel.setContactMessageWaiting(_contact.bare, False) - # _new_panel = Chat(host, _contact, type_) # XXX: pyjamas doesn't seems to support creating with cls directly - # _new_panel.historyPrint() - # host.setSelected(_new_panel) - # _new_panel.refresh() - # return _new_panel - def onKeyDown(self, sender, keycode, modifiers): if keycode == KEY_ENTER: self.host.showWarning(None, None) @@ -214,21 +203,6 @@ self.host.removeListener('presence', self.presenceListener) self.host.bridge.call('mucLeave', None, unicode(self.target.bare)) - # def historyPrint(self, size=C.HISTORY_LIMIT_DEFAULT): - # """Print the initial history""" - # def getHistoryCB(history): - # # display day change - # day_format = "%A, %d %b %Y" - # previous_day = datetime.now().strftime(day_format) - # for line in history: - # timestamp, from_jid_s, to_jid_s, message, mess_type, extra = line - # message_day = datetime.fromtimestamp(float(timestamp or time())).strftime(day_format) - # if previous_day != message_day: - # self.printInfo("* " + message_day) - # previous_day = message_day - # self.printMessage(jid.JID(from_jid_s), message, extra, timestamp) - # self.host.bridge.call('getHistory', getHistoryCB, self.host.whoami.bare, self.target.bare, size, True) - def printInfo(self, msg, type_='normal', extra=None, link_cb=None): """Print general info @param msg: message to print
--- a/src/browser/sat_browser/contact_list.py Mon Apr 20 08:51:25 2015 +0200 +++ b/src/browser/sat_browser/contact_list.py Mon Apr 20 09:14:03 2015 +0200 @@ -233,18 +233,6 @@ if box: box.update() - def hasVisibleMembers(self, group): - """Tell if the given group actually has visible members - - @param group (unicode): the group to check - @return: boolean - """ - raise Exception # FIXME: remove this method - for jid_ in self.groups[group]: - if self._contacts_panel.updateContactBox(jid_).isVisible(): - return True - return False - def offlineContactsToShow(self): """Tell if offline contacts should be visible according to the user settings @@ -265,27 +253,6 @@ if box: # box doesn't exist for MUC bare entity, don't create it box.update() - # def updateVisibility(self, jids, groups): - # """Set the widgets visibility for the given contacts and groups - - # @param jids (list[unicode]): list of JID - # @param groups (list[unicode]): list of groups - # """ - # for jid_s in jids: - # try: - # self._contacts_panel.getContactBox(jid_s).setVisible(jid_s in self.connected or self.offlineContactsToShow()) - # except TypeError: - # log.warning('No box for contact %s: this code line should not be reached' % jid_s) - # for group in groups: - # try: - # self._group_panel.getGroupBox(group).setVisible(self.hasVisibleMembers(group) or self.emtyGroupsToShow()) - # except TypeError: - # log.warning('No box for group %s: this code line should not be reached' % group) - - # def refresh(self): - # """Show or hide disconnected contacts and empty groups""" - # self.updateVisibility(self._contacts_panel.contacts, self.groups.keys()) - class JIDList(list): """JID-friendly list implementation for Pyjamas"""
--- a/src/browser/sat_browser/json.py Mon Apr 20 08:51:25 2015 +0200 +++ b/src/browser/sat_browser/json.py Mon Apr 20 09:14:03 2015 +0200 @@ -126,13 +126,6 @@ except KeyError: pass else: - # if isinstance(_cb, tuple): - # #we have arguments attached to the callback - # #we send them after the answer - # callback, args = _cb - # callback(response, *args) - # else: - # #No additional argument, we call directly the callback _cb(response) del self.cb[request_info.id] @@ -188,6 +181,7 @@ "syntaxConvert", "getAccountDialogUI", "getMainResource", "getWaitingConf", "getEntitiesData", "getVersion", "getLiberviaVersion", "getDefaultMUC", ]) + def __call__(self, *args, **kwargs): return LiberviaJsonProxy.__call__(self, *args, **kwargs)
--- a/src/browser/sat_browser/libervia_widget.py Mon Apr 20 08:51:25 2015 +0200 +++ b/src/browser/sat_browser/libervia_widget.py Mon Apr 20 09:14:03 2015 +0200 @@ -388,15 +388,6 @@ if self._selectable: self.addClickListener(self) - # FIXME - # def onClose(sender): - # """Check dynamically if the unibox is enable or not""" - # if self.host.uni_box: - # self.host.uni_box.onWidgetClosed(sender) - - # self.addCloseListener(onClose) - # self.host.registerWidget(self) # FIXME - @property def plugin_menu_context(self): return self._plugin_menu_context