comparison src/plugins/plugin_xep_0048.py @ 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
comparison
equal deleted inserted replaced
983:c34e0b2bbf08 984:df8e1b557125
55 info(_("Bookmarks plugin initialization")) 55 info(_("Bookmarks plugin initialization"))
56 self.host = host 56 self.host = host
57 # self.__menu_id = host.registerCallback(self._bookmarksMenu, with_data=True) 57 # self.__menu_id = host.registerCallback(self._bookmarksMenu, with_data=True)
58 self.__bm_save_id = host.registerCallback(self._bookmarksSaveCb, with_data=True) 58 self.__bm_save_id = host.registerCallback(self._bookmarksSaveCb, with_data=True)
59 host.importMenu((D_("Communication"), D_("bookmarks")), self._bookmarksMenu, security_limit=0, help_string=D_("Use and manage bookmarks")) 59 host.importMenu((D_("Communication"), D_("bookmarks")), self._bookmarksMenu, security_limit=0, help_string=D_("Use and manage bookmarks"))
60 self.__selected_id = host.registerCallback(self._bookmarkSelectedCb, with_data=True)
60 try: 61 try:
61 self.private_plg = self.host.plugins["XEP-0049"] 62 self.private_plg = self.host.plugins["XEP-0049"]
62 except KeyError: 63 except KeyError:
63 self.private_plg = None 64 self.private_plg = None
64 try: 65 try:
205 except KeyError: 206 except KeyError:
206 pass 207 pass
207 208
208 return storage_elt 209 return storage_elt
209 210
211 def _bookmarkSelectedCb(self, data, profile):
212 try:
213 room_jid_s, nick = data['index'].split(' ', 1)
214 room_jid = jid.JID(room_jid_s)
215 except (KeyError, RuntimeError):
216 warning(_("No room jid selected"))
217 return {}
218
219 d = self.host.plugins['XEP-0045'].join(room_jid, nick, {}, profile_key=profile)
220 def join_eb(failure):
221 warning("Error while trying to join room: %s" % failure)
222 # FIXME: failure are badly managed in plugin XEP-0045. Plugin XEP-0045 need to be fixed before managing errors correctly here
223 return {}
224 d.addCallbacks(lambda dummy: {}, join_eb)
225 return d
226
210 def _bookmarksMenu(self, data, profile): 227 def _bookmarksMenu(self, data, profile):
211 """ XMLUI activated by menu: return Gateways UI 228 """ XMLUI activated by menu: return Gateways UI
212 @param profile: %(doc_profile)s 229 @param profile: %(doc_profile)s
213 230
214 """ 231 """
215 client = self.host.getClient(profile) 232 client = self.host.getClient(profile)
216 xmlui = xml_tools.XMLUI(title=_('Bookmarks manager')) 233 xmlui = xml_tools.XMLUI(title=_('Bookmarks manager'))
234 adv_list = xmlui.changeContainer('advanced_list', columns=3, selectable='single', callback_id=self.__selected_id)
235 for bookmarks in (client.bookmarks_local, client.bookmarks_private, client.bookmarks_pubsub):
236 if bookmarks is None:
237 continue
238 for (room_jid, data) in sorted(bookmarks[XEP_0048.MUC_TYPE].items(), key=lambda item: item[1].get('name',item[0].user)):
239 room_jid_s = room_jid.full()
240 adv_list.setRowIndex(u'%s %s' % (room_jid_s, data.get('nick') or client.jid.user))
241 xmlui.addText(data.get('name',''))
242 xmlui.addJid(room_jid)
243 if data.get('autojoin', 'false') == 'true':
244 xmlui.addText('autojoin')
245 else:
246 xmlui.addEmpty()
247 adv_list.end()
248 xmlui.addDivider('dash')
217 xmlui.addText(_("add a bookmark")) 249 xmlui.addText(_("add a bookmark"))
218 xmlui.changeContainer("pairs") 250 xmlui.changeContainer("pairs")
219 xmlui.addLabel(_('Name')) 251 xmlui.addLabel(_('Name'))
220 xmlui.addString('name') 252 xmlui.addString('name')
221 xmlui.addLabel(_('jid')) 253 xmlui.addLabel(_('jid'))