diff --git a/src/solid/devices/backends/upower/CMakeLists.txt b/src/solid/devices/backends/upower/CMakeLists.txt --- a/src/solid/devices/backends/upower/CMakeLists.txt +++ b/src/solid/devices/backends/upower/CMakeLists.txt @@ -5,3 +5,12 @@ devices/backends/upower/upowerdeviceinterface.cpp devices/backends/upower/upowergenericinterface.cpp ) + +set(UPOWER_INTERFACE_XML devices/backends/upower/dbus/org.freedesktop.UPower.xml) +set(UPOWER_DEVICE_INTERFACE_XML devices/backends/upower/dbus/org.freedesktop.UPower.Device.xml) + +set_source_files_properties(${UPOWER_INTERFACE_XML} PROPERTIES NO_NAMESPACE true) +qt5_add_dbus_interface(solid_LIB_SRCS ${UPOWER_INTERFACE_XML} upower_interface) + +set_source_files_properties(${UPOWER_DEVICE_INTERFACE_XML} PROPERTIES NO_NAMESPACE true) +qt5_add_dbus_interface(solid_LIB_SRCS ${UPOWER_DEVICE_INTERFACE_XML} upower_device_interface) diff --git a/src/solid/devices/backends/upower/dbus/org.freedesktop.UPower.Device.xml b/src/solid/devices/backends/upower/dbus/org.freedesktop.UPower.Device.xml new file mode 100644 --- /dev/null +++ b/src/solid/devices/backends/upower/dbus/org.freedesktop.UPower.Device.xml @@ -0,0 +1,668 @@ + +]> + + + + + + Objects implementing this interface are usually discovered through + the org.freedesktop.UPower interface on + the /org/freedesktop/UPower object on + the D-Bus system bus service with the well-known + name org.freedesktop.UPower using + the + EnumerateDevices + method. + + + + +$ dbus-send --print-reply \ + --system \ + --dest=org.freedesktop.UPower \ + /org/freedesktop/UPower/devices/battery_BAT0 \ + org.freedesktop.DBus.Properties.GetAll \ + string:org.freedesktop.UPower.Device + +method return sender=:1.386 -> dest=:1.477 reply_serial=2 + array [ + dict entry( + string "native-path" + variant string "/sys/devices/LNXSYSTM:00/device:00/PNP0A08:00/device:01/PNP0C09:00/PNP0C0A:00/power_supply/BAT0" + ) + dict entry( + string "vendor" + variant string "SONY" + ) + dict entry( + string "model" + variant string "42T4568" + ) + dict entry( + string "serial" + variant string "4179" + ) + dict entry( + string "update-time" + variant uint64 1226417875 + ) + dict entry( + string "type" + variant uint 2 + ) + dict entry( + string "power-supply" + variant boolean true + ) + dict entry( + string "has-history" + variant boolean true + ) + dict entry( + string "has-statistics" + variant boolean true + ) + dict entry( + string "online" + variant boolean false + ) + dict entry( + string "energy" + variant double 72.85 + ) + dict entry( + string "energy-empty" + variant double 0 + ) + dict entry( + string "energy-full" + variant double 74.55 + ) + dict entry( + string "energy-full-design" + variant double 74.88 + ) + dict entry( + string "energy-rate" + variant double 0 + ) + dict entry( + string "voltage" + variant double 16.415 + ) + dict entry( + string "time-to-empty" + variant int64 0 + ) + dict entry( + string "time-to-full" + variant int64 0 + ) + dict entry( + string "percentage" + variant double 97.7197 + ) + dict entry( + string "is-present" + variant boolean true + ) + dict entry( + string "state" + variant uint 3 + ) + dict entry( + string "is-rechargeable" + variant boolean true + ) + dict entry( + string "capacity" + variant double 100 + ) + dict entry( + string "technology" + variant uint 1 + ) + ] + + + + + Unless otherwise noted, an empty string or the value 0 in a + property on this interface means not set. + + + + + + + + + + + + Refreshes the data collected from the power source. + + + Callers need the org.freedesktop.upower.refresh-power-source authorization + + if an error occured while refreshing + + + + + + + + + + + + OS specific native path of the power source. On Linux this + is the sysfs path, for + example /sys/devices/LNXSYSTM:00/device:00/PNP0C0A:00/power_supply/BAT0. Is + blank if the device is being driven by a user space + driver. + + + + + + + + + + Name of the vendor of the battery. + + + + + + + + + + Name of the model of this battery. + + + + + + + + + + Unique serial number of the battery. + + + + + + + + + + The point in time (seconds since the Epoch Jan 1, 1970 + 0:00 UTC) that data was read from the power source. + + + + + + + + + + Type of power source. + + + + 0Unknown + + + 1Line Power + + + 2Battery + + + 3Ups + + + 4Monitor + + + 5Mouse + + + 6Keyboard + + + 7Pda + + + 8Phone + + + + + + + + + + + If the power device is used to supply the system. + This would be set TRUE for laptop batteries and UPS devices, + but set FALSE for wireless mice or PDAs. + + + + + + + + + + If the power device has history. + + + + + + + + + + If the power device has statistics. + + + + + + + + + + Whether power is currently being provided through line power. + This property is only valid if the property + type + has the value "line-power". + + + + + + + + + + Amount of energy (measured in Wh) currently available in + the power source. + + This property is only valid if the property + type + has the value "battery". + + + + + + + + + + Amount of energy (measured in Wh) in the power source when + it's considered to be empty. + + This property is only valid if the property + type + has the value "battery". + + + + + + + + + + Amount of energy (measured in Wh) in the power source when + it's considered full. + + This property is only valid if the property + type + has the value "battery". + + + + + + + + + + Amount of energy (measured in Wh) the power source is + designed to hold when it's considered full. + + This property is only valid if the property + type + has the value "battery". + + + + + + + + + + Amount of energy being drained from the source, measured + in W. If positive, the source is being discharged, if + negative it's being charged. + + This property is only valid if the property + type + has the value "battery". + + + + + + + + + + Voltage in the Cell or being recorded by the meter. + + + + + + + + + + Luminosity being recorded by the meter. + + + + + + + + + + Number of seconds until the power source is considered empty. + Is set to 0 if unknown. + + This property is only valid if the property + type + has the value "battery". + + + + + + + + + + Number of seconds until the power source is considered full. + Is set to 0 if unknown. + + This property is only valid if the property + type + has the value "battery". + + + + + + + + + + The amount of energy left in the power source expressed as + a percentage between 0 and 100. Typically this is the same as + (energy - + energy-empty) / + (energy-full - + energy-empty). + However, some primitive power sources are capable of only + reporting percentages and in this case the energy-* + properties will be unset while this property is set. + + This property is only valid if the property + type + has the value "battery". + + + The percentage will be an approximation if the battery level + is set to something other than None. The percentage is kept for compatibility reasons. + + + + + + + + + + The temperature of the device in degrees Celsius. This property is + only valid if the property + type + has the value "battery". + + + + + + + + + + If the power source is present in the bay. + This field is required as some batteries are hot-removable, for example + expensive UPS and most laptop batteries. + + This property is only valid if the property + type + has the value "battery". + + + + + + + + + + The battery power state. + + + + 0Unknown + + + 1Charging + + + 2Discharging + + + 3Empty + + + 4Fully charged + + + 5Pending charge + + + 6Pending discharge + + + + This property is only valid if the property + type + has the value "battery". + + + + + + + + + + If the power source is rechargeable. + + This property is only valid if the property + type + has the value "battery". + + + + + + + + + + The capacity of the power source expressed as a percentage between 0 and 100. + The capacity of the battery will reduce with age. + A capacity value less than 75% is usually a sign that you should renew your battery. + Typically this value is the same as + (full-design / + full) * 100. + However, some primitive power sources are not capable reporting capacity + and in this case the capacity property will be unset. + + This property is only valid if the property + type + has the value "battery". + + + + + + + + + + Technology used in the battery: + + + + 0Unknown + + + 1Lithium ion + + + 2Lithium polymer + + + 3Lithium iron phosphate + + + 4Lead acid + + + 5Nickel cadmium + + + 6Nickel metal hydride + + + + This property is only valid if the property + type + has the value "battery". + + + + + + + + + + Warning level of the battery: + + + + 0Unknown + + + 1None + + + 2Discharging (only for UPSes) + + + 3Low + + + 4Critical + + + 5Action + + + + + + + + + + + The level of the battery for devices which do not report a percentage but rather a coarse battery level. If the value + is None, then the device does not support coarse battery reporting, and the percentage should be used instead. + + + + 0Unknown + + + 1None (the battery does not use a coarse level of battery reporting) + + + 3Low + + + 4Critical + + + 6Normal + + + 7High + + + 8Full + + + + + + + + + + +

An icon name, following the Icon Naming Specification

+

Note that the icons might not match end-user expectations in terms of presentation relative to the amount of battery left or perceived to be left. It is recommended that front-ends use the BatteryLevel property first, if available, followed by the Percentage, to present a more realistic battery level to the user.

+
+
+
+
+
+ +
diff --git a/src/solid/devices/backends/upower/dbus/org.freedesktop.UPower.xml b/src/solid/devices/backends/upower/dbus/org.freedesktop.UPower.xml new file mode 100644 --- /dev/null +++ b/src/solid/devices/backends/upower/dbus/org.freedesktop.UPower.xml @@ -0,0 +1,204 @@ + + + + + + + + The UPower service is available via the system message + bus. To access the service, use + the org.freedesktop.UPower interface on + the /org/freedesktop/UPower object on + the D-Bus system bus service with the well-known + name org.freedesktop.UPower. + + + + +$ dbus-send --print-reply \ + --system \ + --dest=org.freedesktop.UPower \ + /org/freedesktop/UPower \ + org.freedesktop.UPower.EnumerateDevices + +method return sender=:1.386 -> dest=:1.451 reply_serial=2 + array [ + object path "/org/freedesktop/UPower/devices/line_power_AC" + object path "/org/freedesktop/UPower/devices/battery_BAT0" + ] + + + + + + + + + + + + An array of object paths for devices. + + + + + + Enumerate all power objects on the system. + + + + + + + + + An object path for the "display device. + + + + + + Get the object to the "display device", a composite device that represents the + status icon to show in desktop environments. You can also access the object directly + as its path is guaranteed to be /org/freedesktop/UPower/devices/DisplayDevice. + The following standard org.freedesktop.UPower.Device + properties will be defined (only IsPresent takes a special meaning): + + + Typethe type of the display device, UPS or Battery. Note that this value can change, as opposed to real devices. + + + Statethe power state of the display device, such as Charging or Discharging. + + + Percentagethe amount of energy left on the device. + + + EnergyAmount of energy (measured in Wh) currently available in the power source. + + + EnergyFullAmount of energy (measured in Wh) in the power source when it's considered full. + + + EnergyRateAmount of energy being drained from the source, measured in W. If positive, the source is being discharged, if negative it's being charged. + + + TimeToEmptyNumber of seconds until the power source is considered empty. + + + TimeToFullNumber of seconds until the power source is considered full. + + + IsPresentWhether a status icon using this information should be presented. + + + IconNameAn icon name representing the device state. + + + WarningLevelThe same as the overall WarningLevel + + + + + + + + + + + A string representing the critical action configured and available. + + + + + + When the system's power supply is critical (critically low batteries or UPS), + the system will take this action. Possible values are: + + + HybridSleep + + + Hibernate + + + PowerOff + + + + + + + + + + + + Object path of device that was added. + + + + + + Emitted when a device is added. + + + + + + + + + + Object path of device that was removed. + + + + + + Emitted when a device is removed. + + + + + + + + + + Version of the running daemon, e.g. 002. + + + + + + Indicates whether the system is running on battery power. + This property is provided for convenience. + + + + + + + + Indicates if the laptop lid is closed where the display cannot be seen. + + + + + + + + + + If the system has a lid device. + + + + + + + + diff --git a/src/solid/devices/backends/upower/upowerdevice.h b/src/solid/devices/backends/upower/upowerdevice.h --- a/src/solid/devices/backends/upower/upowerdevice.h +++ b/src/solid/devices/backends/upower/upowerdevice.h @@ -29,6 +29,8 @@ #include #include +#include "upower_device_interface.h" + namespace Solid { namespace Backends @@ -67,7 +69,7 @@ private: QString batteryTechnology() const; - mutable QDBusInterface m_device; + OrgFreedesktopUPowerDeviceInterface m_device; QString m_udi; mutable QVariantMap m_cache; diff --git a/src/solid/devices/backends/upower/upowerdevice.cpp b/src/solid/devices/backends/upower/upowerdevice.cpp --- a/src/solid/devices/backends/upower/upowerdevice.cpp +++ b/src/solid/devices/backends/upower/upowerdevice.cpp @@ -32,24 +32,20 @@ #include #include +#include + using namespace Solid::Backends::UPower; UPowerDevice::UPowerDevice(const QString &udi) : Solid::Ifaces::Device() , m_device(UP_DBUS_SERVICE, udi, - UP_DBUS_INTERFACE_DEVICE, QDBusConnection::systemBus()) , m_udi(udi) { if (m_device.isValid()) { - if (m_device.metaObject()->indexOfSignal("Changed()") != -1) { - connect(&m_device, SIGNAL(Changed()), this, SLOT(slotChanged())); - } else { - // for UPower >= 0.99.0, missing Changed() signal - QDBusConnection::systemBus().connect(UP_DBUS_SERVICE, m_udi, "org.freedesktop.DBus.Properties", "PropertiesChanged", this, - SLOT(onPropertiesChanged(QString,QVariantMap,QStringList))); - } + QDBusConnection::systemBus().connect(UP_DBUS_SERVICE, m_udi, "org.freedesktop.DBus.Properties", "PropertiesChanged", this, + SLOT(onPropertiesChanged(QString,QVariantMap,QStringList))); // TODO port this to Solid::Power, we can't link against kdelibs4support for this signal // older upower versions not affected diff --git a/src/solid/devices/backends/upower/upowermanager.h b/src/solid/devices/backends/upower/upowermanager.h --- a/src/solid/devices/backends/upower/upowermanager.h +++ b/src/solid/devices/backends/upower/upowermanager.h @@ -28,6 +28,8 @@ #include #include +#include "upower_interface.h" + namespace Solid { namespace Backends @@ -54,7 +56,7 @@ private: QSet m_supportedInterfaces; - QDBusInterface m_manager; + OrgFreedesktopUPowerInterface m_manager; }; } diff --git a/src/solid/devices/backends/upower/upowermanager.cpp b/src/solid/devices/backends/upower/upowermanager.cpp --- a/src/solid/devices/backends/upower/upowermanager.cpp +++ b/src/solid/devices/backends/upower/upowermanager.cpp @@ -37,7 +37,6 @@ : Solid::Ifaces::DeviceManager(parent), m_manager(UP_DBUS_SERVICE, UP_DBUS_PATH, - UP_DBUS_INTERFACE, QDBusConnection::systemBus()) { m_supportedInterfaces @@ -63,18 +62,10 @@ } if (serviceFound) { - if (m_manager.metaObject()->indexOfSignal("DeviceAdded(QDBusObjectPath)") != -1) { - // for UPower >= 0.99.0, changed signature :o/ - connect(&m_manager, SIGNAL(DeviceAdded(QDBusObjectPath)), - this, SLOT(onDeviceAdded(QDBusObjectPath))); - connect(&m_manager, SIGNAL(DeviceRemoved(QDBusObjectPath)), - this, SLOT(onDeviceRemoved(QDBusObjectPath))); - } else { - connect(&m_manager, SIGNAL(DeviceAdded(QString)), - this, SIGNAL(deviceAdded(QString))); - connect(&m_manager, SIGNAL(DeviceRemoved(QString)), - this, SIGNAL(deviceRemoved(QString))); - } + connect(&m_manager, &OrgFreedesktopUPowerInterface::DeviceAdded, + this, &UPowerManager::onDeviceAdded); + connect(&m_manager, &OrgFreedesktopUPowerInterface::DeviceRemoved, + this, &UPowerManager::onDeviceRemoved); } }