diff --git a/src/common/connection.py b/src/common/connection.py index 79dfde839..45c91ed12 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -228,7 +228,7 @@ class Connection(ConnectionHandlers): return is_form = data[2] if is_form: - conf = self.parse_data_form(data[1]) + conf = data[1] else: conf = data[1].asDict() self.dispatch('REGISTER_AGENT_INFO', (data[0], conf, is_form)) diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index fe6bf0389..c4674a634 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -608,37 +608,15 @@ class ConnectionDisco: agent) self.connection.SendAndCallForResponse(iq, self._ReceivedRegInfo, {'agent': agent}) - - def build_data_from_dict(self, query, config): - x = query.setTag(common.xmpp.NS_DATA + ' x', attrs = {'type': 'submit'}) - i = 0 - while config.has_key(i): - if not config[i].has_key('type'): - i += 1 - continue - if config[i]['type'] == 'fixed': - i += 1 - continue - tag = x.addChild('field') - if config[i].has_key('var'): - tag.setAttr('var', config[i]['var']) - if config[i].has_key('values'): - for val in config[i]['values']: - if val == False: - val = '0' - elif val == True: - val = '1' - # Force to create a new child - tag.addChild('value').addData(val) - i += 1 - + def register_agent(self, agent, info, is_form = False): if not self.connection: return if is_form: iq = common.xmpp.Iq('set', common.xmpp.NS_REGISTER, to = agent) query = iq.getTag('query') - self.build_data_from_dict(query, info) + info.setAttr('type', 'submit') + query.addChild(node = info) self.connection.send(iq) else: # fixed: blocking @@ -1778,67 +1756,9 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, self.dispatch('NOTIFY', (jid_stripped, show, status, resource, prio, keyID, timestamp)) # END presenceCB + def _StanzaArrivedCB(self, con, obj): self.last_io = gajim.idlequeue.current_time() - - - def parse_data_form(self, node): - dic = {} - tag = node.getTag('title') - if tag: - dic['title'] = tag.getData() - tag = node.getTag('instructions') - if tag: - dic['instructions'] = tag.getData() - i = 0 - for child in node.getChildren(): - if child.getName() != 'field': - continue - var = child.getAttr('var') - ctype = child.getAttr('type') - label = child.getAttr('label') - if not var and ctype != 'fixed': # We must have var if type != fixed - continue - dic[i] = {} - if var: - dic[i]['var'] = var - if ctype: - dic[i]['type'] = ctype - if label: - dic[i]['label'] = label - tags = child.getTags('value') - if len(tags): - dic[i]['values'] = [] - for tag in tags: - data = tag.getData() - if ctype == 'boolean': - if data in ('yes', 'true', 'assent', '1'): - data = True - else: - data = False - dic[i]['values'].append(data) - tag = child.getTag('desc') - if tag: - dic[i]['desc'] = tag.getData() - option_tags = child.getTags('option') - if len(option_tags): - dic[i]['options'] = {} - j = 0 - for option_tag in option_tags: - dic[i]['options'][j] = {} - label = option_tag.getAttr('label') - tags = option_tag.getTags('value') - dic[i]['options'][j]['values'] = [] - for tag in tags: - dic[i]['options'][j]['values'].append(tag.getData()) - if not label: - label = dic[i]['options'][j]['values'][0] - dic[i]['options'][j]['label'] = label - j += 1 - if not dic[i].has_key('values'): - dic[i]['values'] = [dic[i]['options'][0]['values'][0]] - i += 1 - return dic def _MucOwnerCB(self, con, iq_obj): gajim.log.debug('MucOwnerCB') diff --git a/src/config.py b/src/config.py index 5ed408a6e..dd2654412 100644 --- a/src/config.py +++ b/src/config.py @@ -2079,165 +2079,27 @@ class AccountsWindow: gajim.connections[gajim.ZEROCONF_ACC_NAME].change_status('online', '') self.on_checkbutton_toggled(widget, 'enable_zeroconf') - -class DataFormWindow: - def __init__(self, account, config): - self.account = account - self.config = config - self.xml = gtkgui_helpers.get_glade('data_form_window.glade', 'data_form_window') - self.window = self.xml.get_widget('data_form_window') - self.window.set_transient_for(gajim.interface.roster.window) - self.config_vbox = self.xml.get_widget('config_vbox') - if config: - self.fill_vbox() - else: - self.config_vbox.set_no_show_all(True) - self.config_vbox.hide() - self.xml.signal_autoconnect(self) - self.window.show_all() - def on_cancel_button_clicked(self, widget): - self.window.destroy() - - def on_ok_button_clicked(self, widget): - '''NOTE: child class should implement this''' - pass - - def on_data_form_window_destroy(self, widget): - '''NOTE: child class should implement this''' - pass - - def on_checkbutton_toggled(self, widget, index): - self.config[index]['values'][0] = widget.get_active() - - def on_checkbutton_toggled2(self, widget, index1, index2): - val = self.config[index1]['options'][index2]['values'][0] - if widget.get_active() and val not in self.config[index1]['values']: - self.config[index1]['values'].append(val) - elif not widget.get_active() and val in self.config[index1]['values']: - self.config[index1]['values'].remove(val) - - def on_combobox_changed(self, widget, index): - self.config[index]['values'][0] = self.config[index]['options'][ \ - widget.get_active()]['values'][0] - - def on_entry_changed(self, widget, index): - self.config[index]['values'][0] = widget.get_text().decode('utf-8') - - def on_textbuffer_changed(self, widget, index): - begin, end = widget.get_bounds() - self.config[index]['values'][0] = widget.get_text(begin, end) - - def fill_vbox(self): - '''see JEP0004''' - if self.config.has_key('title'): - self.window.set_title(self.config['title']) - if self.config.has_key('instructions'): - self.xml.get_widget('instructions_label').set_text( - self.config['instructions']) - i = 0 - while self.config.has_key(i): - if not self.config[i].has_key('type'): - i += 1 - continue - ctype = self.config[i]['type'] - if ctype == 'hidden': - i += 1 - continue - hbox = gtk.HBox(spacing = 5) - label = gtk.Label('') - label.set_line_wrap(True) - label.set_alignment(0.0, 0.5) - label.set_property('width_request', 150) - hbox.pack_start(label, False) - if self.config[i].has_key('label'): - label.set_text(self.config[i]['label']) - if ctype == 'boolean': - desc = None - if self.config[i].has_key('desc'): - desc = self.config[i]['desc'] - widget = gtk.CheckButton(desc, False) - activ = False - if self.config[i].has_key('values'): - activ = self.config[i]['values'][0] - widget.set_active(activ) - widget.connect('toggled', self.on_checkbutton_toggled, i) - elif ctype == 'fixed': - widget = gtk.Label('\n'.join(self.config[i]['values'])) - widget.set_line_wrap(True) - widget.set_alignment(0.0, 0.5) - elif ctype == 'jid-multi': - #FIXME - widget = gtk.Label('') - elif ctype == 'jid-single': - #FIXME - widget = gtk.Label('') - elif ctype == 'list-multi': - j = 0 - widget = gtk.Table(1, 1) - while self.config[i]['options'].has_key(j): - widget.resize(j + 1, 1) - child = gtk.CheckButton(self.config[i]['options'][j]['label'], - False) - if self.config[i]['options'][j]['values'][0] in \ - self.config[i]['values']: - child.set_active(True) - child.connect('toggled', self.on_checkbutton_toggled2, i, j) - widget.attach(child, 0, 1, j, j+1) - j += 1 - elif ctype == 'list-single': - widget = gtk.combo_box_new_text() - widget.connect('changed', self.on_combobox_changed, i) - index = 0 - j = 0 - while self.config[i]['options'].has_key(j): - if self.config[i]['options'][j]['values'][0] == \ - self.config[i]['values'][0]: - index = j - widget.append_text(self.config[i]['options'][j]['label']) - j += 1 - widget.set_active(index) - elif ctype == 'text-multi': - widget = gtk.TextView() - widget.set_size_request(100, -1) - widget.get_buffer().connect('changed', self.on_textbuffer_changed, \ - i) - widget.get_buffer().set_text('\n'.join(self.config[i]['values'])) - elif ctype == 'text-private': - widget = gtk.Entry() - widget.connect('changed', self.on_entry_changed, i) - if not self.config[i].has_key('values'): - self.config[i]['values'] = [''] - widget.set_text(self.config[i]['values'][0]) - widget.set_visibility(False) - elif ctype == 'text-single': - widget = gtk.Entry() - widget.connect('changed', self.on_entry_changed, i) - if not self.config[i].has_key('values'): - self.config[i]['values'] = [''] - widget.set_text(self.config[i]['values'][0]) - i += 1 - hbox.pack_start(widget, False) - hbox.pack_start(gtk.Label('')) # So that widhet doesn't take all space - self.config_vbox.pack_start(hbox, False) - self.config_vbox.show_all() - -class ServiceRegistrationWindow(DataFormWindow): +class ServiceRegistrationWindow: '''Class for Service registration window: Window that appears when we want to subscribe to a service - if is_form we use DataFormWindow else we use service_registarion_window''' + if is_form we use dataforms_widget else we use service_registarion_window''' def __init__(self, service, infos, account, is_form): self.service = service self.infos = infos self.account = account self.is_form = is_form + self.xml = gtkgui_helpers.get_glade('service_registration_window.glade') + self.window = self.xml.get_widget('service_registration_window') + self.window.set_transient_for(gajim.interface.roster.window) if self.is_form: - DataFormWindow.__init__(self, account, infos) + dataform = dataforms.ExtendForm(node = self.infos) + self.data_form_widget = dataforms_widget.DataFormWidget(dataform) + if self.data_form_widget.title: + self.window.set_title("%s - Gajim" % self.data_form_widget.title) + table = self.xml.get_widget('table') + table.attach(self.data_form_widget, 0, 2, 0, 1) else: - self.xml = gtkgui_helpers.get_glade( - 'service_registration_window.glade') - self.window = self.xml.get_widget('service_registration_window') - self.window.set_transient_for(gajim.interface.roster.window) if infos.has_key('registered'): self.window.set_title(_('Edit %s') % service) else: @@ -2245,8 +2107,9 @@ class ServiceRegistrationWindow(DataFormWindow): self.xml.get_widget('label').set_text(infos['instructions']) self.entries = {} self.draw_table() - self.xml.signal_autoconnect(self) - self.window.show_all() + + self.xml.signal_autoconnect(self) + self.window.show_all() def on_cancel_button_clicked(self, widget): self.window.destroy() @@ -2279,11 +2142,9 @@ class ServiceRegistrationWindow(DataFormWindow): def on_ok_button_clicked(self, widget): if self.is_form: - # We pressed OK button of the DataFormWindow - if self.infos.has_key('registered'): - del self.infos['registered'] + form = self.data_form_widget.data_form gajim.connections[self.account].register_agent(self.service, - self.infos, True) # True is for is_form + form, True) # True is for is_form else: # we pressed OK of service_registration_window # send registration info to the core @@ -2470,7 +2331,6 @@ class GroupchatConfigWindow: del gajim.interface.instances[self.account]['gc_config'][self.room_jid] def on_ok_button_clicked(self, widget): - # We pressed OK button of the DataFormWindow if self.form: form = self.data_form_widget.data_form gajim.connections[self.account].send_gc_config(self.room_jid, form) diff --git a/src/gajim.py b/src/gajim.py index ac87fed68..4d615918f 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -911,8 +911,9 @@ class Interface: self.roster.remove_contact(c, account) def handle_event_register_agent_info(self, account, array): - #('REGISTER_AGENT_INFO', account, (agent, infos, is_form)) - if array[1].has_key('instructions'): + # ('REGISTER_AGENT_INFO', account, (agent, infos, is_form)) + # info in a dataform if is_form is True + if array[2] or array[1].has_key('instructions'): config.ServiceRegistrationWindow(array[0], array[1], account, array[2]) else: