def _dbus_notify(self, header, msg, level='info'): item = "org.freedesktop.Notifications" path = "/org/freedesktop/Notifications" interface = "org.freedesktop.Notifications" app_name = "vorta" v = QtCore.QVariant(12321) # random int to identify all notifications if v.convert(QtCore.QVariant.UInt): id_replace = v icon = "" title = header text = msg actions_list = QtDBus.QDBusArgument([], QtCore.QMetaType.QStringList) hint = {'urgency': self.URGENCY[level]} time = 5000 # milliseconds for display timeout bus = QtDBus.QDBusConnection.sessionBus() notify = QtDBus.QDBusInterface(item, path, interface, bus) if notify.isValid(): x = notify.call(QtDBus.QDBus.AutoDetect, "Notify", app_name, id_replace, icon, title, text, actions_list, hint, time) if x.errorName(): logger.warning("Failed to send notification!") logger.warning(x.errorMessage()) else: logger.warning("Invalid dbus interface")
def alert(i, group_id, id, notify) : print("######### Match found at {0}th post! Link: {1} ###########".format(i, text)) if not notify : return item = "org.freedesktop.Notifications" path = "/org/freedesktop/Notifications" interface = "org.freedesktop.Notifications" app_name = "Marketplace Notification" v = QtCore.QVariant(91424) if v.convert(QtCore.QVariant.UInt): id_replace = v icon = "" title = "Match found in marketplace!" text = "https://www.facebook.com/groups/{0}/permalink/{1}".format(group_id, id) actions_list = QtDBus.QDBusArgument([], QtCore.QMetaType.QStringList) hint = {} time = 7000 # milliseconds for display timeout bus = QtDBus.QDBusConnection.sessionBus() if not bus.isConnected(): print("Not connected to dbus!") notify = QtDBus.QDBusInterface(item, path, interface, bus) if notify.isValid(): x = notify.call(QtDBus.QDBus.AutoDetect, "Notify", app_name, id_replace, icon, title, text, actions_list, hint, time) if x.errorName(): print("Failed to send notification!") print(x.errorMessage()) else: print("Invalid dbus interface")
def send_notification(): global app_name global notification_id global saved_due_card_count due_card_count = len(mw.col.find_cards("is:new or is:due")) to_notify = due_card_count > saved_due_card_count saved_due_card_count = due_card_count if not to_notify: return short_app_name = "Anki" qt_notification_id = QtCore.QVariant(notification_id) qt_notification_id.convert(QtCore.QVariant.UInt) icon = app_name title = "Anki" text = str(due_card_count) + (" card" if due_card_count == 1 else " cards") + " to study" actions_list = QtDBus.QDBusArgument([], QtCore.QMetaType.QStringList) hint = {} time = -1 item = "org.freedesktop.Notifications" path = "/org/freedesktop/Notifications" interface = "org.freedesktop.Notifications" bus = QtDBus.QDBusConnection.sessionBus() if not bus.isConnected(): print("Not connected to dbus!") notify = QtDBus.QDBusInterface(item, path, interface, bus) if notify.isValid(): msg = notify.call(QtDBus.QDBus.AutoDetect, "Notify", short_app_name, qt_notification_id, icon, title, text, actions_list, hint, time) if msg.errorName(): print("Failed to send notification!") print(msg.errorMessage()) notification_id = msg.arguments()[0] else: print("Invalid dbus interface!")
def _notify(self, header, msg): if self._is_windows(): return False item = "org.freedesktop.Notifications" path = "/org/freedesktop/Notifications" interface = "org.freedesktop.Notifications" app_name = "pomito" v = QtCore.QVariant(100021) # random int to identify all notifications if v.convert(QtCore.QVariant.UInt): id_replace = v icon = "" title = header text = msg actions_list = QtDBus.QDBusArgument([], QtCore.QMetaType.QStringList) hint = {} time = 100 # milliseconds for display timeout bus = QtDBus.QDBusConnection.sessionBus() if not bus.isConnected(): logger.debug("Not connected to dbus!") return False notify = QtDBus.QDBusInterface(item, path, interface, bus) if notify.isValid(): x = notify.call(QtDBus.QDBus.AutoDetect, "Notify", app_name, id_replace, icon, title, text, actions_list, hint, time) if x.errorName(): logger.debug("Failed to send notification!") logger.debug(x.errorMessage()) return False else: logger.debug("Invalid dbus interface") return False return True