plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room

This commit is contained in:
Goffi 2014-04-07 16:24:28 +02:00
commit 7b971278f8

View file

@ -57,6 +57,7 @@ class XEP_0048(object):
# self.__menu_id = host.registerCallback(self._bookmarksMenu, with_data=True)
self.__bm_save_id = host.registerCallback(self._bookmarksSaveCb, with_data=True)
host.importMenu((D_("Communication"), D_("bookmarks")), self._bookmarksMenu, security_limit=0, help_string=D_("Use and manage bookmarks"))
self.__selected_id = host.registerCallback(self._bookmarkSelectedCb, with_data=True)
try:
self.private_plg = self.host.plugins["XEP-0049"]
except KeyError:
@ -207,6 +208,22 @@ class XEP_0048(object):
return storage_elt
def _bookmarkSelectedCb(self, data, profile):
try:
room_jid_s, nick = data['index'].split(' ', 1)
room_jid = jid.JID(room_jid_s)
except (KeyError, RuntimeError):
warning(_("No room jid selected"))
return {}
d = self.host.plugins['XEP-0045'].join(room_jid, nick, {}, profile_key=profile)
def join_eb(failure):
warning("Error while trying to join room: %s" % failure)
# FIXME: failure are badly managed in plugin XEP-0045. Plugin XEP-0045 need to be fixed before managing errors correctly here
return {}
d.addCallbacks(lambda dummy: {}, join_eb)
return d
def _bookmarksMenu(self, data, profile):
""" XMLUI activated by menu: return Gateways UI
@param profile: %(doc_profile)s
@ -214,6 +231,21 @@ class XEP_0048(object):
"""
client = self.host.getClient(profile)
xmlui = xml_tools.XMLUI(title=_('Bookmarks manager'))
adv_list = xmlui.changeContainer('advanced_list', columns=3, selectable='single', callback_id=self.__selected_id)
for bookmarks in (client.bookmarks_local, client.bookmarks_private, client.bookmarks_pubsub):
if bookmarks is None:
continue
for (room_jid, data) in sorted(bookmarks[XEP_0048.MUC_TYPE].items(), key=lambda item: item[1].get('name',item[0].user)):
room_jid_s = room_jid.full()
adv_list.setRowIndex(u'%s %s' % (room_jid_s, data.get('nick') or client.jid.user))
xmlui.addText(data.get('name',''))
xmlui.addJid(room_jid)
if data.get('autojoin', 'false') == 'true':
xmlui.addText('autojoin')
else:
xmlui.addEmpty()
adv_list.end()
xmlui.addDivider('dash')
xmlui.addText(_("add a bookmark"))
xmlui.changeContainer("pairs")
xmlui.addLabel(_('Name'))