Skip to content

Commit

Permalink
Merge pull request mixxxdj#2160 from rrrapha/battery-unknown
Browse files Browse the repository at this point in the history
Fix battery tooltip text when minutesLeft is unknown
  • Loading branch information
daschuer authored and haslersn committed Jun 16, 2019
2 parents 1710d69 + 851cc34 commit a2941cc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/util/battery/battery.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class Battery : public QObject {
Q_OBJECT
public:
static constexpr int TIME_UNKNOWN = -1;
enum ChargingState {
UNKNOWN,
DISCHARGING,
Expand Down
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 = Battery::TIME_UNKNOWN;
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 = Battery::TIME_UNKNOWN;
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
9 changes: 6 additions & 3 deletions src/util/battery/batterywindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ BatteryWindows::~BatteryWindows() {
}

void BatteryWindows::read() {
m_iMinutesLeft = 0;
m_iMinutesLeft = Battery::TIME_UNKNOWN;
m_dPercentage = 0.0;
m_chargingState = Battery::UNKNOWN;

Expand All @@ -39,8 +39,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)
int seconds_left = static_cast<int>(spsPwr.BatteryLifeTime);
if (seconds_left >= 0) {
m_iMinutesLeft = seconds_left / 60;
}
}

// QString bat = "unknown";
Expand Down
4 changes: 2 additions & 2 deletions src/widget/wbattery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void WBattery::update() {
pixmapIndexFromPercentage(dPercentage,
m_chargingPixmaps.size())];
}
if (minutesLeft == -1) {
if (minutesLeft == Battery::TIME_UNKNOWN) {
setBaseTooltip(tr("Time until charged unknown."));
} else {
setBaseTooltip(tr("Time until charged: %1")
Expand All @@ -118,7 +118,7 @@ void WBattery::update() {
pixmapIndexFromPercentage(dPercentage,
m_dischargingPixmaps.size())];
}
if (minutesLeft == -1) {
if (minutesLeft == Battery::TIME_UNKNOWN) {
setBaseTooltip(tr("Time left unknown."));
} else {
setBaseTooltip(tr("Time left: %1")
Expand Down

0 comments on commit a2941cc

Please sign in to comment.