changeset 984:df8e1b557125

plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
author Goffi <goffi@goffi.org>
date Mon, 07 Apr 2014 16:24:28 +0200
parents c34e0b2bbf08
children 9ebdba4ab907
files src/plugins/plugin_xep_0048.py
diffstat 1 files changed, 32 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0048.py	Mon Apr 07 16:22:35 2014 +0200
+++ b/src/plugins/plugin_xep_0048.py	Mon Apr 07 16:24:28 2014 +0200
@@ -57,6 +57,7 @@
         # 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 @@
 
         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 @@
         """
         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'))