support JEP-0055 (search) for non-dataform services. TODO: improve GUI
This commit is contained in:
parent
f3676520c4
commit
9ed8a292f2
|
@ -1349,13 +1349,34 @@ class Connection(ConnectionHandlers):
|
||||||
iq = common.xmpp.Iq(typ = 'get', to = jid, queryNS = \
|
iq = common.xmpp.Iq(typ = 'get', to = jid, queryNS = \
|
||||||
common.xmpp.NS_SEARCH)
|
common.xmpp.NS_SEARCH)
|
||||||
self.connection.send(iq)
|
self.connection.send(iq)
|
||||||
|
|
||||||
def send_search_form(self, jid, form, is_form):
|
def send_search_form(self, jid, form, is_form):
|
||||||
|
iq = common.xmpp.Iq(typ = 'set', to = jid, queryNS = \
|
||||||
|
common.xmpp.NS_SEARCH)
|
||||||
|
item = iq.getTag('query')
|
||||||
if is_form:
|
if is_form:
|
||||||
iq = common.xmpp.Iq(typ = 'set', to = jid, queryNS = \
|
|
||||||
common.xmpp.NS_SEARCH)
|
|
||||||
item = iq.getTag('query')
|
|
||||||
item.addChild(node = form)
|
item.addChild(node = form)
|
||||||
self.connection.send(iq)
|
else:
|
||||||
|
for i in form.keys():
|
||||||
|
item.setTagData(i,form[i])
|
||||||
|
def _on_response(resp):
|
||||||
|
jid = jid = helpers.get_jid_from_iq(resp)
|
||||||
|
tag = resp.getTag('query', namespace = common.xmpp.NS_SEARCH)
|
||||||
|
if not tag:
|
||||||
|
self.dispatch('SEARCH_RESULT', (jid, None, False))
|
||||||
|
return
|
||||||
|
df = tag.getTag('x', namespace = common.xmpp.NS_DATA)
|
||||||
|
if df:
|
||||||
|
self.dispatch('SEARCH_RESULT', (jid, df, True))
|
||||||
|
return
|
||||||
|
df = []
|
||||||
|
for item in tag.getTags('item'):
|
||||||
|
f = {}
|
||||||
|
for i in item.getPayload():
|
||||||
|
f[i.getName()] = i.getData()
|
||||||
|
df.append(f)
|
||||||
|
self.dispatch('SEARCH_RESULT', (jid, df, False))
|
||||||
|
|
||||||
|
self.connection.SendAndCallForResponse(iq, _on_response)
|
||||||
|
|
||||||
# END Connection
|
# END Connection
|
||||||
|
|
|
@ -1936,18 +1936,16 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
|
||||||
jid = jid = helpers.get_jid_from_iq(iq_obj)
|
jid = jid = helpers.get_jid_from_iq(iq_obj)
|
||||||
tag = iq_obj.getTag('query', namespace = common.xmpp.NS_SEARCH)
|
tag = iq_obj.getTag('query', namespace = common.xmpp.NS_SEARCH)
|
||||||
if not tag:
|
if not tag:
|
||||||
self.dispatch('SEARCH_RESULT', (jid, None, False))
|
self.dispatch('SEARCH_FORM', (jid, None, False))
|
||||||
return
|
return
|
||||||
df = tag.getTag('x', namespace = common.xmpp.NS_DATA)
|
df = tag.getTag('x', namespace = common.xmpp.NS_DATA)
|
||||||
if df:
|
if df:
|
||||||
self.dispatch('SEARCH_RESULT', (jid, df, True))
|
self.dispatch('SEARCH_FORM', (jid, df, True))
|
||||||
return
|
return
|
||||||
df = {}
|
df = {}
|
||||||
for i in iq_obj.getQueryPayload():
|
for i in iq_obj.getQueryPayload():
|
||||||
if not isinstance(i, common.xmpp.Node):
|
|
||||||
pass
|
|
||||||
df[i.getName()] = i.getData()
|
df[i.getName()] = i.getData()
|
||||||
self.dispatch('SEARCH_RESULT', (jid, df, False))
|
self.dispatch('SEARCH_FORM', (jid, df, False))
|
||||||
|
|
||||||
def _register_handlers(self, con, con_type):
|
def _register_handlers(self, con, con_type):
|
||||||
# try to find another way to register handlers in each class
|
# try to find another way to register handlers in each class
|
||||||
|
|
10
src/gajim.py
10
src/gajim.py
|
@ -1671,11 +1671,18 @@ class Interface:
|
||||||
ctrl = self.msg_win_mgr.get_control(contact.jid, account)
|
ctrl = self.msg_win_mgr.get_control(contact.jid, account)
|
||||||
ctrl.print_conversation(_('Error.'), 'status')
|
ctrl.print_conversation(_('Error.'), 'status')
|
||||||
|
|
||||||
|
def handle_event_search_form(self, account, data):
|
||||||
|
# ('SEARCH_FORM', account, (jid, dataform, is_dataform))
|
||||||
|
if not self.instances[account]['search'].has_key(data[0]):
|
||||||
|
return
|
||||||
|
self.instances[account]['search'][data[0]].on_form_arrived(data[1],
|
||||||
|
data[2])
|
||||||
|
|
||||||
def handle_event_search_result(self, account, data):
|
def handle_event_search_result(self, account, data):
|
||||||
# ('SEARCH_RESULT', account, (jid, dataform, is_dataform))
|
# ('SEARCH_RESULT', account, (jid, dataform, is_dataform))
|
||||||
if not self.instances[account]['search'].has_key(data[0]):
|
if not self.instances[account]['search'].has_key(data[0]):
|
||||||
return
|
return
|
||||||
self.instances[account]['search'][data[0]].on_form_arrived(data[1],
|
self.instances[account]['search'][data[0]].on_result_arrived(data[1],
|
||||||
data[2])
|
data[2])
|
||||||
|
|
||||||
def read_sleepy(self):
|
def read_sleepy(self):
|
||||||
|
@ -1993,6 +2000,7 @@ class Interface:
|
||||||
'PING_SENT': self.handle_event_ping_sent,
|
'PING_SENT': self.handle_event_ping_sent,
|
||||||
'PING_REPLY': self.handle_event_ping_reply,
|
'PING_REPLY': self.handle_event_ping_reply,
|
||||||
'PING_ERROR': self.handle_event_ping_error,
|
'PING_ERROR': self.handle_event_ping_error,
|
||||||
|
'SEARCH_FORM': self.handle_event_search_form,
|
||||||
'SEARCH_RESULT': self.handle_event_search_result,
|
'SEARCH_RESULT': self.handle_event_search_result,
|
||||||
}
|
}
|
||||||
gajim.handlers = self.handlers
|
gajim.handlers = self.handlers
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
## search.py
|
## search_window.py
|
||||||
##
|
##
|
||||||
## Copyright (C) 2007 Yann Le Boulanger <asterix@lagaule.org>
|
## Copyright (C) 2007 Yann Le Boulanger <asterix@lagaule.org>
|
||||||
##
|
##
|
||||||
|
@ -33,16 +33,10 @@ class SearchWindow:
|
||||||
self.xml = gtkgui_helpers.get_glade('search_window.glade')
|
self.xml = gtkgui_helpers.get_glade('search_window.glade')
|
||||||
self.window = self.xml.get_widget('search_window')
|
self.window = self.xml.get_widget('search_window')
|
||||||
for name in ('label', 'progressbar', 'search_vbox', 'search_button'):
|
for name in ('label', 'progressbar', 'search_vbox', 'search_button'):
|
||||||
# 'execute_button','close_button','stages_notebook',
|
|
||||||
# 'retrieving_commands_stage_vbox',
|
|
||||||
# 'command_list_stage_vbox','command_list_vbox',
|
|
||||||
# 'sending_form_stage_vbox','sending_form_progressbar',
|
|
||||||
# 'notes_label','no_commands_stage_vbox','error_stage_vbox',
|
|
||||||
# 'error_description_label'):
|
|
||||||
self.__dict__[name] = self.xml.get_widget(name)
|
self.__dict__[name] = self.xml.get_widget(name)
|
||||||
|
|
||||||
self.data_form_widget = dataforms_widget.DataFormWidget()
|
self.data_form_widget = dataforms_widget.DataFormWidget()
|
||||||
self.search_vbox.pack_start(self.data_form_widget)
|
self.table = None
|
||||||
|
|
||||||
# displaying the window
|
# displaying the window
|
||||||
self.xml.signal_autoconnect(self)
|
self.xml.signal_autoconnect(self)
|
||||||
|
@ -51,6 +45,10 @@ class SearchWindow:
|
||||||
self.pulse_id = gobject.timeout_add(80, self.pulse_callback)
|
self.pulse_id = gobject.timeout_add(80, self.pulse_callback)
|
||||||
|
|
||||||
self.is_form = None
|
self.is_form = None
|
||||||
|
|
||||||
|
# for non-dataform forms
|
||||||
|
self.entries = {}
|
||||||
|
self.info = {}
|
||||||
|
|
||||||
def request_form(self):
|
def request_form(self):
|
||||||
gajim.connections[self.account].request_search_fields(self.jid)
|
gajim.connections[self.account].request_search_fields(self.jid)
|
||||||
|
@ -76,10 +74,19 @@ class SearchWindow:
|
||||||
self.data_form_widget.data_form.type = 'submit'
|
self.data_form_widget.data_form.type = 'submit'
|
||||||
gajim.connections[self.account].send_search_form(self.jid,
|
gajim.connections[self.account].send_search_form(self.jid,
|
||||||
self.data_form_widget.data_form, True)
|
self.data_form_widget.data_form, True)
|
||||||
|
self.search_vbox.remove(self.data_form_widget)
|
||||||
|
else:
|
||||||
|
for name in self.entries.keys():
|
||||||
|
self.infos[name] = self.entries[name].get_text().decode('utf-8')
|
||||||
|
if self.infos.has_key('instructions'):
|
||||||
|
del self.infos['instructions']
|
||||||
|
gajim.connections[self.account].send_search_form(self.jid, self.infos,
|
||||||
|
False)
|
||||||
|
self.search_vbox.remove(self.table)
|
||||||
|
|
||||||
self.progressbar.show()
|
self.progressbar.show()
|
||||||
self.label.set_text(_('Waiting for results'))
|
self.label.set_text(_('Waiting for results'))
|
||||||
self.label.show()
|
self.label.show()
|
||||||
self.data_form_widget.hide()
|
|
||||||
self.pulse_id = gobject.timeout_add(80, self.pulse_callback)
|
self.pulse_id = gobject.timeout_add(80, self.pulse_callback)
|
||||||
self.search_button.hide()
|
self.search_button.hide()
|
||||||
|
|
||||||
|
@ -91,7 +98,32 @@ class SearchWindow:
|
||||||
|
|
||||||
if not is_form:
|
if not is_form:
|
||||||
self.is_form = False
|
self.is_form = False
|
||||||
print 'no form, not supported yet'
|
self.infos = form
|
||||||
|
nbrow = 0
|
||||||
|
if self.infos.has_key('instructions'):
|
||||||
|
self.label.set_text(self.infos['instructions'])
|
||||||
|
self.label.show()
|
||||||
|
self.table = gtk.Table()
|
||||||
|
for name in self.infos.keys():
|
||||||
|
if not name:
|
||||||
|
continue
|
||||||
|
if name == 'instructions':
|
||||||
|
continue
|
||||||
|
|
||||||
|
nbrow = nbrow + 1
|
||||||
|
self.table.resize(rows = nbrow, columns = 2)
|
||||||
|
label = gtk.Label(name.capitalize() + ':')
|
||||||
|
self.table.attach(label, 0, 1, nbrow - 1, nbrow, 0, 0, 0, 0)
|
||||||
|
entry = gtk.Entry()
|
||||||
|
entry.set_activates_default(True)
|
||||||
|
if self.infos[name]:
|
||||||
|
entry.set_text(self.infos[name])
|
||||||
|
if name == 'password':
|
||||||
|
entry.set_visibility(False)
|
||||||
|
self.table.attach(entry, 1, 2, nbrow - 1, nbrow, 0, 0, 0, 0)
|
||||||
|
self.entries[name] = entry
|
||||||
|
self.table.show_all()
|
||||||
|
self.search_vbox.pack_start(self.table)
|
||||||
return
|
return
|
||||||
|
|
||||||
self.dataform = dataforms.ExtendForm(node = form)
|
self.dataform = dataforms.ExtendForm(node = form)
|
||||||
|
@ -105,7 +137,59 @@ class SearchWindow:
|
||||||
return
|
return
|
||||||
self.is_form = True
|
self.is_form = True
|
||||||
|
|
||||||
|
self.search_vbox.pack_start(self.data_form_widget)
|
||||||
self.data_form_widget.show()
|
self.data_form_widget.show()
|
||||||
if self.data_form_widget.title:
|
if self.data_form_widget.title:
|
||||||
self.window.set_title("%s - Search - Gajim" % \
|
self.window.set_title('%s - Search - Gajim' % \
|
||||||
self.data_form_widget.title)
|
self.data_form_widget.title)
|
||||||
|
|
||||||
|
def on_result_arrived(self, form, is_form):
|
||||||
|
if self.pulse_id:
|
||||||
|
gobject.source_remove(self.pulse_id)
|
||||||
|
self.progressbar.hide()
|
||||||
|
self.label.hide()
|
||||||
|
|
||||||
|
if not is_form:
|
||||||
|
if not form:
|
||||||
|
self.label.set_text(_('No result'))
|
||||||
|
self.label.show()
|
||||||
|
return
|
||||||
|
# We suppose all items have the same fields
|
||||||
|
sw = gtk.ScrolledWindow()
|
||||||
|
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
||||||
|
treeview = gtk.TreeView()
|
||||||
|
sw.add(treeview)
|
||||||
|
# Create model
|
||||||
|
fieldtypes = [str]*len(form[0])
|
||||||
|
model = gtk.ListStore(*fieldtypes)
|
||||||
|
# Copy data to model
|
||||||
|
for item in form:
|
||||||
|
model.append(item.values())
|
||||||
|
# Create columns
|
||||||
|
counter = 0
|
||||||
|
for field in form[0].keys():
|
||||||
|
treeview.append_column(
|
||||||
|
gtk.TreeViewColumn(field, gtk.CellRendererText(),
|
||||||
|
text = counter))
|
||||||
|
counter += 1
|
||||||
|
treeview.set_model(model)
|
||||||
|
sw.show_all()
|
||||||
|
self.search_vbox.pack_start(sw)
|
||||||
|
return
|
||||||
|
|
||||||
|
self.dataform = dataforms.ExtendForm(node = form)
|
||||||
|
|
||||||
|
self.data_form_widget.set_sensitive(True)
|
||||||
|
try:
|
||||||
|
self.data_form_widget.data_form = self.dataform
|
||||||
|
except dataforms.Error:
|
||||||
|
self.label.set_text(_('Error in received dataform'))
|
||||||
|
self.label.show()
|
||||||
|
return
|
||||||
|
|
||||||
|
self.search_vbox.pack_start(self.data_form_widget)
|
||||||
|
self.data_form_widget.show()
|
||||||
|
if self.data_form_widget.title:
|
||||||
|
self.window.set_title('%s - Search - Gajim' % \
|
||||||
|
self.data_form_widget.title)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue