|
1 /* |
|
2 * Copyright (c) 2002-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: A find operation that loops the contact data |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CFindOperation.h" |
|
22 |
|
23 #include "CVPbkSimContact.h" |
|
24 #include "CVPbkSimCntField.h" |
|
25 #include "CStoreBase.h" |
|
26 #include "CContactArray.h" |
|
27 #include "MVPbkSimFindObserver.h" |
|
28 #include <CVPbkContactFindPolicy.h> |
|
29 |
|
30 |
|
31 namespace VPbkSimStoreImpl { |
|
32 |
|
33 // CONSTANTS |
|
34 /// The amount of contacts to loop through in on cycle |
|
35 const TInt KContactsToCheckInOneCycle = 50; |
|
36 |
|
37 // ============================ MEMBER FUNCTIONS =============================== |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CFindOperation::CFindOperation |
|
41 // C++ default constructor can NOT contain any code, that |
|
42 // might leave. |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 CFindOperation::CFindOperation( MVPbkSimFindObserver& aObserver, |
|
46 CStoreBase& aStore ) |
|
47 : CActive( EPriorityStandard ), |
|
48 iObserver( aObserver ), |
|
49 iStore( aStore ) |
|
50 { |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CFindOperation::ConstructL |
|
55 // Symbian 2nd phase constructor can leave. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 void CFindOperation::ConstructL( const TDesC& aStringToFind, |
|
59 RVPbkSimFieldTypeArray& aFieldTypes ) |
|
60 { |
|
61 CActiveScheduler::Add( this ); |
|
62 iStringToFind = aStringToFind.AllocL(); |
|
63 const TInt count = aFieldTypes.Count(); |
|
64 for ( TInt i = 0; i < count; ++i ) |
|
65 { |
|
66 iFieldTypes.AppendL( aFieldTypes[i] ); |
|
67 } |
|
68 |
|
69 // Create a find policy object via ECom |
|
70 iFindPolicy = CVPbkContactFindPolicy::NewL(); |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CFindOperation::NewL |
|
75 // Two-phased constructor. |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 CFindOperation* CFindOperation::NewL( MVPbkSimFindObserver& aObserver, |
|
79 CStoreBase& aStore, const TDesC& aStringToFind, |
|
80 RVPbkSimFieldTypeArray& aFieldTypes ) |
|
81 { |
|
82 CFindOperation* self = new( ELeave ) CFindOperation( aObserver, aStore ); |
|
83 CleanupStack::PushL( self ); |
|
84 self->ConstructL( aStringToFind, aFieldTypes ); |
|
85 CleanupStack::Pop( self ); |
|
86 return self; |
|
87 } |
|
88 |
|
89 // Destructor |
|
90 CFindOperation::~CFindOperation() |
|
91 { |
|
92 Cancel(); |
|
93 delete iFindPolicy; |
|
94 delete iStringToFind; |
|
95 iFieldTypes.Close(); |
|
96 iResults.Close(); |
|
97 // Find policy is loaded as ECOM plug-in so clean ECOM server |
|
98 REComSession::FinalClose(); |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CFindOperation::Execute |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 void CFindOperation::Execute() |
|
106 { |
|
107 // Start from the first sim index |
|
108 iNextSimIndex = 1; |
|
109 iResults.Reset(); |
|
110 NextCycle(); |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CFindOperation::RunL |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 void CFindOperation::RunL() |
|
118 { |
|
119 TInt lastIndex = iNextSimIndex + KContactsToCheckInOneCycle; |
|
120 TInt cntArraySize = iStore.Contacts().Size(); |
|
121 if ( lastIndex > cntArraySize ) |
|
122 { |
|
123 lastIndex = cntArraySize; |
|
124 } |
|
125 |
|
126 while ( iNextSimIndex <= lastIndex ) |
|
127 { |
|
128 MVPbkSimContact* cnt = iStore.Contacts().At( iNextSimIndex ); |
|
129 if ( cnt && IsMatch( *cnt ) ) |
|
130 { |
|
131 iResults.AppendIntL( cnt->SimIndex() ); |
|
132 } |
|
133 ++iNextSimIndex; |
|
134 } |
|
135 |
|
136 if ( iNextSimIndex > lastIndex ) |
|
137 { |
|
138 iObserver.FindCompleted( iStore, iResults ); |
|
139 } |
|
140 else |
|
141 { |
|
142 NextCycle(); |
|
143 } |
|
144 } |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 // CFindOperation::DoCancel |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 void CFindOperation::DoCancel() |
|
151 { |
|
152 // Nothing to cancel here |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // CFindOperation::RunError |
|
157 // ----------------------------------------------------------------------------- |
|
158 // |
|
159 TInt CFindOperation::RunError( TInt aError ) |
|
160 { |
|
161 iObserver.FindError( iStore, aError ); |
|
162 return KErrNone; |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CFindOperation::NextCycle |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 void CFindOperation::NextCycle() |
|
170 { |
|
171 TRequestStatus* status = &iStatus; |
|
172 User::RequestComplete( status, KErrNone ); |
|
173 SetActive(); |
|
174 } |
|
175 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // CFindOperation::IsMatch |
|
178 // ----------------------------------------------------------------------------- |
|
179 // |
|
180 TBool CFindOperation::IsMatch( MVPbkSimContact& aContact ) |
|
181 { |
|
182 const TInt count = iFieldTypes.Count(); |
|
183 for ( TInt i = 0; i < count; ++i ) |
|
184 { |
|
185 MVPbkSimContact::TFieldLookup lookup = |
|
186 aContact.FindField( iFieldTypes[i] ); |
|
187 while ( !lookup.EndOfLookup() ) |
|
188 { |
|
189 if ( IsMatch( aContact.ConstFieldAt( lookup.Index() ).Data() ) ) |
|
190 { |
|
191 return ETrue; |
|
192 } |
|
193 aContact.FindNextField( lookup ); |
|
194 } |
|
195 } |
|
196 return EFalse; |
|
197 } |
|
198 |
|
199 // ----------------------------------------------------------------------------- |
|
200 // CFindOperation::IsMatch |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 TBool CFindOperation::IsMatch( const TDesC& aString ) |
|
204 { |
|
205 // uses virtual phonebook find policy for finding |
|
206 TBool ret = EFalse; |
|
207 |
|
208 // ignore find errors and return a false match |
|
209 TRAP_IGNORE( |
|
210 ret = iFindPolicy->MatchRefineL(aString, *iStringToFind)); |
|
211 return ret; |
|
212 } |
|
213 |
|
214 } // namespace VPbkSimStoreImpl |
|
215 |
|
216 // End of File |