changeset 11:331c093e4eb3

magicBox is now able to send global microblog
author Goffi <goffi@goffi.org>
date Sat, 26 Mar 2011 17:53:12 +0100
parents c28a4840e1a8
children 513fe9bd0665
files libervia.py libervia.tac
diffstat 2 files changed, 29 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/libervia.py	Fri Mar 25 00:32:58 2011 +0100
+++ b/libervia.py	Sat Mar 26 17:53:12 2011 +0100
@@ -34,6 +34,7 @@
 from pyjamas.ui.DropWidget import DropWidget
 from pyjamas import Window
 from pyjamas.JSONService import JSONProxy
+from pyjamas.ui.KeyboardListener import KEY_ENTER
 from register import RegisterPanel, RegisterBox
 from pyjamas import DOM
 from contact import ContactPanel
@@ -47,7 +48,8 @@
         self.cb={}
 
     def call(self, method, cb, *args):
-        self.cb[method] = cb
+        if cb:
+            self.cb[method] = cb
         self.callMethod(method,args)
 
     def onRemoteResponse(self, response, request_info):
@@ -74,7 +76,7 @@
 class BridgeCall(LiberviaJsonProxy):
     def __init__(self):
         LiberviaJsonProxy.__init__(self, "/json_api",
-                        ["getContacts"])
+                        ["getContacts", "sendMblog"])
 
 class BridgeSignals(LiberviaJsonProxy):
     def __init__(self):
@@ -119,45 +121,22 @@
 
 class MagicBox(AutoCompleteTextBox):
 
-    def __init__(self):
+    def __init__(self, host):
         AutoCompleteTextBox.__init__(self)
+        self.host = host
 
     def addKey(self, key):
         self.getCompletionItems().completions.append(key)
 
-    def addContact(self, jid, attributes, groups):
-        """Add a contact to the panel
-        @param jid: jid
-        @attributes: cf SàT Bridge API's newContact
-        @param groups: list of groups"""
-        for group in groups:
-            if not self.groups.has_key(group):
-                self.groups[group] = set()
-                self._groupList.add(group)
-                self.host.magicBox.addKey("@%s: " % group)
-            self.groups[group].add(jid)
-        self._contactList.add(jid)
+    def onKeyPress(self, sender, keycode, modifiers):
+        if keycode == KEY_ENTER and not self.visible: 
+            self.host.bridge.call('sendMblog', None, self.getText())
+            self.setText('')
 
-    def onMouseMove(self, sender, x, y):
-        pass
-        
-    def onMouseDown(self, sender, x, y):
-        pass
-
-    def onMouseUp(self, sender, x, y):
-        pass
-
-    def onMouseEnter(self, sender):
-        if isinstance(sender, GroupLabel):
-            for contact in self._contactList:
-                if contact.jid in self.groups[sender.group]:
-                    contact.addStyleName("selected")
-    
-    def onMouseLeave(self, sender):
-        if isinstance(sender, GroupLabel):
-            for contact in self._contactList:
-                if contact.jid in self.groups[sender.group]:
-                    contact.removeStyleName("selected")
+    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 EmptyPanel(DropWidget, SimplePanel):
     """Empty dropable panel"""
@@ -282,7 +261,10 @@
 
 class SatWebFrontend:
     def onModuleLoad(self):
-        self.magicBox = MagicBox()
+        self.bridge = BridgeCall()
+        self.bridge_signals = BridgeSignals()
+        self.magicBox = MagicBox(self)
+        self.magicBox.addKey("@@: ")
         self.contactPanel = ContactPanel(self)
         self.panel = MainPanel(self)
         self.middle_panel = self.panel.middle_panel
@@ -314,11 +296,8 @@
             del self._dialog # don't work if self._dialog is None
         
         #it's time to fill the page
-        bridge = BridgeCall()
-        bridge.call('getContacts', self._getContactsCB)
-
-        bridge_signals = BridgeSignals()
-        bridge_signals.call('getSignals', self._getSignalsCB)
+        self.bridge.call('getContacts', self._getContactsCB)
+        self.bridge_signals.call('getSignals', self._getSignalsCB)
 
 
     def _getContactsCB(self, contacts_data):
--- a/libervia.tac	Fri Mar 25 00:32:58 2011 +0100
+++ b/libervia.tac	Sat Mar 26 17:53:12 2011 +0100
@@ -55,12 +55,20 @@
             return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc'))
         return jsonrpc.JSONRPC.render(self, request)
         
-
     def jsonrpc_getContacts(self):
         """Return all passed args."""
         profile = self.session.sat_profile
         return self.sat_host.bridge.getContacts(profile)
 
+    def jsonrpc_sendMblog(self, raw_text):
+        """Parse raw_text of the microblog box, and send message consequently"""
+        profile = self.session.sat_profile
+        if raw_text.startswith('@@: '):
+            #This text if for the public microblog
+            text = raw_text[4:]
+            if text:
+                return self.sat_host.bridge.sendPersonalEvent("MICROBLOG", {'content':text}, profile)
+
 class Register(jsonrpc.JSONRPC):
     """This class manage the registration procedure with SàT
     It provide an api for the browser, check password and setup the web server"""