2005-06-25 01:43:24 +02:00
|
|
|
## advanced.py
|
2005-04-24 01:57:02 +02:00
|
|
|
##
|
|
|
|
## Gajim Team:
|
2005-05-21 00:41:39 +02:00
|
|
|
## - Yann Le Boulanger <asterix@lagaule.org>
|
|
|
|
## - Vincent Hanquez <tab@snarc.org>
|
|
|
|
## - Nikos Kouremenos <kourem@gmail.com>
|
2005-04-24 01:57:02 +02:00
|
|
|
##
|
|
|
|
## Copyright (C) 2003-2005 Gajim Team
|
|
|
|
##
|
|
|
|
## This program is free software; you can redistribute it and/or modify
|
|
|
|
## it under the terms of the GNU General Public License as published
|
|
|
|
## by the Free Software Foundation; version 2 only.
|
|
|
|
##
|
|
|
|
## This program is distributed in the hope that it will be useful,
|
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
|
|
|
|
|
|
|
import gtk
|
|
|
|
import gtk.glade
|
|
|
|
import gobject
|
|
|
|
|
|
|
|
from common import gajim
|
2005-05-18 14:28:29 +02:00
|
|
|
from common import i18n
|
2005-04-24 01:57:02 +02:00
|
|
|
|
2005-05-18 14:02:57 +02:00
|
|
|
_ = i18n._
|
|
|
|
APP = i18n.APP
|
|
|
|
gtk.glade.bindtextdomain(APP, i18n.DIR)
|
|
|
|
gtk.glade.textdomain(APP)
|
|
|
|
|
2005-04-24 01:57:02 +02:00
|
|
|
OPT_TYPE = 0
|
|
|
|
OPT_VAL = 1
|
|
|
|
|
|
|
|
GTKGUI_GLADE = 'gtkgui.glade'
|
|
|
|
|
2005-06-11 00:45:50 +02:00
|
|
|
class AdvancedConfigurationWindow:
|
2005-05-25 00:35:50 +02:00
|
|
|
def __init__(self, plugin):
|
|
|
|
self.plugin = plugin
|
|
|
|
|
|
|
|
self.xml = gtk.glade.XML(GTKGUI_GLADE, 'advanced_configuration_window', None)
|
|
|
|
self.window = self.xml.get_widget('advanced_configuration_window')
|
|
|
|
self.entry = self.xml.get_widget('advanced_entry')
|
|
|
|
|
|
|
|
treeview = self.xml.get_widget('advanced_treeview')
|
|
|
|
self.model = gtk.TreeStore(str, str, str)
|
|
|
|
self.model.set_sort_column_id(0, gtk.SORT_ASCENDING)
|
|
|
|
self.modelfilter = self.model.filter_new()
|
|
|
|
self.modelfilter.set_visible_func(self.visible_func)
|
|
|
|
|
|
|
|
renderer_text = gtk.CellRendererText()
|
|
|
|
col = treeview.insert_column_with_attributes(-1, _('Preference Name'),
|
|
|
|
renderer_text, text = 0)
|
|
|
|
col.set_resizable(True)
|
2005-08-10 02:56:18 +02:00
|
|
|
|
2005-05-25 00:35:50 +02:00
|
|
|
renderer_text = gtk.CellRendererText()
|
|
|
|
renderer_text.set_property('editable', 1)
|
|
|
|
renderer_text.connect('edited', self.on_config_edited)
|
|
|
|
col = treeview.insert_column_with_attributes(-1, _('Value'),
|
|
|
|
renderer_text, text = 1)
|
2005-08-10 02:56:18 +02:00
|
|
|
col.set_cell_data_func(renderer_text, self.cb_value_column_data)
|
2005-05-25 00:35:50 +02:00
|
|
|
|
|
|
|
#col.set_resizable(True) DO NOT REMOVE
|
|
|
|
# GTK+ bug http://bugzilla.gnome.org/show_bug.cgi?id=304139
|
|
|
|
col.set_max_width(250)
|
|
|
|
|
|
|
|
renderer_text = gtk.CellRendererText()
|
|
|
|
treeview.insert_column_with_attributes(-1, _('Type'),
|
|
|
|
renderer_text, text = 2)
|
|
|
|
|
|
|
|
# add data to model
|
|
|
|
gajim.config.foreach(self.fill, self.model)
|
|
|
|
|
|
|
|
treeview.set_model(self.modelfilter)
|
|
|
|
|
|
|
|
self.xml.signal_autoconnect(self)
|
|
|
|
self.window.show_all()
|
|
|
|
self.plugin.windows['advanced_config'] = self
|
|
|
|
|
2005-08-10 02:56:18 +02:00
|
|
|
def cb_value_column_data(self, col, cell, model, iter):
|
2005-08-26 02:52:44 +02:00
|
|
|
opttype = model[iter][2].decode('utf-8')
|
2005-08-10 02:56:18 +02:00
|
|
|
if opttype == 'boolean':
|
|
|
|
cell.set_property('editable', 0)
|
|
|
|
else:
|
|
|
|
cell.set_property('editable', 1)
|
|
|
|
|
|
|
|
def on_advanced_treeview_row_activated(self, treeview, path, column):
|
|
|
|
modelpath = self.modelfilter.convert_path_to_child_path(path)
|
|
|
|
modelrow = self.model[modelpath]
|
2005-08-26 02:52:44 +02:00
|
|
|
option = modelrow[0].decode('utf-8')
|
2005-08-10 02:56:18 +02:00
|
|
|
if modelrow[2] == 'boolean':
|
|
|
|
newval = {'False': 'True', 'True': 'False'}[modelrow[1]]
|
|
|
|
if len(modelpath) > 1:
|
|
|
|
optnamerow = self.model[modelpath[0]]
|
2005-08-26 02:52:44 +02:00
|
|
|
optname = optnamerow[0].decode('utf-8')
|
2005-08-10 02:56:18 +02:00
|
|
|
keyrow = self.model[modelpath[:2]]
|
2005-08-26 02:52:44 +02:00
|
|
|
key = keyrow[0].decode('utf-8')
|
2005-08-10 02:56:18 +02:00
|
|
|
gajim.config.set_per(optname, key, option, newval)
|
|
|
|
else:
|
|
|
|
gajim.config.set(option, newval)
|
|
|
|
self.plugin.save_config()
|
|
|
|
modelrow[1] = newval
|
|
|
|
|
2005-07-23 09:26:41 +02:00
|
|
|
def on_config_edited(self, cell, path, text):
|
2005-08-10 02:56:18 +02:00
|
|
|
# convert modelfilter path to model path
|
2005-07-23 09:26:41 +02:00
|
|
|
modelpath = self.modelfilter.convert_path_to_child_path(path)
|
|
|
|
modelrow = self.model[modelpath]
|
2005-08-26 02:52:44 +02:00
|
|
|
option = modelrow[0].decode('utf-8')
|
|
|
|
text = text.decode('utf-8')
|
2005-07-23 09:26:41 +02:00
|
|
|
if len(modelpath) > 1:
|
|
|
|
optnamerow = self.model[modelpath[0]]
|
2005-08-26 02:52:44 +02:00
|
|
|
optname = optnamerow[0].decode('utf-8')
|
2005-07-23 09:38:33 +02:00
|
|
|
keyrow = self.model[modelpath[:2]]
|
2005-08-26 02:52:44 +02:00
|
|
|
key = keyrow[0].decode('utf-8')
|
2005-08-05 12:26:10 +02:00
|
|
|
gajim.config.set_per(optname, key, option, text)
|
2005-05-26 23:09:01 +02:00
|
|
|
else:
|
2005-08-05 12:26:10 +02:00
|
|
|
gajim.config.set(option, text)
|
2005-05-07 15:14:37 +02:00
|
|
|
self.plugin.save_config()
|
2005-04-24 01:57:02 +02:00
|
|
|
modelrow[1] = text
|
2005-06-09 17:31:29 +02:00
|
|
|
|
2005-05-14 03:42:10 +02:00
|
|
|
def on_advanced_configuration_window_destroy(self, widget):
|
2005-07-24 23:05:44 +02:00
|
|
|
# update ui of preferences window to get possible changes we did
|
|
|
|
self.plugin.windows['preferences'].update_preferences_window()
|
2005-04-27 17:16:40 +02:00
|
|
|
del self.plugin.windows['advanced_config']
|
2005-04-24 01:57:02 +02:00
|
|
|
|
2005-04-27 17:16:40 +02:00
|
|
|
def on_advanced_close_button_clicked(self, widget):
|
|
|
|
self.window.destroy()
|
2005-04-24 01:57:02 +02:00
|
|
|
|
2005-04-27 21:03:28 +02:00
|
|
|
def find_iter(self, model, parent_iter, name):
|
2005-04-24 01:57:02 +02:00
|
|
|
if not parent_iter:
|
2005-04-27 21:03:28 +02:00
|
|
|
iter = model.get_iter_root()
|
2005-04-24 01:57:02 +02:00
|
|
|
else:
|
2005-04-27 21:03:28 +02:00
|
|
|
iter = model.iter_children(parent_iter)
|
2005-04-24 01:57:02 +02:00
|
|
|
while iter:
|
2005-08-26 02:52:44 +02:00
|
|
|
if model[iter][0].decode('utf-8') == name:
|
2005-04-24 01:57:02 +02:00
|
|
|
break
|
2005-04-27 21:03:28 +02:00
|
|
|
iter = model.iter_next(iter)
|
2005-04-24 01:57:02 +02:00
|
|
|
return iter
|
|
|
|
|
2005-04-27 21:03:28 +02:00
|
|
|
def fill(self, model, name, parents, val):
|
2005-04-24 01:57:02 +02:00
|
|
|
iter = None
|
|
|
|
if parents:
|
|
|
|
for p in parents:
|
2005-04-27 21:03:28 +02:00
|
|
|
iter2 = self.find_iter(model, iter, p)
|
2005-04-24 01:57:02 +02:00
|
|
|
if iter2:
|
|
|
|
iter = iter2
|
|
|
|
|
|
|
|
if not val:
|
2005-04-27 21:03:28 +02:00
|
|
|
model.append(iter, [name, '', ''])
|
2005-04-24 01:57:02 +02:00
|
|
|
return
|
2005-05-01 00:24:45 +02:00
|
|
|
type = ''
|
|
|
|
if val[OPT_TYPE]:
|
|
|
|
type = val[OPT_TYPE][0]
|
|
|
|
model.append(iter, [name, val[OPT_VAL], type])
|
2005-04-24 01:57:02 +02:00
|
|
|
|
2005-05-13 20:05:15 +02:00
|
|
|
def visible_func(self, model, iter):
|
2005-08-26 02:52:44 +02:00
|
|
|
str = self.entry.get_text().decode('utf-8')
|
2005-04-27 17:16:40 +02:00
|
|
|
if str is None or str == '':
|
2005-04-29 10:00:06 +02:00
|
|
|
return True # show all
|
2005-08-26 02:52:44 +02:00
|
|
|
name = model[iter][0].decode('utf-8')
|
2005-07-23 10:11:50 +02:00
|
|
|
# If a child of the iter matches, we return True
|
2005-07-23 10:04:44 +02:00
|
|
|
if model.iter_has_child(iter):
|
|
|
|
iterC = model.iter_children(iter)
|
|
|
|
while iterC:
|
2005-08-26 02:52:44 +02:00
|
|
|
nameC = model[iterC][0].decode('utf-8')
|
2005-07-23 10:04:44 +02:00
|
|
|
if model.iter_has_child(iterC):
|
|
|
|
iterCC = model.iter_children(iterC)
|
|
|
|
while iterCC:
|
2005-08-26 02:52:44 +02:00
|
|
|
nameCC = model[iterCC][0].decode('utf-8')
|
2005-07-23 10:04:44 +02:00
|
|
|
if nameCC.find(str) != -1:
|
|
|
|
return True
|
|
|
|
iterCC = model.iter_next(iterCC)
|
|
|
|
elif nameC.find(str) != -1:
|
|
|
|
return True
|
|
|
|
iterC = model.iter_next(iterC)
|
|
|
|
elif name.find(str) != -1:
|
2005-04-27 17:16:40 +02:00
|
|
|
return True
|
|
|
|
return False
|
2005-04-24 01:57:02 +02:00
|
|
|
|
2005-04-27 17:16:40 +02:00
|
|
|
def on_advanced_entry_changed(self, widget):
|
2005-08-26 02:52:44 +02:00
|
|
|
text = widget.get_text().decode('utf-8')
|
2005-05-13 20:05:15 +02:00
|
|
|
self.modelfilter.refilter()
|