8#include "upowerdevice.h"
10#include "upowerbattery.h"
11#include "upowerdeviceinterface.h"
12#include "upowergenericinterface.h"
14#include <solid/device.h>
15#include <solid/genericinterface.h>
17#include <QDBusConnection>
21using namespace Solid::Backends::UPower;
23UPowerDevice::UPowerDevice(
const QString &udi)
29 "org.freedesktop.DBus.Properties",
37 "/org/freedesktop/login1",
38 "org.freedesktop.login1.Manager",
41 SLOT(login1Resuming(
bool)));
44UPowerDevice::~UPowerDevice()
50 if (!queryDeviceInterface(type)) {
54 DeviceInterface *iface =
nullptr;
56 case Solid::DeviceInterface::GenericInterface:
57 iface =
new GenericInterface(
this);
59 case Solid::DeviceInterface::Battery:
60 iface =
new Battery(
this);
70 const UpDeviceKind uptype =
static_cast<UpDeviceKind
>(prop(
"Type").
toUInt());
72 case Solid::DeviceInterface::GenericInterface:
74 case Solid::DeviceInterface::Battery:
76 case UP_DEVICE_KIND_BATTERY:
77 case UP_DEVICE_KIND_UPS:
78 case UP_DEVICE_KIND_MOUSE:
79 case UP_DEVICE_KIND_KEYBOARD:
80 case UP_DEVICE_KIND_PDA:
81 case UP_DEVICE_KIND_PHONE:
82 case UP_DEVICE_KIND_TABLET:
83 case UP_DEVICE_KIND_GAMING_INPUT:
84 case UP_DEVICE_KIND_SPEAKERS:
85 case UP_DEVICE_KIND_HEADSET:
86 case UP_DEVICE_KIND_HEADPHONES:
87 case UP_DEVICE_KIND_BLUETOOTH_GENERIC:
88 case UP_DEVICE_KIND_TOUCHPAD:
90 case UP_DEVICE_KIND_UNKNOWN:
96 case UP_DEVICE_KIND_LINE_POWER:
97 case UP_DEVICE_KIND_MONITOR:
98 case UP_DEVICE_KIND_MEDIA_PLAYER:
99 case UP_DEVICE_KIND_COMPUTER:
100 case UP_DEVICE_KIND_LAST:
114QString UPowerDevice::description()
const
116 if (queryDeviceInterface(Solid::DeviceInterface::Battery)) {
117 return tr(
"%1 Battery",
"%1 is battery technology").
arg(batteryTechnology());
127QString UPowerDevice::batteryTechnology()
const
129 const UpDeviceTechnology tech =
static_cast<UpDeviceTechnology
>(prop(
"Technology").
toUInt());
131 case UP_DEVICE_TECHNOLOGY_UNKNOWN:
132 return tr(
"Unknown",
"battery technology");
133 case UP_DEVICE_TECHNOLOGY_LITHIUM_ION:
134 return tr(
"Lithium Ion",
"battery technology");
135 case UP_DEVICE_TECHNOLOGY_LITHIUM_POLYMER:
136 return tr(
"Lithium Polymer",
"battery technology");
137 case UP_DEVICE_TECHNOLOGY_LITHIUM_IRON_PHOSPHATE:
138 return tr(
"Lithium Iron Phosphate",
"battery technology");
139 case UP_DEVICE_TECHNOLOGY_LEAD_ACID:
140 return tr(
"Lead Acid",
"battery technology");
141 case UP_DEVICE_TECHNOLOGY_NICKEL_CADMIUM:
142 return tr(
"Nickel Cadmium",
"battery technology");
143 case UP_DEVICE_TECHNOLOGY_NICKEL_METAL_HYDRIDE:
144 return tr(
"Nickel Metal Hydride",
"battery technology");
145 case UP_DEVICE_TECHNOLOGY_LAST:
146 return tr(
"Unknown",
"battery technology");
148 return tr(
"Unknown",
"battery technology");
151QString UPowerDevice::icon()
const
153 if (queryDeviceInterface(Solid::DeviceInterface::Battery)) {
160QString UPowerDevice::product()
const
165 result = description();
171QString UPowerDevice::vendor()
const
176QString UPowerDevice::udi()
const
181QString UPowerDevice::parentUdi()
const
183 return UP_UDI_PREFIX;
186void UPowerDevice::checkCache(
const QString &key)
const
188 if (m_cache.contains(key) || m_negativeCache.
contains(key)) {
194 if (m_cache.contains(key)) {
203 m_cache[key] = reply.value();
205 m_negativeCache.
append(key);
212 return m_cache.value(key);
215bool UPowerDevice::propertyExists(
const QString &key)
const
218 return m_cache.contains(key);
221void UPowerDevice::loadCache()
const
228 m_cache = reply.value();
229 m_cacheComplete =
true;
237 if (!m_cacheComplete) {
244void UPowerDevice::onPropertiesChanged(
const QString &ifaceName,
const QVariantMap &changedProps,
const QStringList &invalidatedProps)
246 if (ifaceName != UP_DBUS_INTERFACE_DEVICE)
250 for (
auto it = changedProps.begin(); it != changedProps.end(); ++it) {
251 m_cache[it.key()] = it.value();
253 changeMap.
insert(it.key(), Solid::GenericInterface::PropertyModified);
255 for (
const auto &propName : invalidatedProps) {
256 m_cache.remove(propName);
258 changeMap.
insert(propName, Solid::GenericInterface::PropertyModified);
259 m_cacheComplete =
false;
261 Q_EMIT propertyChanged(changeMap);
264void UPowerDevice::login1Resuming(
bool active)
271 for (
auto it = m_cache.begin(); it != m_cache.end(); ++it) {
272 if (it.value().isValid()) {
273 changeMap.
insert(it.key(), Solid::GenericInterface::PropertyModified);
277 m_negativeCache.
clear();
278 m_cacheComplete =
false;
279 Q_EMIT propertyChanged(changeMap);
282#include "moc_upowerdevice.cpp"
Type
This enum type defines the type of device interface that a Device can have.
This class allows applications to deal with devices available in the underlying system.
The single responsibility of this class is to create arguments valid for logind Inhibit call.
QDBusMessage call(const QDBusMessage &message, QDBus::CallMode mode, int timeout) const const
bool connect(const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
QDBusConnection systemBus()
QDBusMessage createMethodCall(const QString &service, const QString &path, const QString &interface, const QString &method)
void setArguments(const QList< QVariant > &arguments)
bool isValid() const const
void append(QList< T > &&value)
bool removeOne(const AT &t)
iterator insert(const Key &key, const T &value)
QString tr(const char *sourceText, const char *disambiguation, int n)
QString arg(Args &&... args) const const
bool isEmpty() const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
QString toString() const const
uint toUInt(bool *ok) const const