~feng-kylin/youker-assistant/youker-assistant

« back to all changes in this revision

Viewing changes to backends/kylin-assistant-daemon/src/beautify/settings.py

  • Committer: lixiang
  • Date: 2018-03-06 03:13:06 UTC
  • Revision ID: lixiang@kylinos.cn-20180306031306-fd7qnru3vm4a1xjd
Rewrite with Qt5, and add system monitor

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python3
 
2
# -*- coding: utf-8 -*-
 
3
 
 
4
### BEGIN LICENSE
 
5
# Copyright (C) 2013 ~ 2014 National University of Defense Technology(NUDT) & Kylin Ltd
 
6
#
 
7
# Author:     Kobe Lee <xiangli@ubuntukylin.com>
 
8
# Maintainer: Ubuntu Kylin
 
9
#
 
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.
 
13
#
 
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.
 
18
#
 
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/>.
 
21
### END LICENSE
 
22
 
 
23
 
 
24
from gi.repository import Gio as gio
 
25
import os, sys
 
26
import types
 
27
from .common import Schema
 
28
 
 
29
#http://lazka.github.io/pgi-docs/api/Gio_2.0/classes/Settings.html
 
30
 
 
31
class Settings:
 
32
    #db = None
 
33
    #BASE_KEY             = "org.gnome.gedit.preferences.encodings"
 
34
    def __init__(self, schema):
 
35
        self.db = gio.Settings.new(schema)
 
36
 
 
37
    #def open_settings_db(self):
 
38
    #    try:
 
39
    #        self.db = gio.Settings.new(self.BASE_KEY)
 
40
    #    except Exception as e:
 
41
    #        print e
 
42
 
 
43
    def get_value(self, key, type):
 
44
        try:
 
45
            setting_type = type
 
46
            get_func = {
 
47
                int:     self.db.get_int,
 
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,
 
53
            }[setting_type]
 
54
            return get_func(key)
 
55
        except Exception as e:
 
56
            print(e)
 
57
            return None
 
58
 
 
59
    def set_value(self, key, type, value):
 
60
        try:
 
61
            setting_type = type
 
62
            set_func = {
 
63
                int:     self.db.set_int,
 
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,
 
69
            }[setting_type]
 
70
            set_func(key, value)
 
71
        except Exception as e:
 
72
            print(e)
 
73
 
 
74
    def get_schema_value(self, schema, key):
 
75
        schema_default = Schema.load_schema(schema, key)
 
76
        if schema_default is not None:
 
77
            return schema_default
 
78
        else:
 
79
            raise NotImplemented
 
80
 
 
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)
 
86
 
 
87
#    def kobe_test(self, settings, key):
 
88
#        print "notify test success----------------------------"
 
89
 
 
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'>
 
97
    #print value
 
98
    #if value == list_off:
 
99
    #    settings.set_value("auto-detected", types.ListType, list_on)
 
100
    #else:
 
101
    #    settings.set_value("auto-detected", types.ListType, list_off)
 
102
 
 
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'>
 
108
    #print value
 
109
 
 
110
    default_value = settings.get_schema_value("org.gnome.gedit.preferences.encodings", "auto-detected")
 
111
    print("default_value->")
 
112
    print(default_value)
 
113
 
 
114
 
 
115