Merge lp:~charlesk/indicator-datetime/15.04-lp-1505688-different-default-sounds-for-alarms-and-events into lp:indicator-datetime/15.04

Proposed by Charles Kerr on 2015-10-13
Status: Merged
Approved by: Antti Kaijanmäki on 2015-10-14
Approved revision: 430
Merged at revision: 422
Proposed branch: lp:~charlesk/indicator-datetime/15.04-lp-1505688-different-default-sounds-for-alarms-and-events
Merge into: lp:indicator-datetime/15.04
Diff against target: 654 lines (+206/-40)
22 files modified
CMakeLists.txt (+6/-0)
data/CMakeLists.txt (+5/-3)
data/com.canonical.indicator.datetime.gschema.xml.in.in (+8/-1)
debian/control (+2/-0)
include/datetime/settings-live.h (+1/-0)
include/datetime/settings-shared.h (+1/-0)
include/datetime/settings.h (+1/-0)
include/datetime/snap.h (+2/-0)
include/notifications/sound.h (+22/-0)
src/main.cpp (+2/-1)
src/settings-live.cpp (+14/-0)
src/snap.cpp (+15/-9)
tests/CMakeLists.txt (+3/-1)
tests/manual-test-snap.cpp (+2/-1)
tests/test-eds-ics-missing-trigger.cpp (+1/-1)
tests/test-eds-ics-missing-trigger.ics.in (+2/-2)
tests/test-eds-ics-nonrepeating-events.cpp (+1/-1)
tests/test-eds-ics-nonrepeating-events.ics.in (+1/-1)
tests/test-eds-ics-repeating-events.cpp (+8/-8)
tests/test-eds-ics-repeating-events.ics.in (+1/-1)
tests/test-settings.cpp (+1/-0)
tests/test-snap.cpp (+107/-10)
To merge this branch: bzr merge lp:~charlesk/indicator-datetime/15.04-lp-1505688-different-default-sounds-for-alarms-and-events
Reviewer Review Type Date Requested Status
Antti Kaijanmäki (community) Approve on 2015-10-14
PS Jenkins bot (community) continuous-integration Approve on 2015-10-14
dobey (community) 2015-10-13 Approve on 2015-10-13
Review via email: mp+274307@code.launchpad.net

Commit message

Use a different default sound for alarms and calendar events.

Description of the change

15.04 copy of https://code.launchpad.net/~charlesk/indicator-datetime/15.10-lp-1505688-different-default-sounds-for-alarms-and-events/+merge/274304

* Use a different default sound for alarms and calendar events.

* Define the default sounds once in cmake so that source files, schemas, and test datafiles don't all have to change each time the default value changes.

* Add a simple Sound factory so that we can use dependency injection to test notification sounds' properties

* Add unit tests to confirm the role and default sound of alarms and calendar events.

To post a comment you must log in.
dobey (dobey) :
review: Approve
dobey (dobey) :
review: Approve
Antti Kaijanmäki (kaijanmaki) wrote :

LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2014-08-19 04:03:38 +0000
3+++ CMakeLists.txt 2015-10-14 02:18:01 +0000
4@@ -9,6 +9,12 @@
5 add_definitions (-DGETTEXT_PACKAGE="${GETTEXT_PACKAGE}"
6 -DGNOMELOCALEDIR="${CMAKE_INSTALL_FULL_LOCALEDIR}")
7
8+set(ALARM_DEFAULT_SOUND "/usr/share/sounds/ubuntu/ringtones/Alarm clock.ogg")
9+set(CALENDAR_DEFAULT_SOUND "/usr/share/sounds/ubuntu/ringtones/Marimbach.ogg")
10+add_definitions(-DALARM_DEFAULT_SOUND="${ALARM_DEFAULT_SOUND}"
11+ -DCALENDAR_DEFAULT_SOUND="${CALENDAR_DEFAULT_SOUND}")
12+
13+
14 option (enable_tests "Build the package's automatic tests." ON)
15 option (enable_lcov "Generate lcov code coverage reports." ON)
16
17
18=== modified file 'data/CMakeLists.txt'
19--- data/CMakeLists.txt 2014-06-27 13:53:13 +0000
20+++ data/CMakeLists.txt 2015-10-14 02:18:01 +0000
21@@ -4,9 +4,11 @@
22
23 include (UseGSettings)
24 set (SCHEMA_NAME "com.canonical.indicator.datetime.gschema.xml")
25-set (SCHEMA_FILE "${CMAKE_CURRENT_BINARY_DIR}/${SCHEMA_NAME}")
26-set (SCHEMA_FILE_IN "${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_NAME}.in")
27-
28+set (SCHEMA_FILE_IN_IN "${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_NAME}.in.in")
29+set (SCHEMA_FILE_IN "${CMAKE_CURRENT_BINARY_DIR}/${SCHEMA_NAME}.in")
30+set (SCHEMA_FILE "${CMAKE_CURRENT_BINARY_DIR}/${SCHEMA_NAME}")
31+# generate the .xml.in file so cmake constants are included
32+configure_file(${SCHEMA_FILE_IN_IN} ${SCHEMA_FILE_IN})
33 # generate the .xml file using intltool
34 set (ENV{LC_ALL} "C")
35 execute_process (COMMAND intltool-merge -quiet --xml-style --utf8 --no-translations "${SCHEMA_FILE_IN}" "${SCHEMA_FILE}")
36
37=== renamed file 'data/com.canonical.indicator.datetime.gschema.xml.in' => 'data/com.canonical.indicator.datetime.gschema.xml.in.in'
38--- data/com.canonical.indicator.datetime.gschema.xml.in 2015-10-07 14:07:15 +0000
39+++ data/com.canonical.indicator.datetime.gschema.xml.in.in 2015-10-14 02:18:01 +0000
40@@ -131,8 +131,15 @@
41 Two modes are currently supported: 'pulse', 'none'.
42 </_description>
43 </key>
44+ <key name="calendar-default-sound" type="s">
45+ <default>'@CALENDAR_DEFAULT_SOUND@'</default>
46+ <_summary>The calendar's default sound file.</_summary>
47+ <_description>
48+ If a calendar or reminder event doesn't specify its own sound file, this file will be used as the fallback sound.
49+ </_description>
50+ </key>
51 <key name="alarm-default-sound" type="s">
52- <default>'/usr/share/sounds/ubuntu/ringtones/Alarm clock.ogg'</default>
53+ <default>'@ALARM_DEFAULT_SOUND@'</default>
54 <_summary>The alarm's default sound file.</_summary>
55 <_description>
56 If an alarm doesn't specify its own sound file, this file will be used as the fallback sound.
57
58=== modified file 'debian/control'
59--- debian/control 2015-04-06 14:25:59 +0000
60+++ debian/control 2015-10-14 02:18:01 +0000
61@@ -27,6 +27,8 @@
62 # for running live EDS tests:
63 evolution-data-server,
64 gvfs-daemons,
65+# for phone alarm/calendar notification sound tests:
66+ ubuntu-touch-sounds,
67 Standards-Version: 3.9.3
68 Homepage: https://launchpad.net/indicator-datetime
69 # If you aren't a member of ~indicator-applet-developers but need to upload
70
71=== modified file 'include/datetime/settings-live.h'
72--- include/datetime/settings-live.h 2014-09-02 15:37:03 +0000
73+++ include/datetime/settings-live.h 2015-10-14 02:18:01 +0000
74@@ -55,6 +55,7 @@
75 void update_show_year();
76 void update_time_format_mode();
77 void update_timezone_name();
78+ void update_calendar_sound();
79 void update_alarm_sound();
80 void update_alarm_volume();
81 void update_alarm_duration();
82
83=== modified file 'include/datetime/settings-shared.h'
84--- include/datetime/settings-shared.h 2014-09-02 15:37:03 +0000
85+++ include/datetime/settings-shared.h 2015-10-14 02:18:01 +0000
86@@ -45,6 +45,7 @@
87 #define SETTINGS_SHOW_DETECTED_S "show-auto-detected-location"
88 #define SETTINGS_LOCATIONS_S "locations"
89 #define SETTINGS_TIMEZONE_NAME_S "timezone-name"
90+#define SETTINGS_CALENDAR_SOUND_S "calendar-default-sound"
91 #define SETTINGS_ALARM_SOUND_S "alarm-default-sound"
92 #define SETTINGS_ALARM_VOLUME_S "alarm-default-volume"
93 #define SETTINGS_ALARM_DURATION_S "alarm-duration-minutes"
94
95=== modified file 'include/datetime/settings.h'
96--- include/datetime/settings.h 2014-09-02 15:37:03 +0000
97+++ include/datetime/settings.h 2015-10-14 02:18:01 +0000
98@@ -56,6 +56,7 @@
99 core::Property<bool> show_year;
100 core::Property<TimeFormatMode> time_format_mode;
101 core::Property<std::string> timezone_name;
102+ core::Property<std::string> calendar_sound;
103 core::Property<std::string> alarm_sound;
104 core::Property<std::string> alarm_haptic;
105 core::Property<unsigned int> alarm_volume;
106
107=== modified file 'include/datetime/snap.h'
108--- include/datetime/snap.h 2015-03-31 23:54:04 +0000
109+++ include/datetime/snap.h 2015-10-14 02:18:01 +0000
110@@ -24,6 +24,7 @@
111 #include <datetime/settings.h>
112
113 #include <notifications/notifications.h>
114+#include <notifications/sound.h>
115
116 #include <functional>
117 #include <memory>
118@@ -39,6 +40,7 @@
119 {
120 public:
121 Snap(const std::shared_ptr<unity::indicator::notifications::Engine>& engine,
122+ const std::shared_ptr<unity::indicator::notifications::SoundBuilder>& sound_builder,
123 const std::shared_ptr<const Settings>& settings);
124 virtual ~Snap();
125
126
127=== modified file 'include/notifications/sound.h'
128--- include/notifications/sound.h 2015-01-22 01:57:59 +0000
129+++ include/notifications/sound.h 2015-10-14 02:18:01 +0000
130@@ -53,6 +53,28 @@
131 ****
132 ***/
133
134+class SoundBuilder
135+{
136+public:
137+ SoundBuilder() =default;
138+ virtual ~SoundBuilder() =default;
139+ virtual std::shared_ptr<Sound> create(const std::string& role, const std::string& uri, unsigned int volume, bool loop) =0;
140+};
141+
142+class DefaultSoundBuilder: public SoundBuilder
143+{
144+public:
145+ DefaultSoundBuilder() =default;
146+ ~DefaultSoundBuilder() =default;
147+ virtual std::shared_ptr<Sound> create(const std::string& role, const std::string& uri, unsigned int volume, bool loop) override {
148+ return std::make_shared<Sound>(role, uri, volume, loop);
149+ }
150+};
151+
152+/***
153+****
154+***/
155+
156 } // namespace notifications
157 } // namespace indicator
158 } // namespace unity
159
160=== modified file 'src/main.cpp'
161--- src/main.cpp 2015-04-03 18:11:39 +0000
162+++ src/main.cpp 2015-10-14 02:18:01 +0000
163@@ -136,7 +136,8 @@
164 // set up the snap decisions
165 auto snooze_planner = std::make_shared<SnoozePlanner>(state->settings, state->clock);
166 auto notification_engine = std::make_shared<uin::Engine>("indicator-datetime-service");
167- std::unique_ptr<Snap> snap (new Snap(notification_engine, state->settings));
168+ auto sound_builder = std::make_shared<uin::DefaultSoundBuilder>();
169+ std::unique_ptr<Snap> snap (new Snap(notification_engine, sound_builder, state->settings));
170 auto alarm_queue = create_simple_alarm_queue(state->clock, snooze_planner, engine, timezone_);
171 auto on_snooze = [snooze_planner](const Appointment& appointment, const Alarm& alarm) {
172 snooze_planner->add(appointment, alarm);
173
174=== modified file 'src/settings-live.cpp'
175--- src/settings-live.cpp 2014-09-02 15:37:03 +0000
176+++ src/settings-live.cpp 2015-10-14 02:18:01 +0000
177@@ -52,6 +52,7 @@
178 update_show_year();
179 update_time_format_mode();
180 update_timezone_name();
181+ update_calendar_sound();
182 update_alarm_sound();
183 update_alarm_volume();
184 update_alarm_duration();
185@@ -121,6 +122,10 @@
186 g_settings_set_string(m_settings, SETTINGS_TIMEZONE_NAME_S, value.c_str());
187 });
188
189+ calendar_sound.changed().connect([this](const std::string& value){
190+ g_settings_set_string(m_settings, SETTINGS_CALENDAR_SOUND_S, value.c_str());
191+ });
192+
193 alarm_sound.changed().connect([this](const std::string& value){
194 g_settings_set_string(m_settings, SETTINGS_ALARM_SOUND_S, value.c_str());
195 });
196@@ -230,6 +235,13 @@
197 g_free(val);
198 }
199
200+void LiveSettings::update_calendar_sound()
201+{
202+ auto val = g_settings_get_string(m_settings, SETTINGS_CALENDAR_SOUND_S);
203+ calendar_sound.set(val);
204+ g_free(val);
205+}
206+
207 void LiveSettings::update_alarm_sound()
208 {
209 auto val = g_settings_get_string(m_settings, SETTINGS_ALARM_SOUND_S);
210@@ -300,6 +312,8 @@
211 update_show_detected_locations();
212 else if (key == SETTINGS_TIMEZONE_NAME_S)
213 update_timezone_name();
214+ else if (key == SETTINGS_CALENDAR_SOUND_S)
215+ update_calendar_sound();
216 else if (key == SETTINGS_ALARM_SOUND_S)
217 update_alarm_sound();
218 else if (key == SETTINGS_ALARM_VOLUME_S)
219
220=== modified file 'src/snap.cpp'
221--- src/snap.cpp 2015-10-07 14:07:15 +0000
222+++ src/snap.cpp 2015-10-14 02:18:01 +0000
223@@ -52,8 +52,10 @@
224 public:
225
226 Impl(const std::shared_ptr<unity::indicator::notifications::Engine>& engine,
227+ const std::shared_ptr<unity::indicator::notifications::SoundBuilder>& sound_builder,
228 const std::shared_ptr<const Settings>& settings):
229 m_engine(engine),
230+ m_sound_builder(sound_builder),
231 m_settings(settings),
232 m_cancellable(g_cancellable_new())
233 {
234@@ -97,10 +99,10 @@
235 if (appointment.is_ubuntu_alarm() || !silent_mode()) {
236 // create the sound.
237 const auto role = appointment.is_ubuntu_alarm() ? "alarm" : "alert";
238- const auto uri = get_alarm_uri(alarm, m_settings);
239+ const auto uri = get_alarm_uri(appointment, alarm, m_settings);
240 const auto volume = m_settings->alarm_volume.get();
241 const bool loop = interactive;
242- sound = std::make_shared<uin::Sound>(role, uri, volume, loop);
243+ sound = m_sound_builder->create(role, uri, volume, loop);
244 }
245
246 // create the haptic feedback...
247@@ -189,14 +191,16 @@
248 && (accounts_service_sound_get_other_vibrate(m_accounts_service_sound_proxy));
249 }
250
251- std::string get_alarm_uri(const Alarm& alarm,
252+ std::string get_alarm_uri(const Appointment& appointment,
253+ const Alarm& alarm,
254 const std::shared_ptr<const Settings>& settings) const
255 {
256- const char* FALLBACK {"/usr/share/sounds/ubuntu/ringtones/Alarm clock.ogg"};
257-
258- const std::string candidates[] = { alarm.audio_url,
259- settings->alarm_sound.get(),
260- FALLBACK };
261+ const auto is_alarm = appointment.is_ubuntu_alarm();
262+ const std::string candidates[] = {
263+ alarm.audio_url,
264+ is_alarm ? settings->alarm_sound.get() : settings->calendar_sound.get(),
265+ is_alarm ? ALARM_DEFAULT_SOUND : CALENDAR_DEFAULT_SOUND
266+ };
267
268 std::string uri;
269
270@@ -223,6 +227,7 @@
271 }
272
273 const std::shared_ptr<unity::indicator::notifications::Engine> m_engine;
274+ const std::shared_ptr<unity::indicator::notifications::SoundBuilder> m_sound_builder;
275 const std::shared_ptr<const Settings> m_settings;
276 std::set<int> m_notifications;
277 GCancellable * m_cancellable {nullptr};
278@@ -234,8 +239,9 @@
279 ***/
280
281 Snap::Snap(const std::shared_ptr<unity::indicator::notifications::Engine>& engine,
282+ const std::shared_ptr<unity::indicator::notifications::SoundBuilder>& sound_builder,
283 const std::shared_ptr<const Settings>& settings):
284- impl(new Impl(engine, settings))
285+ impl(new Impl(engine, sound_builder, settings))
286 {
287 }
288
289
290=== modified file 'tests/CMakeLists.txt'
291--- tests/CMakeLists.txt 2015-07-10 17:29:12 +0000
292+++ tests/CMakeLists.txt 2015-10-14 02:18:01 +0000
293@@ -73,6 +73,8 @@
294
295 function(add_eds_ics_test_by_name name)
296 set (TEST_NAME ${name})
297+ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${TEST_NAME}.ics.in"
298+ "${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}.ics")
299 add_executable(${TEST_NAME} ${TEST_NAME}.cpp gschemas.compiled)
300 target_link_libraries (${TEST_NAME} indicatordatetimeservice gtest ${DBUSTEST_LIBRARIES} ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBS})
301 add_test (${TEST_NAME}
302@@ -81,7 +83,7 @@
303 ${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME} # arg2: test executable path
304 ${TEST_NAME} # arg3: test name
305 ${CMAKE_CURRENT_SOURCE_DIR}/test-eds-ics-config-files # arg4: base directory for config file template
306- ${CMAKE_CURRENT_SOURCE_DIR}/${TEST_NAME}.ics) # arg5: the ical file for this test
307+ ${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}.ics) # arg5: the ical file for this test
308 endfunction()
309 add_eds_ics_test_by_name(test-eds-ics-all-day-events)
310 add_eds_ics_test_by_name(test-eds-ics-repeating-events)
311
312=== modified file 'tests/manual-test-snap.cpp'
313--- tests/manual-test-snap.cpp 2015-04-05 22:27:52 +0000
314+++ tests/manual-test-snap.cpp 2015-10-14 02:18:01 +0000
315@@ -92,7 +92,8 @@
316 settings->alarm_volume.set(volume);
317
318 auto notification_engine = std::make_shared<uin::Engine>("indicator-datetime-service");
319- Snap snap (notification_engine, settings);
320+ auto sound_builder = std::make_shared<uin::DefaultSoundBuilder>();
321+ Snap snap (notification_engine, sound_builder, settings);
322 snap(a, a.alarms.front(), on_snooze, on_ok);
323 g_main_loop_run(loop);
324
325
326=== renamed file 'tests/test-eds-ics-all-day-events.ics' => 'tests/test-eds-ics-all-day-events.ics.in'
327=== modified file 'tests/test-eds-ics-missing-trigger.cpp'
328--- tests/test-eds-ics-missing-trigger.cpp 2015-10-07 14:07:15 +0000
329+++ tests/test-eds-ics-missing-trigger.cpp 2015-10-14 02:18:01 +0000
330@@ -77,7 +77,7 @@
331 a.begin = DateTime { gtz, 2015, 6, 18, 10, 0, 0};
332 a.end = a.begin;
333 a.alarms.resize(1);
334- a.alarms[0].audio_url = "file:///usr/share/sounds/ubuntu/ringtones/Alarm clock.ogg";
335+ a.alarms[0].audio_url = "file://" ALARM_DEFAULT_SOUND;
336 a.alarms[0].time = a.begin;
337 a.alarms[0].text = a.summary;
338 expected.push_back(a);
339
340=== renamed file 'tests/test-eds-ics-missing-trigger.ics' => 'tests/test-eds-ics-missing-trigger.ics.in'
341--- tests/test-eds-ics-missing-trigger.ics 2015-10-07 14:07:15 +0000
342+++ tests/test-eds-ics-missing-trigger.ics.in 2015-10-14 02:18:01 +0000
343@@ -14,7 +14,7 @@
344 BEGIN:VALARM
345 X-EVOLUTION-ALARM-UID:20150617T211838Z-6217-32011-2036-2@ubuntu-phablet
346 ACTION:AUDIO
347-ATTACH:file:///usr/share/sounds/ubuntu/ringtones/Alarm clock.ogg
348+ATTACH:file://@ALARM_DEFAULT_SOUND@
349 END:VALARM
350 BEGIN:VALARM
351 X-EVOLUTION-ALARM-UID:20150617T211838Z-6217-32011-2036-3@ubuntu-phablet
352@@ -34,7 +34,7 @@
353 BEGIN:VALARM
354 X-EVOLUTION-ALARM-UID:20150617T211913Z-6217-32011-2036-6@ubuntu-phablet
355 ACTION:AUDIO
356-ATTACH:file:///usr/share/sounds/ubuntu/ringtones/Alarm clock.ogg
357+ATTACH:file://@ALARM_DEFAULT_SOUND@
358 END:VALARM
359 BEGIN:VALARM
360 X-EVOLUTION-ALARM-UID:20150617T211913Z-6217-32011-2036-7@ubuntu-phablet
361
362=== modified file 'tests/test-eds-ics-nonrepeating-events.cpp'
363--- tests/test-eds-ics-nonrepeating-events.cpp 2015-10-07 14:07:15 +0000
364+++ tests/test-eds-ics-nonrepeating-events.cpp 2015-10-14 02:18:01 +0000
365@@ -73,7 +73,7 @@
366 expected_appt.color = "#becedd";
367 expected_appt.summary = "Alarm";
368 std::array<Alarm,1> expected_alarms = {
369- Alarm({"Alarm", "file:///usr/share/sounds/ubuntu/ringtones/Alarm clock.ogg", DateTime(gtz,2015,5,20,20,00,0)})
370+ Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,20,20,00,0)})
371 };
372
373 // compare it to what we actually loaded...
374
375=== renamed file 'tests/test-eds-ics-nonrepeating-events.ics' => 'tests/test-eds-ics-nonrepeating-events.ics.in'
376--- tests/test-eds-ics-nonrepeating-events.ics 2015-10-07 14:07:15 +0000
377+++ tests/test-eds-ics-nonrepeating-events.ics.in 2015-10-14 02:18:01 +0000
378@@ -14,7 +14,7 @@
379 BEGIN:VALARM
380 X-EVOLUTION-ALARM-UID:20150520T223932Z-22506-32011-1771-2@ubuntu-phablet
381 ACTION:AUDIO
382-ATTACH:file:///usr/share/sounds/ubuntu/ringtones/Alarm clock.ogg
383+ATTACH:file://@ALARM_DEFAULT_SOUND@
384 TRIGGER;VALUE=DURATION;RELATED=START:PT0S
385 END:VALARM
386 BEGIN:VALARM
387
388=== modified file 'tests/test-eds-ics-repeating-events.cpp'
389--- tests/test-eds-ics-repeating-events.cpp 2015-10-07 14:07:15 +0000
390+++ tests/test-eds-ics-repeating-events.cpp 2015-10-14 02:18:01 +0000
391@@ -73,14 +73,14 @@
392 expected_appt.color = "#becedd";
393 expected_appt.summary = "Alarm";
394 std::array<Alarm,8> expected_alarms = {
395- Alarm({"Alarm", "file:///usr/share/sounds/ubuntu/ringtones/Alarm clock.ogg", DateTime(gtz,2015,5, 8,16,40,0)}),
396- Alarm({"Alarm", "file:///usr/share/sounds/ubuntu/ringtones/Alarm clock.ogg", DateTime(gtz,2015,5,15,16,40,0)}),
397- Alarm({"Alarm", "file:///usr/share/sounds/ubuntu/ringtones/Alarm clock.ogg", DateTime(gtz,2015,5,22,16,40,0)}),
398- Alarm({"Alarm", "file:///usr/share/sounds/ubuntu/ringtones/Alarm clock.ogg", DateTime(gtz,2015,5,29,16,40,0)}),
399- Alarm({"Alarm", "file:///usr/share/sounds/ubuntu/ringtones/Alarm clock.ogg", DateTime(gtz,2015,6, 5,16,40,0)}),
400- Alarm({"Alarm", "file:///usr/share/sounds/ubuntu/ringtones/Alarm clock.ogg", DateTime(gtz,2015,6,12,16,40,0)}),
401- Alarm({"Alarm", "file:///usr/share/sounds/ubuntu/ringtones/Alarm clock.ogg", DateTime(gtz,2015,6,19,16,40,0)}),
402- Alarm({"Alarm", "file:///usr/share/sounds/ubuntu/ringtones/Alarm clock.ogg", DateTime(gtz,2015,6,26,16,40,0)})
403+ Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5, 8,16,40,0)}),
404+ Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,15,16,40,0)}),
405+ Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,22,16,40,0)}),
406+ Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,29,16,40,0)}),
407+ Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6, 5,16,40,0)}),
408+ Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6,12,16,40,0)}),
409+ Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6,19,16,40,0)}),
410+ Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6,26,16,40,0)})
411 };
412
413 // compare it to what we actually loaded...
414
415=== renamed file 'tests/test-eds-ics-repeating-events.ics' => 'tests/test-eds-ics-repeating-events.ics.in'
416--- tests/test-eds-ics-repeating-events.ics 2015-10-07 14:07:15 +0000
417+++ tests/test-eds-ics-repeating-events.ics.in 2015-10-14 02:18:01 +0000
418@@ -15,7 +15,7 @@
419 BEGIN:VALARM
420 X-EVOLUTION-ALARM-UID:20150507T211449Z-4262-32011-1418-2@ubuntu-phablet
421 ACTION:AUDIO
422-ATTACH:file:///usr/share/sounds/ubuntu/ringtones/Alarm clock.ogg
423+ATTACH:file://@ALARM_DEFAULT_SOUND@
424 TRIGGER;VALUE=DURATION;RELATED=START:PT0S
425 END:VALARM
426 BEGIN:VALARM
427
428=== renamed file 'tests/test-eds-ics-repeating-valarms.ics' => 'tests/test-eds-ics-repeating-valarms.ics.in'
429=== renamed file 'tests/test-eds-ics-tzids-2.ics' => 'tests/test-eds-ics-tzids-2.ics.in'
430=== renamed file 'tests/test-eds-ics-tzids.ics' => 'tests/test-eds-ics-tzids.ics.in'
431=== modified file 'tests/test-settings.cpp'
432--- tests/test-settings.cpp 2014-09-17 16:51:51 +0000
433+++ tests/test-settings.cpp 2015-10-14 02:18:01 +0000
434@@ -160,6 +160,7 @@
435 TestStringProperty(m_settings->custom_time_format, SETTINGS_CUSTOM_TIME_FORMAT_S);
436 TestStringProperty(m_settings->timezone_name, SETTINGS_TIMEZONE_NAME_S);
437 TestStringProperty(m_settings->alarm_sound, SETTINGS_ALARM_SOUND_S);
438+ TestStringProperty(m_settings->calendar_sound, SETTINGS_CALENDAR_SOUND_S);
439 TestStringProperty(m_settings->alarm_haptic, SETTINGS_ALARM_HAPTIC_S);
440 }
441
442
443=== modified file 'tests/test-snap.cpp'
444--- tests/test-snap.cpp 2015-04-08 23:48:24 +0000
445+++ tests/test-snap.cpp 2015-10-14 02:18:01 +0000
446@@ -34,6 +34,8 @@
447
448 using namespace unity::indicator::datetime;
449
450+namespace uin = unity::indicator::notifications;
451+
452 #include "glib-fixture.h"
453
454 /***
455@@ -92,6 +94,7 @@
456 static constexpr char const * PROP_SILENT_MODE {"SilentMode"};
457
458 Appointment appt;
459+ Appointment ualarm;
460 GDBusConnection * system_bus = nullptr;
461 GDBusConnection * session_bus = nullptr;
462 DbusTestService * service = nullptr;
463@@ -113,15 +116,25 @@
464
465 super::SetUp();
466
467- // init the Appointment
468+ // init an Appointment
469 appt.color = "green";
470- appt.summary = "Alarm";
471+ appt.summary = "Christmas";
472 appt.uid = "D4B57D50247291478ED31DED17FF0A9838DED402";
473 appt.type = Appointment::EVENT;
474 const auto christmas = DateTime::Local(2015,12,25,0,0,0);
475 appt.begin = christmas.start_of_day();
476 appt.end = christmas.end_of_day();
477- appt.alarms.push_back(Alarm{"Alarm Text", "", appt.begin});
478+ appt.alarms.push_back(Alarm{"Ho Ho Ho!", "", appt.begin});
479+
480+ // init an Ubuntu Alarm
481+ ualarm.color = "red";
482+ ualarm.summary = "Wakeup";
483+ ualarm.uid = "E4B57D50247291478ED31DED17FF0A9838DED403";
484+ ualarm.type = Appointment::UBUNTU_ALARM;
485+ const auto tomorrow = DateTime::NowLocal().add_days(1);
486+ ualarm.begin = tomorrow;
487+ ualarm.end = tomorrow;
488+ ualarm.alarms.push_back(Alarm{"It's Tomorrow!", "", appt.begin});
489
490 service = dbus_test_service_new(nullptr);
491
492@@ -360,6 +373,15 @@
493 &error);
494 g_assert_no_error (error);
495 }
496+
497+ std::shared_ptr<Snap> create_snap(const std::shared_ptr<uin::Engine>& ne,
498+ const std::shared_ptr<uin::SoundBuilder>& sb,
499+ const std::shared_ptr<Settings>& settings)
500+ {
501+ auto snap = std::make_shared<Snap>(ne, sb, settings);
502+ wait_msec(100); // wait a moment for the Snap to finish its async dbus bootstrapping
503+ return snap;
504+ }
505 };
506
507 /***
508@@ -381,13 +403,14 @@
509 auto settings = std::make_shared<Settings>();
510 settings->alarm_duration.set(duration_minutes);
511 auto ne = std::make_shared<unity::indicator::notifications::Engine>(APP_NAME);
512- Snap snap (ne, settings);
513+ auto sb = std::make_shared<unity::indicator::notifications::DefaultSoundBuilder>();
514+ auto snap = create_snap(ne, sb, settings);
515
516 make_interactive();
517
518 // call the Snap Decision
519 auto func = [this](const Appointment&, const Alarm&){g_idle_add(quit_idle, loop);};
520- snap(appt, appt.alarms.front(), func, func);
521+ (*snap)(appt, appt.alarms.front(), func, func);
522
523 // confirm that Notify got called once
524 guint len = 0;
525@@ -431,7 +454,8 @@
526 {
527 auto settings = std::make_shared<Settings>();
528 auto ne = std::make_shared<unity::indicator::notifications::Engine>(APP_NAME);
529- auto snap = new Snap (ne, settings);
530+ auto sb = std::make_shared<unity::indicator::notifications::DefaultSoundBuilder>();
531+ auto snap = create_snap(ne, sb, settings);
532
533 make_interactive();
534
535@@ -458,7 +482,7 @@
536
537 // force-close the snap
538 wait_msec(100);
539- delete snap;
540+ snap.reset();
541 wait_msec(100);
542
543 // confirm that sleep got uninhibted
544@@ -486,7 +510,8 @@
545 {
546 auto settings = std::make_shared<Settings>();
547 auto ne = std::make_shared<unity::indicator::notifications::Engine>(APP_NAME);
548- auto snap = new Snap (ne, settings);
549+ auto sb = std::make_shared<unity::indicator::notifications::DefaultSoundBuilder>();
550+ auto snap = create_snap(ne, sb, settings);
551
552 make_interactive();
553
554@@ -507,7 +532,7 @@
555
556 // force-close the snap
557 wait_msec(100);
558- delete snap;
559+ snap.reset();
560 wait_msec(100);
561
562 // confirm that sleep got uninhibted
563@@ -527,6 +552,7 @@
564 {
565 auto settings = std::make_shared<Settings>();
566 auto ne = std::make_shared<unity::indicator::notifications::Engine>(APP_NAME);
567+ auto sb = std::make_shared<unity::indicator::notifications::DefaultSoundBuilder>();
568 auto func = [this](const Appointment&, const Alarm&){g_idle_add(quit_idle, loop);};
569 GError * error = nullptr;
570
571@@ -541,7 +567,7 @@
572 { true, "pulse", true }
573 };
574
575- auto snap = std::make_shared<Snap>(ne, settings);
576+ auto snap = create_snap(ne, sb, settings);
577
578 for(const auto& test_case : test_cases)
579 {
580@@ -570,3 +596,74 @@
581 EXPECT_EQ(test_case.expected_vibrate_called, vibrate_called);
582 }
583 }
584+
585+/***
586+****
587+***/
588+
589+/**
590+ * A DefaultSoundBuilder wrapper which remembers the parameters of the last sound created.
591+ */
592+class TestSoundBuilder: public uin::SoundBuilder
593+{
594+public:
595+ TestSoundBuilder() =default;
596+ ~TestSoundBuilder() =default;
597+
598+ virtual std::shared_ptr<uin::Sound> create(const std::string& role, const std::string& uri, unsigned int volume, bool loop) override {
599+ m_role = role;
600+ m_uri = uri;
601+ m_volume = volume;
602+ m_loop = loop;
603+ return m_impl.create(role, uri, volume, loop);
604+ }
605+
606+ const std::string& role() { return m_role; }
607+ const std::string& uri() { return m_uri; }
608+ unsigned int volume() { return m_volume; }
609+ bool loop() { return m_loop; }
610+
611+private:
612+ std::string m_role;
613+ std::string m_uri;
614+ unsigned int m_volume;
615+ bool m_loop;
616+ uin::DefaultSoundBuilder m_impl;
617+};
618+
619+std::string path_to_uri(const std::string& path)
620+{
621+ auto file = g_file_new_for_path(path.c_str());
622+ auto uri_cstr = g_file_get_uri(file);
623+ std::string uri = uri_cstr;
624+ g_free(uri_cstr);
625+ g_clear_pointer(&file, g_object_unref);
626+ return uri;
627+}
628+
629+TEST_F(SnapFixture,DefaultSounds)
630+{
631+ auto settings = std::make_shared<Settings>();
632+ auto ne = std::make_shared<uin::Engine>(APP_NAME);
633+ auto sb = std::make_shared<TestSoundBuilder>();
634+ auto func = [this](const Appointment&, const Alarm&){g_idle_add(quit_idle, loop);};
635+
636+ const struct {
637+ Appointment appointment;
638+ std::string expected_role;
639+ std::string expected_uri;
640+ } test_cases[] = {
641+ { ualarm, "alarm", path_to_uri(ALARM_DEFAULT_SOUND) },
642+ { appt, "alert", path_to_uri(CALENDAR_DEFAULT_SOUND) }
643+ };
644+
645+ auto snap = create_snap(ne, sb, settings);
646+
647+ for(const auto& test_case : test_cases)
648+ {
649+ (*snap)(test_case.appointment, test_case.appointment.alarms.front(), func, func);
650+ wait_msec(100);
651+ EXPECT_EQ(test_case.expected_uri, sb->uri());
652+ EXPECT_EQ(test_case.expected_role, sb->role());
653+ }
654+}

Subscribers

People subscribed via source and target branches