Coverage for /home/antoine/projects/xpra-git/dist/python3/lib64/python/xpra/notifications/notifier_base.py : 43%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# This file is part of Xpra.
2# Copyright (C) 2011-2019 Antoine Martin <antoine@xpra.org>
3# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
4# later version. See the file COPYING for details.
6import os
7import tempfile
9from xpra.os_util import osexpand
10from xpra.log import Logger
12log = Logger("notify")
15class NotifierBase:
17 def __init__(self, closed_cb=None, action_cb=None):
18 #posix only - but degrades ok on non-posix:
19 self.dbus_id = os.environ.get("DBUS_SESSION_BUS_ADDRESS", "")
20 self.temp_files = {}
21 self.closed_cb = closed_cb
22 self.action_cb = action_cb
23 self.handles_actions = False
25 def cleanup(self):
26 tf = self.temp_files
27 if tf:
28 self.temp_files = {}
29 for nid in self.temp_files:
30 self.clean_notification(nid)
32 def show_notify(self, dbus_id, tray, nid,
33 app_name, replaces_nid, app_icon,
34 summary, body, actions, hints, timeout, icon):
35 pass
37 def get_icon_string(self, nid : int, app_icon, icon):
38 if app_icon and not os.path.isabs(app_icon):
39 #safe to use
40 return app_icon
41 if icon and icon[0]==b"png":
42 icon_data = icon[3]
43 from xpra.platform.paths import get_xpra_tmp_dir
44 tmp = osexpand(get_xpra_tmp_dir())
45 d = tmp
46 missing = []
47 while d and not os.path.exists(d):
48 missing.append(d)
49 d = os.path.dirname(d)
50 for d in reversed(missing):
51 os.mkdir(d, 0o700)
52 temp = tempfile.NamedTemporaryFile(mode='w+b', suffix='.png',
53 prefix='xpra-notification-icon-', dir=tmp, delete=False)
54 temp.write(icon_data)
55 temp.close()
56 self.temp_files[nid] = temp.name
57 return temp.name
58 return ""
60 def clean_notification(self, nid : int):
61 temp_file = self.temp_files.pop(nid, None)
62 log("clean_notification(%s) temp_file=%s", nid, temp_file)
63 if temp_file:
64 try:
65 os.unlink(temp_file)
66 except Exception as e:
67 log("failed to remove temporary icon file '%s':", temp_file)
68 log(" %s", e)
70 def dbus_check(self, dbus_id):
71 if dbus_id and self.dbus_id==dbus_id:
72 log.warn("remote dbus instance is the same as our local one")
73 log.warn(" cannot forward notification to ourself as this would create a loop")
74 log.warn(" disable notifications to avoid this warning")
75 return False
76 return True