Merge lp:~psusi/ubuntu/natty/gnome-power-manager/fix-duplicate-battery into lp:ubuntu/natty/gnome-power-manager
- Natty (11.04)
- fix-duplicate-battery
- Merge into natty
Proposed by
Phillip Susi
Status: | Merged |
---|---|
Merge reported by: | Phillip Susi |
Merged at revision: | not available |
Proposed branch: | lp:~psusi/ubuntu/natty/gnome-power-manager/fix-duplicate-battery |
Merge into: | lp:ubuntu/natty/gnome-power-manager |
Diff against target: |
1358 lines (+1308/-3) 6 files modified
.pc/16-fix-duplicate-battery.patch/src/gpm-engine.c (+1277/-0) .pc/applied-patches (+1/-0) debian/changelog (+8/-0) debian/patches/16-fix-duplicate-battery.patch (+20/-0) debian/patches/series (+2/-0) src/gpm-engine.c (+0/-3) |
To merge this branch: | bzr merge lp:~psusi/ubuntu/natty/gnome-power-manager/fix-duplicate-battery |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Marc Deslauriers | Approve | ||
Michele Damiano Torelli (community) | Approve | ||
Luke Yelavich | Pending | ||
Ubuntu branches | Pending | ||
Review via email: mp+67466@code.launchpad.net |
This proposal supersedes a proposal from 2011-06-26.
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Luke Yelavich (themuso) wrote : Posted in a previous version of this proposal | # |
review:
Needs Fixing
Revision history for this message
Michele Damiano Torelli (s3th) : | # |
review:
Approve
Revision history for this message
Marc Deslauriers (mdeslaur) wrote : | # |
This looks good. I've uploaded it to -proposed with a simple change to debian/changelog to use a better version number, and to specify the right pocket.
Thanks!
review:
Approve
Revision history for this message
Scott Moser (smoser) wrote : | # |
If you are able to, please mark this as Merged.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added directory '.pc/16-fix-duplicate-battery.patch' | |||
2 | === added file '.pc/16-fix-duplicate-battery.patch/.timestamp' | |||
3 | === added directory '.pc/16-fix-duplicate-battery.patch/src' | |||
4 | === added file '.pc/16-fix-duplicate-battery.patch/src/gpm-engine.c' | |||
5 | --- .pc/16-fix-duplicate-battery.patch/src/gpm-engine.c 1970-01-01 00:00:00 +0000 | |||
6 | +++ .pc/16-fix-duplicate-battery.patch/src/gpm-engine.c 2011-07-10 20:29:23 +0000 | |||
7 | @@ -0,0 +1,1277 @@ | |||
8 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- | ||
9 | 2 | * | ||
10 | 3 | * Copyright (C) 2007-2008 Richard Hughes <richard@hughsie.com> | ||
11 | 4 | * | ||
12 | 5 | * Licensed under the GNU General Public License Version 2 | ||
13 | 6 | * | ||
14 | 7 | * This program is free software; you can redistribute it and/or modify | ||
15 | 8 | * it under the terms of the GNU General Public License as published by | ||
16 | 9 | * the Free Software Foundation; either version 2 of the License, or | ||
17 | 10 | * (at your option) any later version. | ||
18 | 11 | * | ||
19 | 12 | * This program is distributed in the hope that it will be useful, | ||
20 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
21 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
22 | 15 | * GNU General Public License for more details. | ||
23 | 16 | * | ||
24 | 17 | * You should have received a copy of the GNU General Public License | ||
25 | 18 | * along with this program; if not, write to the Free Software | ||
26 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
27 | 20 | */ | ||
28 | 21 | |||
29 | 22 | #include "config.h" | ||
30 | 23 | |||
31 | 24 | #include <string.h> | ||
32 | 25 | #include <glib.h> | ||
33 | 26 | #include <glib/gi18n.h> | ||
34 | 27 | #include <gconf/gconf-client.h> | ||
35 | 28 | #include <libupower-glib/upower.h> | ||
36 | 29 | |||
37 | 30 | #include "egg-debug.h" | ||
38 | 31 | |||
39 | 32 | #include "gpm-common.h" | ||
40 | 33 | #include "gpm-upower.h" | ||
41 | 34 | #include "gpm-marshal.h" | ||
42 | 35 | #include "gpm-engine.h" | ||
43 | 36 | #include "gpm-stock-icons.h" | ||
44 | 37 | #include "gpm-prefs-server.h" | ||
45 | 38 | #include "gpm-phone.h" | ||
46 | 39 | |||
47 | 40 | static void gpm_engine_finalize (GObject *object); | ||
48 | 41 | |||
49 | 42 | #define GPM_ENGINE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPM_TYPE_ENGINE, GpmEnginePrivate)) | ||
50 | 43 | #define GPM_ENGINE_RESUME_DELAY 2*1000 | ||
51 | 44 | #define GPM_ENGINE_WARN_ACCURACY 20 | ||
52 | 45 | |||
53 | 46 | struct GpmEnginePrivate | ||
54 | 47 | { | ||
55 | 48 | GConfClient *conf; | ||
56 | 49 | UpClient *client; | ||
57 | 50 | UpDevice *battery_composite; | ||
58 | 51 | GPtrArray *array; | ||
59 | 52 | GpmPhone *phone; | ||
60 | 53 | GpmIconPolicy icon_policy; | ||
61 | 54 | gchar *previous_icon; | ||
62 | 55 | gchar *previous_summary; | ||
63 | 56 | |||
64 | 57 | gboolean use_time_primary; | ||
65 | 58 | gboolean time_is_accurate; | ||
66 | 59 | |||
67 | 60 | guint low_percentage; | ||
68 | 61 | guint critical_percentage; | ||
69 | 62 | guint action_percentage; | ||
70 | 63 | guint low_time; | ||
71 | 64 | guint critical_time; | ||
72 | 65 | guint action_time; | ||
73 | 66 | }; | ||
74 | 67 | |||
75 | 68 | enum { | ||
76 | 69 | ICON_CHANGED, | ||
77 | 70 | SUMMARY_CHANGED, | ||
78 | 71 | FULLY_CHARGED, | ||
79 | 72 | CHARGE_LOW, | ||
80 | 73 | CHARGE_CRITICAL, | ||
81 | 74 | CHARGE_ACTION, | ||
82 | 75 | DISCHARGING, | ||
83 | 76 | LOW_CAPACITY, | ||
84 | 77 | PERHAPS_RECALL, | ||
85 | 78 | DEVICES_CHANGED, | ||
86 | 79 | LAST_SIGNAL | ||
87 | 80 | }; | ||
88 | 81 | |||
89 | 82 | static guint signals [LAST_SIGNAL] = { 0 }; | ||
90 | 83 | static gpointer gpm_engine_object = NULL; | ||
91 | 84 | |||
92 | 85 | G_DEFINE_TYPE (GpmEngine, gpm_engine, G_TYPE_OBJECT) | ||
93 | 86 | |||
94 | 87 | static UpDevice *gpm_engine_get_composite_device (GpmEngine *engine, UpDevice *original_device); | ||
95 | 88 | static UpDevice *gpm_engine_update_composite_device (GpmEngine *engine, UpDevice *original_device); | ||
96 | 89 | |||
97 | 90 | typedef enum { | ||
98 | 91 | GPM_ENGINE_WARNING_NONE = 0, | ||
99 | 92 | GPM_ENGINE_WARNING_DISCHARGING = 1, | ||
100 | 93 | GPM_ENGINE_WARNING_LOW = 2, | ||
101 | 94 | GPM_ENGINE_WARNING_CRITICAL = 3, | ||
102 | 95 | GPM_ENGINE_WARNING_ACTION = 4 | ||
103 | 96 | } GpmEngineWarning; | ||
104 | 97 | |||
105 | 98 | /** | ||
106 | 99 | * gpm_engine_get_warning_csr: | ||
107 | 100 | **/ | ||
108 | 101 | static GpmEngineWarning | ||
109 | 102 | gpm_engine_get_warning_csr (GpmEngine *engine, UpDevice *device) | ||
110 | 103 | { | ||
111 | 104 | gdouble percentage; | ||
112 | 105 | |||
113 | 106 | /* get device properties */ | ||
114 | 107 | g_object_get (device, "percentage", &percentage, NULL); | ||
115 | 108 | |||
116 | 109 | if (percentage < 26.0f) | ||
117 | 110 | return GPM_ENGINE_WARNING_LOW; | ||
118 | 111 | else if (percentage < 13.0f) | ||
119 | 112 | return GPM_ENGINE_WARNING_CRITICAL; | ||
120 | 113 | return GPM_ENGINE_WARNING_NONE; | ||
121 | 114 | } | ||
122 | 115 | |||
123 | 116 | /** | ||
124 | 117 | * gpm_engine_get_warning_percentage: | ||
125 | 118 | **/ | ||
126 | 119 | static GpmEngineWarning | ||
127 | 120 | gpm_engine_get_warning_percentage (GpmEngine *engine, UpDevice *device) | ||
128 | 121 | { | ||
129 | 122 | gdouble percentage; | ||
130 | 123 | |||
131 | 124 | /* get device properties */ | ||
132 | 125 | g_object_get (device, "percentage", &percentage, NULL); | ||
133 | 126 | |||
134 | 127 | if (percentage <= engine->priv->action_percentage) | ||
135 | 128 | return GPM_ENGINE_WARNING_ACTION; | ||
136 | 129 | if (percentage <= engine->priv->critical_percentage) | ||
137 | 130 | return GPM_ENGINE_WARNING_CRITICAL; | ||
138 | 131 | if (percentage <= engine->priv->low_percentage) | ||
139 | 132 | return GPM_ENGINE_WARNING_LOW; | ||
140 | 133 | return GPM_ENGINE_WARNING_NONE; | ||
141 | 134 | } | ||
142 | 135 | |||
143 | 136 | /** | ||
144 | 137 | * gpm_engine_get_warning_time: | ||
145 | 138 | **/ | ||
146 | 139 | static GpmEngineWarning | ||
147 | 140 | gpm_engine_get_warning_time (GpmEngine *engine, UpDevice *device) | ||
148 | 141 | { | ||
149 | 142 | UpDeviceKind kind; | ||
150 | 143 | gint64 time_to_empty; | ||
151 | 144 | |||
152 | 145 | /* get device properties */ | ||
153 | 146 | g_object_get (device, | ||
154 | 147 | "kind", &kind, | ||
155 | 148 | "time-to-empty", &time_to_empty, | ||
156 | 149 | NULL); | ||
157 | 150 | |||
158 | 151 | /* this is probably an error condition */ | ||
159 | 152 | if (time_to_empty == 0) { | ||
160 | 153 | egg_debug ("time zero, falling back to percentage for %s", up_device_kind_to_string (kind)); | ||
161 | 154 | return gpm_engine_get_warning_percentage (engine, device); | ||
162 | 155 | } | ||
163 | 156 | |||
164 | 157 | if (time_to_empty <= engine->priv->action_time) | ||
165 | 158 | return GPM_ENGINE_WARNING_ACTION; | ||
166 | 159 | if (time_to_empty <= engine->priv->critical_time) | ||
167 | 160 | return GPM_ENGINE_WARNING_CRITICAL; | ||
168 | 161 | if (time_to_empty <= engine->priv->low_time) | ||
169 | 162 | return GPM_ENGINE_WARNING_LOW; | ||
170 | 163 | return GPM_ENGINE_WARNING_NONE; | ||
171 | 164 | } | ||
172 | 165 | |||
173 | 166 | /** | ||
174 | 167 | * gpm_engine_get_warning: | ||
175 | 168 | * | ||
176 | 169 | * This gets the possible engine state for the device according to the | ||
177 | 170 | * policy, which could be per-percent, or per-time. | ||
178 | 171 | * | ||
179 | 172 | * Return value: A GpmEngine state, e.g. GPM_ENGINE_WARNING_DISCHARGING | ||
180 | 173 | **/ | ||
181 | 174 | static GpmEngineWarning | ||
182 | 175 | gpm_engine_get_warning (GpmEngine *engine, UpDevice *device) | ||
183 | 176 | { | ||
184 | 177 | UpDeviceKind kind; | ||
185 | 178 | UpDeviceState state; | ||
186 | 179 | GpmEngineWarning warning_type; | ||
187 | 180 | |||
188 | 181 | /* get device properties */ | ||
189 | 182 | g_object_get (device, | ||
190 | 183 | "kind", &kind, | ||
191 | 184 | "state", &state, | ||
192 | 185 | NULL); | ||
193 | 186 | |||
194 | 187 | /* default to no engine */ | ||
195 | 188 | warning_type = GPM_ENGINE_WARNING_NONE; | ||
196 | 189 | |||
197 | 190 | /* if the device in question is on ac, don't give a warning */ | ||
198 | 191 | if (state == UP_DEVICE_STATE_CHARGING) | ||
199 | 192 | goto out; | ||
200 | 193 | |||
201 | 194 | if (kind == UP_DEVICE_KIND_MOUSE || | ||
202 | 195 | kind == UP_DEVICE_KIND_KEYBOARD) { | ||
203 | 196 | |||
204 | 197 | warning_type = gpm_engine_get_warning_csr (engine, device); | ||
205 | 198 | |||
206 | 199 | } else if (kind == UP_DEVICE_KIND_UPS || | ||
207 | 200 | #if UP_CHECK_VERSION(0,9,5) | ||
208 | 201 | kind == UP_DEVICE_KIND_MEDIA_PLAYER || | ||
209 | 202 | kind == UP_DEVICE_KIND_TABLET || | ||
210 | 203 | kind == UP_DEVICE_KIND_COMPUTER || | ||
211 | 204 | #endif | ||
212 | 205 | kind == UP_DEVICE_KIND_PDA) { | ||
213 | 206 | |||
214 | 207 | warning_type = gpm_engine_get_warning_percentage (engine, device); | ||
215 | 208 | |||
216 | 209 | } else if (kind == UP_DEVICE_KIND_PHONE) { | ||
217 | 210 | |||
218 | 211 | warning_type = gpm_engine_get_warning_percentage (engine, device); | ||
219 | 212 | |||
220 | 213 | } else if (kind == UP_DEVICE_KIND_BATTERY) { | ||
221 | 214 | /* only use the time when it is accurate, and GConf is not disabled */ | ||
222 | 215 | if (engine->priv->use_time_primary) | ||
223 | 216 | warning_type = gpm_engine_get_warning_time (engine, device); | ||
224 | 217 | else | ||
225 | 218 | warning_type = gpm_engine_get_warning_percentage (engine, device); | ||
226 | 219 | } | ||
227 | 220 | |||
228 | 221 | /* If we have no important engines, we should test for discharging */ | ||
229 | 222 | if (warning_type == GPM_ENGINE_WARNING_NONE) { | ||
230 | 223 | if (state == UP_DEVICE_STATE_DISCHARGING) | ||
231 | 224 | warning_type = GPM_ENGINE_WARNING_DISCHARGING; | ||
232 | 225 | } | ||
233 | 226 | |||
234 | 227 | out: | ||
235 | 228 | return warning_type; | ||
236 | 229 | } | ||
237 | 230 | |||
238 | 231 | /** | ||
239 | 232 | * gpm_engine_get_summary: | ||
240 | 233 | * @engine: This engine class instance | ||
241 | 234 | * @string: The returned string | ||
242 | 235 | * | ||
243 | 236 | * Returns the complete tooltip ready for display | ||
244 | 237 | **/ | ||
245 | 238 | gchar * | ||
246 | 239 | gpm_engine_get_summary (GpmEngine *engine) | ||
247 | 240 | { | ||
248 | 241 | guint i; | ||
249 | 242 | GPtrArray *array; | ||
250 | 243 | UpDevice *device; | ||
251 | 244 | UpDeviceState state; | ||
252 | 245 | GString *tooltip = NULL; | ||
253 | 246 | gchar *part; | ||
254 | 247 | gboolean is_present; | ||
255 | 248 | |||
256 | 249 | g_return_val_if_fail (GPM_IS_ENGINE (engine), NULL); | ||
257 | 250 | |||
258 | 251 | /* need to get AC state */ | ||
259 | 252 | tooltip = g_string_new (""); | ||
260 | 253 | |||
261 | 254 | /* do we have specific device types? */ | ||
262 | 255 | array = engine->priv->array; | ||
263 | 256 | for (i=0;i<array->len;i++) { | ||
264 | 257 | device = g_ptr_array_index (engine->priv->array, i); | ||
265 | 258 | g_object_get (device, | ||
266 | 259 | "is-present", &is_present, | ||
267 | 260 | "state", &state, | ||
268 | 261 | NULL); | ||
269 | 262 | if (!is_present) | ||
270 | 263 | continue; | ||
271 | 264 | if (state == UP_DEVICE_STATE_EMPTY) | ||
272 | 265 | continue; | ||
273 | 266 | part = gpm_upower_get_device_summary (device); | ||
274 | 267 | if (part != NULL) | ||
275 | 268 | g_string_append_printf (tooltip, "%s\n", part); | ||
276 | 269 | g_free (part); | ||
277 | 270 | } | ||
278 | 271 | |||
279 | 272 | /* remove the last \n */ | ||
280 | 273 | g_string_truncate (tooltip, tooltip->len-1); | ||
281 | 274 | |||
282 | 275 | egg_debug ("tooltip: %s", tooltip->str); | ||
283 | 276 | |||
284 | 277 | return g_string_free (tooltip, FALSE); | ||
285 | 278 | } | ||
286 | 279 | |||
287 | 280 | /** | ||
288 | 281 | * gpm_engine_get_icon_priv: | ||
289 | 282 | * | ||
290 | 283 | * Returns the icon | ||
291 | 284 | **/ | ||
292 | 285 | static gchar * | ||
293 | 286 | gpm_engine_get_icon_priv (GpmEngine *engine, UpDeviceKind device_kind, GpmEngineWarning warning, gboolean use_state) | ||
294 | 287 | { | ||
295 | 288 | guint i; | ||
296 | 289 | GPtrArray *array; | ||
297 | 290 | UpDevice *device; | ||
298 | 291 | GpmEngineWarning warning_temp; | ||
299 | 292 | UpDeviceKind kind; | ||
300 | 293 | UpDeviceState state; | ||
301 | 294 | gboolean is_present; | ||
302 | 295 | |||
303 | 296 | /* do we have specific device types? */ | ||
304 | 297 | array = engine->priv->array; | ||
305 | 298 | for (i=0;i<array->len;i++) { | ||
306 | 299 | device = g_ptr_array_index (engine->priv->array, i); | ||
307 | 300 | |||
308 | 301 | /* get device properties */ | ||
309 | 302 | g_object_get (device, | ||
310 | 303 | "kind", &kind, | ||
311 | 304 | "state", &state, | ||
312 | 305 | "is-present", &is_present, | ||
313 | 306 | NULL); | ||
314 | 307 | |||
315 | 308 | /* if battery then use composite device to cope with multiple batteries */ | ||
316 | 309 | if (kind == UP_DEVICE_KIND_BATTERY) | ||
317 | 310 | device = gpm_engine_get_composite_device (engine, device); | ||
318 | 311 | |||
319 | 312 | warning_temp = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(device), "engine-warning-old")); | ||
320 | 313 | if (kind == device_kind && is_present) { | ||
321 | 314 | if (warning != GPM_ENGINE_WARNING_NONE) { | ||
322 | 315 | if (warning_temp == warning) | ||
323 | 316 | return gpm_upower_get_device_icon (device); | ||
324 | 317 | continue; | ||
325 | 318 | } | ||
326 | 319 | if (use_state) { | ||
327 | 320 | if (state == UP_DEVICE_STATE_CHARGING || state == UP_DEVICE_STATE_DISCHARGING) | ||
328 | 321 | return gpm_upower_get_device_icon (device); | ||
329 | 322 | continue; | ||
330 | 323 | } | ||
331 | 324 | return gpm_upower_get_device_icon (device); | ||
332 | 325 | } | ||
333 | 326 | } | ||
334 | 327 | return NULL; | ||
335 | 328 | } | ||
336 | 329 | |||
337 | 330 | /** | ||
338 | 331 | * gpm_engine_get_icon: | ||
339 | 332 | * | ||
340 | 333 | * Returns the icon | ||
341 | 334 | **/ | ||
342 | 335 | gchar * | ||
343 | 336 | gpm_engine_get_icon (GpmEngine *engine) | ||
344 | 337 | { | ||
345 | 338 | gchar *icon = NULL; | ||
346 | 339 | |||
347 | 340 | g_return_val_if_fail (GPM_IS_ENGINE (engine), NULL); | ||
348 | 341 | |||
349 | 342 | /* policy */ | ||
350 | 343 | if (engine->priv->icon_policy == GPM_ICON_POLICY_NEVER) { | ||
351 | 344 | egg_debug ("no icon allowed, so no icon will be displayed."); | ||
352 | 345 | return NULL; | ||
353 | 346 | } | ||
354 | 347 | |||
355 | 348 | /* we try CRITICAL: BATTERY, UPS, MOUSE, KEYBOARD */ | ||
356 | 349 | icon = gpm_engine_get_icon_priv (engine, UP_DEVICE_KIND_BATTERY, GPM_ENGINE_WARNING_CRITICAL, FALSE); | ||
357 | 350 | if (icon != NULL) | ||
358 | 351 | return icon; | ||
359 | 352 | icon = gpm_engine_get_icon_priv (engine, UP_DEVICE_KIND_UPS, GPM_ENGINE_WARNING_CRITICAL, FALSE); | ||
360 | 353 | if (icon != NULL) | ||
361 | 354 | return icon; | ||
362 | 355 | icon = gpm_engine_get_icon_priv (engine, UP_DEVICE_KIND_MOUSE, GPM_ENGINE_WARNING_CRITICAL, FALSE); | ||
363 | 356 | if (icon != NULL) | ||
364 | 357 | return icon; | ||
365 | 358 | icon = gpm_engine_get_icon_priv (engine, UP_DEVICE_KIND_KEYBOARD, GPM_ENGINE_WARNING_CRITICAL, FALSE); | ||
366 | 359 | if (icon != NULL) | ||
367 | 360 | return icon; | ||
368 | 361 | |||
369 | 362 | /* policy */ | ||
370 | 363 | if (engine->priv->icon_policy == GPM_ICON_POLICY_CRITICAL) { | ||
371 | 364 | egg_debug ("no devices critical, so no icon will be displayed."); | ||
372 | 365 | return NULL; | ||
373 | 366 | } | ||
374 | 367 | |||
375 | 368 | /* we try CRITICAL: BATTERY, UPS, MOUSE, KEYBOARD */ | ||
376 | 369 | icon = gpm_engine_get_icon_priv (engine, UP_DEVICE_KIND_BATTERY, GPM_ENGINE_WARNING_LOW, FALSE); | ||
377 | 370 | if (icon != NULL) | ||
378 | 371 | return icon; | ||
379 | 372 | icon = gpm_engine_get_icon_priv (engine, UP_DEVICE_KIND_UPS, GPM_ENGINE_WARNING_LOW, FALSE); | ||
380 | 373 | if (icon != NULL) | ||
381 | 374 | return icon; | ||
382 | 375 | icon = gpm_engine_get_icon_priv (engine, UP_DEVICE_KIND_MOUSE, GPM_ENGINE_WARNING_LOW, FALSE); | ||
383 | 376 | if (icon != NULL) | ||
384 | 377 | return icon; | ||
385 | 378 | icon = gpm_engine_get_icon_priv (engine, UP_DEVICE_KIND_KEYBOARD, GPM_ENGINE_WARNING_LOW, FALSE); | ||
386 | 379 | if (icon != NULL) | ||
387 | 380 | return icon; | ||
388 | 381 | |||
389 | 382 | /* policy */ | ||
390 | 383 | if (engine->priv->icon_policy == GPM_ICON_POLICY_LOW) { | ||
391 | 384 | egg_debug ("no devices low, so no icon will be displayed."); | ||
392 | 385 | return NULL; | ||
393 | 386 | } | ||
394 | 387 | |||
395 | 388 | /* we try (DIS)CHARGING: BATTERY, UPS */ | ||
396 | 389 | icon = gpm_engine_get_icon_priv (engine, UP_DEVICE_KIND_BATTERY, GPM_ENGINE_WARNING_NONE, TRUE); | ||
397 | 390 | if (icon != NULL) | ||
398 | 391 | return icon; | ||
399 | 392 | icon = gpm_engine_get_icon_priv (engine, UP_DEVICE_KIND_UPS, GPM_ENGINE_WARNING_NONE, TRUE); | ||
400 | 393 | if (icon != NULL) | ||
401 | 394 | return icon; | ||
402 | 395 | |||
403 | 396 | /* policy */ | ||
404 | 397 | if (engine->priv->icon_policy == GPM_ICON_POLICY_CHARGE) { | ||
405 | 398 | egg_debug ("no devices (dis)charging, so no icon will be displayed."); | ||
406 | 399 | return NULL; | ||
407 | 400 | } | ||
408 | 401 | |||
409 | 402 | /* we try PRESENT: BATTERY, UPS */ | ||
410 | 403 | icon = gpm_engine_get_icon_priv (engine, UP_DEVICE_KIND_BATTERY, GPM_ENGINE_WARNING_NONE, FALSE); | ||
411 | 404 | if (icon != NULL) | ||
412 | 405 | return icon; | ||
413 | 406 | icon = gpm_engine_get_icon_priv (engine, UP_DEVICE_KIND_UPS, GPM_ENGINE_WARNING_NONE, FALSE); | ||
414 | 407 | if (icon != NULL) | ||
415 | 408 | return icon; | ||
416 | 409 | |||
417 | 410 | /* policy */ | ||
418 | 411 | if (engine->priv->icon_policy == GPM_ICON_POLICY_PRESENT) { | ||
419 | 412 | egg_debug ("no devices present, so no icon will be displayed."); | ||
420 | 413 | return NULL; | ||
421 | 414 | } | ||
422 | 415 | |||
423 | 416 | /* we fallback to the ac_adapter icon */ | ||
424 | 417 | egg_debug ("Using fallback"); | ||
425 | 418 | return g_strdup (GPM_STOCK_AC_ADAPTER); | ||
426 | 419 | } | ||
427 | 420 | |||
428 | 421 | /** | ||
429 | 422 | * gpm_engine_recalculate_state_icon: | ||
430 | 423 | */ | ||
431 | 424 | static gboolean | ||
432 | 425 | gpm_engine_recalculate_state_icon (GpmEngine *engine) | ||
433 | 426 | { | ||
434 | 427 | gchar *icon; | ||
435 | 428 | |||
436 | 429 | g_return_val_if_fail (engine != NULL, FALSE); | ||
437 | 430 | g_return_val_if_fail (GPM_IS_ENGINE (engine), FALSE); | ||
438 | 431 | |||
439 | 432 | /* show a different icon if we are disconnected */ | ||
440 | 433 | icon = gpm_engine_get_icon (engine); | ||
441 | 434 | if (icon == NULL) { | ||
442 | 435 | /* none before, now none */ | ||
443 | 436 | if (engine->priv->previous_icon == NULL) | ||
444 | 437 | return FALSE; | ||
445 | 438 | /* icon before, now none */ | ||
446 | 439 | egg_debug ("** EMIT: icon-changed: none"); | ||
447 | 440 | g_signal_emit (engine, signals [ICON_CHANGED], 0, NULL); | ||
448 | 441 | |||
449 | 442 | g_free (engine->priv->previous_icon); | ||
450 | 443 | engine->priv->previous_icon = NULL; | ||
451 | 444 | return TRUE; | ||
452 | 445 | } | ||
453 | 446 | |||
454 | 447 | /* no icon before, now icon */ | ||
455 | 448 | if (engine->priv->previous_icon == NULL) { | ||
456 | 449 | egg_debug ("** EMIT: icon-changed: %s", icon); | ||
457 | 450 | g_signal_emit (engine, signals [ICON_CHANGED], 0, icon); | ||
458 | 451 | engine->priv->previous_icon = icon; | ||
459 | 452 | return TRUE; | ||
460 | 453 | } | ||
461 | 454 | |||
462 | 455 | /* icon before, now different */ | ||
463 | 456 | if (strcmp (engine->priv->previous_icon, icon) != 0) { | ||
464 | 457 | g_free (engine->priv->previous_icon); | ||
465 | 458 | engine->priv->previous_icon = icon; | ||
466 | 459 | egg_debug ("** EMIT: icon-changed: %s", icon); | ||
467 | 460 | g_signal_emit (engine, signals [ICON_CHANGED], 0, icon); | ||
468 | 461 | return TRUE; | ||
469 | 462 | } | ||
470 | 463 | |||
471 | 464 | egg_debug ("no change"); | ||
472 | 465 | /* nothing to do */ | ||
473 | 466 | g_free (icon); | ||
474 | 467 | return FALSE; | ||
475 | 468 | } | ||
476 | 469 | |||
477 | 470 | /** | ||
478 | 471 | * gpm_engine_recalculate_state_summary: | ||
479 | 472 | */ | ||
480 | 473 | static gboolean | ||
481 | 474 | gpm_engine_recalculate_state_summary (GpmEngine *engine) | ||
482 | 475 | { | ||
483 | 476 | gchar *summary; | ||
484 | 477 | |||
485 | 478 | summary = gpm_engine_get_summary (engine); | ||
486 | 479 | if (engine->priv->previous_summary == NULL) { | ||
487 | 480 | engine->priv->previous_summary = summary; | ||
488 | 481 | egg_debug ("** EMIT: summary-changed(1): %s", summary); | ||
489 | 482 | g_signal_emit (engine, signals [SUMMARY_CHANGED], 0, summary); | ||
490 | 483 | return TRUE; | ||
491 | 484 | } | ||
492 | 485 | |||
493 | 486 | if (strcmp (engine->priv->previous_summary, summary) != 0) { | ||
494 | 487 | g_free (engine->priv->previous_summary); | ||
495 | 488 | engine->priv->previous_summary = summary; | ||
496 | 489 | egg_debug ("** EMIT: summary-changed(2): %s", summary); | ||
497 | 490 | g_signal_emit (engine, signals [SUMMARY_CHANGED], 0, summary); | ||
498 | 491 | return TRUE; | ||
499 | 492 | } | ||
500 | 493 | egg_debug ("no change"); | ||
501 | 494 | /* nothing to do */ | ||
502 | 495 | g_free (summary); | ||
503 | 496 | return FALSE; | ||
504 | 497 | } | ||
505 | 498 | |||
506 | 499 | /** | ||
507 | 500 | * gpm_engine_recalculate_state: | ||
508 | 501 | */ | ||
509 | 502 | static void | ||
510 | 503 | gpm_engine_recalculate_state (GpmEngine *engine) | ||
511 | 504 | { | ||
512 | 505 | |||
513 | 506 | g_return_if_fail (engine != NULL); | ||
514 | 507 | g_return_if_fail (GPM_IS_ENGINE (engine)); | ||
515 | 508 | |||
516 | 509 | gpm_engine_recalculate_state_icon (engine); | ||
517 | 510 | gpm_engine_recalculate_state_summary (engine); | ||
518 | 511 | |||
519 | 512 | g_signal_emit (engine, signals [DEVICES_CHANGED], 0); | ||
520 | 513 | } | ||
521 | 514 | |||
522 | 515 | /** | ||
523 | 516 | * gpm_engine_conf_key_changed_cb: | ||
524 | 517 | **/ | ||
525 | 518 | static void | ||
526 | 519 | gpm_engine_conf_key_changed_cb (GConfClient *conf, guint cnxn_id, GConfEntry *entry, GpmEngine *engine) | ||
527 | 520 | { | ||
528 | 521 | GConfValue *value; | ||
529 | 522 | gchar *icon_policy; | ||
530 | 523 | |||
531 | 524 | if (entry == NULL) | ||
532 | 525 | return; | ||
533 | 526 | value = gconf_entry_get_value (entry); | ||
534 | 527 | if (value == NULL) | ||
535 | 528 | return; | ||
536 | 529 | |||
537 | 530 | if (strcmp (entry->key, GPM_CONF_USE_TIME_POLICY) == 0) { | ||
538 | 531 | |||
539 | 532 | engine->priv->use_time_primary = gconf_value_get_bool (value); | ||
540 | 533 | |||
541 | 534 | } else if (strcmp (entry->key, GPM_CONF_UI_ICON_POLICY) == 0) { | ||
542 | 535 | |||
543 | 536 | /* do we want to display the icon in the tray */ | ||
544 | 537 | icon_policy = gconf_client_get_string (conf, GPM_CONF_UI_ICON_POLICY, NULL); | ||
545 | 538 | engine->priv->icon_policy = gpm_icon_policy_from_string (icon_policy); | ||
546 | 539 | g_free (icon_policy); | ||
547 | 540 | |||
548 | 541 | /* perhaps change icon */ | ||
549 | 542 | gpm_engine_recalculate_state_icon (engine); | ||
550 | 543 | } | ||
551 | 544 | } | ||
552 | 545 | |||
553 | 546 | /** | ||
554 | 547 | * gpm_engine_device_check_capacity: | ||
555 | 548 | **/ | ||
556 | 549 | static gboolean | ||
557 | 550 | gpm_engine_device_check_capacity (GpmEngine *engine, UpDevice *device) | ||
558 | 551 | { | ||
559 | 552 | gboolean ret; | ||
560 | 553 | UpDeviceKind kind; | ||
561 | 554 | gdouble capacity; | ||
562 | 555 | |||
563 | 556 | /* get device properties */ | ||
564 | 557 | g_object_get (device, | ||
565 | 558 | "kind", &kind, | ||
566 | 559 | "capacity", &capacity, | ||
567 | 560 | NULL); | ||
568 | 561 | |||
569 | 562 | /* not laptop battery */ | ||
570 | 563 | if (kind != UP_DEVICE_KIND_BATTERY) | ||
571 | 564 | return FALSE; | ||
572 | 565 | |||
573 | 566 | /* capacity okay */ | ||
574 | 567 | if (capacity > 50.0f) | ||
575 | 568 | return FALSE; | ||
576 | 569 | |||
577 | 570 | /* capacity invalid */ | ||
578 | 571 | if (capacity < 1.0f) | ||
579 | 572 | return FALSE; | ||
580 | 573 | |||
581 | 574 | /* only emit this if specified in gconf */ | ||
582 | 575 | ret = gconf_client_get_bool (engine->priv->conf, GPM_CONF_NOTIFY_LOW_CAPACITY, NULL); | ||
583 | 576 | if (ret) { | ||
584 | 577 | egg_debug ("** EMIT: low-capacity"); | ||
585 | 578 | g_signal_emit (engine, signals [LOW_CAPACITY], 0, device); | ||
586 | 579 | } | ||
587 | 580 | return TRUE; | ||
588 | 581 | } | ||
589 | 582 | |||
590 | 583 | /** | ||
591 | 584 | * gpm_engine_get_composite_device: | ||
592 | 585 | **/ | ||
593 | 586 | static UpDevice * | ||
594 | 587 | gpm_engine_get_composite_device (GpmEngine *engine, UpDevice *original_device) | ||
595 | 588 | { | ||
596 | 589 | guint battery_devices = 0; | ||
597 | 590 | GPtrArray *array; | ||
598 | 591 | UpDevice *device; | ||
599 | 592 | UpDeviceKind kind; | ||
600 | 593 | guint i; | ||
601 | 594 | |||
602 | 595 | /* find out how many batteries in the system */ | ||
603 | 596 | array = engine->priv->array; | ||
604 | 597 | for (i=0;i<array->len;i++) { | ||
605 | 598 | device = g_ptr_array_index (engine->priv->array, i); | ||
606 | 599 | g_object_get (device, | ||
607 | 600 | "kind", &kind, | ||
608 | 601 | NULL); | ||
609 | 602 | if (kind == UP_DEVICE_KIND_BATTERY) | ||
610 | 603 | battery_devices++; | ||
611 | 604 | } | ||
612 | 605 | |||
613 | 606 | /* just use the original device if only one primary battery */ | ||
614 | 607 | if (battery_devices <= 1) { | ||
615 | 608 | egg_debug ("using original device as only one primary battery"); | ||
616 | 609 | device = original_device; | ||
617 | 610 | goto out; | ||
618 | 611 | } | ||
619 | 612 | |||
620 | 613 | /* use the composite device */ | ||
621 | 614 | device = engine->priv->battery_composite; | ||
622 | 615 | out: | ||
623 | 616 | /* return composite device or original device */ | ||
624 | 617 | return device; | ||
625 | 618 | } | ||
626 | 619 | |||
627 | 620 | /** | ||
628 | 621 | * gpm_engine_update_composite_device: | ||
629 | 622 | **/ | ||
630 | 623 | static UpDevice * | ||
631 | 624 | gpm_engine_update_composite_device (GpmEngine *engine, UpDevice *original_device) | ||
632 | 625 | { | ||
633 | 626 | guint i; | ||
634 | 627 | gdouble percentage = 0.0; | ||
635 | 628 | gdouble energy = 0.0; | ||
636 | 629 | gdouble energy_full = 0.0; | ||
637 | 630 | gdouble energy_rate = 0.0; | ||
638 | 631 | gdouble energy_total = 0.0; | ||
639 | 632 | gdouble energy_full_total = 0.0; | ||
640 | 633 | gdouble energy_rate_total = 0.0; | ||
641 | 634 | gint64 time_to_empty = 0; | ||
642 | 635 | gint64 time_to_full = 0; | ||
643 | 636 | guint battery_devices = 0; | ||
644 | 637 | gboolean is_charging = FALSE; | ||
645 | 638 | gboolean is_discharging = FALSE; | ||
646 | 639 | gboolean is_fully_charged = TRUE; | ||
647 | 640 | GPtrArray *array; | ||
648 | 641 | UpDevice *device; | ||
649 | 642 | UpDeviceState state; | ||
650 | 643 | UpDeviceKind kind; | ||
651 | 644 | gboolean debug; | ||
652 | 645 | gchar *text; | ||
653 | 646 | |||
654 | 647 | /* are we printing to console? */ | ||
655 | 648 | debug = egg_debug_enabled (); | ||
656 | 649 | |||
657 | 650 | /* update the composite device */ | ||
658 | 651 | array = engine->priv->array; | ||
659 | 652 | for (i=0;i<array->len;i++) { | ||
660 | 653 | device = g_ptr_array_index (engine->priv->array, i); | ||
661 | 654 | g_object_get (device, | ||
662 | 655 | "kind", &kind, | ||
663 | 656 | "state", &state, | ||
664 | 657 | "energy", &energy, | ||
665 | 658 | "energy-full", &energy_full, | ||
666 | 659 | "energy-rate", &energy_rate, | ||
667 | 660 | NULL); | ||
668 | 661 | if (kind != UP_DEVICE_KIND_BATTERY) | ||
669 | 662 | continue; | ||
670 | 663 | |||
671 | 664 | if (debug) { | ||
672 | 665 | text = up_device_to_text (device); | ||
673 | 666 | egg_debug ("printing device %i:\n%s", i, text); | ||
674 | 667 | g_free (text); | ||
675 | 668 | } | ||
676 | 669 | |||
677 | 670 | /* one of these will be charging or discharging */ | ||
678 | 671 | if (state == UP_DEVICE_STATE_CHARGING) | ||
679 | 672 | is_charging = TRUE; | ||
680 | 673 | if (state == UP_DEVICE_STATE_DISCHARGING) | ||
681 | 674 | is_discharging = TRUE; | ||
682 | 675 | if (state != UP_DEVICE_STATE_FULLY_CHARGED) | ||
683 | 676 | is_fully_charged = FALSE; | ||
684 | 677 | |||
685 | 678 | /* sum up composite */ | ||
686 | 679 | energy_total += energy; | ||
687 | 680 | energy_full_total += energy_full; | ||
688 | 681 | energy_rate_total += energy_rate; | ||
689 | 682 | battery_devices++; | ||
690 | 683 | } | ||
691 | 684 | |||
692 | 685 | /* just use the original device if only one primary battery */ | ||
693 | 686 | if (battery_devices == 1) { | ||
694 | 687 | egg_debug ("using original device as only one primary battery"); | ||
695 | 688 | device = original_device; | ||
696 | 689 | goto out; | ||
697 | 690 | } | ||
698 | 691 | |||
699 | 692 | /* use percentage weighted for each battery capacity */ | ||
700 | 693 | percentage = 100.0 * energy_total / energy_full_total; | ||
701 | 694 | |||
702 | 695 | /* set composite state */ | ||
703 | 696 | if (is_charging) | ||
704 | 697 | state = UP_DEVICE_STATE_CHARGING; | ||
705 | 698 | else if (is_discharging) | ||
706 | 699 | state = UP_DEVICE_STATE_DISCHARGING; | ||
707 | 700 | else if (is_fully_charged) | ||
708 | 701 | state = UP_DEVICE_STATE_FULLY_CHARGED; | ||
709 | 702 | else | ||
710 | 703 | state = UP_DEVICE_STATE_UNKNOWN; | ||
711 | 704 | |||
712 | 705 | /* calculate a quick and dirty time remaining value */ | ||
713 | 706 | if (energy_rate_total > 0) { | ||
714 | 707 | if (state == UP_DEVICE_STATE_DISCHARGING) | ||
715 | 708 | time_to_empty = 3600 * (energy_total / energy_rate_total); | ||
716 | 709 | else if (state == UP_DEVICE_STATE_CHARGING) | ||
717 | 710 | time_to_full = 3600 * ((energy_full_total - energy_total) / energy_rate_total); | ||
718 | 711 | } | ||
719 | 712 | |||
720 | 713 | /* okay, we can use the composite device */ | ||
721 | 714 | device = engine->priv->battery_composite; | ||
722 | 715 | |||
723 | 716 | egg_debug ("printing composite device"); | ||
724 | 717 | g_object_set (device, | ||
725 | 718 | "energy", energy, | ||
726 | 719 | "energy-full", energy_full, | ||
727 | 720 | "energy-rate", energy_rate, | ||
728 | 721 | "time-to-empty", time_to_empty, | ||
729 | 722 | "time-to-full", time_to_full, | ||
730 | 723 | "percentage", percentage, | ||
731 | 724 | "state", state, | ||
732 | 725 | NULL); | ||
733 | 726 | if (debug) { | ||
734 | 727 | text = up_device_to_text (device); | ||
735 | 728 | egg_debug ("composite:\n%s", text); | ||
736 | 729 | g_free (text); | ||
737 | 730 | } | ||
738 | 731 | |||
739 | 732 | /* force update of icon */ | ||
740 | 733 | gpm_engine_recalculate_state_icon (engine); | ||
741 | 734 | out: | ||
742 | 735 | /* return composite device or original device */ | ||
743 | 736 | return device; | ||
744 | 737 | } | ||
745 | 738 | |||
746 | 739 | /** | ||
747 | 740 | * gpm_engine_device_add: | ||
748 | 741 | **/ | ||
749 | 742 | static void | ||
750 | 743 | gpm_engine_device_add (GpmEngine *engine, UpDevice *device) | ||
751 | 744 | { | ||
752 | 745 | GpmEngineWarning warning; | ||
753 | 746 | UpDeviceState state; | ||
754 | 747 | UpDeviceKind kind; | ||
755 | 748 | UpDevice *composite; | ||
756 | 749 | |||
757 | 750 | /* assign warning */ | ||
758 | 751 | warning = gpm_engine_get_warning (engine, device); | ||
759 | 752 | g_object_set_data (G_OBJECT(device), "engine-warning-old", GUINT_TO_POINTER(warning)); | ||
760 | 753 | |||
761 | 754 | /* check capacity */ | ||
762 | 755 | gpm_engine_device_check_capacity (engine, device); | ||
763 | 756 | |||
764 | 757 | /* get device properties */ | ||
765 | 758 | g_object_get (device, | ||
766 | 759 | "kind", &kind, | ||
767 | 760 | "state", &state, | ||
768 | 761 | NULL); | ||
769 | 762 | |||
770 | 763 | /* add old state for transitions */ | ||
771 | 764 | egg_debug ("adding %s with state %s", up_device_get_object_path (device), up_device_state_to_string (state)); | ||
772 | 765 | g_object_set_data (G_OBJECT(device), "engine-state-old", GUINT_TO_POINTER(state)); | ||
773 | 766 | |||
774 | 767 | if (kind == UP_DEVICE_KIND_BATTERY) { | ||
775 | 768 | egg_debug ("updating because we added a device"); | ||
776 | 769 | composite = gpm_engine_update_composite_device (engine, device); | ||
777 | 770 | |||
778 | 771 | /* get the same values for the composite device */ | ||
779 | 772 | warning = gpm_engine_get_warning (engine, composite); | ||
780 | 773 | g_object_set_data (G_OBJECT(composite), "engine-warning-old", GUINT_TO_POINTER(warning)); | ||
781 | 774 | g_object_get (composite, "state", &state, NULL); | ||
782 | 775 | g_object_set_data (G_OBJECT(composite), "engine-state-old", GUINT_TO_POINTER(state)); | ||
783 | 776 | } | ||
784 | 777 | } | ||
785 | 778 | |||
786 | 779 | /** | ||
787 | 780 | * gpm_engine_check_recall: | ||
788 | 781 | **/ | ||
789 | 782 | static gboolean | ||
790 | 783 | gpm_engine_check_recall (GpmEngine *engine, UpDevice *device) | ||
791 | 784 | { | ||
792 | 785 | UpDeviceKind kind; | ||
793 | 786 | gboolean recall_notice = FALSE; | ||
794 | 787 | gchar *recall_vendor = NULL; | ||
795 | 788 | gchar *recall_url = NULL; | ||
796 | 789 | |||
797 | 790 | /* get device properties */ | ||
798 | 791 | g_object_get (device, | ||
799 | 792 | "kind", &kind, | ||
800 | 793 | "recall-notice", &recall_notice, | ||
801 | 794 | "recall-vendor", &recall_vendor, | ||
802 | 795 | "recall-url", &recall_url, | ||
803 | 796 | NULL); | ||
804 | 797 | |||
805 | 798 | /* not battery */ | ||
806 | 799 | if (kind != UP_DEVICE_KIND_BATTERY) | ||
807 | 800 | goto out; | ||
808 | 801 | |||
809 | 802 | /* no recall data */ | ||
810 | 803 | if (!recall_notice) | ||
811 | 804 | goto out; | ||
812 | 805 | |||
813 | 806 | /* emit signal for manager */ | ||
814 | 807 | egg_debug ("** EMIT: perhaps-recall"); | ||
815 | 808 | g_signal_emit (engine, signals [PERHAPS_RECALL], 0, device, recall_vendor, recall_url); | ||
816 | 809 | out: | ||
817 | 810 | g_free (recall_vendor); | ||
818 | 811 | g_free (recall_url); | ||
819 | 812 | return recall_notice; | ||
820 | 813 | } | ||
821 | 814 | |||
822 | 815 | /** | ||
823 | 816 | * gpm_engine_coldplug_idle_cb: | ||
824 | 817 | **/ | ||
825 | 818 | static gboolean | ||
826 | 819 | gpm_engine_coldplug_idle_cb (GpmEngine *engine) | ||
827 | 820 | { | ||
828 | 821 | guint i; | ||
829 | 822 | GPtrArray *array; | ||
830 | 823 | gboolean has_battery = FALSE; | ||
831 | 824 | gboolean has_ups = FALSE; | ||
832 | 825 | GpmPrefsServer *prefs_server; | ||
833 | 826 | UpDevice *device; | ||
834 | 827 | UpDeviceKind kind; | ||
835 | 828 | gboolean ret; | ||
836 | 829 | GError *error = NULL; | ||
837 | 830 | |||
838 | 831 | g_return_val_if_fail (engine != NULL, FALSE); | ||
839 | 832 | g_return_val_if_fail (GPM_IS_ENGINE (engine), FALSE); | ||
840 | 833 | |||
841 | 834 | /* get devices from UPower */ | ||
842 | 835 | ret = up_client_enumerate_devices_sync (engine->priv->client, NULL, &error); | ||
843 | 836 | if (!ret) { | ||
844 | 837 | egg_error ("failed to get device list: %s", error->message); | ||
845 | 838 | g_error_free (error); | ||
846 | 839 | goto out; | ||
847 | 840 | } | ||
848 | 841 | engine->priv->array = up_client_get_devices (engine->priv->client); | ||
849 | 842 | |||
850 | 843 | /* do we have specific device types? */ | ||
851 | 844 | array = engine->priv->array; | ||
852 | 845 | for (i=0;i<array->len;i++) { | ||
853 | 846 | device = g_ptr_array_index (engine->priv->array, i); | ||
854 | 847 | |||
855 | 848 | /* get device properties */ | ||
856 | 849 | g_object_get (device, | ||
857 | 850 | "kind", &kind, | ||
858 | 851 | NULL); | ||
859 | 852 | |||
860 | 853 | if (kind == UP_DEVICE_KIND_BATTERY) | ||
861 | 854 | has_battery = TRUE; | ||
862 | 855 | else if (kind == UP_DEVICE_KIND_UPS) | ||
863 | 856 | has_ups = TRUE; | ||
864 | 857 | } | ||
865 | 858 | |||
866 | 859 | /* only show the battery prefs section if we have batteries */ | ||
867 | 860 | prefs_server = gpm_prefs_server_new (); | ||
868 | 861 | if (has_battery) | ||
869 | 862 | gpm_prefs_server_set_capability (prefs_server, GPM_PREFS_SERVER_BATTERY); | ||
870 | 863 | if (has_ups) | ||
871 | 864 | gpm_prefs_server_set_capability (prefs_server, GPM_PREFS_SERVER_UPS); | ||
872 | 865 | g_object_unref (prefs_server); | ||
873 | 866 | |||
874 | 867 | /* connected mobile phones */ | ||
875 | 868 | gpm_phone_coldplug (engine->priv->phone); | ||
876 | 869 | |||
877 | 870 | gpm_engine_recalculate_state (engine); | ||
878 | 871 | |||
879 | 872 | /* add to database */ | ||
880 | 873 | for (i=0;i<array->len;i++) { | ||
881 | 874 | device = g_ptr_array_index (engine->priv->array, i); | ||
882 | 875 | gpm_engine_device_add (engine, device); | ||
883 | 876 | gpm_engine_check_recall (engine, device); | ||
884 | 877 | } | ||
885 | 878 | out: | ||
886 | 879 | /* never repeat */ | ||
887 | 880 | return FALSE; | ||
888 | 881 | } | ||
889 | 882 | |||
890 | 883 | /** | ||
891 | 884 | * gpm_engine_device_added_cb: | ||
892 | 885 | **/ | ||
893 | 886 | static void | ||
894 | 887 | gpm_engine_device_added_cb (UpClient *client, UpDevice *device, GpmEngine *engine) | ||
895 | 888 | { | ||
896 | 889 | /* add to list */ | ||
897 | 890 | g_ptr_array_add (engine->priv->array, g_object_ref (device)); | ||
898 | 891 | gpm_engine_check_recall (engine, device); | ||
899 | 892 | |||
900 | 893 | gpm_engine_recalculate_state (engine); | ||
901 | 894 | } | ||
902 | 895 | |||
903 | 896 | /** | ||
904 | 897 | * gpm_engine_device_removed_cb: | ||
905 | 898 | **/ | ||
906 | 899 | static void | ||
907 | 900 | gpm_engine_device_removed_cb (UpClient *client, UpDevice *device, GpmEngine *engine) | ||
908 | 901 | { | ||
909 | 902 | gboolean ret; | ||
910 | 903 | ret = g_ptr_array_remove (engine->priv->array, device); | ||
911 | 904 | if (!ret) | ||
912 | 905 | return; | ||
913 | 906 | gpm_engine_recalculate_state (engine); | ||
914 | 907 | } | ||
915 | 908 | |||
916 | 909 | |||
917 | 910 | /** | ||
918 | 911 | * gpm_engine_device_changed_cb: | ||
919 | 912 | **/ | ||
920 | 913 | static void | ||
921 | 914 | gpm_engine_device_changed_cb (UpClient *client, UpDevice *device, GpmEngine *engine) | ||
922 | 915 | { | ||
923 | 916 | UpDeviceKind kind; | ||
924 | 917 | UpDeviceState state; | ||
925 | 918 | UpDeviceState state_old; | ||
926 | 919 | GpmEngineWarning warning_old; | ||
927 | 920 | GpmEngineWarning warning; | ||
928 | 921 | |||
929 | 922 | /* get device properties */ | ||
930 | 923 | g_object_get (device, | ||
931 | 924 | "kind", &kind, | ||
932 | 925 | NULL); | ||
933 | 926 | |||
934 | 927 | /* if battery then use composite device to cope with multiple batteries */ | ||
935 | 928 | if (kind == UP_DEVICE_KIND_BATTERY) { | ||
936 | 929 | egg_debug ("updating because %s changed", up_device_get_object_path (device)); | ||
937 | 930 | device = gpm_engine_update_composite_device (engine, device); | ||
938 | 931 | } | ||
939 | 932 | |||
940 | 933 | /* get device properties (may be composite) */ | ||
941 | 934 | g_object_get (device, | ||
942 | 935 | "state", &state, | ||
943 | 936 | NULL); | ||
944 | 937 | |||
945 | 938 | egg_debug ("%s state is now %s", up_device_get_object_path (device), up_device_state_to_string (state)); | ||
946 | 939 | |||
947 | 940 | /* see if any interesting state changes have happened */ | ||
948 | 941 | state_old = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(device), "engine-state-old")); | ||
949 | 942 | if (state_old != state) { | ||
950 | 943 | if (state == UP_DEVICE_STATE_DISCHARGING) { | ||
951 | 944 | egg_debug ("** EMIT: discharging"); | ||
952 | 945 | g_signal_emit (engine, signals [DISCHARGING], 0, device); | ||
953 | 946 | } else if (state == UP_DEVICE_STATE_FULLY_CHARGED) { | ||
954 | 947 | egg_debug ("** EMIT: fully charged"); | ||
955 | 948 | g_signal_emit (engine, signals [FULLY_CHARGED], 0, device); | ||
956 | 949 | } | ||
957 | 950 | |||
958 | 951 | /* save new state */ | ||
959 | 952 | g_object_set_data (G_OBJECT(device), "engine-state-old", GUINT_TO_POINTER(state)); | ||
960 | 953 | } | ||
961 | 954 | |||
962 | 955 | /* check the warning state has not changed */ | ||
963 | 956 | warning_old = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(device), "engine-warning-old")); | ||
964 | 957 | warning = gpm_engine_get_warning (engine, device); | ||
965 | 958 | if (warning != warning_old) { | ||
966 | 959 | if (warning == GPM_ENGINE_WARNING_LOW) { | ||
967 | 960 | egg_debug ("** EMIT: charge-low"); | ||
968 | 961 | g_signal_emit (engine, signals [CHARGE_LOW], 0, device); | ||
969 | 962 | } else if (warning == GPM_ENGINE_WARNING_CRITICAL) { | ||
970 | 963 | egg_debug ("** EMIT: charge-critical"); | ||
971 | 964 | g_signal_emit (engine, signals [CHARGE_CRITICAL], 0, device); | ||
972 | 965 | } else if (warning == GPM_ENGINE_WARNING_ACTION) { | ||
973 | 966 | egg_debug ("** EMIT: charge-action"); | ||
974 | 967 | g_signal_emit (engine, signals [CHARGE_ACTION], 0, device); | ||
975 | 968 | } | ||
976 | 969 | /* save new state */ | ||
977 | 970 | g_object_set_data (G_OBJECT(device), "engine-warning-old", GUINT_TO_POINTER(warning)); | ||
978 | 971 | } | ||
979 | 972 | |||
980 | 973 | gpm_engine_recalculate_state (engine); | ||
981 | 974 | } | ||
982 | 975 | |||
983 | 976 | /** | ||
984 | 977 | * gpm_engine_get_devices: | ||
985 | 978 | * | ||
986 | 979 | * Return value: the UpDevice array, free with g_ptr_array_unref() | ||
987 | 980 | **/ | ||
988 | 981 | GPtrArray * | ||
989 | 982 | gpm_engine_get_devices (GpmEngine *engine) | ||
990 | 983 | { | ||
991 | 984 | return g_ptr_array_ref (engine->priv->array); | ||
992 | 985 | } | ||
993 | 986 | |||
994 | 987 | /** | ||
995 | 988 | * phone_device_added_cb: | ||
996 | 989 | **/ | ||
997 | 990 | static void | ||
998 | 991 | phone_device_added_cb (GpmPhone *phone, guint idx, GpmEngine *engine) | ||
999 | 992 | { | ||
1000 | 993 | UpDevice *device; | ||
1001 | 994 | device = up_device_new (); | ||
1002 | 995 | |||
1003 | 996 | egg_debug ("phone added %i", idx); | ||
1004 | 997 | |||
1005 | 998 | /* get device properties */ | ||
1006 | 999 | g_object_set (device, | ||
1007 | 1000 | "kind", UP_DEVICE_KIND_PHONE, | ||
1008 | 1001 | "is-rechargeable", TRUE, | ||
1009 | 1002 | "native-path", g_strdup_printf ("dummy:phone_%i", idx), | ||
1010 | 1003 | "is-present", TRUE, | ||
1011 | 1004 | NULL); | ||
1012 | 1005 | |||
1013 | 1006 | /* state changed */ | ||
1014 | 1007 | gpm_engine_device_add (engine, device); | ||
1015 | 1008 | g_ptr_array_add (engine->priv->array, g_object_ref (device)); | ||
1016 | 1009 | gpm_engine_recalculate_state (engine); | ||
1017 | 1010 | } | ||
1018 | 1011 | |||
1019 | 1012 | /** | ||
1020 | 1013 | * phone_device_removed_cb: | ||
1021 | 1014 | **/ | ||
1022 | 1015 | static void | ||
1023 | 1016 | phone_device_removed_cb (GpmPhone *phone, guint idx, GpmEngine *engine) | ||
1024 | 1017 | { | ||
1025 | 1018 | guint i; | ||
1026 | 1019 | UpDevice *device; | ||
1027 | 1020 | UpDeviceKind kind; | ||
1028 | 1021 | |||
1029 | 1022 | egg_debug ("phone removed %i", idx); | ||
1030 | 1023 | |||
1031 | 1024 | for (i=0; i<engine->priv->array->len; i++) { | ||
1032 | 1025 | device = g_ptr_array_index (engine->priv->array, i); | ||
1033 | 1026 | |||
1034 | 1027 | /* get device properties */ | ||
1035 | 1028 | g_object_get (device, | ||
1036 | 1029 | "kind", &kind, | ||
1037 | 1030 | NULL); | ||
1038 | 1031 | |||
1039 | 1032 | if (kind == UP_DEVICE_KIND_PHONE) { | ||
1040 | 1033 | g_ptr_array_remove_index (engine->priv->array, i); | ||
1041 | 1034 | break; | ||
1042 | 1035 | } | ||
1043 | 1036 | } | ||
1044 | 1037 | |||
1045 | 1038 | /* state changed */ | ||
1046 | 1039 | gpm_engine_recalculate_state (engine); | ||
1047 | 1040 | } | ||
1048 | 1041 | |||
1049 | 1042 | /** | ||
1050 | 1043 | * phone_device_refresh_cb: | ||
1051 | 1044 | **/ | ||
1052 | 1045 | static void | ||
1053 | 1046 | phone_device_refresh_cb (GpmPhone *phone, guint idx, GpmEngine *engine) | ||
1054 | 1047 | { | ||
1055 | 1048 | guint i; | ||
1056 | 1049 | UpDevice *device; | ||
1057 | 1050 | UpDeviceKind kind; | ||
1058 | 1051 | UpDeviceState state; | ||
1059 | 1052 | gboolean is_present; | ||
1060 | 1053 | gdouble percentage; | ||
1061 | 1054 | |||
1062 | 1055 | egg_debug ("phone refresh %i", idx); | ||
1063 | 1056 | |||
1064 | 1057 | for (i=0; i<engine->priv->array->len; i++) { | ||
1065 | 1058 | device = g_ptr_array_index (engine->priv->array, i); | ||
1066 | 1059 | |||
1067 | 1060 | /* get device properties */ | ||
1068 | 1061 | g_object_get (device, | ||
1069 | 1062 | "kind", &kind, | ||
1070 | 1063 | "state", &state, | ||
1071 | 1064 | "percentage", &percentage, | ||
1072 | 1065 | "is-present", &is_present, | ||
1073 | 1066 | NULL); | ||
1074 | 1067 | |||
1075 | 1068 | if (kind == UP_DEVICE_KIND_PHONE) { | ||
1076 | 1069 | is_present = gpm_phone_get_present (phone, idx); | ||
1077 | 1070 | state = gpm_phone_get_on_ac (phone, idx) ? UP_DEVICE_STATE_CHARGING : UP_DEVICE_STATE_DISCHARGING; | ||
1078 | 1071 | percentage = gpm_phone_get_percentage (phone, idx); | ||
1079 | 1072 | break; | ||
1080 | 1073 | } | ||
1081 | 1074 | } | ||
1082 | 1075 | |||
1083 | 1076 | /* state changed */ | ||
1084 | 1077 | gpm_engine_recalculate_state (engine); | ||
1085 | 1078 | } | ||
1086 | 1079 | |||
1087 | 1080 | /** | ||
1088 | 1081 | * gpm_engine_init: | ||
1089 | 1082 | * @engine: This class instance | ||
1090 | 1083 | **/ | ||
1091 | 1084 | static void | ||
1092 | 1085 | gpm_engine_init (GpmEngine *engine) | ||
1093 | 1086 | { | ||
1094 | 1087 | gchar *icon_policy; | ||
1095 | 1088 | |||
1096 | 1089 | engine->priv = GPM_ENGINE_GET_PRIVATE (engine); | ||
1097 | 1090 | |||
1098 | 1091 | engine->priv->array = g_ptr_array_new_with_free_func (g_object_unref); | ||
1099 | 1092 | engine->priv->client = up_client_new (); | ||
1100 | 1093 | g_signal_connect (engine->priv->client, "device-added", | ||
1101 | 1094 | G_CALLBACK (gpm_engine_device_added_cb), engine); | ||
1102 | 1095 | g_signal_connect (engine->priv->client, "device-removed", | ||
1103 | 1096 | G_CALLBACK (gpm_engine_device_removed_cb), engine); | ||
1104 | 1097 | g_signal_connect (engine->priv->client, "device-changed", | ||
1105 | 1098 | G_CALLBACK (gpm_engine_device_changed_cb), engine); | ||
1106 | 1099 | |||
1107 | 1100 | engine->priv->conf = gconf_client_get_default (); | ||
1108 | 1101 | gconf_client_notify_add (engine->priv->conf, GPM_CONF_DIR, | ||
1109 | 1102 | (GConfClientNotifyFunc) gpm_engine_conf_key_changed_cb, | ||
1110 | 1103 | engine, NULL, NULL); | ||
1111 | 1104 | |||
1112 | 1105 | engine->priv->phone = gpm_phone_new (); | ||
1113 | 1106 | g_signal_connect (engine->priv->phone, "device-added", | ||
1114 | 1107 | G_CALLBACK (phone_device_added_cb), engine); | ||
1115 | 1108 | g_signal_connect (engine->priv->phone, "device-removed", | ||
1116 | 1109 | G_CALLBACK (phone_device_removed_cb), engine); | ||
1117 | 1110 | g_signal_connect (engine->priv->phone, "device-refresh", | ||
1118 | 1111 | G_CALLBACK (phone_device_refresh_cb), engine); | ||
1119 | 1112 | |||
1120 | 1113 | /* create a fake virtual composite battery */ | ||
1121 | 1114 | engine->priv->battery_composite = up_device_new (); | ||
1122 | 1115 | g_object_set (engine->priv->battery_composite, | ||
1123 | 1116 | "kind", UP_DEVICE_KIND_BATTERY, | ||
1124 | 1117 | "is-rechargeable", TRUE, | ||
1125 | 1118 | "native-path", "dummy:composite_battery", | ||
1126 | 1119 | "power-supply", TRUE, | ||
1127 | 1120 | "is-present", TRUE, | ||
1128 | 1121 | NULL); | ||
1129 | 1122 | |||
1130 | 1123 | engine->priv->previous_icon = NULL; | ||
1131 | 1124 | engine->priv->previous_summary = NULL; | ||
1132 | 1125 | |||
1133 | 1126 | /* do we want to display the icon in the tray */ | ||
1134 | 1127 | icon_policy = gconf_client_get_string (engine->priv->conf, GPM_CONF_UI_ICON_POLICY, NULL); | ||
1135 | 1128 | engine->priv->icon_policy = gpm_icon_policy_from_string (icon_policy); | ||
1136 | 1129 | g_free (icon_policy); | ||
1137 | 1130 | |||
1138 | 1131 | /* get percentage policy */ | ||
1139 | 1132 | engine->priv->low_percentage = gconf_client_get_int (engine->priv->conf, GPM_CONF_THRESH_PERCENTAGE_LOW, NULL); | ||
1140 | 1133 | engine->priv->critical_percentage = gconf_client_get_int (engine->priv->conf, GPM_CONF_THRESH_PERCENTAGE_CRITICAL, NULL); | ||
1141 | 1134 | engine->priv->action_percentage = gconf_client_get_int (engine->priv->conf, GPM_CONF_THRESH_PERCENTAGE_ACTION, NULL); | ||
1142 | 1135 | |||
1143 | 1136 | /* get time policy */ | ||
1144 | 1137 | engine->priv->low_time = gconf_client_get_int (engine->priv->conf, GPM_CONF_THRESH_TIME_LOW, NULL); | ||
1145 | 1138 | engine->priv->critical_time = gconf_client_get_int (engine->priv->conf, GPM_CONF_THRESH_TIME_CRITICAL, NULL); | ||
1146 | 1139 | engine->priv->action_time = gconf_client_get_int (engine->priv->conf, GPM_CONF_THRESH_TIME_ACTION, NULL); | ||
1147 | 1140 | |||
1148 | 1141 | /* we can disable this if the time remaining is inaccurate or just plain wrong */ | ||
1149 | 1142 | engine->priv->use_time_primary = gconf_client_get_bool (engine->priv->conf, GPM_CONF_USE_TIME_POLICY, NULL); | ||
1150 | 1143 | if (engine->priv->use_time_primary) | ||
1151 | 1144 | egg_debug ("Using per-time notification policy"); | ||
1152 | 1145 | else | ||
1153 | 1146 | egg_debug ("Using percentage notification policy"); | ||
1154 | 1147 | |||
1155 | 1148 | g_idle_add ((GSourceFunc) gpm_engine_coldplug_idle_cb, engine); | ||
1156 | 1149 | } | ||
1157 | 1150 | |||
1158 | 1151 | /** | ||
1159 | 1152 | * gpm_engine_class_init: | ||
1160 | 1153 | * @engine: This class instance | ||
1161 | 1154 | **/ | ||
1162 | 1155 | static void | ||
1163 | 1156 | gpm_engine_class_init (GpmEngineClass *klass) | ||
1164 | 1157 | { | ||
1165 | 1158 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | ||
1166 | 1159 | object_class->finalize = gpm_engine_finalize; | ||
1167 | 1160 | g_type_class_add_private (klass, sizeof (GpmEnginePrivate)); | ||
1168 | 1161 | |||
1169 | 1162 | signals [ICON_CHANGED] = | ||
1170 | 1163 | g_signal_new ("icon-changed", | ||
1171 | 1164 | G_TYPE_FROM_CLASS (object_class), | ||
1172 | 1165 | G_SIGNAL_RUN_LAST, | ||
1173 | 1166 | G_STRUCT_OFFSET (GpmEngineClass, icon_changed), | ||
1174 | 1167 | NULL, NULL, g_cclosure_marshal_VOID__STRING, | ||
1175 | 1168 | G_TYPE_NONE, 1, G_TYPE_STRING); | ||
1176 | 1169 | signals [SUMMARY_CHANGED] = | ||
1177 | 1170 | g_signal_new ("summary-changed", | ||
1178 | 1171 | G_TYPE_FROM_CLASS (object_class), | ||
1179 | 1172 | G_SIGNAL_RUN_LAST, | ||
1180 | 1173 | G_STRUCT_OFFSET (GpmEngineClass, summary_changed), | ||
1181 | 1174 | NULL, NULL, g_cclosure_marshal_VOID__STRING, | ||
1182 | 1175 | G_TYPE_NONE, 1, G_TYPE_STRING); | ||
1183 | 1176 | signals [LOW_CAPACITY] = | ||
1184 | 1177 | g_signal_new ("low-capacity", | ||
1185 | 1178 | G_TYPE_FROM_CLASS (object_class), | ||
1186 | 1179 | G_SIGNAL_RUN_LAST, | ||
1187 | 1180 | G_STRUCT_OFFSET (GpmEngineClass, low_capacity), | ||
1188 | 1181 | NULL, NULL, g_cclosure_marshal_VOID__POINTER, | ||
1189 | 1182 | G_TYPE_NONE, 1, G_TYPE_POINTER); | ||
1190 | 1183 | signals [PERHAPS_RECALL] = | ||
1191 | 1184 | g_signal_new ("perhaps-recall", | ||
1192 | 1185 | G_TYPE_FROM_CLASS (object_class), | ||
1193 | 1186 | G_SIGNAL_RUN_LAST, | ||
1194 | 1187 | G_STRUCT_OFFSET (GpmEngineClass, perhaps_recall), | ||
1195 | 1188 | NULL, NULL, gpm_marshal_VOID__POINTER_STRING_STRING, | ||
1196 | 1189 | G_TYPE_NONE, | ||
1197 | 1190 | 3, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_STRING); | ||
1198 | 1191 | signals [FULLY_CHARGED] = | ||
1199 | 1192 | g_signal_new ("fully-charged", | ||
1200 | 1193 | G_TYPE_FROM_CLASS (object_class), | ||
1201 | 1194 | G_SIGNAL_RUN_LAST, | ||
1202 | 1195 | G_STRUCT_OFFSET (GpmEngineClass, fully_charged), | ||
1203 | 1196 | NULL, NULL, g_cclosure_marshal_VOID__POINTER, | ||
1204 | 1197 | G_TYPE_NONE, 1, G_TYPE_POINTER); | ||
1205 | 1198 | signals [DISCHARGING] = | ||
1206 | 1199 | g_signal_new ("discharging", | ||
1207 | 1200 | G_TYPE_FROM_CLASS (object_class), | ||
1208 | 1201 | G_SIGNAL_RUN_LAST, | ||
1209 | 1202 | G_STRUCT_OFFSET (GpmEngineClass, discharging), | ||
1210 | 1203 | NULL, NULL, g_cclosure_marshal_VOID__POINTER, | ||
1211 | 1204 | G_TYPE_NONE, 1, G_TYPE_POINTER); | ||
1212 | 1205 | signals [CHARGE_ACTION] = | ||
1213 | 1206 | g_signal_new ("charge-action", | ||
1214 | 1207 | G_TYPE_FROM_CLASS (object_class), | ||
1215 | 1208 | G_SIGNAL_RUN_LAST, | ||
1216 | 1209 | G_STRUCT_OFFSET (GpmEngineClass, charge_action), | ||
1217 | 1210 | NULL, NULL, g_cclosure_marshal_VOID__POINTER, | ||
1218 | 1211 | G_TYPE_NONE, 1, G_TYPE_POINTER); | ||
1219 | 1212 | signals [CHARGE_LOW] = | ||
1220 | 1213 | g_signal_new ("charge-low", | ||
1221 | 1214 | G_TYPE_FROM_CLASS (object_class), | ||
1222 | 1215 | G_SIGNAL_RUN_LAST, | ||
1223 | 1216 | G_STRUCT_OFFSET (GpmEngineClass, charge_low), | ||
1224 | 1217 | NULL, NULL, g_cclosure_marshal_VOID__POINTER, | ||
1225 | 1218 | G_TYPE_NONE, 1, G_TYPE_POINTER); | ||
1226 | 1219 | signals [CHARGE_CRITICAL] = | ||
1227 | 1220 | g_signal_new ("charge-critical", | ||
1228 | 1221 | G_TYPE_FROM_CLASS (object_class), | ||
1229 | 1222 | G_SIGNAL_RUN_LAST, | ||
1230 | 1223 | G_STRUCT_OFFSET (GpmEngineClass, charge_critical), | ||
1231 | 1224 | NULL, NULL, g_cclosure_marshal_VOID__POINTER, | ||
1232 | 1225 | G_TYPE_NONE, 1, G_TYPE_POINTER); | ||
1233 | 1226 | signals [DEVICES_CHANGED] = | ||
1234 | 1227 | g_signal_new ("devices-changed", | ||
1235 | 1228 | G_TYPE_FROM_CLASS (object_class), | ||
1236 | 1229 | G_SIGNAL_RUN_LAST, | ||
1237 | 1230 | G_STRUCT_OFFSET (GpmEngineClass, devices_changed), | ||
1238 | 1231 | NULL, NULL, g_cclosure_marshal_VOID__VOID, | ||
1239 | 1232 | G_TYPE_NONE, 0); | ||
1240 | 1233 | } | ||
1241 | 1234 | |||
1242 | 1235 | /** | ||
1243 | 1236 | * gpm_engine_finalize: | ||
1244 | 1237 | * @object: This class instance | ||
1245 | 1238 | **/ | ||
1246 | 1239 | static void | ||
1247 | 1240 | gpm_engine_finalize (GObject *object) | ||
1248 | 1241 | { | ||
1249 | 1242 | GpmEngine *engine; | ||
1250 | 1243 | |||
1251 | 1244 | g_return_if_fail (object != NULL); | ||
1252 | 1245 | g_return_if_fail (GPM_IS_ENGINE (object)); | ||
1253 | 1246 | |||
1254 | 1247 | engine = GPM_ENGINE (object); | ||
1255 | 1248 | engine->priv = GPM_ENGINE_GET_PRIVATE (engine); | ||
1256 | 1249 | |||
1257 | 1250 | g_ptr_array_unref (engine->priv->array); | ||
1258 | 1251 | g_object_unref (engine->priv->client); | ||
1259 | 1252 | g_object_unref (engine->priv->phone); | ||
1260 | 1253 | g_object_unref (engine->priv->battery_composite); | ||
1261 | 1254 | |||
1262 | 1255 | g_free (engine->priv->previous_icon); | ||
1263 | 1256 | g_free (engine->priv->previous_summary); | ||
1264 | 1257 | |||
1265 | 1258 | G_OBJECT_CLASS (gpm_engine_parent_class)->finalize (object); | ||
1266 | 1259 | } | ||
1267 | 1260 | |||
1268 | 1261 | /** | ||
1269 | 1262 | * gpm_engine_new: | ||
1270 | 1263 | * Return value: new class instance. | ||
1271 | 1264 | **/ | ||
1272 | 1265 | GpmEngine * | ||
1273 | 1266 | gpm_engine_new (void) | ||
1274 | 1267 | { | ||
1275 | 1268 | if (gpm_engine_object != NULL) { | ||
1276 | 1269 | g_object_ref (gpm_engine_object); | ||
1277 | 1270 | } else { | ||
1278 | 1271 | gpm_engine_object = g_object_new (GPM_TYPE_ENGINE, NULL); | ||
1279 | 1272 | g_object_add_weak_pointer (gpm_engine_object, &gpm_engine_object); | ||
1280 | 1273 | } | ||
1281 | 1274 | return GPM_ENGINE (gpm_engine_object); | ||
1282 | 1275 | |||
1283 | 1276 | } | ||
1284 | 1277 | |||
1285 | 0 | 1278 | ||
1286 | === modified file '.pc/applied-patches' | |||
1287 | --- .pc/applied-patches 2011-03-15 01:04:40 +0000 | |||
1288 | +++ .pc/applied-patches 2011-07-10 20:29:23 +0000 | |||
1289 | @@ -6,3 +6,4 @@ | |||
1290 | 6 | 14_fix_no_xbacklight_crash.patch | 6 | 14_fix_no_xbacklight_crash.patch |
1291 | 7 | 14-critical-message-timeout.patch | 7 | 14-critical-message-timeout.patch |
1292 | 8 | 15-keyboard-backlight-support.patch | 8 | 15-keyboard-backlight-support.patch |
1293 | 9 | 16-fix-duplicate-battery.patch | ||
1294 | 9 | 10 | ||
1295 | === modified file 'debian/changelog' | |||
1296 | --- debian/changelog 2011-03-15 01:04:40 +0000 | |||
1297 | +++ debian/changelog 2011-07-10 20:29:23 +0000 | |||
1298 | @@ -1,3 +1,11 @@ | |||
1299 | 1 | gnome-power-manager (2.32.0-2ubuntu3) natty; urgency=low | ||
1300 | 2 | |||
1301 | 3 | * 16-fix-duplicate-battery.patch: Don't add hot-added battery to device | ||
1302 | 4 | list, because libupower-glib already does that (LP: #675108) | ||
1303 | 5 | [ Maxim Levitsky <maximlevitsky@gmail.com> ] | ||
1304 | 6 | |||
1305 | 7 | -- Phillip Susi <psusi@ubuntu.com> Mon, 13 Jun 2011 14:04:01 -0400 | ||
1306 | 8 | |||
1307 | 1 | gnome-power-manager (2.32.0-2ubuntu2) natty; urgency=low | 9 | gnome-power-manager (2.32.0-2ubuntu2) natty; urgency=low |
1308 | 2 | 10 | ||
1309 | 3 | [ Alex Murray <murray.alex@gmail.com> ] | 11 | [ Alex Murray <murray.alex@gmail.com> ] |
1310 | 4 | 12 | ||
1311 | === added file 'debian/patches/16-fix-duplicate-battery.patch' | |||
1312 | --- debian/patches/16-fix-duplicate-battery.patch 1970-01-01 00:00:00 +0000 | |||
1313 | +++ debian/patches/16-fix-duplicate-battery.patch 2011-07-10 20:29:23 +0000 | |||
1314 | @@ -0,0 +1,20 @@ | |||
1315 | 1 | Description: Don't add hot-added battery to device list, because libupower-glib | ||
1316 | 2 | already does that (LP: #616443) | ||
1317 | 3 | Author: Maxim Levitsky <maximlevitsky@gmail.com> | ||
1318 | 4 | Bug-Ubuntu: https://launchpad.net/bugs/616443 | ||
1319 | 5 | Forwarded: no | ||
1320 | 6 | Last-Update: <2011-06-13> | ||
1321 | 7 | |||
1322 | 8 | --- gnome-power-manager-2.32.0.orig/src/gpm-engine.c | ||
1323 | 9 | +++ gnome-power-manager-2.32.0/src/gpm-engine.c | ||
1324 | 10 | @@ -886,10 +886,7 @@ out: | ||
1325 | 11 | static void | ||
1326 | 12 | gpm_engine_device_added_cb (UpClient *client, UpDevice *device, GpmEngine *engine) | ||
1327 | 13 | { | ||
1328 | 14 | - /* add to list */ | ||
1329 | 15 | - g_ptr_array_add (engine->priv->array, g_object_ref (device)); | ||
1330 | 16 | gpm_engine_check_recall (engine, device); | ||
1331 | 17 | - | ||
1332 | 18 | gpm_engine_recalculate_state (engine); | ||
1333 | 19 | } | ||
1334 | 20 | |||
1335 | 0 | 21 | ||
1336 | === modified file 'debian/patches/series' | |||
1337 | --- debian/patches/series 2011-03-15 01:04:40 +0000 | |||
1338 | +++ debian/patches/series 2011-07-10 20:29:23 +0000 | |||
1339 | @@ -6,3 +6,5 @@ | |||
1340 | 6 | 14_fix_no_xbacklight_crash.patch | 6 | 14_fix_no_xbacklight_crash.patch |
1341 | 7 | 14-critical-message-timeout.patch | 7 | 14-critical-message-timeout.patch |
1342 | 8 | 15-keyboard-backlight-support.patch | 8 | 15-keyboard-backlight-support.patch |
1343 | 9 | 16-fix-duplicate-battery.patch | ||
1344 | 10 | |||
1345 | 9 | 11 | ||
1346 | === modified file 'src/gpm-engine.c' | |||
1347 | --- src/gpm-engine.c 2011-01-26 17:20:06 +0000 | |||
1348 | +++ src/gpm-engine.c 2011-07-10 20:29:23 +0000 | |||
1349 | @@ -886,10 +886,7 @@ | |||
1350 | 886 | static void | 886 | static void |
1351 | 887 | gpm_engine_device_added_cb (UpClient *client, UpDevice *device, GpmEngine *engine) | 887 | gpm_engine_device_added_cb (UpClient *client, UpDevice *device, GpmEngine *engine) |
1352 | 888 | { | 888 | { |
1353 | 889 | /* add to list */ | ||
1354 | 890 | g_ptr_array_add (engine->priv->array, g_object_ref (device)); | ||
1355 | 891 | gpm_engine_check_recall (engine, device); | 889 | gpm_engine_check_recall (engine, device); |
1356 | 892 | |||
1357 | 893 | gpm_engine_recalculate_state (engine); | 890 | gpm_engine_recalculate_state (engine); |
1358 | 894 | } | 891 | } |
1359 | 895 | 892 |
See comments in above referenced bug re SRU paperwork and oneiric fix.