PowerStatus: fix a possible division error.

* also fix some types misuses.
This commit is contained in:
Jérôme Duval
2013-11-28 18:18:54 +01:00
parent bf5786ebd6
commit 7cf7fa23f4
2 changed files with 10 additions and 13 deletions
+3 -5
View File
@@ -43,8 +43,8 @@ RateBuffer::AddRate(int32 rate)
int32 int32
RateBuffer::GetMeanRate() RateBuffer::GetMeanRate()
{ {
int mean = 0; int32 mean = 0;
for (int i = 0; i < fCurrentSize; i++) { for (int8 i = 0; i < fCurrentSize; i++) {
mean += fRateBuffer[i]; mean += fRateBuffer[i];
} }
@@ -98,7 +98,7 @@ Battery::GetBatteryInfoCached(battery_info* info)
info->capacity = fCachedAcpiInfo.capacity; info->capacity = fCachedAcpiInfo.capacity;
info->full_capacity = fExtendedBatteryInfo.last_full_charge; info->full_capacity = fExtendedBatteryInfo.last_full_charge;
fRateBuffer.AddRate(fCachedAcpiInfo.current_rate); fRateBuffer.AddRate(fCachedAcpiInfo.current_rate);
if (fCachedAcpiInfo.current_rate > 0) if (fCachedAcpiInfo.current_rate > 0 && fRateBuffer.GetMeanRate() != 0)
info->time_left = 3600 * fCachedAcpiInfo.capacity info->time_left = 3600 * fCachedAcpiInfo.capacity
/ fRateBuffer.GetMeanRate(); / fRateBuffer.GetMeanRate();
else else
@@ -254,5 +254,3 @@ ACPIDriverInterface::_FindDrivers(const char* dirpath)
} }
return status; return status;
} }
+7 -8
View File
@@ -5,7 +5,7 @@
* Authors: * Authors:
* Axel Dörfler, [email protected] * Axel Dörfler, [email protected]
* Clemens Zeidler, [email protected] * Clemens Zeidler, [email protected]
* Alexander von Gluck, [email protected] * Alexander von Gluck, [email protected]
*/ */
@@ -336,7 +336,7 @@ void
PowerStatusView::Update(bool force) PowerStatusView::Update(bool force)
{ {
int32 previousPercent = fPercent; int32 previousPercent = fPercent;
bool previousTimeLeft = fTimeLeft; time_t previousTimeLeft = fTimeLeft;
bool wasOnline = fOnline; bool wasOnline = fOnline;
_GetBatteryInfo(&fBatteryInfo, fBatteryID); _GetBatteryInfo(&fBatteryInfo, fBatteryID);
@@ -350,7 +350,7 @@ PowerStatusView::Update(bool force)
} else { } else {
fPercent = 0; fPercent = 0;
fOnline = false; fOnline = false;
fTimeLeft = false; fTimeLeft = -1;
} }
@@ -375,7 +375,7 @@ PowerStatusView::Update(bool force)
if (fHasBattery) { if (fHasBattery) {
size_t length = snprintf(text, sizeof(text), "%s%" B_PRId32 size_t length = snprintf(text, sizeof(text), "%s%" B_PRId32
"%%%s", open, fPercent, close); "%%%s", open, fPercent, close);
if (fTimeLeft) { if (fTimeLeft >= 0) {
length += snprintf(text + length, sizeof(text) - length, length += snprintf(text + length, sizeof(text) - length,
"\n%" B_PRId32 ":%02" B_PRId32, fTimeLeft / 3600, "\n%" B_PRId32 ":%02" B_PRId32, fTimeLeft / 3600,
(fTimeLeft / 60) % 60); (fTimeLeft / 60) % 60);
@@ -421,7 +421,7 @@ PowerStatusView::FromMessage(const BMessage* archive)
fShowStatusIcon = value; fShowStatusIcon = value;
if (archive->FindBool("show time", &value) == B_OK) if (archive->FindBool("show time", &value) == B_OK)
fShowTime = value; fShowTime = value;
//Incase we have a bad saving and none are showed.. //Incase we have a bad saving and none are showed..
if (!fShowLabel && !fShowStatusIcon) if (!fShowLabel && !fShowStatusIcon)
fShowLabel = true; fShowLabel = true;
@@ -548,7 +548,7 @@ PowerStatusReplicant::MessageReceived(BMessage *message)
fShowLabel = !fShowLabel; fShowLabel = !fShowLabel;
else else
fShowLabel = true; fShowLabel = true;
Update(true); Update(true);
break; break;
@@ -610,7 +610,7 @@ PowerStatusReplicant::MouseDown(BPoint point)
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menu->AddItem(new BMenuItem(B_TRANSLATE("About" B_UTF8_ELLIPSIS), menu->AddItem(new BMenuItem(B_TRANSLATE("About" B_UTF8_ELLIPSIS),
new BMessage(B_ABOUT_REQUESTED))); new BMessage(B_ABOUT_REQUESTED)));
menu->AddItem(new BMenuItem(B_TRANSLATE("Quit"), menu->AddItem(new BMenuItem(B_TRANSLATE("Quit"),
new BMessage(B_QUIT_REQUESTED))); new BMessage(B_QUIT_REQUESTED)));
menu->SetTargetForItems(this); menu->SetTargetForItems(this);
@@ -751,4 +751,3 @@ instantiate_deskbar_item(void)
{ {
return new PowerStatusReplicant(BRect(0, 0, 15, 15), B_FOLLOW_NONE, true); return new PowerStatusReplicant(BRect(0, 0, 15, 15), B_FOLLOW_NONE, true);
} }