Merge lp:~artmello/indicator-datetime/indicator-datetime-notfication_settings into lp:indicator-datetime

Proposed by Arthur Mello
Status: Merged
Approved by: Charles Kerr
Approved revision: 464
Merged at revision: 457
Proposed branch: lp:~artmello/indicator-datetime/indicator-datetime-notfication_settings
Merge into: lp:indicator-datetime
Diff against target: 809 lines (+296/-164)
11 files modified
debian/control (+2/-2)
include/datetime/settings-live.h (+12/-4)
include/datetime/settings-shared.h (+9/-2)
include/datetime/settings.h (+6/-1)
include/notifications/notifications.h (+6/-0)
src/notifications.cpp (+24/-1)
src/settings-live.cpp (+109/-49)
src/snap.cpp (+46/-20)
tests/test-notification.cpp (+22/-14)
tests/test-settings.cpp (+48/-71)
tests/test-sound.cpp (+12/-0)
To merge this branch: bzr merge lp:~artmello/indicator-datetime/indicator-datetime-notfication_settings
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+298162@code.launchpad.net

Commit message

Update indicator-datetime to work with the new notification settings

Description of the change

Update indicator-datetime to work with the new notification settings

To post a comment you must log in.
Revision history for this message
Charles Kerr (charlesk) wrote :

Haven't tested, but code LGTM. A couple of optional minor suggestions inline.

The biggest takeaway that I'm getting from this patch is the gsettings-propertiescpp bridge code is too brittle. That's not new to this patch and isn't your problem; it's just become worse over time as we add more settings and I'll clean it up in a followup patch.

review: Approve
Revision history for this message
Charles Kerr (charlesk) wrote :

I don't understand the point of r456/r457 and would prefer they be backed out altogether. Surely the gsettings schema should be a hard requirement for us?

review: Needs Information
458. By Arthur Mello

Undo revisions 456/457

459. By Arthur Mello

Fix notifications so it respects if it should or not show bubbles or add to notification list

Revision history for this message
Arthur Mello (artmello) wrote :

> I don't understand the point of r456/r457 and would prefer they be backed out
> altogether. Surely the gsettings schema should be a hard requirement for us?

r458 reverted both r456 and r457 and unittests run fine on device (krillin, rc-proposed r369). This was added to silo 54 and, unfortunately, its build fails under all archs for Vivid, Xenial and Yakkety. Log file [0] for armhf/vivid (but the same error happens on all of them) shows that test-settings is failing with an exception related with missing 'com.canonical.indicator.datetime' gsetting schema. When we instantiate LiveSettings on that test, it will try to open the settings using that schema and that is causing the crash. Idea with r456/r457 was to lookup for the schema and skip settings test if it was missing. Any suggestions on how can we fix this build?

[0] https://launchpadlibrarian.net/268720228/buildlog_ubuntu-vivid-armhf.indicator-datetime_15.10+15.04.20160630-0ubuntu1_BUILDING.txt.gz

Revision history for this message
Arthur Mello (artmello) wrote :

Also r459 fix the control for displaying notification bubbles and adding notifications to messaging menu. Let me know what you think about it

Revision history for this message
Charles Kerr (charlesk) wrote :

> exception related with missing 'com.canonical.indicator.datetime' gsetting schema... any suggestions on how can we fix this build?

That's strange, tests/CMakeLists.txt already has rules in it to ensure the tests can find the schema, and this has been passing up until now.

Off the top of my head I don't know what's going wrong here. I'll see if I can reproduce in a vivid chroot that doesn't have indicator-datetime installed.

A couple of questions about schema lookups are inline below

review: Needs Information
Revision history for this message
Arthur Mello (artmello) wrote :

> That's strange, tests/CMakeLists.txt already has rules in it to ensure the
> tests can find the schema, and this has been passing up until now.
>
> Off the top of my head I don't know what's going wrong here. I'll see if I can
> reproduce in a vivid chroot that doesn't have indicator-datetime installed.

Yes, we were trying to find out what could be causing this after the changes on this MR but didnt find it yet.

> A couple of questions about schema lookups are inline below

I answered those

Revision history for this message
Arthur Mello (artmello) :
Revision history for this message
Charles Kerr (charlesk) wrote :

100% reproducible for me in a vivid chroot. One interesting clue, test-utils loads the same com.canonical.indicator.datetime schema, and /that/ test is passing. They use two different code paths to get there though. I feel like there's something simple here that we're both missing, so I'll stare at the screen a little more. :)

Thanks for explaining the plan with the relocatable schema, that part LGTM.

Revision history for this message
Charles Kerr (charlesk) wrote :

Okay, got a fix for it at http://paste.ubuntu.com/18201522/

The issue is that creating 'source' before calling SetUp() causes glib's schema search path to be created before GLibFixture::SetUp() sets the GSETTINGS_SEARCH_DIR environment variable to prepend our sandbox to the schema search path.

So, that's progress. After that fix I get a new & improved failure:
"Settings schema 'com.ubuntu.notifications.settings' is not installed"

Which I think is more straightforward, I think for /that/ I think we just need to add gsettings-ubuntu-touch-schemes (>= your-version-number) to debian/control

460. By Arthur Mello

Do not fail gracefully if gsettings schema is not installed

461. By Arthur Mello

Remove gsettings source call during unit tests
Set minimal version for gsettings-ubuntu-touch-schemas package

462. By Arthur Mello

Only wake device if bubbles notifications are enabled

463. By Arthur Mello

If in silent mode should only vibrate if the settings say so

464. By Arthur Mello

Should not use sounds notifications for calendar in silent mode

Revision history for this message
Charles Kerr (charlesk) wrote :

LGTM. Thanks Art :-)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2016-05-14 02:07:10 +0000
3+++ debian/control 2016-07-04 23:46:11 +0000
4@@ -15,7 +15,7 @@
5 liburl-dispatcher1-dev,
6 libproperties-cpp-dev,
7 # for com.ubuntu.notifications.hub schema to pick up blacklist of apps that can't show notifications
8- gsettings-ubuntu-schemas,
9+ gsettings-ubuntu-schemas (>= 0.0.7),
10 # for the test harness:
11 libgtest-dev,
12 libdbustest1-dev,
13@@ -47,7 +47,7 @@
14 Architecture: any
15 Depends: ${shlibs:Depends},
16 ${misc:Depends},
17- gsettings-ubuntu-schemas,
18+ gsettings-ubuntu-schemas (>= 0.0.7),
19 systemd | systemd-shim,
20 Recommends: indicator-applet | indicator-renderer,
21 evolution-data-server,
22
23=== modified file 'include/datetime/settings-live.h'
24--- include/datetime/settings-live.h 2016-02-02 00:07:18 +0000
25+++ include/datetime/settings-live.h 2016-07-04 23:46:11 +0000
26@@ -39,9 +39,11 @@
27
28 private:
29 static void on_changed_ccid(GSettings*, gchar*, gpointer);
30- static void on_changed_cunh(GSettings*, gchar*, gpointer);
31+ static void on_changed_cal_notification(GSettings*, gchar*, gpointer);
32+ static void on_changed_general_notification(GSettings*, gchar*, gpointer);
33 void update_key_ccid(const std::string& key);
34- void update_key_cunh(const std::string& key);
35+ void update_key_cal_notification(const std::string& key);
36+ void update_key_general_notification(const std::string& key);
37
38 void update_custom_time_format();
39 void update_locations();
40@@ -63,10 +65,16 @@
41 void update_alarm_duration();
42 void update_alarm_haptic();
43 void update_snooze_duration();
44- void update_muted_apps();
45+ void update_cal_notification_enabled();
46+ void update_cal_notification_sounds();
47+ void update_cal_notification_vibrations();
48+ void update_cal_notification_bubbles();
49+ void update_cal_notification_list();
50+ void update_vibrate_silent_mode();
51
52 GSettings* m_settings;
53- GSettings* m_settings_cunh;
54+ GSettings* m_settings_cal_notification;
55+ GSettings* m_settings_general_notification;
56
57 // we've got a raw pointer here, so disable copying
58 LiveSettings(const LiveSettings&) =delete;
59
60=== modified file 'include/datetime/settings-shared.h'
61--- include/datetime/settings-shared.h 2016-02-02 00:07:18 +0000
62+++ include/datetime/settings-shared.h 2016-07-04 23:46:11 +0000
63@@ -52,7 +52,14 @@
64 #define SETTINGS_ALARM_HAPTIC_S "alarm-haptic-feedback"
65 #define SETTINGS_SNOOZE_DURATION_S "snooze-duration-minutes"
66
67-#define SETTINGS_CUNH_SCHEMA_ID "com.ubuntu.notifications.hub"
68-#define SETTINGS_CUNH_BLACKLIST_S "blacklist"
69+#define SETTINGS_NOTIFY_APPS_SCHEMA_ID "com.ubuntu.notifications.settings.applications"
70+#define SETTINGS_VIBRATE_SILENT_KEY "vibrate-silent-mode"
71+#define SETTINGS_NOTIFY_SCHEMA_ID "com.ubuntu.notifications.settings"
72+#define SETTINGS_NOTIFY_CALENDAR_PATH "/com/ubuntu/NotificationSettings/com.ubuntu.calendar/calendar/"
73+#define SETTINGS_NOTIFY_ENABLED_KEY "enable-notifications"
74+#define SETTINGS_NOTIFY_SOUNDS_KEY "use-sounds-notifications"
75+#define SETTINGS_NOTIFY_VIBRATIONS_KEY "use-vibrations-notifications"
76+#define SETTINGS_NOTIFY_BUBBLES_KEY "use-bubbles-notifications"
77+#define SETTINGS_NOTIFY_LIST_KEY "use-list-notifications"
78
79 #endif // INDICATOR_DATETIME_SETTINGS_SHARED
80
81=== modified file 'include/datetime/settings.h'
82--- include/datetime/settings.h 2016-02-02 00:05:45 +0000
83+++ include/datetime/settings.h 2016-07-04 23:46:11 +0000
84@@ -62,7 +62,12 @@
85 core::Property<unsigned int> alarm_volume;
86 core::Property<unsigned int> alarm_duration;
87 core::Property<unsigned int> snooze_duration;
88- core::Property<std::set<std::pair<std::string,std::string>>> muted_apps;
89+ core::Property<bool> cal_notification_enabled;
90+ core::Property<bool> cal_notification_sounds;
91+ core::Property<bool> cal_notification_vibrations;
92+ core::Property<bool> cal_notification_bubbles;
93+ core::Property<bool> cal_notification_list;
94+ core::Property<bool> vibrate_silent_mode;
95 };
96
97 } // namespace datetime
98
99=== modified file 'include/notifications/notifications.h'
100--- include/notifications/notifications.h 2016-05-14 02:07:10 +0000
101+++ include/notifications/notifications.h 2016-07-04 23:46:11 +0000
102@@ -77,6 +77,12 @@
103 /** Sets the time-out callback. This will be called exactly once. */
104 void set_timeout_callback (std::function<void()>);
105
106+ /** Sets if a notification bubble should be displayed. */
107+ void set_show_notification_bubble (bool show);
108+
109+ /** Sets if notification should be posted to messaging menu after it is closed. */
110+ void set_post_to_messaging_menu (bool post);
111+
112
113 private:
114 friend class Engine;
115
116=== modified file 'src/notifications.cpp'
117--- src/notifications.cpp 2016-05-14 02:07:10 +0000
118+++ src/notifications.cpp 2016-07-04 23:46:11 +0000
119@@ -61,6 +61,8 @@
120 std::vector<std::pair<std::string,std::string>> m_actions;
121 std::function<void(const std::string&)> m_closed_callback;
122 std::function<void()> m_timeout_callback;
123+ bool m_show_notification_bubble;
124+ bool m_post_to_messaging_menu;
125 };
126
127 Builder::Builder():
128@@ -126,6 +128,18 @@
129 impl->m_start_time = time;
130 }
131
132+void
133+Builder::set_show_notification_bubble (bool show)
134+{
135+ impl->m_show_notification_bubble = show;
136+}
137+
138+void
139+Builder::set_post_to_messaging_menu (bool post)
140+{
141+ impl->m_post_to_messaging_menu = post;
142+}
143+
144 /***
145 ****
146 ***/
147@@ -262,7 +276,12 @@
148 m_notifications[key] = { nn, info };
149 g_signal_connect (nn.get(), "closed",
150 G_CALLBACK(on_notification_closed), this);
151-
152+
153+ if (!info.m_show_notification_bubble) {
154+ post(info);
155+ return ret;
156+ }
157+
158 GError * error = nullptr;
159 if (notify_notification_show(nn.get(), &error))
160 {
161@@ -282,6 +301,10 @@
162
163 std::string post(const Builder::Impl& data)
164 {
165+ if (!data.m_post_to_messaging_menu) {
166+ return "";
167+ }
168+
169 if (!m_messaging_app) {
170 return std::string();
171 }
172
173=== modified file 'src/settings-live.cpp'
174--- src/settings-live.cpp 2016-02-03 20:25:19 +0000
175+++ src/settings-live.cpp 2016-07-04 23:46:11 +0000
176@@ -29,16 +29,20 @@
177
178 LiveSettings::~LiveSettings()
179 {
180- g_clear_object(&m_settings_cunh);
181+ g_clear_object(&m_settings_general_notification);
182+ g_clear_object(&m_settings_cal_notification);
183 g_clear_object(&m_settings);
184 }
185
186 LiveSettings::LiveSettings():
187 m_settings(g_settings_new(SETTINGS_INTERFACE)),
188- m_settings_cunh(g_settings_new(SETTINGS_CUNH_SCHEMA_ID))
189+ m_settings_cal_notification(g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH)),
190+ m_settings_general_notification(g_settings_new(SETTINGS_NOTIFY_APPS_SCHEMA_ID))
191 {
192- g_signal_connect (m_settings, "changed", G_CALLBACK(on_changed_ccid), this);
193- g_signal_connect (m_settings_cunh, "changed", G_CALLBACK(on_changed_cunh), this);
194+
195+ g_signal_connect (m_settings, "changed", G_CALLBACK(on_changed_ccid), this);
196+ g_signal_connect (m_settings_cal_notification, "changed", G_CALLBACK(on_changed_cal_notification), this);
197+ g_signal_connect (m_settings_general_notification, "changed", G_CALLBACK(on_changed_general_notification), this);
198
199 // init the Properties from the GSettings backend
200 update_custom_time_format();
201@@ -61,7 +65,12 @@
202 update_alarm_duration();
203 update_alarm_haptic();
204 update_snooze_duration();
205- update_muted_apps();
206+ update_cal_notification_enabled();
207+ update_cal_notification_sounds();
208+ update_cal_notification_vibrations();
209+ update_cal_notification_bubbles();
210+ update_cal_notification_list();
211+ update_vibrate_silent_mode();
212
213 // now listen for clients to change the properties s.t. we can sync update GSettings
214
215@@ -69,17 +78,6 @@
216 g_settings_set_string(m_settings, SETTINGS_CUSTOM_TIME_FORMAT_S, value.c_str());
217 });
218
219- muted_apps.changed().connect([this](const std::set<std::pair<std::string,std::string>>& value){
220- GVariantBuilder builder;
221- g_variant_builder_init(&builder, G_VARIANT_TYPE("a(ss)"));
222- for(const auto& app : value){
223- const std::string& pkgname {app.first};
224- const std::string& appname {app.second};
225- g_variant_builder_add(&builder, "(ss)", pkgname.c_str(), appname.c_str());
226- }
227- g_settings_set_value(m_settings_cunh, SETTINGS_CUNH_BLACKLIST_S, g_variant_builder_end(&builder));
228- });
229-
230 locations.changed().connect([this](const std::vector<std::string>& value){
231 const int n = value.size();
232 gchar** strv = g_new0(gchar*, n+1);
233@@ -160,6 +158,30 @@
234 snooze_duration.changed().connect([this](unsigned int value){
235 g_settings_set_uint(m_settings, SETTINGS_SNOOZE_DURATION_S, value);
236 });
237+
238+ cal_notification_enabled.changed().connect([this](bool value){
239+ g_settings_set_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_ENABLED_KEY, value);
240+ });
241+
242+ cal_notification_sounds.changed().connect([this](bool value){
243+ g_settings_set_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_SOUNDS_KEY, value);
244+ });
245+
246+ cal_notification_vibrations.changed().connect([this](bool value){
247+ g_settings_set_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_VIBRATIONS_KEY, value);
248+ });
249+
250+ cal_notification_bubbles.changed().connect([this](bool value){
251+ g_settings_set_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_BUBBLES_KEY, value);
252+ });
253+
254+ cal_notification_list.changed().connect([this](bool value){
255+ g_settings_set_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_LIST_KEY, value);
256+ });
257+
258+ vibrate_silent_mode.changed().connect([this](bool value){
259+ g_settings_set_boolean(m_settings_general_notification, SETTINGS_VIBRATE_SILENT_KEY, value);
260+ });
261 }
262
263 /***
264@@ -183,24 +205,6 @@
265 locations.set(l);
266 }
267
268-void LiveSettings::update_muted_apps()
269-{
270- std::set<std::pair<std::string,std::string>> apps;
271-
272- auto blacklist = g_settings_get_value(m_settings_cunh, SETTINGS_CUNH_BLACKLIST_S);
273- GVariantIter* iter {nullptr};
274- g_variant_get (blacklist, "a(ss)", &iter);
275- gchar* pkgname;
276- gchar* appname;
277- while (g_variant_iter_loop (iter, "(ss)", &pkgname, &appname)) {
278- apps.insert(std::make_pair(pkgname,appname));
279- }
280- g_variant_iter_free (iter);
281- g_clear_pointer(&blacklist, g_variant_unref);
282-
283- muted_apps.set(apps);
284-}
285-
286 void LiveSettings::update_show_calendar()
287 {
288 const auto val = g_settings_get_boolean(m_settings, SETTINGS_SHOW_CALENDAR_S);
289@@ -304,21 +308,77 @@
290 snooze_duration.set(g_settings_get_uint(m_settings, SETTINGS_SNOOZE_DURATION_S));
291 }
292
293-/***
294-****
295-***/
296-
297-void LiveSettings::on_changed_cunh(GSettings* /*settings*/,
298- gchar* key,
299- gpointer gself)
300-{
301- static_cast<LiveSettings*>(gself)->update_key_cunh(key);
302-}
303-
304-void LiveSettings::update_key_cunh(const std::string& key)
305-{
306- if (key == SETTINGS_CUNH_BLACKLIST_S)
307- update_muted_apps();
308+void LiveSettings::update_cal_notification_enabled()
309+{
310+ cal_notification_enabled.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_ENABLED_KEY));
311+}
312+
313+void LiveSettings::update_cal_notification_sounds()
314+{
315+ cal_notification_sounds.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_SOUNDS_KEY));
316+}
317+
318+void LiveSettings::update_cal_notification_vibrations()
319+{
320+ cal_notification_vibrations.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_VIBRATIONS_KEY));
321+}
322+
323+void LiveSettings::update_cal_notification_bubbles()
324+{
325+ cal_notification_bubbles.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_BUBBLES_KEY));
326+}
327+
328+void LiveSettings::update_cal_notification_list()
329+{
330+ cal_notification_list.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_LIST_KEY));
331+}
332+
333+void LiveSettings::update_vibrate_silent_mode()
334+{
335+ vibrate_silent_mode.set(g_settings_get_boolean(m_settings_general_notification, SETTINGS_VIBRATE_SILENT_KEY));
336+}
337+
338+/***
339+****
340+***/
341+
342+void LiveSettings::on_changed_cal_notification(GSettings* /*settings*/,
343+ gchar* key,
344+ gpointer gself)
345+{
346+ static_cast<LiveSettings*>(gself)->update_key_cal_notification(key);
347+}
348+
349+
350+void LiveSettings::update_key_cal_notification(const std::string& key)
351+{
352+ if (key == SETTINGS_NOTIFY_ENABLED_KEY)
353+ update_cal_notification_enabled();
354+ else if (key == SETTINGS_NOTIFY_SOUNDS_KEY)
355+ update_cal_notification_sounds();
356+ else if (key == SETTINGS_NOTIFY_VIBRATIONS_KEY)
357+ update_cal_notification_vibrations();
358+ else if (key == SETTINGS_NOTIFY_BUBBLES_KEY)
359+ update_cal_notification_bubbles();
360+ else if (key == SETTINGS_NOTIFY_LIST_KEY)
361+ update_cal_notification_list();
362+}
363+
364+/***
365+****
366+***/
367+
368+void LiveSettings::on_changed_general_notification(GSettings* /*settings*/,
369+ gchar* key,
370+ gpointer gself)
371+{
372+ static_cast<LiveSettings*>(gself)->update_key_general_notification(key);
373+}
374+
375+void LiveSettings::update_key_general_notification(const std::string& key)
376+{
377+ if (key == SETTINGS_VIBRATE_SILENT_KEY)
378+ update_vibrate_silent_mode();
379 }
380
381 /***
382
383=== modified file 'src/snap.cpp'
384--- src/snap.cpp 2016-05-14 17:18:45 +0000
385+++ src/snap.cpp 2016-07-04 23:46:11 +0000
386@@ -84,9 +84,9 @@
387 const Alarm& alarm,
388 response_func on_response)
389 {
390- // If calendar notifications are muted, don't show them
391- if (!appointment.is_ubuntu_alarm() && calendar_events_are_muted()) {
392- g_debug("Skipping muted calendar event '%s' notification", appointment.summary.c_str());
393+ // If calendar notifications are disabled, don't show them
394+ if (!appointment.is_ubuntu_alarm() && !calendar_notifications_are_enabled()) {
395+ g_debug("Skipping disabled calendar event '%s' notification", appointment.summary.c_str());
396 return;
397 }
398
399@@ -97,13 +97,14 @@
400 const bool interactive = appointment.is_ubuntu_alarm() && m_engine->supports_actions();
401
402 // force the system to stay awake
403- auto awake = std::make_shared<uin::Awake>(m_engine->app_name());
404+ std::shared_ptr<uin::Awake> awake;
405+ if (appointment.is_ubuntu_alarm() || calendar_bubbles_enabled() || calendar_list_enabled()) {
406+ awake = std::make_shared<uin::Awake>(m_engine->app_name());
407+ }
408
409 // calendar events are muted in silent mode; alarm clocks never are
410 std::shared_ptr<uin::Sound> sound;
411- // FIXME: only play sounds for alarms for now, we should itegrate it with
412- // system settings to decide if we should play sounds for calendar notification or not
413- if (appointment.is_ubuntu_alarm()) {
414+ if (appointment.is_ubuntu_alarm() || (calendar_sounds_enabled() && !silent_mode())) {
415 // create the sound.
416 const auto role = appointment.is_ubuntu_alarm() ? "alarm" : "alert";
417 const auto uri = get_alarm_uri(appointment, alarm, m_settings);
418@@ -114,10 +115,13 @@
419
420 // create the haptic feedback...
421 std::shared_ptr<uin::Haptic> haptic;
422- if (should_vibrate()) {
423- const auto haptic_mode = m_settings->alarm_haptic.get();
424- if (haptic_mode == "pulse")
425- haptic = std::make_shared<uin::Haptic>(uin::Haptic::MODE_PULSE, appointment.is_ubuntu_alarm());
426+ if (should_vibrate() && (appointment.is_ubuntu_alarm() || calendar_vibrations_enabled())) {
427+ // when in silent mode should only vibrate if user defined so
428+ if (!silent_mode() || vibrate_in_silent_mode_enabled()) {
429+ const auto haptic_mode = m_settings->alarm_haptic.get();
430+ if (haptic_mode == "pulse")
431+ haptic = std::make_shared<uin::Haptic>(uin::Haptic::MODE_PULSE, appointment.is_ubuntu_alarm());
432+ }
433 }
434
435 // show a notification...
436@@ -180,6 +184,9 @@
437 });
438 }
439
440+ b.set_show_notification_bubble(appointment.is_ubuntu_alarm() || calendar_bubbles_enabled());
441+ b.set_post_to_messaging_menu(appointment.is_ubuntu_alarm() || calendar_list_enabled());
442+
443 const auto key = m_engine->show(b);
444 if (key)
445 m_notifications.insert (key);
446@@ -187,15 +194,34 @@
447
448 private:
449
450- bool calendar_events_are_muted() const
451- {
452- for(const auto& app : m_settings->muted_apps.get()) {
453- if (app.first == "com.ubuntu.calendar") {
454- return true;
455- }
456- }
457-
458- return false;
459+ bool calendar_notifications_are_enabled() const
460+ {
461+ return m_settings->cal_notification_enabled.get();
462+ }
463+
464+ bool calendar_sounds_enabled() const
465+ {
466+ return m_settings->cal_notification_sounds.get();
467+ }
468+
469+ bool calendar_vibrations_enabled() const
470+ {
471+ return m_settings->cal_notification_vibrations.get();
472+ }
473+
474+ bool calendar_bubbles_enabled() const
475+ {
476+ return m_settings->cal_notification_bubbles.get();
477+ }
478+
479+ bool calendar_list_enabled() const
480+ {
481+ return m_settings->cal_notification_list.get();
482+ }
483+
484+ bool vibrate_in_silent_mode_enabled() const
485+ {
486+ return m_settings->vibrate_silent_mode.get();
487 }
488
489 static void on_sound_proxy_ready(GObject* /*source_object*/, GAsyncResult* res, gpointer gself)
490
491=== modified file 'tests/test-notification.cpp'
492--- tests/test-notification.cpp 2016-05-16 20:57:51 +0000
493+++ tests/test-notification.cpp 2016-07-04 23:46:11 +0000
494@@ -87,18 +87,16 @@
495 { false, true, false }
496 };
497
498- // combinatorial factor #4: system settings' notifications app blacklist
499- const std::set<std::pair<std::string,std::string>> blacklist_calendar { std::make_pair(std::string{"com.ubuntu.calendar"}, std::string{"calendar-app"}) };
500- const std::set<std::pair<std::string,std::string>> blacklist_empty;
501+ // combinatorial factor #4: system settings' notifications disabled
502 struct {
503- std::set<std::pair<std::string,std::string>> muted_apps; // apps that should not trigger notifications
504+ bool cal_notification_enabled; // calendar app can trigger notifications
505 std::set<Appointment::Type> expected_notify_called; // do we expect the notification to show?
506 std::set<Appointment::Type> expected_vibrate_called; // do we expect the phone to vibrate?
507- } test_muted_apps[] = {
508- { blacklist_empty, std::set<Appointment::Type>{ Appointment::Type::UBUNTU_ALARM, Appointment::Type::EVENT },
509- std::set<Appointment::Type>{ Appointment::Type::UBUNTU_ALARM, Appointment::Type::EVENT } },
510- { blacklist_calendar, std::set<Appointment::Type>{ Appointment::Type::UBUNTU_ALARM },
511- std::set<Appointment::Type>{ Appointment::Type::UBUNTU_ALARM } }
512+ } test_cal_disabled[] = {
513+ { true, std::set<Appointment::Type>{ Appointment::Type::UBUNTU_ALARM, Appointment::Type::EVENT },
514+ std::set<Appointment::Type>{ Appointment::Type::UBUNTU_ALARM, Appointment::Type::EVENT } },
515+ { false, std::set<Appointment::Type>{ Appointment::Type::UBUNTU_ALARM },
516+ std::set<Appointment::Type>{ Appointment::Type::UBUNTU_ALARM } }
517 };
518
519 for (const auto& test_appt : test_appts)
520@@ -107,20 +105,24 @@
521 {
522 for (const auto& test_vibes : test_other_vibrations)
523 {
524- for (const auto& test_muted : test_muted_apps)
525+ for (const auto& test_disabled : test_cal_disabled)
526 {
527 const bool expected_notify_called = test_appt.expected_notify_called
528 && test_vibes.expected_notify_called
529- && (test_muted.expected_notify_called.count(test_appt.appt.type) > 0)
530+ && (test_disabled.expected_notify_called.count(test_appt.appt.type) > 0)
531 && test_haptic.expected_notify_called;
532
533 const bool expected_vibrate_called = test_appt.expected_vibrate_called
534 && test_vibes.expected_vibrate_called
535- && (test_muted.expected_vibrate_called.count(test_appt.appt.type) > 0)
536+ && (test_disabled.expected_vibrate_called.count(test_appt.appt.type) > 0)
537 && test_haptic.expected_vibrate_called;
538
539- // set test case properties: blacklist
540- settings->muted_apps.set(test_muted.muted_apps);
541+ // set test case properties: cal_notification_enabled
542+ settings->cal_notification_enabled.set(test_disabled.cal_notification_enabled);
543+ settings->cal_notification_sounds.set(test_disabled.cal_notification_enabled);
544+ settings->cal_notification_vibrations.set(test_disabled.cal_notification_enabled);
545+ settings->cal_notification_bubbles.set(test_disabled.cal_notification_enabled);
546+ settings->cal_notification_list.set(test_disabled.cal_notification_enabled);
547
548 // set test case properties: haptic mode
549 settings->alarm_haptic.set(test_haptic.haptic_mode);
550@@ -228,6 +230,12 @@
551 };
552
553
554+ settings->cal_notification_enabled.set(true);
555+ settings->cal_notification_sounds.set(true);
556+ settings->cal_notification_vibrations.set(true);
557+ settings->cal_notification_bubbles.set(true);
558+ settings->cal_notification_list.set(true);
559+
560 // walk through the tests
561 for (const auto& test : tests)
562 {
563
564=== modified file 'tests/test-settings.cpp'
565--- tests/test-settings.cpp 2016-02-02 00:08:13 +0000
566+++ tests/test-settings.cpp 2016-07-04 23:46:11 +0000
567@@ -37,15 +37,15 @@
568
569 std::shared_ptr<LiveSettings> m_live;
570 std::shared_ptr<Settings> m_settings;
571- GSettings * m_gsettings;
572- GSettings * m_gsettings_cunh;
573+ GSettings * m_gsettings {};
574+ GSettings * m_gsettings_cal_notification {};
575
576 void SetUp() override
577 {
578 super::SetUp();
579
580 m_gsettings = g_settings_new(SETTINGS_INTERFACE);
581- m_gsettings_cunh = g_settings_new(SETTINGS_CUNH_SCHEMA_ID);
582+ m_gsettings_cal_notification = g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH);
583
584 m_live.reset(new LiveSettings);
585 m_settings = std::dynamic_pointer_cast<Settings>(m_live);
586@@ -53,7 +53,7 @@
587
588 void TearDown() override
589 {
590- g_clear_object(&m_gsettings_cunh);
591+ g_clear_object(&m_gsettings_cal_notification);
592 g_clear_object(&m_gsettings);
593 m_settings.reset();
594 m_live.reset();
595@@ -61,62 +61,62 @@
596 super::TearDown();
597 }
598
599- void TestBoolProperty(core::Property<bool>& property, const gchar* key)
600+ void TestBoolProperty(GSettings* gsettings, core::Property<bool>& property, const gchar* key)
601 {
602- EXPECT_EQ(g_settings_get_boolean(m_gsettings, key), property.get());
603- g_settings_set_boolean(m_gsettings, key, false);
604+ EXPECT_EQ(g_settings_get_boolean(gsettings, key), property.get());
605+ g_settings_set_boolean(gsettings, key, false);
606 EXPECT_FALSE(property.get());
607- g_settings_set_boolean(m_gsettings, key, true);
608+ g_settings_set_boolean(gsettings, key, true);
609 EXPECT_TRUE(property.get());
610
611 property.set(false);
612- EXPECT_FALSE(g_settings_get_boolean(m_gsettings, key));
613+ EXPECT_FALSE(g_settings_get_boolean(gsettings, key));
614 property.set(true);
615- EXPECT_TRUE(g_settings_get_boolean(m_gsettings, key));
616+ EXPECT_TRUE(g_settings_get_boolean(gsettings, key));
617 }
618
619- void TestStringProperty(core::Property<std::string>& property, const gchar* key)
620+ void TestStringProperty(GSettings* gsettings, core::Property<std::string>& property, const gchar* key)
621 {
622 gchar* tmp;
623 std::string str;
624
625- tmp = g_settings_get_string(m_gsettings, key);
626+ tmp = g_settings_get_string(gsettings, key);
627 EXPECT_EQ(tmp, property.get());
628 g_clear_pointer(&tmp, g_free);
629
630 str = "a";
631- g_settings_set_string(m_gsettings, key, str.c_str());
632+ g_settings_set_string(gsettings, key, str.c_str());
633 EXPECT_EQ(str, property.get());
634
635 str = "b";
636- g_settings_set_string(m_gsettings, key, str.c_str());
637+ g_settings_set_string(gsettings, key, str.c_str());
638 EXPECT_EQ(str, property.get());
639
640 str = "a";
641 property.set(str);
642- tmp = g_settings_get_string(m_gsettings, key);
643+ tmp = g_settings_get_string(gsettings, key);
644 EXPECT_EQ(str, tmp);
645 g_clear_pointer(&tmp, g_free);
646
647 str = "b";
648 property.set(str);
649- tmp = g_settings_get_string(m_gsettings, key);
650+ tmp = g_settings_get_string(gsettings, key);
651 EXPECT_EQ(str, tmp);
652 g_clear_pointer(&tmp, g_free);
653 }
654
655- void TestUIntProperty(core::Property<unsigned int>& property, const gchar* key)
656+ void TestUIntProperty(GSettings* gsettings, core::Property<unsigned int>& property, const gchar* key)
657 {
658- EXPECT_EQ(g_settings_get_uint(m_gsettings, key), property.get());
659+ EXPECT_EQ(g_settings_get_uint(gsettings, key), property.get());
660
661 unsigned int expected_values[] = { 1, 2, 3 };
662
663 // modify GSettings and confirm that the new value is propagated
664 for(const auto& expected_value : expected_values)
665 {
666- g_settings_set_uint(m_gsettings, key, expected_value);
667+ g_settings_set_uint(gsettings, key, expected_value);
668 EXPECT_EQ(expected_value, property.get());
669- EXPECT_EQ(expected_value, g_settings_get_uint(m_gsettings, key));
670+ EXPECT_EQ(expected_value, g_settings_get_uint(gsettings, key));
671 }
672
673 // modify the property and confirm that the new value is propagated
674@@ -124,7 +124,7 @@
675 {
676 property.set(expected_value);
677 EXPECT_EQ(expected_value, property.get());
678- EXPECT_EQ(expected_value, g_settings_get_uint(m_gsettings, key));
679+ EXPECT_EQ(expected_value, g_settings_get_uint(gsettings, key));
680 }
681 }
682 };
683@@ -140,32 +140,32 @@
684
685 TEST_F(SettingsFixture, BoolProperties)
686 {
687- TestBoolProperty(m_settings->show_seconds, SETTINGS_SHOW_SECONDS_S);
688- TestBoolProperty(m_settings->show_calendar, SETTINGS_SHOW_CALENDAR_S);
689- TestBoolProperty(m_settings->show_clock, SETTINGS_SHOW_CLOCK_S);
690- TestBoolProperty(m_settings->show_date, SETTINGS_SHOW_DATE_S);
691- TestBoolProperty(m_settings->show_day, SETTINGS_SHOW_DAY_S);
692- TestBoolProperty(m_settings->show_detected_location, SETTINGS_SHOW_DETECTED_S);
693- TestBoolProperty(m_settings->show_events, SETTINGS_SHOW_EVENTS_S);
694- TestBoolProperty(m_settings->show_locations, SETTINGS_SHOW_LOCATIONS_S);
695- TestBoolProperty(m_settings->show_week_numbers, SETTINGS_SHOW_WEEK_NUMBERS_S);
696- TestBoolProperty(m_settings->show_year, SETTINGS_SHOW_YEAR_S);
697+ TestBoolProperty(m_gsettings, m_settings->show_seconds, SETTINGS_SHOW_SECONDS_S);
698+ TestBoolProperty(m_gsettings, m_settings->show_calendar, SETTINGS_SHOW_CALENDAR_S);
699+ TestBoolProperty(m_gsettings, m_settings->show_clock, SETTINGS_SHOW_CLOCK_S);
700+ TestBoolProperty(m_gsettings, m_settings->show_date, SETTINGS_SHOW_DATE_S);
701+ TestBoolProperty(m_gsettings, m_settings->show_day, SETTINGS_SHOW_DAY_S);
702+ TestBoolProperty(m_gsettings, m_settings->show_detected_location, SETTINGS_SHOW_DETECTED_S);
703+ TestBoolProperty(m_gsettings, m_settings->show_events, SETTINGS_SHOW_EVENTS_S);
704+ TestBoolProperty(m_gsettings, m_settings->show_locations, SETTINGS_SHOW_LOCATIONS_S);
705+ TestBoolProperty(m_gsettings, m_settings->show_week_numbers, SETTINGS_SHOW_WEEK_NUMBERS_S);
706+ TestBoolProperty(m_gsettings, m_settings->show_year, SETTINGS_SHOW_YEAR_S);
707 }
708
709 TEST_F(SettingsFixture, UIntProperties)
710 {
711- TestUIntProperty(m_settings->alarm_duration, SETTINGS_ALARM_DURATION_S);
712- TestUIntProperty(m_settings->alarm_volume, SETTINGS_ALARM_VOLUME_S);
713- TestUIntProperty(m_settings->snooze_duration, SETTINGS_SNOOZE_DURATION_S);
714+ TestUIntProperty(m_gsettings, m_settings->alarm_duration, SETTINGS_ALARM_DURATION_S);
715+ TestUIntProperty(m_gsettings, m_settings->alarm_volume, SETTINGS_ALARM_VOLUME_S);
716+ TestUIntProperty(m_gsettings, m_settings->snooze_duration, SETTINGS_SNOOZE_DURATION_S);
717 }
718
719 TEST_F(SettingsFixture, StringProperties)
720 {
721- TestStringProperty(m_settings->custom_time_format, SETTINGS_CUSTOM_TIME_FORMAT_S);
722- TestStringProperty(m_settings->timezone_name, SETTINGS_TIMEZONE_NAME_S);
723- TestStringProperty(m_settings->alarm_sound, SETTINGS_ALARM_SOUND_S);
724- TestStringProperty(m_settings->calendar_sound, SETTINGS_CALENDAR_SOUND_S);
725- TestStringProperty(m_settings->alarm_haptic, SETTINGS_ALARM_HAPTIC_S);
726+ TestStringProperty(m_gsettings, m_settings->custom_time_format, SETTINGS_CUSTOM_TIME_FORMAT_S);
727+ TestStringProperty(m_gsettings, m_settings->timezone_name, SETTINGS_TIMEZONE_NAME_S);
728+ TestStringProperty(m_gsettings, m_settings->alarm_sound, SETTINGS_ALARM_SOUND_S);
729+ TestStringProperty(m_gsettings, m_settings->calendar_sound, SETTINGS_CALENDAR_SOUND_S);
730+ TestStringProperty(m_gsettings, m_settings->alarm_haptic, SETTINGS_ALARM_HAPTIC_S);
731 }
732
733 TEST_F(SettingsFixture, TimeFormatMode)
734@@ -229,36 +229,13 @@
735
736 TEST_F(SettingsFixture, MutedApps)
737 {
738- const auto key = SETTINGS_CUNH_BLACKLIST_S;
739-
740- struct {
741- std::string pkgname;
742- std::string appname;
743- } apps[] = {
744- { "", "ubuntu-system-settings" },
745- { "com.ubuntu.calendar", "calendar" },
746- { "com.ubuntu.developer.webapps.webapp-facebook", "webapp-facebook" },
747- { "com.ubuntu.reminders", "reminders" }
748- };
749- std::set<std::pair<std::string,std::string>> apps_set;
750- for (const auto& app : apps)
751- apps_set.insert(std::make_pair(app.pkgname, app.appname));
752-
753- // test that changing Settings is reflected in the schema
754- m_settings->muted_apps.set(apps_set);
755- auto v = g_settings_get_value(m_gsettings_cunh, key);
756- auto str = g_variant_print(v, true);
757- EXPECT_STREQ("[('', 'ubuntu-system-settings'), ('com.ubuntu.calendar', 'calendar'), ('com.ubuntu.developer.webapps.webapp-facebook', 'webapp-facebook'), ('com.ubuntu.reminders', 'reminders')]", str);
758- g_clear_pointer(&str, g_free);
759-
760- // test that clearing the schema clears the settings
761- g_settings_reset(m_gsettings_cunh, key);
762- EXPECT_EQ(0, m_settings->muted_apps.get().size());
763-
764- // test thst setting the schema updates the settings
765- g_settings_set_value(m_gsettings_cunh, key, v);
766- EXPECT_EQ(apps_set, m_settings->muted_apps.get());
767-
768- // cleanup
769- g_clear_pointer(&v, g_variant_unref);
770+ if (!m_gsettings_cal_notification) {
771+ return;
772+ }
773+
774+ TestBoolProperty(m_gsettings_cal_notification, m_settings->cal_notification_enabled, SETTINGS_NOTIFY_ENABLED_KEY);
775+ TestBoolProperty(m_gsettings_cal_notification, m_settings->cal_notification_sounds, SETTINGS_NOTIFY_SOUNDS_KEY);
776+ TestBoolProperty(m_gsettings_cal_notification, m_settings->cal_notification_vibrations, SETTINGS_NOTIFY_VIBRATIONS_KEY);
777+ TestBoolProperty(m_gsettings_cal_notification, m_settings->cal_notification_bubbles, SETTINGS_NOTIFY_BUBBLES_KEY);
778+ TestBoolProperty(m_gsettings_cal_notification, m_settings->cal_notification_list, SETTINGS_NOTIFY_LIST_KEY);
779 }
780
781=== modified file 'tests/test-sound.cpp'
782--- tests/test-sound.cpp 2016-05-14 17:20:00 +0000
783+++ tests/test-sound.cpp 2016-07-04 23:46:11 +0000
784@@ -59,6 +59,12 @@
785 auto sb = std::make_shared<unity::indicator::notifications::DefaultSoundBuilder>();
786 auto snap = create_snap(ne, sb, settings);
787
788+ settings->cal_notification_enabled.set(true);
789+ settings->cal_notification_sounds.set(true);
790+ settings->cal_notification_vibrations.set(true);
791+ settings->cal_notification_bubbles.set(true);
792+ settings->cal_notification_list.set(true);
793+
794 make_interactive();
795
796 // call the Snap Decision
797@@ -150,6 +156,12 @@
798 auto sb = std::make_shared<TestSoundBuilder>();
799 auto func = [this](const Appointment&, const Alarm&, const Snap::Response&){g_idle_add(quit_idle, loop);};
800
801+ settings->cal_notification_enabled.set(true);
802+ settings->cal_notification_sounds.set(true);
803+ settings->cal_notification_vibrations.set(true);
804+ settings->cal_notification_bubbles.set(true);
805+ settings->cal_notification_list.set(true);
806+
807 const struct {
808 Appointment appointment;
809 std::string expected_role;

Subscribers

People subscribed via source and target branches