Merge lp:~artmello/ubuntu-push/ubuntu-push-settings_notifications into lp:ubuntu-push

Proposed by Arthur Mello
Status: Merged
Approved by: Bill Filler
Approved revision: 163
Merged at revision: 163
Proposed branch: lp:~artmello/ubuntu-push/ubuntu-push-settings_notifications
Merge into: lp:ubuntu-push
Diff against target: 774 lines (+419/-128)
12 files modified
bus/haptic/haptic.go (+18/-2)
bus/notifications/raw.go (+13/-0)
click/cblacklist/cblacklist.go (+0/-75)
click/cnotificationsettings/cnotificationsettings.go (+230/-0)
client/service/postal.go (+4/-4)
client/service/postal_test.go (+11/-11)
debian/push-helper.hook (+1/-1)
debian/ubuntu-push-client.install (+1/-0)
messaging/messaging.go (+8/-0)
scripts/click-hook (+113/-35)
scripts/click-hook-wrapper (+13/-0)
sounds/sounds.go (+7/-0)
To merge this branch: bzr merge lp:~artmello/ubuntu-push/ubuntu-push-settings_notifications
Reviewer Review Type Date Requested Status
system-apps-ci-bot continuous-integration Needs Fixing
Ubuntu Push Hackers Pending
Review via email: mp+299587@code.launchpad.net

Commit message

Update ubuntu-push to work wih the new Notification panel

Description of the change

Update ubuntu-push to work wih the new Notification panel

To post a comment you must log in.
Revision history for this message
system-apps-ci-bot (system-apps-ci-bot) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bus/haptic/haptic.go'
2--- bus/haptic/haptic.go 2015-03-05 14:09:54 +0000
3+++ bus/haptic/haptic.go 2016-07-08 17:08:02 +0000
4@@ -1,5 +1,5 @@
5 /*
6- Copyright 2014 Canonical Ltd.
7+ Copyright 2014-2016 Canonical Ltd.
8
9 This program is free software: you can redistribute it and/or modify it
10 under the terms of the GNU General Public License version 3, as published
11@@ -22,6 +22,7 @@
12 "launchpad.net/ubuntu-push/bus"
13 "launchpad.net/ubuntu-push/bus/accounts"
14 "launchpad.net/ubuntu-push/click"
15+ "launchpad.net/ubuntu-push/click/cnotificationsettings"
16 "launchpad.net/ubuntu-push/launch_helper"
17 "launchpad.net/ubuntu-push/logger"
18 )
19@@ -46,12 +47,27 @@
20 return &Haptic{endp, log, acc, fallback}
21 }
22
23+var vibrateInSilentMode = cnotificationsettings.VibrateInSilentMode
24+var canUseVibrationsNotify = cnotificationsettings.CanUseVibrationsNotify
25+
26 // Present presents the notification via a vibrate pattern
27-func (haptic *Haptic) Present(_ *click.AppId, nid string, notification *launch_helper.Notification) bool {
28+func (haptic *Haptic) Present(app *click.AppId, nid string, notification *launch_helper.Notification) bool {
29 if notification == nil {
30 panic("please check notification is not nil before calling present")
31 }
32
33+ if !canUseVibrationsNotify(app) {
34+ haptic.log.Debugf("[%s] vibrate disabled by user for this app.", nid)
35+ return false
36+ }
37+
38+ if (haptic.acc.SilentMode()) {
39+ if (!vibrateInSilentMode()) {
40+ haptic.log.Debugf("[%s] vibrate disabled by user when in Silent Mode.", nid)
41+ return false
42+ }
43+ }
44+
45 if !haptic.acc.Vibrate() {
46 haptic.log.Debugf("[%s] vibrate disabled by user.", nid)
47 return false
48
49=== modified file 'bus/notifications/raw.go'
50--- bus/notifications/raw.go 2015-12-04 15:31:27 +0000
51+++ bus/notifications/raw.go 2016-07-08 17:08:02 +0000
52@@ -29,6 +29,7 @@
53
54 "launchpad.net/ubuntu-push/bus"
55 "launchpad.net/ubuntu-push/click"
56+ "launchpad.net/ubuntu-push/click/cnotificationsettings"
57 "launchpad.net/ubuntu-push/launch_helper"
58 "launchpad.net/ubuntu-push/logger"
59 "launchpad.net/ubuntu-push/sounds"
60@@ -127,6 +128,8 @@
61 return ch, nil
62 }
63
64+var canUseBubblesNotify = cnotificationsettings.CanUseBubblesNotify
65+
66 // Present displays a given card.
67 //
68 // If card.Actions is empty it's a plain, noninteractive bubble notification.
69@@ -138,6 +141,16 @@
70 panic("please check notification is not nil before calling present")
71 }
72
73+ if (!canUseBubblesNotify(app)) {
74+ raw.log.Debugf("[%s] bubbles disabled by user for this app.", nid)
75+
76+ if raw.sound != nil {
77+ return raw.sound.Present(app, nid, notification)
78+ } else {
79+ return false
80+ }
81+ }
82+
83 card := notification.Card
84
85 if card == nil || !card.Popup || card.Summary == "" {
86
87=== removed directory 'click/cblacklist'
88=== removed file 'click/cblacklist/cblacklist.go'
89--- click/cblacklist/cblacklist.go 2014-08-01 23:25:43 +0000
90+++ click/cblacklist/cblacklist.go 1970-01-01 00:00:00 +0000
91@@ -1,75 +0,0 @@
92-/*
93- Copyright 2013-2014 Canonical Ltd.
94-
95- This program is free software: you can redistribute it and/or modify it
96- under the terms of the GNU General Public License version 3, as published
97- by the Free Software Foundation.
98-
99- This program is distributed in the hope that it will be useful, but
100- WITHOUT ANY WARRANTY; without even the implied warranties of
101- MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
102- PURPOSE. See the GNU General Public License for more details.
103-
104- You should have received a copy of the GNU General Public License along
105- with this program. If not, see <http://www.gnu.org/licenses/>.
106-*/
107-
108-// Package cblacklist accesses the g_settings notification blacklist
109-
110-package cblacklist
111-
112-/*
113-#cgo pkg-config: gio-unix-2.0
114-#cgo pkg-config: glib-2.0
115-
116-#include <stdlib.h>
117-#include <gio/gio.h>
118-
119-#define BLACKLIST_CONFIG_SCHEMA_ID "com.ubuntu.notifications.hub"
120-#define BLACKLIST_KEY "blacklist"
121-
122-int is_blacklisted(const char *pkgname, const char *appname) {
123- static GSettings *pushSettings = NULL;
124- GVariantIter *iter;
125- gchar *pkg;
126- gchar *app;
127- int blacklisted = 0;
128-
129- if (!pushSettings) {
130- GSettingsSchemaSource * source = g_settings_schema_source_get_default ();
131- if (!g_settings_schema_source_lookup (g_settings_schema_source_get_default (), BLACKLIST_CONFIG_SCHEMA_ID, TRUE)) {
132- return -1;
133- }
134- pushSettings = g_settings_new(BLACKLIST_CONFIG_SCHEMA_ID);
135- }
136- GVariant *blacklist = g_settings_get_value(pushSettings, BLACKLIST_KEY);
137- g_variant_get (blacklist, "a(ss)", &iter);
138- while (g_variant_iter_loop (iter, "(ss)", &pkg, &app)) {
139- if (0==g_strcmp0(pkg, pkgname) && 0==g_strcmp0(app, appname)) {
140- blacklisted = 1;
141- break;
142- }
143- // No need to free pkg and app, according to GVariant array example
144- }
145- g_variant_iter_free (iter);
146- g_variant_unref (blacklist);
147- return blacklisted;
148-}
149-
150-*/
151-import "C"
152-
153-import (
154- "unsafe"
155-
156- "launchpad.net/ubuntu-push/click"
157-)
158-
159-// IsBlacklisted returns true if the application is in the gsettings blacklist
160-func IsBlacklisted(app *click.AppId) bool {
161- pkgname := C.CString(app.Package)
162- appname := C.CString(app.Application)
163- defer C.free(unsafe.Pointer(pkgname))
164- defer C.free(unsafe.Pointer(appname))
165- return C.is_blacklisted(pkgname, appname) == 1
166-}
167
168=== added directory 'click/cnotificationsettings'
169=== added file 'click/cnotificationsettings/cnotificationsettings.go'
170--- click/cnotificationsettings/cnotificationsettings.go 1970-01-01 00:00:00 +0000
171+++ click/cnotificationsettings/cnotificationsettings.go 2016-07-08 17:08:02 +0000
172@@ -0,0 +1,230 @@
173+/*
174+ Copyright 2016 Canonical Ltd.
175+
176+ This program is free software: you can redistribute it and/or modify it
177+ under the terms of the GNU General Public License version 3, as published
178+ by the Free Software Foundation.
179+
180+ This program is distributed in the hope that it will be useful, but
181+ WITHOUT ANY WARRANTY; without even the implied warranties of
182+ MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
183+ PURPOSE. See the GNU General Public License for more details.
184+
185+ You should have received a copy of the GNU General Public License along
186+ with this program. If not, see <http://www.gnu.org/licenses/>.
187+*/
188+
189+// Package cnotificationsettings accesses the g_settings notification settings
190+
191+package cnotificationsettings
192+
193+/*
194+#cgo pkg-config: gio-unix-2.0
195+#cgo pkg-config: glib-2.0
196+
197+#include <stdlib.h>
198+#include <gio/gio.h>
199+
200+#define NOTIFICATION_APPS_SETTINGS_SCHEMA_ID "com.ubuntu.notifications.settings.applications"
201+#define VIBRATE_SILENT_MODE_KEY "vibrate-silent-mode"
202+#define NOTIFICATION_SETTINGS_SCHEMA_ID "com.ubuntu.notifications.settings"
203+#define SETTINGS_BASE_PATH "/com/ubuntu/NotificationSettings/"
204+#define ENABLE_NOTIFICATIONS_KEY "enable-notifications"
205+#define USE_SOUNDS_NOTIFICATIONS_KEY "use-sounds-notifications"
206+#define USE_VIBRATIONS_NOTIFICATIONS_KEY "use-vibrations-notifications"
207+#define USE_BUBBLES_NOTIFICATIONS_KEY "use-bubbles-notifications"
208+#define USE_LIST_NOTIFICATIONS_KEY "use-list-notifications"
209+
210+GSettings* get_settings() {
211+ // Check if GSettings schema exists
212+ GSettingsSchemaSource *source = g_settings_schema_source_get_default();
213+ if (!g_settings_schema_source_lookup(source, NOTIFICATION_APPS_SETTINGS_SCHEMA_ID, TRUE)) {
214+ return NULL;
215+ }
216+
217+ return g_settings_new(NOTIFICATION_APPS_SETTINGS_SCHEMA_ID);
218+}
219+
220+int vibrate_in_silent_mode() {
221+ GSettings *settings = NULL;
222+ int vibrateInSilentMode = 0;
223+
224+ settings = get_settings();
225+ if (!settings) {
226+ return -1;
227+ }
228+
229+ if (g_settings_get_boolean(settings, VIBRATE_SILENT_MODE_KEY)) {
230+ vibrateInSilentMode = 1;
231+ }
232+
233+ g_object_unref(settings);
234+ return vibrateInSilentMode;
235+}
236+
237+GSettings* get_settings_for_app(const char *pkgname, const char *appname) {
238+ GSettings *settings = NULL;
239+ gchar *path;
240+
241+ // Check if GSettings schema exists
242+ GSettingsSchemaSource *source = g_settings_schema_source_get_default();
243+ if (!g_settings_schema_source_lookup(source, NOTIFICATION_SETTINGS_SCHEMA_ID, TRUE)) {
244+ return NULL;
245+ }
246+
247+ // Define notifications settings GSettings path
248+ if (pkgname == "") {
249+ // Use "dpkg" as package name for legacy apps
250+ path = g_strconcat(SETTINGS_BASE_PATH, "dpkg/", appname, "/", NULL);
251+ } else {
252+ path = g_strconcat(SETTINGS_BASE_PATH, pkgname, "/", appname, "/", NULL);
253+ }
254+
255+ settings = g_settings_new_with_path(NOTIFICATION_SETTINGS_SCHEMA_ID, path);
256+ g_free(path);
257+
258+ return settings;
259+}
260+
261+int are_notifications_enabled(const char *pkgname, const char *appname) {
262+ GSettings *notificationSettings = NULL;
263+ int enableNotifications = 0;
264+
265+ notificationSettings = get_settings_for_app(pkgname, appname);
266+ if (!notificationSettings) {
267+ return -1;
268+ }
269+
270+ if (g_settings_get_boolean(notificationSettings, ENABLE_NOTIFICATIONS_KEY)) {
271+ enableNotifications = 1;
272+ }
273+
274+ g_object_unref(notificationSettings);
275+ return enableNotifications;
276+}
277+
278+int can_use_sounds_notify(const char *pkgname, const char *appname) {
279+ GSettings *notificationSettings = NULL;
280+ int soundsNotify = 0;
281+
282+ notificationSettings = get_settings_for_app(pkgname, appname);
283+ if (!notificationSettings) {
284+ return -1;
285+ }
286+
287+ if (g_settings_get_boolean(notificationSettings, USE_SOUNDS_NOTIFICATIONS_KEY)) {
288+ soundsNotify = 1;
289+ }
290+
291+ g_object_unref(notificationSettings);
292+ return soundsNotify;
293+}
294+
295+int can_use_vibrations_notify(const char *pkgname, const char *appname) {
296+ GSettings *notificationSettings = NULL;
297+ int vibrationsNotify = 0;
298+
299+ notificationSettings = get_settings_for_app(pkgname, appname);
300+ if (!notificationSettings) {
301+ return -1;
302+ }
303+
304+ if (g_settings_get_boolean(notificationSettings, USE_VIBRATIONS_NOTIFICATIONS_KEY)) {
305+ vibrationsNotify = 1;
306+ }
307+
308+ g_object_unref(notificationSettings);
309+ return vibrationsNotify;
310+}
311+
312+int can_use_bubbles_notify(const char *pkgname, const char *appname) {
313+ GSettings *notificationSettings = NULL;
314+ int bubblesNotify = 0;
315+
316+ notificationSettings = get_settings_for_app(pkgname, appname);
317+ if (!notificationSettings) {
318+ return -1;
319+ }
320+
321+ if (g_settings_get_boolean(notificationSettings, USE_BUBBLES_NOTIFICATIONS_KEY)) {
322+ bubblesNotify = 1;
323+ }
324+
325+ g_object_unref(notificationSettings);
326+ return bubblesNotify;
327+}
328+
329+int can_use_list_notify(const char *pkgname, const char *appname) {
330+ GSettings *notificationSettings = NULL;
331+ int listNotify = 0;
332+
333+ notificationSettings = get_settings_for_app(pkgname, appname);
334+ if (!notificationSettings) {
335+ return -1;
336+ }
337+
338+ if (g_settings_get_boolean(notificationSettings, USE_LIST_NOTIFICATIONS_KEY)) {
339+ listNotify = 1;
340+ }
341+
342+ g_object_unref(notificationSettings);
343+ return listNotify;
344+}
345+*/
346+import "C"
347+
348+import (
349+ "unsafe"
350+
351+ "launchpad.net/ubuntu-push/click"
352+)
353+
354+// VibrateInSilentMode returns true if applications can use vibrations notify when in silent mode
355+func VibrateInSilentMode() bool {
356+ return C.vibrate_in_silent_mode() != 0
357+}
358+
359+// AreNotificationsEnabled returns true if the application is marked on gsettings to use notifications
360+func AreNotificationsEnabled(app *click.AppId) bool {
361+ pkgname := C.CString(app.Package)
362+ appname := C.CString(app.Application)
363+ defer C.free(unsafe.Pointer(pkgname))
364+ defer C.free(unsafe.Pointer(appname))
365+ return C.are_notifications_enabled(pkgname, appname) != 0
366+}
367+
368+// CanUseSoundsNotify returns true if the application is marked on gsettings to use sounds notify
369+func CanUseSoundsNotify(app *click.AppId) bool {
370+ pkgname := C.CString(app.Package)
371+ appname := C.CString(app.Application)
372+ defer C.free(unsafe.Pointer(pkgname))
373+ defer C.free(unsafe.Pointer(appname))
374+ return C.can_use_sounds_notify(pkgname, appname) != 0
375+}
376+
377+// CanUseVibrationsNotify returns true if the application is marked on gsettings to use vibrations notify
378+func CanUseVibrationsNotify(app *click.AppId) bool {
379+ pkgname := C.CString(app.Package)
380+ appname := C.CString(app.Application)
381+ defer C.free(unsafe.Pointer(pkgname))
382+ defer C.free(unsafe.Pointer(appname))
383+ return C.can_use_vibrations_notify(pkgname, appname) != 0
384+}
385+
386+// CanUseBubblesNotify returns true if the application is marked on gsettings to use bubbles notify
387+func CanUseBubblesNotify(app *click.AppId) bool {
388+ pkgname := C.CString(app.Package)
389+ appname := C.CString(app.Application)
390+ defer C.free(unsafe.Pointer(pkgname))
391+ defer C.free(unsafe.Pointer(appname))
392+ return C.can_use_bubbles_notify(pkgname, appname) != 0
393+}
394+
395+// CanUseListNotify returns true if the application is marked on gsettings to use list notificy
396+func CanUseListNotify(app *click.AppId) bool {
397+ pkgname := C.CString(app.Package)
398+ appname := C.CString(app.Application)
399+ defer C.free(unsafe.Pointer(pkgname))
400+ defer C.free(unsafe.Pointer(appname))
401+ return C.can_use_list_notify(pkgname, appname) != 0
402+}
403
404=== modified file 'client/service/postal.go'
405--- client/service/postal.go 2015-12-04 15:31:27 +0000
406+++ client/service/postal.go 2016-07-08 17:08:02 +0000
407@@ -31,7 +31,7 @@
408 "launchpad.net/ubuntu-push/bus/unitygreeter"
409 "launchpad.net/ubuntu-push/bus/windowstack"
410 "launchpad.net/ubuntu-push/click"
411- "launchpad.net/ubuntu-push/click/cblacklist"
412+ "launchpad.net/ubuntu-push/click/cnotificationsettings"
413 "launchpad.net/ubuntu-push/launch_helper"
414 "launchpad.net/ubuntu-push/logger"
415 "launchpad.net/ubuntu-push/messaging"
416@@ -416,7 +416,7 @@
417 return svc.urlDispatcher.TestURL(app, notif.Card.Actions)
418 }
419
420-var isBlacklisted = cblacklist.IsBlacklisted
421+var areNotificationsEnabled = cnotificationsettings.AreNotificationsEnabled
422
423 func (svc *PostalService) messageHandler(app *click.AppId, nid string, output *launch_helper.HelperOutput) bool {
424 if output == nil || output.Notification == nil {
425@@ -437,8 +437,8 @@
426 return false
427 }
428
429- if isBlacklisted(app) {
430- svc.Log.Debugf("notification skipped (except emblem counter) because app is blacklisted")
431+ if !areNotificationsEnabled(app) {
432+ svc.Log.Debugf("notification skipped (except emblem counter) because app has notifications disabled")
433 return svc.emblemCounter.Present(app, nid, output.Notification)
434 }
435
436
437=== modified file 'client/service/postal_test.go'
438--- client/service/postal_test.go 2016-05-03 11:12:44 +0000
439+++ client/service/postal_test.go 2016-07-08 17:08:02 +0000
440@@ -175,8 +175,8 @@
441 accountsCh chan []interface{}
442 fakeLauncher *fakeHelperLauncher
443 getTempDir func(string) (string, error)
444- oldIsBlisted func(*click.AppId) bool
445- blacklisted bool
446+ oldAreEnabled func(*click.AppId) bool
447+ notifyEnabled bool
448 }
449
450 type ualPostalSuite struct {
451@@ -191,8 +191,8 @@
452 var _ = Suite(&trivialPostalSuite{})
453
454 func (ps *postalSuite) SetUpTest(c *C) {
455- ps.oldIsBlisted = isBlacklisted
456- isBlacklisted = func(*click.AppId) bool { return ps.blacklisted }
457+ ps.oldAreEnabled = areNotificationsEnabled
458+ areNotificationsEnabled = func(*click.AppId) bool { return ps.notifyEnabled }
459 ps.log = helpers.NewTestLogger(c, "debug")
460 ps.cfg = &PostalServiceSetup{}
461 ps.bus = testibus.NewTestingEndpoint(condition.Work(true), condition.Work(true))
462@@ -209,7 +209,7 @@
463 ps.unityGreeterBus = testibus.NewTestingEndpoint(condition.Work(true), condition.Work(true), false)
464 ps.winStackBus = testibus.NewTestingEndpoint(condition.Work(true), condition.Work(true), []windowstack.WindowsInfo{})
465 ps.fakeLauncher = &fakeHelperLauncher{ch: make(chan []byte)}
466- ps.blacklisted = false
467+ ps.notifyEnabled = true
468
469 ps.getTempDir = launch_helper.GetTempDir
470 d := c.MkDir()
471@@ -223,7 +223,7 @@
472 }
473
474 func (ps *postalSuite) TearDownTest(c *C) {
475- isBlacklisted = ps.oldIsBlisted
476+ areNotificationsEnabled = ps.oldAreEnabled
477 launch_helper.GetTempDir = ps.getTempDir
478 close(ps.accountsCh)
479 }
480@@ -866,19 +866,19 @@
481 ps.unityGreeterBus = testibus.NewTestingEndpoint(condition.Work(true), condition.Work(true), false, false, false, false)
482 svc := ps.replaceBuses(NewPostalService(ps.cfg, ps.log))
483 svc.Start()
484- ps.blacklisted = false
485+ ps.notifyEnabled = true
486
487 emb := &launch_helper.EmblemCounter{Count: 2, Visible: true}
488 card := &launch_helper.Card{Icon: "icon-value", Summary: "summary-value", Persist: true}
489 output := &launch_helper.HelperOutput{Notification: &launch_helper.Notification{Card: card}}
490 embOut := &launch_helper.HelperOutput{Notification: &launch_helper.Notification{EmblemCounter: emb}}
491 app := clickhelp.MustParseAppId("com.example.app_app_1.0")
492- // sanity check: things are presented as normal if blacklist == false
493- ps.blacklisted = false
494+ // sanity check: things are presented as normal if notifyEnabled == true
495+ ps.notifyEnabled = true
496 c.Check(svc.messageHandler(app, "0", output), Equals, true)
497 c.Check(svc.messageHandler(app, "1", embOut), Equals, true)
498- ps.blacklisted = true
499- // and regular notifications (but not emblem counters) are suppressed if blacklisted.
500+ ps.notifyEnabled = false
501+ // and regular notifications (but not emblem counters) are suppressed if notifications are disabled.
502 c.Check(svc.messageHandler(app, "2", output), Equals, false)
503 c.Check(svc.messageHandler(app, "3", embOut), Equals, true)
504 }
505
506=== modified file 'debian/push-helper.hook'
507--- debian/push-helper.hook 2014-07-29 20:41:34 +0000
508+++ debian/push-helper.hook 2016-07-08 17:08:02 +0000
509@@ -1,4 +1,4 @@
510 Pattern: ${home}/.local/share/ubuntu-push-client/helpers/${id}.json
511 User-Level: yes
512 Hook-Name: push-helper
513-Exec: /usr/lib/ubuntu-push-client/click-hook
514+Exec: /usr/lib/ubuntu-push-client/click-hook-wrapper
515
516=== modified file 'debian/ubuntu-push-client.install'
517--- debian/ubuntu-push-client.install 2014-08-12 02:31:51 +0000
518+++ debian/ubuntu-push-client.install 2016-07-08 17:08:02 +0000
519@@ -4,6 +4,7 @@
520 debian/exec-tool /usr/lib/${DEB_HOST_MULTIARCH}/ubuntu-app-launch/push-helper
521 debian/push-helper.hook /usr/share/click/hooks
522 signing-helper/signing-helper /usr/lib/ubuntu-push-client
523+scripts/click-hook-wrapper /usr/lib/ubuntu-push-client
524 scripts/click-hook /usr/lib/ubuntu-push-client
525 usr/bin/ubuntu-push => /usr/lib/ubuntu-push-client/ubuntu-push-client
526
527
528=== modified file 'messaging/messaging.go'
529--- messaging/messaging.go 2015-08-13 19:59:45 +0000
530+++ messaging/messaging.go 2016-07-08 17:08:02 +0000
531@@ -25,6 +25,7 @@
532
533 "launchpad.net/ubuntu-push/bus/notifications"
534 "launchpad.net/ubuntu-push/click"
535+ "launchpad.net/ubuntu-push/click/cnotificationsettings"
536 "launchpad.net/ubuntu-push/launch_helper"
537 "launchpad.net/ubuntu-push/logger"
538 "launchpad.net/ubuntu-push/messaging/cmessaging"
539@@ -143,11 +144,18 @@
540 return len(nids)
541 }
542
543+var canUseListNotify = cnotificationsettings.CanUseListNotify
544+
545 func (mmu *MessagingMenu) Present(app *click.AppId, nid string, notification *launch_helper.Notification) bool {
546 if notification == nil {
547 panic("please check notification is not nil before calling present")
548 }
549
550+ if !canUseListNotify(app) {
551+ mmu.Log.Debugf("[%s] list notify disabled by user for this app.", nid)
552+ return false
553+ }
554+
555 card := notification.Card
556
557 if card == nil || !card.Persist || card.Summary == "" {
558
559=== modified file 'scripts/click-hook'
560--- scripts/click-hook 2015-04-01 14:46:20 +0000
561+++ scripts/click-hook 2016-07-08 17:08:02 +0000
562@@ -17,38 +17,24 @@
563 hook_ext = '.json'
564
565
566-def tup2variant(tup):
567- builder = GLib.VariantBuilder.new(GLib.VariantType.new("(ss)"))
568- builder.add_value(GLib.Variant.new_string(tup[0]))
569- builder.add_value(GLib.Variant.new_string(tup[1]))
570- return builder.end()
571-
572-
573-def cleanup_settings():
574- settings = Gio.Settings.new('com.ubuntu.notifications.hub')
575- blacklist = settings.get_value('blacklist').unpack()
576+def migrate_old_settings():
577+ old_settings = Gio.Settings.new('com.ubuntu.notifications.hub')
578+ blacklist = old_settings.get_value('blacklist').unpack()
579 if not blacklist:
580 return
581
582- clickdb = Click.DB.new()
583- clickdb.read()
584-
585- pkgnames = set()
586- for package in clickdb.get_packages(False):
587- pkgnames.add(package.get_property('package'))
588-
589- goodapps = GLib.VariantBuilder.new(GLib.VariantType.new("a(ss)"))
590-
591- dirty = False
592-
593- for appname in blacklist:
594- if appname[0] not in pkgnames and Gio.DesktopAppInfo.new(appname[1] + ".desktop") is None:
595- dirty = True
596- else:
597- goodapps.add_value(tup2variant(appname))
598-
599- if dirty:
600- settings.set_value('blacklist', goodapps.end())
601+ old_settings.reset('blacklist')
602+
603+ for app in blacklist:
604+ app_key = app[0] + '/'
605+ if not app[0]:
606+ app_key = 'dpkg/'
607+
608+ app_key += app[1]
609+
610+ settings_path = '/com/ubuntu/NotificationSettings/' + app_key + '/'
611+ settings = Gio.Settings.new_with_path('com.ubuntu.notifications.settings', settings_path)
612+ settings.set_boolean('enable-notifications', False)
613
614
615 def collect_helpers(helpers_data_path, helpers_data_path_tmp, hooks_path):
616@@ -92,15 +78,107 @@
617 return False
618
619
620+def populate_settings_from_legacy_dpkg():
621+ dpkg_apps_keys = list()
622+ legacy_helpers_path = '/usr/lib/ubuntu-push-client/legacy-helpers/'
623+ if os.path.isdir(legacy_helpers_path):
624+ for f in os.listdir(legacy_helpers_path):
625+ if not os.path.isfile(os.path.join(legacy_helpers_path, f)):
626+ break
627+
628+ dpkg_app_key = '/'.join(['dpkg', f, '0'])
629+ dpkg_apps_keys.append(dpkg_app_key)
630+
631+ return dpkg_apps_keys
632+
633+
634+def reset_settings(path=None):
635+ if not path:
636+ return
637+
638+ settings_path = '/com/ubuntu/NotificationSettings/' + path + '/'
639+ try:
640+ settings = Gio.Settings.new_with_path('com.ubuntu.notifications.settings', settings_path)
641+ for k in settings.list_keys():
642+ settings.reset(k)
643+ except Exception:
644+ pass
645+
646+
647+def reset_removed_applications(current_apps=None, new_apps=None):
648+ if not current_apps or not new_apps:
649+ return
650+
651+ current_keys = list()
652+ for k in current_apps:
653+ key = '/'.join(k.split('/')[:2])
654+ current_keys.append(key)
655+
656+ new_keys = list()
657+ for k in new_apps:
658+ key = '/'.join(k.split('/')[:2])
659+ new_keys.append(key)
660+
661+ for settings_path in set(current_keys) - set(new_keys):
662+ reset_settings(settings_path)
663+
664+
665+def populate_notifications_settings(hooks_path=None):
666+ if not hooks_path or not os.path.isdir(hooks_path):
667+ return
668+
669+ db = Click.DB.new()
670+ db.read()
671+
672+ settings = Gio.Settings.new('com.ubuntu.notifications.settings.applications')
673+ applications = GLib.VariantBuilder.new(GLib.VariantType.new('as'))
674+
675+ current_applications_keys = settings.get_value('applications').unpack()
676+
677+ applications_keys = list()
678+ applications_keys += populate_settings_from_legacy_dpkg()
679+ for hook in os.listdir(hooks_path):
680+ helper_id = os.path.splitext(hook)[0]
681+ pkg_name, helper_name, version = helper_id.split('_')
682+
683+ manifest = json.loads(db.get_manifest_as_string(pkg_name, version))
684+ hooks = manifest.get('hooks', None)
685+ if not hooks:
686+ continue
687+
688+ app_names = list()
689+ for h in hooks.keys():
690+ if 'desktop' in hooks[h].keys():
691+ app_names.append(h)
692+
693+ for app_name in app_names:
694+ app_key = '/'.join([pkg_name, app_name, version])
695+ applications_keys.append(app_key)
696+
697+ for app_key in applications_keys:
698+ applications.add_value(GLib.Variant.new_string(app_key))
699+
700+ settings.set_value('applications', applications.end())
701+
702+ reset_removed_applications(current_applications_keys, applications_keys)
703+
704+
705 def main(helpers_data_path=None, helpers_data_path_tmp=None, hooks_path=None):
706 collect_fail = collect_helpers(helpers_data_path, helpers_data_path_tmp,
707 hooks_path)
708- clean_settings_fail = False
709- try:
710- cleanup_settings()
711- except Exception:
712- clean_settings_fail = True
713- return int(collect_fail or clean_settings_fail)
714+ migrate_old_settings_fail = False
715+ try:
716+ migrate_old_settings()
717+ except Exception:
718+ migrate_old_settings_fail = True
719+
720+ populate_settings_fail = False
721+ try:
722+ populate_notifications_settings(hooks_path)
723+ except Exception:
724+ populate_settings_fail = True
725+
726+ return int(collect_fail or migrate_old_settings_fail or populate_settings_fail)
727
728
729 if __name__ == "__main__":
730
731=== added file 'scripts/click-hook-wrapper'
732--- scripts/click-hook-wrapper 1970-01-01 00:00:00 +0000
733+++ scripts/click-hook-wrapper 2016-07-08 17:08:02 +0000
734@@ -0,0 +1,13 @@
735+#!/bin/sh
736+
737+# PackageKit clears all environment variables, so we get the UID and then read
738+# in $DBUS_SESSION_BUS_ADDRESS from /run/user/$UID/dbus-session
739+
740+USERID=`id -u`
741+
742+if test -z "$DBUS_SESSION_BUS_ADDRESS" ; then
743+ [ -e /run/user/$USERID/dbus-session ] && . /run/user/$USERID/dbus-session
744+ [ -n "$DBUS_SESSION_BUS_ADDRESS" ] && export DBUS_SESSION_BUS_ADDRESS
745+fi
746+
747+/usr/lib/ubuntu-push-client/click-hook
748
749=== modified file 'sounds/sounds.go'
750--- sounds/sounds.go 2015-12-04 15:31:27 +0000
751+++ sounds/sounds.go 2016-07-08 17:08:02 +0000
752@@ -27,6 +27,7 @@
753
754 "launchpad.net/ubuntu-push/bus/accounts"
755 "launchpad.net/ubuntu-push/click"
756+ "launchpad.net/ubuntu-push/click/cnotificationsettings"
757 "launchpad.net/ubuntu-push/launch_helper"
758 "launchpad.net/ubuntu-push/logger"
759 )
760@@ -84,8 +85,14 @@
761 return true
762 }
763
764+var canUseSoundsNotify = cnotificationsettings.CanUseSoundsNotify
765+
766 // Returns the absolute path of the sound to be played for app, nid and notification.
767 func (snd *sound) GetSound(app *click.AppId, nid string, notification *launch_helper.Notification) string {
768+ if !canUseSoundsNotify(app) {
769+ snd.log.Debugf("[%s] sounds disabled by user for this app.", nid)
770+ return ""
771+ }
772
773 if snd.acc.SilentMode() {
774 snd.log.Debugf("[%s] no sounds: silent mode on.", nid)

Subscribers

People subscribed via source and target branches