|
1 /* |
|
2 * Copyright (c) 2005-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: Contact model store Voice tag attribute operation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "csindvoicetagattributelistoperation.h" |
|
20 #include "ccontactstore.h" |
|
21 #include "ccontactlink.h" |
|
22 |
|
23 #include <cvpbkcontactlinkarray.h> |
|
24 #include <mvpbkcontactfindobserver.h> |
|
25 |
|
26 // System includes |
|
27 #include <vuivoicerecogdefs.h> // KVoiceDialContext |
|
28 // From Contacts Model |
|
29 #include <cntitem.h> |
|
30 |
|
31 namespace VPbkCntModel { |
|
32 |
|
33 namespace { |
|
34 |
|
35 #ifdef _DEBUG |
|
36 enum TPanicCode |
|
37 { |
|
38 EPreCond_GetContextCompleted |
|
39 }; |
|
40 |
|
41 void Panic( TPanicCode aPanicCode ) |
|
42 { |
|
43 _LIT(KPanicText, "CSindVoiceTagAttributeListOperation"); |
|
44 User::Panic(KPanicText, aPanicCode); |
|
45 }; |
|
46 #endif // _DEBUG |
|
47 |
|
48 } // unnamed namespace |
|
49 |
|
50 // -------------------------------------------------------------------------- |
|
51 // CSindVoiceTagAttributeListOperation::CSindVoiceTagAttributeListOperation |
|
52 // -------------------------------------------------------------------------- |
|
53 // |
|
54 CSindVoiceTagAttributeListOperation::CSindVoiceTagAttributeListOperation( |
|
55 CContactStore& aContactStore, |
|
56 MNssContextMgr& aNssContextManager, |
|
57 MNssTagMgr& aNssTagManager, |
|
58 MVPbkContactFindObserver& aObserver) : |
|
59 iContactStore( aContactStore ), |
|
60 iNssContextManager( aNssContextManager ), |
|
61 iNssTagManager( aNssTagManager ), |
|
62 iFindObserver( aObserver ), |
|
63 iContactIterator( aContactStore.NativeDatabase() ) |
|
64 { |
|
65 } |
|
66 |
|
67 // -------------------------------------------------------------------------- |
|
68 // CSindVoiceTagAttributeListOperation::ConstructL |
|
69 // -------------------------------------------------------------------------- |
|
70 // |
|
71 void CSindVoiceTagAttributeListOperation::ConstructL() |
|
72 { |
|
73 iContactLinks = CVPbkContactLinkArray::NewL(); |
|
74 } |
|
75 |
|
76 // -------------------------------------------------------------------------- |
|
77 // CSindVoiceTagAttributeListOperation::NewListLC |
|
78 // -------------------------------------------------------------------------- |
|
79 // |
|
80 CSindVoiceTagAttributeListOperation* CSindVoiceTagAttributeListOperation::NewListLC( |
|
81 CContactStore& aContactStore, |
|
82 MNssContextMgr& aNssContextManager, |
|
83 MNssTagMgr& aNssTagManager, |
|
84 MVPbkContactFindObserver& aObserver) |
|
85 { |
|
86 CSindVoiceTagAttributeListOperation* self = |
|
87 new(ELeave) CSindVoiceTagAttributeListOperation( aContactStore, |
|
88 aNssContextManager, aNssTagManager, aObserver); |
|
89 CleanupStack::PushL(self); |
|
90 self->ConstructL(); |
|
91 return self; |
|
92 } |
|
93 |
|
94 // -------------------------------------------------------------------------- |
|
95 // CSindVoiceTagAttributeListOperation::~CSindVoiceTagAttributeListOperation |
|
96 // -------------------------------------------------------------------------- |
|
97 // |
|
98 CSindVoiceTagAttributeListOperation::~CSindVoiceTagAttributeListOperation() |
|
99 { |
|
100 delete iContactLinks; |
|
101 delete iNssContext; |
|
102 } |
|
103 |
|
104 // -------------------------------------------------------------------------- |
|
105 // CSindVoiceTagAttributeListOperation::StartL |
|
106 // -------------------------------------------------------------------------- |
|
107 // |
|
108 void CSindVoiceTagAttributeListOperation::StartL() |
|
109 { |
|
110 // Get first the voice tag context asynchronously. |
|
111 // See GetContextCompleted. |
|
112 TInt res = iNssContextManager.GetContext( this, KVoiceDialContext ); |
|
113 if ( res != TNssVasCoreConstant::EVasSuccess ) |
|
114 { |
|
115 // NSS error codes can positive. We must use system wide error |
|
116 // codes. |
|
117 if ( res >= 0 ) |
|
118 { |
|
119 res = KErrUnknown; |
|
120 } |
|
121 User::Leave( res ); |
|
122 } |
|
123 } |
|
124 |
|
125 // -------------------------------------------------------------------------- |
|
126 // CSindVoiceTagAttributeListOperation::Cancel |
|
127 // -------------------------------------------------------------------------- |
|
128 // |
|
129 void CSindVoiceTagAttributeListOperation::Cancel() |
|
130 { |
|
131 // CancelGetContext not yet available |
|
132 } |
|
133 |
|
134 // -------------------------------------------------------------------------- |
|
135 // CSindVoiceTagAttributeListOperation::GetContextCompleted |
|
136 // -------------------------------------------------------------------------- |
|
137 // |
|
138 void CSindVoiceTagAttributeListOperation::GetContextCompleted( |
|
139 MNssContext* aContext ) |
|
140 { |
|
141 __ASSERT_DEBUG( !iNssContext, Panic( EPreCond_GetContextCompleted )); |
|
142 delete iNssContext; |
|
143 iNssContext = aContext; |
|
144 |
|
145 // Context received. Voice tags can be checked now. |
|
146 TRAPD( res, GetNextTagL() ); |
|
147 if ( res != KErrNone ) |
|
148 { |
|
149 iFindObserver.FindFailed( res ); |
|
150 } |
|
151 } |
|
152 |
|
153 // -------------------------------------------------------------------------- |
|
154 // CSindVoiceTagAttributeListOperation::GetContextListCompleted |
|
155 // -------------------------------------------------------------------------- |
|
156 // |
|
157 void CSindVoiceTagAttributeListOperation::GetContextListCompleted( |
|
158 MNssContextListArray* /*aContextList*/ ) |
|
159 { |
|
160 // Not used by this operation |
|
161 } |
|
162 |
|
163 // -------------------------------------------------------------------------- |
|
164 // CSindVoiceTagAttributeListOperation::GetContextFailed |
|
165 // -------------------------------------------------------------------------- |
|
166 // |
|
167 void CSindVoiceTagAttributeListOperation::GetContextFailed( |
|
168 TNssGetContextClientFailCode aFailCode ) |
|
169 { |
|
170 TInt res = KErrUnknown; |
|
171 |
|
172 switch ( aFailCode ) |
|
173 { |
|
174 case MNssGetContextClient::EVASDBItemNotFound: |
|
175 { |
|
176 res = KErrNotFound; |
|
177 break; |
|
178 } |
|
179 case MNssGetContextClient::EVASDBNoMemory: |
|
180 { |
|
181 res = KErrNoMemory; |
|
182 break; |
|
183 } |
|
184 case MNssGetContextClient::EVASDBDiskFull: |
|
185 { |
|
186 res = KErrDiskFull; |
|
187 break; |
|
188 } |
|
189 default: |
|
190 { |
|
191 // Do nothing |
|
192 break; |
|
193 } |
|
194 } |
|
195 |
|
196 iFindObserver.FindFailed( res ); |
|
197 } |
|
198 |
|
199 // -------------------------------------------------------------------------- |
|
200 // CSindVoiceTagAttributeListOperation::GetTagListCompleted |
|
201 // -------------------------------------------------------------------------- |
|
202 // |
|
203 void CSindVoiceTagAttributeListOperation::GetTagListCompleted( |
|
204 MNssTagListArray* aTagList ) |
|
205 { |
|
206 TRAPD( res, HandleGetTagListCompletedL( aTagList ) ); |
|
207 if ( res != KErrNone ) |
|
208 { |
|
209 iFindObserver.FindFailed( res ); |
|
210 } |
|
211 } |
|
212 |
|
213 // -------------------------------------------------------------------------- |
|
214 // CSindVoiceTagAttributeListOperation::GetTagFailed |
|
215 // -------------------------------------------------------------------------- |
|
216 // |
|
217 void CSindVoiceTagAttributeListOperation::GetTagFailed( |
|
218 TNssGetTagClientFailCode aFailCode ) |
|
219 { |
|
220 TInt res = KErrNone; |
|
221 |
|
222 switch ( aFailCode ) |
|
223 { |
|
224 case MNssGetTagClient::EVASDBItemNotFound: |
|
225 { |
|
226 // Tag not found for the iCurrentId -> move to next contact. |
|
227 TRAP( res, GetNextTagL() ); |
|
228 break; |
|
229 } |
|
230 case MNssGetTagClient::EVASDBNoMemory: |
|
231 { |
|
232 res = KErrNoMemory; |
|
233 break; |
|
234 } |
|
235 case MNssGetTagClient::EVASDBDiskFull: |
|
236 { |
|
237 res = KErrDiskFull; |
|
238 break; |
|
239 } |
|
240 default: |
|
241 { |
|
242 res = KErrUnknown; |
|
243 break; |
|
244 } |
|
245 } |
|
246 |
|
247 if ( res != KErrNone ) |
|
248 { |
|
249 iFindObserver.FindFailed( res ); |
|
250 } |
|
251 } |
|
252 |
|
253 // -------------------------------------------------------------------------- |
|
254 // CSindVoiceTagAttributeListOperation::CompleteOperation |
|
255 // -------------------------------------------------------------------------- |
|
256 // |
|
257 void CSindVoiceTagAttributeListOperation::CompleteOperation() |
|
258 { |
|
259 // An empty store -> return an empty link array |
|
260 CVPbkContactLinkArray* results = iContactLinks; |
|
261 iContactLinks = NULL; |
|
262 // Client takes the ownership of results. See MVPbkContactFindObserver |
|
263 TRAPD( res, iFindObserver.FindCompleteL( results ) ); |
|
264 if ( res != KErrNone ) |
|
265 { |
|
266 iFindObserver.FindFailed( res ); |
|
267 } |
|
268 } |
|
269 |
|
270 // -------------------------------------------------------------------------- |
|
271 // CSindVoiceTagAttributeListOperation::HandleGetTagListCompletedL |
|
272 // -------------------------------------------------------------------------- |
|
273 // |
|
274 void CSindVoiceTagAttributeListOperation::HandleGetTagListCompletedL( |
|
275 MNssTagListArray* aTagList ) |
|
276 { |
|
277 if ( aTagList ) |
|
278 { |
|
279 TBool hasVoiceTag = aTagList->Count() > 0; |
|
280 aTagList->ResetAndDestroy(); |
|
281 delete aTagList; |
|
282 if ( hasVoiceTag ) |
|
283 { |
|
284 // There is a voice tag for a contact |
|
285 CContactLink* link = CContactLink::NewLC( iContactStore, |
|
286 iCurrentId ); |
|
287 iContactLinks->AppendL( link ); |
|
288 CleanupStack::Pop( link ); |
|
289 } |
|
290 } |
|
291 |
|
292 GetNextTagL(); |
|
293 } |
|
294 |
|
295 // -------------------------------------------------------------------------- |
|
296 // CSindVoiceTagAttributeListOperation::GetNextTagL |
|
297 // -------------------------------------------------------------------------- |
|
298 // |
|
299 void CSindVoiceTagAttributeListOperation::GetNextTagL() |
|
300 { |
|
301 // Note that iterator is used asynchronously in this opeartion which |
|
302 // means that the iterator can become invalid if some other client |
|
303 // is modifying the data base. |
|
304 iCurrentId = iContactIterator.NextL(); |
|
305 TBool asyncRequestStarted = EFalse; |
|
306 while ( iCurrentId != KNullContactId && !asyncRequestStarted ) |
|
307 { |
|
308 const TInt position = 0; |
|
309 // This is asynchronous operation if it returns KErrNone. |
|
310 // Otherwise it's synchronous. |
|
311 TInt res = iNssTagManager.GetTagList( this, iNssContext, |
|
312 (TInt) iCurrentId, position ); |
|
313 if ( res != KErrNone ) |
|
314 { |
|
315 // The current id didn't have voice tag. Try next. |
|
316 iCurrentId = iContactIterator.NextL(); |
|
317 } |
|
318 else |
|
319 { |
|
320 // The current id has a voice tag but now this is asynchrnous |
|
321 // and it can not be canceled though the tag is already known. |
|
322 // Wait callback. See GetTagListCompleted. |
|
323 asyncRequestStarted = ETrue; |
|
324 } |
|
325 } |
|
326 |
|
327 if ( iCurrentId == KNullContactId ) |
|
328 { |
|
329 CompleteOperation(); |
|
330 } |
|
331 } |
|
332 } // namespace VPbkCntModel |
|
333 |
|
334 // End of File |