Implementing error type=modify handling for XEP-0077

This commit is contained in:
Alexander Bogdanov 2019-04-16 18:33:32 +02:00 committed by Philipp Hörist
parent 2f9b716ab0
commit 64bac1d910
2 changed files with 63 additions and 27 deletions

View File

@ -87,7 +87,10 @@ class Register(BaseModule):
error = stanza.getErrorMsg()
self._log.info('Error: %s', error)
if error_cb() is not None:
error_cb()(error)
form = is_form = None
if stanza.getErrorType() == 'modify':
form, is_form = self._get_register_form(stanza)
error_cb()(error, form, is_form)
return
self._con.get_module('Presence').subscribe(agent, auto_auth=True)
@ -119,19 +122,25 @@ class Register(BaseModule):
error_cb()(error)
else:
self._log.info('Register form received')
parse_bob_data(stanza.getQuery())
form = stanza.getQuery().getTag('x', namespace=nbxmpp.NS_DATA)
is_form = form is not None
if not is_form:
form = {}
for field in stanza.getQueryPayload():
if not isinstance(field, nbxmpp.Node):
continue
form[field.getName()] = field.getData()
if success_cb() is not None:
form, is_form = self._get_register_form(stanza)
success_cb()(form, is_form)
@staticmethod
def _get_register_form(stanza):
parse_bob_data(stanza.getQuery())
form = stanza.getQuery().getTag('x', namespace=nbxmpp.NS_DATA)
is_form = form is not None
if not is_form:
form = {}
for field in stanza.getQueryPayload():
if not isinstance(field, nbxmpp.Node):
continue
form[field.getName()] = field.getData()
return form, is_form
def get_instance(*args, **kwargs):
return Register(*args, **kwargs), 'Register'

View File

@ -75,6 +75,18 @@ class ServiceRegistration(Gtk.Assistant):
sidebar = main_box.get_children()[0]
main_box.remove(sidebar)
def _build_dataform(self, form, is_form):
if not is_form:
from gajim import config
return config.FakeDataForm(form)
dataform = dataforms.extend_form(node=form)
form_widget = DataFormWidget(dataform)
form_widget.connect('is-valid', self._on_is_valid)
form_widget.validate()
return form_widget
def _on_page_change(self, assistant, page):
if self.get_current_page() == Page.REQUEST:
self._con.get_module('Register').get_register_form(
@ -86,28 +98,24 @@ class ServiceRegistration(Gtk.Assistant):
def _on_get_success(self, form, is_form):
log.info('Show Form page')
self._is_form = is_form
if is_form:
dataform = dataforms.extend_form(node=form)
self._data_form_widget = DataFormWidget(dataform)
self._data_form_widget.connect('is-valid', self._on_is_valid)
self._data_form_widget.validate()
else:
from gajim import config
self._data_form_widget = config.FakeDataForm(form)
page = self.get_nth_page(Page.FORM)
page.pack_start(self._data_form_widget, True, True, 0)
self._data_form_widget.show_all()
self._data_form_widget = self._build_dataform(form, is_form)
self.get_nth_page(Page.FORM).set_form(self._data_form_widget)
self.set_current_page(Page.FORM)
def _on_is_valid(self, _widget, is_valid):
self.set_page_complete(self.get_nth_page(Page.FORM), is_valid)
def _on_error(self, error_text):
log.info('Show Error page')
page = self.get_nth_page(Page.ERROR)
page.set_text(error_text)
self.set_current_page(Page.ERROR)
def _on_error(self, error_text, form=None, is_form=False):
if form is not None:
log.info('Show Form page')
self._is_form = is_form
self._data_form_widget = self._build_dataform(form, is_form)
self.get_nth_page(Page.FORM).set_form(self._data_form_widget, error_text=error_text)
self.set_current_page(Page.FORM)
else:
log.info('Show Error page')
self.get_nth_page(Page.ERROR).set_text(error_text)
self.set_current_page(Page.ERROR)
def _on_cancel(self, widget):
self.destroy()
@ -164,6 +172,25 @@ class FormPage(Gtk.Box):
def __init__(self):
super().__init__(orientation=Gtk.Orientation.VERTICAL)
self._form = None
self._label = Gtk.Label()
self._label.set_no_show_all(True)
self._label.get_style_context().add_class('error-color')
self.pack_end(self._label, False, False, 0)
def set_form(self, form, error_text=None):
if self._form is not None:
self.remove(self._form)
self._form.destroy()
self._label.hide()
self._form = form
if error_text is not None:
self._label.set_text(error_text)
self._label.show()
self.pack_start(form, True, True, 0)
self._form.show_all()
class SuccessfulPage(Gtk.Box):