summaryrefslogtreecommitdiff
path: root/lib/battery/upower.vala
diff options
context:
space:
mode:
Diffstat (limited to 'lib/battery/upower.vala')
-rw-r--r--lib/battery/upower.vala32
1 files changed, 27 insertions, 5 deletions
diff --git a/lib/battery/upower.vala b/lib/battery/upower.vala
index 9c18ffd..223633e 100644
--- a/lib/battery/upower.vala
+++ b/lib/battery/upower.vala
@@ -1,23 +1,40 @@
-namespace AstalBattery {
-public class UPower : Object {
+/**
+ * Client for the UPower [[https://upower.freedesktop.org/docs/UPower.html|dbus interface]].
+ */
+public class AstalBattery.UPower : Object {
private IUPower proxy;
private HashTable<string, Device> _devices =
new HashTable<string, Device>(str_hash, str_equal);
+ /** List of UPower devices. */
public List<weak Device> devices {
owned get { return _devices.get_values(); }
}
+ /** Emitted when a new device is connected. */
public signal void device_added(Device device);
+
+ /** Emitted a new device is disconnected. */
public signal void device_removed(Device device);
+ /** A composite device that represents the battery status. */
public Device display_device { owned get { return Device.get_default(); }}
public string daemon_version { owned get { return proxy.daemon_version; } }
+
+ /** Indicates whether the system is running on battery power. */
public bool on_battery { get { return proxy.on_battery; } }
+
+ /** Indicates if the laptop lid is closed where the display cannot be seen. */
public bool lid_is_closed { get { return proxy.lid_is_closed; } }
+
+ /** Indicates if the system has a lid device. */
public bool lis_is_present { get { return proxy.lid_is_closed; } }
+ /**
+ * When the system's power supply is critical (critically low batteries or UPS),
+ * the system will take this action.
+ */
public string critical_action {
owned get {
try {
@@ -41,8 +58,14 @@ public class UPower : Object {
_devices.set(path, new Device(path));
proxy.device_added.connect((path) => {
- _devices.set(path, new Device(path));
- notify_property("devices");
+ try {
+ var d = new Device(path);
+ _devices.set(path, d);
+ device_added(d);
+ notify_property("devices");
+ } catch (Error err) {
+ critical(err.message);
+ }
});
proxy.device_removed.connect((path) => {
@@ -55,4 +78,3 @@ public class UPower : Object {
}
}
}
-}