|
1 /* |
|
2 * Copyright (c) 2008 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: Definition of the class CPbkxRclSearchEngine. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "emailtrace.h" |
|
20 #include <coemain.h> |
|
21 //<cmail> |
|
22 #include "cfsccontactactionservice.h" |
|
23 #include "mfsccontactaction.h" |
|
24 #include "fscactionpluginactionuids.h" |
|
25 |
|
26 #include "tfsccontactactionqueryresult.h" |
|
27 //</cmail> |
|
28 #include <CPbkContactEngine.h> |
|
29 #include <CPbkContactItem.h> |
|
30 |
|
31 #include <CVPbkContactStoreUriArray.h> |
|
32 #include <TVPbkContactStoreUriPtr.h> |
|
33 #include <CVPbkContactManager.h> |
|
34 #include <MVPbkContactStore.h> |
|
35 #include <MVPbkContactStoreList.h> |
|
36 #include <MVPbkContactStoreProperties.h> |
|
37 #include <MVPbkStoreContact.h> // for RFscStoreContactList items |
|
38 |
|
39 #include "cpbkxrclactionservicewrapper.h" |
|
40 #include "pbkxrclengineconstants.h" |
|
41 #include "cpbkxrclcontactconverter.h" |
|
42 |
|
43 |
|
44 // Contact databases |
|
45 _LIT(KRclDefaultCntDbURI, "cntdb://c:contacts.cdb"); |
|
46 |
|
47 // ======== MEMBER FUNCTIONS ======== |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // CPbkxRclActionServiceWrapper::NewL |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 CPbkxRclActionServiceWrapper* CPbkxRclActionServiceWrapper::NewL( |
|
54 CPbkContactEngine& aContactEngine ) |
|
55 { |
|
56 FUNC_LOG; |
|
57 CPbkxRclActionServiceWrapper* wrapper = new ( ELeave ) |
|
58 CPbkxRclActionServiceWrapper( aContactEngine ); |
|
59 CleanupStack::PushL( wrapper ); |
|
60 wrapper->ConstructL(); |
|
61 CleanupStack::Pop( wrapper ); |
|
62 return wrapper; |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // CPbkxRclActionServiceWrapper::CPbkxRclActionServiceWrapper |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 CPbkxRclActionServiceWrapper::CPbkxRclActionServiceWrapper( CPbkContactEngine& |
|
70 aContactEngine ) : CBase(), iContactEngine( aContactEngine ) |
|
71 { |
|
72 FUNC_LOG; |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // CPbkxRclActionServiceWrapper::~CPbkxRclActionServiceWrapper |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 CPbkxRclActionServiceWrapper::~CPbkxRclActionServiceWrapper() |
|
80 { |
|
81 FUNC_LOG; |
|
82 |
|
83 iConvertedContact.ResetAndDestroy(); |
|
84 |
|
85 if( iContactManager ) |
|
86 { |
|
87 if ( iContactStore ) |
|
88 { |
|
89 iContactStore->Close(*this); |
|
90 } |
|
91 } |
|
92 delete iContactManager; |
|
93 delete iContactActionService; |
|
94 delete iContactConverter; |
|
95 delete iWait; |
|
96 |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // CPbkxRclActionServiceWrapper::ConstructL |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 void CPbkxRclActionServiceWrapper::ConstructL() |
|
104 { |
|
105 FUNC_LOG; |
|
106 // Create Contact Manager |
|
107 CVPbkContactStoreUriArray* uriList = CVPbkContactStoreUriArray::NewLC(); |
|
108 uriList->AppendL( TVPbkContactStoreUriPtr( KRclDefaultCntDbURI ) ); |
|
109 iContactManager = CVPbkContactManager::NewL( *uriList, &(CCoeEnv::Static()->FsSession()) ); |
|
110 CleanupStack::PopAndDestroy( uriList ); |
|
111 |
|
112 // Get store list |
|
113 MVPbkContactStoreList& defaultstore = iContactManager->ContactStoresL(); |
|
114 |
|
115 // Open contact store |
|
116 iContactStore = &defaultstore.At( 0 ); |
|
117 iContactStore->OpenL( *this ); |
|
118 |
|
119 iContactActionService = CFscContactActionService::NewL( *iContactManager ); |
|
120 |
|
121 iContactConverter = CPbkxRclContactConverter::NewL( |
|
122 iContactEngine, *iContactManager, *iContactStore ); |
|
123 |
|
124 iWait = new ( ELeave ) CActiveSchedulerWait(); |
|
125 |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------------------------- |
|
129 // CPbkxRclActionServiceWrapper::SetContactSelectorMode |
|
130 // --------------------------------------------------------------------------- |
|
131 // |
|
132 void CPbkxRclActionServiceWrapper::SetContactSelectorMode( |
|
133 TBool aContactSelectorMode ) |
|
134 { |
|
135 FUNC_LOG; |
|
136 iContactSelectorMode = aContactSelectorMode; |
|
137 if ( aContactSelectorMode ) |
|
138 { |
|
139 // in contact selector mode the flags are static |
|
140 |
|
141 // all actions except save as is queried |
|
142 iFlags = KFscAtMan & ( ~KFscAtManSaveAs ); |
|
143 } |
|
144 } |
|
145 |
|
146 // --------------------------------------------------------------------------- |
|
147 // CPbkxRclActionServiceWrapper::SetActionMenuMode |
|
148 // --------------------------------------------------------------------------- |
|
149 // |
|
150 void CPbkxRclActionServiceWrapper::SetActionMenuMode( |
|
151 TBool aActionMenuMode ) |
|
152 { |
|
153 FUNC_LOG; |
|
154 // if not in contact selector mode, flags depend on whether |
|
155 // we are showing the action menu or not |
|
156 if ( !iContactSelectorMode ) |
|
157 { |
|
158 if ( aActionMenuMode ) |
|
159 { |
|
160 // in action menu mode poc and save as are disabled |
|
161 iFlags = KFscAtAll & ( ~KFscAtComCallPoc ) & ( ~KFscAtManSaveAs ); |
|
162 } |
|
163 else |
|
164 { |
|
165 // when not in action menu mode, all actions but save as contact |
|
166 // are enabled |
|
167 iFlags = KFscAtAll & ( ~KFscAtManSaveAs ); |
|
168 } |
|
169 } |
|
170 } |
|
171 |
|
172 // --------------------------------------------------------------------------- |
|
173 // CPbkxRclActionServiceWrapper::SetCurrentContactL |
|
174 // --------------------------------------------------------------------------- |
|
175 // |
|
176 void CPbkxRclActionServiceWrapper::SetCurrentContactL( CPbkContactItem* aContactItem ) |
|
177 { |
|
178 FUNC_LOG; |
|
179 |
|
180 iConvertedContact.ResetAndDestroy(); // clean before new use |
|
181 |
|
182 // Convert contact to MVPbkStoreContact object, only one item in |
|
183 if ( aContactItem ) |
|
184 { |
|
185 iContactConverter->ConvertContactL( *aContactItem, iConvertedContact ); |
|
186 } |
|
187 |
|
188 iContactActionService->SetContactSetL( iConvertedContact ); |
|
189 |
|
190 iSaveAsContactActionExists = EFalse; |
|
191 |
|
192 iQueryComplete = EFalse; |
|
193 // first query for save as contact |
|
194 iContactActionService->QueryActionsL( this, EFalse, KFscAtManSaveAs ); |
|
195 |
|
196 // Wait async operation callback. If operation is completed before returning method call |
|
197 // don't start waiting |
|
198 if (!iQueryComplete) |
|
199 { |
|
200 iWait->Start(); |
|
201 } |
|
202 |
|
203 const CFscContactActionList& actions = iContactActionService->QueryResults(); |
|
204 |
|
205 // look for save as contact |
|
206 for ( TInt i = 0; i < actions.Count(); i++ ) |
|
207 { |
|
208 const TFscContactActionQueryResult& result = actions[i]; |
|
209 if ( result.iAction->Uid() == KFscActionUidSaveAsContact ) |
|
210 { |
|
211 iSaveAsContactResult = TFscContactActionQueryResult( |
|
212 result.iAction, |
|
213 result.iPriority, |
|
214 result.iActionMenuVisibility, |
|
215 result.iOptionsMenuVisibility ); |
|
216 |
|
217 iSaveAsContactActionExists = ETrue; |
|
218 break; |
|
219 } |
|
220 } |
|
221 |
|
222 // Wait async operation callback. If operation is completed before returning method call |
|
223 // don't start waiting |
|
224 iQueryComplete = EFalse; |
|
225 iContactActionService->QueryActionsL( this, EFalse, iFlags ); |
|
226 if (!iQueryComplete) |
|
227 { |
|
228 iWait->Start(); |
|
229 } |
|
230 |
|
231 } |
|
232 |
|
233 // --------------------------------------------------------------------------- |
|
234 // CPbkxRclActionServiceWrapper::IsActionEnabled |
|
235 // --------------------------------------------------------------------------- |
|
236 // |
|
237 TBool CPbkxRclActionServiceWrapper::IsActionEnabled( |
|
238 const TUint64 aActionType ) const |
|
239 { |
|
240 FUNC_LOG; |
|
241 TBool enabled = EFalse; |
|
242 |
|
243 const TFscContactActionQueryResult* result = GetResult( aActionType ); |
|
244 |
|
245 if ( result != NULL ) |
|
246 { |
|
247 enabled = ( result->iOptionsMenuVisibility.iVisibility == |
|
248 TFscContactActionVisibility::EFscActionVisible && |
|
249 result->iPriority >= 0 ); |
|
250 } |
|
251 |
|
252 return enabled; |
|
253 } |
|
254 |
|
255 // --------------------------------------------------------------------------- |
|
256 // CPbkxRclActionServiceWrapper::GetActionL |
|
257 // --------------------------------------------------------------------------- |
|
258 // |
|
259 const TFscContactActionQueryResult* CPbkxRclActionServiceWrapper::GetActionL( |
|
260 const TUint64 aActionType) const |
|
261 { |
|
262 const CFscContactActionList& actions = iContactActionService->AllActionsListL( KFscAtAll ); |
|
263 |
|
264 for ( TInt i = 0; i < actions.Count(); i++ ) |
|
265 { |
|
266 const TFscContactActionQueryResult& queryResult = actions[i]; |
|
267 if ( queryResult.iAction->Type() == aActionType ) |
|
268 { |
|
269 return &queryResult; |
|
270 } |
|
271 } |
|
272 |
|
273 return NULL; |
|
274 } |
|
275 |
|
276 |
|
277 // --------------------------------------------------------------------------- |
|
278 // CPbkxRclActionServiceWrapper::ExecuteActionL |
|
279 // --------------------------------------------------------------------------- |
|
280 // |
|
281 void CPbkxRclActionServiceWrapper::ExecuteActionL( const TUint64 aActionType ) |
|
282 { |
|
283 FUNC_LOG; |
|
284 const TFscContactActionQueryResult* result = GetActionL(aActionType); |
|
285 |
|
286 if ( result == NULL ) |
|
287 { |
|
288 User::Leave( KErrNotFound ); |
|
289 } |
|
290 |
|
291 iExecuteComplete = EFalse; |
|
292 iContactActionService->ExecuteL( result->iAction->Uid(), this ); |
|
293 // Wait async operation callback. If operation is completed before returning method call |
|
294 // don't start waiting |
|
295 if (!iExecuteComplete) |
|
296 { |
|
297 iWait->Start(); |
|
298 } |
|
299 |
|
300 } |
|
301 |
|
302 // --------------------------------------------------------------------------- |
|
303 // CPbkxRclActionServiceWrapper::ActionService |
|
304 // --------------------------------------------------------------------------- |
|
305 // |
|
306 CFscContactActionService* CPbkxRclActionServiceWrapper::ActionService() |
|
307 { |
|
308 FUNC_LOG; |
|
309 return iContactActionService; |
|
310 } |
|
311 |
|
312 // --------------------------------------------------------------------------- |
|
313 // CPbkxRclActionServiceWrapper::GetResult |
|
314 // --------------------------------------------------------------------------- |
|
315 // |
|
316 const TFscContactActionQueryResult* CPbkxRclActionServiceWrapper::GetResult( |
|
317 const TUint64 aType ) const |
|
318 { |
|
319 FUNC_LOG; |
|
320 if ( iSaveAsContactActionExists && aType == iSaveAsContactResult.iAction->Type() ) |
|
321 { |
|
322 return &iSaveAsContactResult; |
|
323 } |
|
324 else |
|
325 { |
|
326 const CFscContactActionList& actions = iContactActionService->QueryResults(); |
|
327 |
|
328 for ( TInt i = 0; i < actions.Count(); i++ ) |
|
329 { |
|
330 const TFscContactActionQueryResult& queryResult = actions[i]; |
|
331 if ( queryResult.iAction->Type() == aType ) |
|
332 { |
|
333 return &queryResult; |
|
334 } |
|
335 } |
|
336 } |
|
337 return NULL; |
|
338 } |
|
339 // --------------------------------------------------------------------------- |
|
340 // CPbkxRclActionServiceWrapper::ContactConverter |
|
341 // --------------------------------------------------------------------------- |
|
342 // |
|
343 CPbkxRclContactConverter* CPbkxRclActionServiceWrapper::ContactConverter() |
|
344 { |
|
345 FUNC_LOG; |
|
346 return iContactConverter; |
|
347 } |
|
348 |
|
349 // --------------------------------------------------------------------------- |
|
350 // CPbkxRclActionServiceWrapper::StoreReady |
|
351 // --------------------------------------------------------------------------- |
|
352 // |
|
353 void CPbkxRclActionServiceWrapper::StoreReady( |
|
354 MVPbkContactStore& /* aContactStore */ ) |
|
355 { |
|
356 FUNC_LOG; |
|
357 iLastError = KErrNone; |
|
358 } |
|
359 // --------------------------------------------------------------------------- |
|
360 // CPbkxRclActionServiceWrapper::StoreUnavailable() |
|
361 // --------------------------------------------------------------------------- |
|
362 // |
|
363 void CPbkxRclActionServiceWrapper::StoreUnavailable( |
|
364 MVPbkContactStore& /* aContactStore */, |
|
365 TInt aReason ) |
|
366 { |
|
367 FUNC_LOG; |
|
368 iLastError = aReason; |
|
369 } |
|
370 |
|
371 // --------------------------------------------------------------------------- |
|
372 // CPbkxRclActionServiceWrapper::HandleStoreEventL() |
|
373 // --------------------------------------------------------------------------- |
|
374 // |
|
375 void CPbkxRclActionServiceWrapper::HandleStoreEventL( |
|
376 MVPbkContactStore& /* aContactStore */, |
|
377 TVPbkContactStoreEvent /* aStoreEvent */ ) |
|
378 { |
|
379 FUNC_LOG; |
|
380 } |
|
381 |
|
382 // --------------------------------------------------------------------------- |
|
383 // CPbkxRclActionServiceWrapper::QueryActionsComplete() |
|
384 // --------------------------------------------------------------------------- |
|
385 // |
|
386 void CPbkxRclActionServiceWrapper::QueryActionsComplete() |
|
387 { |
|
388 FUNC_LOG; |
|
389 iLastError = KErrNone; |
|
390 iQueryComplete = ETrue; |
|
391 if (iWait->IsStarted()) |
|
392 { |
|
393 iWait->AsyncStop(); |
|
394 } |
|
395 } |
|
396 |
|
397 // --------------------------------------------------------------------------- |
|
398 // CPbkxRclActionServiceWrapper::QueryActionsFailed() |
|
399 // --------------------------------------------------------------------------- |
|
400 // |
|
401 void CPbkxRclActionServiceWrapper::QueryActionsFailed( TInt aError ) |
|
402 { |
|
403 FUNC_LOG; |
|
404 iLastError = aError; |
|
405 iQueryComplete = ETrue; |
|
406 if (iWait->IsStarted()) |
|
407 { |
|
408 iWait->AsyncStop(); |
|
409 } |
|
410 } |
|
411 |
|
412 // --------------------------------------------------------------------------- |
|
413 // CPbkxRclActionServiceWrapper::ExecuteComplete() |
|
414 // --------------------------------------------------------------------------- |
|
415 // |
|
416 void CPbkxRclActionServiceWrapper::ExecuteComplete() |
|
417 { |
|
418 FUNC_LOG; |
|
419 iLastError = KErrNone; |
|
420 iExecuteComplete = ETrue; |
|
421 if (iWait->IsStarted()) |
|
422 { |
|
423 iWait->AsyncStop(); |
|
424 } |
|
425 } |
|
426 |
|
427 // --------------------------------------------------------------------------- |
|
428 // CPbkxRclActionServiceWrapper::ExecuteFailed() |
|
429 // --------------------------------------------------------------------------- |
|
430 // |
|
431 void CPbkxRclActionServiceWrapper::ExecuteFailed( TInt aError ) |
|
432 { |
|
433 FUNC_LOG; |
|
434 iLastError = aError; |
|
435 iExecuteComplete = ETrue; |
|
436 if (iWait->IsStarted()) |
|
437 { |
|
438 iWait->AsyncStop(); |
|
439 } |
|
440 } |
|
441 |
|
442 // --------------------------------------------------------------------------- |
|
443 // CPbkxRclActionServiceWrapper::ExecuteFailed() |
|
444 // --------------------------------------------------------------------------- |
|
445 // |
|
446 void CPbkxRclActionServiceWrapper::CancelQuery() |
|
447 { |
|
448 FUNC_LOG; |
|
449 iContactActionService->CancelQueryActions(); |
|
450 if (iWait->IsStarted()) |
|
451 { |
|
452 iWait->AsyncStop(); |
|
453 } |
|
454 } |
|
455 |
|
456 //RCL - Add |
|
457 // --------------------------------------------------------------------------- |
|
458 // CPbkxRclActionServiceWrapper::ContactManager() |
|
459 // --------------------------------------------------------------------------- |
|
460 // |
|
461 CVPbkContactManager& CPbkxRclActionServiceWrapper::ContactManager() |
|
462 { |
|
463 return *iContactManager; |
|
464 } |