Nokia N97 SDK
Example Applications Guide

CAddressBookView Class Reference

#include <AddressBookView.h>

Inheritance diagram for CAddressBookView:

List of all members.

Detailed Description

CAddressBookView container control class, shows the application state on the screen

Definition at line 66 of file AddressBookView.h.


Public Member Functions

void  ConstructL (const TRect &aRect)
  CAddressBookView (CAddressBookEngine &aEngine)
  ~CAddressBookView ()
void  UpdateL (RPointerArray< CAddressBookContact > &aContactArray)
void  OpenItemL ()
void  CloseItem ()
void  ChangeCbaL (TInt aResourceId, TDrawNow aDrawNow)
bool  ShowAbout (TBool aAboutVisible=ETrue)
CAddressBookContact *  CurrentContact ()
void  AppendRowL (TPtrC8 aValue, const TDesC8 &aFieldName, CDesCArray &aArray)
void  HandleListBoxEventL (CEikListBox *, TListBoxEvent aEventType)

Private Member Functions

void  SizeChanged ()
TInt  CountComponentControls () const
CCoeControl *  ComponentControl (TInt aIndex) const
void  Draw (const TRect &aRect) const
void  HandleControlEventL (CCoeControl *aControl, TCoeEvent aEventType)
virtual TKeyResponse  OfferKeyEventL (const TKeyEvent &aKeyEvent, TEventCode aType)

Private Attributes

CAddressBookEngine &  iEngine
TBool  iDetailedView
CEikColumnListBox *  iSearchList
CEikTextListBox *  iDetailList
CDesCArray *  iItemList
const CFont *  iFont


Constructor & Destructor Documentation

CAddressBookView::CAddressBookView (  CAddressBookEngine &  aEngine  ) 
 

C++ default constructor.

Definition at line 41 of file AddressBookView.cpp.

00042 :
00043 iEngine(aEngine),
00044 iDetailedView(EFalse),
00045 iSearchList(NULL),
00046 iDetailList(NULL)
00047     {
00048     }

CAddressBookView::~CAddressBookView (   ) 
 

Destructor.

Definition at line 55 of file AddressBookView.cpp.

References iDetailList, iItemList, and iSearchList.

00056     {
00057     delete iSearchList;
00058         if (iItemList)
00059                 iItemList->Reset();
00060         
00061         delete iItemList;
00062         delete iDetailList;
00063         }


Member Function Documentation

void CAddressBookView::ConstructL (  const TRect &  aRect  ) 
 

By default Symbian 2nd phase constructor is private.

Parameters:
aRect  Frame rectangle for container.

Definition at line 70 of file AddressBookView.cpp.

References iDetailList, iFont, iItemList, and iSearchList.

Referenced by CAddressBookAppUi::ConstructL().

00071     {
00072     CreateWindowL();
00073     
00074     iFont = AknLayoutUtils::FontFromId(EAknLogicalFontSecondaryFont);
00075     
00076         iSearchList = new (ELeave) CAknSingleStyleListBox();
00077         iSearchList->ConstructL(this);
00078         iSearchList->SetContainerWindowL(*this);
00079         iSearchList->CreateScrollBarFrameL(ETrue);
00080         iSearchList->ScrollBarFrame()->SetScrollBarVisibilityL(
00081                                                                                                         CEikScrollBarFrame::EOn,
00082                                                                                                         CEikScrollBarFrame::EAuto);
00083 
00084         iItemList = new (ELeave) CDesCArrayFlat(3);
00085         iSearchList->Model()->SetItemTextArray(iItemList);
00086         iSearchList->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray);
00087         
00088         iDetailList = new (ELeave) CAknFormDoubleStyleListBox;
00089         iDetailList->ConstructL(this);
00090         iDetailList->SetContainerWindowL(*this);
00091         iDetailList->CreateScrollBarFrameL(ETrue);
00092         iDetailList->ScrollBarFrame()->SetScrollBarVisibilityL(
00093                                                                                                 CEikScrollBarFrame::EOn,
00094                                                                                                 CEikScrollBarFrame::EAuto);
00095         iDetailList->Model()->SetOwnershipType(ELbmOwnsItemArray);
00096         iDetailList->MakeVisible(EFalse);
00097         iSearchList->MakeVisible(ETrue); // show "no results" at startup
00098         iSearchList->SetListBoxObserver(this);
00099     SetRect(aRect);
00100     ActivateL();
00101         MakeVisible(ETrue);
00102         }

void CAddressBookView::UpdateL (  RPointerArray< CAddressBookContact > &  aContactArray  ) 
 

Updates bufer containing the contact information when search was finished

Parameters:
aContactArray  - descriptor on the array connecting finding information

Definition at line 126 of file AddressBookView.cpp.

References iItemList, iSearchList, and CAddressBookContact::MobilePhoneL().

Referenced by CAddressBookAppUi::SearchFinishedL().

00127         {
00128         iItemList->Reset();
00129         iSearchList->MakeVisible(ETrue);
00130         TInt count = aContactArray.Count();
00131         if(count > 0)
00132                 {
00133                 for( TInt i = 0; i < count; ++i )
00134                         {
00135                         CAddressBookContact* item = aContactArray[i];
00136                         
00137                         HBufC8* pRow = HBufC8::NewLC(128);
00138                         TPtr8 ptrRow = pRow->Des();
00139                         if (item->MobilePhoneL() != KNullDesC8)
00140                                 {
00141                                 ptrRow.Append(KHasPhoneChar);   
00142                                 }
00143                         ptrRow.Append(KTab);
00144                         ptrRow.Append(item->LastName());
00145                         ptrRow.Append(KSpace);
00146                         ptrRow.Append(item->FirstName());
00147                         ptrRow.Append(KTab);
00148                         ptrRow.Append(KTab);
00149 
00150                         HBufC* pRowAsUnicode = SenXmlUtils::ToUnicodeLC(ptrRow);
00151                         if(pRowAsUnicode)
00152                                 {
00153                                 iItemList->AppendL(*pRowAsUnicode);
00154                                 }
00155                         CleanupStack::PopAndDestroy(pRowAsUnicode); 
00156                         CleanupStack::PopAndDestroy(pRow); 
00157                         }
00158                 
00159                 iSearchList->HandleItemAdditionL();
00160                 iSearchList->SetFocus(ETrue, EDrawNow);
00161                 iSearchList->SetCurrentItemIndexAndDraw(0);
00162                 }
00163         else
00164                 {
00165                 iSearchList->HandleItemRemovalL();
00166                 }
00167         }

void CAddressBookView::OpenItemL (   ) 
 

is needed to browse Contact information

Definition at line 249 of file AddressBookView.cpp.

References AppendRowL(), CAddressBookContact::Country(), CAddressBookContact::Email(), CAddressBookContact::ExtraAddress(), CAddressBookContact::FaxL(), CAddressBookContact::FirstName(), CAddressBookEngine::GetContact(), iDetailedView, iEngine, iSearchList, CAddressBookContact::LastName(), CAddressBookContact::Locality(), CAddressBookContact::MiddleName(), CAddressBookContact::MobilePhoneL(), CAddressBookContact::Organization(), CAddressBookContact::PhoneL(), CAddressBookContact::PostCode(), CAddressBookContact::Region(), SizeChanged(), CAddressBookContact::Street(), CAddressBookContact::Title(), and CAddressBookContact::Unit().

Referenced by HandleListBoxEventL().

00250         {
00251         if (iDetailedView)
00252                 return;
00253 
00254         CAddressBookContact* item = NULL; 
00255         TInt success = iEngine.GetContact(iSearchList->CurrentItemIndex(), item);
00256         if (success == KErrNotFound)
00257                 return;
00258         iSearchList->MakeVisible(EFalse);
00259         CDesCArray* array = new (ELeave) CDesCArrayFlat(3);
00260 
00261         AppendRowL(item->LastName(), KLastname, *array);
00262         AppendRowL(item->FirstName(), KFirstname,*array);
00263         AppendRowL(item->MiddleName(), KMiddlename, *array);
00264         AppendRowL(item->ExtraAddress(), KExtAddr, *array);
00265         AppendRowL(item->Street(), KStreet, *array);
00266         AppendRowL(item->Locality(), KLocality, *array);
00267         AppendRowL(item->Region(), KRegion, *array);
00268         AppendRowL(item->PostCode(), KPCode, *array);
00269         AppendRowL(item->Country(), KCountry, *array);
00270         AppendRowL(item->PhoneL(), KPhone, *array);
00271         AppendRowL(item->MobilePhoneL(), KMobile, *array);
00272         AppendRowL(item->FaxL(), KFax, *array);
00273         AppendRowL(item->Email(), KEmail, *array);
00274         AppendRowL(item->Title(), KTitle, *array);
00275         AppendRowL(item->Organization(), KOrganization, *array);
00276         AppendRowL(item->Unit(), KUnit, *array);
00277         
00278         iDetailedView = ETrue;
00279         iDetailList->Model()->SetItemTextArray(array);
00280         iDetailList->MakeVisible(ETrue);
00281         iDetailList->SetCurrentItemIndexAndDraw(0);
00282         SizeChanged();
00283         iDetailList->ActivateL();
00284         }

void CAddressBookView::CloseItem (   ) 
 

It is called when Contact information was browsed and needed to be closed

Definition at line 237 of file AddressBookView.cpp.

References iDetailedView, and iSearchList.

Referenced by CAddressBookAppUi::HandleCommandL().

00238         {
00239         iDetailedView = EFalse;
00240         iSearchList->MakeVisible(ETrue);
00241         iDetailList->MakeVisible(EFalse);
00242         DrawDeferred();
00243         }

void CAddressBookView::ChangeCbaL (  TInt  aResourceId,
TDrawNow  aDrawNow
) 
 

It is called when need to open or close some item to change common button area

Parameters:
aResourceId  - Id of Resource
aDrawNow  - ENoDrawNow - Redraw of the control is not required immediately. EDrawNow - Redraw control immediately.

Definition at line 319 of file AddressBookView.cpp.

Referenced by CAddressBookAppUi::HandleCommandL(), and HandleListBoxEventL().

00320     {
00321     CEikButtonGroupContainer* Cba = CEikButtonGroupContainer::Current();
00322     if(Cba)
00323         {
00324         Cba->SetCommandSetL(aResourceId);
00325         
00326         if(aDrawNow)
00327                 Cba->DrawNow();
00328         else
00329                 Cba->DrawDeferred();    
00330                 }
00331     }

bool CAddressBookView::ShowAbout (  TBool  aAboutVisible = ETrue  ) 
 

Shows information about Address Book aplication.

Parameters:
aAboutVisible  - ETrue in case that to show information on the screen
Returns:
aAboutVisible

Definition at line 338 of file AddressBookView.cpp.

References iDetailedView, and iSearchList.

Referenced by CAddressBookAppUi::HandleCommandL().

00339         {
00340         iDetailedView = EFalse;
00341         iSearchList->MakeVisible(!aAboutVisible);
00342         iDetailList->MakeVisible(EFalse);
00343         DrawDeferred();
00344         return aAboutVisible; 
00345         }

CAddressBookContact * CAddressBookView::CurrentContact (   ) 
 

Is needed to add current contact into PnoneBook database.

Returns:
descriptor on current contact

Definition at line 352 of file AddressBookView.cpp.

References CAddressBookEngine::GetContact(), iEngine, and iSearchList.

Referenced by CAddressBookAppUi::DynInitMenuPaneL(), and CAddressBookAppUi::HandleCommandL().

00353         {
00354         CAddressBookContact* pContact = NULL;
00355         iEngine.GetContact(iSearchList->CurrentItemIndex(), 
00356                                                 pContact // pContact remains NULL if not found
00357                                                 ); 
00358         return pContact;
00359         }

void CAddressBookView::AppendRowL (  TPtrC8  aValue,
const TDesC8 &  aFieldName,
CDesCArray &  aArray
) 
 

Creates card (full contact information) about a person who was found

Parameters:
aValue  - value of field that is needed to locate in the aArray
aFieldName  - name of field whose value contains in aValue
aArray  - pointer on the array where will be located this card

Definition at line 367 of file AddressBookView.cpp.

Referenced by OpenItemL().

00369         {
00370         if (aValue != KNullDesC8)
00371                 {
00372                 TBuf8<64> row;
00373                 HBufC* pRowAsUnicode = NULL;
00374                 row.Format(KRowFormat, &aFieldName, &aValue);
00375                 pRowAsUnicode = SenXmlUtils::ToUnicodeLC(row);
00376                 if(pRowAsUnicode)
00377                         {
00378                         aArray.AppendL(*pRowAsUnicode);
00379                         CleanupStack::PopAndDestroy(pRowAsUnicode); 
00380                         }
00381                 }
00382         }

void CAddressBookView::HandleListBoxEventL (  CEikListBox *  ,
TListBoxEvent  aEventType
) 
 

From MEikListBoxObserver, is called when user want to browse the card (full contact information) about employees who was found

Parameters:
aEventType  - type of event

Definition at line 304 of file AddressBookView.cpp.

References ChangeCbaL(), and OpenItemL().

00305     {
00306         if (aEventType == EEventEnterKeyPressed)
00307                 {
00308                 OpenItemL();
00309                 ChangeCbaL(R_AVKON_SOFTKEYS_OPTIONS_BACK, EDrawNow);
00310                 }
00311     }

void CAddressBookView::SizeChanged (   )  [private]
 

From CCoeControl, is called by framework when the view size is changed

Definition at line 109 of file AddressBookView.cpp.

References iDetailList, and iSearchList.

Referenced by OpenItemL().

00110     {
00111         if (iSearchList)
00112                 {
00113                 iSearchList->SetExtent( TPoint(0,0), iSearchList->MinimumSize() );
00114                 }
00115         if (iDetailList)
00116                 {
00117                 iDetailList->SetExtent( TPoint(0,0), iDetailList->MinimumSize() );
00118                 }
00119     }

TInt CAddressBookView::CountComponentControls (   )  const [private]
 

From CCoeControl, is called by the active scheduler to controll count of components

Returns:
1

Definition at line 174 of file AddressBookView.cpp.

00175     {
00176     return 1; 
00177     }

CCoeControl * CAddressBookView::ComponentControl (  TInt  aIndex  )  const [private]
 

From CCoeControl, is called by the active scheduler to controll components

Parameters:
aIndex 
Returns:
- iDetailList/iSearchList(if aIndex == 0)/NULL (if aInex != 0)

Definition at line 184 of file AddressBookView.cpp.

References iDetailedView, and iSearchList.

Referenced by OfferKeyEventL().

00185     {
00186     switch ( aIndex )
00187         {
00188         case 0:
00189                         if (iDetailedView)
00190                                 return iDetailList;
00191                         else
00192                                 {
00193                                 return iSearchList;
00194                                 }
00195         default:
00196             return NULL;
00197         }
00198     }

void CAddressBookView::Draw (  const TRect &  aRect  )  const [private]
 

From CCoeControl, draws rects

Parameters:
aRect  - pointer on rectangle that has to be drawn

Definition at line 204 of file AddressBookView.cpp.

References iFont.

00205     {
00206     CWindowGc& gc = SystemGc();
00207     
00208     gc.SetPenStyle( CGraphicsContext::ENullPen );
00209     gc.SetBrushColor( KRgbWhite );
00210     gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
00211     gc.DrawRect( aRect );
00212 
00213         gc.UseFont(iFont);
00214         TInt lineHeight = iFont->HeightInPixels()+1;
00215         
00216         const TInt col = 5;
00217         gc.DrawText(KAboutString1, TPoint(col, lineHeight));
00218         gc.DrawText(KAboutString2, TPoint(col, lineHeight*2));
00219         gc.DrawText(KAboutString3, TPoint(col, lineHeight*3));  
00220         gc.DrawText(KAboutString4, TPoint(col, lineHeight*4));
00221         gc.DrawText(KAboutString5, TPoint(col, lineHeight*5));
00222     }

void CAddressBookView::HandleControlEventL (  CCoeControl *  aControl,
TCoeEvent  aEventType
)  [private]
 

From MCoeControlObserver, acts upon changes in the hosted control's state.

Parameters:
aControl  - The control changing its state
aEventType  - The type of control event

Definition at line 228 of file AddressBookView.cpp.

00229     {
00230     }

TKeyResponse CAddressBookView::OfferKeyEventL (  const TKeyEvent &  aKeyEvent,
TEventCode  aType
)  [private, virtual]
 

From CCoeControl the key event handler function, is called every time when user presses some button.

Parameters:
aKeyEvent  - Event to handled.
aType  - Type of the key event.
Returns:
Response code (EKeyWasConsumed, EKeyWasNotConsumed).

Definition at line 292 of file AddressBookView.cpp.

References ComponentControl().

00294         {
00295         return ComponentControl(0)->OfferKeyEventL(aKeyEvent,aType);
00296         }


The documentation for this class was generated from the following files:

© Nokia 2009

Back to top