changeset 944:5d9f6d25c586

browser: various fixes this is a first pass to fix main Libervia features which have been broken with changes in backend: - fixed Chat signature - added/removed/replaced a couple of missing methods - use contact_list_widget instead of contact_list when needed
author Goffi <goffi@goffi.org>
date Fri, 19 May 2017 17:03:04 +0200
parents aacda981c348
children 44dde9b955e8
files src/browser/libervia_main.py src/browser/sat_browser/chat.py src/browser/sat_browser/contact_group.py src/browser/sat_browser/dialog.py src/browser/sat_browser/main_panel.py
diffstat 5 files changed, 46 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/browser/libervia_main.py	Fri May 19 13:54:49 2017 +0200
+++ b/src/browser/libervia_main.py	Fri May 19 17:03:04 2017 +0200
@@ -47,7 +47,7 @@
 from sat_browser import register
 from sat_browser.contact_list import ContactList
 from sat_browser import main_panel
-from sat_browser import chat
+# from sat_browser import chat
 from sat_browser import blog
 from sat_browser import xmlui
 from sat_browser import dialog
@@ -215,10 +215,12 @@
         return True
 
     def onTabSelected(self, sender, tab_index):
-        for widget in self.tab_panel.getCurrentPanel().widgets:
-            if isinstance(widget, chat.Chat):
-                clist = self.contact_list
-                clist.removeAlerts(widget.current_target, True)
+        pass
+    # def onTabSelected(self, sender, tab_index):
+    #     for widget in self.tab_panel.getCurrentPanel().widgets:
+    #         if isinstance(widget, chat.Chat):
+    #             clist = self.contact_list
+    #             clist.removeAlerts(widget.current_target, True)
 
     def onEventPreview(self, event):
         if event.type in ["keydown", "keypress", "keyup"] and event.keyCode == KEY_ESCAPE:
@@ -311,6 +313,20 @@
         # XXX: temp, will be reworked in the backed static blog plugin
         self.menus.addMenu(C.MENU_JID_CONTEXT, (D_(u"User"), D_("Public blog")), callback=main_menu.onPublicBlog)
 
+    def removeListener(self, type_, callback):
+        """Remove a callback from listeners
+
+        @param type_: same as for [addListener]
+        @param callback: callback to remove
+        """
+        # FIXME: workaround for pyjamas
+        #        check KeyError issue
+        assert type_ in C.LISTENERS
+        try:
+            self._listeners[type_].pop(callback)
+        except KeyError:
+            pass
+
     def _getSessionMetadataCB(self, metadata):
         if not metadata['plugged']:
             warning = metadata.get("warning")
@@ -357,6 +373,7 @@
         self._profile_plugged = True
         QuickApp.profilePlugged(self, C.PROF_KEY_NONE)
         contact_list = self.widgets.getOrCreateWidget(ContactList, None, on_new_widget=None, profile=C.PROF_KEY_NONE)
+        self.contact_list_widget = contact_list
         self.panel.addContactList(contact_list)
 
         # FIXME: the contact list height has to be set manually the first time
--- a/src/browser/sat_browser/chat.py	Fri May 19 13:54:49 2017 +0200
+++ b/src/browser/sat_browser/chat.py	Fri May 19 17:03:04 2017 +0200
@@ -94,14 +94,14 @@
 
 class Chat(QuickChat, libervia_widget.LiberviaWidget, KeyboardHandler):
 
-    def __init__(self, host, target, type_=C.CHAT_ONE2ONE, profiles=None):
+    def __init__(self, host, target, type_=C.CHAT_ONE2ONE, nick=None, occupants=None, subject=None, profiles=None):
         """Panel used for conversation (one 2 one or group chat)
 
         @param host: SatWebFrontend instance
         @param target: entity (jid.JID) with who we have a conversation (contact's jid for one 2 one chat, or MUC room)
         @param type: one2one for simple conversation, group for MUC
         """
-        QuickChat.__init__(self, host, target, type_, profiles=profiles)
+        QuickChat.__init__(self, host, target, type_, nick, occupants, subject, profiles=profiles)
         self.vpanel = VerticalPanel()
         self.vpanel.setSize('100%', '100%')
 
@@ -127,6 +127,9 @@
             host.addListener('avatar', self.avatarListener, [C.PROF_KEY_NONE])
             Window.addWindowResizeListener(self)
 
+        else:
+            self.chat_state = None
+
         self._body.add(chat_area)
         self.content = AbsolutePanel()
         self.content.setStyleName('chatContent')
@@ -283,14 +286,19 @@
             title += ' %s' % extra
         libervia_widget.LiberviaWidget.setTitle(self, title)
 
+    def onChatState(self, from_jid, state, profile):
+        super(Chat, self).onChatState(from_jid, state, profile)
+        if self.type == C.CHAT_ONE2ONE:
+            self.title_dynamic = C.CHAT_STATE_ICON[state]
+
     def update(self, entity=None):
         """Update one or all entities.
 
         @param entity (jid.JID): entity to update
         """
-        states = self.getEntityStates(self.target)
         if self.type == C.CHAT_ONE2ONE:  # only update the chat title
-            self.setTitle(extra=' '.join([u'({})'.format(value) for value in states.values()]))
+            if self.chat_state:
+                self.setTitle(extra='({})'.format(self.chat_state))
         else:
             if entity is None:  # rebuild all the occupants list
                 nicks = list(self.occupants)
@@ -302,11 +310,14 @@
                 if show == C.PRESENCE_UNAVAILABLE or show is None:
                     self.occupants_panel.removeContactBox(entity)
                 else:
-                    box = self.occupants_panel.updateContactBox(entity)
-                    box.states.setHTML(u''.join(states.values()))
+                    pass
+                    # FIXME: legacy code, chat state must be checked
+                    # box = self.occupants_panel.updateContactBox(entity)
+                    # box.states.setHTML(u''.join(states.values()))
 
-        if 'chat_state' in states.keys():  # start/stop sending "composing" state from now
-            self.chat_state_machine.started = not not states['chat_state']
+        # FIXME: legacy code, chat state must be checked
+        # if 'chat_state' in states.keys():  # start/stop sending "composing" state from now
+        #     self.chat_state_machine.started = not not states['chat_state']
 
         self.onWindowResized()  # be sure to set the good height
 
--- a/src/browser/sat_browser/contact_group.py	Fri May 19 13:54:49 2017 +0200
+++ b/src/browser/sat_browser/contact_group.py	Fri May 19 17:03:04 2017 +0200
@@ -90,7 +90,7 @@
         self.container = container
         self._on_close_callback = onCloseCallback
 
-        self.all_contacts = contact_list.JIDList(self.host.contact_list.roster_entities)
+        self.all_contacts = contact_list.JIDList(self.host.contact_list.roster)
         roster_entities_by_group = self.host.contact_list.roster_entities_by_group
         del roster_entities_by_group[None]  # remove the empty group
         roster_groups = roster_entities_by_group.keys()
@@ -126,7 +126,7 @@
 
         # Hide the contacts list from the main panel to not confuse the user
         self.restore_contact_panel = False
-        clist = self.host.contact_list
+        clist = self.host.contact_list_widget
         if clist.getVisible():
             self.restore_contact_panel = True
             self.host.panel._contactsSwitch()
@@ -168,7 +168,7 @@
 
     def initContactList(self):
         """Add the contact list to the DockPanel."""
-        
+
         self.toggle = CheckBox("Hide assigned contacts")
         self.toggle.addClickListener(lambda dummy: self.updateContactList())
         self.toggle.addStyleName("toggleAssignedContacts")
--- a/src/browser/sat_browser/dialog.py	Fri May 19 13:54:49 2017 +0200
+++ b/src/browser/sat_browser/dialog.py	Fri May 19 17:03:04 2017 +0200
@@ -178,7 +178,7 @@
         """
         selection = self.contacts if keep_selected else []
         self.contacts_list.clear()
-        contacts = self.host.contact_list.roster_entities_connected
+        contacts = self.host.contact_list.roster_connected
         self.contacts_list.setVisibleItemCount(10 if len(contacts) > 5 else 5)
         self.contacts_list.addItem("")
         for contact in contacts:
--- a/src/browser/sat_browser/main_panel.py	Fri May 19 13:54:49 2017 +0200
+++ b/src/browser/sat_browser/main_panel.py	Fri May 19 17:03:04 2017 +0200
@@ -297,7 +297,7 @@
         """ (Un)hide contacts panel """
         if btn is None:
             btn = self.contacts_switch
-        clist = self.host.contact_list
+        clist = self.host.contact_list_widget
         clist.setVisible(not clist.getVisible())
         btn.setText(u"«" if clist.getVisible() else u"»")
         self.host.resize()
@@ -312,6 +312,3 @@
                 return
             self._contacts.removeFromParent()
         parent.insert(self._contacts, 0)
-
-
-