summaryrefslogtreecommitdiff
path: root/src/tests/dbusmock-templates/localed.py
blob: db205d17e7ebf77ac192404450372b6dc5ed0449 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option) any
# later version.  See http://www.gnu.org/copyleft/lgpl.html for the full text
# of the license.

__author__ = 'Marco Trevisan'
__copyright__ = '(c) 2021 Canonical Ltd.'

import dbus
import time

BUS_NAME = 'org.freedesktop.locale1'
MAIN_OBJ = '/org/freedesktop/locale1'
MAIN_IFACE = 'org.freedesktop.locale1'
SYSTEM_BUS = True


def load(mock, parameters):
    mock.AddProperty(MAIN_IFACE, 'Locale', dbus.Array(['LANG=C'], signature='s'))
    mock.AddProperty(MAIN_IFACE, 'X11Layout', dbus.String())
    mock.AddProperty(MAIN_IFACE, 'X11Model', dbus.String())
    mock.AddProperty(MAIN_IFACE, 'X11Variant', dbus.String())
    mock.AddProperty(MAIN_IFACE, 'X11Options', dbus.String())
    mock.AddProperty(MAIN_IFACE, 'VConsoleKeymap', dbus.String())
    mock.AddProperty(MAIN_IFACE, 'VConsoleKeymapToggle', dbus.String())

def simulate_interaction():
    time.sleep(1)

@dbus.service.method(MAIN_IFACE, in_signature='asb')
def SetLocale(self, locale, interactive):
    if interactive:
        simulate_interaction()
    self.Set(MAIN_IFACE, 'Locale', locale)


@dbus.service.method(MAIN_IFACE, in_signature='ssbb')
def SetVConsoleKeyboard(self, keymap, keymap_toggle, convert, interactive):
    if interactive:
        simulate_interaction()
    self.Set(MAIN_IFACE, 'VConsoleKeymap', keymap)
    self.Set(MAIN_IFACE, 'VConsoleKeymapToggle', keymap_toggle)


@dbus.service.method(MAIN_IFACE, in_signature='ssssbb')
def SetVConsoleKeyboard(self, layout, model, variant, options, convert, interactive):
    if interactive:
        simulate_interaction()
    self.Set(MAIN_IFACE, 'X11Layout', layout)
    self.Set(MAIN_IFACE, 'X11Model', model)
    self.Set(MAIN_IFACE, 'X11Variant', variant)
    self.Set(MAIN_IFACE, 'X11Options', options)