From 8ab768f95fdf437dfdafee39a192d9d0180410cd Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 27 Nov 2012 14:14:07 +0530 Subject: [PATCH] Theoretical osx 10.8 notifier --- src/calibre/gui2/notify.py | 46 +++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/calibre/gui2/notify.py b/src/calibre/gui2/notify.py index 947d98f1a4..b51fb89344 100644 --- a/src/calibre/gui2/notify.py +++ b/src/calibre/gui2/notify.py @@ -7,7 +7,7 @@ __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' -from calibre.constants import islinux, isosx +from calibre.constants import islinux, isosx, get_osx_version, __appname__ class Notifier(object): @@ -101,32 +101,36 @@ class QtNotifier(Notifier): except: pass -class GrowlNotifier(Notifier): - - notification_type = 'All notifications' +class AppleNotifier(Notifier): def __init__(self): + self.ok = False + import os, sys try: - import Growl - self.icon = Growl.Image.imageFromPath(I('notify.png')) - self.growl = Growl.GrowlNotifier(applicationName='calibre', - applicationIcon=self.icon, notifications=[self.notification_type]) - self.growl.register() - self.ok = True + self.exe = os.path.join(sys.console_binaries_path, 'notifier') + self.ok = os.access(self.exe, os.X_OK) + import subprocess + self.call = subprocess.check_call except: - self.ok = False + pass - def encode(self, msg): - if isinstance(msg, unicode): - msg = msg.encode('utf-8') - return msg + def notify(self, body, summary): + def encode(x): + if isinstance(x, unicode): + x = x.encode('utf-8') + return x + + cmd = [self.exe, '-title', __appname__, '-activate', + 'net.kovidgoyal.calibre', '-message', encode(body)] + if summary: + cmd += ['-subtitle', encode(summary)] + self.call(cmd) def __call__(self, body, summary=None, replaces_id=None, timeout=0): timeout, body, summary = self.get_msg_parms(timeout, body, summary) if self.ok: try: - self.growl.notify(self.notification_type, self.encode(summary), - self.encode(body)) + self.notify(body, summary) except: import traceback traceback.print_exc() @@ -140,10 +144,10 @@ def get_notifier(systray=None): ans = FDONotifier() if not ans.ok: ans = None - #if isosx: - # ans = GrowlNotifier() - # if not ans.ok: - # ans = None + elif False and isosx and get_osx_version() >= (10, 8, 0): + ans = AppleNotifier() + if not ans.ok: + ans = None if ans is None: ans = QtNotifier(systray) if not ans.ok: