From 164114ab821242bf25faa3573a94dea0641edbbf Mon Sep 17 00:00:00 2001 From: Safihre Date: Mon, 14 Dec 2015 14:58:01 +0100 Subject: [PATCH] Enable Windows Notifications --- .../Config/templates/config_notify.tmpl | 329 +++++++++++------- .../Config/templates/staticcfg/css/style.css | 4 +- sabnzbd/api.py | 6 + sabnzbd/cfg.py | 13 + sabnzbd/growler.py | 10 +- sabnzbd/interface.py | 10 + sabnzbd/skintext.py | 2 + sabnzbd/utils/systrayiconthread.py | 14 + 8 files changed, 263 insertions(+), 125 deletions(-) diff --git a/interfaces/Config/templates/config_notify.tmpl b/interfaces/Config/templates/config_notify.tmpl index 667b8d629..60cf0db29 100644 --- a/interfaces/Config/templates/config_notify.tmpl +++ b/interfaces/Config/templates/config_notify.tmpl @@ -69,7 +69,189 @@ -
+ +
+
+

$T('section-NC')

+
+
+
+
+ + 0 then 'checked="checked"' else ""#--> /> + $T('explain-ncenter_enable') +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + +   +
+
+
+
+ + +
+
+

$T('section-AC')

+
+
+
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + +   +
+
+
+
+ + +
+
+

$T('section-OSD')

+
+
+
+
+ + 0 then 'checked="checked"' else ""#--> /> + $T('explain-ntfosd_enable') +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + 0 then 'checked="checked"' else ""#--> /> +
+
+ + +   +
+
+
+
+ +

$T('growlSettings')

@@ -138,128 +320,6 @@
- -
-
-

$T('section-NC')

-
-
-
-
- - 0 then 'checked="checked"' else ""#--> /> - $T('explain-ncenter_enable') -
-
- - 0 then 'checked="checked"' else ""#--> /> -
-
- - 0 then 'checked="checked"' else ""#--> /> -
-
- - 0 then 'checked="checked"' else ""#--> /> -
-
- - 0 then 'checked="checked"' else ""#--> /> -
-
- - 0 then 'checked="checked"' else ""#--> /> -
-
- - 0 then 'checked="checked"' else ""#--> /> -
-
- - 0 then 'checked="checked"' else ""#--> /> -
-
- - 0 then 'checked="checked"' else ""#--> /> -
-
- - 0 then 'checked="checked"' else ""#--> /> -
-
- - 0 then 'checked="checked"' else ""#--> /> -
-
- - -   -
-
-
-
- - -
-
-

$T('section-OSD')

-
-
-
-
- - 0 then 'checked="checked"' else ""#--> /> - $T('explain-ntfosd_enable') -
-
- - 0 then 'checked="checked"' else ""#--> /> -
-
- - 0 then 'checked="checked"' else ""#--> /> -
-
- - 0 then 'checked="checked"' else ""#--> /> -
-
- - 0 then 'checked="checked"' else ""#--> /> -
-
- - 0 then 'checked="checked"' else ""#--> /> -
-
- - 0 then 'checked="checked"' else ""#--> /> -
-
- - 0 then 'checked="checked"' else ""#--> /> -
-
- - 0 then 'checked="checked"' else ""#--> /> -
-
- - 0 then 'checked="checked"' else ""#--> /> -
-
- - 0 then 'checked="checked"' else ""#--> /> -
-
- - -   -
-
-
-
-

$T('section-Prowl')

@@ -650,6 +710,29 @@ } }); }); + \$('#test_windows_notification').click(function () { + \$.ajax({ + type: "GET", + url: "../../tapi", + data: {mode: 'test_windows', apikey: '$session', output: 'json' }, + beforeSend: function () { + \$('#test_notification').attr("disabled", "disabled"); + \$('#testnotice-result').removeClass("success failure").addClass("loading").html('$T('post-Verifying')'); + console.log('asdas') + }, + complete: function () { + \$('#test_notification').removeAttr("disabled"); + \$('#testnotice-result').removeClass("loading"); + }, + success: function (data) { + if (data.status == true) { + \$('#testnotice-result').addClass("success").html('$T('smpl-notesent')'); + } else { + \$('#testnotice-result').addClass("failure").html(data.error); + } + } + }); + }); \$('#test_pushbullet').click(function () { var data = { mode: 'test_pushbullet', apikey: '$session', output: 'json' }; \$("#pushbullet").extractFormDataTo(data); diff --git a/interfaces/Config/templates/staticcfg/css/style.css b/interfaces/Config/templates/staticcfg/css/style.css index d39eb779c..25dd629b2 100644 --- a/interfaces/Config/templates/staticcfg/css/style.css +++ b/interfaces/Config/templates/staticcfg/css/style.css @@ -155,7 +155,9 @@ input[type="checkbox"]+.desc { .infoTableSeperator.alt { background-color: #F8F8F8; } - +.success { + color: #5cb85c !important; +} .typeahead.dropdown-menu { padding: 0; min-width: 300px; diff --git a/sabnzbd/api.py b/sabnzbd/api.py index 416271120..7fcb36f41 100644 --- a/sabnzbd/api.py +++ b/sabnzbd/api.py @@ -719,6 +719,11 @@ def _api_test_email(name, output, kwargs): res = None return report(output, error=res) +def _api_test_windows(name, output, kwargs): + """ API: send a test to Windows, return result """ + logging.info("Sending test notification") + res = sabnzbd.growler.send_windows('SABnzbd', T('Test Notification'), 'other') + return report(output, error=res) def _api_test_notif(name, output, kwargs): """ API: send a test to Notification Center, return result """ @@ -908,6 +913,7 @@ _api_table = { 'retry_all': (_api_retry_all, 2), 'reset_quota': (_api_reset_quota, 2), 'test_email': (_api_test_email, 2), + 'test_windows': (_api_test_windows, 2), 'test_notif': (_api_test_notif, 2), 'test_growl': (_api_test_growl, 2), 'test_osd': (_api_test_osd, 2), diff --git a/sabnzbd/cfg.py b/sabnzbd/cfg.py index 9ed4cfa5d..c2f3ced1d 100644 --- a/sabnzbd/cfg.py +++ b/sabnzbd/cfg.py @@ -272,6 +272,19 @@ ncenter_prio_error = OptionBool('ncenter', 'ncenter_prio_error', False) ncenter_prio_queue_done = OptionBool('ncenter', 'ncenter_prio_queue_done', True) ncenter_prio_other = OptionBool('ncenter', 'ncenter_prio_other', False) +# [acenter] +acenter_enable = OptionBool('acenter', 'acenter_enable', sabnzbd.WIN32) +acenter_prio_startup = OptionBool('acenter', 'acenter_prio_startup', True) +acenter_prio_download = OptionBool('acenter', 'acenter_prio_download', False) +acenter_prio_pp = OptionBool('acenter', 'acenter_prio_pp', False) +acenter_prio_complete = OptionBool('acenter', 'acenter_prio_complete', True) +acenter_prio_failed = OptionBool('acenter', 'acenter_prio_failed', True) +acenter_prio_disk_full = OptionBool('acenter', 'acenter_prio_disk_full', True) +acenter_prio_warning = OptionBool('acenter', 'acenter_prio_warning', False) +acenter_prio_error = OptionBool('acenter', 'acenter_prio_error', False) +acenter_prio_queue_done = OptionBool('acenter', 'acenter_prio_queue_done', True) +acenter_prio_other = OptionBool('acenter', 'acenter_prio_other', False) + # [ntfosd] ntfosd_enable = OptionBool('ntfosd', 'ntfosd_enable', not sabnzbd.WIN32 and not sabnzbd.DARWIN) ntfosd_prio_startup = OptionBool('ntfosd', 'ntfosd_prio_startup', True) diff --git a/sabnzbd/growler.py b/sabnzbd/growler.py index eddc6e279..245fd9b46 100644 --- a/sabnzbd/growler.py +++ b/sabnzbd/growler.py @@ -123,6 +123,11 @@ def send_notification(title, msg, gtype): if sabnzbd.DARWIN_VERSION > 7 and sabnzbd.cfg.ncenter_enable(): if check_classes(gtype, 'ncenter'): send_notification_center(title, msg, gtype) + + # Windows + if sabnzbd.WIN32 and sabnzbd.cfg.acenter_enable(): + if check_classes(gtype, 'acenter'): + send_windows(title, msg, gtype) # Growl if sabnzbd.cfg.growl_enable() and check_classes(gtype, 'growl'): @@ -154,7 +159,6 @@ def send_notification(title, msg, gtype): if have_ntfosd() and sabnzbd.cfg.ntfosd_enable() and check_classes(gtype, 'ntfosd'): send_notify_osd(title, msg) - def reset_growl(): """ Reset Growl (after changing language) """ global _GROWL, _GROWL_REG @@ -534,3 +538,7 @@ def send_pushbullet(title, msg, gtype, force=False, test=None): logging.info('Traceback: ', exc_info=True) return T('Failed to send pushbullet message') return '' + +def send_windows(title, msg, gtype): + sabnzbd.WINTRAY.sendnotification(title, msg) + return None diff --git a/sabnzbd/interface.py b/sabnzbd/interface.py index 178a436f9..53c5c229f 100644 --- a/sabnzbd/interface.py +++ b/sabnzbd/interface.py @@ -2743,6 +2743,10 @@ LIST_NCENTER = ('ncenter_enable', 'ncenter_prio_startup', 'ncenter_prio_download', 'ncenter_prio_pp', 'ncenter_prio_complete', 'ncenter_prio_failed', 'ncenter_prio_disk_full', 'ncenter_prio_warning', 'ncenter_prio_error', 'ncenter_prio_queue_done', 'ncenter_prio_other' ) +LIST_ACENTER = ('acenter_enable', + 'acenter_prio_startup', 'acenter_prio_download', 'acenter_prio_pp', 'acenter_prio_complete', 'acenter_prio_failed', + 'acenter_prio_disk_full', 'acenter_prio_warning', 'acenter_prio_error', 'acenter_prio_queue_done', 'acenter_prio_other' + ) LIST_NTFOSD = ('ntfosd_enable', 'ntfosd_prio_startup', 'ntfosd_prio_download', 'ntfosd_prio_pp', 'ntfosd_prio_complete', 'ntfosd_prio_failed', 'ntfosd_prio_disk_full', 'ntfosd_prio_warning', 'ntfosd_prio_error', 'ntfosd_prio_queue_done', 'ntfosd_prio_other' @@ -2797,6 +2801,8 @@ class ConfigNotify(object): conf[kw] = config.get_config('pushbullet', kw)() for kw in LIST_NCENTER: conf[kw] = config.get_config('ncenter', kw)() + for kw in LIST_ACENTER: + conf[kw] = config.get_config('acenter', kw)() for kw in LIST_NTFOSD: conf[kw] = config.get_config('ntfosd', kw)() conf['notify_texts'] = sabnzbd.growler.NOTIFICATION @@ -2824,6 +2830,10 @@ class ConfigNotify(object): msg = config.get_config('ncenter', kw).set(platform_encode(kwargs.get(kw))) if msg: return badParameterResponse(T('Incorrect value for %s: %s') % (kw, unicoder(msg)), ajax) + for kw in LIST_ACENTER: + msg = config.get_config('acenter', kw).set(platform_encode(kwargs.get(kw))) + if msg: + return badParameterResponse(T('Incorrect value for %s: %s') % (kw, unicoder(msg)), ajax) for kw in LIST_NTFOSD: msg = config.get_config('ntfosd', kw).set(platform_encode(kwargs.get(kw))) if msg: diff --git a/sabnzbd/skintext.py b/sabnzbd/skintext.py index cb24fbbbf..ff9768d54 100644 --- a/sabnzbd/skintext.py +++ b/sabnzbd/skintext.py @@ -620,8 +620,10 @@ SKIN_TEXT = { 'explain-ntfosd_enable' : TT('Send notifications to NotifyOSD'), #: Don't translate "NotifyOSD" 'opt-ncenter_enable' : TT('Notification Center'), 'explain-ncenter_enable' : TT('Send notifications to Notification Center'), + 'opt-acenter_enable' : TT('Enable Windows Notifications'), 'testNotify' : TT('Test Notification'), 'section-NC' : TT('Notification Center'), #: Header for OSX Notfication Center section + 'section-AC' : TT('Windows Notifications'), 'section-OSD' : TT('NotifyOSD'), #: Header for Ubuntu's NotifyOSD notifications section 'section-Prowl' : TT('Prowl'), #: Header for Prowl notification section 'opt-prowl_enable' : TT('Enable Prowl notifications'), #: Prowl settings diff --git a/sabnzbd/utils/systrayiconthread.py b/sabnzbd/utils/systrayiconthread.py index a6f2d4b48..e248dd234 100644 --- a/sabnzbd/utils/systrayiconthread.py +++ b/sabnzbd/utils/systrayiconthread.py @@ -94,6 +94,20 @@ class SysTrayIconThread(Thread): # override this def doUpdates(self): pass + + # Notification + def sendnotification(self, title, msg): + hicon = self.get_icon(self.icon) + win32gui.Shell_NotifyIcon(win32gui.NIM_MODIFY, + (self.hwnd, + 0, + win32gui.NIF_INFO, + win32con.WM_USER+20, + hicon, + "Balloon tooltip", + msg, + 200, + title)) def _add_ids_to_menu_options(self, menu_options): result = []