def popup(event_type, jid, account, type_='', path_to_image=None, title=None, text=None, timeout=-1): """ Notify a user of an event using GNotification and GApplication under linux, the older style PopupNotificationWindow method under windows """ # default image if not path_to_image: path_to_image = gtkgui_helpers.get_icon_path('gajim-chat_msg_recv', 48) if timeout < 0: timeout = app.config.get('notification_timeout') if sys.platform == 'win32': instance = PopupNotificationWindow(event_type, jid, account, type_, path_to_image, title, text, timeout) app.interface.roster.popup_notification_windows.append(instance) return # use GNotification # TODO: Move to standard GTK+ icons here. icon = Gio.FileIcon.new(Gio.File.new_for_path(path_to_image)) notification = Gio.Notification() if title is not None: notification.set_title(title) if text is not None: notification.set_body(text) notification.set_icon(icon) notif_id = None if event_type in (_('Contact Signed In'), _('Contact Signed Out'), _('New Message'), _('New Single Message'), _('New Private Message'), _('Contact Changed Status'), _('File Transfer Request'), _('File Transfer Error'), _('File Transfer Completed'), _('File Transfer Stopped'), _('Groupchat Invitation'), _('Connection Failed'), _('Subscription request'), _('Unsubscribed')): # Create Variant Dict dict_ = { 'account': GLib.Variant('s', account), 'jid': GLib.Variant('s', jid), 'type_': GLib.Variant('s', type_) } variant_dict = GLib.Variant('a{sv}', dict_) action = 'app.{}-open-event'.format(account) #Button in notification notification.add_button_with_target(_('Open'), action, variant_dict) notification.set_default_action_and_target(action, variant_dict) if event_type in (_('New Message'), _('New Single Message'), _('New Private Message')): # Only one notification per JID notif_id = jid notification.set_priority(Gio.NotificationPriority.NORMAL) notification.set_urgent(False) app.app.send_notification(notif_id, notification)
async def on_message(self, event): sender = await event.get_sender() notify = True if self.is_active(): notify = False await self.load_dialogs_list() if event.chat_id == self.selected_dialog: await self.add_message(event) if notify: print('New Message!') notification = Gio.Notification(utils.get_display_name(sender)) notification.set_body(event.text) notification.set_default_action('app.show') self.app.send_notification('message', notification)
def _update_notification(self, state): self._hide_notification() if state not in ('error', 'success') or self.is_active(): return notification = Gio.Notification() uuid_variant = GLib.Variant('s', self.uuid) if state == 'error': notification.set_title(N_('Download failed')) notification.set_default_action_and_target( 'app.notification-error', uuid_variant) elif state == 'success': notification.set_title(N_('Download finished')) notification.set_default_action_and_target( 'app.notification-success', uuid_variant) notification.add_button_with_target( N_('Open Download Location'), 'app.notification-open-download-dir', uuid_variant) else: assert False, 'unreachable' self.get_application().send_notification(self.uuid, notification)
def _update_notification(self, state): self._hide_notification() if state not in ('error', 'success') or self.is_active(): return notification = Gio.Notification() if state == 'error': notification.set_title(N_('Download failed')) action_name_with_uuid = 'app.notification-error--%s' % self.uuid notification.set_default_action(action_name_with_uuid) elif state == 'success': notification.set_title(N_('Download finished')) action_name_with_uuid = 'app.notification-success--%s' % self.uuid notification.set_default_action(action_name_with_uuid) button_action_name_with_uuid = ( 'app.notification-open-download-dir--%s' % self.uuid) notification.add_button(N_('Open Download Location'), button_action_name_with_uuid) else: assert False, 'unreachable' self.get_application().send_notification(self.uuid, notification)
def popup(self, event_type, jid, account, type_='', icon_name=None, title=None, text=None, timeout=-1, room_jid=None): """ Notify a user of an event using GNotification and GApplication under Linux, Use PopupNotificationWindow under Windows """ if icon_name is None: icon_name = 'mail-message-new' if timeout < 0: timeout = app.config.get('notification_timeout') if sys.platform == 'win32': self._withdraw() self._win32_active_popup = PopupNotification( event_type, jid, account, type_, icon_name, title, text, timeout) self._win32_active_popup.connect('destroy', self._on_popup_destroy) return if not self._dbus_available: return icon = Gio.ThemedIcon.new(icon_name) notification = Gio.Notification() if title is not None: notification.set_title(title) if text is not None: notification.set_body(text) notif_id = None if event_type in (_('Contact Signed In'), _('Contact Signed Out'), _('New Message'), _('New Single Message'), _('New Private Message'), _('New Group Chat Message'), _('Contact Changed Status'), _('File Transfer Request'), _('File Transfer Error'), _('File Transfer Completed'), _('File Transfer Stopped'), _('Group Chat Invitation'), _('Connection Failed'), _('Subscription request'), _('Unsubscribed')): if 'actions' in self._daemon_capabilities: # Create Variant Dict dict_ = { 'account': GLib.Variant('s', account), 'jid': GLib.Variant('s', jid), 'type_': GLib.Variant('s', type_) } variant_dict = GLib.Variant('a{sv}', dict_) action = 'app.{}-open-event'.format(account) #Button in notification notification.add_button_with_target(_('Open'), action, variant_dict) notification.set_default_action_and_target( action, variant_dict) # Only one notification per JID if event_type in (_('Contact Signed In'), _('Contact Signed Out'), _('Contact Changed Status')): notif_id = self._make_id('contact-status-changed', account, jid) elif event_type == _('Group Chat Invitation'): notif_id = self._make_id('gc-invitation', account, room_jid) elif event_type == _('Connection Failed'): notif_id = self._make_id('connection-failed', account) elif event_type in (_('New Message'), _('New Single Message'), _('New Private Message'), _('New Group Chat Message')): if app.desktop_env == 'gnome': icon = self._get_avatar_for_notification(account, jid) notif_id = self._make_id('new-message', account, jid) notification.set_icon(icon) notification.set_priority(Gio.NotificationPriority.NORMAL) app.app.send_notification(notif_id, notification)
def popup(self, event_type, jid, account, type_='', icon_name=None, title=None, text=None, timeout=-1): """ Notify a user of an event using GNotification and GApplication under Linux, Use PopupNotificationWindow under Windows """ if icon_name is None: icon_name = 'gajim-chat_msg_recv' if timeout < 0: timeout = app.config.get('notification_timeout') if sys.platform == 'win32': instance = PopupNotificationWindow(event_type, jid, account, type_, icon_name, title, text, timeout) app.interface.roster.popup_notification_windows.append(instance) return scale = gtkgui_helpers.get_monitor_scale_factor() icon_pixbuf = gtkgui_helpers.gtk_icon_theme.load_icon_for_scale( icon_name, 48, scale, 0) notification = Gio.Notification() if title is not None: notification.set_title(title) if text is not None: notification.set_body(text) notification.set_icon(icon_pixbuf) notif_id = None if event_type in (_('Contact Signed In'), _('Contact Signed Out'), _('New Message'), _('New Single Message'), _('New Private Message'), _('Contact Changed Status'), _('File Transfer Request'), _('File Transfer Error'), _('File Transfer Completed'), _('File Transfer Stopped'), _('Groupchat Invitation'), _('Connection Failed'), _('Subscription request'), _('Unsubscribed')): if 'actions' in self.daemon_capabilities: # Create Variant Dict dict_ = { 'account': GLib.Variant('s', account), 'jid': GLib.Variant('s', jid), 'type_': GLib.Variant('s', type_) } variant_dict = GLib.Variant('a{sv}', dict_) action = 'app.{}-open-event'.format(account) #Button in notification notification.add_button_with_target(_('Open'), action, variant_dict) notification.set_default_action_and_target( action, variant_dict) # Only one notification per JID if event_type in (_('Contact Signed In'), _('Contact Signed Out'), _('Contact Changed Status')): notif_id = self._id('contact-status-changed', account, jid) elif event_type == _('Groupchat Invitation'): notif_id = self._id('gc-invitation', account, jid) elif event_type == _('Connection Failed'): notif_id = self._id('connection-failed', account) elif event_type in (_('New Message'), _('New Single Message'), _('New Private Message')): notif_id = self._id('new-message', account, jid) notification.set_priority(Gio.NotificationPriority.NORMAL) app.app.send_notification(notif_id, notification)