summaryrefslogtreecommitdiff
path: root/src/gpm-engine.c
diff options
context:
space:
mode:
authorraveit65 <[email protected]>2016-07-10 17:43:40 +0200
committerraveit65 <[email protected]>2016-07-25 16:13:41 +0200
commit85afd16cee70390540d73e0b66999b0d859d299e (patch)
tree97d2571ee1ff6d1bdc77c6dcc3da0c438bd6c093 /src/gpm-engine.c
parentab62a95bb36351eb67638a992bfc57aff3deda87 (diff)
downloadmate-power-manager-85afd16cee70390540d73e0b66999b0d859d299e.tar.bz2
mate-power-manager-85afd16cee70390540d73e0b66999b0d859d299e.tar.xz
Show the primary device time remaining as the first entry in the context menu
taken from: https://git.gnome.org/browse/gnome-power-manager/commit/?id=93da9b4
Diffstat (limited to 'src/gpm-engine.c')
-rw-r--r--src/gpm-engine.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/gpm-engine.c b/src/gpm-engine.c
index 6f16381..611ccf5 100644
--- a/src/gpm-engine.c
+++ b/src/gpm-engine.c
@@ -1012,6 +1012,50 @@ gpm_engine_get_devices (GpmEngine *engine)
}
/**
+ * gpm_engine_get_primary_device:
+ *
+ * Return value: the #UpDevice, free with g_object_unref()
+ **/
+UpDevice *
+gpm_engine_get_primary_device (GpmEngine *engine)
+{
+ guint i;
+ UpDevice *device = NULL;
+ UpDevice *device_tmp;
+ UpDeviceKind kind;
+ UpDeviceState state;
+ gboolean is_present;
+
+ for (i=0; i<engine->priv->array->len; i++) {
+ device_tmp = g_ptr_array_index (engine->priv->array, i);
+
+ /* get device properties */
+ g_object_get (device_tmp,
+ "kind", &kind,
+ "state", &state,
+ "is-present", &is_present,
+ NULL);
+
+ /* not present */
+ if (!is_present)
+ continue;
+
+ /* not discharging */
+ if (state != UP_DEVICE_STATE_DISCHARGING)
+ continue;
+
+ /* not battery */
+ if (kind != UP_DEVICE_KIND_BATTERY)
+ continue;
+
+ /* use composite device to cope with multiple batteries */
+ device = g_object_ref (gpm_engine_get_composite_device (engine, device_tmp));
+ break;
+ }
+ return device;
+}
+
+/**
* phone_device_added_cb:
**/
static void