1
#! /usr/bin/env python3
2
# -*- coding: utf-8 -*-
5
# Copyright (C) 2013 ~ 2014 National University of Defense Technology(NUDT) & Kylin Ltd
7
# Author: Kobe Lee <xiangli@ubuntukylin.com>
8
# Maintainer: Ubuntu Kylin
10
# This program is free software: you can redistribute it and/or modify it
11
# under the terms of the GNU General Public License version 3, as published
12
# by the Free Software Foundation.
14
# This program is distributed in the hope that it will be useful, but
15
# WITHOUT ANY WARRANTY; without even the implied warranties of
16
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
17
# PURPOSE. See the GNU General Public License for more details.
19
# You should have received a copy of the GNU General Public License along
20
# with this program. If not, see <http://www.gnu.org/licenses/>.
24
from gi.repository import Gio as gio
27
from .common import Schema
29
#http://lazka.github.io/pgi-docs/api/Gio_2.0/classes/Settings.html
33
#BASE_KEY = "org.gnome.gedit.preferences.encodings"
34
def __init__(self, schema):
35
self.db = gio.Settings.new(schema)
37
#def open_settings_db(self):
39
# self.db = gio.Settings.new(self.BASE_KEY)
40
# except Exception as e:
43
def get_value(self, key, type):
48
bytes: self.db.get_string,
49
bool: self.db.get_boolean,
50
list: self.db.get_strv,
51
dict: self.db.get_string,
52
type(None): self.db.get_value,
55
except Exception as e:
59
def set_value(self, key, type, value):
64
bytes: self.db.set_string,
65
bool: self.db.set_boolean,
66
list: self.db.set_strv,
67
dict: self.db.set_string,
68
type(None): self.db.set_value,
71
except Exception as e:
74
def get_schema_value(self, schema, key):
75
schema_default = Schema.load_schema(schema, key)
76
if schema_default is not None:
81
# kobe: test notify func
82
# def connect_notify(self):
83
# #def connect_notify(self, func, data=None):
84
## gs = gio.Settings("org.gnome.nautilus.desktop", None)
85
# self.db.connect("changed::home-icon-visible", self.kobe_test)
87
# def kobe_test(self, settings, key):
88
# print "notify test success----------------------------"
90
if __name__ == '__main__':
91
#list_on = ['GB18030', 'UTF-8', 'CURRENT', 'ISO-8859-15', 'UTF-16']
92
#list_off = ['UTF-8', 'CURRENT', 'ISO-8859-15', 'UTF-16']
93
settings = Settings("org.gnome.gedit.preferences.encodings")
94
##settings.open_settings_db()
95
#value = settings.get_value("auto-detected", types.ListType)
96
#print type(value)#<type 'list'>
98
#if value == list_off:
99
# settings.set_value("auto-detected", types.ListType, list_on)
101
# settings.set_value("auto-detected", types.ListType, list_off)
103
#settings = Settings("org.gnome.nautilus.preferences")
104
#value = settings.get_value("always-use-location-entry", types.BooleanType)
105
#settings = Settings("org.gnome.desktop.media-handling")
106
#value = settings.get_value("automount", types.BooleanType)
107
#print type(value)#<type 'list'>
110
default_value = settings.get_schema_value("org.gnome.gedit.preferences.encodings", "auto-detected")
111
print("default_value->")