00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
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
00043
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