diff browser_side/panels.py @ 231:fab7aa366576

browser_side: dialogs take **kwargs arguments + unibox helper method - add the **kwargs arguments to the dialog classes, especially to pass the Width='xxx' setting - add a method getTargetAndData to UniBox, for external use and to get the message recipient and body without dealing with the target hooks, selected panels...
author souliane <souliane@mailoo.org>
date Tue, 08 Oct 2013 13:38:42 +0200
parents 266e9678eec0
children 0ed09cc0566f
line wrap: on
line diff
--- a/browser_side/panels.py	Tue Oct 08 13:57:35 2013 +0200
+++ b/browser_side/panels.py	Tue Oct 08 13:38:42 2013 +0200
@@ -210,6 +210,29 @@
         else:
             self.__onComposing()
 
+    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):
+            target = self._selected_cache.target
+        return (_txt, target)
+
     def __onComposing(self):
         """Callback when the user is composing a text."""
         if hasattr(self._selected_cache, "target"):