Improve IBR form handling (#990)

* Change register account dialog to show instructions

Change data forms to handle title and instructions elements

* Change register account dialog to show fixed fields

Closes #988

* Change form switch to halign start

Closes #992

* Change register account dialog to markup URLs
This commit is contained in:
Michel Le Bihan 2021-02-17 22:57:53 +01:00 committed by GitHub
parent a417cb396b
commit e06cc08425
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 1 deletions

View file

@ -339,11 +339,20 @@ public class AddAccountDialog : Gtk.Dialog {
register_form_continue.visible = true; register_form_continue.visible = true;
register_form_continue.grab_focus(); register_form_continue.grab_focus();
} else if (form.fields.size > 0) { } else if (form.fields.size > 0) {
if (form.instructions != null && form.instructions != "") {
string markup_instructions = Util.parse_add_markup(form.instructions, null, true, false);
form_box.add(new Label(markup_instructions) { use_markup=true, halign=Align.CENTER, xalign=0, margin_top=7,
wrap=true, wrap_mode=Pango.WrapMode.WORD_CHAR, visible=true });
}
foreach (Xep.DataForms.DataForm.Field field in form.fields) { foreach (Xep.DataForms.DataForm.Field field in form.fields) {
Widget? field_widget = Util.get_data_form_field_widget(field); Widget? field_widget = Util.get_data_form_field_widget(field);
if (field.label != null && field.label != "" && field_widget != null) { if (field.label != null && field.label != "" && field_widget != null) {
form_box.add(new Label(field.label) { xalign=0, margin_top=7, visible=true }); form_box.add(new Label(field.label) { xalign=0, margin_top=7, visible=true });
form_box.add(field_widget); form_box.add(field_widget);
} else if (field.type_ == Xep.DataForms.DataForm.Type.FIXED && field.get_value_string() != "") {
string markup_fixed_field = Util.parse_add_markup(field.get_value_string(), null, true, false);
form_box.add(new Label(markup_fixed_field) { use_markup=true, xalign=0, margin_top=7,
wrap=true, wrap_mode=Pango.WrapMode.WORD_CHAR, visible=true });
} }
} }
register_form_continue.visible = true; register_form_continue.visible = true;

View file

@ -11,7 +11,7 @@ public static Widget? get_data_form_field_widget(DataForms.DataForm.Field field)
switch (field.type_) { switch (field.type_) {
case DataForms.DataForm.Type.BOOLEAN: case DataForms.DataForm.Type.BOOLEAN:
DataForms.DataForm.BooleanField boolean_field = field as DataForms.DataForm.BooleanField; DataForms.DataForm.BooleanField boolean_field = field as DataForms.DataForm.BooleanField;
Switch sw = new Switch() { active=boolean_field.value, valign=Align.CENTER, visible=true }; Switch sw = new Switch() { active=boolean_field.value, halign=Align.START, valign=Align.CENTER, visible=true };
sw.state_set.connect((state) => { sw.state_set.connect((state) => {
boolean_field.value = state; boolean_field.value = state;
return false; return false;

View file

@ -9,6 +9,8 @@ public class DataForm {
public StanzaNode stanza_node { get; set; } public StanzaNode stanza_node { get; set; }
public Gee.List<Field> fields = new ArrayList<Field>(); public Gee.List<Field> fields = new ArrayList<Field>();
public string? form_type = null; public string? form_type = null;
public string? instructions = null;
public string? title = null;
public StanzaNode get_submit_node() { public StanzaNode get_submit_node() {
stanza_node.set_attribute("type", "submit"); stanza_node.set_attribute("type", "submit");
@ -215,6 +217,16 @@ public class DataForm {
fields.add(new TextSingleField(field_node)); break; fields.add(new TextSingleField(field_node)); break;
} }
} }
StanzaNode? instructions_node = node.get_subnode("instructions", NS_URI);
if (instructions_node != null) {
instructions = instructions_node.get_string_content();
}
StanzaNode? title_node = node.get_subnode("title", NS_URI);
if (title_node != null) {
title = title_node.get_string_content();
}
} }
internal DataForm() { internal DataForm() {