changeset 696:c2f22ca12e23

browser and server side: remove unibox
author souliane <souliane@mailoo.org>
date Mon, 20 Apr 2015 08:51:25 +0200
parents e86490a7c76e
children b395d1309936
files src/browser/libervia_main.py src/browser/public/libervia.css src/browser/sat_browser/chat.py src/browser/sat_browser/constants.py src/browser/sat_browser/contact_list.py src/browser/sat_browser/editor_widget.py src/browser/sat_browser/main_panel.py src/browser/sat_browser/widget.py src/common/constants.py src/server/server.py
diffstat 10 files changed, 17 insertions(+), 367 deletions(-) [+]
line wrap: on
line diff
--- a/src/browser/libervia_main.py	Sun Apr 19 13:10:41 2015 +0200
+++ b/src/browser/libervia_main.py	Mon Apr 20 08:51:25 2015 +0200
@@ -84,7 +84,6 @@
         log.info("============ onModuleLoad ==============")
         self.bridge_signals = json.BridgeSignals(self)
         QuickApp.__init__(self, json.BridgeCall)
-        self.uni_box = None # FIXME: to be removed
         self.panel = main_panel.MainPanel(self)
         self.tab_panel = self.panel.tab_panel
         self.tab_panel.addTabListener(self)
--- a/src/browser/public/libervia.css	Sun Apr 19 13:10:41 2015 +0200
+++ b/src/browser/public/libervia.css	Mon Apr 20 08:51:25 2015 +0200
@@ -600,28 +600,6 @@
     margin: 0px;
 }
 
-/* UniBox & Status */
-
-.uniBoxPanel {
-    margin: 15px 22px 0 22px;
-}
-
-.uniBox {
-    width: 100%;
-    height: 45px;
-    padding: 5px;
-    border: 1px solid #bbb;
-    color: #444;
-    background: #fff url('media/libervia/unibox_2.png') top right no-repeat;    
-    -webkit-box-shadow:inset 0 0 10px #ddd;    
-    box-shadow:inset 0 0 10px #ddd;
-}
-
-.uniBoxButton {
-    width:30px;
-    height:45px;
-}
-
 .presenceStatusPanel {
     margin: auto;
     text-align: center;
@@ -1259,9 +1237,6 @@
 /* Misc */
 
 .selected_widget .widgetHeader  {
-    /* this property is set when a widget is the current target of the uniBox
-     * (messages entered in unibox will be sent to this widget)
-     */
     background-color: #cf2828;
     background: -webkit-gradient(linear, left top, left bottom, from(#cf2828), to(#981a1a));
     background: -webkit-linear-gradient(top, #cf2828, #981a1a);
--- a/src/browser/sat_browser/chat.py	Sun Apr 19 13:10:41 2015 +0200
+++ b/src/browser/sat_browser/chat.py	Mon Apr 20 08:51:25 2015 +0200
@@ -119,7 +119,12 @@
         self.addStyleName('chatPanel')
         self.setWidget(self.vpanel)
         self.chat_state_machine = plugin_xep_0085.ChatStateMachine(self.host, unicode(self.target))
-        self.refresh()
+
+        self.message_box = editor_widget.MessageBox(self.host)
+        self.message_box.onSelectedChange(self)
+        self.message_box.addKeyboardListener(self)
+        self.vpanel.add(self.message_box)
+
         if type_ == C.CHAT_ONE2ONE:
             self.historyPrint(profile=self.profile)
 
@@ -153,22 +158,6 @@
     #     _new_panel.refresh()
     #     return _new_panel
 
-    def refresh(self):  # FIXME: not needed anymore since unibox has been removed
-        """Refresh the display of this widget. If the unibox is disabled,
-        add a message box at the bottom of the panel"""
-        # FIXME: must be checked
-        # self.host.contact_panel.setContactMessageWaiting(self.target.bare, False)
-        # self.content_scroll.scrollToBottom()
-
-        enable_box = self.host.uni_box is None
-        if hasattr(self, 'message_box'):
-            self.message_box.setVisible(enable_box)
-        elif enable_box:
-            self.message_box = editor_widget.MessageBox(self.host)
-            self.message_box.onSelectedChange(self)
-            self.message_box.addKeyboardListener(self)
-            self.vpanel.add(self.message_box)
-
     def onKeyDown(self, sender, keycode, modifiers):
         if keycode == KEY_ENTER:
             self.host.showWarning(None, None)
--- a/src/browser/sat_browser/constants.py	Sun Apr 19 13:10:41 2015 +0200
+++ b/src/browser/sat_browser/constants.py	Mon Apr 20 08:51:25 2015 +0200
@@ -30,8 +30,7 @@
     # Cached parameters, e.g those that have an incidence on UI display/refresh:
     #     - they can be any parameter (not necessarily specific to Libervia)
     #     - list them as a couple (category, name)
-    CACHED_PARAMS = [(C.COMPOSITION_KEY, C.ENABLE_UNIBOX_PARAM),
-                     ('General', C.SHOW_OFFLINE_CONTACTS),
+    CACHED_PARAMS = [('General', C.SHOW_OFFLINE_CONTACTS),
                      ('General', C.SHOW_EMPTY_GROUPS),
                      ]
 
--- a/src/browser/sat_browser/contact_list.py	Sun Apr 19 13:10:41 2015 +0200
+++ b/src/browser/sat_browser/contact_list.py	Mon Apr 20 08:51:25 2015 +0200
@@ -184,112 +184,6 @@
             ideal_height -= tab_panel.getTabBar().getOffsetHeight()
         self.scroll_panel.setHeight("%s%s" % (ideal_height, "px"))
 
-    # def updateContact(self, jid_s, attributes, groups):
-    #     """Add a contact to the panel if it doesn't exist, update it else
-
-    #     @param jid_s: jid userhost as unicode
-    #     @param attributes: cf SàT Bridge API's newContact
-    #     @param groups: list of groups"""
-    #     _current_groups = self.getContactGroups(jid_s)
-    #     _new_groups = set(groups)
-    #     _key = "@%s: "
-
-    #     for group in _current_groups.difference(_new_groups):
-    #         # We remove the contact from the groups where he isn't anymore
-    #         self.groups[group].remove(jid_s)
-    #         if not self.groups[group]:
-    #             # The group is now empty, we must remove it
-    #             del self.groups[group]
-    #             self._group_panel.remove(group)
-    #             if self.host.uni_box:
-    #                 self.host.uni_box.removeKey(_key % group)
-
-    #     for group in _new_groups.difference(_current_groups):
-    #         # We add the contact to the groups he joined
-    #         if group not in self.groups.keys():
-    #             self.groups[group] = set()
-    #             self._group_panel.add(group)
-    #             if self.host.uni_box:
-    #                 self.host.uni_box.addKey(_key % group)
-    #         self.groups[group].add(jid_s)
-
-    #     # We add the contact to contact list, it will check if contact already exists
-    #     self._contacts_panel.add(jid_s)
-    #     self.updateVisibility([jid_s], self.getContactGroups(jid_s))
-
-    # def removeContact(self, jid):
-    #     """Remove contacts from groups where he is and contact list"""
-    #     self.updateContact(jid, {}, [])  # we remove contact from every group
-    #     self._contacts_panel.remove(jid)
-
-    # def setConnected(self, jid_s, resource, availability, priority, statuses):
-    #     """Set connection status
-    #     @param jid_s (unicode): JID userhost as unicode
-    #     """
-    #     if availability == 'unavailable':
-    #         if jid_s in self.connected:
-    #             if resource in self.connected[jid_s]:
-    #                 del self.connected[jid_s][resource]
-    #             if not self.connected[jid_s]:
-    #                 del self.connected[jid_s]
-    #     else:
-    #         if jid_s not in self.connected:
-    #             self.connected[jid_s] = {}
-    #         self.connected[jid_s][resource] = (availability, priority, statuses)
-
-    #     # check if the contact is connected with another resource, use the one with highest priority
-    #     if jid_s in self.connected:
-    #         max_resource = max_priority = None
-    #         for tmp_resource in self.connected[jid_s]:
-    #             if max_priority is None or self.connected[jid_s][tmp_resource][1] >= max_priority:
-    #                 max_resource = tmp_resource
-    #                 max_priority = self.connected[jid_s][tmp_resource][1]
-    #         if availability == "unavailable":  # do not check the priority here, because 'unavailable' has a dummy one
-    #             priority = max_priority
-    #             availability = self.connected[jid_s][max_resource][0]
-    #     if jid_s not in self.connected or priority >= max_priority:
-    #         # case 1: jid not in self.connected means all resources are disconnected, update with 'unavailable'
-    #         # case 2: update (or confirm) with the values of the resource which takes precedence
-    #         self._contacts_panel.setState(jid_s, "availability", availability)
-
-    #     self.updateVisibility([jid_s], self.getContactGroups(jid_s))
-
-    def setContactMessageWaiting(self, jid, waiting):
-        """Show a visual indicator that contact has send a message
-
-        @param jid: jid of the contact
-        @param waiting: True if message are waiting"""
-        raise Exception("Should not be there")
-        # self._contacts_panel.setState(jid, "messageWaiting", waiting)
-
-    # def getConnected(self, filter_muc=False):
-    #     """return a list of all jid (bare jid) connected
-    #     @param filter_muc: if True, remove the groups from the list
-    #     """
-    #     contacts = self.connected.keys()
-    #     contacts.sort()
-    #     return contacts if not filter_muc else list(set(contacts).intersection(set(self.getContacts())))
-
-    # def getContactGroups(self, contact_jid_s):
-    #     """Get groups where contact is
-    #    @param group: string of single group, or list of string
-    #    @param contact_jid_s: jid to test, as unicode
-    #     """
-    #     result = set()
-    #     for group in self.groups:
-    #         if self.isContactInGroup(group, contact_jid_s):
-    #             result.add(group)
-    #     return result
-
-    # def isContactInGroup(self, group, contact_jid):
-    #     """Test if the contact_jid is in the group
-    #     @param group: string of single group, or list of string
-    #     @param contact_jid: jid to test
-    #     @return: True if contact_jid is in on of the groups"""
-    #     if group in self.groups and contact_jid in self.groups[group]:
-    #         return True
-    #     return False
-
     def isContactInRoster(self, contact_jid):
         """Test if the contact is in our roster list"""
         for contact_box in self._contacts_panel:
@@ -297,9 +191,6 @@
                 return True
         return False
 
-    # def getContacts(self):
-    #     return self._contacts_panel.getContacts()
-
     def getGroups(self):
         return self.groups.keys()
 
--- a/src/browser/sat_browser/editor_widget.py	Sun Apr 19 13:10:41 2015 +0200
+++ b/src/browser/sat_browser/editor_widget.py	Mon Apr 20 08:51:25 2015 +0200
@@ -171,27 +171,21 @@
 
         return diff(content, self._original_content)
 
-    def edit(self, edit, abort=False, sync=False):
+    def edit(self, edit, abort=False):
         """
         Remark: the editor must be visible before you call this method.
         @param edit: set to True to edit the content or False to only display it
         @param abort: set to True to cancel the edition and loose the changes.
         If edit and abort are both True, self.abortEdition can be used to ask for a
         confirmation. When edit is False and abort is True, abortion is actually done.
-        @param sync: set to True to cancel the edition after the content has been saved somewhere else
         """
         if edit:
-            if not self.initialized:
-                self.syncToEditor()  # e.g.: use the selected target and unibox content
             self.setFocus(True)
             if abort:
                 content = self.getContent()
                 if not self.modified(content) or self.abortEdition(content):  # e.g: ask for confirmation
-                    self.edit(False, True, sync)
+                    self.edit(False, True)
                     return
-            if sync:
-                self.syncFromEditor(content)  # e.g.: save the content to unibox
-                return
         else:
             if not self.initialized:
                 return
@@ -217,12 +211,6 @@
         """
         raise NotImplementedError
 
-    def syncToEditor(self):
-        pass
-
-    def syncFromEditor(self, content):
-        pass
-
     def abortEdition(self, content):
         return True
 
@@ -271,7 +259,7 @@
     def getContent(self):
         raise NotImplementedError
 
-    def edit(self, edit, abort=False, sync=False):
+    def edit(self, edit, abort=False):
         BaseTextEditor.edit(self, edit)
         if edit:
             if self.options['listen_focus'] and self not in self.textarea._focusListeners:
@@ -352,11 +340,11 @@
         text = DOM.getInnerHTML(self.getElement())
         return {'text': self.strproc(text) if text else ''}
 
-    def edit(self, edit, abort=False, sync=False):
+    def edit(self, edit, abort=False):
         if edit:
             self.textarea.setHTML(self._original_content['text'])
         self.getElement().setAttribute('contenteditable', 'true' if edit else 'false')
-        SimpleTextEditor.edit(self, edit, abort, sync)
+        SimpleTextEditor.edit(self, edit, abort)
 
     def setFocus(self, focus):
         if focus:
@@ -378,11 +366,11 @@
         text = self.textarea.getText()
         return {'text': self.strproc(text) if text else ''}
 
-    def edit(self, edit, abort=False, sync=False):
+    def edit(self, edit, abort=False):
         if edit:
             self.textarea.setText(self._original_content['text'])
         self.setWidget(self.textarea if edit else self.display)
-        SimpleTextEditor.edit(self, edit, abort, sync)
+        SimpleTextEditor.edit(self, edit, abort)
 
     def setFocus(self, focus):
         if focus and self.isAttached():
--- a/src/browser/sat_browser/main_panel.py	Sun Apr 19 13:10:41 2015 +0200
+++ b/src/browser/sat_browser/main_panel.py	Mon Apr 20 08:51:25 2015 +0200
@@ -81,7 +81,7 @@
         if type_ == "NONE":
             return
         if not msg:
-            log.warning("no msg set uniBox warning")
+            log.warning("no msg set")
             return
         if type_ == "PUBLIC":
             style = "targetPublic"
@@ -296,7 +296,6 @@
 
     def refresh(self):
         """Refresh the main panel"""
-        self.unibox_panel.refresh()
         self.host.contact_panel.refresh()
 
 
--- a/src/browser/sat_browser/widget.py	Sun Apr 19 13:10:41 2015 +0200
+++ b/src/browser/sat_browser/widget.py	Mon Apr 20 08:51:25 2015 +0200
@@ -37,178 +37,6 @@
 from sat_frontends.tools import host_listener
 
 
-# class UniBoxPanel(HorizontalPanel):
-#     """Panel containing the UniBox"""
-#
-#     def __init__(self, host):
-#         HorizontalPanel.__init__(self)
-#         self.host = host
-#         self.setStyleName('uniBoxPanel')
-#         self.unibox = None
-#
-#     def refresh(self):
-#         """Enable or disable this panel. Contained widgets are created when necessary."""
-#         enable = self.host.getCachedParam(C.COMPOSITION_KEY, C.ENABLE_UNIBOX_PARAM) == 'true'
-#         self.setVisible(enable)
-#         if enable and not self.unibox:
-#             self.button = Button('<img src="media/icons/tango/actions/32/format-text-italic.png" class="richTextIcon"/>')
-#             self.button.setTitle('Open the rich text editor')
-#             self.button.addStyleName('uniBoxButton')
-#             self.add(self.button)
-#             self.unibox = UniBox(self.host)
-#             self.add(self.unibox)
-#             self.setCellWidth(self.unibox, '100%')
-#             self.button.addClickListener(self.openRichMessageEditor)
-#             self.unibox.addKey("@@: ")
-#             self.unibox.onSelectedChange(self.host.getSelected())
-#
-#     def openRichMessageEditor(self):
-#         """Open the rich text editor."""
-#         self.button.setVisible(False)
-#         self.unibox.setVisible(False)
-#         self.setCellWidth(self.unibox, '0px')
-#         self.host.panel._contactsMove(self)
-#
-#         def afterEditCb():
-#             Window.removeWindowResizeListener(self)
-#             self.host.panel._contactsMove(self.host.panel._hpanel)
-#             self.setCellWidth(self.unibox, '100%')
-#             self.button.setVisible(True)
-#             self.unibox.setVisible(True)
-#             self.host.resize()
-#
-#         richtext.RichMessageEditor.getOrCreate(self.host, self, afterEditCb)
-#         Window.addWindowResizeListener(self)
-#         self.host.resize()
-#
-#     def onWindowResized(self, width, height):
-#         right = self.host.panel.menu.getAbsoluteLeft() + self.host.panel.menu.getOffsetWidth()
-#         left = self.host.panel._contacts.getAbsoluteLeft() + self.host.panel._contacts.getOffsetWidth()
-#         ideal_width = right - left - 40
-#         self.host.richtext.setWidth("%spx" % ideal_width)
-
-
-
-# class UniBox(MessageBox, MouseHandler):  # AutoCompleteTextBox):
-#     """This text box is used as a main typing point, for message, microblog, etc"""
-#
-#     def __init__(self, host):
-#         MessageBox.__init__(self, host)
-#         #AutoCompleteTextBox.__init__(self)
-#         self.setStyleName('uniBox')
-#         # FIXME
-#         # host.addSelectedListener(self.onSelectedChange)
-#
-#     def addKey(self, key):
-#         return
-#         #self.getCompletionItems().completions.append(key)
-#
-#     def removeKey(self, key):
-#         return
-#         # TODO: investigate why AutoCompleteTextBox doesn't work here,
-#         # maybe it can work on a TextBox but no TextArea. Remove addKey
-#         # and removeKey methods if they don't serve anymore.
-#         try:
-#             self.getCompletionItems().completions.remove(key)
-#         except KeyError:
-#             log.warning("trying to remove an unknown key")
-#
-#     def _getTarget(self, txt):
-#         """ Say who will receive the messsage
-#         @return: a tuple (selected, target_type, target info) with:
-#             - target_hook: None if we use the selected widget, (msg, data) if we have a hook (e.g. "@@: " for a public blog), where msg is the parsed message (i.e. without the "hook key: "@@: bla" become ("bla", None))
-#             - target_type: one of PUBLIC, GROUP, ONE2ONE, STATUS, MISC
-#             - msg: HTML message which will appear in the privacy warning banner """
-#         target = self._selected_cache
-#
-#         def getSelectedOrStatus():
-#             if target and target.isSelectable():
-#                 _type, msg = target.getWarningData()
-#                 target_hook = None  # we use the selected widget, not a hook
-#             else:
-#                 _type, msg = "STATUS", "This will be your new status message"
-#                 target_hook = (txt, None)
-#             return (target_hook, _type, msg)
-#
-#         if not txt.startswith('@'):
-#             target_hook, _type, msg = getSelectedOrStatus()
-#         elif txt.startswith('@@: '):
-#             _type = "PUBLIC"
-#             msg = MicroblogPanel.warning_msg_public
-#             target_hook = (txt[4:], None)
-#         elif txt.startswith('@'):
-#             _end = txt.find(': ')
-#             if _end == -1:
-#                 target_hook, _type, msg = getSelectedOrStatus()
-#             else:
-#                 group = txt[1:_end]  # only one target group is managed for the moment
-#                 if not group or not group in self.host.contact_panel.getGroups():
-#                     # the group doesn't exists, we ignore the key
-#                     group = None
-#                     target_hook, _type, msg = getSelectedOrStatus()
-#                 else:
-#                     _type = "GROUP"
-#                     msg = MicroblogPanel.warning_msg_group % group
-#                     target_hook = (txt[_end + 2:], group)
-#         else:
-#             log.error("Unknown target")
-#             target_hook, _type, msg = getSelectedOrStatus()
-#
-#         return (target_hook, _type, msg)
-#
-#     def onKeyPress(self, sender, keycode, modifiers):
-#         _txt = self.getText()
-#         target_hook, type_, msg = self._getTarget(_txt)
-#
-#         if keycode == KEY_ENTER:
-#             if _txt:
-#                 if target_hook:
-#                     parsed_txt, data = target_hook
-#                     self.host.send([(type_, data)], parsed_txt)
-#                     self.host._updateInputHistory(_txt)
-#                     self.setText('')
-#             self.host.showWarning(None, None)
-#         else:
-#             self.host.showWarning(type_, msg)
-#         MessageBox.onKeyPress(self, sender, keycode, modifiers)
-#
-#     def getTargetAndData(self):
-#         """For external use, to get information about the (hypothetical) message
-#         that would be sent if we press Enter right now in the unibox.
-#         @return a tuple (target, data) with:
-#           - data: what would be the content of the message (body)
-#           - target: JID, group with the prefix "@" or the public entity "@@"
-#         """
-#         _txt = self.getText()
-#         target_hook, _type, _msg = self._getTarget(_txt)
-#         if target_hook:
-#             data, target = target_hook
-#             if target is None:
-#                 return target_hook
-#             return (data, "@%s" % (target if target != "" else "@"))
-#         if isinstance(self._selected_cache, MicroblogPanel):
-#             groups = self._selected_cache.accepted_groups
-#             target = "@%s" % (groups[0] if len(groups) > 0 else "@")
-#             if len(groups) > 1:
-#                 Window.alert("Sole the first group of the selected panel is taken in consideration: '%s'" % groups[0])
-#         # elif isinstance(self._selected_cache, ChatPanel): # FIXME
-#         #     target = self._selected_cache.target
-#         else:
-#             target = None
-#         return (_txt, target)
-#
-#     def onWidgetClosed(self, lib_wid):
-#         """Called when a libervia widget is closed"""
-#         if self._selected_cache == lib_wid:
-#             self.onSelectedChange(None)
-#
-#     """def complete(self):
-#
-#         #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done
-#         #XXX: fixed directly on pyjamas, if the patch is accepted, no need to walk around this
-#         return AutoCompleteTextBox.complete(self)"""
-
-
 class WebWidget(quick_widgets.QuickWidget, libervia_widget.LiberviaWidget):
     """ (mini)browser like widget """
 
--- a/src/common/constants.py	Sun Apr 19 13:10:41 2015 +0200
+++ b/src/common/constants.py	Mon Apr 20 08:51:25 2015 +0200
@@ -26,10 +26,6 @@
 
     LIBERVIA_MAIN_PAGE = "libervia.html"
 
-    # Frontend parameters
-    COMPOSITION_KEY = D_("Composition")
-    ENABLE_UNIBOX_PARAM = D_("Enable unibox")
-
     # MISC
     PASSWORD_MIN_LENGTH = 6  # for new account creation
 
--- a/src/server/server.py	Sun Apr 19 13:10:41 2015 +0200
+++ b/src/server/server.py	Mon Apr 20 08:51:25 2015 +0200
@@ -838,22 +838,8 @@
 
     def jsonrpc_registerParams(self):
         """Register the frontend specific parameters"""
-        params = """
-        <params>
-        <individual>
-        <category name="%(category_name)s" label="%(category_label)s">
-            <param name="%(enable_unibox)s" label="%(enable_unibox_label)s" value="false" type="bool" security="0"/>
-         </category>
-        </individual>
-        </params>
-        """ % {
-            'category_name': C.COMPOSITION_KEY,
-            'category_label': _(C.COMPOSITION_KEY),
-            'enable_unibox': C.ENABLE_UNIBOX_PARAM,
-            'enable_unibox_label': _(C.ENABLE_UNIBOX_PARAM),
-        }
-
-        self.sat_host.bridge.paramsRegisterApp(params, C.SECURITY_LIMIT, C.APP_NAME)
+        # params = """<params><individual>...</category></individual>"""
+        # self.sat_host.bridge.paramsRegisterApp(params, C.SECURITY_LIMIT, C.APP_NAME)
 
     def jsonrpc_getMenus(self):
         """Return the parameters XML for profile"""