2008-03-08 00:04:41 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# TerminatorConfig - layered config classes
|
|
|
|
# Copyright (C) 2006-2008 cmsj@tenshu.net
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
"""TerminatorConfig by Chris Jones <cmsj@tenshu.net>
|
|
|
|
|
|
|
|
The config scheme works in layers, with defaults at the base,
|
|
|
|
and a simple/flexible class which can be placed over the top
|
|
|
|
in multiple layers. This was written for Terminator, but
|
|
|
|
could be used generically. Its original use is to guarantee
|
|
|
|
default values for any config item, while allowing them to be
|
|
|
|
overridden by at least two other stores of configuration values.
|
|
|
|
Those being gconf and a plain config file.
|
|
|
|
In addition to the value, the default layer must also provide
|
|
|
|
the datatype (str, int, float and bool are currently supported).
|
|
|
|
values are found as attributes of the TerminatorConfig object.
|
|
|
|
Trying to read a value that doesn't exist will raise an
|
|
|
|
AttributeError. This is by design. If you want to look something
|
|
|
|
up, set a default for it first."""
|
|
|
|
|
2008-08-03 02:09:38 +00:00
|
|
|
import os, platform, sys, re
|
2008-03-08 00:04:41 +00:00
|
|
|
import pwd
|
2008-08-28 15:34:34 +00:00
|
|
|
import gtk, pango
|
2008-10-28 22:24:42 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
import gio
|
|
|
|
except ImportError:
|
|
|
|
pass
|
2008-03-08 00:04:41 +00:00
|
|
|
|
|
|
|
# set this to true to enable debugging output
|
2008-08-15 03:11:24 +00:00
|
|
|
# These should be moved somewhere better.
|
2008-06-26 23:24:52 +00:00
|
|
|
debug = False
|
2008-03-08 00:04:41 +00:00
|
|
|
|
|
|
|
def dbg (log = ""):
|
2008-07-22 11:03:30 +00:00
|
|
|
"""Print a message if debugging is enabled"""
|
2008-03-08 00:04:41 +00:00
|
|
|
if debug:
|
|
|
|
print >> sys.stderr, log
|
2008-06-28 20:20:49 +00:00
|
|
|
|
2008-06-16 23:10:44 +00:00
|
|
|
def err (log = ""):
|
2008-07-22 11:03:30 +00:00
|
|
|
"""Print an error message"""
|
2008-06-16 23:10:44 +00:00
|
|
|
print >> sys.stderr, log
|
2008-03-08 00:04:41 +00:00
|
|
|
|
2008-08-26 14:41:27 +00:00
|
|
|
from configfile import ConfigFile, ParsedWithErrors
|
2008-08-15 03:11:24 +00:00
|
|
|
|
2008-08-15 12:40:10 +00:00
|
|
|
Defaults = {
|
|
|
|
'gt_dir' : '/apps/gnome-terminal',
|
|
|
|
'profile_dir' : '/apps/gnome-terminal/profiles',
|
|
|
|
'titlebars' : True,
|
|
|
|
'titletips' : False,
|
|
|
|
'allow_bold' : True,
|
|
|
|
'silent_bell' : True,
|
|
|
|
'background_color' : '#000000',
|
|
|
|
'background_darkness' : 0.5,
|
|
|
|
'background_type' : 'solid',
|
|
|
|
'background_image' : '',
|
|
|
|
'backspace_binding' : 'ascii-del',
|
|
|
|
'delete_binding' : 'delete-sequence',
|
|
|
|
'cursor_blink' : True,
|
|
|
|
'emulation' : 'xterm',
|
2008-11-03 23:14:06 +00:00
|
|
|
'font' : 'Mono 10',
|
2008-08-15 12:40:10 +00:00
|
|
|
'foreground_color' : '#AAAAAA',
|
|
|
|
'scrollbar_position' : "right",
|
|
|
|
'scroll_background' : True,
|
|
|
|
'scroll_on_keystroke' : True,
|
|
|
|
'scroll_on_output' : True,
|
|
|
|
'scrollback_lines' : 500,
|
|
|
|
'focus' : 'click',
|
|
|
|
'exit_action' : 'close',
|
|
|
|
'palette' : '#000000000000:#CDCD00000000:#0000CDCD0000:#CDCDCDCD0000:#30BF30BFA38E:#A53C212FA53C:#0000CDCDCDCD:#FAFAEBEBD7D7:#404040404040:#FFFF00000000:#0000FFFF0000:#FFFFFFFF0000:#00000000FFFF:#FFFF0000FFFF:#0000FFFFFFFF:#FFFFFFFFFFFF',
|
|
|
|
'word_chars' : '-A-Za-z0-9,./?%&#:_',
|
|
|
|
'mouse_autohide' : True,
|
|
|
|
'update_records' : True,
|
|
|
|
'login_shell' : False,
|
|
|
|
'use_custom_command' : False,
|
|
|
|
'custom_command' : '',
|
|
|
|
'use_system_font' : True,
|
|
|
|
'use_theme_colors' : False,
|
|
|
|
'http_proxy' : '',
|
|
|
|
'ignore_hosts' : ['localhost','127.0.0.0/8','*.local'],
|
|
|
|
'encoding' : 'UTF-8',
|
|
|
|
'active_encodings' : ['UTF-8', 'ISO-8859-1'],
|
|
|
|
'extreme_tabs' : False,
|
|
|
|
'fullscreen' : False,
|
|
|
|
'borderless' : False,
|
|
|
|
'maximise' : False,
|
|
|
|
'handle_size' : -1,
|
|
|
|
'focus_on_close' : 'auto',
|
|
|
|
'f11_modifier' : False,
|
|
|
|
'force_no_bell' : False,
|
|
|
|
'cycle_term_tab' : True,
|
|
|
|
'copy_on_selection' : False,
|
|
|
|
'close_button_on_tab' : True,
|
2008-08-28 16:08:15 +00:00
|
|
|
'tab_position' : 'top',
|
2008-08-15 12:40:10 +00:00
|
|
|
'enable_real_transparency' : False,
|
|
|
|
'try_posix_regexp' : platform.system() != 'Linux',
|
|
|
|
'keybindings' : {
|
|
|
|
'zoom_in' : '<Ctrl>plus',
|
|
|
|
'zoom_out' : '<Ctrl>minus',
|
|
|
|
'zoom_normal' : '<Ctrl>0',
|
|
|
|
'new_root_tab' : '<Ctrl><Shift><Alt>T',
|
|
|
|
'new_tab' : '<Ctrl><Shift>T',
|
2008-08-23 22:57:51 +00:00
|
|
|
'go_next' : ('<Ctrl><Shift>N','<Ctrl>Tab'),
|
|
|
|
'go_prev' : ('<Ctrl><Shift>P','<Ctrl><Shift>Tab'),
|
2008-12-19 07:41:55 +00:00
|
|
|
'go_up' : '<Alt>Up',
|
|
|
|
'go_down' : '<Alt>Down',
|
|
|
|
'go_left' : '<Alt>Left',
|
|
|
|
'go_right' : '<Alt>Right',
|
2008-08-15 12:40:10 +00:00
|
|
|
'split_horiz' : '<Ctrl><Shift>O',
|
|
|
|
'split_vert' : '<Ctrl><Shift>E',
|
|
|
|
'close_term' : '<Ctrl><Shift>W',
|
|
|
|
'copy' : '<Ctrl><Shift>C',
|
|
|
|
'paste' : '<Ctrl><Shift>V',
|
|
|
|
'toggle_scrollbar' : '<Ctrl><Shift>S',
|
|
|
|
'search' : '<Ctrl><Shift>F',
|
|
|
|
'close_window' : '<Ctrl><Shift>Q',
|
|
|
|
'resize_up' : '<Ctrl><Shift>Up',
|
|
|
|
'resize_down' : '<Ctrl><Shift>Down',
|
|
|
|
'resize_left' : '<Ctrl><Shift>Left',
|
|
|
|
'resize_right' : '<Ctrl><Shift>Right',
|
|
|
|
'move_tab_right' : '<Ctrl><Shift>Page_Down',
|
|
|
|
'move_tab_left' : '<Ctrl><Shift>Page_Up',
|
|
|
|
'toggle_zoom' : '<Ctrl><Shift>X',
|
|
|
|
'scaled_zoom' : '<Ctrl><Shift>Z',
|
|
|
|
'next_tab' : '<Ctrl>Page_Down',
|
|
|
|
'prev_tab' : '<Ctrl>Page_Up',
|
|
|
|
'full_screen' : 'F11',
|
2008-11-17 10:42:34 +00:00
|
|
|
'reset' : '<Ctrl><Shift>R',
|
|
|
|
'reset_clear' : '<Ctrl><Shift>G',
|
2008-08-15 12:40:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-08 00:04:41 +00:00
|
|
|
class TerminatorConfig:
|
2008-07-22 11:03:30 +00:00
|
|
|
"""This class is used as the base point of the config system"""
|
2008-03-08 00:04:41 +00:00
|
|
|
callback = None
|
|
|
|
sources = []
|
|
|
|
|
2008-07-22 11:03:30 +00:00
|
|
|
def __init__ (self, sources):
|
2008-08-15 03:11:24 +00:00
|
|
|
self._keys = None
|
2008-03-08 00:04:41 +00:00
|
|
|
for source in sources:
|
|
|
|
if isinstance(source, TerminatorConfValuestore):
|
|
|
|
self.sources.append (source)
|
|
|
|
|
|
|
|
# We always add a default valuestore last so no valid config item ever goes unset
|
|
|
|
source = TerminatorConfValuestoreDefault ()
|
|
|
|
self.sources.append (source)
|
2008-08-15 03:11:24 +00:00
|
|
|
|
|
|
|
def _merge_keybindings(self):
|
|
|
|
if self._keys:
|
|
|
|
return self._keys
|
|
|
|
|
|
|
|
self._keys = {}
|
|
|
|
for source in reversed(self.sources):
|
|
|
|
try:
|
2008-08-22 05:45:31 +00:00
|
|
|
val = source['keybindings']
|
2008-08-15 03:11:24 +00:00
|
|
|
self._keys.update(val)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
return self._keys
|
|
|
|
|
|
|
|
keybindings = property(_merge_keybindings)
|
|
|
|
|
2008-03-08 00:04:41 +00:00
|
|
|
def __getattr__ (self, keyname):
|
|
|
|
for source in self.sources:
|
2008-05-23 10:31:05 +00:00
|
|
|
dbg ("TConfig: Looking for: '%s' in '%s'"%(keyname, source.type))
|
2008-03-08 00:04:41 +00:00
|
|
|
try:
|
2008-08-22 02:05:22 +00:00
|
|
|
val = source[keyname]
|
2008-04-07 20:49:10 +00:00
|
|
|
dbg (" TConfig: got: '%s' from a '%s'"%(val, source.type))
|
2008-03-08 00:04:41 +00:00
|
|
|
return (val)
|
2008-08-22 02:05:22 +00:00
|
|
|
except KeyError:
|
2008-03-08 00:04:41 +00:00
|
|
|
pass
|
2008-04-07 21:46:26 +00:00
|
|
|
|
2008-04-07 20:49:10 +00:00
|
|
|
dbg (" TConfig: Out of sources")
|
2008-03-08 00:04:41 +00:00
|
|
|
raise (AttributeError)
|
|
|
|
|
|
|
|
class TerminatorConfValuestore:
|
|
|
|
type = "Base"
|
|
|
|
values = {}
|
2008-03-08 01:38:42 +00:00
|
|
|
reconfigure_callback = None
|
|
|
|
|
2008-03-08 00:04:41 +00:00
|
|
|
# Our settings
|
2008-08-22 02:05:22 +00:00
|
|
|
def __getitem__ (self, keyname):
|
2008-03-08 00:04:41 +00:00
|
|
|
if self.values.has_key (keyname):
|
2008-10-23 22:29:26 +00:00
|
|
|
value = self.values[keyname]
|
|
|
|
dbg ("Returning '%s':'%s'"%(keyname, value))
|
|
|
|
return value
|
2008-03-08 00:04:41 +00:00
|
|
|
else:
|
2008-05-23 10:31:05 +00:00
|
|
|
dbg ("Failed to find '%s'"%keyname)
|
2008-08-22 02:05:22 +00:00
|
|
|
raise (KeyError)
|
2008-03-08 00:04:41 +00:00
|
|
|
|
|
|
|
class TerminatorConfValuestoreDefault (TerminatorConfValuestore):
|
|
|
|
def __init__ (self):
|
|
|
|
self.type = "Default"
|
2008-08-15 12:40:10 +00:00
|
|
|
self.values = Defaults
|
2008-03-08 00:04:41 +00:00
|
|
|
|
|
|
|
class TerminatorConfValuestoreRC (TerminatorConfValuestore):
|
|
|
|
rcfilename = ""
|
2008-08-15 03:11:24 +00:00
|
|
|
type = "RCFile"
|
2008-03-08 00:04:41 +00:00
|
|
|
def __init__ (self):
|
2008-06-17 00:20:37 +00:00
|
|
|
try:
|
|
|
|
directory = os.environ['XDG_CONFIG_HOME']
|
2008-07-12 14:35:36 +00:00
|
|
|
except KeyError, e:
|
2008-08-29 13:09:29 +00:00
|
|
|
dbg(" VS_RCFile: Environment variable XDG_CONFIG_HOME not found. defaulting to ~/.config")
|
2008-07-12 14:35:36 +00:00
|
|
|
directory = os.path.join (os.path.expanduser("~"), ".config")
|
|
|
|
self.rcfilename = os.path.join(directory, "terminator/config")
|
2008-07-12 23:36:53 +00:00
|
|
|
dbg(" VS_RCFile: config file located at %s" % self.rcfilename)
|
2008-10-23 22:29:26 +00:00
|
|
|
self.call_parser(True)
|
|
|
|
|
2008-12-26 16:15:48 +00:00
|
|
|
#try:
|
|
|
|
# monfile = gio.File(self.rcfilename)
|
|
|
|
# monmon = monfile.monitor_file()
|
|
|
|
# monmon.connect("changed", self.file_changed)
|
|
|
|
#except NameError:
|
|
|
|
# dbg ("gio module not found, config file monitoring disabled")
|
2008-10-23 22:29:26 +00:00
|
|
|
|
|
|
|
def set_reconfigure_callback (self, function):
|
|
|
|
dbg (" VS_RCFile: setting callback to: %s"%function)
|
|
|
|
self.reconfigure_callback = function
|
|
|
|
return (True)
|
|
|
|
|
|
|
|
def file_changed (self, monitor, file, unknown, event):
|
|
|
|
if event == gio.FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
|
2008-12-26 16:15:48 +00:00
|
|
|
dbg (" VS_RCFile: config file changed, reload")
|
2008-10-23 22:29:26 +00:00
|
|
|
self.values = {}
|
|
|
|
self.call_parser()
|
|
|
|
self.reconfigure_callback()
|
|
|
|
|
|
|
|
def call_parser (self, is_init = False):
|
|
|
|
dbg (" VS_RCFile: parsing config file")
|
|
|
|
try:
|
2008-11-01 10:07:58 +00:00
|
|
|
ini = ConfigFile(self.rcfilename, self._rc_set_callback())
|
2008-10-23 22:29:26 +00:00
|
|
|
ini.parse()
|
2008-11-01 10:07:58 +00:00
|
|
|
except IOError, e:
|
2008-11-04 17:01:00 +00:00
|
|
|
dbg (" VS_RCFile: unable to open %s (%r)" % (self.rcfilename, e))
|
2008-10-23 22:29:26 +00:00
|
|
|
except ParsedWithErrors, e:
|
|
|
|
# We don't really want to produce an error dialog every run
|
|
|
|
if not is_init:
|
|
|
|
pass
|
|
|
|
msg = _("""<big><b>Configuration error</b></big>
|
2008-08-28 15:34:34 +00:00
|
|
|
|
|
|
|
Errors were encountered while parsing terminator_config(5) file:
|
2008-08-26 16:04:53 +00:00
|
|
|
|
|
|
|
<b>%s</b>
|
|
|
|
|
2008-08-28 15:34:34 +00:00
|
|
|
%d line(s) have been ignored.""") % (self.rcfilename, len(e.errors))
|
|
|
|
|
2008-10-23 22:29:26 +00:00
|
|
|
dialog = gtk.Dialog(_("Configuration error"), None, gtk.DIALOG_MODAL,
|
|
|
|
(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
|
|
|
|
dialog.set_has_separator(False)
|
|
|
|
dialog.set_resizable(False)
|
|
|
|
|
|
|
|
image = gtk.image_new_from_stock(gtk.STOCK_DIALOG_WARNING, gtk.ICON_SIZE_DIALOG)
|
|
|
|
image.set_alignment (0.5, 0)
|
|
|
|
dmsg = gtk.Label(msg)
|
|
|
|
dmsg.set_use_markup(True)
|
|
|
|
dmsg.set_alignment(0, 0.5)
|
|
|
|
|
|
|
|
textbuff = gtk.TextBuffer()
|
|
|
|
textbuff.set_text("\n".join(map(lambda e: str(e), e.errors)))
|
|
|
|
textview = gtk.TextView(textbuff)
|
|
|
|
textview.set_editable(False)
|
|
|
|
|
|
|
|
textview.modify_font(pango.FontDescription(Defaults['font']))
|
|
|
|
textscroll = gtk.ScrolledWindow()
|
|
|
|
textscroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
|
|
|
textscroll.add(textview)
|
|
|
|
# This should be scaled with the size of the text and font
|
|
|
|
textscroll.set_size_request(600, 200)
|
|
|
|
|
|
|
|
root = gtk.VBox()
|
|
|
|
root.pack_start(dmsg, padding = 6)
|
|
|
|
root.pack_start(textscroll, padding = 6)
|
|
|
|
|
|
|
|
box = gtk.HBox()
|
|
|
|
box.pack_start (image, False, False, 6)
|
|
|
|
box.pack_start (root, False, False, 6)
|
|
|
|
dialog.vbox.pack_start (box, False, False, 12)
|
|
|
|
dialog.show_all()
|
|
|
|
|
|
|
|
dialog.run()
|
|
|
|
dialog.destroy()
|
2008-03-08 00:04:41 +00:00
|
|
|
|
2008-11-04 17:01:00 +00:00
|
|
|
dbg("ConfigFile settings are: %r" % self.values)
|
2008-08-26 23:55:57 +00:00
|
|
|
|
2008-08-26 23:30:13 +00:00
|
|
|
def _rc_set_callback(self):
|
2008-11-01 11:31:12 +00:00
|
|
|
def callback(sections, key, value):
|
2008-11-04 17:01:00 +00:00
|
|
|
dbg("Setting: section=%r with %r => %r" % (sections, key, value))
|
2008-11-01 11:31:12 +00:00
|
|
|
section = None
|
|
|
|
if len(sections) > 0:
|
|
|
|
section = sections[0]
|
2008-08-26 23:30:13 +00:00
|
|
|
if section is None:
|
|
|
|
if not Defaults.has_key (key):
|
2008-11-04 17:01:00 +00:00
|
|
|
raise ValueError("Unknown configuration option %r" % key)
|
2008-08-26 23:30:13 +00:00
|
|
|
deftype = Defaults[key].__class__.__name__
|
|
|
|
if key.endswith('_color'):
|
|
|
|
try:
|
|
|
|
gtk.gdk.color_parse(value)
|
2008-08-15 03:11:24 +00:00
|
|
|
self.values[key] = value
|
2008-08-26 23:30:13 +00:00
|
|
|
except ValueError:
|
2008-11-04 17:01:00 +00:00
|
|
|
raise ValueError(_("Setting %r value %r not a valid colour; ignoring") % (key, value))
|
2008-08-28 16:08:15 +00:00
|
|
|
elif key == 'tab_position':
|
|
|
|
if value.lower() in ('top', 'left', 'bottom', 'right'):
|
|
|
|
self.values[key] = value.lower()
|
|
|
|
else:
|
|
|
|
raise ValueError(_("%s must be one of: top, left, right, bottom") % key)
|
2008-08-26 23:30:13 +00:00
|
|
|
elif deftype == 'bool':
|
|
|
|
if value.lower () in ('true', 'yes', 'on'):
|
|
|
|
self.values[key] = True
|
|
|
|
elif value.lower () in ('false', 'no', 'off'):
|
|
|
|
self.values[key] = False
|
2008-08-15 03:11:24 +00:00
|
|
|
else:
|
2008-08-26 23:30:13 +00:00
|
|
|
raise ValueError(_("Boolean setting %s expecting one of: yes, no, true, false, on, off") % key)
|
|
|
|
elif deftype == 'int':
|
|
|
|
self.values[key] = int (value)
|
|
|
|
elif deftype == 'float':
|
|
|
|
self.values[key] = float (value)
|
|
|
|
elif deftype == 'list':
|
|
|
|
raise ValueError(_("Reading list values from terminator_config(5) is not currently supported"))
|
|
|
|
elif deftype == 'dict':
|
|
|
|
if type(value) != dict:
|
2008-11-04 17:01:00 +00:00
|
|
|
raise ValueError(_("Setting %r should be a section name") % key)
|
2008-08-26 23:30:13 +00:00
|
|
|
self.values[key] = value
|
|
|
|
else:
|
|
|
|
self.values[key] = value
|
2008-05-23 12:28:56 +00:00
|
|
|
|
2008-11-04 17:01:00 +00:00
|
|
|
dbg (" VS_RCFile: Set value %r to %r" % (key, self.values[key]))
|
2008-08-26 23:30:13 +00:00
|
|
|
elif section == 'keybindings':
|
|
|
|
self.values.setdefault(section, {})
|
|
|
|
if not Defaults[section].has_key(key):
|
2008-11-04 17:01:00 +00:00
|
|
|
raise ValueError("Keybinding name %r is unknown" % key)
|
2008-08-26 23:30:13 +00:00
|
|
|
else:
|
|
|
|
self.values[section][key] = value
|
|
|
|
else:
|
2008-11-04 17:01:00 +00:00
|
|
|
raise ValueError("Section name %r is unknown" % section)
|
2008-08-26 23:30:13 +00:00
|
|
|
return callback
|
2008-03-08 00:04:41 +00:00
|
|
|
|
|
|
|
class TerminatorConfValuestoreGConf (TerminatorConfValuestore):
|
|
|
|
profile = ""
|
|
|
|
client = None
|
2008-04-11 12:09:34 +00:00
|
|
|
cache = {}
|
2008-03-08 00:04:41 +00:00
|
|
|
|
|
|
|
def __init__ (self, profile = None):
|
|
|
|
self.type = "GConf"
|
2008-08-26 20:43:07 +00:00
|
|
|
self.inactive = False
|
2008-03-08 00:04:41 +00:00
|
|
|
|
2008-04-02 21:10:32 +00:00
|
|
|
import gconf
|
|
|
|
|
2008-03-08 00:04:41 +00:00
|
|
|
self.client = gconf.client_get_default ()
|
|
|
|
|
|
|
|
# Grab a couple of values from base class to avoid recursing with our __getattr__
|
2008-08-15 16:27:16 +00:00
|
|
|
self._gt_dir = Defaults['gt_dir']
|
|
|
|
self._profile_dir = Defaults['profile_dir']
|
2008-03-08 00:04:41 +00:00
|
|
|
|
2008-06-15 10:15:45 +00:00
|
|
|
dbg ('VSGConf: Profile requested is: "%s"'%profile)
|
2008-03-08 01:38:42 +00:00
|
|
|
if not profile:
|
|
|
|
profile = self.client.get_string (self._gt_dir + '/global/default_profile')
|
2008-06-15 10:15:45 +00:00
|
|
|
dbg ('VSGConf: Profile bet on is: "%s"'%profile)
|
2008-03-08 01:38:42 +00:00
|
|
|
profiles = self.client.get_list (self._gt_dir + '/global/profile_list','string')
|
2008-06-15 10:15:45 +00:00
|
|
|
dbg ('VSGConf: Found profiles: "%s"'%profiles)
|
2008-03-08 01:38:42 +00:00
|
|
|
|
2008-05-15 16:03:57 +00:00
|
|
|
#set up the active encoding list
|
|
|
|
self.active_encodings = self.client.get_list (self._gt_dir + '/global/active_encodings', 'string')
|
|
|
|
|
2008-05-20 23:37:04 +00:00
|
|
|
#need to handle the list of Gconf.value
|
2008-03-08 01:38:42 +00:00
|
|
|
if profile in profiles:
|
2008-04-07 20:49:10 +00:00
|
|
|
dbg (" VSGConf: Found profile '%s' in profile_list"%profile)
|
2008-03-08 01:38:42 +00:00
|
|
|
self.profile = '%s/%s'%(self._profile_dir, profile)
|
|
|
|
elif "Default" in profiles:
|
2008-04-07 20:49:10 +00:00
|
|
|
dbg (" VSGConf: profile '%s' not found, but 'Default' exists"%profile)
|
2008-03-08 01:38:42 +00:00
|
|
|
self.profile = '%s/%s'%(self._profile_dir, "Default")
|
2008-03-08 00:04:41 +00:00
|
|
|
else:
|
2008-03-08 01:38:42 +00:00
|
|
|
# We're a bit stuck, there is no profile in the list
|
|
|
|
# FIXME: Find a better way to handle this than setting a non-profile
|
2008-08-26 20:43:07 +00:00
|
|
|
dbg ("VSGConf: No profile found, marking inactive")
|
|
|
|
self.inactive = True
|
2008-09-13 00:58:48 +00:00
|
|
|
return
|
2008-03-08 01:38:42 +00:00
|
|
|
|
|
|
|
self.client.add_dir (self.profile, gconf.CLIENT_PRELOAD_RECURSIVE)
|
|
|
|
if self.on_gconf_notify:
|
|
|
|
self.client.notify_add (self.profile, self.on_gconf_notify)
|
|
|
|
|
|
|
|
self.client.add_dir ('/apps/metacity/general', gconf.CLIENT_PRELOAD_RECURSIVE)
|
|
|
|
self.client.notify_add ('/apps/metacity/general/focus_mode', self.on_gconf_notify)
|
2008-04-07 23:12:22 +00:00
|
|
|
self.client.add_dir ('/desktop/gnome/interface', gconf.CLIENT_PRELOAD_RECURSIVE)
|
|
|
|
self.client.notify_add ('/desktop/gnome/interface/monospace_font_name', self.on_gconf_notify)
|
2008-04-02 21:10:32 +00:00
|
|
|
# FIXME: Do we need to watch more non-profile stuff here?
|
|
|
|
|
|
|
|
def set_reconfigure_callback (self, function):
|
2008-04-07 20:49:10 +00:00
|
|
|
dbg (" VSConf: setting callback to: %s"%function)
|
2008-04-02 21:10:32 +00:00
|
|
|
self.reconfigure_callback = function
|
|
|
|
return (True)
|
2008-03-08 01:38:42 +00:00
|
|
|
|
|
|
|
def on_gconf_notify (self, client, cnxn_id, entry, what):
|
2008-04-11 12:09:34 +00:00
|
|
|
dbg (" VSGConf: invalidating cache")
|
|
|
|
self.cache = {}
|
2008-10-16 15:30:42 +00:00
|
|
|
dbg (" VSGConf: gconf changed, may run a callback. %s, %s"%(entry.key, entry.value))
|
|
|
|
if entry.key[-12:] == 'visible_name':
|
|
|
|
dbg (" VSGConf: only a visible_name change, ignoring")
|
|
|
|
return False
|
2008-03-08 01:38:42 +00:00
|
|
|
if self.reconfigure_callback:
|
2008-10-16 15:30:42 +00:00
|
|
|
dbg (" VSGConf: callback is: %s"%self.reconfigure_callback)
|
2008-03-08 01:38:42 +00:00
|
|
|
self.reconfigure_callback ()
|
2008-03-08 00:04:41 +00:00
|
|
|
|
2008-08-22 02:05:22 +00:00
|
|
|
def __getitem__ (self, key = ""):
|
2008-08-26 20:43:07 +00:00
|
|
|
if self.inactive:
|
2008-08-28 12:56:16 +00:00
|
|
|
raise KeyError
|
2008-08-26 20:43:07 +00:00
|
|
|
|
2008-04-11 12:09:34 +00:00
|
|
|
if self.cache.has_key (key):
|
|
|
|
dbg (" VSGConf: returning cached value: %s"%self.cache[key])
|
|
|
|
return (self.cache[key])
|
|
|
|
|
2008-03-08 00:04:41 +00:00
|
|
|
ret = None
|
2008-04-07 20:49:10 +00:00
|
|
|
value = None
|
2008-03-08 00:04:41 +00:00
|
|
|
|
2008-04-07 20:49:10 +00:00
|
|
|
dbg (' VSGConf: preparing: %s/%s'%(self.profile, key))
|
2008-05-20 23:37:04 +00:00
|
|
|
|
2008-04-07 22:26:51 +00:00
|
|
|
# FIXME: Ugly special cases we should look to fix in some other way.
|
2008-08-26 20:43:07 +00:00
|
|
|
if key == 'font' and self['use_system_font']:
|
2008-04-07 22:26:51 +00:00
|
|
|
value = self.client.get ('/desktop/gnome/interface/monospace_font_name')
|
|
|
|
elif key == 'focus':
|
|
|
|
value = self.client.get ('/apps/metacity/general/focus_mode')
|
2008-04-09 23:22:20 +00:00
|
|
|
elif key == 'http_proxy':
|
|
|
|
if self.client.get_bool ('/system/http_proxy/use_http_proxy'):
|
|
|
|
dbg ('HACK: Mangling http_proxy')
|
|
|
|
|
2008-09-02 14:25:12 +00:00
|
|
|
if self.client.get_bool ('/system/http_proxy/use_authentication'):
|
2008-04-09 23:22:20 +00:00
|
|
|
dbg ('HACK: Using proxy authentication')
|
|
|
|
value = 'http://%s:%s@%s:%s/'%(
|
|
|
|
self.client.get_string ('/system/http_proxy/authentication_user'),
|
|
|
|
self.client.get_string ('/system/http_proxy/authentication_password'),
|
|
|
|
self.client.get_string ('/system/http_proxy/host'),
|
|
|
|
self.client.get_int ('/system/http_proxy/port'))
|
|
|
|
else:
|
|
|
|
dbg ('HACK: Not using proxy authentication')
|
|
|
|
value = 'http://%s:%s/'%(
|
|
|
|
self.client.get_string ('/system/http_proxy/host'),
|
|
|
|
self.client.get_int ('/system/http_proxy/port'))
|
2008-04-02 21:10:32 +00:00
|
|
|
else:
|
|
|
|
value = self.client.get ('%s/%s'%(self.profile, key))
|
2008-04-07 20:49:10 +00:00
|
|
|
|
2008-03-08 00:04:41 +00:00
|
|
|
if value:
|
2008-09-04 21:27:13 +00:00
|
|
|
from types import StringType
|
|
|
|
if type(value) is StringType:
|
|
|
|
ret = value
|
|
|
|
else:
|
|
|
|
funcname = "get_" + Defaults[key].__class__.__name__
|
|
|
|
dbg (' GConf: picked function: %s'%funcname)
|
|
|
|
# Special case for str
|
|
|
|
if funcname == "get_str":
|
|
|
|
funcname = "get_string"
|
|
|
|
# Special case for strlist
|
|
|
|
if funcname == "get_strlist":
|
|
|
|
funcname = "get_list"
|
|
|
|
typefunc = getattr (value, funcname)
|
|
|
|
ret = typefunc ()
|
2008-03-08 00:04:41 +00:00
|
|
|
|
2008-04-11 12:09:34 +00:00
|
|
|
self.cache[key] = ret
|
2008-03-08 00:04:41 +00:00
|
|
|
return (ret)
|
|
|
|
else:
|
2008-08-22 02:05:22 +00:00
|
|
|
raise (KeyError)
|
2008-03-08 00:04:41 +00:00
|
|
|
|