Nokia N97 SDK
Example Applications Guide

CAddressBookAppUi Class Reference

#include <AddressBookAppUi.h>

Inheritance diagram for CAddressBookAppUi:

MAddressBookEngineObserver List of all members.

Detailed Description

Application UI class. Provides support for the following features:

Definition at line 43 of file AddressBookAppUi.h.


Public Member Functions

  ~CAddressBookAppUi ()
virtual void  ErrorL (TInt aCode)
virtual void  ConnectionReady ()
virtual void  SearchFinishedL (RPointerArray< CAddressBookContact > &aContactArray)

Private Member Functions

void  ConstructL ()
void  UpdateFieldL (CPbkContactItem *aModifiableItem, TPbkFieldId aFieldId, const TDesC8 &aNewValue)
void  DynInitMenuPaneL (TInt aResourceId, CEikMenuPane *aMenuPane)
void  DialogDismissedL (TInt aButtonId)
TBool  IsProcessDone () const
void  ProcessFinished ()
void  StepL ()
void  HandleCommandL (TInt aCommand)
virtual TKeyResponse  HandleKeyEventL (const TKeyEvent &aKeyEvent, TEventCode aType)

Private Attributes

CAddressBookView *  iAppContainer
CAddressBookEngine *  iEngine
CPbkContactEngine *  iContactEngine
CAknWaitNoteWrapper *  iWaitNote
TBool  iReady
TBool  iFirstTime
TBool  iConnecting
TBool  iAbout


Constructor & Destructor Documentation

CAddressBookAppUi::~CAddressBookAppUi (   ) 
 

Destructor.

Definition at line 64 of file AddressBookAppUi.cpp.

References iAppContainer, iContactEngine, iEngine, and iWaitNote.

00065     {
00066     if (iAppContainer)
00067         {
00068         RemoveFromStack( iAppContainer );
00069         delete iAppContainer;
00070         }
00071         delete iEngine;
00072         delete iContactEngine;
00073         delete iWaitNote;
00074    }


Member Function Documentation

void CAddressBookAppUi::ErrorL (  TInt  aCode  )  [virtual]
 

From MAddressBookEngineObserver, checks errors that can happen

Parameters:
aCode  Code of Error

Implements MAddressBookEngineObserver.

Definition at line 286 of file AddressBookAppUi.cpp.

References iReady.

00287         {
00288         _LIT(KNotReady, "Connection is not ready.");
00289         _LIT(KTooManyMatches, "Too many search results, please refine your search.");
00290         _LIT(KSearchFailed, "Internal error, please try again.");
00291 
00292         iReady = ETrue;
00293         CAknErrorNote* note = new (ELeave) CAknErrorNote(EFalse);
00294         TBuf<70> errorMessage;
00295         switch(aCode) 
00296                 {
00297                 case EConnectionNotReady:
00298                         errorMessage = KNotReady;
00299                         break;
00300                 case ETooManyMatches:
00301                         errorMessage = KTooManyMatches;
00302                         break;
00303                 case ESearchFailed:
00304                         errorMessage = KSearchFailed;
00305                         break;
00306                 default:
00307                         break;
00308                 }
00309         note->ExecuteLD(errorMessage);
00310         }

void CAddressBookAppUi::ConnectionReady (   )  [virtual]
 

From MAddressBookEngineObserver, is called by the CAddressBookEngine::SetStatus(const TInt aStatus) to set conection's status as ready

Implements MAddressBookEngineObserver.

Definition at line 319 of file AddressBookAppUi.cpp.

References iReady.

00320         {
00321         iReady = ETrue;
00322         }

void CAddressBookAppUi::SearchFinishedL (  RPointerArray< CAddressBookContact > &  aContactArray  )  [virtual]
 

From MAddressBookEngineObserver, updates bufer containing the contact information and sets status as READY

Parameters:
aContactArray  - contact information that was found

Implements MAddressBookEngineObserver.

Definition at line 355 of file AddressBookAppUi.cpp.

References iAppContainer, iReady, and CAddressBookView::UpdateL().

00356         {
00357         iAppContainer->UpdateL(aContactArray);
00358         iReady = ETrue;
00359         }

void CAddressBookAppUi::ConstructL (   )  [private]
 

By default Symbian 2nd phase constructor is private.

Definition at line 41 of file AddressBookAppUi.cpp.

References CAddressBookView::ConstructL(), iAbout, iAppContainer, iConnecting, iContactEngine, iEngine, iFirstTime, iReady, iWaitNote, and CAddressBookEngine::NewL().

00042     {
00043     BaseConstructL(CAknAppUi::EAknEnableSkin);
00044         iWaitNote = CAknWaitNoteWrapper::NewL();
00045         iReady = EFalse;
00046         iFirstTime = ETrue;
00047         iConnecting = EFalse;
00048         iAbout = EFalse;
00049 
00050         iEngine = CAddressBookEngine::NewL(*this);
00051     iAppContainer = new (ELeave) CAddressBookView(*iEngine);
00052     iAppContainer->SetMopParent( this );
00053     iAppContainer->ConstructL( ClientRect() );
00054     AddToStackL( iAppContainer );
00055     iContactEngine = CPbkContactEngine::NewL(NULL);
00056     }

void CAddressBookAppUi::UpdateFieldL (  CPbkContactItem *  aModifiableItem,
TPbkFieldId  aFieldId,
const TDesC8 &  aNewValue
)  [private]
 

Updates field of CPbkContactItem when user select the point of menu "Add to contacts". The change doesn't reflect to database.

Parameters:
modifiableItem  - Item that need to modify
fieldId  - Field of modifiableItem
newValue  - Value that will be added instead an old one

Definition at line 332 of file AddressBookAppUi.cpp.

Referenced by HandleCommandL().

00335         {
00336     TPbkContactItemField* Field =
00337         modifiableItem->FindField(fieldId);
00338     if( Field )
00339                 {
00340                 HBufC* pValAsUnicode = SenXmlUtils::ToUnicodeLC(newValue);
00341         if(pValAsUnicode)
00342                         {
00343                         Field->TextStorage()->SetTextL(*pValAsUnicode);
00344                         }
00345                 CleanupStack::PopAndDestroy(pValAsUnicode); 
00346                 }
00347         }

void CAddressBookAppUi::DynInitMenuPaneL (  TInt  aResourceId,
CEikMenuPane *  aMenuPane
)  [private]
 

From MEikMenuObserver, is called by EIKON framework just before it displays a menu pane, sets the state of menu items dynamically according to the state of application data.

Parameters:
aResourceId  specifies dialog-resource ID.
aMenuPane  specifies menu pane

Definition at line 83 of file AddressBookAppUi.cpp.

References CAddressBookEngine::Connected(), CAddressBookView::CurrentContact(), iAbout, iAppContainer, and iEngine.

00085     {
00086         if (aResourceId == R_ADDRESSBOOK_MENU)
00087                 {
00088                 TBool connected = iEngine->Connected();
00089                 TBool isContact(EFalse);
00090                 if ((iAppContainer->CurrentContact()) && (!iAbout))
00091                         isContact = ETrue;
00092 
00093                 aMenuPane->SetItemDimmed(EAddressBookCmdAppConnect, connected);
00094                 aMenuPane->SetItemDimmed(EAddressBookCmdAppSearch, !connected);
00095                 aMenuPane->SetItemDimmed(EAddressBookCmdAppAdd, !isContact);
00096                 aMenuPane->SetItemDimmed(EAddressBookCmdAppConnectAbout, iAbout);
00097                 }
00098         }

void CAddressBookAppUi::DialogDismissedL (  TInt  aButtonId  )  [private]
 

From MAknBackgroundProcess, is called by the active scheduler to dismiss the dialog

Parameters:
aButtonId  specifies button that was pressed

Definition at line 234 of file AddressBookAppUi.cpp.

References CAddressBookEngine::Cancel(), and iEngine.

00235         {
00236         if (aButtonId == EAknSoftkeyCancel)
00237                 {
00238                 iEngine->Cancel();
00239                 }
00240         }

TBool CAddressBookAppUi::IsProcessDone (   )  const [private]
 

From MAknBackgroundProcess, is called by the active scheduler to check if is process already done

Definition at line 248 of file AddressBookAppUi.cpp.

References iReady.

00249         {
00250         return iReady;
00251         }

void CAddressBookAppUi::ProcessFinished (   )  [private]
 

From MAknBackgroundProcess is called by the active scheduler to finish the process

Definition at line 259 of file AddressBookAppUi.cpp.

00260         {
00261         }

void CAddressBookAppUi::StepL (   )  [private]
 

From MAknBackgroundProcess, and is called by the active scheduler to do one step of processing Purpose this function in AddressBook to run AddressBookEngine::ConnectL() if connection is not established yet

Definition at line 271 of file AddressBookAppUi.cpp.

References CAddressBookEngine::ConnectL(), iConnecting, and iEngine.

00272         {
00273         if (!iConnecting)
00274                 {
00275                 iConnecting = ETrue;    // do this only once
00276                 iEngine->ConnectL();
00277                 }
00278         }

void CAddressBookAppUi::HandleCommandL (  TInt  aCommand  )  [private]
 

From CEikAppUi, takes care of command handling.

Parameters:
aCommand  command to be handled

Definition at line 116 of file AddressBookAppUi.cpp.

References CAddressBookView::ChangeCbaL(), CAddressBookView::CloseItem(), CAddressBookView::CurrentContact(), CAddressBookContact::Email(), CAddressBookContact::FaxL(), CAddressBookContact::FirstName(), iAbout, iAppContainer, iConnecting, iContactEngine, iEngine, iFirstTime, iReady, iWaitNote, CAddressBookContact::LastName(), CAddressBookContact::MobilePhoneL(), CAddressBookContact::Organization(), CAddressBookContact::PhoneL(), CAddressBookEngine::SendSearchL(), CAddressBookView::ShowAbout(), CAddressBookContact::Street(), CAddressBookContact::Title(), and UpdateFieldL().

00117     {
00118     switch ( aCommand )
00119         {
00120         case EAknSoftkeyBack:
00121                         iAppContainer->ChangeCbaL(R_AVKON_SOFTKEYS_OPTIONS_EXIT, EDrawNow);
00122                         iAppContainer->CloseItem();
00123                         iAbout = iAppContainer->ShowAbout(EFalse);
00124                         break;
00125         case EEikCmdExit:
00126                 case EAknSoftkeyExit:
00127             {
00128             Exit();
00129             break;
00130             }
00131                 case EAddressBookCmdAppConnect:
00132                         {
00133                         iReady = EFalse;
00134                         iConnecting = EFalse;
00135                 
00136                         // ---------------------------------------------------------------------
00137                         // ExecuteL(R_CONNECTING_NOTE, *this, ETrue) runs the active scheduler, 
00138                         // that calls CAknWaitNoteWrapper::RunL(),it checks 
00139                         //       1. if is process already done - then calls function IsProcessDone() 
00140                         //                  (it is overridden from interface MAknBackgroundProcess to AddressBookAppUi)
00141                         //       2. if process is not finished yet then RunL() calls StepL() that does one step of processing
00142                         //                      (it is overridden from interface MAknBackgroundProcess to AddressBookAppUi)
00143                         //                      This step establishes connection.
00144                         // After establishing of connection the active scheduler calls 
00145                         // function DialogDismissedL(TInt aButtonId) which is overriden 
00146                         // in AddressBookAppUi from interface MAknBackgroundProcess 
00147                         // ---------------------------------------------------------------------
00148                         //
00149                         iWaitNote->ExecuteL(R_CONNECTING_NOTE, *this, ETrue);
00150                         iAbout = iAppContainer->ShowAbout(EFalse);
00151                         break;
00152                         }
00153         case EAddressBookCmdAppSearch:
00154             {
00155             if (iFirstTime)
00156                                 {
00157                                 _LIT(KInfoLine, "How to Search? Use first name, last name or phone number as criteria for search.");
00158                                 CAknInformationNote* note = new (ELeave) CAknInformationNote(ETrue);
00159                                 note->ExecuteLD(KInfoLine);
00160                                 }
00161                         TBuf<50> searchFor;
00162                         CAknTextQueryDialog* dlg = new(ELeave)CAknTextQueryDialog(searchFor, CAknQueryDialog::ENoTone );
00163                         dlg->SetPredictiveTextInputPermitted(ETrue);
00164                         if (dlg->ExecuteLD( R_MY_DATA_QUERY_DIALOG ) )
00165                                 {
00166                                 iFirstTime = EFalse;
00167                                 iReady = EFalse;
00168                                 iEngine->SendSearchL(searchFor);
00169                                 
00170                                 // ---------------------------------------------------------------------
00171                                 // ExecuteL(R_SEARCHING_NOTE, *this) runs the active scheduler, 
00172                                 // that calls CSenServiceConnectionImpl::RunL() and it calls 
00173                                 // function HandleMessageL(const TDesC8& aMessage)
00174                                 // (it is overridden from interface MSenServiceConsumer to AddressBookAppUi)
00175                                 // for receiving messages from the SendL()(CSenServiceConnection)function
00176                                 // call
00177                                 // ---------------------------------------------------------------------
00178                                 //
00179                                 iWaitNote->ExecuteL(R_SEARCHING_NOTE, *this);
00180                                 iAppContainer->ChangeCbaL(R_AVKON_SOFTKEYS_OPTIONS_EXIT, EDrawNow);
00181                                 iAbout = iAppContainer->ShowAbout(EFalse);
00182                                 }
00183             break;
00184             }
00185                 case EAddressBookCmdAppConnectAbout:
00186                         iAbout = iAppContainer->ShowAbout();
00187                         iAppContainer->ChangeCbaL(R_AVKON_SOFTKEYS_OPTIONS_BACK, EDrawNow);
00188                         break;
00189                 case EAddressBookCmdAppAdd:
00190                         {
00191                         CAddressBookContact* pContact = iAppContainer->CurrentContact();
00192                         if (pContact)
00193                                 {
00194                                 CPbkContactItem* newItem = 
00195                                                                 iContactEngine->CreateEmptyContactL();
00196                                 CleanupStack::PushL(newItem);
00197                                 // Update personal information
00198                                 UpdateFieldL( newItem, EPbkFieldIdPhoneNumberMobile, 
00199                                         pContact->MobilePhoneL());
00200                                 UpdateFieldL( newItem, EPbkFieldIdPhoneNumberGeneral, 
00201                                         pContact->PhoneL());
00202                                 UpdateFieldL( newItem, EPbkFieldIdFirstName, 
00203                                         pContact->FirstName());
00204                                 UpdateFieldL( newItem, EPbkFieldIdLastName, 
00205                                         pContact->LastName());
00206                                 UpdateFieldL( newItem, EPbkFieldIdFaxNumber, 
00207                                         pContact->FaxL());
00208                                 UpdateFieldL( newItem, EPbkFieldIdEmailAddress, 
00209                                         pContact->Email());
00210                                 UpdateFieldL( newItem, EPbkFieldIdJobTitle, 
00211                                         pContact->Title());
00212                                 UpdateFieldL( newItem, EPbkFieldIdCompanyName, 
00213                                         pContact->Organization());
00214                                 UpdateFieldL( newItem, EPbkFieldIdPostalAddress, 
00215                                         pContact->Street());
00216 
00217                                 // add the new contact to the phone book. 
00218                                 iContactEngine->AddNewContactL(*newItem);
00219                                 CleanupStack::PopAndDestroy(newItem);
00220                                 }
00221                         }
00222                         break;
00223         default:
00224             break;
00225         }
00226   }

TKeyResponse CAddressBookAppUi::HandleKeyEventL (  const TKeyEvent &  aKeyEvent,
TEventCode  aType
)  [private, virtual]
 

From CEikAppUi, handles key events.

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

Definition at line 105 of file AddressBookAppUi.cpp.

00107     {
00108         return EKeyWasNotConsumed;
00109     }


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

© Nokia 2009

Back to top