From f1bfd2dff3c1d50f2f1cf199ab4b175c8ddaa694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 29 Dec 2014 10:19:18 +0100 Subject: [PATCH] PowerStatus: minor cleanup. * Moved low battery notification code into its own method. * Slightly changed low battery notification text. --- src/apps/powerstatus/PowerStatusView.cpp | 77 +++++++++++++----------- src/apps/powerstatus/PowerStatusView.h | 1 + 2 files changed, 43 insertions(+), 35 deletions(-) diff --git a/src/apps/powerstatus/PowerStatusView.cpp b/src/apps/powerstatus/PowerStatusView.cpp index 3b3a89acde..f33aa00254 100644 --- a/src/apps/powerstatus/PowerStatusView.cpp +++ b/src/apps/powerstatus/PowerStatusView.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2006-2012, Haiku, Inc. All Rights Reserved. + * Copyright 2006-2014, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -410,38 +410,7 @@ PowerStatusView::Update(bool force) if ((hadBattery && !fHasBattery) || (previousPercent > kLowBatteryPercentage && fPercent <= kLowBatteryPercentage)) { - - BBitmap* bitmap = NULL; - BResources resources; - resources.SetToImage((void*)&instantiate_deskbar_item); - if (resources.InitCheck() == B_OK) { - size_t resourceSize = 0; - const void* resourceData = resources.LoadResource( - B_VECTOR_ICON_TYPE, fHasBattery - ? "battery_low" : "battery_critical", &resourceSize); - if (resourceData != NULL) { - BMemoryIO memoryIO(resourceData, resourceSize); - bitmap = BTranslationUtils::GetBitmap(&memoryIO); - } - } - - BNotification notification(fHasBattery ? B_INFORMATION_NOTIFICATION - : B_ERROR_NOTIFICATION); - - if (fHasBattery) { - notification.SetTitle(B_TRANSLATE("Battery low")); - notification.SetContent(B_TRANSLATE( - "The battery level is getting low, please plug the device in.")); - } else { - notification.SetTitle(B_TRANSLATE("Battery critical")); - notification.SetContent(B_TRANSLATE( - "The battery level is critical, please plug the device in" - " immediately.")); - } - - notification.SetIcon(bitmap); - notification.Send(); - delete bitmap; + _NotifyLowBattery(); } } @@ -505,11 +474,49 @@ PowerStatusView::_GetBatteryInfo(battery_info* batteryInfo, int batteryID) } -// #pragma mark - +void +PowerStatusView::_NotifyLowBattery() +{ + BBitmap* bitmap = NULL; + BResources resources; + resources.SetToImage((void*)&instantiate_deskbar_item); + + if (resources.InitCheck() == B_OK) { + size_t resourceSize = 0; + const void* resourceData = resources.LoadResource( + B_VECTOR_ICON_TYPE, fHasBattery + ? "battery_low" : "battery_critical", &resourceSize); + if (resourceData != NULL) { + BMemoryIO memoryIO(resourceData, resourceSize); + bitmap = BTranslationUtils::GetBitmap(&memoryIO); + } + } + + BNotification notification( + fHasBattery ? B_INFORMATION_NOTIFICATION : B_ERROR_NOTIFICATION); + + if (fHasBattery) { + notification.SetTitle(B_TRANSLATE("Battery low")); + notification.SetContent(B_TRANSLATE( + "The battery level is getting low, please plug in the device.")); + } else { + notification.SetTitle(B_TRANSLATE("Battery critical")); + notification.SetContent(B_TRANSLATE( + "The battery level is critical, please plug in the device " + "immediately.")); + } + + notification.SetIcon(bitmap); + notification.Send(); + delete bitmap; +} + + +// #pragma mark - Replicant view PowerStatusReplicant::PowerStatusReplicant(BRect frame, int32 resizingMode, - bool inDeskbar) + bool inDeskbar) : PowerStatusView(NULL, frame, resizingMode, -1, inDeskbar) { diff --git a/src/apps/powerstatus/PowerStatusView.h b/src/apps/powerstatus/PowerStatusView.h index 006cb0658e..2dfd2c6221 100644 --- a/src/apps/powerstatus/PowerStatusView.h +++ b/src/apps/powerstatus/PowerStatusView.h @@ -49,6 +49,7 @@ private: void _Init(); void _SetLabel(char* buffer, size_t bufferLength); void _DrawBattery(BRect rect); + void _NotifyLowBattery(); protected: PowerStatusDriverInterface* fDriverInterface;