| 1 | ## advanced.py |
|---|
| 2 | ## |
|---|
| 3 | ## Gajim Team: |
|---|
| 4 | ## - Yann Le Boulanger <asterix@lagaule.org> |
|---|
| 5 | ## - Vincent Hanquez <tab@snarc.org> |
|---|
| 6 | ## - Nikos Kouremenos <kourem@gmail.com> |
|---|
| 7 | ## |
|---|
| 8 | ## Copyright (C) 2003-2005 Gajim Team |
|---|
| 9 | ## |
|---|
| 10 | ## This program is free software; you can redistribute it and/or modify |
|---|
| 11 | ## it under the terms of the GNU General Public License as published |
|---|
| 12 | ## by the Free Software Foundation; version 2 only. |
|---|
| 13 | ## |
|---|
| 14 | ## This program is distributed in the hope that it will be useful, |
|---|
| 15 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 | ## GNU General Public License for more details. |
|---|
| 18 | ## |
|---|
| 19 | |
|---|
| 20 | import gtk |
|---|
| 21 | import gtk.glade |
|---|
| 22 | import gobject |
|---|
| 23 | |
|---|
| 24 | from common import gajim |
|---|
| 25 | from common import i18n |
|---|
| 26 | |
|---|
| 27 | _ = i18n._ |
|---|
| 28 | APP = i18n.APP |
|---|
| 29 | gtk.glade.bindtextdomain(APP, i18n.DIR) |
|---|
| 30 | gtk.glade.textdomain(APP) |
|---|
| 31 | |
|---|
| 32 | OPT_TYPE = 0 |
|---|
| 33 | OPT_VAL = 1 |
|---|
| 34 | |
|---|
| 35 | GTKGUI_GLADE = 'gtkgui.glade' |
|---|
| 36 | |
|---|
| 37 | class AdvancedConfigurationWindow: |
|---|
| 38 | def __init__(self, plugin): |
|---|
| 39 | self.plugin = plugin |
|---|
| 40 | |
|---|
| 41 | self.xml = gtk.glade.XML(GTKGUI_GLADE, 'advanced_configuration_window', None) |
|---|
| 42 | self.window = self.xml.get_widget('advanced_configuration_window') |
|---|
| 43 | self.entry = self.xml.get_widget('advanced_entry') |
|---|
| 44 | |
|---|
| 45 | treeview = self.xml.get_widget('advanced_treeview') |
|---|
| 46 | self.model = gtk.TreeStore(str, str, str) |
|---|
| 47 | self.model.set_sort_column_id(0, gtk.SORT_ASCENDING) |
|---|
| 48 | self.modelfilter = self.model.filter_new() |
|---|
| 49 | self.modelfilter.set_visible_func(self.visible_func) |
|---|
| 50 | |
|---|
| 51 | renderer_text = gtk.CellRendererText() |
|---|
| 52 | col = treeview.insert_column_with_attributes(-1, _('Preference Name'), |
|---|
| 53 | renderer_text, text = 0) |
|---|
| 54 | col.set_resizable(True) |
|---|
| 55 | |
|---|
| 56 | renderer_text = gtk.CellRendererText() |
|---|
| 57 | renderer_text.set_property('editable', 1) |
|---|
| 58 | renderer_text.connect('edited', self.on_config_edited) |
|---|
| 59 | col = treeview.insert_column_with_attributes(-1, _('Value'), |
|---|
| 60 | renderer_text, text = 1) |
|---|
| 61 | col.set_cell_data_func(renderer_text, self.cb_value_column_data) |
|---|
| 62 | |
|---|
| 63 | #col.set_resizable(True) DO NOT REMOVE |
|---|
| 64 | # GTK+ bug http://bugzilla.gnome.org/show_bug.cgi?id=304139 |
|---|
| 65 | col.set_max_width(250) |
|---|
| 66 | |
|---|
| 67 | renderer_text = gtk.CellRendererText() |
|---|
| 68 | treeview.insert_column_with_attributes(-1, _('Type'), |
|---|
| 69 | renderer_text, text = 2) |
|---|
| 70 | |
|---|
| 71 | # add data to model |
|---|
| 72 | gajim.config.foreach(self.fill, self.model) |
|---|
| 73 | |
|---|
| 74 | treeview.set_model(self.modelfilter) |
|---|
| 75 | |
|---|
| 76 | self.xml.signal_autoconnect(self) |
|---|
| 77 | self.window.show_all() |
|---|
| 78 | self.plugin.windows['advanced_config'] = self |
|---|
| 79 | |
|---|
| 80 | def cb_value_column_data(self, col, cell, model, iter): |
|---|
| 81 | opttype = model[iter][2] |
|---|
| 82 | if opttype == 'boolean': |
|---|
| 83 | cell.set_property('editable', 0) |
|---|
| 84 | else: |
|---|
| 85 | cell.set_property('editable', 1) |
|---|
| 86 | |
|---|
| 87 | def on_advanced_treeview_row_activated(self, treeview, path, column): |
|---|
| 88 | modelpath = self.modelfilter.convert_path_to_child_path(path) |
|---|
| 89 | modelrow = self.model[modelpath] |
|---|
| 90 | option = modelrow[0] |
|---|
| 91 | if modelrow[2] == 'boolean': |
|---|
| 92 | newval = {'False': 'True', 'True': 'False'}[modelrow[1]] |
|---|
| 93 | if len(modelpath) > 1: |
|---|
| 94 | optnamerow = self.model[modelpath[0]] |
|---|
| 95 | optname = optnamerow[0] |
|---|
| 96 | keyrow = self.model[modelpath[:2]] |
|---|
| 97 | key = keyrow[0] |
|---|
| 98 | gajim.config.set_per(optname, key, option, newval) |
|---|
| 99 | else: |
|---|
| 100 | gajim.config.set(option, newval) |
|---|
| 101 | self.plugin.save_config() |
|---|
| 102 | modelrow[1] = newval |
|---|
| 103 | |
|---|
| 104 | def on_config_edited(self, cell, path, text): |
|---|
| 105 | # convert modelfilter path to model path |
|---|
| 106 | modelpath = self.modelfilter.convert_path_to_child_path(path) |
|---|
| 107 | modelrow = self.model[modelpath] |
|---|
| 108 | option = modelrow[0] |
|---|
| 109 | if len(modelpath) > 1: |
|---|
| 110 | optnamerow = self.model[modelpath[0]] |
|---|
| 111 | optname = optnamerow[0] |
|---|
| 112 | keyrow = self.model[modelpath[:2]] |
|---|
| 113 | key = keyrow[0] |
|---|
| 114 | gajim.config.set_per(optname, key, option, text) |
|---|
| 115 | else: |
|---|
| 116 | gajim.config.set(option, text) |
|---|
| 117 | self.plugin.save_config() |
|---|
| 118 | modelrow[1] = text |
|---|
| 119 | |
|---|
| 120 | def on_advanced_configuration_window_destroy(self, widget): |
|---|
| 121 | # update ui of preferences window to get possible changes we did |
|---|
| 122 | self.plugin.windows['preferences'].update_preferences_window() |
|---|
| 123 | del self.plugin.windows['advanced_config'] |
|---|
| 124 | |
|---|
| 125 | def on_advanced_close_button_clicked(self, widget): |
|---|
| 126 | self.window.destroy() |
|---|
| 127 | |
|---|
| 128 | def find_iter(self, model, parent_iter, name): |
|---|
| 129 | if not parent_iter: |
|---|
| 130 | iter = model.get_iter_root() |
|---|
| 131 | else: |
|---|
| 132 | iter = model.iter_children(parent_iter) |
|---|
| 133 | while iter: |
|---|
| 134 | if model[iter][0] == name: |
|---|
| 135 | break |
|---|
| 136 | iter = model.iter_next(iter) |
|---|
| 137 | return iter |
|---|
| 138 | |
|---|
| 139 | def fill(self, model, name, parents, val): |
|---|
| 140 | iter = None |
|---|
| 141 | if parents: |
|---|
| 142 | for p in parents: |
|---|
| 143 | iter2 = self.find_iter(model, iter, p) |
|---|
| 144 | if iter2: |
|---|
| 145 | iter = iter2 |
|---|
| 146 | |
|---|
| 147 | if not val: |
|---|
| 148 | model.append(iter, [name, '', '']) |
|---|
| 149 | return |
|---|
| 150 | type = '' |
|---|
| 151 | if val[OPT_TYPE]: |
|---|
| 152 | type = val[OPT_TYPE][0] |
|---|
| 153 | model.append(iter, [name, val[OPT_VAL], type]) |
|---|
| 154 | |
|---|
| 155 | def visible_func(self, model, iter): |
|---|
| 156 | str = self.entry.get_text() |
|---|
| 157 | if str is None or str == '': |
|---|
| 158 | return True # show all |
|---|
| 159 | name = model[iter][0] |
|---|
| 160 | # If a child of the iter matches, we return True |
|---|
| 161 | if model.iter_has_child(iter): |
|---|
| 162 | iterC = model.iter_children(iter) |
|---|
| 163 | while iterC: |
|---|
| 164 | nameC = model[iterC][0] |
|---|
| 165 | if model.iter_has_child(iterC): |
|---|
| 166 | iterCC = model.iter_children(iterC) |
|---|
| 167 | while iterCC: |
|---|
| 168 | nameCC = model[iterCC][0] |
|---|
| 169 | if nameCC.find(str) != -1: |
|---|
| 170 | return True |
|---|
| 171 | iterCC = model.iter_next(iterCC) |
|---|
| 172 | elif nameC.find(str) != -1: |
|---|
| 173 | return True |
|---|
| 174 | iterC = model.iter_next(iterC) |
|---|
| 175 | elif name.find(str) != -1: |
|---|
| 176 | return True |
|---|
| 177 | return False |
|---|
| 178 | |
|---|
| 179 | def on_advanced_entry_changed(self, widget): |
|---|
| 180 | text = widget.get_text() |
|---|
| 181 | self.modelfilter.refilter() |
|---|