📄 powerresmancontainer.cpp
字号:
/**
*
* Definition of CPowerResManContainer
*
* Copyright (c) 2004 Nokia Corporation
* version 2.0
*/
// INCLUDE FILES
#include "PowerResManContainer.h"
#include "StateVarObserver.h"
#include <sacls.h>
#include <stringloader.h>
#include <badesca.h>
// ================= MEMBER FUNCTIONS =======================
// 2nd Phase constructor
void CPowerResManContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
// Create the listbox
iListbox = new(ELeave)CAknDoubleStyleListBox();
iListbox->SetContainerWindowL( *this);
// Construct the listbox from the resource specified
TResourceReader reader;
CEikonEnv::Static()->CreateResourceReaderLC(reader, R_SYSTEMAGENT_LIST);
iListbox->SetObserver(this);
iListbox->ConstructFromResourceL( reader );
CleanupStack::PopAndDestroy(); // resource
// Populate the list box dynamically with default values
SetupListItemsL();
SetRect(aRect);
ActivateL();
}
// Destructor
CPowerResManContainer::~CPowerResManContainer()
{
delete iListbox;
}
// Called by framework when the view size is changed
void CPowerResManContainer::SizeChanged()
{
// Resize the list control
iListbox->SetRect( Rect() );
}
// // return nbr of controls inside this container
TInt CPowerResManContainer::CountComponentControls() const
{
return 1;
}
// Get the specified component of a compound control.
CCoeControl* CPowerResManContainer::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iListbox;
default:
return NULL;
}
}
// Called by the window server to draw a control
void CPowerResManContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.SetPenStyle( CGraphicsContext::ENullPen );
gc.SetBrushColor( KRgbGray );
gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
gc.DrawRect( aRect );
}
// Handles an event from an observed control.
void CPowerResManContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
}
// Sets the text in the control on the specified line of the list
void CPowerResManContainer::SetTextL(TSystemAgentListLineId aLine, const TDesC& aText)
{
// Get a pointer to the listbox model
CTextListBoxModel* model = iListbox->Model();
// we do not want to take ownership of the item array
model->SetOwnershipType (ELbmOwnsItemArray);
// Retrieve the item array from the listbox model
CDesCArray* listArray = STATIC_CAST(CDesCArray*, model->ItemTextArray());
// Make the changes to the array
// Delete the value that has been modified
listArray->Delete(aLine);
// Insert the new value
listArray->InsertL(aLine, aText);
iListbox->DrawDeferred();
}
// Responsible for updating the values in the list control when a change occurs
void CPowerResManContainer::ProcessStateVarChangeL(TUid aStateVarUid, TInt aNewState)
{
TInt stateTextId = R_NOTAVAILABLE_TEXT;
// The ID of the line in the list corresponding to aStateVarUid
TSystemAgentListLineId lineId = ESystemAgentListBatteryStateLabel;
// listItem is used to set the text for a particular item in the list array
HBufC* listItem = NULL;
// Workout which label and state strings correspond with the new state
//if (aStateVarUid == KUidBatteryStrength) //doesn't work since 2nd ed. FP2
if (aStateVarUid == KUidBatteryBars)
{
lineId = ESystemAgentListBatteryStateLabel;
listItem = StringLoader::LoadLC(R_BATTERY_STATUS);
#ifdef __SERIES60_3X__ //scale to 0-7, CTelephony gives 0,14,28,..
aNewState = aNewState/14;
#endif
switch (aNewState)
{
case ESABBars_0:
stateTextId = R_BATTERY_EMPTY_TEXT;
break;
case ESABBars_1:
stateTextId = R_BATTERY_ALMOST_EMPTY_TEXT;
break;
case ESABBars_2:
stateTextId = R_BATTERY_LOW_TEXT;
break;
case ESABBars_3:
stateTextId = R_BATTERY_MEDIUM_TEXT;
break;
case ESABBars_4:
stateTextId = R_BATTERY_MEDIUM_TEXT;
break;
case ESABBars_5:
stateTextId = R_BATTERY_ALMOST_FULL_TEXT;
break;
case ESABBars_6:
stateTextId = R_BATTERY_ALMOST_FULL_TEXT;
break;
case ESABBars_7:
stateTextId = R_BATTERY_FULL_TEXT;
break;
default:
stateTextId = R_NOTAVAILABLE_TEXT;
break;
}
}
else if (aStateVarUid == KUidChargerStatus)
{
lineId = ESystemAgentListChargerStateLabel;
listItem = StringLoader::LoadLC(R_CHARGER_STATUS);
#ifdef __SERIES60_3X__
//In 3rd edition this value is read in StateVarObserver::RunL
//if(iIndicatorV1.iIndicator & CTelephony::KIndChargerConnected)
if (aNewState == 0)
stateTextId = R_CHARGER_DISCONNECTED_TEXT;
else if (aNewState == 1)
stateTextId = R_CHARGER_CHARGING_TEXT;
else
stateTextId = R_NOTAVAILABLE_TEXT;
#else
//In 1st and 2nd edition this value is System Agent's
//KUidChargerStatus
switch (aNewState)
{
case ESAChargerConnected:
stateTextId = R_CHARGER_CHARGING_TEXT;
break;
case ESAChargerDisconnected:
stateTextId = R_CHARGER_DISCONNECTED_TEXT;
break;
case ESAChargerNotCharging:
stateTextId = R_CHARGER_NOTCHARGING_TEXT;
break;
default:
stateTextId = R_NOTAVAILABLE_TEXT;
break;
}
#endif
}
else if (aStateVarUid == KUidNetworkStrength)
{
lineId = ESystemAgentListNetworkStrengthStateLabel;
listItem = StringLoader::LoadLC(R_WINDOW_STATUS);
#ifdef __SERIES60_3X__
if( aNewState == 0 )
stateTextId = R_NETWORKSTRENGTH_NONE_TEXT;
else if( aNewState <= 2 )
stateTextId = R_NETWORKSTRENGTH_LOW_TEXT;
else if ( aNewState <= 5 )
stateTextId = R_NETWORKSTRENGTH_MEDIUM_TEXT;
else if ( aNewState <= 7 )
stateTextId = R_NETWORKSTRENGTH_HIGH_TEXT;
else
stateTextId = R_NETWORKSTRENGTH_UNKNOWN_TEXT;
#else
switch (aNewState)
{
case ESANetworkStrengthNone:
stateTextId = R_NETWORKSTRENGTH_NONE_TEXT;
break;
case ESANetworkStrengthLow:
stateTextId = R_NETWORKSTRENGTH_LOW_TEXT;
break;
case ESANetworkStrengthMedium:
stateTextId = R_NETWORKSTRENGTH_MEDIUM_TEXT;
break;
case ESANetworkStrengthHigh:
stateTextId = R_NETWORKSTRENGTH_HIGH_TEXT;
break;
case ESANetworkStrengthUnknown:
stateTextId = R_NETWORKSTRENGTH_UNKNOWN_TEXT;
break;
default:
stateTextId = R_NONETWORK_TEXT;
break;
}
#endif
}
else
User::Leave(KErrNotSupported);
// Complete the list item text by adding the state text
if(listItem)
{
HBufC* stateText = StringLoader::LoadLC(stateTextId);
listItem = listItem->ReAllocL(listItem->Length() + stateText->Length());
CleanupStack::Pop(2); // stateText, original listItem
CleanupStack::PushL(listItem);
CleanupStack::PushL(stateText);
listItem->Des().Append(*stateText);
// Set the text in the appropriate line of the list
SetTextL(lineId, *listItem);
CleanupStack::PopAndDestroy(2,listItem); //listItem, stateText
}
}
// Responsible for creating the initial list values
void CPowerResManContainer::SetupListItemsL()
{
// get the model from the listbox
CTextListBoxModel* model = iListbox->Model();
// we are not taking ownership
model->SetOwnershipType (ELbmOwnsItemArray);
// retrieve the list item array from the model
CDesCArray* defaultArray = STATIC_CAST(CDesCArray*, model->ItemTextArray());
// Populate the list with default values
LoadDefaultValuesL(*defaultArray);
}
// Populates the list model's item array with default values
void CPowerResManContainer::LoadDefaultValuesL(CDesCArray& aDefaultValuesArray)
{
// All 3 states are initially set up as 'Not available'
// Battery Status
HBufC* notAvail = StringLoader::LoadLC(R_NOTAVAILABLE_TEXT);
HBufC* listItem = StringLoader::LoadLC(R_BATTERY_STATUS);
listItem = listItem->ReAllocL(listItem->Length() + notAvail->Length());
CleanupStack::Pop(); // original listItem
CleanupStack::PushL(listItem);
(listItem->Des()).Append(*notAvail);
aDefaultValuesArray.AppendL(*listItem);
CleanupStack::PopAndDestroy(listItem);
listItem = NULL;
// Charger Status
listItem = StringLoader::LoadLC(R_CHARGER_STATUS);
listItem = listItem->ReAllocL(listItem->Length() + notAvail->Length());
CleanupStack::Pop(); // original listItem
CleanupStack::PushL(listItem);
(listItem->Des()).Append(*notAvail);
aDefaultValuesArray.AppendL(*listItem);
CleanupStack::PopAndDestroy(listItem);
listItem = NULL;
// Network status
listItem = StringLoader::LoadLC(R_WINDOW_STATUS);
TInt lengthRequired = listItem->Length() + notAvail->Length();
listItem = listItem->ReAllocL(lengthRequired);
CleanupStack::Pop(); // original listItem
CleanupStack::PushL(listItem);
(listItem->Des()).Append(*notAvail);
aDefaultValuesArray.AppendL(*listItem);
CleanupStack::PopAndDestroy(2, notAvail);
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -