Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 电池的UPower服务刷新接口 #323

Merged
merged 1 commit into from
May 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 30 additions & 18 deletions deepin-devicemanager/src/Page/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,24 +187,36 @@ void MainWindow::refresh()

void MainWindow::refreshBatteryStatus()
{
QDBusConnection bus = QDBusConnection::systemBus();

//创建Dbus接口
QDBusInterface interfaceService("org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.UPower", bus);
if(interfaceService.isValid()) {
QDBusReply<QString> interfacePath = interfaceService.call("EnumerateDevices");
if(interfacePath.value().contains("/org/freedesktop/UPower/devices/battery_BAT1")) {
QDBusInterface interfaceBattery("org.freedesktop.UPower", "/org/freedesktop/UPower/devices/battery_BAT1", "org.freedesktop.UPower.Device", bus);
if(interfaceBattery.isValid()) {
QDBusMessage reply = interfaceBattery.call("Refresh");

if(reply.type() != QDBusMessage::ReplyMessage)
qWarning() << "call Refresh failure:" << reply.errorMessage();
}
}
} else {
qDebug() << "interface UPower invalid";
}
QDBusConnection bus = QDBusConnection::systemBus();

//创建Dbus接口
QDBusInterface interfaceService("org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.UPower", bus);
if (interfaceService.isValid()) {
QProcess process;
QString command = "gdbus call --system --dest org.freedesktop.UPower --object-path /org/freedesktop/UPower --method org.freedesktop.UPower.EnumerateDevices";
process.start(command);
process.waitForFinished();

QByteArray output = process.readAllStandardOutput();
QString outputStr = QString::fromLocal8Bit(output);
QStringList outputList = outputStr.split(",");

foreach (const QString& str, outputList) {
if (str.contains("BAT")) {
QStringList pathStr = str.split("'");
if (pathStr.size() >= 2) {
QDBusInterface interfaceBattery("org.freedesktop.UPower", pathStr.at(1), "org.freedesktop.UPower.Device", bus);
if (interfaceBattery.isValid()) {
QDBusMessage reply = interfaceBattery.call("Refresh");
if (reply.type() != QDBusMessage::ReplyMessage)
qWarning() << "call Refresh failure:" << reply.errorMessage();
}
}
}
}
} else {
qDebug() << "interface UPower invalid";
}
}

bool MainWindow::exportTo()
Expand Down
Loading