S60 3rd Edition SDK for Symbian OS
Example Applications Guide

CAddressBookAppUi Class Reference

#include <AddressBookAppUi.h>

Inheritance diagram for CAddressBookAppUi:

MAddressBookEngineObserver List of all members.

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

Detailed Description

Application UI class. Provides support for the following features:

Definition at line 43 of file AddressBookAppUi.h.


Constructor & Destructor Documentation

CAddressBookAppUi::~CAddressBookAppUi (   ) 
 

Destructor.

Definition at line 63 of file AddressBookAppUi.cpp.

References iAppContainer, iContactEngine, iEngine, and iWaitNote.

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


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 282 of file AddressBookAppUi.cpp.

References iReady.

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

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 315 of file AddressBookAppUi.cpp.

References iReady.

00316         {
00317         iReady = ETrue;
00318         }

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 351 of file AddressBookAppUi.cpp.

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

00352         {
00353         iAppContainer->UpdateL(aContactArray);
00354         iReady = ETrue;
00355         }

void CAddressBookAppUi::ConstructL (   )  [private]
 

By default Symbian 2nd phase constructor is private.

Definition at line 41 of file AddressBookAppUi.cpp.

References CAddressBookView::ConstructL(), 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 
00049         iEngine = CAddressBookEngine::NewL(*this);
00050     iAppContainer = new (ELeave) CAddressBookView(*iEngine);
00051     iAppContainer->SetMopParent( this );
00052     iAppContainer->ConstructL( ClientRect() );
00053     AddToStackL( iAppContainer );
00054     iContactEngine = CPbkContactEngine::NewL(NULL);
00055     }

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 328 of file AddressBookAppUi.cpp.

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

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 82 of file AddressBookAppUi.cpp.

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

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

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 230 of file AddressBookAppUi.cpp.

References CAddressBookEngine::Cancel(), and iEngine.

00231         {
00232         if (aButtonId == EAknSoftkeyCancel)
00233                 {
00234                 iEngine->Cancel();
00235                 }
00236         }

TBool CAddressBookAppUi::IsProcessDone (   )  const [private]
 

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

Definition at line 244 of file AddressBookAppUi.cpp.

References iReady.

00245         {
00246         return iReady;
00247         }

void CAddressBookAppUi::ProcessFinished (   )  [private]
 

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

Definition at line 255 of file AddressBookAppUi.cpp.

00256         {
00257         }

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 267 of file AddressBookAppUi.cpp.

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

00268         {
00269         if (!iConnecting)
00270                 {
00271                 iConnecting = ETrue;    // do this only once
00272                 iEngine->ConnectL();
00273                 }
00274         }

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

From CEikAppUi, takes care of command handling.

Parameters:
aCommand command to be handled

Definition at line 114 of file AddressBookAppUi.cpp.

References CAddressBookView::ChangeCbaL(), CAddressBookView::CloseItem(), CAddressBookView::CurrentContact(), CAddressBookContact::Email(), CAddressBookContact::FaxL(), CAddressBookContact::FirstName(), 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().

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

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 103 of file AddressBookAppUi.cpp.

00105     {
00106         return EKeyWasNotConsumed;
00107     }


© Nokia 2006

Back to top