| 1 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
|
| 3 |
import logging |
| 4 |
|
| 5 |
import dbus.service |
| 6 |
from dbusmock import MOCK_IFACE |
| 7 |
|
| 8 |
|
| 9 |
BUS_NAME = "org.freedesktop.portal.Desktop" |
| 10 |
MAIN_OBJ = "/org/freedesktop/portal/desktop" |
| 11 |
MAIN_IFACE = "org.freedesktop.portal.Notification" |
| 12 |
SYSTEM_BUS = False |
| 13 |
VERSION = 1 |
| 14 |
|
| 15 |
|
| 16 |
logger = logging.getLogger("portal") |
| 17 |
logger.setLevel(logging.DEBUG) |
| 18 |
|
| 19 |
|
| 20 |
def load(mock, parameters={}): |
| 21 |
logger.debug(f"Loading parameters: {parameters}") |
| 22 |
|
| 23 |
mock.AddProperties( |
| 24 |
MAIN_IFACE, |
| 25 |
dbus.Dictionary( |
| 26 |
{ |
| 27 |
"version": dbus.UInt32(parameters.get("version", VERSION)), |
| 28 |
"SupportedOptions": dbus.Dictionary( |
| 29 |
parameters.get("SupportedOptions", {}), signature="sv" |
| 30 |
), |
| 31 |
}, |
| 32 |
), |
| 33 |
) |
| 34 |
mock.notifications = {} |
| 35 |
|
| 36 |
|
| 37 |
@dbus.service.method( |
| 38 |
MAIN_IFACE, |
| 39 |
in_signature="sa{sv}", |
| 40 |
out_signature="", |
| 41 |
) |
| 42 |
def AddNotification(self, id, notification): |
| 43 |
logger.debug(f"AddNotification({id}, {notification})") |
| 44 |
|
| 45 |
self.notifications[id] = notification |
| 46 |
|
| 47 |
|
| 48 |
@dbus.service.method( |
| 49 |
MAIN_IFACE, |
| 50 |
in_signature="s", |
| 51 |
out_signature="", |
| 52 |
) |
| 53 |
def RemoveNotification(self, id): |
| 54 |
logger.debug(f"AddNotification({id})") |
| 55 |
|
| 56 |
del self.notifications[id] |
| 57 |
|
| 58 |
|
| 59 |
@dbus.service.method( |
| 60 |
MOCK_IFACE, |
| 61 |
in_signature="ssav", |
| 62 |
out_signature="", |
| 63 |
) |
| 64 |
def EmitActionInvoked(self, id, action, parameter): |
| 65 |
logger.debug(f"EmitActionInvoked({id}, {action}, {parameter})") |
| 66 |
|
| 67 |
self.EmitSignal( |
| 68 |
MAIN_IFACE, |
| 69 |
"ActionInvoked", |
| 70 |
"ssav", |
| 71 |
[ |
| 72 |
id, |
| 73 |
action, |
| 74 |
dbus.Array(parameter, signature="v"), |
| 75 |
], |
| 76 |
) |