def test_parse_image_path(self): from xpra.platform.paths import get_icon_filename filename = get_icon_filename("xpra") assert common.parse_image_path(filename) is not None f = tempfile.NamedTemporaryFile(prefix="test-invalid-file", delete=False) try: f.file.write(b"0000000000000001111111111111111111111") f.file.flush() f.close() for x in ("", None, "/invalid-path", f.name): with silence_error(common): assert common.parse_image_path(x) is None finally: os.unlink(f.name)
def parse_hints(self, dbus_hints): hints = {} h = dbus_to_native(dbus_hints) for x in ("image-data", "icon_data"): try: data = h.pop(x) except KeyError: pass else: v = parse_image_data(data) if v: hints["image-data"] = v break if "image-data" not in hints: try: image_path = h.pop("image-path") except KeyError: pass else: v = parse_image_path(image_path) if v: hints["image-data"] = v for x in ("action-icons", "category", "desktop-entry", "resident", "transient", "x", "y", "urgency"): v = h.get(x) if v is not None: hints[x] = v log("parse_hints(%s)=%s", dbus_hints, hints) return hints
def may_notify(self, nid, summary, body, actions=[], hints={}, expire_timeout=10 * 1000, icon_name=None): log("may_notify%s client_supports_notifications=%s, notifier=%s", (nid, summary, body, actions, hints, expire_timeout, icon_name), self.client_supports_notifications, self.notifier) n = self.notifier if not self.client_supports_notifications or not n: return try: from xpra.notifications.common import parse_image_path icon_filename = get_icon_filename(icon_name) icon = parse_image_path(icon_filename) n.show_notify("", self.tray, nid, "Xpra", nid, "", summary, body, actions, hints, expire_timeout, icon) except Exception as e: log("failed to show notification", exc_info=True) log.error("Error: cannot show notification") log.error(" '%s'", summary) log.error(" %s", e)
def do_notify(self, nid, summary, body, actions=(), hints=None, expire_timeout=10 * 1000, icon_name=None): log("do_notify%s client_supports_notifications=%s, notifier=%s", (nid, summary, body, actions, hints, expire_timeout, icon_name), self.client_supports_notifications, self.notifier) n = self.notifier if not self.client_supports_notifications or not n: #just log it instead: log.info("%s", summary) if body: for x in body.splitlines(): log.info(" %s", x) return try: from xpra.notifications.common import parse_image_path icon_filename = get_icon_filename(icon_name) icon = parse_image_path(icon_filename) n.show_notify("", self.tray, nid, "Xpra", nid, "", summary, body, actions, hints or {}, expire_timeout, icon) except Exception as e: log("failed to show notification", exc_info=True) log.error("Error: cannot show notification") log.error(" '%s'", summary) log.error(" %s", e)
def may_notify(self, nid, summary, body, actions=[], hints={}, expire_timeout=10*1000, icon_name=None, user_callback=None): try: from xpra.platform.paths import get_icon_filename from xpra.notifications.common import parse_image_path except ImportError as e: notifylog("not sending notification: %s", e) else: icon_filename = get_icon_filename(icon_name) icon = parse_image_path(icon_filename) self.notify("", nid, "Xpra", 0, "", summary, body, actions, hints, expire_timeout, icon, user_callback)
def notify_new_user(self, ss): #tell other users: notifylog("notify_new_user(%s) sources=%s", ss, self._server_sources) if not self._server_sources: return nid = XPRA_NEW_USER_NOTIFICATION_ID icon = parse_image_path(get_icon_filename("user")) title = "User '%s' connected to the session" % (ss.name or ss.username or ss.uuid) body = "\n".join(ss.get_connect_info()) for s in self._server_sources.values(): s.notify("", nid, "Xpra", 0, "", title, body, [], {}, 10*1000, icon)
def show_notification(): try: from xpra.notifications.common import parse_image_path icon_filename = get_icon_filename(icon_name) icon = parse_image_path(icon_filename) n.show_notify("", self.tray, nid, "Xpra", nid, "", summary, body, actions, hints or {}, expire_timeout, icon) except Exception as e: log("failed to show notification", exc_info=True) log.error("Error: cannot show notification") log.error(" '%s'", summary) log.error(" %s", e)
def do_notify_startup(self, title, body="", replaces_nid=0): #overriden here so we can show the notification #directly on the screen we shadow notifylog("do_notify_startup%s", (title, body, replaces_nid)) if self.notifier: tray = self.get_notification_tray() #pylint: disable=assignment-from-none nid = XPRA_STARTUP_NOTIFICATION_ID actions = [] hints = {} icon = None icon_filename = os.path.join(get_icon_dir(), "server-connected.png") if os.path.exists(icon_filename): icon = parse_image_path(icon_filename) self.notifier.show_notify("", tray, nid, "Xpra", replaces_nid, "", title, body, actions, hints, 10 * 1000, icon)
def notify_new_user(self, ss): #overriden here so we can show the notification #directly on the screen we shadow notifylog("notify_new_user(%s) notifier=%s", ss, self.notifier) if self.notifier: tray = self.get_notification_tray() #pylint: disable=assignment-from-none nid = XPRA_NEW_USER_NOTIFICATION_ID title = "User '%s' connected to the session" % ( ss.name or ss.username or ss.uuid) body = "\n".join(ss.get_connect_info()) actions = [] hints = {} icon = None icon_filename = os.path.join(get_icon_dir(), "user.png") if os.path.exists(icon_filename): icon = parse_image_path(icon_filename) self.notifier.show_notify("", tray, nid, "Xpra", 0, "", title, body, actions, hints, 10 * 1000, icon)
def notify_new_user(self, ss): #tell other users: log("notify_new_user(%s) sources=%s", ss, self._server_sources) if not self._server_sources: return try: from xpra.util import XPRA_NEW_USER_NOTIFICATION_ID nid = XPRA_NEW_USER_NOTIFICATION_ID from xpra.notifications.common import parse_image_path from xpra.platform.paths import get_icon_filename icon = parse_image_path(get_icon_filename("user")) title = "User '%s' connected to the session" % (ss.name or ss.username or ss.uuid) body = "\n".join(ss.get_connect_info()) for s in self._server_sources.values(): if s!=ss: s.notify("", nid, "Xpra", 0, "", title, body, [], {}, 10*1000, icon) except Exception as e: log("%s(%s)", self.notify_new_user, ss, exc_info=True) log.error("Error: failed to show notification of user login:"******" %s", e)
def may_notify( self, nid=0, summary="", body="", #pylint: disable=arguments-differ actions=(), hints=None, expire_timeout=10 * 1000, icon_name=None, user_callback=None): try: from xpra.platform.paths import get_icon_filename from xpra.notifications.common import parse_image_path except ImportError as e: log("not sending notification: %s", e) else: icon_filename = get_icon_filename(icon_name) icon = parse_image_path(icon_filename) or "" self.notify("", nid, "Xpra", 0, "", summary, body, actions, hints or {}, expire_timeout, icon, user_callback)