| |   |
| 23 | 23 | from gsentinel.plugin import PluginBase |
| 24 | 24 | from gmailatom import Message |
| 25 | 25 | import pynotify |
| 26 | import logging |
| 27 | import os |
| 26 | 28 | from gettext import gettext as _ |
| 27 | 29 | |
| 28 | 30 | class GmailNotification: |
| 29 | 31 | """ Notification pop-up. """ |
| 30 | 32 | template = "<i>%s: </i>%s\n<i>%s: </i>%s\n\n%s" |
| 31 | 33 | |
| 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 |
| 34 | 37 | self.counter = 0 |
| 35 | 38 | 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) |
| 37 | 41 | self.popup.set_timeout(timeout) |
| 38 | 42 | |
| 39 | 43 | self.popup.add_action("open", "Open", self.__open_link) |
| … | … | |
| 52 | 52 | if next >= 0 and next < len(self.data): |
| 53 | 53 | self.counter = next |
| 54 | 54 | 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) |
| 56 | 57 | self.popup.set_timeout(self.timeout) |
| 57 | 58 | self.popup.show() |
| 58 | 59 | |
| … | … | |
| 68 | 68 | def __open_link (self, notification, data): |
| 69 | 69 | """Open on the default browser the message pointed by |
| 70 | 70 | 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) |
| 72 | 74 | |
| 73 | 75 | def attach_to_status_icon (self, status_icon): |
| 74 | 76 | """ Make the popup appear from the WIDGET""" |
| … | … | |
| 91 | 91 | def initialize (self, config): |
| 92 | 92 | """ Routine for plugin initialization""" |
| 93 | 93 | self.timeout = int(config["timeout"]) * 1000 |
| 94 | | self.media_path = config["mediapath"] |
| 94 | self.icon_file = config["iconfile"] |
| 95 | self.browser = config["browser"] |
| 95 | 96 | pynotify.init(_("gmail-sentinel notification plugin")) |
| 97 | logging.info("[NotifyPlugin] Application registred for notifications") |
| 96 | 98 | |
| 97 | 99 | def destroy (self): |
| 98 | 100 | """ Routine for plugin closing clean-up""" |
| … | … | |
| 102 | 102 | |
| 103 | 103 | def new_messages (self, **kwargs): |
| 104 | 104 | """ Show notification for new messages""" |
| 105 | | notification = GmailNotification(kwargs["messages"], self.timeout) |
| 105 | notification = GmailNotification(kwargs["messages"], self.timeout, self.icon_file, self.browser) |
| 106 | 106 | notification.show() |
| 107 | logging.info("[NotifyPlugin] New message pop up shown") |
| 107 | 108 | |
| 108 | 109 | def no_new_messages (self, **kwargs): |
| 109 | 110 | """ Nothing happens without new_messages""" |
| toggle raw diff |
--- a/plugins/libnotify.py
+++ b/plugins/libnotify.py
@@ -23,17 +23,21 @@ Libnotify plugin for gmail-sentinel
from gsentinel.plugin import PluginBase
from gmailatom import Message
import pynotify
+import logging
+import os
from gettext import gettext as _
class GmailNotification:
""" Notification pop-up. """
template = "<i>%s: </i>%s\n<i>%s: </i>%s\n\n%s"
- def __init__ (self, alist, timeout):
- self.data, self.timeout, = alist, timeout
+ def __init__ (self, alist, timeout, icon_file, browser):
+ self.data, self.timeout = alist, timeout
+ self.icon_file, self.browser = icon_file, browser
self.counter = 0
self.popup = pynotify.Notification(_("You have %d new messages") % len(alist),
- self.__format_msg(self.data[0]))
+ self.__format_msg(self.data[0]),
+ self.icon_file)
self.popup.set_timeout(timeout)
self.popup.add_action("open", "Open", self.__open_link)
@@ -48,7 +52,8 @@ class GmailNotification:
if next >= 0 and next < len(self.data):
self.counter = next
self.popup.update(self.popup.get_property('summary'),
- self.__format_msg(self.data[self.counter]))
+ self.__format_msg(self.data[self.counter]),
+ self.icon_file)
self.popup.set_timeout(self.timeout)
self.popup.show()
@@ -63,7 +68,9 @@ class GmailNotification:
def __open_link (self, notification, data):
"""Open on the default browser the message pointed by
self.counter"""
- print "Open link"
+ command = "%s '%s'" % (self.browser, self.data[self.counter]['link'])
+ logging.info("[NotifyPlugin] Open link command: %s", command)
+ os.system(command)
def attach_to_status_icon (self, status_icon):
""" Make the popup appear from the WIDGET"""
@@ -84,8 +91,10 @@ class NotifyPlugin (PluginBase):
def initialize (self, config):
""" Routine for plugin initialization"""
self.timeout = int(config["timeout"]) * 1000
- self.media_path = config["mediapath"]
+ self.icon_file = config["iconfile"]
+ self.browser = config["browser"]
pynotify.init(_("gmail-sentinel notification plugin"))
+ logging.info("[NotifyPlugin] Application registred for notifications")
def destroy (self):
""" Routine for plugin closing clean-up"""
@@ -93,8 +102,9 @@ class NotifyPlugin (PluginBase):
def new_messages (self, **kwargs):
""" Show notification for new messages"""
- notification = GmailNotification(kwargs["messages"], self.timeout)
+ notification = GmailNotification(kwargs["messages"], self.timeout, self.icon_file, self.browser)
notification.show()
+ logging.info("[NotifyPlugin] New message pop up shown")
def no_new_messages (self, **kwargs):
""" Nothing happens without new_messages""" |