From 3a8df2069eba3a5a4174749fc46a6698c1877ec1 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Tue, 30 May 2017 22:17:41 +0200 Subject: MUC config form (data forms), MUC room info --- xmpp-vala/src/module/xep/0004_data_forms.vala | 208 ++++++++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 xmpp-vala/src/module/xep/0004_data_forms.vala (limited to 'xmpp-vala/src/module/xep/0004_data_forms.vala') diff --git a/xmpp-vala/src/module/xep/0004_data_forms.vala b/xmpp-vala/src/module/xep/0004_data_forms.vala new file mode 100644 index 00000000..add2fa9a --- /dev/null +++ b/xmpp-vala/src/module/xep/0004_data_forms.vala @@ -0,0 +1,208 @@ +using Gee; + +using Xmpp.Core; + +namespace Xmpp.Xep.DataForms { + +public const string NS_URI = "jabber:x:data"; + +public class DataForm { + + public StanzaNode stanza_node { get; set; } + public Gee.List fields = new ArrayList(); + + public XmppStream stream; + public OnResult on_result; + public Object? store; + + public void cancel() { + StanzaNode stanza_node = new StanzaNode.build("x", NS_URI); + stanza_node.add_self_xmlns().set_attribute("type", "cancel"); + on_result(stream, stanza_node, store); + } + + public void submit() { + stanza_node.set_attribute("type", "submit"); + on_result(stream, stanza_node, store); + } + + public enum Type { + BOOLEAN, + FIXED, + HIDDEN, + JID_MULTI, + LIST_SINGLE, + LIST_MULTI, + TEXT_PRIVATE, + TEXT_SINGLE, + } + + public class Option { + public string label { get; set; } + public string value { get; set; } + + public Option(string label, string value) { + this.label = label; + this.value = value; + } + } + + public abstract class Field { + public string label { + get { return node.get_attribute("label", NS_URI); } + set { node.set_attribute("label", value); } + } + public StanzaNode node { get; set; } + public abstract Type type_ { get; internal set; } + public string var { + get { return node.get_attribute("var", NS_URI); } + set { node.set_attribute("var", value); } + } + + public Field(StanzaNode node) { + this.node = node; + } + + internal Gee.List get_values() { + Gee.List ret = new ArrayList(); + Gee.List value_nodes = node.get_subnodes("value", NS_URI); + foreach (StanzaNode node in value_nodes) { + ret.add(node.get_string_content()); + } + return ret; + } + + internal string get_value_string() { + Gee.List values = get_values(); + return values.size > 0 ? values[0] : ""; + } + + internal void set_value_string(string val) { + StanzaNode? value_node = node.get_subnode("value", NS_URI); + if (value_node == null) { + value_node = new StanzaNode.build("value", NS_URI); + node.put_node(value_node); + } + value_node.sub_nodes.clear(); + value_node.put_node(new StanzaNode.text(val)); + } + + internal void add_value_string(string val) { + StanzaNode node = new StanzaNode.build("value"); + node.put_node(new StanzaNode.text(val)); + } + + internal Gee.List