# HG changeset patch # User Goffi # Date 1306854419 -7200 # Node ID 12e889a683ce07bfdb66ca3952c93fd97329d70c # Parent 80c490e6a1a78502de24926147aa61843b767fa2 server side: misc stuff: - fixed lot of misuse in callbacks - chat history fixed - a visual indicator now appear when we have message waiting from a contact - fixed About dialog size issue in webkit - fixed Drag'n'Drop for webkit - defaut room to join is now libervia@conference.libervia.org diff -r 80c490e6a1a7 -r 12e889a683ce browser_side/card_game.py --- a/browser_side/card_game.py Tue May 31 17:03:37 2011 +0200 +++ b/browser_side/card_game.py Tue May 31 17:06:59 2011 +0200 @@ -80,7 +80,7 @@ self.setHTML("Please select your contrat") self.setWidget(content) - def onChoose(self): + def onChoose(self, button): self.hide() self._parent.contratSelected(self.contrats_list.getSelectedItemText()[0]) diff -r 80c490e6a1a7 -r 12e889a683ce browser_side/contact.py --- a/browser_side/contact.py Tue May 31 17:03:37 2011 +0200 +++ b/browser_side/contact.py Tue May 31 17:06:59 2011 +0200 @@ -24,11 +24,13 @@ from pyjamas.ui.VerticalPanel import VerticalPanel from pyjamas.ui.HorizontalPanel import HorizontalPanel from pyjamas.ui.Label import Label +from pyjamas.ui.HTML import HTML from pyjamas import Window from pyjamas import DOM from pyjamas.dnd import makeDraggable from pyjamas.ui.DragWidget import DragWidget, DragContainer +from browser_side.tools import html_sanitize from jid import JID class DragLabel(DragWidget): @@ -39,28 +41,9 @@ self._type = type def onDragStart(self, event): - print "onDragStart" dt = event.dataTransfer - #self.addMessage('types is %s' % dt.getTypes()) - dt.setData('Text', self._text) - dt.setData('type', self._type) - #self.addMessage('after setting, len is %s' % len(dt.dataStore.items)) - #self.addMessage('types is %s' % dt.getTypes()) + dt.setData('text/plain', "%s\n%s" % (self._text, self._type)) dt.setDragImage(self.getElement(), 15, 15) - #dt.effectAllowed = 'copy' - #self.addMessage('mode is %s' % dt.dataStore.items.mode) - - def onDragEnd(self, event): - print "onDragEnd" - #self.addMessage('Drag ended') - #self.addMessage('mode is %s' % dt._data.mode) - - def addMessage(self, message): - print "addMessage" - #parent = self.getParent() - #while not hasattr(parent, 'addMessage'): - # parent = parent.getParent() - #parent.addMessage(message) class GroupLabel(DragLabel, Label): def __init__(self, group): @@ -70,15 +53,28 @@ DragLabel.__init__(self, group, "GROUP") -class ContactLabel(DragLabel, Label): +class ContactLabel(DragLabel, HTML): def __init__(self, jid, name=None): - if not name: - name=jid - Label.__init__(self, name) + HTML.__init__(self) + self.name = name or jid + self.waiting = False self.jid=jid + self._fill() self.setStyleName('contact') DragLabel.__init__(self, jid, "CONTACT") + def _fill(self): + if self.waiting: + _wait_html = "(*) " + self.setHTML("%(wait)s%(name)s" % {'wait': _wait_html, + 'name': html_sanitize(self.name)}) + + def setMessageWaiting(self, waiting): + """Show a visual indicator if message are waiting + @param waiting: True if message are waiting""" + self.waiting = waiting + self._fill() + class GroupList(VerticalPanel): def __init__(self, parent): @@ -132,16 +128,24 @@ return wid return None - def setState(self, jid, state): + def setState(self, jid, type, state): """Change the appearance of the contact, according to the state @param jid: jid which need to change state - @param state: 'unavailable' if not connected, else presence like RFC6121 #4.7.2.1""" + @param type: one of availability, messageWaiting + @param state: + - for messageWaiting type: + True if message are waiting + - for availability type: + 'unavailable' if not connected, else presence like RFC6121 #4.7.2.1""" _item = self.getContactLabel(jid) if _item: - if state == 'unavailable': - _item.removeStyleName('contactConnected') - else: - _item.addStyleName('contactConnected') + if type == 'availability': + if state == 'unavailable': + _item.removeStyleName('contactConnected') + else: + _item.addStyleName('contactConnected') + elif type == 'messageWaiting': + _item.setMessageWaiting(state) class ContactTitleLabel(DragLabel, Label): def __init__(self, text): @@ -219,7 +223,15 @@ if not self.connected.has_key(jid): self.connected[jid] = {} self.connected[jid][resource] = (availability, priority, statuses) - self._contact_list.setState(jid, availability) + self._contact_list.setState(jid, "availability", availability) + + def setContactMessageWaiting(self, jid, waiting): + """Show an visual indicator that contact has send a message + @param jid: jid of the contact + @param waiting: True if message are waiting""" + self._contact_list.setState(jid, "messageWaiting", waiting) + + def getConnected(self): """return a list of all jid (bare jid) connected""" diff -r 80c490e6a1a7 -r 12e889a683ce browser_side/dialog.py --- a/browser_side/dialog.py Tue May 31 17:03:37 2011 +0200 +++ b/browser_side/dialog.py Tue May 31 17:06:59 2011 +0200 @@ -28,6 +28,7 @@ from pyjamas.ui.TextBox import TextBox from pyjamas.ui.Label import Label from pyjamas.ui.HTML import HTML +from pyjamas.ui.Frame import Frame from pyjamas.ui import HasAlignment from pyjamas.ui.KeyboardListener import KEY_ESCAPE, KEY_ENTER @@ -63,7 +64,7 @@ self.setHTML(text) self.setWidget(content) - def onChange(self): + def onChange(self, sender): if self.nb_contact: if len(self.contacts_list.getSelectedValues()) == self.nb_contact: self.choose_button.setEnabled(True) @@ -80,11 +81,11 @@ self.contacts_list.addItem(contact) self.show() - def onChoose(self): + def onChoose(self, sender): self.hide() self.callback(self.contacts_list.getSelectedValues()) - def onCancel(self): + def onCancel(self, sender): self.hide() class GenericConfirmDialog(DialogBox): @@ -109,11 +110,11 @@ self.setHTML(title) self.setWidget(content) - def onConfirm(self): + def onConfirm(self, sender): self.hide() self.callback(True) - def onCancel(self): + def onCancel(self, sender): self.hide() self.callback(False) @@ -141,9 +142,12 @@ _body.setCellHorizontalAlignment(_close_button, HasAlignment.ALIGN_CENTER) self.setHTML(title) self.setWidget(_body) - self.panel.setWidth('100%') + if isinstance(widget, Frame): + #Need this hack to have correct size for About box + Social Contract + #in Gecko & Webkit + self.panel.setWidth('100%') - def onClose(self): + def onClose(self, sender): self.hide() if self.callback: self.callback() diff -r 80c490e6a1a7 -r 12e889a683ce browser_side/panels.py --- a/browser_side/panels.py Tue May 31 17:03:37 2011 +0200 +++ b/browser_side/panels.py Tue May 31 17:06:59 2011 +0200 @@ -144,7 +144,6 @@ def updateContactCb(sender): _jid = _contacts_list.getValue(_contacts_list.getSelectedIndex()) self.host.bridge.call('updateContact', None, _jid, '', _dialog.getSelectedGroups()) - print "contactUpdated" def onContactChange(_list): _jid = _contacts_list.getValue(_contacts_list.getSelectedIndex()) @@ -202,7 +201,7 @@ _main_panel = VerticalPanel() _label = Label("Discussion room:") _edit = TextBox() - _edit.setText('libervia@conference.tazar.int') + _edit.setText('libervia@conference.libervia.org') hpanel = HorizontalPanel() hpanel.add(_label) hpanel.add(_edit) @@ -236,12 +235,10 @@ DropWidget.__init__(self) def onDragEnter(self, event): - print "drag enter" self.addStyleName('dragover') DOM.eventPreventDefault(event) def onDragLeave(self, event): - print "\ndrag leave" if event.clientX <= self.getAbsoluteLeft() or event.clientY <= self.getAbsoluteTop() or\ event.clientX >= self.getAbsoluteLeft() + self.getOffsetWidth()-1 or event.clientY >= self.getAbsoluteTop() + self.getOffsetHeight()-1: #We check that we are inside widget's box, and we don't remove the style in this case because @@ -260,12 +257,13 @@ def onDrop(self, event): - print "Empty Panel: onDrop" dt = event.dataTransfer #'text', 'text/plain', and 'Text' are equivalent. try: - item = dt.getData("text/plain") - item_type = dt.getData("type") + item, item_type = dt.getData("text/plain").split('\n') #Workaround for webkit, only text/plain seems to be managed + if item_type and item_type[-1] == '\0': #Workaround for what looks like a pyjamas bug: the \0 should not be there, and + item_type = item_type[:-1] # .strip('\0') and .replace('\0','') don't work. TODO: check this and fill a bug report + #item_type = dt.getData("type") print "message: %s" % item print "type: %s" % item_type except: @@ -279,6 +277,7 @@ self.host.FillMicroblogPanel(_new_panel) elif item_type=="CONTACT": _contact = JID(item) + self.host.contact_panel.setContactMessageWaiting(_contact.bare, False) _new_panel = ChatPanel(self.host, _contact) _new_panel.historyPrint() elif item_type=="CONTACT_TITLE": @@ -431,7 +430,7 @@ type = "ONE2ONE" target = str(self.host.selected.target) else: - print self.host.selected + print "Unknown selected host:",self.host.selected type = "UNKNOWN" return (type, target) @@ -550,7 +549,7 @@ self.status = new_status or ' ' self.setHTML(self.__getContent()) - def onClick(self, sender, event): + def onClick(self, sender): #As status is the default target of uniBar, we don't want to select anything if click on it self.host.select(None) @@ -655,7 +654,7 @@ #the event will not propagate to children ScrollPanelWrapper.doAttachChildren(self) - def onClick(self, sender, event): + def onClick(self, sender): self.host.select(self) def setUserNick(self, nick): @@ -670,12 +669,10 @@ self.occupants_list.addOccupant(nick) def userJoined(self, nick, data): - print "userJoined:", nick, data self.occupants_list.addOccupant(nick) self.printInfo("=> %s has joined the room" % nick) def userLeft(self, nick, data): - print "userLeft:", nick, data self.occupants_list.removeOccupant(nick) self.printInfo("<= %s has left the room" % nick) @@ -686,7 +683,7 @@ stamps.sort() for stamp in stamps: self.printMessage(history[stamp][0], history[stamp][1], stamp) - self.host.bridge.call('getHistory', getHistoryCB, self.host.whoami.bare, str(self.target), 20) + self.host.bridge.call('getHistory', getHistoryCB, self.host.whoami.bare, self.target.bare, 20) def printInfo(self, msg, type='normal'): """Print general info @@ -758,7 +755,6 @@ Window.addWindowResizeListener(self) def onWindowResized(self, width, height): - print "onWindowResized" tab_panel_elt = self.getElement() _elts = doc().getElementsByClassName('gwt-TabBar') if not _elts.length: diff -r 80c490e6a1a7 -r 12e889a683ce browser_side/register.py --- a/browser_side/register.py Tue May 31 17:03:37 2011 +0200 +++ b/browser_side/register.py Tue May 31 17:06:59 2011 +0200 @@ -117,10 +117,10 @@ else: self.changeMode("login") - def onLogin(self): + def onLogin(self, button): self.submit() - def onRegister(self): + def onRegister(self, button): print self.login_box.getText() if not re.match(r'^[a-z0-9_-]+$',self.login_box.getText(), re.IGNORECASE): self.warning_msg.setText('Invaling login, valid characters are a-z A-Z 0-9 _ -') @@ -142,6 +142,8 @@ Window.alert('You login and/or password is incorrect. Please try again') elif result == "LOGGED": self.callback() + elif result == "SESSION_ACTIVE": + Window.alert('Session already active, this should not happen, please contact contact the author to fix it') elif result == "ALREADY EXISTS": self.warning_msg.setText('This login already exists, please choose an other one') self.warning_msg.setVisible(True) diff -r 80c490e6a1a7 -r 12e889a683ce libervia.py --- a/libervia.py Tue May 31 17:03:37 2011 +0200 +++ b/libervia.py Tue May 31 17:06:59 2011 +0200 @@ -50,8 +50,14 @@ del self.cb[request_info.id] def onRemoteError(self, code, errobj, request_info): + """def dump(obj): + print "\n\nDUMPING %s\n\n" % obj + for i in dir(obj): + print "%s: %s" % (i, getattr(obj,i))""" if code != 0: Window.alert("Internal server error") + """for o in code, error, request_info: + dump(o)""" else: if isinstance(errobj['message'],dict): Window.alert("Error %s: %s" % (errobj['message']['faultCode'], errobj['message']['faultString'])) @@ -152,7 +158,7 @@ def _isConnectedCB(self, connected): if not connected: - self._register.call('connect',self.logged) + self._register.call('connect',lambda x:self.logged()) else: self.logged() @@ -256,9 +262,17 @@ def _newMessageCb(self, from_jid, msg, msg_type, to_jid): _from = JID(from_jid) _to = JID(to_jid) + showed = False for panel in self.mpanels + self.other_panels: if isinstance(panel,panels.ChatPanel) and (panel.target.bare == _from.bare or panel.target.bare == _to.bare): panel.printMessage(_from, msg) + showed = True + if not showed: + #The message has not been showed, we must indicate it + other = _to if _from.bare == self.whoami.bare else _from + self.contact_panel.setContactMessageWaiting(other.bare, True) + + def _presenceUpdateCb(self, entity, show, priority, statuses): _entity = JID(entity) @@ -327,9 +341,9 @@ _dialog = None msg = HTML('The contact %s want to add you in his/her contact list, do you accept ?' % html_sanitize(entity)) - def ok_cb(): + def ok_cb(ignore): self.bridge.call('subscription', None, "subscribed", entity, '', _dialog.getSelectedGroups()) - def cancel_cb(): + def cancel_cb(ignore): self.bridge.call('subscription', None, "unsubscribed", entity, '', '') _dialog = dialog.GroupSelector([msg], self.contact_panel.getGroups(), [], ok_cb, cancel_cb)