|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : AddressBookAppUi.cpp 00004 * Part of : AddressBook 00005 * Interface : 00006 * Description : Application UI class, CAddressBookAppUi - 00007 * responsible for handling user commands 00008 * Version : 00009 * 00010 * Copyright (c) 2002-2006 Nokia Corporation. 00011 * This material, including documentation and any related 00012 * computer programs, is protected by copyright controlled by 00013 * Nokia Corporation. 00014 * ============================================================================== 00015 */ 00016 00017 // INCLUDES 00018 #include "AddressBookAppUi.h" 00019 #include "AddressBookView.h" 00020 #include <AddressBook.rsg> 00021 #include "AddressBook.hrh" 00022 #include "AddressBookEngine.h" 00023 #include "AddressBookContact.h" 00024 00025 #include <SenXmlUtils.h> 00026 00027 #include <cpbkfieldinfo.h> 00028 #include <cpbkfieldsinfo.h> 00029 00030 #include <avkon.hrh> 00031 #include <eikmenup.h> 00032 #include <aknnotewrappers.h> 00033 #include <aknquerydialog.h> 00034 00035 // ================= MEMBER FUNCTIONS ======================= 00036 00037 // ---------------------------------------------------------------------------- 00038 // CAddressBookAppUi::ConstructL() 00039 // ---------------------------------------------------------------------------- 00040 // 00041 void CAddressBookAppUi::ConstructL() 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 } 00056 00057 // ---------------------------------------------------------------------------- 00058 // CAddressBookAppUi::~CAddressBookAppUi() 00059 // Destructor 00060 // Frees reserved resources 00061 // ---------------------------------------------------------------------------- 00062 // 00063 CAddressBookAppUi::~CAddressBookAppUi() 00064 { 00065 if (iAppContainer) 00066 { 00067 RemoveFromStack( iAppContainer ); 00068 delete iAppContainer; 00069 } 00070 delete iEngine; 00071 delete iContactEngine; 00072 delete iWaitNote; 00073 } 00074 00075 // ---------------------------------------------------------------------------- 00076 // CAddressBookAppUi::DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane) 00077 // This function is called by the EIKON framework just before it displays 00078 // a menu pane. Sets the state of menu items dynamically according 00079 // to the state of application data. 00080 // ---------------------------------------------------------------------------- 00081 // 00082 void CAddressBookAppUi::DynInitMenuPaneL( 00083 TInt aResourceId, CEikMenuPane* aMenuPane) 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 } 00097 00098 // ---------------------------------------------------------------------------- 00099 // CAddressBookAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent,TEventCode) 00100 // takes care of key event handling 00101 // ---------------------------------------------------------------------------- 00102 // 00103 TKeyResponse CAddressBookAppUi::HandleKeyEventL( 00104 const TKeyEvent&,TEventCode) 00105 { 00106 return EKeyWasNotConsumed; 00107 } 00108 00109 // ---------------------------------------------------------------------------- 00110 // CAddressBookAppUi::HandleCommandL(TInt aCommand) 00111 // takes care of command handling 00112 // ---------------------------------------------------------------------------- 00113 // 00114 void CAddressBookAppUi::HandleCommandL(TInt aCommand) 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 } 00223 00224 // ---------------------------------------------------------------------------- 00225 // CAddressBookAppUi::DialogDismissedL(TInt aButtonId) 00226 // It is overridden function from interface MAknBackgroundProcess 00227 // and is called by the active scheduler to dismiss the dialog 00228 // ---------------------------------------------------------------------------- 00229 // 00230 void CAddressBookAppUi::DialogDismissedL(TInt aButtonId) 00231 { 00232 if (aButtonId == EAknSoftkeyCancel) 00233 { 00234 iEngine->Cancel(); 00235 } 00236 } 00237 00238 // ---------------------------------------------------------------------------- 00239 // CAddressBookAppUi::IsProcessDone() const 00240 // It is overridden function from interface MAknBackgroundProcess 00241 // and is called by the active scheduler to check if is process already done 00242 // ---------------------------------------------------------------------------- 00243 // 00244 TBool CAddressBookAppUi::IsProcessDone() const 00245 { 00246 return iReady; 00247 } 00248 00249 // ---------------------------------------------------------------------------- 00250 // CAddressBookAppUi::ProcessFinished() 00251 // It is overridden function from interface MAknBackgroundProcess 00252 // and is called by the active scheduler to finish the process 00253 // ---------------------------------------------------------------------------- 00254 // 00255 void CAddressBookAppUi::ProcessFinished() 00256 { 00257 } 00258 00259 // ---------------------------------------------------------------------------- 00260 // CAddressBookAppUi::StepL() 00261 // It is overridden function from interface MAknBackgroundProcess 00262 // and is called by the active scheduler to do one step of processing 00263 // Purpose this function in AddressBook to run AddressBookEngine::ConnectL() 00264 // if connection is not established yet 00265 // ---------------------------------------------------------------------------- 00266 // 00267 void CAddressBookAppUi::StepL() 00268 { 00269 if (!iConnecting) 00270 { 00271 iConnecting = ETrue; // do this only once 00272 iEngine->ConnectL(); 00273 } 00274 } 00275 00276 // ---------------------------------------------------------------------------- 00277 // CAddressBookAppUi::ErrorL(TInt aCode) 00278 // It is overridden function from interface MAddressBookEngineObserver 00279 // Checks errors that can happen 00280 // ---------------------------------------------------------------------------- 00281 // 00282 void CAddressBookAppUi::ErrorL(TInt aCode) 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 } 00307 00308 // ---------------------------------------------------------------------------- 00309 // CAddressBookAppUi::ConnectionReady() 00310 // It is overridden function from interface MAddressBookEngineObserver 00311 // It is called by the CAddressBookEngine::SetStatus(const TInt aStatus) 00312 // to set conection's status as ready 00313 // ---------------------------------------------------------------------------- 00314 // 00315 void CAddressBookAppUi::ConnectionReady() 00316 { 00317 iReady = ETrue; 00318 } 00319 00320 // ---------------------------------------------------------------------------- 00321 // CAddressBookAppUi::UpdateFieldL (CPbkContactItem* modifiableItem, 00322 // TPbkFieldId fieldId, 00323 // const TDesC8& newValue) 00324 // Updates field of CPbkContactItem when user select the point of menu "Add to contacts". 00325 // The change doesn't reflect to database. 00326 // ---------------------------------------------------------------------------- 00327 // 00328 void CAddressBookAppUi::UpdateFieldL(CPbkContactItem* modifiableItem, 00329 TPbkFieldId fieldId, 00330 const TDesC8& newValue) 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 } 00344 00345 // ---------------------------------------------------------------------------- 00346 // CAddressBookAppUi::SearchFinishedL(RPointerArray<CAddressBookContact>& aContactArray) 00347 // It is overridden function from MAddressBookEngineObserver interface 00348 // Updates bufer containing the contact information and sets status as READY 00349 // ---------------------------------------------------------------------------- 00350 // 00351 void CAddressBookAppUi::SearchFinishedL(RPointerArray<CAddressBookContact>& aContactArray) 00352 { 00353 iAppContainer->UpdateL(aContactArray); 00354 iReady = ETrue; 00355 } 00356 00357 // End of File 00358
|
© Nokia 2006 |