Merge pull request !104 from 杨敏/openkylin/nile
This commit is contained in:
杨敏 2024-10-25 07:03:38 +00:00 committed by Gitee
commit b44b8d323b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 25 additions and 19 deletions

View File

@ -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";
}
QDBusConnection::systemBus().connect(
upowerService, batteryPath, propertiesInterface, "PropertiesChanged", this, SLOT(dealMessage(QDBusMessage)));
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,21 +70,23 @@ UpowerHelper::UpowerHelper(QObject *parent) : QObject(parent)
upowerService, upowerPath, propertiesInterface, "PropertiesChanged", this, SLOT(onLidWatcherMessage()));
}
m_engineDevice = EngineDevice::getInstance();
// onBatteryChanged(m_engineDevice->engine_get_state());
if (m_upowerService->isValid()) {
m_engineDevice = EngineDevice::getInstance();
// onBatteryChanged(m_engineDevice->engine_get_state());
int size;
size = m_engineDevice->devices.size();
for (int i = 0; i < size; i++) {
DEVICE *dv;
dv = m_engineDevice->devices.at(i);
int size;
size = m_engineDevice->devices.size();
for (int i = 0; i < size; i++) {
DEVICE *dv;
dv = m_engineDevice->devices.at(i);
if (dv->m_dev.kind == UP_DEVICE_KIND_LINE_POWER) {
if (dv->m_dev.kind == UP_DEVICE_KIND_LINE_POWER) {
continue;
}
connect(m_engineDevice, &EngineDevice::engine_signal_Battery_State, this, &UpowerHelper::onBatteryChanged);
continue;
}
connect(m_engineDevice, &EngineDevice::engine_signal_Battery_State, this, &UpowerHelper::onBatteryChanged);
continue;
}
}
@ -91,7 +94,7 @@ 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();
}

View File

@ -72,7 +72,7 @@ private:
QDBusInterface *m_batInterface = nullptr;
QDBusInterface *m_upowerService = nullptr;
EngineDevice *m_engineDevice;
EngineDevice *m_engineDevice = nullptr;
bool m_isBattery = false;
};