~jconti/recent-notifications/trunk

« back to all changes in this revision

Viewing changes to recent_notifications/Notification.py

  • Committer: Jason Conti
  • Date: 2011-02-12 23:44:24 UTC
  • Revision ID: jason.conti@gmail.com-20110212234424-frw0kjj1klqx2ncy
Adding an option to blacklist notifications based on app_name. Applications to be blacklisted should be listed in the file ~/.config/recent-notifications/blacklist, one app_name per line. The app_names are case-sensitive and are listed in the notifications as "from app_name" such as "from Gwibber" or "from Pidgin". They can also be found in ~/.cache/recent-notifications.log on the app_name lines. Thanks to Dinero Francis for reporting the issue.

Show diffs side-by-side

added added

removed removed

Lines of Context:
184
184
  def __init__(self):
185
185
    gobject.GObject.__init__(self)
186
186
 
 
187
    self._blacklist = set()
187
188
    self._match_string = "type='method_call',interface='org.freedesktop.Notifications',member='Notify'"
188
189
 
189
190
    DBusGMainLoop(set_as_default=True)
192
193
    self._bus.add_message_filter(self._message_filter)
193
194
 
194
195
  def close(self):
 
196
    """Closes the connection to the session bus."""
195
197
    self._bus.close()
196
198
 
 
199
  def set_blacklist(self, blacklist):
 
200
    """Defines the set of app_names of messages to be discarded."""
 
201
    self._blacklist = set(blacklist)
 
202
 
197
203
  def _message_filter(self, connection, dbus_message):
 
204
    """Triggers when messages are received from the session bus."""
198
205
    if dbus_message.get_member() == "Notify" and dbus_message.get_interface() == "org.freedesktop.Notifications":
199
206
      try:
200
207
        message = Message(dbus_message, Timestamp.now())
201
208
      except:
202
209
        logger.exception("Failed to parse dbus message: " + repr(dbus_message.get_args_list()))
203
210
      else:
 
211
        # Discard unwanted messages
 
212
        if message.is_volume_notification() or message.app_name in self._blacklist:
 
213
          return
204
214
        glib.idle_add(self.emit, "message-received", message)
205
215
 
206
216
if gtk.pygtk_version < (2, 8, 0):