2
# -*- coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
4
# Copyright (C) 2016 Canonical
6
# This program is free software; you can redistribute it and/or modify it under
7
# the terms of the GNU General Public License as published by the Free Software
8
# Foundation; version 3.
10
# This program is distributed in the hope that it will be useful, but WITHOUTa
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15
# You should have received a copy of the GNU General Public License along with
16
# this program. If not, see <http://www.gnu.org/licenses/>.
19
# Copy ubuntu-system-settings keyboard panel settings from AccountsService to
20
# GSettings. This might seem backwards (AS has the more modern location),
21
# and early on in Ubuntu Touch days, we did indeed only store the values in
22
# AccountsService. But once we started using indicator-keyboard, which read
23
# from GSettings, it was easier to copy the values to both places rather than
24
# update the indicator and all other legacy consumers of the GSettings key in
25
# Ubuntu. So we do a one-time sync here if we have values in AccountsService
26
# but not GSettings. Along with a change to our code to write to both places
27
# when the user adjust settings.
34
from gi.repository import Gio
35
from gi.repository import GLib
38
system_bus = dbus.SystemBus()
39
manager_proxy = system_bus.get_object('org.freedesktop.Accounts',
40
'/org/freedesktop/Accounts')
41
object_path = manager_proxy.FindUserById(
42
os.getuid(), dbus_interface='org.freedesktop.Accounts'
44
user_proxy = system_bus.get_object('org.freedesktop.Accounts', object_path)
46
gsettings = Gio.Settings(schema="org.gnome.desktop.input-sources")
49
def get_accountsservice():
51
return user_proxy.Get("org.freedesktop.Accounts.User", "InputSources",
52
dbus_interface=dbus.PROPERTIES_IFACE)
53
except dbus.exceptions.DBusException as e:
54
print("Couldn't get InputSources: %s" % (e), file=sys.stderr)
59
return bool(gsettings.get_value("sources"))
62
def set_gsettings(as_value):
63
# AS stores a list of maps, GSettings stores a list of tuples.
64
builder = GLib.VariantBuilder.new(GLib.VariantType.new("a(ss)"))
65
for as_map in as_value:
67
gkey = GLib.Variant.new_string(as_key)
68
gvalue = GLib.Variant.new_string(as_map[as_key])
69
gtuple = GLib.Variant.new_tuple(gkey, gvalue)
70
builder.add_value(gtuple)
71
gsettings.set_value("sources", builder.end())
74
as_value = get_accountsservice()
75
if as_value and not has_gsettings():
76
set_gsettings(as_value)