changelog: Describe v0.4, closes 1 bug
[dragbox/debian.git] / Dragbox / preferences.py
blobb1124301256e43f14b035dbccce157ed3b5ee4ec
1 # Copyright (C) 2006 Ulrik Sverdrup
3 # dragbox -- Commandline drag-and-drop tool for GNOME
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18 # USA
20 u"""
21 Preference database handlers
22 interfaces with gconf
23 """
24 from version import pref_id
26 from gconf import client_get_default
27 shared_client = client_get_default()
29 def get_gconf_client():
30 """
31 Returns a gconf client object
32 """
33 return shared_client
35 def get_bool(key, if_none=None):
36 """
37 get a bool value
39 @param key: key in the application domain to get
40 @type key: a string object.
42 @param if_none: Placeholder if no value is set
43 @type if_none: a bool object.
44 """
45 client = shared_client
46 gcvalue = client.get_without_default(pref_id + key)
48 if gcvalue:
49 value = gcvalue.get_bool()
50 else:
51 value = if_none
53 return value
55 def set_bool(key, value):
56 """
57 Sets a key in the application domain
59 @param key: key
60 @type key: a string object.
62 @param value:
63 @type value: a bool object.
64 """
65 client = shared_client
66 client.set_bool(pref_id + key, value)
68 def notify_add(key, callback, user_info=None):
69 """
70 Registers a delegate for callbacks when a key is changed
72 Callback id:
73 callback(client, connection, entry, user_info):
75 @param key: The prefs key that changes
76 @type key: a string object.
78 @param callback:
79 @type callback: a function object.
81 @param user_info: optional user info
82 @type user_info: an object.
83 """
84 from utils import print_debug
85 #print_debug("notify-add: %s" % (dragbox_pref_id + key,))
86 shared_client.notify_add(pref_id + key, callback, user_info)