examples/SFExamples/PIM/ContactAsynchSort/src/SortWrapper.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 "SortWrapper.h"
00018 
00019 CSortWrapper::CSortWrapper(CContactAsynchSortMainView& aView, CContactDatabase& aDb)
00020                 : CActive(0), iView(aView), iDb(aDb)
00021         {
00022         CActiveScheduler::Add(this);
00023         }
00024 
00025 void CSortWrapper::StartL(CContactRead& aReader)
00026         {
00027         iContactReader = &aReader;
00028         aReader.SortByNameL(iStatus);
00029         SetActive();
00030         }
00031 
00032 void CSortWrapper::RunL()
00033         {
00034         // report result on the Label control
00035         if (KErrNone == iStatus.Int())
00036                 {
00037                 CContactIdArray* result = CContactIdArray::NewLC(iDb.SortedItemsL());
00038                 TBuf<256> textBuf;
00039                 _LIT(KPrefix, "success :");
00040                 textBuf.Append(KPrefix());
00041                 _LIT(KNoName, "NoName");
00042                 // \PIM\PopulateContact should have created at least 3 cards
00043                 // with both first names and last names.
00044                 for (TInt ii = 0; ii < result->Count() && ii < 3; ++ii)
00045                         {
00046                         CDesCArray* last = iContactReader->ReadTextFieldL((*result)[ii], KUidContactFieldFamilyName);
00047                         CleanupStack::PushL(last);
00048                         CDesCArray* first = iContactReader->ReadTextFieldL((*result)[ii], KUidContactFieldGivenName);
00049                         if (last->Count() > 0)
00050                                 textBuf.Append(last->MdcaPoint(0));
00051                         else
00052                                 textBuf.Append(KNoName());
00053                         if (first->Count() > 0)
00054                                 textBuf.Append(first->MdcaPoint(0));
00055                         else
00056                                 textBuf.Append(KNoName());
00057                         delete first;
00058                         CleanupStack::PopAndDestroy(last);
00059                         }
00060                 CleanupStack::PopAndDestroy(result);
00061                 iView.SetTextL(textBuf);
00062                 }
00063         else
00064                 {
00065                 _LIT(KErrorMsg, "Symbian Error Code = %D");
00066                 TBuf<32> errorBuf;
00067                 errorBuf.Format(KErrorMsg(), iStatus.Int());
00068                 iView.SetTextL(errorBuf);
00069                 }
00070         }
00071 
00072 TInt CSortWrapper::RunError(TInt aError)
00073         {
00074         _LIT(KErrorMsg2, "Symbian Error Code = %D");
00075         TBuf<32> errorBuf;
00076         errorBuf.Format(KErrorMsg2(), aError);
00077         TRAPD(error, iView.SetTextL(errorBuf));
00078         return error;
00079         }
00080 
00081 
00082 void CSortWrapper::DoCancel()
00083         {
00084         iDb.CancelAsyncSort();
00085         }
00086 

Generated by  doxygen 1.6.2