2008-08-15 19:31:51 +02:00
|
|
|
# -*- coding:utf-8 -*-
|
2008-08-15 05:20:23 +02:00
|
|
|
## src/advanced.py
|
2005-04-24 01:57:02 +02:00
|
|
|
##
|
2008-08-15 05:20:23 +02:00
|
|
|
## Copyright (C) 2005 Travis Shirk <travis AT pobox.com>
|
|
|
|
## Vincent Hanquez <tab AT snarc.org>
|
|
|
|
## Copyright (C) 2005-2007 Yann Leboulanger <asterix AT lagaule.org>
|
|
|
|
## Nikos Kouremenos <kourem AT gmail.com>
|
|
|
|
## Copyright (C) 2006 Dimitur Kirov <dkirov AT gmail.com>
|
|
|
|
## Copyright (C) 2006-2007 Jean-Marie Traissard <jim AT lapin.org>
|
2005-04-24 01:57:02 +02:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## This file is part of Gajim.
|
|
|
|
##
|
|
|
|
## Gajim is free software; you can redistribute it and/or modify
|
2005-04-24 01:57:02 +02:00
|
|
|
## it under the terms of the GNU General Public License as published
|
2007-10-22 13:13:13 +02:00
|
|
|
## by the Free Software Foundation; version 3 only.
|
2005-04-24 01:57:02 +02:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## Gajim is distributed in the hope that it will be useful,
|
2005-04-24 01:57:02 +02:00
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-08-15 05:20:23 +02:00
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2005-04-24 01:57:02 +02:00
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## You should have received a copy of the GNU General Public License
|
2008-08-15 05:20:23 +02:00
|
|
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-22 13:13:13 +02:00
|
|
|
##
|
2005-04-24 01:57:02 +02:00
|
|
|
|
|
|
|
import gtk
|
2006-05-02 17:53:25 +02:00
|
|
|
import gtkgui_helpers
|
2008-11-05 21:26:58 +01:00
|
|
|
import gobject
|
2005-04-24 01:57:02 +02:00
|
|
|
|
|
|
|
from common import gajim
|
2005-05-18 14:02:57 +02:00
|
|
|
|
2005-12-01 19:08:10 +01:00
|
|
|
(
|
|
|
|
OPT_TYPE,
|
|
|
|
OPT_VAL
|
|
|
|
) = range(2)
|
2005-04-24 01:57:02 +02:00
|
|
|
|
2005-09-08 23:29:42 +02:00
|
|
|
(
|
|
|
|
C_PREFNAME,
|
|
|
|
C_VALUE,
|
|
|
|
C_TYPE
|
|
|
|
) = range(3)
|
|
|
|
|
2006-05-21 22:50:48 +02:00
|
|
|
GTKGUI_GLADE = 'manage_accounts_window.glade'
|
2005-04-24 01:57:02 +02:00
|
|
|
|
2008-11-05 21:26:58 +01:00
|
|
|
def rate_limit(rate):
|
|
|
|
''' call func at most *rate* times per second '''
|
|
|
|
def decorator(func):
|
|
|
|
timeout = [None]
|
|
|
|
def f(*args, **kwargs):
|
|
|
|
if timeout[0] is not None:
|
|
|
|
gobject.source_remove(timeout[0])
|
|
|
|
timeout[0] = None
|
|
|
|
def timeout_func():
|
|
|
|
func(*args, **kwargs)
|
|
|
|
timeout[0] = None
|
|
|
|
timeout[0] = gobject.timeout_add(int(1000.0 / rate), timeout_func)
|
|
|
|
return f
|
|
|
|
return decorator
|
|
|
|
|
|
|
|
def tree_model_iter_children(model, treeiter):
|
|
|
|
it = model.iter_children(treeiter)
|
|
|
|
while it:
|
|
|
|
yield it
|
|
|
|
it = model.iter_next(it)
|
|
|
|
|
|
|
|
def tree_model_pre_order(model, treeiter):
|
|
|
|
yield treeiter
|
|
|
|
for childiter in tree_model_iter_children(model, treeiter):
|
|
|
|
for it in tree_model_pre_order(model, childiter):
|
|
|
|
yield it
|
|
|
|
|
|
|
|
try:
|
|
|
|
any(()) # builtin since python 2.5
|
|
|
|
except Exception:
|
|
|
|
def any(iterable):
|
|
|
|
for element in iterable:
|
|
|
|
if element:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2006-10-06 02:08:46 +02:00
|
|
|
class AdvancedConfigurationWindow(object):
|
2005-10-20 13:17:17 +02:00
|
|
|
def __init__(self):
|
2006-05-02 17:53:25 +02:00
|
|
|
self.xml = gtkgui_helpers.get_glade('advanced_configuration_window.glade')
|
2005-05-25 00:35:50 +02:00
|
|
|
self.window = self.xml.get_widget('advanced_configuration_window')
|
2006-07-18 10:40:44 +02:00
|
|
|
self.window.set_transient_for(
|
|
|
|
gajim.interface.instances['preferences'].window)
|
2005-05-25 00:35:50 +02:00
|
|
|
self.entry = self.xml.get_widget('advanced_entry')
|
2005-09-03 14:28:30 +02:00
|
|
|
self.desc_label = self.xml.get_widget('advanced_desc_label')
|
2006-03-04 01:25:36 +01:00
|
|
|
self.restart_label = self.xml.get_widget('restart_label')
|
|
|
|
|
|
|
|
# Format:
|
|
|
|
# key = option name (root/subopt/opt separated by \n then)
|
|
|
|
# value = array(oldval, newval)
|
|
|
|
self.changed_opts = {}
|
2008-12-03 22:56:12 +01:00
|
|
|
|
2007-01-15 00:04:29 +01:00
|
|
|
# For i18n
|
2008-12-03 22:56:12 +01:00
|
|
|
self.right_true_dict = {True: _('Activated'), False: _('Deactivated')}
|
2007-01-15 00:04:29 +01:00
|
|
|
self.types = {
|
|
|
|
'boolean': _('Boolean'),
|
|
|
|
'integer': _('Integer'),
|
|
|
|
'string': _('Text'),
|
2008-12-03 22:56:12 +01:00
|
|
|
'color': _('Color')}
|
2005-05-25 00:35:50 +02:00
|
|
|
|
|
|
|
treeview = self.xml.get_widget('advanced_treeview')
|
2008-11-05 21:26:58 +01:00
|
|
|
self.treeview = treeview
|
2005-05-25 00:35:50 +02:00
|
|
|
self.model = gtk.TreeStore(str, str, str)
|
2008-11-05 21:26:58 +01:00
|
|
|
self.fill_model()
|
2005-05-25 00:35:50 +02:00
|
|
|
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-12-06 13:45:32 +01:00
|
|
|
|
2005-05-25 00:35:50 +02:00
|
|
|
renderer_text = gtk.CellRendererText()
|
|
|
|
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
|
|
|
|
2007-01-17 00:26:38 +01:00
|
|
|
col.props.resizable = True
|
2005-05-25 00:35:50 +02:00
|
|
|
col.set_max_width(250)
|
|
|
|
|
|
|
|
renderer_text = gtk.CellRendererText()
|
|
|
|
treeview.insert_column_with_attributes(-1, _('Type'),
|
|
|
|
renderer_text, text = 2)
|
|
|
|
|
|
|
|
treeview.set_model(self.modelfilter)
|
2005-12-06 13:45:32 +01:00
|
|
|
|
2005-09-03 14:28:30 +02:00
|
|
|
# connect signal for selection change
|
2005-09-08 21:55:47 +02:00
|
|
|
treeview.get_selection().connect('changed',
|
|
|
|
self.on_advanced_treeview_selection_changed)
|
2005-12-06 13:45:32 +01:00
|
|
|
|
2005-05-25 00:35:50 +02:00
|
|
|
self.xml.signal_autoconnect(self)
|
|
|
|
self.window.show_all()
|
2006-03-04 01:25:36 +01:00
|
|
|
self.restart_label.hide()
|
2005-11-13 16:08:47 +01:00
|
|
|
gajim.interface.instances['advanced_config'] = self
|
2005-05-25 00:35:50 +02:00
|
|
|
|
2008-10-11 12:22:04 +02:00
|
|
|
def cb_value_column_data(self, col, cell, model, iter_):
|
2005-11-10 14:40:39 +01:00
|
|
|
'''check if it's boolen or holds password stuff and if yes
|
|
|
|
make the cellrenderertext not editable else it's editable'''
|
2008-10-11 12:22:04 +02:00
|
|
|
optname = model[iter_][C_PREFNAME]
|
|
|
|
opttype = model[iter_][C_TYPE]
|
2007-10-25 14:36:57 +02:00
|
|
|
if opttype == self.types['boolean'] or optname == 'password':
|
2005-11-10 14:29:58 +01:00
|
|
|
cell.set_property('editable', False)
|
2005-08-10 02:56:18 +02:00
|
|
|
else:
|
2005-11-10 14:29:58 +01:00
|
|
|
cell.set_property('editable', True)
|
2005-12-06 13:45:32 +01:00
|
|
|
|
2008-10-11 12:22:04 +02:00
|
|
|
def get_option_path(self, model, iter_):
|
2006-03-04 01:25:36 +01:00
|
|
|
# It looks like path made from reversed array
|
|
|
|
# path[0] is the true one optname
|
|
|
|
# path[1] is the key name
|
|
|
|
# path[2] is the root of tree
|
|
|
|
# last two is optional
|
2008-10-11 12:22:04 +02:00
|
|
|
path = [model[iter_][0].decode('utf-8')]
|
|
|
|
parent = model.iter_parent(iter_)
|
2006-03-04 01:25:36 +01:00
|
|
|
while parent:
|
|
|
|
path.append(model[parent][0].decode('utf-8'))
|
|
|
|
parent = model.iter_parent(parent)
|
|
|
|
return path
|
|
|
|
|
2005-09-03 14:28:30 +02:00
|
|
|
def on_advanced_treeview_selection_changed(self, treeselection):
|
2008-12-03 18:16:04 +01:00
|
|
|
model, iter_ = treeselection.get_selected()
|
2005-09-21 05:19:45 +02:00
|
|
|
# Check for GtkTreeIter
|
2008-12-03 18:16:04 +01:00
|
|
|
if iter_:
|
|
|
|
opt_path = self.get_option_path(model, iter_)
|
2005-09-21 05:19:45 +02:00
|
|
|
# Get text from first column in this row
|
2006-03-04 01:25:36 +01:00
|
|
|
desc = None
|
|
|
|
if len(opt_path) == 3:
|
|
|
|
desc = gajim.config.get_desc_per(opt_path[2], opt_path[1],
|
|
|
|
opt_path[0])
|
|
|
|
elif len(opt_path) == 1:
|
|
|
|
desc = gajim.config.get_desc(opt_path[0])
|
2005-09-21 05:19:45 +02:00
|
|
|
if desc:
|
2006-03-04 01:25:36 +01:00
|
|
|
self.desc_label.set_text(desc)
|
2005-09-21 05:19:45 +02:00
|
|
|
else:
|
2005-11-10 14:29:58 +01:00
|
|
|
#we talk about option description in advanced configuration editor
|
2005-09-21 05:19:45 +02:00
|
|
|
self.desc_label.set_text(_('(None)'))
|
2005-12-06 13:45:32 +01:00
|
|
|
|
2006-03-04 01:25:36 +01:00
|
|
|
def remember_option(self, option, oldval, newval):
|
2008-10-07 22:41:59 +02:00
|
|
|
if option in self.changed_opts:
|
2006-03-04 01:25:36 +01:00
|
|
|
self.changed_opts[option] = (self.changed_opts[option][0], newval)
|
|
|
|
else:
|
|
|
|
self.changed_opts[option] = (oldval, newval)
|
|
|
|
|
2005-08-10 02:56:18 +02:00
|
|
|
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')
|
2007-01-15 00:04:29 +01:00
|
|
|
if modelrow[2] == self.types['boolean']:
|
|
|
|
for key in self.right_true_dict.keys():
|
|
|
|
if self.right_true_dict[key] == modelrow[1]:
|
|
|
|
modelrow[1] = key
|
|
|
|
newval = {'False': True, 'True': False}[modelrow[1]]
|
2005-08-10 02:56:18 +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-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')
|
2006-03-04 01:25:36 +01:00
|
|
|
gajim.config.get_desc_per(optname, key, option)
|
|
|
|
self.remember_option(option + '\n' + key + '\n' + optname,
|
|
|
|
modelrow[1], newval)
|
2005-08-10 02:56:18 +02:00
|
|
|
gajim.config.set_per(optname, key, option, newval)
|
|
|
|
else:
|
2006-03-04 01:25:36 +01:00
|
|
|
self.remember_option(option, modelrow[1], newval)
|
2005-08-10 02:56:18 +02:00
|
|
|
gajim.config.set(option, newval)
|
2005-10-20 13:17:17 +02:00
|
|
|
gajim.interface.save_config()
|
2007-01-15 00:04:29 +01:00
|
|
|
modelrow[1] = self.right_true_dict[newval]
|
2006-03-04 01:25:36 +01:00
|
|
|
self.check_for_restart()
|
|
|
|
|
|
|
|
def check_for_restart(self):
|
|
|
|
self.restart_label.hide()
|
|
|
|
for opt in self.changed_opts:
|
|
|
|
opt_path = opt.split('\n')
|
|
|
|
if len(opt_path)==3:
|
|
|
|
restart = gajim.config.get_restart_per(opt_path[2], opt_path[1],
|
|
|
|
opt_path[0])
|
|
|
|
else:
|
|
|
|
restart = gajim.config.get_restart(opt_path[0])
|
|
|
|
if restart:
|
|
|
|
if self.changed_opts[opt][0] != self.changed_opts[opt][1]:
|
|
|
|
self.restart_label.show()
|
|
|
|
break
|
2005-08-10 02:56:18 +02:00
|
|
|
|
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')
|
2006-03-04 01:25:36 +01:00
|
|
|
self.remember_option(option + '\n' + key + '\n' + optname, modelrow[1],
|
|
|
|
text)
|
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:
|
2006-03-04 01:25:36 +01:00
|
|
|
self.remember_option(option, modelrow[1], text)
|
2005-08-05 12:26:10 +02:00
|
|
|
gajim.config.set(option, text)
|
2005-10-20 13:17:17 +02:00
|
|
|
gajim.interface.save_config()
|
2005-04-24 01:57:02 +02:00
|
|
|
modelrow[1] = text
|
2006-03-04 01:25:36 +01:00
|
|
|
self.check_for_restart()
|
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-11-13 16:08:47 +01:00
|
|
|
del gajim.interface.instances['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
|
|
|
|
2008-11-05 21:26:58 +01:00
|
|
|
def fill_model(self, node=None, parent=None):
|
|
|
|
for item, option in gajim.config.get_children(node):
|
|
|
|
name = item[-1]
|
|
|
|
if option is None: # Node
|
|
|
|
newparent = self.model.append(parent, [name, '', ''])
|
|
|
|
self.fill_model(item, newparent)
|
|
|
|
else: # Leaf
|
|
|
|
type_ = self.types[option[OPT_TYPE][0]]
|
|
|
|
if name == 'password':
|
|
|
|
value = _('Hidden')
|
|
|
|
else:
|
|
|
|
value = self.right_true_dict.get(option[OPT_VAL],
|
|
|
|
option[OPT_VAL])
|
|
|
|
self.model.append(parent, [name, value, type_])
|
2005-12-06 13:45:32 +01:00
|
|
|
|
2008-11-05 21:26:58 +01:00
|
|
|
def visible_func(self, model, treeiter):
|
2009-04-23 08:58:55 +02:00
|
|
|
search_string = self.entry.get_text().lower()
|
|
|
|
for it in tree_model_pre_order(model,treeiter):
|
|
|
|
if model[it][C_TYPE] != '':
|
|
|
|
opt_path = self.get_option_path(model, it)
|
|
|
|
if len(opt_path) == 3:
|
|
|
|
desc = gajim.config.get_desc_per(opt_path[2], opt_path[1],
|
|
|
|
opt_path[0])
|
|
|
|
elif len(opt_path) == 1:
|
|
|
|
desc = gajim.config.get_desc(opt_path[0])
|
|
|
|
if search_string in model[it][C_PREFNAME] or (desc and \
|
|
|
|
search_string in desc.lower()):
|
|
|
|
return True
|
|
|
|
return False
|
2008-11-05 21:26:58 +01:00
|
|
|
|
|
|
|
@rate_limit(3)
|
2005-04-27 17:16:40 +02:00
|
|
|
def on_advanced_entry_changed(self, widget):
|
2005-05-13 20:05:15 +02:00
|
|
|
self.modelfilter.refilter()
|
2008-11-05 21:26:58 +01:00
|
|
|
if not widget.get_text():
|
|
|
|
# Maybe the expanded rows should be remembered here ...
|
|
|
|
self.treeview.collapse_all()
|
|
|
|
else:
|
|
|
|
# ... and be restored correctly here
|
2008-12-03 22:56:12 +01:00
|
|
|
self.treeview.expand_all()
|
2008-07-29 21:49:31 +02:00
|
|
|
|
2008-08-15 05:20:23 +02:00
|
|
|
# vim: se ts=3:
|