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 CContactRead::CContactRead()
00034 : iCallback(&CContactRead:: ParseWord)
00035 {
00036 }
00037
00038 void CContactRead::ConstructL()
00039 {
00040 TRAPD(error, iCntDb = CContactDatabase::OpenL());
00041 if (KErrNotFound == error)
00042 {
00043 iCntDb = CContactDatabase::CreateL();
00044 }
00045 else
00046 {
00047 User::LeaveIfError(error);
00048 }
00049 }
00050
00051 CContactDatabase& CContactRead::CntDatabase()
00052 {
00053 return *iCntDb;
00054 }
00055
00056 CContactIdArray* CContactRead::FindWithCallbackL(TFieldType aField, const TDesC& aMatch)
00057 {
00058 TContactTextDefItem field(aField);
00059 CContactTextDef* textDef = CContactTextDef::NewL();
00060 CleanupStack::PushL(textDef);
00061 textDef->AppendL(field);
00062
00063 CDesCArray* match = new (ELeave) CDesCArrayFlat(1);
00064 CleanupStack::PushL(match);
00065 match->AppendL(aMatch);
00066
00067 CContactIdArray* result = iCntDb->FindInTextDefLC(*match, textDef, iCallback);
00068 CleanupStack::Pop(result);
00069 CleanupStack::PopAndDestroy(match);
00070 CleanupStack::PopAndDestroy(textDef);
00071 return result;
00072 }
00073
00074
00075
00076
00077
00078
00079
00080 TInt CContactRead::ParseWord(TAny* aParam)
00081 {
00082 SFindInTextDefWordParser* parserStruct = (SFindInTextDefWordParser*)aParam;
00083 TPtrC searchString(*(parserStruct->iSearchString));
00084 TInt index = KErrNotFound;
00085 TInt error = KErrNone;
00086 while(0 <= (index = searchString.Locate(' ')))
00087 {
00088 if (index > 0)
00089 {
00090 TRAP(error, parserStruct->iWordArray->AppendL(searchString.Left(index)));
00091 if (error != KErrNone)
00092 return error;
00093 if (searchString.Length() > index + 1)
00094 {
00095 searchString.Set(searchString.Mid(index +1));
00096 }
00097 else
00098 {
00099 searchString.Set(KNullDesC());
00100 break;
00101 }
00102 }
00103 else
00104 {
00105
00106 searchString.Set(searchString.Mid(1));
00107 }
00108 }
00109 if(searchString.Length() > 0)
00110 {
00111 TRAP(error, parserStruct->iWordArray->AppendL(searchString));
00112 if (error != KErrNone)
00113 return error;
00114 }
00115 return KErrNone;
00116 }
00117
00118
00119
00120