# HG changeset patch # User souliane # Date 1388354848 -3600 # Node ID 05e264e96a1ce00ac18b10516e00d7453135f654 # Parent 0ca441ba4317909ff5e8e601a9033f9d64ac73e0 browser_side: make unibox optional diff -r 0ca441ba4317 -r 05e264e96a1c browser_side/base_widget.py --- a/browser_side/base_widget.py Fri Dec 27 13:59:06 2013 +0100 +++ b/browser_side/base_widget.py Sun Dec 29 23:07:28 2013 +0100 @@ -184,7 +184,13 @@ self.addStyleName('widget') if self.__selectable: self.addClickListener(self) - self.addCloseListener(self.host.uni_box.onWidgetClosed) + + 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) def getDebugName(self): diff -r 0ca441ba4317 -r 05e264e96a1c browser_side/contact.py --- a/browser_side/contact.py Fri Dec 27 13:59:06 2013 +0100 +++ b/browser_side/contact.py Sun Dec 29 23:07:28 2013 +0100 @@ -270,14 +270,16 @@ # The group is now empty, we must remove it del self.groups[group] self._groupList.remove(group) - self.host.uni_box.removeKey(_key % 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 not group in self.groups.keys(): self.groups[group] = set() self._groupList.add(group) - self.host.uni_box.addKey(_key % group) + if self.host.uni_box: + self.host.uni_box.addKey(_key % group) self.groups[group].add(jid) # We add the contact to contact list, it will check if contact already exists diff -r 0ca441ba4317 -r 05e264e96a1c browser_side/panels.py --- a/browser_side/panels.py Fri Dec 27 13:59:06 2013 +0100 +++ b/browser_side/panels.py Sun Dec 29 23:07:28 2013 +0100 @@ -71,17 +71,26 @@ HorizontalPanel.__init__(self) self.host = host self.setStyleName('uniBoxPanel') - - self.button = Button ('') - self.button.setTitle('Open the rich text editor') - self.button.addStyleName('uniBoxButton') - self.add(self.button) + self.unibox = None - self.unibox = UniBox(host) - self.add(self.unibox) - self.setCellWidth(self.unibox, '100%') - - self.button.addClickListener(self.openRichTextEditor) + def setUniBox(self, enable): + """Enable or disable the unibox widget. + @param enable: boolean + """ + if enable: + self.button = Button ('') + 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.openRichTextEditor) + self.unibox.addKey("@@: ") + else: + if self.unibox: + self.remove(self.unibox) + self.unibox = None def openRichTextEditor(self): """Open the rich text editor.""" @@ -365,7 +374,7 @@ self.comments = mblog_entry.comments self.pub_data = (mblog_entry.hash[0], mblog_entry.hash[1], mblog_entry.id) - self.editable_content = [mblog_entry.xhtml, const._SYNTAX_XHTML] if mblog_entry.xhtml else [mblog_entry.content, None] + self.editable_content = [mblog_entry.xhtml, const.SYNTAX_XHTML] if mblog_entry.xhtml else [mblog_entry.content, None] self.panel = FlowPanel() self.panel.setStyleName('mb_entry') @@ -1148,8 +1157,7 @@ self.menu = Menu(host) # unibox - unibox_panel = UniBoxPanel(host) - self.host.setUniBox(unibox_panel.unibox) + self.unibox_panel = UniBoxPanel(host) # status bar status = host.status_panel @@ -1170,7 +1178,7 @@ header = AbsolutePanel() header.add(self.menu) - header.add(unibox_panel) + header.add(self.unibox_panel) header.add(status) header.setStyleName('header') self.add(header) diff -r 0ca441ba4317 -r 05e264e96a1c browser_side/richtext.py --- a/browser_side/richtext.py Fri Dec 27 13:59:06 2013 +0100 +++ b/browser_side/richtext.py Sun Dec 29 23:07:28 2013 +0100 @@ -71,6 +71,7 @@ self._parent = parent self._on_close_callback = onCloseCallback + self.original_text = '' if not self.no_recipient: # recipient types sub-panels are automatically added by the manager @@ -209,6 +210,8 @@ def syncFromUniBox(self): """Synchronize from unibox.""" + if not self.host.uni_box: + return data, target = self.host.uni_box.getTargetAndData() if hasattr(self, 'recipient'): self.recipient.setContacts({"To": [target]} if target else {}) @@ -220,6 +223,8 @@ def setText(): self.host.uni_box.setText("" if emptyText else self.textarea.getText()) + if not self.host.uni_box: + return if not hasattr(self, 'recipient'): setText() return True @@ -251,7 +256,7 @@ def cancelWithoutSaving(self): """Ask for confirmation before closing the dialog.""" - if self.update_msg and self.original_text and self.textarea.getText() == self.original_text: + if self.update_msg and self.textarea.getText() == self.original_text: self.__close(CANCEL) return diff -r 0ca441ba4317 -r 05e264e96a1c libervia.py --- a/libervia.py Fri Dec 27 13:59:06 2013 +0100 +++ b/libervia.py Sun Dec 29 23:07:28 2013 +0100 @@ -36,6 +36,7 @@ from browser_side.tools import html_sanitize from sat_frontends.tools.misc import InputHistory from sat_frontends.tools.strings import getURLParams +from sat_frontends.constants import Const MAX_MBLOG_CACHE = 500 # Max microblog entries kept in memories @@ -262,10 +263,12 @@ except KeyError: print ('WARNING: trying to remove a non registered Widget:', wid.getDebugName()) - def setUniBox(self, unibox): - """register the unibox widget""" - self.uni_box = unibox - self.uni_box.addKey("@@: ") + def _setUniBox(self, enable): + """Enable or disable the unibox widget. + @param enable: boolean + """ + self.panel.unibox_panel.setUniBox(enable == 'true') + self.uni_box = self.panel.unibox_panel.unibox def addTab(self, label, wid, select=True): """Create a new tab and eventually add a widget in @@ -325,6 +328,7 @@ self._defaultDomain = "libervia.org" self.bridge.call("getNewAccountDomain", (domain_cb, domain_eb)) + self.bridge.call('asyncGetParamA', self._setUniBox, Const.ENABLE_UNIBOX_PARAM, Const.ENABLE_UNIBOX_KEY) def _tryAutoConnect(self): """This method retrieve the eventual URL parameters to auto-connect the user.""" diff -r 0ca441ba4317 -r 05e264e96a1c libervia.tac --- a/libervia.tac Fri Dec 27 13:59:06 2013 +0100 +++ b/libervia.tac Sun Dec 29 23:07:28 2013 +0100 @@ -243,6 +243,9 @@ profile = ISATSession(self.session).profile extra['allow_comments'] = 'True' + if not type_: # auto-detect + type_ = "PUBLIC" if dest == [] else "GROUP" + if type_ in ("PUBLIC", "GROUP") and text: if type_ == "PUBLIC": #This text if for the public microblog @@ -508,7 +511,7 @@ profile = ISATSession(self.session).profile self.sat_host.bridge.confirmationAnswer(confirmation_id, result, answer_data, profile) - def jsonrpc_syntaxConvert(self, text, syntax_from=Const._SYNTAX_XHTML, syntax_to=Const._SYNTAX_CURRENT): + def jsonrpc_syntaxConvert(self, text, syntax_from=Const.SYNTAX_XHTML, syntax_to=Const.SYNTAX_CURRENT): """ Convert a text between two syntaxes @param text: text to convert @param syntax_from: source syntax (e.g. "markdown")