Merge lp:~psusi/ubuntu/natty/gnome-power-manager/fix-duplicate-battery into lp:ubuntu/natty/gnome-power-manager

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
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.

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

See comments in above referenced bug re SRU paperwork and oneiric fix.

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

Subscribers

People subscribed via source and target branches

to all changes: