| 2080 | | class DataFormWindow: |
| 2081 | | def __init__(self, account, config): |
| 2082 | | self.account = account |
| 2083 | | self.config = config |
| 2084 | | self.xml = gtkgui_helpers.get_glade('data_form_window.glade', 'data_form_window') |
| 2085 | | self.window = self.xml.get_widget('data_form_window') |
| 2086 | | self.window.set_transient_for(gajim.interface.roster.window) |
| 2087 | | self.config_vbox = self.xml.get_widget('config_vbox') |
| 2088 | | if config: |
| 2089 | | self.fill_vbox() |
| 2090 | | else: |
| 2091 | | self.config_vbox.set_no_show_all(True) |
| 2092 | | self.config_vbox.hide() |
| 2093 | | self.xml.signal_autoconnect(self) |
| 2094 | | self.window.show_all() |
| 2095 | | |
| 2096 | | def on_cancel_button_clicked(self, widget): |
| 2097 | | self.window.destroy() |
| 2098 | | |
| 2099 | | def on_ok_button_clicked(self, widget): |
| 2100 | | '''NOTE: child class should implement this''' |
| 2101 | | pass |
| 2102 | | |
| 2103 | | def on_data_form_window_destroy(self, widget): |
| 2104 | | '''NOTE: child class should implement this''' |
| 2105 | | pass |
| 2106 | | |
| 2107 | | def on_checkbutton_toggled(self, widget, index): |
| 2108 | | self.config[index]['values'][0] = widget.get_active() |
| 2109 | | |
| 2110 | | def on_checkbutton_toggled2(self, widget, index1, index2): |
| 2111 | | val = self.config[index1]['options'][index2]['values'][0] |
| 2112 | | if widget.get_active() and val not in self.config[index1]['values']: |
| 2113 | | self.config[index1]['values'].append(val) |
| 2114 | | elif not widget.get_active() and val in self.config[index1]['values']: |
| 2115 | | self.config[index1]['values'].remove(val) |
| 2116 | | |
| 2117 | | def on_combobox_changed(self, widget, index): |
| 2118 | | self.config[index]['values'][0] = self.config[index]['options'][ \ |
| 2119 | | widget.get_active()]['values'][0] |
| 2120 | | |
| 2121 | | def on_entry_changed(self, widget, index): |
| 2122 | | self.config[index]['values'][0] = widget.get_text().decode('utf-8') |
| 2123 | | |
| 2124 | | def on_textbuffer_changed(self, widget, index): |
| 2125 | | begin, end = widget.get_bounds() |
| 2126 | | self.config[index]['values'][0] = widget.get_text(begin, end) |
| 2127 | | |
| 2128 | | def fill_vbox(self): |
| 2129 | | '''see JEP0004''' |
| 2130 | | if self.config.has_key('title'): |
| 2131 | | self.window.set_title(self.config['title']) |
| 2132 | | if self.config.has_key('instructions'): |
| 2133 | | self.xml.get_widget('instructions_label').set_text( |
| 2134 | | self.config['instructions']) |
| 2135 | | i = 0 |
| 2136 | | while self.config.has_key(i): |
| 2137 | | if not self.config[i].has_key('type'): |
| 2138 | | i += 1 |
| 2139 | | continue |
| 2140 | | ctype = self.config[i]['type'] |
| 2141 | | if ctype == 'hidden': |
| 2142 | | i += 1 |
| 2143 | | continue |
| 2144 | | hbox = gtk.HBox(spacing = 5) |
| 2145 | | label = gtk.Label('') |
| 2146 | | label.set_line_wrap(True) |
| 2147 | | label.set_alignment(0.0, 0.5) |
| 2148 | | label.set_property('width_request', 150) |
| 2149 | | hbox.pack_start(label, False) |
| 2150 | | if self.config[i].has_key('label'): |
| 2151 | | label.set_text(self.config[i]['label']) |
| 2152 | | if ctype == 'boolean': |
| 2153 | | desc = None |
| 2154 | | if self.config[i].has_key('desc'): |
| 2155 | | desc = self.config[i]['desc'] |
| 2156 | | widget = gtk.CheckButton(desc, False) |
| 2157 | | activ = False |
| 2158 | | if self.config[i].has_key('values'): |
| 2159 | | activ = self.config[i]['values'][0] |
| 2160 | | widget.set_active(activ) |
| 2161 | | widget.connect('toggled', self.on_checkbutton_toggled, i) |
| 2162 | | elif ctype == 'fixed': |
| 2163 | | widget = gtk.Label('\n'.join(self.config[i]['values'])) |
| 2164 | | widget.set_line_wrap(True) |
| 2165 | | widget.set_alignment(0.0, 0.5) |
| 2166 | | elif ctype == 'jid-multi': |
| 2167 | | #FIXME |
| 2168 | | widget = gtk.Label('') |
| 2169 | | elif ctype == 'jid-single': |
| 2170 | | #FIXME |
| 2171 | | widget = gtk.Label('') |
| 2172 | | elif ctype == 'list-multi': |
| 2173 | | j = 0 |
| 2174 | | widget = gtk.Table(1, 1) |
| 2175 | | while self.config[i]['options'].has_key(j): |
| 2176 | | widget.resize(j + 1, 1) |
| 2177 | | child = gtk.CheckButton(self.config[i]['options'][j]['label'], |
| 2178 | | False) |
| 2179 | | if self.config[i]['options'][j]['values'][0] in \ |
| 2180 | | self.config[i]['values']: |
| 2181 | | child.set_active(True) |
| 2182 | | child.connect('toggled', self.on_checkbutton_toggled2, i, j) |
| 2183 | | widget.attach(child, 0, 1, j, j+1) |
| 2184 | | j += 1 |
| 2185 | | elif ctype == 'list-single': |
| 2186 | | widget = gtk.combo_box_new_text() |
| 2187 | | widget.connect('changed', self.on_combobox_changed, i) |
| 2188 | | index = 0 |
| 2189 | | j = 0 |
| 2190 | | while self.config[i]['options'].has_key(j): |
| 2191 | | if self.config[i]['options'][j]['values'][0] == \ |
| 2192 | | self.config[i]['values'][0]: |
| 2193 | | index = j |
| 2194 | | widget.append_text(self.config[i]['options'][j]['label']) |
| 2195 | | j += 1 |
| 2196 | | widget.set_active(index) |
| 2197 | | elif ctype == 'text-multi': |
| 2198 | | widget = gtk.TextView() |
| 2199 | | widget.set_size_request(100, -1) |
| 2200 | | widget.get_buffer().connect('changed', self.on_textbuffer_changed, \ |
| 2201 | | i) |
| 2202 | | widget.get_buffer().set_text('\n'.join(self.config[i]['values'])) |
| 2203 | | elif ctype == 'text-private': |
| 2204 | | widget = gtk.Entry() |
| 2205 | | widget.connect('changed', self.on_entry_changed, i) |
| 2206 | | if not self.config[i].has_key('values'): |
| 2207 | | self.config[i]['values'] = [''] |
| 2208 | | widget.set_text(self.config[i]['values'][0]) |
| 2209 | | widget.set_visibility(False) |
| 2210 | | elif ctype == 'text-single': |
| 2211 | | widget = gtk.Entry() |
| 2212 | | widget.connect('changed', self.on_entry_changed, i) |
| 2213 | | if not self.config[i].has_key('values'): |
| 2214 | | self.config[i]['values'] = [''] |
| 2215 | | widget.set_text(self.config[i]['values'][0]) |
| 2216 | | i += 1 |
| 2217 | | hbox.pack_start(widget, False) |
| 2218 | | hbox.pack_start(gtk.Label('')) # So that widhet doesn't take all space |
| 2219 | | self.config_vbox.pack_start(hbox, False) |
| 2220 | | self.config_vbox.show_all() |
| 2221 | | |
| 2222 | | class ServiceRegistrationWindow(DataFormWindow): |
| 2223 | | '''Class for Service registration window: |
| 2224 | | Window that appears when we want to subscribe to a service |
| 2225 | | if is_form we use DataFormWindow else we use service_registarion_window''' |
| 2226 | | def __init__(self, service, infos, account, is_form): |
| 2227 | | self.service = service |
| | 2080 | class FakeDataForm(gtk.Table, object): |
| | 2081 | '''Class for forms that are in XML format <entry1>value1</entry1> |
| | 2082 | infos in a table {entry1: value1, }''' |
| | 2083 | def __init__(self, infos): |
| | 2084 | gtk.Table.__init__(self) |
| 2275 | | table.show_all() |
| | 2117 | |
| | 2118 | def get_infos(self): |
| | 2119 | for name in self.entries.keys(): |
| | 2120 | self.infos[name] = self.entries[name].get_text().decode('utf-8') |
| | 2121 | return self.infos |
| | 2122 | |
| | 2123 | class ServiceRegistrationWindow: |
| | 2124 | '''Class for Service registration window: |
| | 2125 | Window that appears when we want to subscribe to a service |
| | 2126 | if is_form we use DataFormWindow else we use service_registarion_window''' |
| | 2127 | def __init__(self, service, infos, account, is_form): |
| | 2128 | self.service = service |
| | 2129 | self.account = account |
| | 2130 | self.is_form = is_form |
| | 2131 | if self.is_form: |
| | 2132 | dataform = dataforms.ExtendForm(node = infos) |
| | 2133 | self.data_form_widget = dataforms_widget.DataFormWidget(dataform) |
| | 2134 | if self.data_form_widget.title: |
| | 2135 | self.window.set_title('%s - Gajim' % self.data_form_widget.title) |
| | 2136 | table = self.xml.get_widget('table') |
| | 2137 | table.attach(self.data_form_widget, 0, 2, 0, 1) |
| | 2138 | else: |
| | 2139 | if infos.has_key('registered'): |
| | 2140 | self.window.set_title(_('Edit %s') % service) |
| | 2141 | else: |
| | 2142 | self.window.set_title(_('Register to %s') % service) |
| | 2143 | self.data_form_widget = FakeDataForm(infos) |
| | 2144 | table = self.xml.get_widget('table') |
| | 2145 | table.attach(self.data_form_widget, 0, 2, 0, 1) |
| | 2146 | self.xml.signal_autoconnect(self) |
| | 2147 | self.window.show_all() |
| | 2148 | |
| | 2149 | def on_cancel_button_clicked(self, widget): |
| | 2150 | self.window.destroy() |