introduce a FakeDataForm class that draws a table from dict {entry: value} and use it for service registration

This commit is contained in:
Yann Leboulanger 2007-05-22 17:55:25 +00:00
parent 0f3071ed06
commit cb104420d2
2 changed files with 65 additions and 75 deletions

View File

@ -2,6 +2,7 @@
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd"> <!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
<glade-interface> <glade-interface>
<widget class="GtkWindow" id="service_registration_window"> <widget class="GtkWindow" id="service_registration_window">
<property name="border_width">6</property> <property name="border_width">6</property>
<property name="title" translatable="yes">Register to</property> <property name="title" translatable="yes">Register to</property>
@ -18,6 +19,7 @@
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property> <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property> <property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<child> <child>
<widget class="GtkVBox" id="vbox12"> <widget class="GtkVBox" id="vbox12">
@ -25,31 +27,6 @@
<property name="homogeneous">False</property> <property name="homogeneous">False</property>
<property name="spacing">6</property> <property name="spacing">6</property>
<child>
<widget class="GtkLabel" id="label">
<property name="visible">True</property>
<property name="label" translatable="yes"></property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">True</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">4</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="padding">4</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
<child> <child>
<widget class="GtkTable" id="table"> <widget class="GtkTable" id="table">
<property name="visible">True</property> <property name="visible">True</property>
@ -232,4 +209,5 @@
</widget> </widget>
</child> </child>
</widget> </widget>
</glade-interface> </glade-interface>

View File

@ -2087,44 +2087,23 @@ class AccountsWindow:
self.on_checkbutton_toggled(widget, 'enable_zeroconf') self.on_checkbutton_toggled(widget, 'enable_zeroconf')
class ServiceRegistrationWindow: class FakeDataForm(gtk.Table, object):
'''Class for Service registration window: '''Class for forms that are in XML format <entry1>value1</entry1>
Window that appears when we want to subscribe to a service infos in a table {entry1: value1, }'''
if is_form we use dataforms_widget else we use service_registarion_window''' def __init__(self, infos):
def __init__(self, service, infos, account, is_form): gtk.Table.__init__(self)
self.service = service
self.infos = infos 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:
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:
if infos.has_key('registered'):
self.window.set_title(_('Edit %s') % service)
else:
self.window.set_title(_('Register to %s') % service)
self.xml.get_widget('label').set_text(infos['instructions'])
self.entries = {} self.entries = {}
self.draw_table() self._draw_table()
self.xml.signal_autoconnect(self) def _draw_table(self):
self.window.show_all()
def on_cancel_button_clicked(self, widget):
self.window.destroy()
def draw_table(self):
'''Draw the table in the window''' '''Draw the table in the window'''
nbrow = 0 nbrow = 0
table = self.xml.get_widget('table') if self.infos.has_key('instructions'):
nbrow = 1
self.resize(rows = nbrow, columns = 2)
label = gtk.Label(self.infos['instructions'])
self.attach(label, 0, 2, 0, 1, 0, 0, 0, 0)
for name in self.infos.keys(): for name in self.infos.keys():
if name in ('key', 'instructions', 'x', 'registered'): if name in ('key', 'instructions', 'x', 'registered'):
continue continue
@ -2132,41 +2111,74 @@ class ServiceRegistrationWindow:
continue continue
nbrow = nbrow + 1 nbrow = nbrow + 1
table.resize(rows = nbrow, columns = 2) self.resize(rows = nbrow, columns = 2)
label = gtk.Label(name.capitalize() + ':') label = gtk.Label(name.capitalize() + ':')
table.attach(label, 0, 1, nbrow - 1, nbrow, 0, 0, 0, 0) self.attach(label, 0, 1, nbrow - 1, nbrow, 0, 0, 0, 0)
entry = gtk.Entry() entry = gtk.Entry()
entry.set_activates_default(True) entry.set_activates_default(True)
if self.infos[name]: if self.infos[name]:
entry.set_text(self.infos[name]) entry.set_text(self.infos[name])
if name == 'password': if name == 'password':
entry.set_visibility(False) entry.set_visibility(False)
table.attach(entry, 1, 2, nbrow - 1, nbrow, 0, 0, 0, 0) self.attach(entry, 1, 2, nbrow - 1, nbrow, 0, 0, 0, 0)
self.entries[name] = entry self.entries[name] = entry
if nbrow == 1: if nbrow == 1:
entry.grab_focus() entry.grab_focus()
table.show_all()
def get_infos(self):
for name in self.entries.keys():
self.infos[name] = self.entries[name].get_text().decode('utf-8')
return self.infos
class ServiceRegistrationWindow:
'''Class for Service registration window:
Window that appears when we want to subscribe to a service
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.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:
dataform = dataforms.ExtendForm(node = 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:
if infos.has_key('registered'):
self.window.set_title(_('Edit %s') % service)
else:
self.window.set_title(_('Register to %s') % service)
self.data_form_widget = FakeDataForm(infos)
table = self.xml.get_widget('table')
table.attach(self.data_form_widget, 0, 2, 0, 1)
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): def on_ok_button_clicked(self, widget):
# send registration info to the core
if self.is_form: if self.is_form:
form = self.data_form_widget.data_form form = self.data_form_widget.data_form
gajim.connections[self.account].register_agent(self.service, gajim.connections[self.account].register_agent(self.service,
form, True) # True is for is_form form, True) # True is for is_form
else: else:
# we pressed OK of service_registration_window infos = self.data_form_widget.get_infos()
# send registration info to the core if infos.has_key('instructions'):
for name in self.entries.keys(): del infos['instructions']
self.infos[name] = self.entries[name].get_text().decode('utf-8') if infos.has_key('registered'):
if self.infos.has_key('instructions'): del infos['registered']
del self.infos['instructions'] gajim.connections[self.account].register_agent(self.service, infos)
if self.infos.has_key('registered'):
del self.infos['registered']
gajim.connections[self.account].register_agent(self.service,
self.infos)
self.window.destroy() self.window.destroy()
class GroupchatConfigWindow: class GroupchatConfigWindow:
'''GroupchatConfigWindow class''' '''GroupchatConfigWindow class'''
def __init__(self, account, room_jid, form = None): def __init__(self, account, room_jid, form = None):