Move SearchWindow to gtk folder
This commit is contained in:
parent
39dfe41af5
commit
88f30f92f7
|
@ -52,7 +52,6 @@ from gi.repository import GdkPixbuf
|
|||
from gajim import gtkgui_helpers
|
||||
from gajim import groups
|
||||
from gajim import adhoc_commands
|
||||
from gajim import search_window
|
||||
|
||||
from gajim.common import app
|
||||
from gajim.common.i18n import _
|
||||
|
@ -62,6 +61,7 @@ from gajim.common.const import StyleAttr
|
|||
from gajim.gtk.dialogs import ErrorDialog
|
||||
from gajim.gtk.dialogs import InformationDialog
|
||||
from gajim.gtk.service_registration import ServiceRegistration
|
||||
from gajim.gtk.discovery_search import SearchWindow
|
||||
|
||||
LABELS = {
|
||||
1: _('This service has not yet responded with detailed information'),
|
||||
|
@ -1299,7 +1299,7 @@ class ToplevelAgentBrowser(AgentBrowser):
|
|||
present()
|
||||
else:
|
||||
app.interface.instances[self.account]['search'][service] = \
|
||||
search_window.SearchWindow(self.account, service)
|
||||
SearchWindow(self.account, service)
|
||||
|
||||
def cleanup(self):
|
||||
AgentBrowser.cleanup(self)
|
||||
|
|
|
@ -24,33 +24,25 @@ from gajim.common import ged
|
|||
from gajim.common.modules import dataforms
|
||||
from gajim.common.i18n import _
|
||||
|
||||
from gajim import gtkgui_helpers
|
||||
from gajim import vcard
|
||||
from gajim import config
|
||||
from gajim import dataforms_widget
|
||||
|
||||
from gajim.gtk.util import get_builder
|
||||
from gajim.gtk.add_contact import AddNewContactWindow
|
||||
|
||||
|
||||
class SearchWindow:
|
||||
def __init__(self, account, jid):
|
||||
"""
|
||||
Create new window
|
||||
"""
|
||||
# an account object
|
||||
self.account = account
|
||||
self.jid = jid
|
||||
|
||||
# retrieving widgets from xml
|
||||
self.xml = gtkgui_helpers.get_gtk_builder('search_window.ui')
|
||||
self.window = self.xml.get_object('search_window')
|
||||
for name in ('label', 'progressbar', 'search_vbox', 'search_button',
|
||||
'add_contact_button', 'information_button'):
|
||||
self.__dict__[name] = self.xml.get_object(name)
|
||||
self._ui = get_builder('search_window.ui')
|
||||
self.window = self._ui.search_window
|
||||
|
||||
self.search_button.set_sensitive(False)
|
||||
self._ui.search_button.set_sensitive(False)
|
||||
|
||||
# displaying the window
|
||||
self.xml.connect_signals(self)
|
||||
self._ui.connect_signals(self)
|
||||
self.window.show_all()
|
||||
self.request_form()
|
||||
self.pulse_id = GLib.timeout_add(80, self.pulse_callback)
|
||||
|
@ -60,36 +52,40 @@ class SearchWindow:
|
|||
# Is there a jid column in results ? if -1: no, else column number
|
||||
self.jid_column = -1
|
||||
|
||||
app.ged.register_event_handler('search-form-received', ged.GUI1,
|
||||
self._nec_search_form_received)
|
||||
app.ged.register_event_handler('search-result-received', ged.GUI1,
|
||||
self._nec_search_result_received)
|
||||
app.ged.register_event_handler('search-form-received',
|
||||
ged.GUI1,
|
||||
self._nec_search_form_received)
|
||||
app.ged.register_event_handler('search-result-received',
|
||||
ged.GUI1,
|
||||
self._nec_search_result_received)
|
||||
|
||||
def request_form(self):
|
||||
con = app.connections[self.account]
|
||||
con.get_module('Search').request_search_fields(self.jid)
|
||||
|
||||
def pulse_callback(self):
|
||||
self.progressbar.pulse()
|
||||
self._ui.progressbar.pulse()
|
||||
return True
|
||||
|
||||
def on_search_window_key_press_event(self, widget, event):
|
||||
def on_search_window_key_press_event(self, _widget, event):
|
||||
if event.keyval == Gdk.KEY_Escape:
|
||||
self.window.destroy()
|
||||
|
||||
def on_search_window_destroy(self, widget):
|
||||
def on_search_window_destroy(self, _widget):
|
||||
if self.pulse_id:
|
||||
GLib.source_remove(self.pulse_id)
|
||||
del app.interface.instances[self.account]['search'][self.jid]
|
||||
app.ged.remove_event_handler('search-form-received', ged.GUI1,
|
||||
self._nec_search_form_received)
|
||||
app.ged.remove_event_handler('search-result-received', ged.GUI1,
|
||||
self._nec_search_result_received)
|
||||
app.ged.remove_event_handler('search-form-received',
|
||||
ged.GUI1,
|
||||
self._nec_search_form_received)
|
||||
app.ged.remove_event_handler('search-result-received',
|
||||
ged.GUI1,
|
||||
self._nec_search_result_received)
|
||||
|
||||
def on_close_button_clicked(self, button):
|
||||
def on_close_button_clicked(self, _button):
|
||||
self.window.destroy()
|
||||
|
||||
def on_search_button_clicked(self, button):
|
||||
def on_search_button_clicked(self, _button):
|
||||
con = app.connections[self.account]
|
||||
if self.is_form:
|
||||
self.data_form_widget.data_form.type_ = 'submit'
|
||||
|
@ -101,22 +97,22 @@ class SearchWindow:
|
|||
del infos['instructions']
|
||||
con.get_module('Search').send_search_form(self.jid, infos, False)
|
||||
|
||||
self.search_vbox.remove(self.data_form_widget)
|
||||
self._ui.search_vbox.remove(self.data_form_widget)
|
||||
|
||||
self.progressbar.show()
|
||||
self.label.set_text(_('Waiting for results'))
|
||||
self.label.show()
|
||||
self._ui.progressbar.show()
|
||||
self._ui.label.set_text(_('Waiting for results'))
|
||||
self._ui.label.show()
|
||||
self.pulse_id = GLib.timeout_add(80, self.pulse_callback)
|
||||
self.search_button.hide()
|
||||
self._ui.search_button.hide()
|
||||
|
||||
def on_add_contact_button_clicked(self, widget):
|
||||
def on_add_contact_button_clicked(self, _widget):
|
||||
(model, iter_) = self.result_treeview.get_selection().get_selected()
|
||||
if not iter_:
|
||||
return
|
||||
jid = model[iter_][self.jid_column]
|
||||
AddNewContactWindow(self.account, jid)
|
||||
|
||||
def on_information_button_clicked(self, widget):
|
||||
def on_information_button_clicked(self, _widget):
|
||||
(model, iter_) = self.result_treeview.get_selection().get_selected()
|
||||
if not iter_:
|
||||
return
|
||||
|
@ -131,8 +127,8 @@ class SearchWindow:
|
|||
def _nec_search_form_received(self, obj):
|
||||
if self.pulse_id:
|
||||
GLib.source_remove(self.pulse_id)
|
||||
self.progressbar.hide()
|
||||
self.label.hide()
|
||||
self._ui.progressbar.hide()
|
||||
self._ui.label.hide()
|
||||
|
||||
if obj.is_dataform:
|
||||
self.is_form = True
|
||||
|
@ -142,19 +138,19 @@ class SearchWindow:
|
|||
try:
|
||||
self.data_form_widget.data_form = self.dataform
|
||||
except dataforms.Error:
|
||||
self.label.set_text(_('Error in received dataform'))
|
||||
self.label.show()
|
||||
self._ui.label.set_text(_('Error in received dataform'))
|
||||
self._ui.label.show()
|
||||
return
|
||||
if self.data_form_widget.title:
|
||||
self.window.set_title('%s - Search - Gajim' % \
|
||||
self.data_form_widget.title)
|
||||
self.window.set_title(
|
||||
'%s - Search - Gajim' % self.data_form_widget.title)
|
||||
else:
|
||||
self.is_form = False
|
||||
self.data_form_widget = config.FakeDataForm(obj.data)
|
||||
|
||||
self.data_form_widget.show_all()
|
||||
self.search_vbox.pack_start(self.data_form_widget, True, True, 0)
|
||||
self.search_button.set_sensitive(True)
|
||||
self._ui.search_vbox.pack_start(self.data_form_widget, True, True, 0)
|
||||
self._ui.search_button.set_sensitive(True)
|
||||
|
||||
def on_result_treeview_cursor_changed(self, treeview):
|
||||
if self.jid_column == -1:
|
||||
|
@ -163,29 +159,29 @@ class SearchWindow:
|
|||
if not iter_:
|
||||
return
|
||||
if model[iter_][self.jid_column]:
|
||||
self.add_contact_button.set_sensitive(True)
|
||||
self.information_button.set_sensitive(True)
|
||||
self._ui.add_contact_button.set_sensitive(True)
|
||||
self._ui.information_button.set_sensitive(True)
|
||||
else:
|
||||
self.add_contact_button.set_sensitive(False)
|
||||
self.information_button.set_sensitive(False)
|
||||
self._ui.add_contact_button.set_sensitive(False)
|
||||
self._ui.information_button.set_sensitive(False)
|
||||
|
||||
def _nec_search_result_received(self, obj):
|
||||
if self.pulse_id:
|
||||
GLib.source_remove(self.pulse_id)
|
||||
self.progressbar.hide()
|
||||
self.label.hide()
|
||||
self._ui.progressbar.hide()
|
||||
self._ui.label.hide()
|
||||
|
||||
if not obj.is_dataform:
|
||||
if not obj.data:
|
||||
self.label.set_text(_('No result'))
|
||||
self.label.show()
|
||||
self._ui.label.set_text(_('No result'))
|
||||
self._ui.label.show()
|
||||
return
|
||||
# We suppose all items have the same fields
|
||||
sw = Gtk.ScrolledWindow()
|
||||
sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
|
||||
self.result_treeview = Gtk.TreeView()
|
||||
self.result_treeview.connect('cursor-changed',
|
||||
self.on_result_treeview_cursor_changed)
|
||||
self.result_treeview.connect(
|
||||
'cursor-changed', self.on_result_treeview_cursor_changed)
|
||||
sw.add(self.result_treeview)
|
||||
# Create model
|
||||
fieldtypes = [str]*len(obj.data[0])
|
||||
|
@ -196,39 +192,41 @@ class SearchWindow:
|
|||
# Create columns
|
||||
counter = 0
|
||||
for field in obj.data[0].keys():
|
||||
self.result_treeview.append_column(Gtk.TreeViewColumn(field,
|
||||
Gtk.CellRendererText(), text=counter))
|
||||
self.result_treeview.append_column(
|
||||
Gtk.TreeViewColumn(field,
|
||||
Gtk.CellRendererText(),
|
||||
text=counter))
|
||||
if field == 'jid':
|
||||
self.jid_column = counter
|
||||
counter += 1
|
||||
self.result_treeview.set_model(model)
|
||||
sw.show_all()
|
||||
self.search_vbox.pack_start(sw, True, True, 0)
|
||||
self._ui.search_vbox.pack_start(sw, True, True, 0)
|
||||
if self.jid_column > -1:
|
||||
self.add_contact_button.show()
|
||||
self.information_button.show()
|
||||
self._ui.add_contact_button.show()
|
||||
self._ui.information_button.show()
|
||||
return
|
||||
|
||||
self.dataform = dataforms.extend_form(node=obj.data)
|
||||
if not self.dataform.items:
|
||||
# No result
|
||||
self.label.set_text(_('No result'))
|
||||
self.label.show()
|
||||
self._ui.label.set_text(_('No result'))
|
||||
self._ui.label.show()
|
||||
return
|
||||
|
||||
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()
|
||||
self._ui.label.set_text(_('Error in received dataform'))
|
||||
self._ui.label.show()
|
||||
return
|
||||
|
||||
self.result_treeview = self.data_form_widget.records_treeview
|
||||
selection = self.result_treeview.get_selection()
|
||||
selection.set_mode(Gtk.SelectionMode.SINGLE)
|
||||
self.result_treeview.connect('cursor-changed',
|
||||
self.on_result_treeview_cursor_changed)
|
||||
self.result_treeview.connect(
|
||||
'cursor-changed', self.on_result_treeview_cursor_changed)
|
||||
|
||||
counter = 0
|
||||
for field in self.dataform.reported.iter_fields():
|
||||
|
@ -236,11 +234,11 @@ class SearchWindow:
|
|||
self.jid_column = counter
|
||||
break
|
||||
counter += 1
|
||||
self.search_vbox.pack_start(self.data_form_widget, True, True, 0)
|
||||
self._ui.search_vbox.pack_start(self.data_form_widget, True, True, 0)
|
||||
self.data_form_widget.show()
|
||||
if self.jid_column > -1:
|
||||
self.add_contact_button.show()
|
||||
self.information_button.show()
|
||||
self._ui.add_contact_button.show()
|
||||
self._ui.information_button.show()
|
||||
if self.data_form_widget.title:
|
||||
self.window.set_title('%s - Search - Gajim' % \
|
||||
self.data_form_widget.title)
|
||||
self.window.set_title(
|
||||
'%s - Search - Gajim' % self.data_form_widget.title)
|
Loading…
Reference in New Issue