diff --git a/frontends/wix/form.py b/frontends/wix/form.py
new file mode 100644
index 00000000..bb7f18e8
--- /dev/null
+++ b/frontends/wix/form.py
@@ -0,0 +1,103 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+"""
+wix: a SAT frontend
+Copyright (C) 2009 Jérôme Poisson (goffi@goffi.org)
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see .
+"""
+
+
+
+import wx
+import pdb
+from xml.dom import minidom
+from logging import debug, info, error
+from tools.jid import JID
+
+
+class Form(wx.Frame):
+ def __init__(self, host, xml_data='', title="Form", type="Form"):
+ super(Form, self).__init__(None, title=title)
+
+ self.host = host
+
+ self.modified = {} # dict of modified data (i.e. what we have to save)
+ self.ctl_list = {} # usefull to access ctrl, key = (name, category)
+
+ self.sizer = wx.BoxSizer(wx.VERTICAL)
+ self.SetSizer(self.sizer)
+ self.SetAutoLayout(True)
+
+ #events
+ self.Bind(wx.EVT_CLOSE, self.onClose, self)
+
+ self.MakeModal()
+
+ self.constructForm(xml_data)
+
+ self.Show()
+
+ def constructForm(self, xml_data):
+ panel=wx.Panel(self)
+ panel.sizer = wx.BoxSizer(wx.VERTICAL)
+
+ cat_dom = minidom.parseString(xml_data.encode('utf-8'))
+
+ for elem in cat_dom.documentElement.getElementsByTagName("elem"):
+ name = elem.getAttribute("name")
+ label = elem.getAttribute("label") if elem.hasAttribute('label') else name
+ type = elem.getAttribute("type")
+ value = elem.firstChild.wholeText if elem.firstChild else u'' #TODO: must check if the first child is really the text value
+ sizer = wx.BoxSizer(wx.HORIZONTAL)
+ if type=="text":
+ ctrl = wx.StaticText(panel, -1, value)
+ elif type=="string":
+ label=wx.StaticText(panel, -1, label+": ")
+ ctrl = wx.TextCtrl(panel, -1, value)
+ sizer.Add(label)
+ elif type=="password":
+ label=wx.StaticText(panel, -1, label+": ")
+ ctrl = wx.TextCtrl(panel, -1, value, style=wx.TE_PASSWORD)
+ sizer.Add(label)
+ else:
+ error("FIXME FIXME FIXME: type [%s] is not implemented" % type) #FIXME !
+ raise NotImplementedError
+ sizer.Add(ctrl, 1, flag=wx.EXPAND)
+ #self.ctl_list[(name, category)] = ctrl
+ panel.sizer.Add(sizer, flag=wx.EXPAND)
+
+ if type=="string" or type=="password":
+ panel.Bind(wx.EVT_TEXT, self.onTextChanged, ctrl)
+
+ panel.SetSizer(panel.sizer)
+ panel.SetAutoLayout(True)
+ panel.sizer.Fit(self)
+ self.sizer.Add(panel, 1, flag=wx.EXPAND)
+ cat_dom.unlink()
+
+ def onTextChanged(self, event):
+ """Called when a formated is modified"""
+ #self.modified[event.GetEventObject().form_id]=event.GetString()
+
+ event.Skip()
+
+ def onClose(self, event):
+ """Close event: we have to send the form."""
+ debug("close")
+
+ self.MakeModal(False)
+ event.Skip()
+
diff --git a/frontends/wix/gateways.py b/frontends/wix/gateways.py
index 1a96af6d..615494e2 100644
--- a/frontends/wix/gateways.py
+++ b/frontends/wix/gateways.py
@@ -33,7 +33,6 @@ class GatewaysManager(wx.Frame):
super(GatewaysManager, self).__init__(None, title=title)
self.host = host
- #self.gateways = gateways
#Fonts
self.normal_font = wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.NORMAL)
diff --git a/frontends/wix/main_window.py b/frontends/wix/main_window.py
index bb9da9e0..757c3b43 100644
--- a/frontends/wix/main_window.py
+++ b/frontends/wix/main_window.py
@@ -23,6 +23,7 @@ along with this program. If not, see .
import wx
from chat import Chat
from param import Param
+from form import Form
from gateways import GatewaysManager
import gobject
import os.path
@@ -329,7 +330,8 @@ class MainWindow(wx.Frame, QuickApp):
dlg.Destroy()
elif type == "FORM":
self.current_action_ids.remove(id)
- info ("Form received !")
+ debug ("Form received")
+ form=Form(self, title='Registration', type = data['type'], xml_data = data['xml'])
elif type == "DICT_DICT":
self.current_action_ids.remove(id)
if self.current_action_ids_cb.has_key(id):
diff --git a/plugins/plugin_xep_0077.py b/plugins/plugin_xep_0077.py
index 19a6f9ac..fb59ec0b 100755
--- a/plugins/plugin_xep_0077.py
+++ b/plugins/plugin_xep_0077.py
@@ -48,7 +48,6 @@ class XEP_0077():
def reg_ok(self, answer):
"""Called after the first get IQ"""
- print "answer:",answer
form = data_form.Form.fromElement(answer.firstChildElement().firstChildElement())
xml_data = XMLTools.dataForm2xml(form)
self.host.bridge.actionResult("FORM", answer['id'], {"type":"registration", "xml":xml_data})
diff --git a/tools/xml_tools.py b/tools/xml_tools.py
index 5707e8c3..c748207f 100644
--- a/tools/xml_tools.py
+++ b/tools/xml_tools.py
@@ -30,9 +30,20 @@ class XMLTools:
@staticmethod
def dataForm2xml(form):
"""Take a data form (xep-0004, Wokkel's implementation) and convert it to a SàT xml"""
- result_xml = ["
"]
+
+ impl = minidom.getDOMImplementation()
+
+ doc = impl.createDocument(None, "form", None)
+ top_element = doc.documentElement
+
+ #result_xml = [""]
if form.instructions:
- result_xml.insert(1,"" % '\n'.join(form.instructions))
+ elem = doc.createElement('elem')
+ elem.setAttribute('name','instructions')
+ elem.setAttribute('type','text')
+ text = doc.createTextNode('\n'.join(form.instructions))
+ elem.appendChild(text)
+ top_element.appendChild(elem)
for field in form.fieldList:
if field.fieldType == 'text-single':
__field_type = "string"
@@ -42,11 +53,14 @@ class XMLTools:
error (u"FIXME FIXME FIXME: Type [%s] is not managed yet by SàT" % field.fieldType)
__field_type = "string_field"
- result_xml.insert(-1,"" % (field.var, __field_type, field.label))
-
- return '\n'.join(result_xml)
-
-
-
-
- pdb.set_trace()
+ elem = doc.createElement('elem')
+ elem.setAttribute('name', field.var)
+ elem.setAttribute('type', __field_type)
+ elem.setAttribute('label', field.label)
+ #text = doc.createTextNode(field.value)
+ #elem.appendChild(text)
+ top_element.appendChild(elem)
+
+ result = doc.toxml()
+ doc.unlink()
+ return result