commit
b44b8d323b
|
@ -37,8 +37,8 @@ UpowerHelper::UpowerHelper(QObject *parent) : QObject(parent)
|
|||
= new QDBusInterface(upowerService, upowerPath, upowerInterface, QDBusConnection::systemBus(), this);
|
||||
|
||||
QString batteryPath = "";
|
||||
QDBusReply<QList<QDBusObjectPath>> reply = m_upowerService->call("EnumerateDevices");
|
||||
if (m_upowerService->isValid()) {
|
||||
QDBusReply<QList<QDBusObjectPath>> reply = m_upowerService->call("EnumerateDevices");
|
||||
for (QDBusObjectPath op : reply.value()) {
|
||||
if (op.path().contains("battery_")) {
|
||||
batteryPath = op.path();
|
||||
|
@ -50,15 +50,16 @@ UpowerHelper::UpowerHelper(QObject *parent) : QObject(parent)
|
|||
qDebug() << "Enumerate devices failed";
|
||||
}
|
||||
|
||||
if (!batteryPath.isEmpty()) {
|
||||
QDBusConnection::systemBus().connect(
|
||||
upowerService, batteryPath, propertiesInterface, "PropertiesChanged", this, SLOT(dealMessage(QDBusMessage)));
|
||||
m_batInterface
|
||||
= new QDBusInterface(upowerService, batteryPath, propertiesInterface, QDBusConnection::systemBus(), this);
|
||||
}
|
||||
|
||||
m_upowerInterface
|
||||
= new QDBusInterface(upowerService, upowerPath, propertiesInterface, QDBusConnection::systemBus(), this);
|
||||
|
||||
m_batInterface
|
||||
= new QDBusInterface(upowerService, batteryPath, propertiesInterface, QDBusConnection::systemBus(), this);
|
||||
|
||||
if (m_upowerInterface->isValid()) {
|
||||
QDBusReply<QVariant> interfaceReply = m_upowerInterface->call("Get", "org.freedesktop.UPower", "LidIsPresent");
|
||||
if (interfaceReply.isValid()) {
|
||||
|
@ -69,6 +70,7 @@ UpowerHelper::UpowerHelper(QObject *parent) : QObject(parent)
|
|||
upowerService, upowerPath, propertiesInterface, "PropertiesChanged", this, SLOT(onLidWatcherMessage()));
|
||||
}
|
||||
|
||||
if (m_upowerService->isValid()) {
|
||||
m_engineDevice = EngineDevice::getInstance();
|
||||
// onBatteryChanged(m_engineDevice->engine_get_state());
|
||||
|
||||
|
@ -85,13 +87,14 @@ UpowerHelper::UpowerHelper(QObject *parent) : QObject(parent)
|
|||
connect(m_engineDevice, &EngineDevice::engine_signal_Battery_State, this, &UpowerHelper::onBatteryChanged);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UpowerHelper::~UpowerHelper() {}
|
||||
|
||||
QString UpowerHelper::getBatteryIconName()
|
||||
{
|
||||
if (m_upowerService->isValid() && m_upowerInterface->isValid()) {
|
||||
if (m_upowerService->isValid() && m_upowerInterface->isValid() && m_batInterface) {
|
||||
bool batteryState = false;
|
||||
QDBusReply<QVariant> reply = m_upowerInterface->call("Get", upowerService, "OnBattery");
|
||||
if (reply.isValid()) {
|
||||
|
@ -114,6 +117,9 @@ QString UpowerHelper::getBatteryIconName()
|
|||
|
||||
QStringList UpowerHelper::getBatteryArgs()
|
||||
{
|
||||
if (!m_engineDevice) {
|
||||
return QStringList();
|
||||
}
|
||||
return m_engineDevice->engine_get_state();
|
||||
}
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ private:
|
|||
QDBusInterface *m_batInterface = nullptr;
|
||||
QDBusInterface *m_upowerService = nullptr;
|
||||
|
||||
EngineDevice *m_engineDevice;
|
||||
EngineDevice *m_engineDevice = nullptr;
|
||||
|
||||
bool m_isBattery = false;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue