~ubuntu-branches/ubuntu/wily/blueman/wily

« back to all changes in this revision

Viewing changes to blueman/plugins/config/Gconf.py

  • Committer: Package Import Robot
  • Author(s): Sean Davis
  • Date: 2015-09-07 12:48:18 UTC
  • mfrom: (2.3.11 sid)
  • Revision ID: package-import@ubuntu.com-20150907124818-evulc0mhjotz8q29
Tags: 2.0-1ubuntu1
* Merge from Debian unstable (LP: #1482626). Remaining changes:
  - debian/patches/03_filemanage_fix.patch:
    + Dropped, no longer needed.
  - debian/patches/dhcpclient_priority
  - debian/patches/01_dont_autostart_lxde.patch
    + Refreshed patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009 Valmantas Paliksa <walmis at balticum-tv dot lt>
2
 
# Copyright (C) 2009 Tadas Dailyda <tadas at dailyda dot com>
3
 
#
4
 
# Licensed under the GNU General Public License Version 3
5
 
#
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.
10
 
#
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.
15
 
#
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/>.
18
 
19
 
 
20
 
from blueman.plugins.ConfigPlugin import ConfigPlugin
21
 
from gi.repository import GConf
22
 
import os
23
 
import subprocess
24
 
 
25
 
BLUEMAN_PATH = "/apps/blueman"
26
 
 
27
 
class Gconf(ConfigPlugin):
28
 
        __priority__ = 0
29
 
        __plugin__ = "GConf"
30
 
        
31
 
        def on_load(self, section):
32
 
                self.section = section
33
 
                if self.section != "":
34
 
                        self.section = "/" + self.section
35
 
                
36
 
                self.client = GConf.Client.get_default ()
37
 
                
38
 
                self.client.add_dir(BLUEMAN_PATH + self.section, GConf.ClientPreloadType.PRELOAD_ONELEVEL)
39
 
                self.client.connect("value_changed", self.value_changed)
40
 
 
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:
48
 
                        return val.get_int()
49
 
                elif val.type == GConf.ValueType.BOOL:
50
 
                        return val.get_bool()
51
 
                elif val.type == GConf.ValueType.LIST:
52
 
                        x = []
53
 
                        for item in val.get_list():
54
 
                                x.append(self.gval2pyval(item))
55
 
                        return x
56
 
                else:
57
 
                        raise AttributeError("Cant get this type from GConf: %s" % str(val.type))
58
 
        
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))             
63
 
        
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])
67
 
        
68
 
        def set(self, key, value):
69
 
                func = None
70
 
        
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
81
 
                else:
82
 
                        raise AttributeError("Cant set this type in GConf: %s" % str(type(value)))
83
 
                
84
 
                func(BLUEMAN_PATH + self.section + "/" + key, value)
85
 
                
86
 
        def get(self, key):
87
 
                val = self.client.get(BLUEMAN_PATH + self.section + "/" + key)
88
 
                if val != None:
89
 
                        return self.gval2pyval(val)
90
 
                else:
91
 
                        return None
92
 
                        
93
 
        def list_dirs(self):
94
 
                rets = self.client.all_dirs(BLUEMAN_PATH + self.section)
95
 
                l = []
96
 
                for r in rets:
97
 
                        l.append(r.replace(BLUEMAN_PATH + "/", ""))
98
 
                return l