parent
675decda42
commit
62c77ba27b
|
@ -0,0 +1,113 @@
|
|||
From: =?utf-8?b?5p2o5pWP?= <yangmin@kylinos.cn>
|
||||
Date: Fri, 25 Oct 2024 07:03:38 +0000
|
||||
Subject: =?utf-8?q?!104_fixbug_Merge_pull_request_!104_from_=E6=9D=A8?=
|
||||
=?utf-8?q?=E6=95=8F/openkylin/nile?=
|
||||
|
||||
---
|
||||
src/dbusifs/upowerhelper.cpp | 42 ++++++++++++++++++++++++------------------
|
||||
src/dbusifs/upowerhelper.h | 2 +-
|
||||
2 files changed, 25 insertions(+), 19 deletions(-)
|
||||
|
||||
diff --git a/src/dbusifs/upowerhelper.cpp b/src/dbusifs/upowerhelper.cpp
|
||||
index fbc1cd5..90bef8a 100644
|
||||
--- a/src/dbusifs/upowerhelper.cpp
|
||||
+++ b/src/dbusifs/upowerhelper.cpp
|
||||
@@ -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) {
|
||||
+ continue;
|
||||
+ }
|
||||
|
||||
- if (dv->m_dev.kind == UP_DEVICE_KIND_LINE_POWER) {
|
||||
+ 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();
|
||||
}
|
||||
|
||||
diff --git a/src/dbusifs/upowerhelper.h b/src/dbusifs/upowerhelper.h
|
||||
index 74d9643..7f31af6 100644
|
||||
--- a/src/dbusifs/upowerhelper.h
|
||||
+++ b/src/dbusifs/upowerhelper.h
|
||||
@@ -72,7 +72,7 @@ private:
|
||||
QDBusInterface *m_batInterface = nullptr;
|
||||
QDBusInterface *m_upowerService = nullptr;
|
||||
|
||||
- EngineDevice *m_engineDevice;
|
||||
+ EngineDevice *m_engineDevice = nullptr;
|
||||
|
||||
bool m_isBattery = false;
|
||||
};
|
|
@ -64,3 +64,4 @@
|
|||
0064-101-issue-I90MAJ.patch
|
||||
0065-102-fixbug.patch
|
||||
0066-103-fixbug.patch
|
||||
0067-104-fixbug.patch
|
||||
|
|
Loading…
Reference in New Issue