primitivus: menu to search directory (using XEP-0055)

This commit is contained in:
Goffi 2013-09-08 18:05:19 +02:00
commit f265c51b49

View file

@ -194,6 +194,7 @@ class PrimitivusApp(QuickApp):
communication = _("Communication")
menu.addMenu(communication, _("Join room"), self.onJoinRoomRequest, 'meta j')
menu.addMenu(communication, _("Find Gateways"), self.onFindGatewaysRequest, 'meta g')
menu.addMenu(communication, _("Search directory"), self.onSearchDirectory)
#additionals menus
#FIXME: do this in a more generic way (in quickapp)
add_menus = self.bridge.getMenus()
@ -519,11 +520,29 @@ class PrimitivusApp(QuickApp):
self.showPopUp(pop_up_widget)
def onFindGatewaysRequest(self, e):
debug(_("Find Gateways request"))
debug(_("Find gateways request"))
id = self.bridge.findGateways(self.profiles[self.profile]['whoami'].domain, self.profile)
self.current_action_ids.add(id)
self.current_action_ids_cb[id] = self.onGatewaysFound
def onSearchDirectory(self, e):
debug(_("Search directory request"))
def requestSearchUi(button, edit):
self.removePopUp()
search_jid = edit.get_edit_text()
if search_jid:
def success(xml):
self.addWindow(XMLUI(self,xml_data=xml, misc={'callback': self._onSearchRequest, 'callback_args': [search_jid,]}))
def failure(error):
self.showPopUp(sat_widgets.Alert(_("Error"), _("Can't get search UI"), ok_cb=self.removePopUp))
self.bridge.getSearchUI(search_jid, self.profile, callback=success, errback=failure)
# TODO: replace users.jabberfr.org by any XEP-0055 compatible service discovered on current server
pop_up_widget = sat_widgets.InputDialog(_("Search directory"), _("Please enter the search jid: "), default_txt="users.jabberfr.org", cancel_cb=lambda ignore: self.removePopUp(), ok_cb=requestSearchUi)
self.showPopUp(pop_up_widget)
def onAddContactRequest(self, menu):
pop_up_widget = sat_widgets.InputDialog(_("Adding a contact"), _("Please enter new contact JID"), default_txt = 'name@server.tld', cancel_cb=self.removePopUp, ok_cb=self.onAddContact)
self.showPopUp(pop_up_widget)
@ -548,6 +567,14 @@ class PrimitivusApp(QuickApp):
gatewayManager = GatewaysManager(self, data, server=target)
self.addWindow(gatewayManager)
def _onSearchRequest(self, data, search_jid):
def success(xml):
ui = XMLUI(self, title=_(u"Search result"), xml_data = xml)
ui.show('window')
def failure(error):
self.showPopUp(sat_widgets.Alert(_("Error"), _("Can't get search UI"), ok_cb=self.removePopUp))
self.bridge.searchRequest(search_jid, dict(data), self.profile, callback=success, errback=failure)
sat = PrimitivusApp()
sat.start()