examples/SFExamples/PIM/ContactAsynchFind/src/ContactAsynchFindAppUi.cpp

00001 // 
00002 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
00003 // All rights reserved.
00004 // This component and the accompanying materials are made available
00005 // under the terms of the License "Eclipse Public License v1.0"
00006 // which accompanies this distribution, and is available
00007 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00008 // 
00009 // Initial Contributors:
00010 // Nokia Corporation - initial contribution.
00011 // 
00012 // Contributors:
00013 // 
00014 // Description:
00015 // 
00016 
00017 #include <eikapp.h>
00018 #include <ContactAsynchFind.rsg>
00019 
00020 #include "ContactAsynchFindAppUi.h"
00021 #include "ContactAsynchFindMainView.h"
00022 #include "ContactRead.h"
00023 #include "ContactAsynchFind.hrh"
00024 
00025 void CContactAsynchFindAppUi::ConstructL()
00026         {
00027 
00028         BaseConstructL(EAknEnableSkin);
00029         iMainView = CContactAsynchFindMainView::NewL(ClientRect());
00030 
00031 
00032         iContactReader = CContactRead::NewL();
00033         }
00034         
00035 CContactAsynchFindAppUi::~CContactAsynchFindAppUi()
00036     {
00037         delete iFindWrapper;
00038     delete iContactReader;
00039         delete iMainView;
00040     }
00041 
00042 void CContactAsynchFindAppUi::HandleCommandL(TInt aCommand)
00043         {
00044         switch ( aCommand )
00045                 {
00046                 case EAknSoftkeyExit:
00047                 case EEikCmdExit:
00048                         {
00049                         Exit();
00050                         break;
00051                         }
00052                 case EContactAsynchFind:
00053                         {
00054                         // \PIM\PopulateContact should have created at a card with the
00055                         // name set to "Partner"
00056                         _LIT(KStringMatch, "Partner");
00057                         TFieldType type = KUidContactFieldGivenName;
00058                         iFindWrapper = iContactReader->FindWithCallbackL(type, KStringMatch, this);
00059                         break;
00060                         }
00061                 default:
00062                         break;
00063                 }
00064         }
00065 
00066 
00067 void CContactAsynchFindAppUi::IdleFindCallback()
00068         {
00069         if (iFindWrapper->IsComplete())
00070                 {
00071                 TInt error = iFindWrapper->Error();
00072                 if (KErrNone ==  error)
00073                         {
00074                         CContactIdArray* result = iFindWrapper->TakeContactIds();
00075                         TBuf<64> textBuf;
00076                         _LIT(KPrefix, "success :");
00077                         _LIT(KCardId, " %D");
00078                         textBuf.Append(KPrefix());
00079                         for (TInt ii = 0; ii < result->Count() && ii < 3; ++ii)
00080                                 {
00081                                 textBuf.AppendFormat(KCardId(), (*result)[ii]);
00082                                 }
00083                         delete result;
00084                         delete iFindWrapper;
00085                         iFindWrapper = NULL; // prevents double deletion !!!!!!
00086                         TRAP(error, iMainView->SetTextL(textBuf));
00087                         }
00088                 if (KErrNone !=  error)
00089                         {
00090                         _LIT(KErrorMsg, "Symbian Error Code = %D");
00091                         TBuf<32> errorBuf;
00092                         errorBuf.Format(KErrorMsg(), error);
00093                         iMainView->SetTextL(errorBuf);
00094                         }
00095                 }
00096         // otherwise, keep going. maybe indicate progress on GUI.
00097         }
00098 
00099 
00100         
00101 
00102 void CContactAsynchFindAppUi::HandleResourceChangeL(TInt aType)
00103         {
00104         CAknAppUi::HandleResourceChangeL(aType);
00105         iMainView->SetRect(ClientRect());
00106         }
00107 
00108         
00109 // End of File

Generated by  doxygen 1.6.2