Commit 19414390eb2a0ac6dee8661894804134c07bb244

libnotify plugin funcitonal

Commit diff

plugins/libnotify.py

 
2323from gsentinel.plugin import PluginBase
2424from gmailatom import Message
2525import pynotify
26import logging
27import os
2628from gettext import gettext as _
2729
2830class GmailNotification:
2931 """ Notification pop-up. """
3032 template = "<i>%s: </i>%s\n<i>%s: </i>%s\n\n%s"
3133
32 def __init__ (self, alist, timeout):
33 self.data, self.timeout, = alist, timeout
34 def __init__ (self, alist, timeout, icon_file, browser):
35 self.data, self.timeout = alist, timeout
36 self.icon_file, self.browser = icon_file, browser
3437 self.counter = 0
3538 self.popup = pynotify.Notification(_("You have %d new messages") % len(alist),
36 self.__format_msg(self.data[0]))
39 self.__format_msg(self.data[0]),
40 self.icon_file)
3741 self.popup.set_timeout(timeout)
3842
3943 self.popup.add_action("open", "Open", self.__open_link)
5252 if next >= 0 and next < len(self.data):
5353 self.counter = next
5454 self.popup.update(self.popup.get_property('summary'),
55 self.__format_msg(self.data[self.counter]))
55 self.__format_msg(self.data[self.counter]),
56 self.icon_file)
5657 self.popup.set_timeout(self.timeout)
5758 self.popup.show()
5859
6868 def __open_link (self, notification, data):
6969 """Open on the default browser the message pointed by
7070 self.counter"""
71 print "Open link"
71 command = "%s '%s'" % (self.browser, self.data[self.counter]['link'])
72 logging.info("[NotifyPlugin] Open link command: %s", command)
73 os.system(command)
7274
7375 def attach_to_status_icon (self, status_icon):
7476 """ Make the popup appear from the WIDGET"""
9191 def initialize (self, config):
9292 """ Routine for plugin initialization"""
9393 self.timeout = int(config["timeout"]) * 1000
94 self.media_path = config["mediapath"]
94 self.icon_file = config["iconfile"]
95 self.browser = config["browser"]
9596 pynotify.init(_("gmail-sentinel notification plugin"))
97 logging.info("[NotifyPlugin] Application registred for notifications")
9698
9799 def destroy (self):
98100 """ Routine for plugin closing clean-up"""
102102
103103 def new_messages (self, **kwargs):
104104 """ Show notification for new messages"""
105 notification = GmailNotification(kwargs["messages"], self.timeout)
105 notification = GmailNotification(kwargs["messages"], self.timeout, self.icon_file, self.browser)
106106 notification.show()
107 logging.info("[NotifyPlugin] New message pop up shown")
107108
108109 def no_new_messages (self, **kwargs):
109110 """ Nothing happens without new_messages"""
toggle raw diff