- extended info window looks a little bit better now.
- cache the battery status and read it out in the polling thread - fix time label git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31517 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -76,23 +76,30 @@ Battery::InitCheck()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
Battery::GetBatteryInfo(battery_info* info)
|
Battery::ReadBatteryInfo()
|
||||||
{
|
{
|
||||||
acpi_battery_info acpiInfo;
|
|
||||||
status_t status;
|
status_t status;
|
||||||
status = ioctl(fDriverHandler, GET_BATTERY_INFO, &acpiInfo,
|
status = ioctl(fDriverHandler, GET_BATTERY_INFO, &fCachedAcpiInfo,
|
||||||
sizeof(acpi_battery_info));
|
sizeof(acpi_battery_info));
|
||||||
|
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
info->state = acpiInfo.state;
|
return B_OK;
|
||||||
info->current_rate = acpiInfo.current_rate;
|
}
|
||||||
info->capacity = acpiInfo.capacity;
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
Battery::GetBatteryInfoCached(battery_info* info)
|
||||||
|
{
|
||||||
|
info->state = fCachedAcpiInfo.state;
|
||||||
|
info->current_rate = fCachedAcpiInfo.current_rate;
|
||||||
|
info->capacity = fCachedAcpiInfo.capacity;
|
||||||
info->full_capacity = fExtendedBatteryInfo.last_full_charge;
|
info->full_capacity = fExtendedBatteryInfo.last_full_charge;
|
||||||
fRateBuffer.AddRate(acpiInfo.current_rate);
|
fRateBuffer.AddRate(fCachedAcpiInfo.current_rate);
|
||||||
if (acpiInfo.current_rate > 0)
|
if (fCachedAcpiInfo.current_rate > 0)
|
||||||
info->time_left = 3600 * acpiInfo.capacity / fRateBuffer.GetMeanRate();
|
info->time_left = 3600 * fCachedAcpiInfo.capacity
|
||||||
|
/ fRateBuffer.GetMeanRate();
|
||||||
else
|
else
|
||||||
info->time_left = -1;
|
info->time_left = -1;
|
||||||
|
|
||||||
@@ -125,8 +132,7 @@ Battery::_Init()
|
|||||||
if (fInitStatus != B_OK)
|
if (fInitStatus != B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
acpi_battery_info info;
|
fInitStatus = ioctl(fDriverHandler, GET_BATTERY_INFO, &fCachedAcpiInfo,
|
||||||
fInitStatus = ioctl(fDriverHandler, GET_BATTERY_INFO, &info,
|
|
||||||
sizeof(acpi_battery_info));
|
sizeof(acpi_battery_info));
|
||||||
if (fInitStatus != B_OK)
|
if (fInitStatus != B_OK)
|
||||||
return;
|
return;
|
||||||
@@ -158,12 +164,12 @@ ACPIDriverInterface::Connect()
|
|||||||
status_t
|
status_t
|
||||||
ACPIDriverInterface::GetBatteryInfo(battery_info* info, int32 index)
|
ACPIDriverInterface::GetBatteryInfo(battery_info* info, int32 index)
|
||||||
{
|
{
|
||||||
BAutolock autolock(fBatteryStatusLock);
|
BAutolock autolock(fInterfaceLocker);
|
||||||
if (index < 0 || index >= fDriverList.CountItems())
|
if (index < 0 || index >= fDriverList.CountItems())
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
status_t status;
|
status_t status;
|
||||||
status = fDriverList.ItemAt(index)->GetBatteryInfo(info);
|
status = fDriverList.ItemAt(index)->GetBatteryInfoCached(info);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +178,7 @@ status_t
|
|||||||
ACPIDriverInterface::GetExtendedBatteryInfo(acpi_extended_battery_info* info,
|
ACPIDriverInterface::GetExtendedBatteryInfo(acpi_extended_battery_info* info,
|
||||||
int32 index)
|
int32 index)
|
||||||
{
|
{
|
||||||
BAutolock autolock(fBatteryStatusLock);
|
BAutolock autolock(fInterfaceLocker);
|
||||||
if (index < 0 || index >= fDriverList.CountItems())
|
if (index < 0 || index >= fDriverList.CountItems())
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
@@ -190,6 +196,16 @@ ACPIDriverInterface::GetBatteryCount()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
ACPIDriverInterface::_ReadBatteryInfo()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < fDriverList.CountItems(); i++)
|
||||||
|
fDriverList.ItemAt(i)->ReadBatteryInfo();
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ACPIDriverInterface::_WatchPowerStatus()
|
ACPIDriverInterface::_WatchPowerStatus()
|
||||||
{
|
{
|
||||||
@@ -197,6 +213,7 @@ ACPIDriverInterface::_WatchPowerStatus()
|
|||||||
// every two seconds
|
// every two seconds
|
||||||
|
|
||||||
while (atomic_get(&fIsWatching) > 0) {
|
while (atomic_get(&fIsWatching) > 0) {
|
||||||
|
_ReadBatteryInfo();
|
||||||
Broadcast(kMsgUpdate);
|
Broadcast(kMsgUpdate);
|
||||||
snooze(kUpdateInterval);
|
snooze(kUpdateInterval);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include <Locker.h>
|
#include <Locker.h>
|
||||||
#include <ObjectList.h>
|
#include <ObjectList.h>
|
||||||
|
|
||||||
|
|
||||||
const int8 kRateBufferSize = 10;
|
const int8 kRateBufferSize = 10;
|
||||||
|
|
||||||
class RateBuffer
|
class RateBuffer
|
||||||
@@ -39,7 +40,9 @@ public:
|
|||||||
|
|
||||||
status_t InitCheck();
|
status_t InitCheck();
|
||||||
|
|
||||||
status_t GetBatteryInfo(battery_info* info);
|
// Read battery info and update the cache.
|
||||||
|
status_t ReadBatteryInfo();
|
||||||
|
status_t GetBatteryInfoCached(battery_info* info);
|
||||||
status_t GetExtendedBatteryInfo(
|
status_t GetExtendedBatteryInfo(
|
||||||
acpi_extended_battery_info* info);
|
acpi_extended_battery_info* info);
|
||||||
|
|
||||||
@@ -53,6 +56,7 @@ private:
|
|||||||
acpi_extended_battery_info fExtendedBatteryInfo;
|
acpi_extended_battery_info fExtendedBatteryInfo;
|
||||||
|
|
||||||
RateBuffer fRateBuffer;
|
RateBuffer fRateBuffer;
|
||||||
|
acpi_battery_info fCachedAcpiInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -69,12 +73,15 @@ public:
|
|||||||
virtual int32 GetBatteryCount();
|
virtual int32 GetBatteryCount();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
// Read the battery info from the hardware.
|
||||||
|
virtual status_t _ReadBatteryInfo();
|
||||||
|
|
||||||
virtual void _WatchPowerStatus();
|
virtual void _WatchPowerStatus();
|
||||||
virtual status_t _FindDrivers(const char* path);
|
virtual status_t _FindDrivers(const char* path);
|
||||||
|
|
||||||
BObjectList<Battery> fDriverList;
|
BObjectList<Battery> fDriverList;
|
||||||
|
|
||||||
BLocker fBatteryStatusLock;
|
BLocker fInterfaceLocker;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -15,20 +15,38 @@
|
|||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
|
|
||||||
BatteryInfoView::BatteryInfoView(BRect frame, int32 resizingMode)
|
FontString::FontString()
|
||||||
|
{
|
||||||
|
font = be_plain_font;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const int kLineSpacing = 5;
|
||||||
|
|
||||||
|
BatteryInfoView::BatteryInfoView()
|
||||||
:
|
:
|
||||||
BView(frame, "battery info view", resizingMode, B_WILL_DRAW |
|
BView("battery info view", B_WILL_DRAW |
|
||||||
B_FULL_UPDATE_ON_RESIZE)
|
B_FULL_UPDATE_ON_RESIZE),
|
||||||
|
fPreferredSize(200, 200),
|
||||||
|
fMaxStringSize(0, 0)
|
||||||
{
|
{
|
||||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BatteryInfoView::~BatteryInfoView()
|
||||||
|
{
|
||||||
|
_ClearStringList();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BatteryInfoView::Update(battery_info& info, acpi_extended_battery_info& extInfo)
|
BatteryInfoView::Update(battery_info& info, acpi_extended_battery_info& extInfo)
|
||||||
{
|
{
|
||||||
fBatteryInfo = info;
|
fBatteryInfo = info;
|
||||||
fBatteryExtendedInfo = extInfo;
|
fBatteryExtendedInfo = extInfo;
|
||||||
|
|
||||||
|
_FillStringList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -37,6 +55,50 @@ BatteryInfoView::Draw(BRect updateRect)
|
|||||||
{
|
{
|
||||||
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
|
||||||
|
BPoint point(10, 10);
|
||||||
|
|
||||||
|
float space = _MeasureString("").height + kLineSpacing;
|
||||||
|
|
||||||
|
for (int i = 0; i < fStringList.CountItems(); i ++)
|
||||||
|
{
|
||||||
|
FontString* fontString = fStringList.ItemAt(i);
|
||||||
|
SetFont(fontString->font);
|
||||||
|
DrawString(fontString->string.String(), point);
|
||||||
|
point.y += space;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BatteryInfoView::GetPreferredSize(float *width, float *height)
|
||||||
|
{
|
||||||
|
*width = fPreferredSize.width;
|
||||||
|
*height = fPreferredSize.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSize
|
||||||
|
BatteryInfoView::_MeasureString(const BString& string)
|
||||||
|
{
|
||||||
|
BFont font;
|
||||||
|
GetFont(&font);
|
||||||
|
BSize size;
|
||||||
|
|
||||||
|
size.width = font.StringWidth(string);
|
||||||
|
|
||||||
|
font_height height;
|
||||||
|
font.GetHeight(&height);
|
||||||
|
size.height = height.ascent + height.descent;
|
||||||
|
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BatteryInfoView::_FillStringList()
|
||||||
|
{
|
||||||
|
_ClearStringList();
|
||||||
|
|
||||||
BString powerUnit;
|
BString powerUnit;
|
||||||
BString rateUnit;
|
BString rateUnit;
|
||||||
switch (fBatteryExtendedInfo.power_unit) {
|
switch (fBatteryExtendedInfo.power_unit) {
|
||||||
@@ -51,100 +113,125 @@ BatteryInfoView::Draw(BRect updateRect)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
BString text;
|
FontString* fontString;
|
||||||
|
|
||||||
|
fontString = new FontString;
|
||||||
|
fStringList.AddItem(fontString);
|
||||||
|
fontString->font = be_bold_font;
|
||||||
|
|
||||||
if (fBatteryInfo.state & BATTERY_CHARGING)
|
if (fBatteryInfo.state & BATTERY_CHARGING)
|
||||||
text = "Battery charging";
|
fontString->string = "Battery charging";
|
||||||
else if (fBatteryInfo.state & BATTERY_DISCHARGING)
|
else if (fBatteryInfo.state & BATTERY_DISCHARGING)
|
||||||
text = "Battery discharging";
|
fontString->string = "Battery discharging";
|
||||||
else if (fBatteryInfo.state & BATTERY_CRITICAL_STATE)
|
else if (fBatteryInfo.state & BATTERY_CRITICAL_STATE)
|
||||||
text = "Empty Battery Slot";
|
fontString->string = "Empty Battery Slot";
|
||||||
else
|
else
|
||||||
text = "Battery unused";
|
fontString->string = "Battery unused";
|
||||||
BPoint point(10, 10);
|
|
||||||
int textHeight = 15;
|
|
||||||
int space = textHeight + 5;
|
|
||||||
DrawString(text.String(), point);
|
|
||||||
point.y += space;
|
|
||||||
|
|
||||||
text = "Capacity: ";
|
fontString = new FontString;
|
||||||
text << fBatteryInfo.capacity;
|
fontString->string = "Capacity: ";
|
||||||
text << powerUnit;
|
fontString->string << fBatteryInfo.capacity;
|
||||||
DrawString(text.String(), point);
|
fontString->string << powerUnit;
|
||||||
point.y += space;
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
text = "Last full Charge: ";
|
fontString = new FontString;
|
||||||
text << fBatteryInfo.full_capacity;
|
fontString->string = "Last full Charge: ";
|
||||||
text << powerUnit;
|
fontString->string << fBatteryInfo.full_capacity;
|
||||||
DrawString(text.String(), point);
|
fontString->string << powerUnit;
|
||||||
point.y += space;
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
text = "Current Rate: ";
|
fontString = new FontString;
|
||||||
text << fBatteryInfo.current_rate;
|
fontString->string = "Current Rate: ";
|
||||||
text << rateUnit;
|
fontString->string << fBatteryInfo.current_rate;
|
||||||
DrawString(text.String(), point);
|
fontString->string << rateUnit;
|
||||||
point.y += space;
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
point.y += space;
|
// empty line
|
||||||
|
fontString = new FontString;
|
||||||
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
text = "Design Capacity: ";
|
fontString = new FontString;
|
||||||
text << fBatteryExtendedInfo.design_capacity;
|
fontString->string = "Design Capacity: ";
|
||||||
text << powerUnit;
|
fontString->string << fBatteryExtendedInfo.design_capacity;
|
||||||
DrawString(text.String(), point);
|
fontString->string << powerUnit;
|
||||||
point.y += space;
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
text = "Technology: ";
|
fontString = new FontString;
|
||||||
text << fBatteryExtendedInfo.technology;
|
fontString->string = "Technology: ";
|
||||||
DrawString(text.String(), point);
|
fontString->string << fBatteryExtendedInfo.technology;
|
||||||
point.y += space;
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
text = "Design Voltage: ";
|
fontString = new FontString;
|
||||||
text << fBatteryExtendedInfo.design_voltage;
|
fontString->string = "Design Voltage: ";
|
||||||
text << " mV";
|
fontString->string << fBatteryExtendedInfo.design_voltage;
|
||||||
DrawString(text.String(), point);
|
fontString->string << " mV";
|
||||||
point.y += space;
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
text = "Design Capacity Warning: ";
|
fontString = new FontString;
|
||||||
text << fBatteryExtendedInfo.design_capacity_warning;
|
fontString->string = "Design Capacity Warning: ";
|
||||||
text << powerUnit;
|
fontString->string << fBatteryExtendedInfo.design_capacity_warning;
|
||||||
DrawString(text.String(), point);
|
fontString->string << powerUnit;
|
||||||
point.y += space;
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
text = "Design Capacity low Warning: ";
|
fontString = new FontString;
|
||||||
text << fBatteryExtendedInfo.design_capacity_low;
|
fontString->string = "Design Capacity low Warning: ";
|
||||||
text << powerUnit;
|
fontString->string << fBatteryExtendedInfo.design_capacity_low;
|
||||||
DrawString(text.String(), point);
|
fontString->string << powerUnit;
|
||||||
point.y += space;
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
text = "Capacity Granularity 1: ";
|
fontString = new FontString;
|
||||||
text << fBatteryExtendedInfo.capacity_granularity_1;
|
fontString->string = "Capacity Granularity 1: ";
|
||||||
DrawString(text.String(), point);
|
fontString->string << fBatteryExtendedInfo.capacity_granularity_1;
|
||||||
point.y += space;
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
text = "Capacity Granularity 2: ";
|
fontString = new FontString;
|
||||||
text << fBatteryExtendedInfo.capacity_granularity_2;
|
fontString->string = "Capacity Granularity 2: ";
|
||||||
DrawString(text.String(), point);
|
fontString->string << fBatteryExtendedInfo.capacity_granularity_2;
|
||||||
point.y += space;
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
text = "Model Number: ";
|
fontString = new FontString;
|
||||||
text << fBatteryExtendedInfo.model_number;
|
fontString->string = "Model Number: ";
|
||||||
DrawString(text.String(), point);
|
fontString->string << fBatteryExtendedInfo.model_number;
|
||||||
point.y += space;
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
text = "Serial number: ";
|
fontString = new FontString;
|
||||||
text << fBatteryExtendedInfo.serial_number;
|
fontString->string = "Serial number: ";
|
||||||
DrawString(text.String(), point);
|
fontString->string << fBatteryExtendedInfo.serial_number;
|
||||||
point.y += space;
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
text = "Type: ";
|
fontString = new FontString;
|
||||||
text += fBatteryExtendedInfo.type;
|
fontString->string = "Type: ";
|
||||||
DrawString(text.String(), point);
|
fontString->string += fBatteryExtendedInfo.type;
|
||||||
point.y += space;
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
text = "OEM Info: ";
|
fontString = new FontString;
|
||||||
text += fBatteryExtendedInfo.oem_info;
|
fontString->string = "OEM Info: ";
|
||||||
DrawString(text.String(), point);
|
fontString->string += fBatteryExtendedInfo.oem_info;
|
||||||
point.y += space;
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
|
fPreferredSize.width = fMaxStringSize.width + 10;
|
||||||
|
fPreferredSize.height = (fMaxStringSize.height + kLineSpacing) *
|
||||||
|
fStringList.CountItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BatteryInfoView::_AddToStringList(FontString* fontString)
|
||||||
|
{
|
||||||
|
fStringList.AddItem(fontString);
|
||||||
|
BSize stringSize = _MeasureString(fontString->string);
|
||||||
|
if (fMaxStringSize.width < stringSize.width)
|
||||||
|
fMaxStringSize = stringSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BatteryInfoView::_ClearStringList()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < fStringList.CountItems(); i ++)
|
||||||
|
delete fStringList.ItemAt(i);
|
||||||
|
fStringList.MakeEmpty();
|
||||||
|
fMaxStringSize = BSize(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -225,7 +312,8 @@ ExtPowerStatusView::_Update(bool force)
|
|||||||
ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface)
|
ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface)
|
||||||
:
|
:
|
||||||
BWindow(BRect(100, 150, 500, 500), "Extended Battery Info", B_TITLED_WINDOW,
|
BWindow(BRect(100, 150, 500, 500), "Extended Battery Info", B_TITLED_WINDOW,
|
||||||
B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS),
|
B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AVOID_FRONT |
|
||||||
|
B_ASYNCHRONOUS_CONTROLS),
|
||||||
fDriverInterface(interface),
|
fDriverInterface(interface),
|
||||||
fSelectedView(NULL)
|
fSelectedView(NULL)
|
||||||
{
|
{
|
||||||
@@ -252,13 +340,17 @@ ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface)
|
|||||||
batteryView->GroupLayout()->SetSpacing(10);
|
batteryView->GroupLayout()->SetSpacing(10);
|
||||||
infoLayout->AddView(batteryView);
|
infoLayout->AddView(batteryView);
|
||||||
|
|
||||||
fBatteryInfoView = new BatteryInfoView(BRect(0, 0, 270, 310), B_FOLLOW_ALL);
|
// create before the battery views
|
||||||
|
fBatteryInfoView = new BatteryInfoView();
|
||||||
|
|
||||||
BGroupLayout* batteryLayout = batteryView->GroupLayout();
|
BGroupLayout* batteryLayout = batteryView->GroupLayout();
|
||||||
BRect batteryRect(0, 0, 50, 30);
|
BRect batteryRect(0, 0, 50, 30);
|
||||||
for (int i = 0; i < interface->GetBatteryCount(); i++) {
|
for (int i = 0; i < interface->GetBatteryCount(); i++) {
|
||||||
ExtPowerStatusView* view = new ExtPowerStatusView(interface,
|
ExtPowerStatusView* view = new ExtPowerStatusView(interface,
|
||||||
batteryRect, B_FOLLOW_ALL, i, this);
|
batteryRect, B_FOLLOW_NONE, i, this);
|
||||||
|
view->SetExplicitMaxSize(BSize(70, 80));
|
||||||
|
view->SetExplicitMinSize(BSize(70, 80));
|
||||||
|
|
||||||
batteryLayout->AddView(view);
|
batteryLayout->AddView(view);
|
||||||
fBatteryViewList.AddItem(view);
|
fBatteryViewList.AddItem(view);
|
||||||
fDriverInterface->StartWatching(view);
|
fDriverInterface->StartWatching(view);
|
||||||
@@ -268,7 +360,7 @@ ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface)
|
|||||||
|
|
||||||
batteryLayout->AddItem(BSpaceLayoutItem::CreateGlue());
|
batteryLayout->AddItem(BSpaceLayoutItem::CreateGlue());
|
||||||
|
|
||||||
infoLayout->AddView(fBatteryInfoView, 20);
|
infoLayout->AddView(fBatteryInfoView);
|
||||||
|
|
||||||
if (!fSelectedView && fBatteryViewList.CountItems() > 0)
|
if (!fSelectedView && fBatteryViewList.CountItems() > 0)
|
||||||
fSelectedView = fBatteryViewList.ItemAt(0);
|
fSelectedView = fBatteryViewList.ItemAt(0);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#define EXTENDED_INFO_WINDOW_H
|
#define EXTENDED_INFO_WINDOW_H
|
||||||
|
|
||||||
#include <ObjectList.h>
|
#include <ObjectList.h>
|
||||||
#include <StringView.h>
|
#include <String.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
@@ -18,18 +18,40 @@
|
|||||||
#include "PowerStatusView.h"
|
#include "PowerStatusView.h"
|
||||||
|
|
||||||
|
|
||||||
|
class FontString
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FontString();
|
||||||
|
|
||||||
|
const BFont* font;
|
||||||
|
BString string;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class BatteryInfoView : public BView
|
class BatteryInfoView : public BView
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BatteryInfoView(BRect frame, int32 resizingMode);
|
BatteryInfoView();
|
||||||
|
~BatteryInfoView();
|
||||||
|
|
||||||
virtual void Update(battery_info& info,
|
virtual void Update(battery_info& info,
|
||||||
acpi_extended_battery_info& extInfo);
|
acpi_extended_battery_info& extInfo);
|
||||||
virtual void Draw(BRect updateRect);
|
virtual void Draw(BRect updateRect);
|
||||||
|
virtual void GetPreferredSize(float *width, float *height);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
BSize _MeasureString(const BString& string);
|
||||||
|
void _FillStringList();
|
||||||
|
void _AddToStringList(FontString* fontString);
|
||||||
|
void _ClearStringList();
|
||||||
|
|
||||||
battery_info fBatteryInfo;
|
battery_info fBatteryInfo;
|
||||||
acpi_extended_battery_info fBatteryExtendedInfo;
|
acpi_extended_battery_info fBatteryExtendedInfo;
|
||||||
|
|
||||||
|
BSize fPreferredSize;
|
||||||
|
|
||||||
|
BObjectList<FontString> fStringList;
|
||||||
|
BSize fMaxStringSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ PowerStatusView::_SetLabel(char* buffer, size_t bufferLength)
|
|||||||
if (!fShowTime && fPercent >= 0)
|
if (!fShowTime && fPercent >= 0)
|
||||||
snprintf(buffer, bufferLength, "%s%ld%%%s", open, fPercent, close);
|
snprintf(buffer, bufferLength, "%s%ld%%%s", open, fPercent, close);
|
||||||
else if (fShowTime && fTimeLeft >= 0) {
|
else if (fShowTime && fTimeLeft >= 0) {
|
||||||
snprintf(buffer, bufferLength, "%s%ld:%ld%s",
|
snprintf(buffer, bufferLength, "%s%ld:%02ld%s",
|
||||||
open, fTimeLeft / 3600, (fTimeLeft / 60) % 60, close);
|
open, fTimeLeft / 3600, (fTimeLeft / 60) % 60, close);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user