Mercurial > libervia-web
changeset 495:587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 15 Jul 2014 18:45:33 +0200 |
parents | 5d8632a7bfde |
children | 0924710b666a |
files | src/browser/libervia_main.py src/browser/public/libervia.css src/browser/sat_browser/contact.py src/browser/sat_browser/panels.py |
diffstat | 4 files changed, 69 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/src/browser/libervia_main.py Tue Jul 15 18:43:55 2014 +0200 +++ b/src/browser/libervia_main.py Tue Jul 15 18:45:33 2014 +0200 @@ -412,6 +412,10 @@ _dialog = dialog.GenericDialog(ui.title, ui, options=options) ui.setCloseCb(_dialog.close) _dialog.show() + elif "public_blog" in data: + # TODO: use the bare instead of node when all blogs can be retrieved + node = jid.JID(data['public_blog']).node + self.addTab("%s's blog" % node, panels.WebPanel(self, "/blog/%s" % node)) else: dialog.InfoDialog("Error", "Unmanaged action result", Width="400px").center()
--- a/src/browser/public/libervia.css Tue Jul 15 18:43:55 2014 +0200 +++ b/src/browser/public/libervia.css Tue Jul 15 18:45:33 2014 +0200 @@ -469,8 +469,20 @@ width: 32px; height: 32px; border-radius: 5px; - margin: 5px 0px 0px 10px; + margin: 5px 5px 0px 10px; +} + +.contactBox .widgetHeader_buttonGroup img { border-radius: 5px; + border-left: 0px; + padding: 0px 0px 0px 0px; + background: -webkit-gradient(linear, left top, left bottom, from(#eee), to(#aaa)); + background: -webkit-linear-gradient(top, #eee, #aaa); + background: linear-gradient(to bottom, #eee, #aaa); +} + +.contactBox table { + width: 100%; } .contactLabel { @@ -718,9 +730,7 @@ background-color: transparent; width: 25px; height: 20px; - padding-top: 2px; - padding-bottom: 3px; - padding-right: 0px; + padding: 2px 0px 3px 0px; border-left: 1px solid #666; border-top: 0; border-radius: 0 0 0 0;
--- a/src/browser/sat_browser/contact.py Tue Jul 15 18:43:55 2014 +0200 +++ b/src/browser/sat_browser/contact.py Tue Jul 15 18:45:33 2014 +0200 @@ -34,7 +34,6 @@ from constants import Const as C from jid import JID -import base_panels import base_widget import panels import html_tools @@ -95,8 +94,23 @@ self.refresh() -class ContactBox(base_widget.DragLabel, VerticalPanel, ClickHandler): - def __init__(self, host, jid, name=None, handleClick=True): +class ContactMenuBar(base_widget.WidgetMenuBar): + + ITEM_TPL = "<img src='media/icons/misc/%s.png' />" + + def __init__(self, host, menu_data): + base_widget.WidgetMenuBar.__init__(self, host) + self.addCachedMenus(C.MENU_ROSTER_JID_CONTEXT, menu_data) + self.addCachedMenus(C.MENU_JID_CONTEXT, menu_data) + + def onBrowserEvent(self, event): + base_widget.WidgetMenuBar.onBrowserEvent(self, event) + event.stopPropagation() # prevent opening the chat dialog + + +class ContactBox(VerticalPanel, ClickHandler, base_widget.DragLabel): + + def __init__(self, host, jid, name=None, click_listener=None, handle_menu=None): VerticalPanel.__init__(self, StyleName='contactBox', VerticalAlignment='middle') base_widget.DragLabel.__init__(self, jid, "CONTACT") self.host = host @@ -104,11 +118,17 @@ self.label = ContactLabel(jid, name) self.avatar = Image() self.updateAvatar(host.getAvatar(jid)) - self.add(self.avatar) + extra = HorizontalPanel() + extra.add(self.avatar) + self.add(extra) self.add(self.label) - if handleClick: + if click_listener: ClickHandler.__init__(self) self.addClickListener(self) + self.click_listener = click_listener + + if handle_menu: + extra.add(ContactMenuBar(host, {'jid': jid})) def setMessageWaiting(self, waiting): """Show a visual indicator if message are waiting @@ -125,7 +145,7 @@ self.avatar.setUrl(url) def onClick(self, sender): - self.host.getOrCreateLiberviaWidget(panels.ChatPanel, self.jid) + self.click_listener(self.jid) class GroupList(VerticalPanel): @@ -157,18 +177,23 @@ the one that is displayed on the left side. Special features like popup menu panel or changing the contact states must be done in a sub-class.""" - def __init__(self, host, handleClick=False): + def __init__(self, host, handle_click=False, handle_menu=False): VerticalPanel.__init__(self) self.host = host self.contacts = [] - self.handleClick = handleClick + self.click_listener = None + self.handle_menu = handle_menu - def add(self, jid, name=None, add_item_cb=None): + if handle_click: + def cb(contact_jid): + self.host.getOrCreateLiberviaWidget(panels.ChatPanel, contact_jid) + self.click_listener = cb + + def add(self, jid, name=None): """Add a contact to the list. @param jid (str): JID of the contact @param name (str): optional name of the contact - @param add_item_cb (method): to be called on the contact's widget after it's been added to the list """ if jid in self.contacts: return @@ -178,10 +203,8 @@ break index += 1 self.contacts.insert(index, jid) - box = ContactBox(self.host, jid, name, handleClick=self.handleClick) + box = ContactBox(self.host, jid, name, self.click_listener, self.handle_menu) VerticalPanel.insert(self, box, index) - if add_item_cb: - add_item_cb(box) def remove(self, jid): box = self.getContactBox(jid) @@ -221,34 +244,20 @@ """The contact list that is displayed on the left side.""" def __init__(self, host): - GenericContactList.__init__(self, host, handleClick=True) - self.menu_entries = {"blog": {"title": "Public blog..."}} - self.context_menu = base_panels.PopupMenuPanel(entries=self.menu_entries, - hide=self.contextMenuHide, - callback=self.contextMenuCallback, - vertical=False, style={"selected": "menu-selected"}) + GenericContactList.__init__(self, host, handle_click=True, handle_menu=True) def contextMenuHide(self, sender, key): """Return True if the item for that sender should be hidden.""" # TODO: enable the blogs of users that are on another server return JID(sender.jid).domain != self.host._defaultDomain - def contextMenuCallback(self, sender, key): - if key == "blog": - # TODO: use the bare when all blogs can be retrieved - node = JID(sender.jid).node - web_panel = panels.WebPanel(self.host, "/blog/%s" % node) - self.host.addTab("%s's blog" % node, web_panel) - else: - sender.onClick(sender) - def add(self, jid_s, name=None): """Add a contact @param jid_s (str): JID as unicode @param name (str): nickname """ - GenericContactList.add(self, jid_s, name, add_item_cb=lambda item: self.context_menu.registerRightClickSender(item)) + GenericContactList.add(self, jid_s, name) def setState(self, jid, type_, state): """Change the appearance of the contact, according to the state
--- a/src/browser/sat_browser/panels.py Tue Jul 15 18:43:55 2014 +0200 +++ b/src/browser/sat_browser/panels.py Tue Jul 15 18:45:33 2014 +0200 @@ -1093,15 +1093,15 @@ @param host: SatWebFrontend instance @param target: entity (jid.JID) with who we have a conversation (contact's jid for one 2 one chat, or MUC room) @param type: one2one for simple conversation, group for MUC""" - base_widget.LiberviaWidget.__init__(self, host, title=target.bare, selectable=True) self.vpanel = VerticalPanel() self.vpanel.setSize('100%', '100%') - self.type = type_ self.nick = None if not target: log.error("Empty target !") return self.target = target + self.type = type_ + base_widget.LiberviaWidget.__init__(self, host, title=target.bare, selectable=True) self.__body = AbsolutePanel() self.__body.setStyleName('chatPanel_body') chat_area = HorizontalPanel() @@ -1168,6 +1168,16 @@ e.include_traceback() return False + def addCachedMenus(self, menu_bar): + """Add cached menus to the header. + + @param menu_bar (GenericMenuBar): menu bar of the widget's header + """ + if self.type == 'group': + menu_bar.addCachedMenus(C.MENU_ROOM, {'room_jid': self.target.bare}) + elif self.type == 'one2one': + menu_bar.addCachedMenus(C.MENU_SINGLE, {'jid': self.target}) + def getWarningData(self): if self.type not in ["one2one", "group"]: raise Exception("Unmanaged type !") @@ -1350,7 +1360,7 @@ AbsolutePanel.__init__(self) # menu - self.menu = menu.Menu(host) + self.menu = menu.MainMenuPanel(host) # unibox self.unibox_panel = UniBoxPanel(host)