1
# Copyright (C) 2009 Valmantas Paliksa <walmis at balticum-tv dot lt>
2
# Copyright (C) 2009 Tadas Dailyda <tadas at dailyda dot com>
4
# Licensed under the GNU General Public License Version 3
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
from blueman.plugins.ConfigPlugin import ConfigPlugin
21
from gi.repository import GConf
25
BLUEMAN_PATH = "/apps/blueman"
27
class Gconf(ConfigPlugin):
31
def on_load(self, section):
32
self.section = section
33
if self.section != "":
34
self.section = "/" + self.section
36
self.client = GConf.Client.get_default ()
38
self.client.add_dir(BLUEMAN_PATH + self.section, GConf.ClientPreloadType.PRELOAD_ONELEVEL)
39
self.client.connect("value_changed", self.value_changed)
41
# convert a GConfValue to python native value
42
def gval2pyval(self, val):
43
if val.type == GConf.ValueType.STRING:
44
return val.get_string()
45
elif val.type == GConf.ValueType.FLOAT:
46
return val.get_float()
47
elif val.type == GConf.ValueType.INT:
49
elif val.type == GConf.ValueType.BOOL:
51
elif val.type == GConf.ValueType.LIST:
53
for item in val.get_list():
54
x.append(self.gval2pyval(item))
57
raise AttributeError("Cant get this type from GConf: %s" % str(val.type))
59
def value_changed(self, client, key, value):
60
if os.path.dirname(key) == BLUEMAN_PATH + self.section:
61
name = os.path.basename(key)
62
self.emit("property-changed", name, self.get(name))
64
def _set_gconf_list(self, key, values):
65
gconf_value = '[%s]' % ','.join(values)
66
subprocess.check_output(["gconftool-2", "--set", "--type=list", "--list-type=string", key, gconf_value])
68
def set(self, key, value):
71
if type(value) == str:
72
func = self.client.set_string
73
elif type(value) == int:
74
func = self.client.set_int
75
elif type(value) == bool:
76
func = self.client.set_bool
77
elif type(value) == float:
78
func = self.client.set_float
79
elif type(value) == list:
80
func = self._set_gconf_list
82
raise AttributeError("Cant set this type in GConf: %s" % str(type(value)))
84
func(BLUEMAN_PATH + self.section + "/" + key, value)
87
val = self.client.get(BLUEMAN_PATH + self.section + "/" + key)
89
return self.gval2pyval(val)
94
rets = self.client.all_dirs(BLUEMAN_PATH + self.section)
97
l.append(r.replace(BLUEMAN_PATH + "/", ""))