00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "ContactRead.h"
00018
00019 CContactRead* CContactRead::NewL()
00020 {
00021 CContactRead* self = new (ELeave) CContactRead();
00022 CleanupStack::PushL(self);
00023 self->ConstructL();
00024 CleanupStack::Pop(self);
00025 return self;
00026 }
00027
00028 CContactRead::~CContactRead()
00029 {
00030 delete iCntDb;
00031 }
00032
00033 void CContactRead::ConstructL()
00034 {
00035 TRAPD(error, iCntDb = CContactDatabase::OpenL());
00036 if (KErrNotFound == error)
00037 {
00038 iCntDb = CContactDatabase::CreateL();
00039 }
00040 else
00041 {
00042 User::LeaveIfError(error);
00043 }
00044 }
00045
00046 CContactDatabase& CContactRead::CntDatabase()
00047 {
00048 return *iCntDb;
00049 }
00050
00051 CContactIdArray* CContactRead::SortByNameL()
00052 {
00053 CArrayFix<CContactDatabase::TSortPref>* sortOrder =
00054 new (ELeave) CArrayFixSeg<CContactDatabase::TSortPref>(2);
00055 CleanupStack::PushL(sortOrder);
00056 CContactDatabase::TSortPref lastNameSort(KUidContactFieldFamilyName);
00057 CContactDatabase::TSortPref firstNameSort(KUidContactFieldGivenName);
00058 sortOrder->AppendL(lastNameSort);
00059 sortOrder->AppendL(firstNameSort);
00060 iCntDb->SortL(sortOrder);
00061 CleanupStack::Pop(sortOrder);
00062 return CContactIdArray::NewL(iCntDb->SortedItemsL());
00063 }
00064
00065 CDesCArray* CContactRead::ReadTextFieldL(TContactItemId aCntId, TFieldType aType)
00066 {
00067 CDesCArray* result = new (ELeave) CDesCArrayFlat(2);
00068 CleanupStack::PushL(result);
00069 CContactItemViewDef* viewDef = CContactItemViewDef::NewLC(
00070 CContactItemViewDef::EIncludeFields,
00071 CContactItemViewDef::EMaskHiddenFields);
00072 viewDef->AddL(aType);
00073 CContactItem* item = iCntDb->ReadContactLC(aCntId, *viewDef);
00074 CContactItemFieldSet& fieldSet = item->CardFields();
00075
00076 for(TInt ii = 0 ; ii < fieldSet.Count() ; ++ii)
00077 {
00078 CContactItemField& field = fieldSet[ii];
00079 if (KStorageTypeText == field.StorageType())
00080 {
00081 if (field.TextStorage()->IsFull())
00082 {
00083 const TPtrC value = field.TextStorage()->Text();
00084 result->AppendL(value);
00085 }
00086 }
00087 }
00088
00089 CleanupStack::PopAndDestroy(item);
00090 CleanupStack::PopAndDestroy(viewDef);
00091 CleanupStack::Pop(result);
00092 return result;
00093 }
00094
00095