diff --git a/src/apps/powerstatus/PowerStatusView.cpp b/src/apps/powerstatus/PowerStatusView.cpp index ec347b7115..2741c89321 100644 --- a/src/apps/powerstatus/PowerStatusView.cpp +++ b/src/apps/powerstatus/PowerStatusView.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -61,6 +62,9 @@ const uint32 kMsgToggleExtInfo = 'texi'; const double kLowBatteryPercentage = 0.15; const double kNoteBatteryPercentage = 0.3; +const double kFullBatteryPercentage = 1.0; + +const time_t kLowBatteryTimeLeft = 30 * 60; PowerStatusView::PowerStatusView(PowerStatusDriverInterface* interface, @@ -116,6 +120,11 @@ PowerStatusView::_Init() fPercent = 1.0; fOnline = true; fTimeLeft = 0; + + fHasNotifiedLowBattery = false; + + add_system_beep_event("Low battery"); + add_system_beep_event("Battery charged"); } @@ -298,6 +307,7 @@ PowerStatusView::Draw(BRect updateRect) DrawTo(this, Bounds()); } + void PowerStatusView::DrawTo(BView* view, BRect rect) { @@ -491,9 +501,23 @@ PowerStatusView::Update(bool force, bool notify) Invalidate(); } - if (!fOnline && fHasBattery && previousPercent > kLowBatteryPercentage - && fPercent <= kLowBatteryPercentage && notify) { + if (fPercent > kLowBatteryPercentage && fTimeLeft > kLowBatteryTimeLeft) + fHasNotifiedLowBattery = false; + + bool justTurnedLowBattery = (previousPercent > kLowBatteryPercentage + && fPercent <= kLowBatteryPercentage) + || (fTimeLeft <= kLowBatteryTimeLeft + && previousTimeLeft > kLowBatteryTimeLeft); + + if (!fOnline && notify && fHasBattery + && !fHasNotifiedLowBattery && justTurnedLowBattery) { _NotifyLowBattery(); + fHasNotifiedLowBattery = true; + } + + if (fOnline && fPercent >= kFullBatteryPercentage + && previousPercent < kFullBatteryPercentage) { + system_beep("Battery charged"); } } @@ -585,6 +609,8 @@ PowerStatusView::_NotifyLowBattery() BNotification notification( fHasBattery ? B_INFORMATION_NOTIFICATION : B_ERROR_NOTIFICATION); + system_beep("Low battery"); + if (fHasBattery) { notification.SetTitle(B_TRANSLATE("Battery low")); notification.SetContent(B_TRANSLATE( diff --git a/src/apps/powerstatus/PowerStatusView.h b/src/apps/powerstatus/PowerStatusView.h index 2b795575cf..4a06aad0fc 100644 --- a/src/apps/powerstatus/PowerStatusView.h +++ b/src/apps/powerstatus/PowerStatusView.h @@ -68,6 +68,8 @@ protected: time_t fTimeLeft; bool fOnline; bool fHasBattery; + + bool fHasNotifiedLowBattery; };