def _nec_notification(self, obj): if obj.do_popup: if obj.popup_image: icon_path = gtkgui_helpers.get_icon_path(obj.popup_image, 48) if icon_path: image_path = icon_path elif obj.popup_image_path: image_path = obj.popup_image_path else: image_path = '' popup(obj.popup_event_type, obj.jid, obj.conn.name, obj.popup_msg_type, path_to_image=image_path, title=obj.popup_title, text=obj.popup_text, timeout=obj.popup_timeout) if obj.do_sound: if obj.sound_file: helpers.play_sound_file(obj.sound_file) elif obj.sound_event: helpers.play_sound(obj.sound_event) if obj.do_command: try: helpers.exec_command(obj.command, use_shell=True) except Exception: pass
def popup(event_type, jid, account, msg_type='', path_to_image=None, title=None, text=None, timeout=-1): """ Notify a user of an event. It first tries to a valid implementation of the Desktop Notification Specification. If that fails, then we fall back to the older style PopupNotificationWindow method """ # default image if not path_to_image: path_to_image = gtkgui_helpers.get_icon_path('gajim-chat_msg_recv', 48) if timeout < 0: timeout = gajim.config.get('notification_timeout') # Try to show our popup via D-Bus and notification daemon if gajim.config.get('use_notif_daemon') and dbus_support.supported: try: DesktopNotification(event_type, jid, account, msg_type, path_to_image, title, gobject.markup_escape_text(text), timeout) return # sucessfully did D-Bus Notification procedure! except dbus.DBusException, e: # Connection to D-Bus failed gajim.log.debug(str(e)) except TypeError, e: # This means that we sent the message incorrectly gajim.log.debug(str(e))
def on_run(self): no_map = None if not self.is_active: pres_keys = sorted(self.plugin.config['presets'].keys()) for key in pres_keys: self.preset_liststore.append((key, )) for name in self.plugin.config_default_values: if name == 'presets': continue if name == 'preview_provider': self.xml.get_object(name).set_active(self.plugin.config[name]) continue widget = self.xml.get_object(name) widget.set_text(str(self.plugin.config[name])) try: import osmgpsmap if osmgpsmap.__version__ < '0.6': no_map = True log.debug('python-osmgpsmap < 0.6 detected') except: no_map = True log.debug('python-osmgpsmap not detected') log.debug('python-osmgpsmap > 0.5 detected') if not no_map and not self.is_active: from layers import DummyLayer vbox = self.xml.get_object('vbox1') vbox.set_size_request(400, -1) self.osm = osmgpsmap.GpsMap() self.osm.layer_add( osmgpsmap.GpsMapOsd(show_dpad=True, show_zoom=True)) self.osm.layer_add(DummyLayer()) lat = self.plugin.config['lat'] lon = self.plugin.config['lon'] if not self.is_valid_coord(lat, lon): self.lat = self.lon = 0.0 self.xml.get_object('lat').set_text('0.0') self.xml.get_object('lon').set_text('0.0') self.osm.set_center_and_zoom(self.lat, self.lon, 12) self.path_to_image = os.path.abspath( gtkgui_helpers.get_icon_path('gajim', 16)) self.icon = gtk.gdk.pixbuf_new_from_file_at_size( self.path_to_image, 16, 16) self.osm.connect('button_release_event', self.map_clicked) vbox.pack_start(self.osm, expand=True, fill=True, padding=6) label = gtk.Label( _('Click the right mouse button to specify the location, \n' 'middle mouse button to show / ' 'hide the contacts on the map')) vbox.pack_start(label, expand=False, fill=False, padding=6) self.is_active = True self.images = [] self.osm_image = self.osm.image_add(self.lat, self.lon, self.icon) self.xml.get_object('lat').connect('changed', self.on_lon_changed) self.xml.get_object('lon').connect('changed', self.on_lon_changed)
def on_run(self): no_map = None if not self.is_active: pres_keys = sorted(self.plugin.config['presets'].keys()) for key in pres_keys: self.preset_liststore.append((key,)) for name in self.plugin.config_default_values: if name == 'presets': continue widget = self.xml.get_object(name) widget.set_text(str(self.plugin.config[name])) try: import osmgpsmap if osmgpsmap.__version__ < '0.6': no_map = True log.debug('python-osmgpsmap < 0.6 detected') except: no_map = True log.debug('python-osmgpsmap not detected') log.debug('python-osmgpsmap > 0.5 detected') if not no_map and not self.is_active: from layers import DummyLayer vbox = self.xml.get_object('vbox1') vbox.set_size_request(400, -1) self.osm = osmgpsmap.GpsMap() self.osm.layer_add(osmgpsmap.GpsMapOsd(show_dpad=True, show_zoom=True)) self.osm.layer_add(DummyLayer()) lat = self.plugin.config['lat'] lon = self.plugin.config['lon'] if not self.is_valid_coord(lat, lon): self.lat = self.lon = 0.0 self.xml.get_object('lat').set_text('0.0') self.xml.get_object('lon').set_text('0.0') self.osm.set_center_and_zoom(self.lat, self.lon, 12) self.path_to_image = os.path.abspath(gtkgui_helpers.get_icon_path( 'gajim', 16)) self.icon = gtk.gdk.pixbuf_new_from_file_at_size( self.path_to_image, 16, 16) self.osm.connect('button_release_event', self.map_clicked) vbox.pack_start(self.osm, expand=True, fill=True, padding=6) label = gtk.Label( _('Click the right mouse button to specify the location, \n' 'middle mouse button to show / ' 'hide the contacts on the map')) vbox.pack_start(label, expand=False, fill=False, padding=6) self.is_active = True self.images = [] self.osm_image = self.osm.image_add(self.lat, self.lon, self.icon) self.xml.get_object('lat').connect('changed', self.on_lon_changed) self.xml.get_object('lon').connect('changed', self.on_lon_changed)
def popup(event_type, jid, account, msg_type='', path_to_image=None, title=None, text=None, timeout=-1): """ Notify a user of an event. It first tries to a valid implementation of the Desktop Notification Specification. If that fails, then we fall back to the older style PopupNotificationWindow method """ # default image if not path_to_image: path_to_image = gtkgui_helpers.get_icon_path('gajim-chat_msg_recv', 48) if timeout < 0: timeout = gajim.config.get('notification_timeout') # Try to show our popup via D-Bus and notification daemon if gajim.config.get('use_notif_daemon') and dbus_support.supported: try: DesktopNotification(event_type, jid, account, msg_type, path_to_image, title, GLib.markup_escape_text(text), timeout) return # sucessfully did D-Bus Notification procedure! except dbus.DBusException as e: # Connection to D-Bus failed gajim.log.debug(str(e)) except TypeError as e: # This means that we sent the message incorrectly gajim.log.debug(str(e)) # Ok, that failed. Let's try pynotify, which also uses notification daemon if gajim.config.get('use_notif_daemon') and USER_HAS_PYNOTIFY: if not text and event_type == 'new_message': # empty text for new_message means do_preview = False # -> default value for text _text = GLib.markup_escape_text(gajim.get_name_from_jid(account, jid)) else: _text = GLib.markup_escape_text(text) if not title: _title = '' else: _title = title notification = Notify.Notification(_title, _text) notification.set_timeout(timeout*1000) notification.set_category(event_type) notification.set_data('event_type', event_type) notification.set_data('jid', jid) notification.set_data('account', account) notification.set_data('msg_type', msg_type) notification.set_property('icon-name', path_to_image) if 'actions' in Notify.get_server_caps(): notification.add_action('default', 'Default Action', on_pynotify_notification_clicked) try: notification.show() return except GObject.GError as e: # Connection to notification-daemon failed, see #2893 gajim.log.debug(str(e)) # Either nothing succeeded or the user wants old-style notifications instance = PopupNotificationWindow(event_type, jid, account, msg_type, path_to_image, title, text, timeout) gajim.interface.roster.popup_notification_windows.append(instance)
def attempt_notify(self): ntype = self.ntype if self.kde_notifications: notification_text = ('<html><img src="%(image)s" align=left />' \ '%(title)s<br/>%(text)s</html>') % {'title': self.title, 'text': self.text, 'image': self.path_to_image} gajim_icon = gtkgui_helpers.get_icon_path('gajim', 48) try: self.notif.Notify( dbus.String(_('Gajim')), # app_name (string) dbus.UInt32(0), # replaces_id (uint) ntype, # event_id (string) dbus.String(gajim_icon), # app_icon (string) dbus.String(''), # summary (string) dbus.String(notification_text), # body (string) # actions (stringlist) (dbus.String('default'), dbus.String(self.event_type), dbus.String('ignore'), dbus.String(_('Ignore'))), [], # hints (not used in KDE yet) dbus.UInt32(self.timeout*1000), # timeout (int), in ms reply_handler=self.attach_by_id, error_handler=self.notify_another_way) return except Exception: pass version = self.version if version[:2] == [0, 2]: actions = {} if 'actions' in self.capabilities: actions = {'default': 0} try: self.notif.Notify( dbus.String(_('Gajim')), dbus.String(self.path_to_image), dbus.UInt32(0), ntype, dbus.Byte(0), dbus.String(self.title), dbus.String(self.text), [dbus.String(self.path_to_image)], actions, [''], True, dbus.UInt32(self.timeout), reply_handler=self.attach_by_id, error_handler=self.notify_another_way) except AttributeError: # we're actually dealing with the newer version version = [0, 3, 1] if version > [0, 3]: if gajim.interface.systray_enabled and \ gajim.config.get('attach_notifications_to_systray'): status_icon = gajim.interface.systray.status_icon rect = status_icon.get_geometry()[2] x, y, width, height = rect.x, rect.y, rect.width, rect.height pos_x = x + (width / 2) pos_y = y + (height / 2) hints = {'x': pos_x, 'y': pos_y} else: hints = {} if version >= [0, 3, 2]: hints['urgency'] = dbus.Byte(0) # Low Urgency hints['category'] = dbus.String(ntype) # it seems notification-daemon doesn't like empty text if self.text: text = self.text if len(self.text) > 200: text = '%s\n...' % self.text[:200] else: text = ' ' if os.environ.get('KDE_FULL_SESSION') == 'true': text = '<table style=\'padding: 3px\'><tr><td>' \ '<img src=\"%s\"></td><td width=20> </td>' \ '<td>%s</td></tr></table>' % (self.path_to_image, text) self.path_to_image = os.path.abspath( gtkgui_helpers.get_icon_path('gajim', 48)) actions = () if 'actions' in self.capabilities: actions = (dbus.String('default'), dbus.String( self.event_type)) try: self.notif.Notify( dbus.String(_('Gajim')), # this notification does not replace other dbus.UInt32(0), dbus.String(self.path_to_image), dbus.String(self.title), dbus.String(text), actions, hints, dbus.UInt32(self.timeout*1000), reply_handler=self.attach_by_id, error_handler=self.notify_another_way) except Exception as e: self.notify_another_way(e) else: try: self.notif.Notify( dbus.String(_('Gajim')), dbus.String(self.path_to_image), dbus.UInt32(0), dbus.String(self.title), dbus.String(self.text), dbus.String(''), hints, dbus.UInt32(self.timeout*1000), reply_handler=self.attach_by_id, error_handler=self.notify_another_way) except Exception as e: self.notify_another_way(e)
def __init__(self, event_type, jid, account, msg_type='', path_to_image=None, title=None, text=None, timeout=-1): self.path_to_image = os.path.abspath(path_to_image) self.event_type = event_type self.title = title self.text = text self.timeout = timeout # 0.3.1 is the only version of notification daemon that has no way # to determine which version it is. If no method exists, it means # they're using that one. self.default_version = [0, 3, 1] self.account = account self.jid = jid self.msg_type = msg_type # default value of text if not text and event_type == 'new_message': # empty text for new_message means do_preview = False self.text = gajim.get_name_from_jid(account, jid) if not title: self.title = event_type # default value if event_type == _('Contact Signed In'): ntype = 'presence.online' elif event_type == _('Contact Signed Out'): ntype = 'presence.offline' elif event_type in (_('New Message'), _('New Single Message'), _('New Private Message')): ntype = 'im.received' elif event_type == _('File Transfer Request'): ntype = 'transfer' elif event_type == _('File Transfer Error'): ntype = 'transfer.error' elif event_type in (_('File Transfer Completed'), _('File Transfer Stopped')): ntype = 'transfer.complete' elif event_type == _('New E-mail'): ntype = 'email.arrived' elif event_type == _('Groupchat Invitation'): ntype = 'im.invitation' elif event_type == _('Contact Changed Status'): ntype = 'presence.status' elif event_type == _('Connection Failed'): ntype = 'connection.failed' elif event_type == _('Subscription request'): ntype = 'subscription.request' elif event_type == _('Unsubscribed'): ntype = 'unsubscribed' else: # default failsafe values self.path_to_image = gtkgui_helpers.get_icon_path( 'gajim-chat_msg_recv', 48) ntype = 'im' # Notification Type self.notif = dbus_support.get_notifications_interface(self) if self.notif is None: raise dbus.DBusException('unable to get notifications interface') self.ntype = ntype if self.kde_notifications: self.attempt_notify() else: self.capabilities = self.notif.GetCapabilities() if self.capabilities is None: self.capabilities = ['actions'] self.get_version()
def popup(event_type, jid, account, msg_type='', path_to_image=None, title=None, text=None, timeout=-1): """ Notify a user of an event. It first tries to a valid implementation of the Desktop Notification Specification. If that fails, then we fall back to the older style PopupNotificationWindow method """ # default image if not path_to_image: path_to_image = gtkgui_helpers.get_icon_path('gajim-chat_msg_recv', 48) if timeout < 0: timeout = gajim.config.get('notification_timeout') # Try to show our popup via D-Bus and notification daemon if gajim.config.get('use_notif_daemon') and dbus_support.supported: try: DesktopNotification(event_type, jid, account, msg_type, path_to_image, title, GLib.markup_escape_text(text), timeout) return # sucessfully did D-Bus Notification procedure! except dbus.DBusException as e: # Connection to D-Bus failed gajim.log.debug(str(e)) except TypeError as e: # This means that we sent the message incorrectly gajim.log.debug(str(e)) # Ok, that failed. Let's try pynotify, which also uses notification daemon if gajim.config.get('use_notif_daemon') and USER_HAS_PYNOTIFY: if not text and event_type == 'new_message': # empty text for new_message means do_preview = False # -> default value for text _text = GLib.markup_escape_text( gajim.get_name_from_jid(account, jid)) else: _text = GLib.markup_escape_text(text) if not title: _title = '' else: _title = title notification = Notify.Notification.new(_title, _text) notification.set_timeout(timeout * 1000) notification.set_category(event_type) notification._data = {} notification._data["event_type"] = event_type notification._data["jid"] = jid notification._data["account"] = account notification._data["msg_type"] = msg_type notification.set_property('icon-name', path_to_image) if 'actions' in Notify.get_server_caps(): notification.add_action('default', 'Default Action', on_pynotify_notification_clicked) try: notification.show() return except GObject.GError as e: # Connection to notification-daemon failed, see #2893 gajim.log.debug(str(e)) # Either nothing succeeded or the user wants old-style notifications instance = PopupNotificationWindow(event_type, jid, account, msg_type, path_to_image, title, text, timeout) gajim.interface.roster.popup_notification_windows.append(instance)
def attempt_notify(self): ntype = self.ntype if self.kde_notifications: notification_text = ('<html><img src="%(image)s" align=left />' \ '%(title)s<br/>%(text)s</html>') % {'title': self.title, 'text': self.text, 'image': self.path_to_image} gajim_icon = gtkgui_helpers.get_icon_path('gajim', 48) try: self.notif.Notify( dbus.String(_('Gajim')), # app_name (string) dbus.UInt32(0), # replaces_id (uint) ntype, # event_id (string) dbus.String(gajim_icon), # app_icon (string) dbus.String(''), # summary (string) dbus.String(notification_text), # body (string) # actions (stringlist) (dbus.String('default'), dbus.String(self.event_type), dbus.String('ignore'), dbus.String(_('Ignore'))), [], # hints (not used in KDE yet) dbus.UInt32(self.timeout * 1000), # timeout (int), in ms reply_handler=self.attach_by_id, error_handler=self.notify_another_way) return except Exception: pass version = self.version if version[:2] == [0, 2]: actions = {} if 'actions' in self.capabilities and self.msg_type: actions = {'default': 0} try: self.notif.Notify(dbus.String(_('Gajim')), dbus.String(self.path_to_image), dbus.UInt32(0), ntype, dbus.Byte(0), dbus.String(self.title), dbus.String(self.text), [dbus.String(self.path_to_image)], actions, [''], True, dbus.UInt32(self.timeout), reply_handler=self.attach_by_id, error_handler=self.notify_another_way) except AttributeError: # we're actually dealing with the newer version version = [0, 3, 1] if version > [0, 3]: if gajim.interface.systray_enabled and \ gajim.config.get('attach_notifications_to_systray'): status_icon = gajim.interface.systray.status_icon rect = status_icon.get_geometry()[2] x, y, width, height = rect.x, rect.y, rect.width, rect.height pos_x = x + (width / 2) pos_y = y + (height / 2) hints = {'x': pos_x, 'y': pos_y} else: hints = {} if version >= [0, 3, 2]: hints['urgency'] = dbus.Byte(0) # Low Urgency hints['category'] = dbus.String(ntype) # it seems notification-daemon doesn't like empty text if self.text: text = self.text if len(self.text) > 200: text = '%s\n…' % self.text[:200] else: text = ' ' if os.environ.get('KDE_FULL_SESSION') == 'true': text = '<table style=\'padding: 3px\'><tr><td>' \ '<img src=\"%s\"></td><td width=20> </td>' \ '<td>%s</td></tr></table>' % (self.path_to_image, text) self.path_to_image = os.path.abspath( gtkgui_helpers.get_icon_path('gajim', 48)) actions = () if 'actions' in self.capabilities and self.msg_type: actions = (dbus.String('default'), dbus.String(self.event_type)) try: self.notif.Notify( dbus.String(_('Gajim')), # this notification does not replace other dbus.UInt32(0), dbus.String(self.path_to_image), dbus.String(self.title), dbus.String(text), actions, hints, dbus.UInt32(self.timeout * 1000), reply_handler=self.attach_by_id, error_handler=self.notify_another_way) except Exception as e: self.notify_another_way(e) else: try: self.notif.Notify(dbus.String(_('Gajim')), dbus.String(self.path_to_image), dbus.UInt32(0), dbus.String(self.title), dbus.String(self.text), dbus.String(''), hints, dbus.UInt32(self.timeout * 1000), reply_handler=self.attach_by_id, error_handler=self.notify_another_way) except Exception as e: self.notify_another_way(e)