Merge lp:~charlesk/indicator-power/lp-1470767-low-battery-sound into lp:indicator-power/15.10
- lp-1470767-low-battery-sound
- Merge into trunk.15.10
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Ted Gould | ||||
Approved revision: | 314 | ||||
Merged at revision: | 291 | ||||
Proposed branch: | lp:~charlesk/indicator-power/lp-1470767-low-battery-sound | ||||
Merge into: | lp:indicator-power/15.10 | ||||
Diff against target: |
1500 lines (+939/-31) 20 files modified
CMakeLists.txt (+3/-1) data/CMakeLists.txt (+9/-0) debian/control (+3/-0) src/CMakeLists.txt (+9/-1) src/datafiles.c (+71/-0) src/datafiles.h (+37/-0) src/main.c (+14/-6) src/notifier.c (+150/-4) src/notifier.h (+6/-2) src/service.c (+50/-9) src/service.h (+6/-1) src/sound-player-gst.c (+173/-0) src/sound-player-gst.h (+70/-0) src/sound-player.c (+45/-0) src/sound-player.h (+72/-0) tests/CMakeLists.txt (+14/-2) tests/glib-fixture.h (+1/-1) tests/sound-player-mock.c (+94/-0) tests/sound-player-mock.h (+75/-0) tests/test-notify.cc (+37/-4) |
||||
To merge this branch: | bzr merge lp:~charlesk/indicator-power/lp-1470767-low-battery-sound | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Approve | |
Ted Gould (community) | Approve | ||
Review via email: mp+281460@code.launchpad.net |
Commit message
Play a 'low battery' sound when the low battery notification is shown.
Description of the change
Play a 'low battery' sound when the low battery notification is shown.
Why so many LOC for this simple feature? Here's what changed:
1. Add dependency on GST, copy gst code from indicator-datetime code
to set the playing sound's role to "alert"
2. Install the low battery sound into CMAKE_INSTALL_
3. Create a SoundPlayer interface so a mock version can be plugged
in during unit tests instead of poking gst. (This is most of the LOC
since indicator-power is written in C)
4. Change startup steps so that dependency injection can be used
on the Notifier class to specify the SoundPlayer.
5. Add an AccountsServices DBus proxy so we can honor silent mode
6. Update tests
- 301. By charles kerr <email address hidden>
-
fix another touched file's copyright date
- 302. By charles kerr <email address hidden>
-
create a data/sounds/ directory in the repo to hold Low battery.ogg
We may be adding sounds for when we transition to battery
charging/discharging, so set up a sounds/ directory now. - 303. By charles kerr <email address hidden>
-
use a symbolic constant for the low battery sound's filename
- 304. By charles kerr <email address hidden>
-
honor com.ubuntu.
touch.AccountsS ervice. Sound.SilentMod e - 305. By charles kerr <email address hidden>
-
update copyright dates on changed files (again)
- 306. By charles kerr <email address hidden>
-
handle service_
set_notifier( NULL) gracefully
Ted Gould (ted) wrote : | # |
- 307. By Charles Kerr
-
add 'bzr fixes' metainfo to the branch
- 308. By Charles Kerr
-
add build-dep to accountsservice
-ubuntu- schemas instead of bundling com.ubuntu. touch.AccountsS ervice. Sound.xml into our source tree - 309. By Charles Kerr
-
add a leak safeguard to accounts_
service_ sound_proxy - 310. By Charles Kerr
-
assume we're in silent mode if we can't get an accounts-service proxy
- 311. By Charles Kerr
-
fix copy-paste typo
- 312. By Charles Kerr
-
move sound-player-mock into the tests/ directory
Charles Kerr (charlesk) wrote : | # |
> It seems you don't have <email address hidden> registered with LP, that makes it not associate the commits with your UID.
Oh dear. I may have broken my config last week. Fixed with a new bzr whoami for r307.
> we need to get this indicator converted to C++11 ;-)
I thought this a couple of times while writing the GObject/GInterface boilerplate, but didn't want to MP that for OTA 9 :)
Inline comments' responses are inline
- 313. By Charles Kerr
-
don't disable the warning sound when AccountServices is completely unavailable
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:312
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 314. By Charles Kerr
-
demote a spurious warning to a debug message
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:314
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 2014-07-21 21:08:29 +0000 | |||
3 | +++ CMakeLists.txt 2016-01-04 20:26:17 +0000 | |||
4 | @@ -7,7 +7,8 @@ | |||
5 | 7 | set(PACKAGE ${CMAKE_PROJECT_NAME}) | 7 | set(PACKAGE ${CMAKE_PROJECT_NAME}) |
6 | 8 | set(GETTEXT_PACKAGE "indicator-power") | 8 | set(GETTEXT_PACKAGE "indicator-power") |
7 | 9 | add_definitions (-DGETTEXT_PACKAGE="${GETTEXT_PACKAGE}" | 9 | add_definitions (-DGETTEXT_PACKAGE="${GETTEXT_PACKAGE}" |
9 | 10 | -DGNOMELOCALEDIR="${CMAKE_INSTALL_FULL_LOCALEDIR}") | 10 | -DGNOMELOCALEDIR="${CMAKE_INSTALL_FULL_LOCALEDIR}" |
10 | 11 | -DLOW_BATTERY_SOUND="Low battery.ogg") | ||
11 | 11 | 12 | ||
12 | 12 | option (enable_tests "Build the package's automatic tests." ON) | 13 | option (enable_tests "Build the package's automatic tests." ON) |
13 | 13 | option (enable_lcov "Generate lcov code coverage reports." ON) | 14 | option (enable_lcov "Generate lcov code coverage reports." ON) |
14 | @@ -38,6 +39,7 @@ | |||
15 | 38 | gio-unix-2.0>=2.36 | 39 | gio-unix-2.0>=2.36 |
16 | 39 | gudev-1.0>=204 | 40 | gudev-1.0>=204 |
17 | 40 | libnotify>=0.7.6 | 41 | libnotify>=0.7.6 |
18 | 42 | gstreamer-1.0>=1.2 | ||
19 | 41 | url-dispatcher-1>=1) | 43 | url-dispatcher-1>=1) |
20 | 42 | 44 | ||
21 | 43 | include_directories (SYSTEM ${SERVICE_DEPS_INCLUDE_DIRS}) | 45 | include_directories (SYSTEM ${SERVICE_DEPS_INCLUDE_DIRS}) |
22 | 44 | 46 | ||
23 | === modified file 'data/CMakeLists.txt' | |||
24 | --- data/CMakeLists.txt 2014-09-09 03:58:48 +0000 | |||
25 | +++ data/CMakeLists.txt 2016-01-04 20:26:17 +0000 | |||
26 | @@ -88,3 +88,12 @@ | |||
27 | 88 | 88 | ||
28 | 89 | install (FILES "${UNITY_INDICATOR_FILE}" | 89 | install (FILES "${UNITY_INDICATOR_FILE}" |
29 | 90 | DESTINATION "${UNITY_INDICATOR_DIR}") | 90 | DESTINATION "${UNITY_INDICATOR_DIR}") |
30 | 91 | |||
31 | 92 | ## | ||
32 | 93 | ## Sounds | ||
33 | 94 | ## | ||
34 | 95 | |||
35 | 96 | # where to install | ||
36 | 97 | set (DATA_HOME "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/${CMAKE_PROJECT_NAME}") | ||
37 | 98 | message (STATUS "${DATA_HOME} is the sounds/ install dir") | ||
38 | 99 | install (DIRECTORY sounds DESTINATION ${DATA_HOME}) | ||
39 | 91 | 100 | ||
40 | === added directory 'data/sounds' | |||
41 | === added file 'data/sounds/Low battery.ogg' | |||
42 | 92 | Binary files data/sounds/Low battery.ogg 1970-01-01 00:00:00 +0000 and data/sounds/Low battery.ogg 2016-01-04 20:26:17 +0000 differ | 101 | Binary files data/sounds/Low battery.ogg 1970-01-01 00:00:00 +0000 and data/sounds/Low battery.ogg 2016-01-04 20:26:17 +0000 differ |
43 | === modified file 'debian/control' | |||
44 | --- debian/control 2015-02-25 14:49:06 +0000 | |||
45 | +++ debian/control 2016-01-04 20:26:17 +0000 | |||
46 | @@ -7,7 +7,10 @@ | |||
47 | 7 | libglib2.0-dev (>= 2.36), | 7 | libglib2.0-dev (>= 2.36), |
48 | 8 | libgudev-1.0-dev, | 8 | libgudev-1.0-dev, |
49 | 9 | liburl-dispatcher1-dev, | 9 | liburl-dispatcher1-dev, |
50 | 10 | libgstreamer1.0-dev, | ||
51 | 10 | python:any, | 11 | python:any, |
52 | 12 | # for com.ubuntu.touch.AccountsService.Sound.xml | ||
53 | 13 | accountsservice-ubuntu-schemas, | ||
54 | 11 | # for packaging | 14 | # for packaging |
55 | 12 | debhelper (>= 9), | 15 | debhelper (>= 9), |
56 | 13 | dh-translations, | 16 | dh-translations, |
57 | 14 | 17 | ||
58 | === modified file 'src/CMakeLists.txt' | |||
59 | --- src/CMakeLists.txt 2015-05-20 15:34:26 +0000 | |||
60 | +++ src/CMakeLists.txt 2016-01-04 20:26:17 +0000 | |||
61 | @@ -6,13 +6,16 @@ | |||
62 | 6 | # handwritten sources | 6 | # handwritten sources |
63 | 7 | set(SERVICE_MANUAL_SOURCES | 7 | set(SERVICE_MANUAL_SOURCES |
64 | 8 | brightness.c | 8 | brightness.c |
65 | 9 | datafiles.c | ||
66 | 9 | device-provider-mock.c | 10 | device-provider-mock.c |
67 | 10 | device-provider-upower.c | 11 | device-provider-upower.c |
68 | 11 | device-provider.c | 12 | device-provider.c |
69 | 12 | device.c | 13 | device.c |
70 | 13 | notifier.c | 14 | notifier.c |
71 | 14 | testing.c | 15 | testing.c |
73 | 15 | service.c) | 16 | service.c |
74 | 17 | sound-player.c | ||
75 | 18 | sound-player-gst.c) | ||
76 | 16 | 19 | ||
77 | 17 | # generated sources | 20 | # generated sources |
78 | 18 | include(GdbusCodegen) | 21 | include(GdbusCodegen) |
79 | @@ -29,6 +32,11 @@ | |||
80 | 29 | com.canonical.indicator.power | 32 | com.canonical.indicator.power |
81 | 30 | Dbus | 33 | Dbus |
82 | 31 | ${CMAKE_SOURCE_DIR}/data/com.canonical.indicator.power.Testing.xml) | 34 | ${CMAKE_SOURCE_DIR}/data/com.canonical.indicator.power.Testing.xml) |
83 | 35 | add_gdbus_codegen_with_namespace(SERVICE_GENERATED_SOURCES dbus-accounts-sound | ||
84 | 36 | com.ubuntu.touch | ||
85 | 37 | Dbus | ||
86 | 38 | /usr/share/accountsservice/interfaces/com.ubuntu.touch.AccountsService.Sound.xml) | ||
87 | 39 | |||
88 | 32 | # add the bin dir to our include path so the code can find the generated header files | 40 | # add the bin dir to our include path so the code can find the generated header files |
89 | 33 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) | 41 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) |
90 | 34 | 42 | ||
91 | 35 | 43 | ||
92 | === added file 'src/datafiles.c' | |||
93 | --- src/datafiles.c 1970-01-01 00:00:00 +0000 | |||
94 | +++ src/datafiles.c 2016-01-04 20:26:17 +0000 | |||
95 | @@ -0,0 +1,71 @@ | |||
96 | 1 | /* | ||
97 | 2 | * Copyright 2016 Canonical Ltd. | ||
98 | 3 | * | ||
99 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
100 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
101 | 6 | * by the Free Software Foundation. | ||
102 | 7 | * | ||
103 | 8 | * This program is distributed in the hope that it will be useful, but | ||
104 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
105 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
106 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
107 | 12 | * | ||
108 | 13 | * You should have received a copy of the GNU General Public License along | ||
109 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
110 | 15 | * | ||
111 | 16 | * Authors: | ||
112 | 17 | * Charles Kerr <charles.kerr@canonical.com> | ||
113 | 18 | */ | ||
114 | 19 | |||
115 | 20 | #include "datafiles.h" | ||
116 | 21 | |||
117 | 22 | static const gchar* | ||
118 | 23 | get_directory_prefix_for_type (DatafileType type) | ||
119 | 24 | { | ||
120 | 25 | switch (type) | ||
121 | 26 | { | ||
122 | 27 | case DATAFILE_TYPE_SOUND: | ||
123 | 28 | return "sounds"; | ||
124 | 29 | |||
125 | 30 | default: | ||
126 | 31 | g_critical("unknown type"); | ||
127 | 32 | return ""; | ||
128 | 33 | } | ||
129 | 34 | } | ||
130 | 35 | |||
131 | 36 | static gchar* | ||
132 | 37 | test_directory_for_file(const char* dir, DatafileType type, const char* basename) | ||
133 | 38 | { | ||
134 | 39 | gchar* filename = g_build_filename(dir, | ||
135 | 40 | GETTEXT_PACKAGE, | ||
136 | 41 | get_directory_prefix_for_type(type), | ||
137 | 42 | basename, | ||
138 | 43 | NULL); | ||
139 | 44 | |||
140 | 45 | g_debug("looking for \"%s\" at \"%s\"", basename, filename); | ||
141 | 46 | if (g_file_test(filename, G_FILE_TEST_EXISTS)) | ||
142 | 47 | return filename; | ||
143 | 48 | |||
144 | 49 | g_free(filename); | ||
145 | 50 | return NULL; | ||
146 | 51 | } | ||
147 | 52 | |||
148 | 53 | gchar* | ||
149 | 54 | datafile_find(DatafileType type, const char * basename) | ||
150 | 55 | { | ||
151 | 56 | gchar * filename; | ||
152 | 57 | const gchar * user_data_dir; | ||
153 | 58 | const gchar * const * system_data_dirs; | ||
154 | 59 | gsize i; | ||
155 | 60 | |||
156 | 61 | user_data_dir = g_get_user_data_dir(); | ||
157 | 62 | if ((filename = test_directory_for_file(user_data_dir, type, basename))) | ||
158 | 63 | return filename; | ||
159 | 64 | |||
160 | 65 | system_data_dirs = g_get_system_data_dirs(); | ||
161 | 66 | for (i=0; system_data_dirs && system_data_dirs[i]; ++i) | ||
162 | 67 | if ((filename = test_directory_for_file(system_data_dirs[i], type, basename))) | ||
163 | 68 | return filename; | ||
164 | 69 | |||
165 | 70 | return NULL; | ||
166 | 71 | } | ||
167 | 0 | 72 | ||
168 | === added file 'src/datafiles.h' | |||
169 | --- src/datafiles.h 1970-01-01 00:00:00 +0000 | |||
170 | +++ src/datafiles.h 2016-01-04 20:26:17 +0000 | |||
171 | @@ -0,0 +1,37 @@ | |||
172 | 1 | /* | ||
173 | 2 | * Copyright 2016 Canonical Ltd. | ||
174 | 3 | * | ||
175 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
176 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
177 | 6 | * by the Free Software Foundation. | ||
178 | 7 | * | ||
179 | 8 | * This program is distributed in the hope that it will be useful, but | ||
180 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
181 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
182 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
183 | 12 | * | ||
184 | 13 | * You should have received a copy of the GNU General Public License along | ||
185 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
186 | 15 | * | ||
187 | 16 | * Authors: | ||
188 | 17 | * Charles Kerr <charles.kerr@canonical.com> | ||
189 | 18 | */ | ||
190 | 19 | |||
191 | 20 | #ifndef __INDICATOR_POWER_DATAFILES_H__ | ||
192 | 21 | #define __INDICATOR_POWER_DATAFILES_H__ | ||
193 | 22 | |||
194 | 23 | #include <gio/gio.h> | ||
195 | 24 | |||
196 | 25 | G_BEGIN_DECLS | ||
197 | 26 | |||
198 | 27 | typedef enum | ||
199 | 28 | { | ||
200 | 29 | DATAFILE_TYPE_SOUND | ||
201 | 30 | } | ||
202 | 31 | DatafileType; | ||
203 | 32 | |||
204 | 33 | gchar* datafile_find(DatafileType type, const char * basename); | ||
205 | 34 | |||
206 | 35 | G_END_DECLS | ||
207 | 36 | |||
208 | 37 | #endif /* __INDICATOR_POWER_DATAFILES_H__ */ | ||
209 | 0 | 38 | ||
210 | === modified file 'src/main.c' | |||
211 | --- src/main.c 2014-10-14 19:09:32 +0000 | |||
212 | +++ src/main.c 2016-01-04 20:26:17 +0000 | |||
213 | @@ -1,8 +1,5 @@ | |||
214 | 1 | /* | 1 | /* |
219 | 2 | * Copyright 2013 Canonical Ltd. | 2 | * Copyright 2013-2016 Canonical Ltd. |
216 | 3 | * | ||
217 | 4 | * Authors: | ||
218 | 5 | * Charles Kerr <charles.kerr@canonical.com> | ||
220 | 6 | * | 3 | * |
221 | 7 | * This program is free software: you can redistribute it and/or modify it | 4 | * This program is free software: you can redistribute it and/or modify it |
222 | 8 | * under the terms of the GNU General Public License version 3, as published | 5 | * under the terms of the GNU General Public License version 3, as published |
223 | @@ -15,6 +12,9 @@ | |||
224 | 15 | * | 12 | * |
225 | 16 | * You should have received a copy of the GNU General Public License along | 13 | * You should have received a copy of the GNU General Public License along |
226 | 17 | * with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
227 | 15 | * | ||
228 | 16 | * Authors: | ||
229 | 17 | * Charles Kerr <charles.kerr@canonical.com> | ||
230 | 18 | */ | 18 | */ |
231 | 19 | 19 | ||
232 | 20 | #include <locale.h> | 20 | #include <locale.h> |
233 | @@ -23,7 +23,9 @@ | |||
234 | 23 | #include <glib/gi18n.h> | 23 | #include <glib/gi18n.h> |
235 | 24 | 24 | ||
236 | 25 | #include "device.h" | 25 | #include "device.h" |
237 | 26 | #include "notifier.h" | ||
238 | 26 | #include "service.h" | 27 | #include "service.h" |
239 | 28 | #include "sound-player-gst.h" | ||
240 | 27 | #include "testing.h" | 29 | #include "testing.h" |
241 | 28 | 30 | ||
242 | 29 | /*** | 31 | /*** |
243 | @@ -40,6 +42,8 @@ | |||
244 | 40 | int | 42 | int |
245 | 41 | main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED) | 43 | main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED) |
246 | 42 | { | 44 | { |
247 | 45 | IndicatorPowerSoundPlayer * sound_player; | ||
248 | 46 | IndicatorPowerNotifier * notifier; | ||
249 | 43 | IndicatorPowerService * service; | 47 | IndicatorPowerService * service; |
250 | 44 | IndicatorPowerTesting * testing; | 48 | IndicatorPowerTesting * testing; |
251 | 45 | GMainLoop * loop; | 49 | GMainLoop * loop; |
252 | @@ -50,7 +54,9 @@ | |||
253 | 50 | textdomain (GETTEXT_PACKAGE); | 54 | textdomain (GETTEXT_PACKAGE); |
254 | 51 | 55 | ||
255 | 52 | /* run */ | 56 | /* run */ |
257 | 53 | service = indicator_power_service_new (NULL); | 57 | sound_player = indicator_power_sound_player_gst_new (); |
258 | 58 | notifier = indicator_power_notifier_new (sound_player); | ||
259 | 59 | service = indicator_power_service_new(NULL, notifier); | ||
260 | 54 | testing = indicator_power_testing_new (service); | 60 | testing = indicator_power_testing_new (service); |
261 | 55 | loop = g_main_loop_new (NULL, FALSE); | 61 | loop = g_main_loop_new (NULL, FALSE); |
262 | 56 | g_signal_connect (service, INDICATOR_POWER_SERVICE_SIGNAL_NAME_LOST, | 62 | g_signal_connect (service, INDICATOR_POWER_SERVICE_SIGNAL_NAME_LOST, |
263 | @@ -59,7 +65,9 @@ | |||
264 | 59 | 65 | ||
265 | 60 | /* cleanup */ | 66 | /* cleanup */ |
266 | 61 | g_main_loop_unref (loop); | 67 | g_main_loop_unref (loop); |
267 | 68 | g_clear_object (&testing); | ||
268 | 62 | g_clear_object (&service); | 69 | g_clear_object (&service); |
270 | 63 | g_clear_object (&testing); | 70 | g_clear_object (¬ifier); |
271 | 71 | g_clear_object (&sound_player); | ||
272 | 64 | return 0; | 72 | return 0; |
273 | 65 | } | 73 | } |
274 | 66 | 74 | ||
275 | === modified file 'src/notifier.c' | |||
276 | --- src/notifier.c 2014-10-15 01:58:28 +0000 | |||
277 | +++ src/notifier.c 2016-01-04 20:26:17 +0000 | |||
278 | @@ -1,5 +1,5 @@ | |||
279 | 1 | /* | 1 | /* |
281 | 2 | * Copyright 2014 Canonical Ltd. | 2 | * Copyright 2014-2016 Canonical Ltd. |
282 | 3 | * | 3 | * |
283 | 4 | * This program is free software: you can redistribute it and/or modify it | 4 | * This program is free software: you can redistribute it and/or modify it |
284 | 5 | * under the terms of the GNU General Public License version 3, as published | 5 | * under the terms of the GNU General Public License version 3, as published |
285 | @@ -17,9 +17,12 @@ | |||
286 | 17 | * Charles Kerr <charles.kerr@canonical.com> | 17 | * Charles Kerr <charles.kerr@canonical.com> |
287 | 18 | */ | 18 | */ |
288 | 19 | 19 | ||
289 | 20 | #include "datafiles.h" | ||
290 | 21 | #include "dbus-accounts-sound.h" | ||
291 | 20 | #include "dbus-battery.h" | 22 | #include "dbus-battery.h" |
292 | 21 | #include "dbus-shared.h" | 23 | #include "dbus-shared.h" |
293 | 22 | #include "notifier.h" | 24 | #include "notifier.h" |
294 | 25 | #include "sound-player.h" | ||
295 | 23 | 26 | ||
296 | 24 | #include <url-dispatcher.h> | 27 | #include <url-dispatcher.h> |
297 | 25 | 28 | ||
298 | @@ -46,10 +49,12 @@ | |||
299 | 46 | { | 49 | { |
300 | 47 | PROP_0, | 50 | PROP_0, |
301 | 48 | PROP_BATTERY, | 51 | PROP_BATTERY, |
302 | 52 | PROP_SOUND_PLAYER, | ||
303 | 49 | LAST_PROP | 53 | LAST_PROP |
304 | 50 | }; | 54 | }; |
305 | 51 | 55 | ||
306 | 52 | #define PROP_BATTERY_NAME "battery" | 56 | #define PROP_BATTERY_NAME "battery" |
307 | 57 | #define PROP_SOUND_PLAYER_NAME "sound-player" | ||
308 | 53 | 58 | ||
309 | 54 | static GParamSpec * properties[LAST_PROP]; | 59 | static GParamSpec * properties[LAST_PROP]; |
310 | 55 | 60 | ||
311 | @@ -77,6 +82,12 @@ | |||
312 | 77 | 82 | ||
313 | 78 | gboolean caps_queried; | 83 | gboolean caps_queried; |
314 | 79 | gboolean actions_supported; | 84 | gboolean actions_supported; |
315 | 85 | |||
316 | 86 | IndicatorPowerSoundPlayer * sound_player; | ||
317 | 87 | |||
318 | 88 | GCancellable * cancellable; | ||
319 | 89 | DbusAccountsServiceSound * accounts_service_sound_proxy; | ||
320 | 90 | gboolean accounts_service_sound_proxy_pending; | ||
321 | 80 | } | 91 | } |
322 | 81 | IndicatorPowerNotifierPrivate; | 92 | IndicatorPowerNotifierPrivate; |
323 | 82 | 93 | ||
324 | @@ -131,6 +142,82 @@ | |||
325 | 131 | } | 142 | } |
326 | 132 | 143 | ||
327 | 133 | /*** | 144 | /*** |
328 | 145 | **** Sounds | ||
329 | 146 | ***/ | ||
330 | 147 | |||
331 | 148 | static void | ||
332 | 149 | on_sound_proxy_ready (GObject * source_object G_GNUC_UNUSED, | ||
333 | 150 | GAsyncResult * res, | ||
334 | 151 | gpointer gself) | ||
335 | 152 | { | ||
336 | 153 | GError * error; | ||
337 | 154 | DbusAccountsServiceSound * proxy; | ||
338 | 155 | |||
339 | 156 | error = NULL; | ||
340 | 157 | proxy = dbus_accounts_service_sound_proxy_new_for_bus_finish (res, &error); | ||
341 | 158 | if (error != NULL) | ||
342 | 159 | { | ||
343 | 160 | if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) | ||
344 | 161 | { | ||
345 | 162 | get_priv(gself)->accounts_service_sound_proxy_pending = FALSE; | ||
346 | 163 | g_debug("%s Couldn't find accounts service sound proxy: %s", G_STRLOC, error->message); | ||
347 | 164 | } | ||
348 | 165 | |||
349 | 166 | g_clear_error(&error); | ||
350 | 167 | } | ||
351 | 168 | else | ||
352 | 169 | { | ||
353 | 170 | IndicatorPowerNotifier * const self = INDICATOR_POWER_NOTIFIER(gself); | ||
354 | 171 | priv_t * const p = get_priv (self); | ||
355 | 172 | g_clear_object (&p->accounts_service_sound_proxy); | ||
356 | 173 | p->accounts_service_sound_proxy = proxy; | ||
357 | 174 | p->accounts_service_sound_proxy_pending = FALSE; | ||
358 | 175 | } | ||
359 | 176 | } | ||
360 | 177 | |||
361 | 178 | static gboolean | ||
362 | 179 | silent_mode (IndicatorPowerNotifier * self) | ||
363 | 180 | { | ||
364 | 181 | priv_t * const p = get_priv (self); | ||
365 | 182 | |||
366 | 183 | /* if we don't have a proxy yet, assume we're in silent mode | ||
367 | 184 | as a "do no harm" level of response */ | ||
368 | 185 | if (p->accounts_service_sound_proxy_pending) | ||
369 | 186 | return TRUE; | ||
370 | 187 | |||
371 | 188 | return (p->accounts_service_sound_proxy != NULL) | ||
372 | 189 | && dbus_accounts_service_sound_get_silent_mode(p->accounts_service_sound_proxy); | ||
373 | 190 | } | ||
374 | 191 | |||
375 | 192 | static void | ||
376 | 193 | play_low_battery_sound (IndicatorPowerNotifier * self) | ||
377 | 194 | { | ||
378 | 195 | const gchar * const key = LOW_BATTERY_SOUND; | ||
379 | 196 | gchar * filename; | ||
380 | 197 | priv_t * const p = get_priv(self); | ||
381 | 198 | |||
382 | 199 | /* can't play? */ | ||
383 | 200 | g_return_if_fail (p->sound_player != NULL); | ||
384 | 201 | |||
385 | 202 | /* won't play? */ | ||
386 | 203 | if (silent_mode(self)) | ||
387 | 204 | return; | ||
388 | 205 | |||
389 | 206 | filename = datafile_find(DATAFILE_TYPE_SOUND, key); | ||
390 | 207 | if (filename != NULL) | ||
391 | 208 | { | ||
392 | 209 | gchar * uri = g_filename_to_uri(filename, NULL, NULL); | ||
393 | 210 | indicator_power_sound_player_play_uri (p->sound_player, uri); | ||
394 | 211 | g_free(uri); | ||
395 | 212 | g_free(filename); | ||
396 | 213 | } | ||
397 | 214 | else | ||
398 | 215 | { | ||
399 | 216 | g_warning("Unable to find '%s' in XDG data dirs", key); | ||
400 | 217 | } | ||
401 | 218 | } | ||
402 | 219 | |||
403 | 220 | /*** | ||
404 | 134 | **** Notifications | 221 | **** Notifications |
405 | 135 | ***/ | 222 | ***/ |
406 | 136 | 223 | ||
407 | @@ -300,6 +387,7 @@ | |||
408 | 300 | ((new_power_level != POWER_LEVEL_OK) && new_discharging && !old_discharging)) | 387 | ((new_power_level != POWER_LEVEL_OK) && new_discharging && !old_discharging)) |
409 | 301 | { | 388 | { |
410 | 302 | notification_show (self); | 389 | notification_show (self); |
411 | 390 | play_low_battery_sound (self); | ||
412 | 303 | } | 391 | } |
413 | 304 | else if (!new_discharging || (new_power_level == POWER_LEVEL_OK)) | 392 | else if (!new_discharging || (new_power_level == POWER_LEVEL_OK)) |
414 | 305 | { | 393 | { |
415 | @@ -330,6 +418,10 @@ | |||
416 | 330 | g_value_set_object (value, p->battery); | 418 | g_value_set_object (value, p->battery); |
417 | 331 | break; | 419 | break; |
418 | 332 | 420 | ||
419 | 421 | case PROP_SOUND_PLAYER: | ||
420 | 422 | g_value_set_object (value, p->sound_player); | ||
421 | 423 | break; | ||
422 | 424 | |||
423 | 333 | default: | 425 | default: |
424 | 334 | G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); | 426 | G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); |
425 | 335 | } | 427 | } |
426 | @@ -349,6 +441,10 @@ | |||
427 | 349 | indicator_power_notifier_set_battery (self, g_value_get_object(value)); | 441 | indicator_power_notifier_set_battery (self, g_value_get_object(value)); |
428 | 350 | break; | 442 | break; |
429 | 351 | 443 | ||
430 | 444 | case PROP_SOUND_PLAYER: | ||
431 | 445 | indicator_power_notifier_set_sound_player (self, g_value_get_object(value)); | ||
432 | 446 | break; | ||
433 | 447 | |||
434 | 352 | default: | 448 | default: |
435 | 353 | G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); | 449 | G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); |
436 | 354 | } | 450 | } |
437 | @@ -360,10 +456,18 @@ | |||
438 | 360 | IndicatorPowerNotifier * const self = INDICATOR_POWER_NOTIFIER(o); | 456 | IndicatorPowerNotifier * const self = INDICATOR_POWER_NOTIFIER(o); |
439 | 361 | priv_t * const p = get_priv (self); | 457 | priv_t * const p = get_priv (self); |
440 | 362 | 458 | ||
441 | 459 | if (p->cancellable != NULL) | ||
442 | 460 | { | ||
443 | 461 | g_cancellable_cancel(p->cancellable); | ||
444 | 462 | g_clear_object(&p->cancellable); | ||
445 | 463 | } | ||
446 | 464 | |||
447 | 363 | indicator_power_notifier_set_bus (self, NULL); | 465 | indicator_power_notifier_set_bus (self, NULL); |
448 | 466 | indicator_power_notifier_set_sound_player (self, NULL); | ||
449 | 364 | notification_clear (self); | 467 | notification_clear (self); |
450 | 365 | indicator_power_notifier_set_battery (self, NULL); | 468 | indicator_power_notifier_set_battery (self, NULL); |
451 | 366 | g_clear_object (&p->dbus_battery); | 469 | g_clear_object (&p->dbus_battery); |
452 | 470 | g_clear_object (&p->accounts_service_sound_proxy); | ||
453 | 367 | 471 | ||
454 | 368 | G_OBJECT_CLASS (indicator_power_notifier_parent_class)->dispose (o); | 472 | G_OBJECT_CLASS (indicator_power_notifier_parent_class)->dispose (o); |
455 | 369 | } | 473 | } |
456 | @@ -382,7 +486,6 @@ | |||
457 | 382 | **** Instantiation | 486 | **** Instantiation |
458 | 383 | ***/ | 487 | ***/ |
459 | 384 | 488 | ||
460 | 385 | |||
461 | 386 | static void | 489 | static void |
462 | 387 | indicator_power_notifier_init (IndicatorPowerNotifier * self) | 490 | indicator_power_notifier_init (IndicatorPowerNotifier * self) |
463 | 388 | { | 491 | { |
464 | @@ -394,8 +497,22 @@ | |||
465 | 394 | 497 | ||
466 | 395 | p->power_level = POWER_LEVEL_OK; | 498 | p->power_level = POWER_LEVEL_OK; |
467 | 396 | 499 | ||
468 | 500 | p->cancellable = g_cancellable_new(); | ||
469 | 501 | |||
470 | 397 | if (!instance_count++ && !notify_init("indicator-power-service")) | 502 | if (!instance_count++ && !notify_init("indicator-power-service")) |
471 | 398 | g_critical("Unable to initialize libnotify! Notifications might not be shown."); | 503 | g_critical("Unable to initialize libnotify! Notifications might not be shown."); |
472 | 504 | |||
473 | 505 | p->accounts_service_sound_proxy_pending = TRUE; | ||
474 | 506 | gchar* object_path = g_strdup_printf("/org/freedesktop/Accounts/User%lu", (gulong)getuid()); | ||
475 | 507 | dbus_accounts_service_sound_proxy_new_for_bus( | ||
476 | 508 | G_BUS_TYPE_SYSTEM, | ||
477 | 509 | G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES, | ||
478 | 510 | "org.freedesktop.Accounts", | ||
479 | 511 | object_path, | ||
480 | 512 | p->cancellable, | ||
481 | 513 | on_sound_proxy_ready, | ||
482 | 514 | self); | ||
483 | 515 | g_clear_pointer(&object_path, g_free); | ||
484 | 399 | } | 516 | } |
485 | 400 | 517 | ||
486 | 401 | static void | 518 | static void |
487 | @@ -415,6 +532,13 @@ | |||
488 | 415 | G_TYPE_OBJECT, | 532 | G_TYPE_OBJECT, |
489 | 416 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); | 533 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); |
490 | 417 | 534 | ||
491 | 535 | properties[PROP_SOUND_PLAYER] = g_param_spec_object ( | ||
492 | 536 | PROP_SOUND_PLAYER_NAME, | ||
493 | 537 | "Sound Player", | ||
494 | 538 | "The current sound player", | ||
495 | 539 | G_TYPE_OBJECT, | ||
496 | 540 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); | ||
497 | 541 | |||
498 | 418 | g_object_class_install_properties (object_class, LAST_PROP, properties); | 542 | g_object_class_install_properties (object_class, LAST_PROP, properties); |
499 | 419 | } | 543 | } |
500 | 420 | 544 | ||
501 | @@ -423,9 +547,11 @@ | |||
502 | 423 | ***/ | 547 | ***/ |
503 | 424 | 548 | ||
504 | 425 | IndicatorPowerNotifier * | 549 | IndicatorPowerNotifier * |
506 | 426 | indicator_power_notifier_new (void) | 550 | indicator_power_notifier_new (IndicatorPowerSoundPlayer * sound_player) |
507 | 427 | { | 551 | { |
509 | 428 | GObject * o = g_object_new (INDICATOR_TYPE_POWER_NOTIFIER, NULL); | 552 | GObject * o = g_object_new (INDICATOR_TYPE_POWER_NOTIFIER, |
510 | 553 | PROP_SOUND_PLAYER_NAME, sound_player, | ||
511 | 554 | NULL); | ||
512 | 429 | 555 | ||
513 | 430 | return INDICATOR_POWER_NOTIFIER (o); | 556 | return INDICATOR_POWER_NOTIFIER (o); |
514 | 431 | } | 557 | } |
515 | @@ -465,6 +591,26 @@ | |||
516 | 465 | } | 591 | } |
517 | 466 | 592 | ||
518 | 467 | void | 593 | void |
519 | 594 | indicator_power_notifier_set_sound_player (IndicatorPowerNotifier * self, | ||
520 | 595 | IndicatorPowerSoundPlayer * sound_player) | ||
521 | 596 | { | ||
522 | 597 | priv_t * p; | ||
523 | 598 | |||
524 | 599 | g_return_if_fail(INDICATOR_IS_POWER_NOTIFIER(self)); | ||
525 | 600 | g_return_if_fail((sound_player == NULL) || INDICATOR_IS_POWER_SOUND_PLAYER(sound_player)); | ||
526 | 601 | |||
527 | 602 | p = get_priv (self); | ||
528 | 603 | |||
529 | 604 | if (p->sound_player == sound_player) | ||
530 | 605 | return; | ||
531 | 606 | |||
532 | 607 | g_clear_object(&p->sound_player); | ||
533 | 608 | |||
534 | 609 | if (sound_player != NULL) | ||
535 | 610 | p->sound_player = g_object_ref(sound_player); | ||
536 | 611 | } | ||
537 | 612 | |||
538 | 613 | void | ||
539 | 468 | indicator_power_notifier_set_bus (IndicatorPowerNotifier * self, | 614 | indicator_power_notifier_set_bus (IndicatorPowerNotifier * self, |
540 | 469 | GDBusConnection * bus) | 615 | GDBusConnection * bus) |
541 | 470 | { | 616 | { |
542 | 471 | 617 | ||
543 | === modified file 'src/notifier.h' | |||
544 | --- src/notifier.h 2014-07-25 04:31:11 +0000 | |||
545 | +++ src/notifier.h 2016-01-04 20:26:17 +0000 | |||
546 | @@ -1,5 +1,5 @@ | |||
547 | 1 | /* | 1 | /* |
549 | 2 | * Copyright 2014 Canonical Ltd. | 2 | * Copyright 2014-2016 Canonical Ltd. |
550 | 3 | * | 3 | * |
551 | 4 | * This program is free software: you can redistribute it and/or modify it | 4 | * This program is free software: you can redistribute it and/or modify it |
552 | 5 | * under the terms of the GNU General Public License version 3, as published | 5 | * under the terms of the GNU General Public License version 3, as published |
553 | @@ -23,6 +23,7 @@ | |||
554 | 23 | #include <gio/gio.h> | 23 | #include <gio/gio.h> |
555 | 24 | 24 | ||
556 | 25 | #include "device.h" | 25 | #include "device.h" |
557 | 26 | #include "sound-player.h" | ||
558 | 26 | 27 | ||
559 | 27 | G_BEGIN_DECLS | 28 | G_BEGIN_DECLS |
560 | 28 | 29 | ||
561 | @@ -55,7 +56,7 @@ | |||
562 | 55 | 56 | ||
563 | 56 | GType indicator_power_notifier_get_type (void); | 57 | GType indicator_power_notifier_get_type (void); |
564 | 57 | 58 | ||
566 | 58 | IndicatorPowerNotifier * indicator_power_notifier_new (void); | 59 | IndicatorPowerNotifier * indicator_power_notifier_new (IndicatorPowerSoundPlayer * sound_player); |
567 | 59 | 60 | ||
568 | 60 | void indicator_power_notifier_set_bus (IndicatorPowerNotifier * self, | 61 | void indicator_power_notifier_set_bus (IndicatorPowerNotifier * self, |
569 | 61 | GDBusConnection * connection); | 62 | GDBusConnection * connection); |
570 | @@ -63,6 +64,9 @@ | |||
571 | 63 | void indicator_power_notifier_set_battery (IndicatorPowerNotifier * self, | 64 | void indicator_power_notifier_set_battery (IndicatorPowerNotifier * self, |
572 | 64 | IndicatorPowerDevice * battery); | 65 | IndicatorPowerDevice * battery); |
573 | 65 | 66 | ||
574 | 67 | void indicator_power_notifier_set_sound_player (IndicatorPowerNotifier * self, | ||
575 | 68 | IndicatorPowerSoundPlayer * battery); | ||
576 | 69 | |||
577 | 66 | #define POWER_LEVEL_STR_OK "ok" | 70 | #define POWER_LEVEL_STR_OK "ok" |
578 | 67 | #define POWER_LEVEL_STR_LOW "low" | 71 | #define POWER_LEVEL_STR_LOW "low" |
579 | 68 | #define POWER_LEVEL_STR_VERY_LOW "very_low" | 72 | #define POWER_LEVEL_STR_VERY_LOW "very_low" |
580 | 69 | 73 | ||
581 | === modified file 'src/service.c' | |||
582 | --- src/service.c 2015-08-27 14:18:40 +0000 | |||
583 | +++ src/service.c 2016-01-04 20:26:17 +0000 | |||
584 | @@ -1,9 +1,5 @@ | |||
585 | 1 | /* | 1 | /* |
591 | 2 | * Copyright 2013 Canonical Ltd. | 2 | * Copyright 2013-2016 Canonical Ltd. |
587 | 3 | * | ||
588 | 4 | * Authors: | ||
589 | 5 | * Charles Kerr <charles.kerr@canonical.com> | ||
590 | 6 | * Ted Gould <ted@canonical.com> | ||
592 | 7 | * | 3 | * |
593 | 8 | * This program is free software: you can redistribute it and/or modify it | 4 | * This program is free software: you can redistribute it and/or modify it |
594 | 9 | * under the terms of the GNU General Public License version 3, as published | 5 | * under the terms of the GNU General Public License version 3, as published |
595 | @@ -16,6 +12,10 @@ | |||
596 | 16 | * | 12 | * |
597 | 17 | * You should have received a copy of the GNU General Public License along | 13 | * You should have received a copy of the GNU General Public License along |
598 | 18 | * with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
599 | 15 | * | ||
600 | 16 | * Authors: | ||
601 | 17 | * Charles Kerr <charles.kerr@canonical.com> | ||
602 | 18 | * Ted Gould <ted@canonical.com> | ||
603 | 19 | */ | 19 | */ |
604 | 20 | 20 | ||
605 | 21 | #include <glib/gi18n.h> | 21 | #include <glib/gi18n.h> |
606 | @@ -53,6 +53,7 @@ | |||
607 | 53 | PROP_0, | 53 | PROP_0, |
608 | 54 | PROP_BUS, | 54 | PROP_BUS, |
609 | 55 | PROP_DEVICE_PROVIDER, | 55 | PROP_DEVICE_PROVIDER, |
610 | 56 | PROP_NOTIFIER, | ||
611 | 56 | LAST_PROP | 57 | LAST_PROP |
612 | 57 | }; | 58 | }; |
613 | 58 | 59 | ||
614 | @@ -952,7 +953,8 @@ | |||
615 | 952 | g_object_notify_by_pspec (G_OBJECT(self), properties[PROP_BUS]); | 953 | g_object_notify_by_pspec (G_OBJECT(self), properties[PROP_BUS]); |
616 | 953 | 954 | ||
617 | 954 | /* export the battery properties */ | 955 | /* export the battery properties */ |
619 | 955 | indicator_power_notifier_set_bus (p->notifier, connection); | 956 | if (p->notifier != NULL) |
620 | 957 | indicator_power_notifier_set_bus (p->notifier, connection); | ||
621 | 956 | 958 | ||
622 | 957 | /* export the actions */ | 959 | /* export the actions */ |
623 | 958 | if ((id = g_dbus_connection_export_action_group (connection, | 960 | if ((id = g_dbus_connection_export_action_group (connection, |
624 | @@ -1094,6 +1096,10 @@ | |||
625 | 1094 | g_value_set_object (value, p->device_provider); | 1096 | g_value_set_object (value, p->device_provider); |
626 | 1095 | break; | 1097 | break; |
627 | 1096 | 1098 | ||
628 | 1099 | case PROP_NOTIFIER: | ||
629 | 1100 | g_value_set_object (value, p->notifier); | ||
630 | 1101 | break; | ||
631 | 1102 | |||
632 | 1097 | default: | 1103 | default: |
633 | 1098 | G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); | 1104 | G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); |
634 | 1099 | } | 1105 | } |
635 | @@ -1113,6 +1119,10 @@ | |||
636 | 1113 | indicator_power_service_set_device_provider (self, g_value_get_object (value)); | 1119 | indicator_power_service_set_device_provider (self, g_value_get_object (value)); |
637 | 1114 | break; | 1120 | break; |
638 | 1115 | 1121 | ||
639 | 1122 | case PROP_NOTIFIER: | ||
640 | 1123 | indicator_power_service_set_notifier (self, g_value_get_object (value)); | ||
641 | 1124 | break; | ||
642 | 1125 | |||
643 | 1116 | default: | 1126 | default: |
644 | 1117 | G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); | 1127 | G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); |
645 | 1118 | } | 1128 | } |
646 | @@ -1155,6 +1165,7 @@ | |||
647 | 1155 | g_clear_object (&p->conn); | 1165 | g_clear_object (&p->conn); |
648 | 1156 | 1166 | ||
649 | 1157 | indicator_power_service_set_device_provider (self, NULL); | 1167 | indicator_power_service_set_device_provider (self, NULL); |
650 | 1168 | indicator_power_service_set_notifier (self, NULL); | ||
651 | 1158 | 1169 | ||
652 | 1159 | G_OBJECT_CLASS (indicator_power_service_parent_class)->dispose (o); | 1170 | G_OBJECT_CLASS (indicator_power_service_parent_class)->dispose (o); |
653 | 1160 | } | 1171 | } |
654 | @@ -1178,8 +1189,6 @@ | |||
655 | 1178 | 1189 | ||
656 | 1179 | p->settings = g_settings_new ("com.canonical.indicator.power"); | 1190 | p->settings = g_settings_new ("com.canonical.indicator.power"); |
657 | 1180 | 1191 | ||
658 | 1181 | p->notifier = indicator_power_notifier_new (); | ||
659 | 1182 | |||
660 | 1183 | p->brightness = indicator_power_brightness_new(); | 1192 | p->brightness = indicator_power_brightness_new(); |
661 | 1184 | g_signal_connect_swapped(p->brightness, "notify::percentage", | 1193 | g_signal_connect_swapped(p->brightness, "notify::percentage", |
662 | 1185 | G_CALLBACK(update_brightness_action_state), self); | 1194 | G_CALLBACK(update_brightness_action_state), self); |
663 | @@ -1241,6 +1250,13 @@ | |||
664 | 1241 | G_TYPE_OBJECT, | 1250 | G_TYPE_OBJECT, |
665 | 1242 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); | 1251 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); |
666 | 1243 | 1252 | ||
667 | 1253 | properties[PROP_NOTIFIER] = g_param_spec_object ( | ||
668 | 1254 | "notifier", | ||
669 | 1255 | "Notifier", | ||
670 | 1256 | "Notifies user of important battery changes", | ||
671 | 1257 | G_TYPE_OBJECT, | ||
672 | 1258 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); | ||
673 | 1259 | |||
674 | 1244 | g_object_class_install_properties (object_class, LAST_PROP, properties); | 1260 | g_object_class_install_properties (object_class, LAST_PROP, properties); |
675 | 1245 | } | 1261 | } |
676 | 1246 | 1262 | ||
677 | @@ -1249,10 +1265,12 @@ | |||
678 | 1249 | ***/ | 1265 | ***/ |
679 | 1250 | 1266 | ||
680 | 1251 | IndicatorPowerService * | 1267 | IndicatorPowerService * |
682 | 1252 | indicator_power_service_new (IndicatorPowerDeviceProvider * device_provider) | 1268 | indicator_power_service_new (IndicatorPowerDeviceProvider * device_provider, |
683 | 1269 | IndicatorPowerNotifier * notifier) | ||
684 | 1253 | { | 1270 | { |
685 | 1254 | GObject * o = g_object_new (INDICATOR_TYPE_POWER_SERVICE, | 1271 | GObject * o = g_object_new (INDICATOR_TYPE_POWER_SERVICE, |
686 | 1255 | "device-provider", device_provider, | 1272 | "device-provider", device_provider, |
687 | 1273 | "notifier", notifier, | ||
688 | 1256 | NULL); | 1274 | NULL); |
689 | 1257 | 1275 | ||
690 | 1258 | return INDICATOR_POWER_SERVICE (o); | 1276 | return INDICATOR_POWER_SERVICE (o); |
691 | @@ -1291,6 +1309,29 @@ | |||
692 | 1291 | } | 1309 | } |
693 | 1292 | } | 1310 | } |
694 | 1293 | 1311 | ||
695 | 1312 | void | ||
696 | 1313 | indicator_power_service_set_notifier (IndicatorPowerService * self, | ||
697 | 1314 | IndicatorPowerNotifier * notifier) | ||
698 | 1315 | { | ||
699 | 1316 | priv_t * p; | ||
700 | 1317 | |||
701 | 1318 | g_return_if_fail (INDICATOR_IS_POWER_SERVICE (self)); | ||
702 | 1319 | g_return_if_fail (!notifier || INDICATOR_IS_POWER_NOTIFIER (notifier)); | ||
703 | 1320 | p = self->priv; | ||
704 | 1321 | |||
705 | 1322 | if (p->notifier == notifier) | ||
706 | 1323 | return; | ||
707 | 1324 | |||
708 | 1325 | g_clear_object (&p->notifier); | ||
709 | 1326 | |||
710 | 1327 | if (notifier != NULL) | ||
711 | 1328 | { | ||
712 | 1329 | p->notifier = g_object_ref (notifier); | ||
713 | 1330 | indicator_power_notifier_set_bus (p->notifier, p->conn); | ||
714 | 1331 | } | ||
715 | 1332 | } | ||
716 | 1333 | |||
717 | 1334 | |||
718 | 1294 | /* If a device has multiple batteries and uses only one of them at a time, | 1335 | /* If a device has multiple batteries and uses only one of them at a time, |
719 | 1295 | they should be presented as separate items inside the battery menu, | 1336 | they should be presented as separate items inside the battery menu, |
720 | 1296 | but everywhere else they should be aggregated (bug 880881). | 1337 | but everywhere else they should be aggregated (bug 880881). |
721 | 1297 | 1338 | ||
722 | === modified file 'src/service.h' | |||
723 | --- src/service.h 2013-06-19 15:10:50 +0000 | |||
724 | +++ src/service.h 2016-01-04 20:26:17 +0000 | |||
725 | @@ -24,6 +24,7 @@ | |||
726 | 24 | #include <glib-object.h> | 24 | #include <glib-object.h> |
727 | 25 | 25 | ||
728 | 26 | #include "device-provider.h" | 26 | #include "device-provider.h" |
729 | 27 | #include "notifier.h" | ||
730 | 27 | 28 | ||
731 | 28 | G_BEGIN_DECLS | 29 | G_BEGIN_DECLS |
732 | 29 | 30 | ||
733 | @@ -64,11 +65,15 @@ | |||
734 | 64 | 65 | ||
735 | 65 | GType indicator_power_service_get_type (void); | 66 | GType indicator_power_service_get_type (void); |
736 | 66 | 67 | ||
738 | 67 | IndicatorPowerService * indicator_power_service_new (IndicatorPowerDeviceProvider * provider); | 68 | IndicatorPowerService * indicator_power_service_new (IndicatorPowerDeviceProvider * provider, |
739 | 69 | IndicatorPowerNotifier * notifier); | ||
740 | 68 | 70 | ||
741 | 69 | void indicator_power_service_set_device_provider (IndicatorPowerService * self, | 71 | void indicator_power_service_set_device_provider (IndicatorPowerService * self, |
742 | 70 | IndicatorPowerDeviceProvider * provider); | 72 | IndicatorPowerDeviceProvider * provider); |
743 | 71 | 73 | ||
744 | 74 | void indicator_power_service_set_notifier (IndicatorPowerService * self, | ||
745 | 75 | IndicatorPowerNotifier * notifier); | ||
746 | 76 | |||
747 | 72 | IndicatorPowerDevice * indicator_power_service_choose_primary_device (GList * devices); | 77 | IndicatorPowerDevice * indicator_power_service_choose_primary_device (GList * devices); |
748 | 73 | 78 | ||
749 | 74 | 79 | ||
750 | 75 | 80 | ||
751 | === added file 'src/sound-player-gst.c' | |||
752 | --- src/sound-player-gst.c 1970-01-01 00:00:00 +0000 | |||
753 | +++ src/sound-player-gst.c 2016-01-04 20:26:17 +0000 | |||
754 | @@ -0,0 +1,173 @@ | |||
755 | 1 | /* | ||
756 | 2 | * Copyright 2016 Canonical Ltd. | ||
757 | 3 | * | ||
758 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
759 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
760 | 6 | * by the Free Software Foundation. | ||
761 | 7 | * | ||
762 | 8 | * This program is distributed in the hope that it will be useful, but | ||
763 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
764 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
765 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
766 | 12 | * | ||
767 | 13 | * You should have received a copy of the GNU General Public License along | ||
768 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
769 | 15 | * | ||
770 | 16 | * Authors: | ||
771 | 17 | * Charles Kerr <charles.kerr@canonical.com> | ||
772 | 18 | */ | ||
773 | 19 | |||
774 | 20 | #include "sound-player.h" | ||
775 | 21 | #include "sound-player-gst.h" | ||
776 | 22 | |||
777 | 23 | #include <gst/gst.h> | ||
778 | 24 | |||
779 | 25 | |||
780 | 26 | /*** | ||
781 | 27 | **** private struct | ||
782 | 28 | ***/ | ||
783 | 29 | |||
784 | 30 | typedef struct | ||
785 | 31 | { | ||
786 | 32 | int unused; | ||
787 | 33 | } | ||
788 | 34 | IndicatorPowerSoundPlayerGSTPrivate; | ||
789 | 35 | |||
790 | 36 | typedef IndicatorPowerSoundPlayerGSTPrivate priv_t; | ||
791 | 37 | |||
792 | 38 | #define get_priv(o) ((priv_t*)indicator_power_sound_player_gst_get_instance_private(o)) | ||
793 | 39 | |||
794 | 40 | |||
795 | 41 | /*** | ||
796 | 42 | **** GObject boilerplate | ||
797 | 43 | ***/ | ||
798 | 44 | |||
799 | 45 | static void indicator_power_device_provider_interface_init ( | ||
800 | 46 | IndicatorPowerSoundPlayerInterface * iface); | ||
801 | 47 | |||
802 | 48 | G_DEFINE_TYPE_WITH_CODE ( | ||
803 | 49 | IndicatorPowerSoundPlayerGST, | ||
804 | 50 | indicator_power_sound_player_gst, | ||
805 | 51 | G_TYPE_OBJECT, | ||
806 | 52 | G_ADD_PRIVATE(IndicatorPowerSoundPlayerGST) | ||
807 | 53 | G_IMPLEMENT_INTERFACE (INDICATOR_TYPE_POWER_SOUND_PLAYER, | ||
808 | 54 | indicator_power_device_provider_interface_init)) | ||
809 | 55 | |||
810 | 56 | /*** | ||
811 | 57 | **** GSTREAMER | ||
812 | 58 | ***/ | ||
813 | 59 | |||
814 | 60 | static void | ||
815 | 61 | gst_init_once(void) | ||
816 | 62 | { | ||
817 | 63 | static gboolean gst_init_checked = FALSE; | ||
818 | 64 | |||
819 | 65 | if (G_UNLIKELY(!gst_init_checked)) | ||
820 | 66 | { | ||
821 | 67 | GError* error = NULL; | ||
822 | 68 | if (!gst_init_check(NULL, NULL, &error)) | ||
823 | 69 | { | ||
824 | 70 | g_critical("Unable to play alarm sound: %s", error->message); | ||
825 | 71 | g_error_free(error); | ||
826 | 72 | } | ||
827 | 73 | gst_init_checked = TRUE; | ||
828 | 74 | } | ||
829 | 75 | } | ||
830 | 76 | |||
831 | 77 | static gboolean bus_callback(GstBus* bus G_GNUC_UNUSED, GstMessage* msg, gpointer gelement) | ||
832 | 78 | { | ||
833 | 79 | const GstMessageType message_type = GST_MESSAGE_TYPE(msg); | ||
834 | 80 | |||
835 | 81 | if (GST_MESSAGE_SRC(msg) != gelement) | ||
836 | 82 | return G_SOURCE_CONTINUE; | ||
837 | 83 | |||
838 | 84 | /* on eos, cleanup the element and cancel our gst bus subscription */ | ||
839 | 85 | if (message_type == GST_MESSAGE_EOS) | ||
840 | 86 | { | ||
841 | 87 | g_debug("got GST_MESSAGE_EOS on sound play"); | ||
842 | 88 | gst_element_set_state(GST_ELEMENT(gelement), GST_STATE_NULL); | ||
843 | 89 | gst_object_unref(gelement); | ||
844 | 90 | return G_SOURCE_REMOVE; | ||
845 | 91 | } | ||
846 | 92 | |||
847 | 93 | /* on stream start, set the media role to 'alert' if we're using pulsesink */ | ||
848 | 94 | if (message_type == GST_MESSAGE_STREAM_START) | ||
849 | 95 | { | ||
850 | 96 | GstElement* audio_sink = NULL; | ||
851 | 97 | g_debug("got GST_MESSAGE_STREAM_START on sound play"); | ||
852 | 98 | g_object_get(gelement, "audio-sink", &audio_sink, NULL); | ||
853 | 99 | if (audio_sink != NULL) | ||
854 | 100 | { | ||
855 | 101 | GstPluginFeature* feature; | ||
856 | 102 | feature = GST_PLUGIN_FEATURE_CAST(GST_ELEMENT_GET_CLASS(audio_sink)->elementfactory); | ||
857 | 103 | if (feature && g_strcmp0(gst_plugin_feature_get_name(feature), "pulsesink") == 0) | ||
858 | 104 | { | ||
859 | 105 | const gchar* const props_str = "props,media.role=alert"; | ||
860 | 106 | GstStructure* props = gst_structure_from_string(props_str, NULL); | ||
861 | 107 | g_debug("setting audio sink properties to '%s'", props_str); | ||
862 | 108 | g_object_set(audio_sink, "stream-properties", props, NULL); | ||
863 | 109 | g_clear_pointer(&props, gst_structure_free); | ||
864 | 110 | } | ||
865 | 111 | gst_object_unref(audio_sink); | ||
866 | 112 | } | ||
867 | 113 | } | ||
868 | 114 | |||
869 | 115 | return G_SOURCE_CONTINUE; | ||
870 | 116 | } | ||
871 | 117 | |||
872 | 118 | /*** | ||
873 | 119 | **** IndicatorPowerSoundPlayer virtual functions | ||
874 | 120 | ***/ | ||
875 | 121 | |||
876 | 122 | static void | ||
877 | 123 | my_play_uri (IndicatorPowerSoundPlayer * self G_GNUC_UNUSED, const gchar * uri) | ||
878 | 124 | { | ||
879 | 125 | GstElement * element; | ||
880 | 126 | GstBus * bus; | ||
881 | 127 | |||
882 | 128 | /* create the element */ | ||
883 | 129 | element = gst_element_factory_make("playbin", NULL); | ||
884 | 130 | |||
885 | 131 | /* start listening for gst events */ | ||
886 | 132 | bus = gst_pipeline_get_bus(GST_PIPELINE(element)); | ||
887 | 133 | gst_bus_add_watch(bus, bus_callback, element); | ||
888 | 134 | gst_object_unref(bus); | ||
889 | 135 | |||
890 | 136 | /* play the sound */ | ||
891 | 137 | g_debug("Playing '%s'", uri); | ||
892 | 138 | g_object_set(element, "uri", uri, NULL); | ||
893 | 139 | gst_element_set_state(element, GST_STATE_PLAYING); | ||
894 | 140 | } | ||
895 | 141 | |||
896 | 142 | /*** | ||
897 | 143 | **** Instantiation | ||
898 | 144 | ***/ | ||
899 | 145 | |||
900 | 146 | static void | ||
901 | 147 | indicator_power_sound_player_gst_class_init (IndicatorPowerSoundPlayerGSTClass * klass G_GNUC_UNUSED) | ||
902 | 148 | { | ||
903 | 149 | gst_init_once(); | ||
904 | 150 | } | ||
905 | 151 | |||
906 | 152 | static void | ||
907 | 153 | indicator_power_device_provider_interface_init (IndicatorPowerSoundPlayerInterface * iface) | ||
908 | 154 | { | ||
909 | 155 | iface->play_uri = my_play_uri; | ||
910 | 156 | } | ||
911 | 157 | |||
912 | 158 | static void | ||
913 | 159 | indicator_power_sound_player_gst_init (IndicatorPowerSoundPlayerGST * self G_GNUC_UNUSED) | ||
914 | 160 | { | ||
915 | 161 | } | ||
916 | 162 | |||
917 | 163 | /*** | ||
918 | 164 | **** Public API | ||
919 | 165 | ***/ | ||
920 | 166 | |||
921 | 167 | IndicatorPowerSoundPlayer * | ||
922 | 168 | indicator_power_sound_player_gst_new(void) | ||
923 | 169 | { | ||
924 | 170 | gpointer o = g_object_new (INDICATOR_TYPE_POWER_SOUND_PLAYER_GST, NULL); | ||
925 | 171 | |||
926 | 172 | return INDICATOR_POWER_SOUND_PLAYER (o); | ||
927 | 173 | } | ||
928 | 0 | 174 | ||
929 | === added file 'src/sound-player-gst.h' | |||
930 | --- src/sound-player-gst.h 1970-01-01 00:00:00 +0000 | |||
931 | +++ src/sound-player-gst.h 2016-01-04 20:26:17 +0000 | |||
932 | @@ -0,0 +1,70 @@ | |||
933 | 1 | /* | ||
934 | 2 | * Copyright 2016 Canonical Ltd. | ||
935 | 3 | * | ||
936 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
937 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
938 | 6 | * by the Free Software Foundation. | ||
939 | 7 | * | ||
940 | 8 | * This program is distributed in the hope that it will be useful, but | ||
941 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
942 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
943 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
944 | 12 | * | ||
945 | 13 | * You should have received a copy of the GNU General Public License along | ||
946 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
947 | 15 | * | ||
948 | 16 | * Authors: | ||
949 | 17 | * Charles Kerr <charles.kerr@canonical.com> | ||
950 | 18 | */ | ||
951 | 19 | |||
952 | 20 | #ifndef __INDICATOR_POWER_SOUND_PLAYER_GST__H__ | ||
953 | 21 | #define __INDICATOR_POWER_SOUND_PLAYER_GST__H__ | ||
954 | 22 | |||
955 | 23 | #include <glib-object.h> /* parent class */ | ||
956 | 24 | |||
957 | 25 | #include "device-provider.h" | ||
958 | 26 | |||
959 | 27 | G_BEGIN_DECLS | ||
960 | 28 | |||
961 | 29 | #define INDICATOR_TYPE_POWER_SOUND_PLAYER_GST \ | ||
962 | 30 | (indicator_power_sound_player_gst_get_type()) | ||
963 | 31 | |||
964 | 32 | #define INDICATOR_POWER_SOUND_PLAYER_GST(o) \ | ||
965 | 33 | (G_TYPE_CHECK_INSTANCE_CAST ((o), \ | ||
966 | 34 | INDICATOR_TYPE_POWER_SOUND_PLAYER_GST, \ | ||
967 | 35 | IndicatorPowerSoundPlayerGST)) | ||
968 | 36 | |||
969 | 37 | #define INDICATOR_POWER_SOUND_PLAYER_GST_GET_CLASS(o) \ | ||
970 | 38 | (G_TYPE_INSTANCE_GET_CLASS ((o), \ | ||
971 | 39 | INDICATOR_TYPE_POWER_SOUND_PLAYER_GST, \ | ||
972 | 40 | IndicatorPowerSoundPlayerGSTClass)) | ||
973 | 41 | |||
974 | 42 | #define INDICATOR_IS_POWER_SOUND_PLAYER_GST(o) \ | ||
975 | 43 | (G_TYPE_CHECK_INSTANCE_TYPE ((o), \ | ||
976 | 44 | INDICATOR_TYPE_POWER_SOUND_PLAYER_GST)) | ||
977 | 45 | |||
978 | 46 | typedef struct _IndicatorPowerSoundPlayerGST | ||
979 | 47 | IndicatorPowerSoundPlayerGST; | ||
980 | 48 | typedef struct _IndicatorPowerSoundPlayerGSTClass | ||
981 | 49 | IndicatorPowerSoundPlayerGSTClass; | ||
982 | 50 | |||
983 | 51 | /** | ||
984 | 52 | * An IndicatorPowerSoundPlayer which gets its devices from GST. | ||
985 | 53 | */ | ||
986 | 54 | struct _IndicatorPowerSoundPlayerGST | ||
987 | 55 | { | ||
988 | 56 | GObject parent_instance; | ||
989 | 57 | }; | ||
990 | 58 | |||
991 | 59 | struct _IndicatorPowerSoundPlayerGSTClass | ||
992 | 60 | { | ||
993 | 61 | GObjectClass parent_class; | ||
994 | 62 | }; | ||
995 | 63 | |||
996 | 64 | GType indicator_power_sound_player_gst_get_type (void); | ||
997 | 65 | |||
998 | 66 | IndicatorPowerSoundPlayer * indicator_power_sound_player_gst_new (void); | ||
999 | 67 | |||
1000 | 68 | G_END_DECLS | ||
1001 | 69 | |||
1002 | 70 | #endif /* __INDICATOR_POWER_SOUND_PLAYER_GST__H__ */ | ||
1003 | 0 | 71 | ||
1004 | === added file 'src/sound-player.c' | |||
1005 | --- src/sound-player.c 1970-01-01 00:00:00 +0000 | |||
1006 | +++ src/sound-player.c 2016-01-04 20:26:17 +0000 | |||
1007 | @@ -0,0 +1,45 @@ | |||
1008 | 1 | /* | ||
1009 | 2 | * Copyright 2016 Canonical Ltd. | ||
1010 | 3 | * | ||
1011 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
1012 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
1013 | 6 | * by the Free Software Foundation. | ||
1014 | 7 | * | ||
1015 | 8 | * This program is distributed in the hope that it will be useful, but | ||
1016 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1017 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1018 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
1019 | 12 | * | ||
1020 | 13 | * You should have received a copy of the GNU General Public License along | ||
1021 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1022 | 15 | * | ||
1023 | 16 | * Authors: | ||
1024 | 17 | * Charles Kerr <charles.kerr@canonical.com> | ||
1025 | 18 | */ | ||
1026 | 19 | |||
1027 | 20 | #include "sound-player.h" | ||
1028 | 21 | |||
1029 | 22 | G_DEFINE_INTERFACE (IndicatorPowerSoundPlayer, | ||
1030 | 23 | indicator_power_sound_player, | ||
1031 | 24 | 0) | ||
1032 | 25 | |||
1033 | 26 | static void | ||
1034 | 27 | indicator_power_sound_player_default_init (IndicatorPowerSoundPlayerInterface * klass G_GNUC_UNUSED) | ||
1035 | 28 | { | ||
1036 | 29 | } | ||
1037 | 30 | |||
1038 | 31 | /*** | ||
1039 | 32 | **** PUBLIC API | ||
1040 | 33 | ***/ | ||
1041 | 34 | |||
1042 | 35 | void | ||
1043 | 36 | indicator_power_sound_player_play_uri (IndicatorPowerSoundPlayer * self, | ||
1044 | 37 | const gchar * uri) | ||
1045 | 38 | { | ||
1046 | 39 | IndicatorPowerSoundPlayerInterface * iface; | ||
1047 | 40 | |||
1048 | 41 | g_return_if_fail (INDICATOR_IS_POWER_SOUND_PLAYER (self)); | ||
1049 | 42 | iface = INDICATOR_POWER_SOUND_PLAYER_GET_INTERFACE (self); | ||
1050 | 43 | g_return_if_fail (iface->play_uri != NULL); | ||
1051 | 44 | iface->play_uri (self, uri); | ||
1052 | 45 | } | ||
1053 | 0 | 46 | ||
1054 | === added file 'src/sound-player.h' | |||
1055 | --- src/sound-player.h 1970-01-01 00:00:00 +0000 | |||
1056 | +++ src/sound-player.h 2016-01-04 20:26:17 +0000 | |||
1057 | @@ -0,0 +1,72 @@ | |||
1058 | 1 | /* | ||
1059 | 2 | * Copyright 2016 Canonical Ltd. | ||
1060 | 3 | * | ||
1061 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
1062 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
1063 | 6 | * by the Free Software Foundation. | ||
1064 | 7 | * | ||
1065 | 8 | * This program is distributed in the hope that it will be useful, but | ||
1066 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1067 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1068 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
1069 | 12 | * | ||
1070 | 13 | * You should have received a copy of the GNU General Public License along | ||
1071 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1072 | 15 | * | ||
1073 | 16 | * Authors: | ||
1074 | 17 | * Charles Kerr <charles.kerr@canonical.com> | ||
1075 | 18 | */ | ||
1076 | 19 | |||
1077 | 20 | #ifndef __INDICATOR_POWER_SOUND_PLAYER__H__ | ||
1078 | 21 | #define __INDICATOR_POWER_SOUND_PLAYER__H__ | ||
1079 | 22 | |||
1080 | 23 | #include <glib-object.h> | ||
1081 | 24 | |||
1082 | 25 | G_BEGIN_DECLS | ||
1083 | 26 | |||
1084 | 27 | #define INDICATOR_TYPE_POWER_SOUND_PLAYER \ | ||
1085 | 28 | (indicator_power_sound_player_get_type ()) | ||
1086 | 29 | |||
1087 | 30 | #define INDICATOR_POWER_SOUND_PLAYER(obj) \ | ||
1088 | 31 | (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ | ||
1089 | 32 | INDICATOR_TYPE_POWER_SOUND_PLAYER, \ | ||
1090 | 33 | IndicatorPowerSoundPlayer)) | ||
1091 | 34 | |||
1092 | 35 | #define INDICATOR_IS_POWER_SOUND_PLAYER(obj) \ | ||
1093 | 36 | (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_TYPE_POWER_SOUND_PLAYER)) | ||
1094 | 37 | |||
1095 | 38 | #define INDICATOR_POWER_SOUND_PLAYER_GET_INTERFACE(inst) \ | ||
1096 | 39 | (G_TYPE_INSTANCE_GET_INTERFACE ((inst), \ | ||
1097 | 40 | INDICATOR_TYPE_POWER_SOUND_PLAYER, \ | ||
1098 | 41 | IndicatorPowerSoundPlayerInterface)) | ||
1099 | 42 | |||
1100 | 43 | typedef struct _IndicatorPowerSoundPlayer | ||
1101 | 44 | IndicatorPowerSoundPlayer; | ||
1102 | 45 | |||
1103 | 46 | typedef struct _IndicatorPowerSoundPlayerInterface | ||
1104 | 47 | IndicatorPowerSoundPlayerInterface; | ||
1105 | 48 | |||
1106 | 49 | /** | ||
1107 | 50 | * An interface class for an object that plays sounds. | ||
1108 | 51 | */ | ||
1109 | 52 | struct _IndicatorPowerSoundPlayerInterface | ||
1110 | 53 | { | ||
1111 | 54 | GTypeInterface parent_iface; | ||
1112 | 55 | |||
1113 | 56 | /* virtual functions */ | ||
1114 | 57 | void (*play_uri) (IndicatorPowerSoundPlayer * self, | ||
1115 | 58 | const gchar * uri); | ||
1116 | 59 | }; | ||
1117 | 60 | |||
1118 | 61 | GType indicator_power_sound_player_get_type (void); | ||
1119 | 62 | |||
1120 | 63 | /*** | ||
1121 | 64 | **** | ||
1122 | 65 | ***/ | ||
1123 | 66 | |||
1124 | 67 | void indicator_power_sound_player_play_uri (IndicatorPowerSoundPlayer * self, | ||
1125 | 68 | const gchar * uri); | ||
1126 | 69 | |||
1127 | 70 | G_END_DECLS | ||
1128 | 71 | |||
1129 | 72 | #endif /* __INDICATOR_POWER_SOUND_PLAYER__H__ */ | ||
1130 | 0 | 73 | ||
1131 | === modified file 'tests/CMakeLists.txt' | |||
1132 | --- tests/CMakeLists.txt 2014-10-10 21:11:36 +0000 | |||
1133 | +++ tests/CMakeLists.txt 2016-01-04 20:26:17 +0000 | |||
1134 | @@ -14,11 +14,23 @@ | |||
1135 | 14 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g ${C_WARNING_ARGS}") | 14 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g ${C_WARNING_ARGS}") |
1136 | 15 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-weak-vtables -Wno-global-constructors") # Google Test | 15 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-weak-vtables -Wno-global-constructors") # Google Test |
1137 | 16 | 16 | ||
1138 | 17 | # build the mocks | ||
1139 | 18 | set(MOCK_LIB "indicatorpowerservicemocks") | ||
1140 | 19 | set(MOCK_SOURCES sound-player-mock.c) | ||
1141 | 20 | set_source_files_properties(${MOCK_SOURCES} | ||
1142 | 21 | PROPERTIES COMPILE_FLAGS "${C_WARNING_ARGS} -g -std=c99") | ||
1143 | 22 | add_library(${MOCK_LIB} STATIC ${MOCK_SOURCES}) | ||
1144 | 23 | |||
1145 | 17 | # build the necessary schemas | 24 | # build the necessary schemas |
1146 | 18 | set_directory_properties (PROPERTIES | 25 | set_directory_properties (PROPERTIES |
1147 | 19 | ADDITIONAL_MAKE_CLEAN_FILES gschemas.compiled) | 26 | ADDITIONAL_MAKE_CLEAN_FILES gschemas.compiled) |
1148 | 20 | set_source_files_properties (gschemas.compiled GENERATED) | 27 | set_source_files_properties (gschemas.compiled GENERATED) |
1149 | 21 | 28 | ||
1150 | 29 | # make a XDG_DATA_HOME for sounds/ | ||
1151 | 30 | set(XDG_DATA_HOME "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}") | ||
1152 | 31 | add_definitions(-DXDG_DATA_HOME="${XDG_DATA_HOME}") | ||
1153 | 32 | file(COPY "${CMAKE_SOURCE_DIR}/data/sounds" DESTINATION "${XDG_DATA_HOME}/${CMAKE_PROJECT_NAME}") | ||
1154 | 33 | |||
1155 | 22 | # GSettings: | 34 | # GSettings: |
1156 | 23 | # compile the indicator-power schema into a gschemas.compiled file in this directory, | 35 | # compile the indicator-power schema into a gschemas.compiled file in this directory, |
1157 | 24 | # and help the tests to find that file by setting -DSCHEMA_DIR | 36 | # and help the tests to find that file by setting -DSCHEMA_DIR |
1158 | @@ -44,8 +56,8 @@ | |||
1159 | 44 | set (TEST_NAME ${name}) | 56 | set (TEST_NAME ${name}) |
1160 | 45 | add_executable (${TEST_NAME} ${TEST_NAME}.cc gschemas.compiled) | 57 | add_executable (${TEST_NAME} ${TEST_NAME}.cc gschemas.compiled) |
1161 | 46 | add_test (${TEST_NAME} ${TEST_NAME}) | 58 | add_test (${TEST_NAME} ${TEST_NAME}) |
1164 | 47 | add_dependencies (${TEST_NAME} libindicatorpowerservice) | 59 | add_dependencies (${TEST_NAME} ${MOCK_LIB} libindicatorpowerservice) |
1165 | 48 | target_link_libraries (${TEST_NAME} indicatorpowerservice gtest ${DBUSTEST_LIBRARIES} ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBS}) | 60 | target_link_libraries (${TEST_NAME} ${MOCK_LIB} indicatorpowerservice gtest ${DBUSTEST_LIBRARIES} ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBS}) |
1166 | 49 | endfunction() | 61 | endfunction() |
1167 | 50 | add_test_by_name(test-notify) | 62 | add_test_by_name(test-notify) |
1168 | 51 | add_test(NAME dear-reader-the-next-test-takes-80-seconds COMMAND true) | 63 | add_test(NAME dear-reader-the-next-test-takes-80-seconds COMMAND true) |
1169 | 52 | 64 | ||
1170 | === modified file 'tests/glib-fixture.h' | |||
1171 | --- tests/glib-fixture.h 2014-09-08 04:56:10 +0000 | |||
1172 | +++ tests/glib-fixture.h 2016-01-04 20:26:17 +0000 | |||
1173 | @@ -52,7 +52,7 @@ | |||
1174 | 52 | 52 | ||
1175 | 53 | if (expected_log[level] != n) | 53 | if (expected_log[level] != n) |
1176 | 54 | for (size_t i=0; i<n; ++i) | 54 | for (size_t i=0; i<n; ++i) |
1178 | 55 | g_print("%d %s\n", (n+1), v[i].c_str()); | 55 | g_print("%d %s\n", int(n+1), v[i].c_str()); |
1179 | 56 | } | 56 | } |
1180 | 57 | 57 | ||
1181 | 58 | expected_log.clear(); | 58 | expected_log.clear(); |
1182 | 59 | 59 | ||
1183 | === added file 'tests/sound-player-mock.c' | |||
1184 | --- tests/sound-player-mock.c 1970-01-01 00:00:00 +0000 | |||
1185 | +++ tests/sound-player-mock.c 2016-01-04 20:26:17 +0000 | |||
1186 | @@ -0,0 +1,94 @@ | |||
1187 | 1 | /* | ||
1188 | 2 | * Copyright 2016 Canonical Ltd. | ||
1189 | 3 | * | ||
1190 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
1191 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
1192 | 6 | * by the Free Software Foundation. | ||
1193 | 7 | * | ||
1194 | 8 | * This program is distributed in the hope that it will be useful, but | ||
1195 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1196 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1197 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
1198 | 12 | * | ||
1199 | 13 | * You should have received a copy of the GNU General Public License along | ||
1200 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1201 | 15 | * | ||
1202 | 16 | * Authors: | ||
1203 | 17 | * Charles Kerr <charles.kerr@canonical.com> | ||
1204 | 18 | */ | ||
1205 | 19 | |||
1206 | 20 | #include "sound-player.h" | ||
1207 | 21 | #include "sound-player-mock.h" | ||
1208 | 22 | |||
1209 | 23 | enum | ||
1210 | 24 | { | ||
1211 | 25 | SIGNAL_URI_PLAYED, | ||
1212 | 26 | LAST_SIGNAL | ||
1213 | 27 | }; | ||
1214 | 28 | |||
1215 | 29 | static guint signals[LAST_SIGNAL] = { 0 }; | ||
1216 | 30 | |||
1217 | 31 | /*** | ||
1218 | 32 | **** GObject boilerplate | ||
1219 | 33 | ***/ | ||
1220 | 34 | |||
1221 | 35 | static void indicator_power_sound_player_interface_init ( | ||
1222 | 36 | IndicatorPowerSoundPlayerInterface * iface); | ||
1223 | 37 | |||
1224 | 38 | G_DEFINE_TYPE_WITH_CODE ( | ||
1225 | 39 | IndicatorPowerSoundPlayerMock, | ||
1226 | 40 | indicator_power_sound_player_mock, | ||
1227 | 41 | G_TYPE_OBJECT, | ||
1228 | 42 | G_IMPLEMENT_INTERFACE (INDICATOR_TYPE_POWER_SOUND_PLAYER, | ||
1229 | 43 | indicator_power_sound_player_interface_init)) | ||
1230 | 44 | |||
1231 | 45 | /*** | ||
1232 | 46 | **** IndicatorPowerSoundPlayer virtual functions | ||
1233 | 47 | ***/ | ||
1234 | 48 | |||
1235 | 49 | static void | ||
1236 | 50 | my_play_uri (IndicatorPowerSoundPlayer * self, const gchar * uri) | ||
1237 | 51 | { | ||
1238 | 52 | g_signal_emit (self, signals[SIGNAL_URI_PLAYED], 0, uri, NULL); | ||
1239 | 53 | } | ||
1240 | 54 | |||
1241 | 55 | /*** | ||
1242 | 56 | **** Instantiation | ||
1243 | 57 | ***/ | ||
1244 | 58 | |||
1245 | 59 | static void | ||
1246 | 60 | indicator_power_sound_player_mock_class_init (IndicatorPowerSoundPlayerMockClass * klass G_GNUC_UNUSED) | ||
1247 | 61 | { | ||
1248 | 62 | signals[SIGNAL_URI_PLAYED] = g_signal_new ( | ||
1249 | 63 | "uri-played", | ||
1250 | 64 | G_TYPE_FROM_CLASS(klass), | ||
1251 | 65 | G_SIGNAL_RUN_LAST, | ||
1252 | 66 | G_STRUCT_OFFSET (IndicatorPowerSoundPlayerMockClass, uri_played), | ||
1253 | 67 | NULL, NULL, | ||
1254 | 68 | g_cclosure_marshal_VOID__STRING, | ||
1255 | 69 | G_TYPE_NONE, 1, G_TYPE_STRING); | ||
1256 | 70 | } | ||
1257 | 71 | |||
1258 | 72 | static void | ||
1259 | 73 | indicator_power_sound_player_interface_init (IndicatorPowerSoundPlayerInterface * iface) | ||
1260 | 74 | { | ||
1261 | 75 | iface->play_uri = my_play_uri; | ||
1262 | 76 | } | ||
1263 | 77 | |||
1264 | 78 | static void | ||
1265 | 79 | indicator_power_sound_player_mock_init (IndicatorPowerSoundPlayerMock * self G_GNUC_UNUSED) | ||
1266 | 80 | { | ||
1267 | 81 | } | ||
1268 | 82 | |||
1269 | 83 | /*** | ||
1270 | 84 | **** Public API | ||
1271 | 85 | ***/ | ||
1272 | 86 | |||
1273 | 87 | IndicatorPowerSoundPlayer * | ||
1274 | 88 | indicator_power_sound_player_mock_new (void) | ||
1275 | 89 | { | ||
1276 | 90 | gpointer o = g_object_new (INDICATOR_TYPE_POWER_SOUND_PLAYER_MOCK, NULL); | ||
1277 | 91 | |||
1278 | 92 | return INDICATOR_POWER_SOUND_PLAYER (o); | ||
1279 | 93 | } | ||
1280 | 94 | |||
1281 | 0 | 95 | ||
1282 | === added file 'tests/sound-player-mock.h' | |||
1283 | --- tests/sound-player-mock.h 1970-01-01 00:00:00 +0000 | |||
1284 | +++ tests/sound-player-mock.h 2016-01-04 20:26:17 +0000 | |||
1285 | @@ -0,0 +1,75 @@ | |||
1286 | 1 | /* | ||
1287 | 2 | * Copyright 2016 Canonical Ltd. | ||
1288 | 3 | * | ||
1289 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
1290 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
1291 | 6 | * by the Free Software Foundation. | ||
1292 | 7 | * | ||
1293 | 8 | * This program is distributed in the hope that it will be useful, but | ||
1294 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1295 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1296 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
1297 | 12 | * | ||
1298 | 13 | * You should have received a copy of the GNU General Public License along | ||
1299 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1300 | 15 | * | ||
1301 | 16 | * Authors: | ||
1302 | 17 | * Charles Kerr <charles.kerr@canonical.com> | ||
1303 | 18 | */ | ||
1304 | 19 | |||
1305 | 20 | #ifndef __INDICATOR_POWER_SOUND_PLAYER_MOCK__H__ | ||
1306 | 21 | #define __INDICATOR_POWER_SOUND_PLAYER_MOCK__H__ | ||
1307 | 22 | |||
1308 | 23 | #include <glib-object.h> /* parent class */ | ||
1309 | 24 | |||
1310 | 25 | #include "sound-player.h" | ||
1311 | 26 | |||
1312 | 27 | G_BEGIN_DECLS | ||
1313 | 28 | |||
1314 | 29 | #define INDICATOR_TYPE_POWER_SOUND_PLAYER_MOCK \ | ||
1315 | 30 | (indicator_power_sound_player_mock_get_type()) | ||
1316 | 31 | |||
1317 | 32 | #define INDICATOR_POWER_SOUND_PLAYER_MOCK(o) \ | ||
1318 | 33 | (G_TYPE_CHECK_INSTANCE_CAST ((o), \ | ||
1319 | 34 | INDICATOR_TYPE_POWER_SOUND_PLAYER_MOCK, \ | ||
1320 | 35 | IndicatorPowerSoundPlayerMock)) | ||
1321 | 36 | |||
1322 | 37 | #define INDICATOR_POWER_SOUND_PLAYER_MOCK_GET_CLASS(o) \ | ||
1323 | 38 | (G_TYPE_INSTANCE_GET_CLASS ((o), \ | ||
1324 | 39 | INDICATOR_TYPE_POWER_SOUND_PLAYER_MOCK, \ | ||
1325 | 40 | IndicatorPowerSoundPlayerMockClass)) | ||
1326 | 41 | |||
1327 | 42 | #define INDICATOR_IS_POWER_SOUND_PLAYER_MOCK(o) \ | ||
1328 | 43 | (G_TYPE_CHECK_INSTANCE_TYPE ((o), \ | ||
1329 | 44 | INDICATOR_TYPE_POWER_SOUND_PLAYER_MOCK)) | ||
1330 | 45 | |||
1331 | 46 | typedef struct _IndicatorPowerSoundPlayerMock | ||
1332 | 47 | IndicatorPowerSoundPlayerMock; | ||
1333 | 48 | typedef struct _IndicatorPowerSoundPlayerMockPriv | ||
1334 | 49 | IndicatorPowerSoundPlayerMockPriv; | ||
1335 | 50 | typedef struct _IndicatorPowerSoundPlayerMockClass | ||
1336 | 51 | IndicatorPowerSoundPlayerMockClass; | ||
1337 | 52 | |||
1338 | 53 | /** | ||
1339 | 54 | * An IndicatorPowerSoundPlayer which gets its devices from Mock. | ||
1340 | 55 | */ | ||
1341 | 56 | struct _IndicatorPowerSoundPlayerMock | ||
1342 | 57 | { | ||
1343 | 58 | GObject parent_instance; | ||
1344 | 59 | }; | ||
1345 | 60 | |||
1346 | 61 | struct _IndicatorPowerSoundPlayerMockClass | ||
1347 | 62 | { | ||
1348 | 63 | GObjectClass parent_class; | ||
1349 | 64 | |||
1350 | 65 | /* signals */ | ||
1351 | 66 | void (*uri_played) (IndicatorPowerSoundPlayer * self, const gchar* uri); | ||
1352 | 67 | }; | ||
1353 | 68 | |||
1354 | 69 | GType indicator_power_sound_player_mock_get_type (void); | ||
1355 | 70 | |||
1356 | 71 | IndicatorPowerSoundPlayer * indicator_power_sound_player_mock_new (void); | ||
1357 | 72 | |||
1358 | 73 | G_END_DECLS | ||
1359 | 74 | |||
1360 | 75 | #endif /* __INDICATOR_POWER_SOUND_PLAYER_MOCK__H__ */ | ||
1361 | 0 | 76 | ||
1362 | === modified file 'tests/test-notify.cc' | |||
1363 | --- tests/test-notify.cc 2014-09-08 04:56:10 +0000 | |||
1364 | +++ tests/test-notify.cc 2016-01-04 20:26:17 +0000 | |||
1365 | @@ -1,5 +1,5 @@ | |||
1366 | 1 | /* | 1 | /* |
1368 | 2 | * Copyright 2014 Canonical Ltd. | 2 | * Copyright 2014-2016 Canonical Ltd. |
1369 | 3 | * | 3 | * |
1370 | 4 | * This program is free software: you can redistribute it and/or modify it | 4 | * This program is free software: you can redistribute it and/or modify it |
1371 | 5 | * under the terms of the GNU General Public License version 3, as published | 5 | * under the terms of the GNU General Public License version 3, as published |
1372 | @@ -23,6 +23,7 @@ | |||
1373 | 23 | #include "dbus-shared.h" | 23 | #include "dbus-shared.h" |
1374 | 24 | #include "device.h" | 24 | #include "device.h" |
1375 | 25 | #include "notifier.h" | 25 | #include "notifier.h" |
1376 | 26 | #include "sound-player-mock.h" | ||
1377 | 26 | 27 | ||
1378 | 27 | #include <gtest/gtest.h> | 28 | #include <gtest/gtest.h> |
1379 | 28 | 29 | ||
1380 | @@ -77,6 +78,8 @@ | |||
1381 | 77 | { | 78 | { |
1382 | 78 | super::SetUp(); | 79 | super::SetUp(); |
1383 | 79 | 80 | ||
1384 | 81 | g_setenv ("XDG_DATA_HOME", XDG_DATA_HOME, TRUE); | ||
1385 | 82 | |||
1386 | 80 | // init DBusMock / dbus-test-runner | 83 | // init DBusMock / dbus-test-runner |
1387 | 81 | 84 | ||
1388 | 82 | service = dbus_test_service_new(nullptr); | 85 | service = dbus_test_service_new(nullptr); |
1389 | @@ -273,7 +276,8 @@ | |||
1390 | 273 | 276 | ||
1391 | 274 | // set up a notifier and give it the battery so changing the battery's | 277 | // set up a notifier and give it the battery so changing the battery's |
1392 | 275 | // charge should show up on the bus. | 278 | // charge should show up on the bus. |
1394 | 276 | auto notifier = indicator_power_notifier_new (); | 279 | auto sound_player = indicator_power_sound_player_mock_new (); |
1395 | 280 | auto notifier = indicator_power_notifier_new (sound_player); | ||
1396 | 277 | indicator_power_notifier_set_battery (notifier, battery); | 281 | indicator_power_notifier_set_battery (notifier, battery); |
1397 | 278 | indicator_power_notifier_set_bus (notifier, bus); | 282 | indicator_power_notifier_set_bus (notifier, bus); |
1398 | 279 | wait_msec(); | 283 | wait_msec(); |
1399 | @@ -315,14 +319,23 @@ | |||
1400 | 315 | 319 | ||
1401 | 316 | // cleanup | 320 | // cleanup |
1402 | 317 | g_dbus_connection_signal_unsubscribe (bus, sub_tag); | 321 | g_dbus_connection_signal_unsubscribe (bus, sub_tag); |
1403 | 322 | g_object_unref (battery); | ||
1404 | 318 | g_object_unref (notifier); | 323 | g_object_unref (notifier); |
1406 | 319 | g_object_unref (battery); | 324 | g_object_unref (sound_player); |
1407 | 320 | } | 325 | } |
1408 | 321 | 326 | ||
1409 | 322 | /*** | 327 | /*** |
1410 | 323 | **** | 328 | **** |
1411 | 324 | ***/ | 329 | ***/ |
1412 | 325 | 330 | ||
1413 | 331 | namespace | ||
1414 | 332 | { | ||
1415 | 333 | static void on_uri_played(IndicatorPowerSoundPlayer*, const char* uri, gpointer glast_uri) | ||
1416 | 334 | { | ||
1417 | 335 | *static_cast<std::string*>(glast_uri) = uri; | ||
1418 | 336 | } | ||
1419 | 337 | } | ||
1420 | 338 | |||
1421 | 326 | TEST_F(NotifyFixture, EventsThatChangeNotifications) | 339 | TEST_F(NotifyFixture, EventsThatChangeNotifications) |
1422 | 327 | { | 340 | { |
1423 | 328 | // GetCapabilities returns an array containing 'actions', so that we'll | 341 | // GetCapabilities returns an array containing 'actions', so that we'll |
1424 | @@ -343,9 +356,18 @@ | |||
1425 | 343 | UP_DEVICE_STATE_DISCHARGING, | 356 | UP_DEVICE_STATE_DISCHARGING, |
1426 | 344 | 30); | 357 | 30); |
1427 | 345 | 358 | ||
1428 | 359 | // the file we expect to play on a low battery notification... | ||
1429 | 360 | const char* expected_file = XDG_DATA_HOME "/" GETTEXT_PACKAGE "/sounds/" LOW_BATTERY_SOUND; | ||
1430 | 361 | char* tmp = g_filename_to_uri(expected_file, nullptr, nullptr); | ||
1431 | 362 | const std::string low_power_uri {tmp}; | ||
1432 | 363 | g_clear_pointer(&tmp, g_free); | ||
1433 | 364 | |||
1434 | 346 | // set up a notifier and give it the battery so changing the battery's | 365 | // set up a notifier and give it the battery so changing the battery's |
1435 | 347 | // charge should show up on the bus. | 366 | // charge should show up on the bus. |
1437 | 348 | auto notifier = indicator_power_notifier_new (); | 367 | std::string last_uri; |
1438 | 368 | auto sound_player = indicator_power_sound_player_mock_new (); | ||
1439 | 369 | g_signal_connect(sound_player, "uri-played", G_CALLBACK(on_uri_played), &last_uri); | ||
1440 | 370 | auto notifier = indicator_power_notifier_new (sound_player); | ||
1441 | 349 | indicator_power_notifier_set_battery (notifier, battery); | 371 | indicator_power_notifier_set_battery (notifier, battery); |
1442 | 350 | indicator_power_notifier_set_bus (notifier, bus); | 372 | indicator_power_notifier_set_bus (notifier, bus); |
1443 | 351 | ChangedParams changed_params; | 373 | ChangedParams changed_params; |
1444 | @@ -363,6 +385,7 @@ | |||
1445 | 363 | // test setup case | 385 | // test setup case |
1446 | 364 | wait_msec(); | 386 | wait_msec(); |
1447 | 365 | EXPECT_STREQ (POWER_LEVEL_STR_OK, changed_params.power_level.c_str()); | 387 | EXPECT_STREQ (POWER_LEVEL_STR_OK, changed_params.power_level.c_str()); |
1448 | 388 | EXPECT_TRUE(last_uri.empty()); | ||
1449 | 366 | 389 | ||
1450 | 367 | // change the percent past the 'low' threshold and confirm that | 390 | // change the percent past the 'low' threshold and confirm that |
1451 | 368 | // a) the power level changes | 391 | // a) the power level changes |
1452 | @@ -373,38 +396,48 @@ | |||
1453 | 373 | EXPECT_EQ (FIELD_POWER_LEVEL|FIELD_IS_WARNING, changed_params.fields); | 396 | EXPECT_EQ (FIELD_POWER_LEVEL|FIELD_IS_WARNING, changed_params.fields); |
1454 | 374 | EXPECT_EQ (indicator_power_notifier_get_power_level(battery), changed_params.power_level); | 397 | EXPECT_EQ (indicator_power_notifier_get_power_level(battery), changed_params.power_level); |
1455 | 375 | EXPECT_TRUE (changed_params.is_warning); | 398 | EXPECT_TRUE (changed_params.is_warning); |
1456 | 399 | EXPECT_EQ (low_power_uri, last_uri); | ||
1457 | 376 | 400 | ||
1458 | 377 | // now test that the warning changes if the level goes down even lower... | 401 | // now test that the warning changes if the level goes down even lower... |
1459 | 402 | last_uri.clear(); | ||
1460 | 378 | changed_params = ChangedParams(); | 403 | changed_params = ChangedParams(); |
1461 | 379 | set_battery_percentage (battery, percent_very_low); | 404 | set_battery_percentage (battery, percent_very_low); |
1462 | 380 | wait_msec(); | 405 | wait_msec(); |
1463 | 381 | EXPECT_EQ (FIELD_POWER_LEVEL, changed_params.fields); | 406 | EXPECT_EQ (FIELD_POWER_LEVEL, changed_params.fields); |
1464 | 382 | EXPECT_STREQ (POWER_LEVEL_STR_VERY_LOW, changed_params.power_level.c_str()); | 407 | EXPECT_STREQ (POWER_LEVEL_STR_VERY_LOW, changed_params.power_level.c_str()); |
1465 | 408 | EXPECT_EQ (low_power_uri, last_uri); | ||
1466 | 383 | 409 | ||
1467 | 384 | // ...and that the warning is taken down if the battery is plugged back in... | 410 | // ...and that the warning is taken down if the battery is plugged back in... |
1468 | 411 | last_uri.clear(); | ||
1469 | 385 | changed_params = ChangedParams(); | 412 | changed_params = ChangedParams(); |
1470 | 386 | g_object_set (battery, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, nullptr); | 413 | g_object_set (battery, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, nullptr); |
1471 | 387 | wait_msec(); | 414 | wait_msec(); |
1472 | 388 | EXPECT_EQ (FIELD_IS_WARNING, changed_params.fields); | 415 | EXPECT_EQ (FIELD_IS_WARNING, changed_params.fields); |
1473 | 389 | EXPECT_FALSE (changed_params.is_warning); | 416 | EXPECT_FALSE (changed_params.is_warning); |
1474 | 417 | EXPECT_TRUE(last_uri.empty()); | ||
1475 | 390 | 418 | ||
1476 | 391 | // ...and that it comes back if we unplug again... | 419 | // ...and that it comes back if we unplug again... |
1477 | 420 | last_uri.clear(); | ||
1478 | 392 | changed_params = ChangedParams(); | 421 | changed_params = ChangedParams(); |
1479 | 393 | g_object_set (battery, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, nullptr); | 422 | g_object_set (battery, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, nullptr); |
1480 | 394 | wait_msec(); | 423 | wait_msec(); |
1481 | 395 | EXPECT_EQ (FIELD_IS_WARNING, changed_params.fields); | 424 | EXPECT_EQ (FIELD_IS_WARNING, changed_params.fields); |
1482 | 396 | EXPECT_TRUE (changed_params.is_warning); | 425 | EXPECT_TRUE (changed_params.is_warning); |
1483 | 426 | EXPECT_EQ (low_power_uri, last_uri); | ||
1484 | 397 | 427 | ||
1485 | 398 | // ...and that it's taken down if the power level is OK | 428 | // ...and that it's taken down if the power level is OK |
1486 | 429 | last_uri.clear(); | ||
1487 | 399 | changed_params = ChangedParams(); | 430 | changed_params = ChangedParams(); |
1488 | 400 | set_battery_percentage (battery, percent_low+1); | 431 | set_battery_percentage (battery, percent_low+1); |
1489 | 401 | wait_msec(); | 432 | wait_msec(); |
1490 | 402 | EXPECT_EQ (FIELD_POWER_LEVEL|FIELD_IS_WARNING, changed_params.fields); | 433 | EXPECT_EQ (FIELD_POWER_LEVEL|FIELD_IS_WARNING, changed_params.fields); |
1491 | 403 | EXPECT_STREQ (POWER_LEVEL_STR_OK, changed_params.power_level.c_str()); | 434 | EXPECT_STREQ (POWER_LEVEL_STR_OK, changed_params.power_level.c_str()); |
1492 | 404 | EXPECT_FALSE (changed_params.is_warning); | 435 | EXPECT_FALSE (changed_params.is_warning); |
1493 | 436 | EXPECT_TRUE(last_uri.empty()); | ||
1494 | 405 | 437 | ||
1495 | 406 | // cleanup | 438 | // cleanup |
1496 | 407 | g_dbus_connection_signal_unsubscribe (bus, sub_tag); | 439 | g_dbus_connection_signal_unsubscribe (bus, sub_tag); |
1497 | 408 | g_object_unref (notifier); | 440 | g_object_unref (notifier); |
1498 | 409 | g_object_unref (battery); | 441 | g_object_unref (battery); |
1499 | 442 | g_object_unref (sound_player); | ||
1500 | 410 | } | 443 | } |
It seems you don't have <email address hidden> registered with LP, that makes it not associate the commits with your UID.
Little fixes. Seems big, but lots of boilerplate, we need to get this indicator converted to C++11 ;-)