| 1 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
# |
| 3 |
# This file is formatted with Python Black |
| 4 |
# mypy: disable-error-code="misc" |
| 5 |
|
| 6 |
from tests.templates import init_logger |
| 7 |
|
| 8 |
import dbus.service |
| 9 |
from dbusmock import MOCK_IFACE |
| 10 |
|
| 11 |
|
| 12 |
BUS_NAME = "org.freedesktop.impl.portal.Test" |
| 13 |
MAIN_OBJ = "/org/freedesktop/portal/desktop" |
| 14 |
SYSTEM_BUS = False |
| 15 |
MAIN_IFACE = "org.freedesktop.impl.portal.Notification" |
| 16 |
VERSION = 2 |
| 17 |
|
| 18 |
|
| 19 |
logger = init_logger(__name__) |
| 20 |
|
| 21 |
|
| 22 |
def load(mock, parameters={}): |
| 23 |
logger.debug(f"Loading parameters: {parameters}") |
| 24 |
|
| 25 |
mock.AddProperties( |
| 26 |
MAIN_IFACE, |
| 27 |
dbus.Dictionary( |
| 28 |
{ |
| 29 |
"version": dbus.UInt32(parameters.get("version", VERSION)), |
| 30 |
"SupportedOptions": dbus.Dictionary( |
| 31 |
parameters.get("SupportedOptions", {}), signature="sv" |
| 32 |
), |
| 33 |
}, |
| 34 |
), |
| 35 |
) |
| 36 |
mock.notifications = {} |
| 37 |
|
| 38 |
|
| 39 |
@dbus.service.method( |
| 40 |
MAIN_IFACE, |
| 41 |
in_signature="ssa{sv}", |
| 42 |
out_signature="", |
| 43 |
) |
| 44 |
def AddNotification(self, app_id, id, notification): |
| 45 |
logger.debug(f"AddNotification({app_id}, {id}, {notification})") |
| 46 |
|
| 47 |
self.notifications.setdefault(app_id, {})[id] = notification |
| 48 |
|
| 49 |
|
| 50 |
@dbus.service.method( |
| 51 |
MAIN_IFACE, |
| 52 |
in_signature="ss", |
| 53 |
out_signature="", |
| 54 |
) |
| 55 |
def RemoveNotification(self, app_id, id): |
| 56 |
logger.debug(f"AddNotification({app_id}, {id})") |
| 57 |
|
| 58 |
del self.notifications[app_id][id] |
| 59 |
|
| 60 |
|
| 61 |
@dbus.service.method( |
| 62 |
MOCK_IFACE, |
| 63 |
in_signature="sssav", |
| 64 |
out_signature="", |
| 65 |
) |
| 66 |
def EmitActionInvoked(self, app_id, id, action, parameter): |
| 67 |
logger.debug(f"EmitActionInvoked({app_id}, {id}, {action}, {parameter})") |
| 68 |
|
| 69 |
# n = self.notifications[app_id][id] |
| 70 |
# FIXME check action is in n |
| 71 |
|
| 72 |
self.EmitSignal( |
| 73 |
MAIN_IFACE, |
| 74 |
"ActionInvoked", |
| 75 |
"sssav", |
| 76 |
[ |
| 77 |
app_id, |
| 78 |
id, |
| 79 |
action, |
| 80 |
dbus.Array(parameter, signature="v"), |
| 81 |
], |
| 82 |
) |