introduce a FakeDataForm class that draws a table from dict {entry: value} and use it for service registration
This commit is contained in:
parent
0f3071ed06
commit
cb104420d2
|
@ -2,6 +2,7 @@
|
|||
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
|
||||
|
||||
<glade-interface>
|
||||
|
||||
<widget class="GtkWindow" id="service_registration_window">
|
||||
<property name="border_width">6</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="gravity">GDK_GRAVITY_NORTH_WEST</property>
|
||||
<property name="focus_on_map">True</property>
|
||||
<property name="urgency_hint">False</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkVBox" id="vbox12">
|
||||
|
@ -25,31 +27,6 @@
|
|||
<property name="homogeneous">False</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>
|
||||
<widget class="GtkTable" id="table">
|
||||
<property name="visible">True</property>
|
||||
|
@ -232,4 +209,5 @@
|
|||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
</glade-interface>
|
||||
|
|
108
src/config.py
108
src/config.py
|
@ -2087,44 +2087,23 @@ class AccountsWindow:
|
|||
|
||||
self.on_checkbutton_toggled(widget, 'enable_zeroconf')
|
||||
|
||||
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
|
||||
class FakeDataForm(gtk.Table, object):
|
||||
'''Class for forms that are in XML format <entry1>value1</entry1>
|
||||
infos in a table {entry1: value1, }'''
|
||||
def __init__(self, infos):
|
||||
gtk.Table.__init__(self)
|
||||
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.draw_table()
|
||||
self._draw_table()
|
||||
|
||||
self.xml.signal_autoconnect(self)
|
||||
self.window.show_all()
|
||||
|
||||
def on_cancel_button_clicked(self, widget):
|
||||
self.window.destroy()
|
||||
|
||||
def draw_table(self):
|
||||
def _draw_table(self):
|
||||
'''Draw the table in the window'''
|
||||
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():
|
||||
if name in ('key', 'instructions', 'x', 'registered'):
|
||||
continue
|
||||
|
@ -2132,41 +2111,74 @@ class ServiceRegistrationWindow:
|
|||
continue
|
||||
|
||||
nbrow = nbrow + 1
|
||||
table.resize(rows = nbrow, columns = 2)
|
||||
self.resize(rows = nbrow, columns = 2)
|
||||
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.set_activates_default(True)
|
||||
if self.infos[name]:
|
||||
entry.set_text(self.infos[name])
|
||||
if name == 'password':
|
||||
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
|
||||
if nbrow == 1:
|
||||
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):
|
||||
# send registration info to the core
|
||||
if self.is_form:
|
||||
form = self.data_form_widget.data_form
|
||||
gajim.connections[self.account].register_agent(self.service,
|
||||
form, True) # True is for is_form
|
||||
else:
|
||||
# we pressed OK of service_registration_window
|
||||
# send registration info to the core
|
||||
for name in self.entries.keys():
|
||||
self.infos[name] = self.entries[name].get_text().decode('utf-8')
|
||||
if self.infos.has_key('instructions'):
|
||||
del self.infos['instructions']
|
||||
if self.infos.has_key('registered'):
|
||||
del self.infos['registered']
|
||||
gajim.connections[self.account].register_agent(self.service,
|
||||
self.infos)
|
||||
infos = self.data_form_widget.get_infos()
|
||||
if infos.has_key('instructions'):
|
||||
del infos['instructions']
|
||||
if infos.has_key('registered'):
|
||||
del infos['registered']
|
||||
gajim.connections[self.account].register_agent(self.service, infos)
|
||||
|
||||
self.window.destroy()
|
||||
|
||||
|
||||
class GroupchatConfigWindow:
|
||||
'''GroupchatConfigWindow class'''
|
||||
def __init__(self, account, room_jid, form = None):
|
||||
|
|
Loading…
Reference in New Issue