Skip to content

Commit

Permalink
Fix battery tooltip text when minutesLeft is unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
rrrapha committed Jun 12, 2019
1 parent e2897ad commit 37235fb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/util/battery/batterylinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ BatteryLinux::~BatteryLinux() {
}

void BatteryLinux::read() {
m_iMinutesLeft = 0;
m_iMinutesLeft = -1;
m_dPercentage = 0.0;
m_chargingState = Battery::UNKNOWN;

Expand Down Expand Up @@ -89,9 +89,11 @@ void BatteryLinux::read() {
}

m_dPercentage = percentage;
if (m_chargingState == CHARGING) {

// upower tells us the remainging time in seconds (0 if unknown)
if (m_chargingState == CHARGING && timeToFull > 0) {
m_iMinutesLeft = timeToFull / 60;
} else if (m_chargingState == DISCHARGING) {
} else if (m_chargingState == DISCHARGING && timeToEmpty > 0) {
m_iMinutesLeft = timeToEmpty / 60;
}
break;
Expand Down
4 changes: 2 additions & 2 deletions src/util/battery/batterymac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ BatteryMac::~BatteryMac() {
}

void BatteryMac::read() {
m_iMinutesLeft = 0;
m_iMinutesLeft = -1;
m_dPercentage = 0.0;
m_chargingState = Battery::UNKNOWN;

Expand Down Expand Up @@ -125,7 +125,7 @@ void BatteryMac::read() {
m_chargingState = DISCHARGING;
}

if (minutes_left != -1) {
if (minutes_left >= 0)
m_iMinutesLeft = minutes_left;
}

Expand Down
10 changes: 7 additions & 3 deletions src/util/battery/batterywindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ BatteryWindows::~BatteryWindows() {
}

void BatteryWindows::read() {
m_iMinutesLeft = 0;
m_iMinutesLeft = -1;
m_dPercentage = 0.0;
m_chargingState = Battery::UNKNOWN;
int seconds_left;

// SYSTEM_POWER_STATUS doc
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa373232(v=vs.85).aspx
Expand All @@ -39,8 +40,11 @@ void BatteryWindows::read() {
if (m_dPercentage > 99) {
m_chargingState = Battery::CHARGED;
}
// windows tells us the remainging time in seconds
m_iMinutesLeft = static_cast<int>(spsPwr.BatteryLifeTime) / 60;
// windows tells us the remainging time in seconds (-1 if unknown)
seconds_left = static_cast<int>(spsPwr.BatteryLifeTime);
if (seconds_left >= 0) {
m_iMinutesLeft = seconds_left / 60;
}
}

// QString bat = "unknown";
Expand Down

0 comments on commit 37235fb

Please sign in to comment.