mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
feat(dde-dock): power display error for bug 2040
This commit is contained in:
parent
6ffbf9e39f
commit
7fece61e31
@ -206,12 +206,11 @@ void PowerPlugin::refreshPluginItemsVisible()
|
||||
void PowerPlugin::refreshTipsData()
|
||||
{
|
||||
const BatteryPercentageMap data = m_powerInter->batteryPercentage();
|
||||
|
||||
const uint percentage = qMin(100.0, qMax(0.0, data.value("Display")));
|
||||
const QString value = QString("%1%").arg(std::round(percentage));
|
||||
const int batteryState = m_powerInter->batteryState()["Display"];
|
||||
|
||||
if (m_powerInter->onBattery()) {
|
||||
if (batteryState == BatteryState::DIS_CHARGING) {
|
||||
qulonglong timeToEmpty = m_systemPowerInter->batteryTimeToEmpty();
|
||||
QDateTime time = QDateTime::fromTime_t(timeToEmpty).toUTC();
|
||||
uint hour = time.toString("hh").toUInt();
|
||||
@ -228,26 +227,24 @@ void PowerPlugin::refreshTipsData()
|
||||
|
||||
m_tipsLabel->setText(tips);
|
||||
}
|
||||
else {
|
||||
if (batteryState == BatteryState::FULLY_CHARGED || percentage == 100.) {
|
||||
m_tipsLabel->setText(tr("Charged %1").arg(value));
|
||||
else if (batteryState == BatteryState::FULLY_CHARGED || percentage == 100.){
|
||||
m_tipsLabel->setText(tr("Charged %1").arg(value));
|
||||
}else if (batteryState == BatteryState::NOT_CHARGED || batteryState == BatteryState::UNKNOWN){
|
||||
m_tipsLabel->setText(tr("Charged %1").arg(value));
|
||||
}else {
|
||||
qulonglong timeToFull = m_systemPowerInter->batteryTimeToFull();
|
||||
QDateTime time = QDateTime::fromTime_t(timeToFull).toUTC();
|
||||
uint hour = time.toString("hh").toUInt();
|
||||
uint min = time.toString("mm").toUInt();
|
||||
QString tips;
|
||||
|
||||
if (hour == 0) {
|
||||
tips = tr("Charging %1, %2 min until full").arg(value).arg(min);
|
||||
}
|
||||
else {
|
||||
qulonglong timeToFull = m_systemPowerInter->batteryTimeToFull();
|
||||
QDateTime time = QDateTime::fromTime_t(timeToFull).toUTC();
|
||||
uint hour = time.toString("hh").toUInt();
|
||||
uint min = time.toString("mm").toUInt();
|
||||
|
||||
QString tips;
|
||||
|
||||
if (hour == 0) {
|
||||
tips = tr("Charging %1, %2 min until full").arg(value).arg(min);
|
||||
}
|
||||
else {
|
||||
tips = tr("Charging %1, %2 hr %3 min until full").arg(value).arg(hour).arg(min);
|
||||
}
|
||||
|
||||
m_tipsLabel->setText(tips);
|
||||
tips = tr("Charging %1, %2 hr %3 min until full").arg(value).arg(hour).arg(min);
|
||||
}
|
||||
|
||||
m_tipsLabel->setText(tips);
|
||||
}
|
||||
}
|
||||
|
@ -36,13 +36,11 @@ using SystemPowerInter = com::deepin::system::Power;
|
||||
// from https://upower.freedesktop.org/docs/Device.html#Device:State
|
||||
enum BatteryState
|
||||
{
|
||||
UNKNOWN = 0,
|
||||
CHARGING = 1,
|
||||
DISCHARGING = 2,
|
||||
EMPTY = 3,
|
||||
FULLY_CHARGED = 4,
|
||||
PENDING_CHARGE = 5,
|
||||
PENDING_DISCHARGE = 6
|
||||
UNKNOWN = 0, // 未知
|
||||
CHARGING = 1, // 充电中
|
||||
DIS_CHARGING = 2, // 放电
|
||||
NOT_CHARGED = 3, // 未充
|
||||
FULLY_CHARGED = 4 // 充满
|
||||
};
|
||||
|
||||
class PowerPlugin : public QObject, PluginsItemInterface
|
||||
|
Loading…
x
Reference in New Issue
Block a user