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