|
1 /* |
|
2 * Copyright (c) 2004-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: Virtual Phonebook speed dial attribute manager |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CSpeedDialAttributeManager.h" |
|
20 #include "CSpeedDialAttributeOperation.h" |
|
21 |
|
22 // From Virtual Phonebook |
|
23 #include <CVPbkContactManager.h> |
|
24 #include <CVPbkSpeedDialAttribute.h> |
|
25 #include <MVPbkContactOperation.h> |
|
26 #include <VPbkStoreUriLiterals.h> |
|
27 #include <MVPbkContactStoreList.h> |
|
28 #include <TVPbkContactStoreUriPtr.h> |
|
29 #include <MVPbkStoreContact.h> |
|
30 #include <CVPbkContactFieldCollection.h> |
|
31 |
|
32 // From VPbkCntModel |
|
33 #include "CContactStore.h" |
|
34 #include "CContact.h" |
|
35 |
|
36 // From Contacts Model |
|
37 #include <cntitem.h> |
|
38 |
|
39 |
|
40 namespace VPbkCntModel { |
|
41 |
|
42 const TInt KMaxSDValue(9); |
|
43 static const TInt speedDialUids[] = |
|
44 {0, // to make this array 1-based |
|
45 KUidSpeedDialOneValue, |
|
46 KUidSpeedDialTwoValue, |
|
47 KUidSpeedDialThreeValue, |
|
48 KUidSpeedDialFourValue, |
|
49 KUidSpeedDialFiveValue, |
|
50 KUidSpeedDialSixValue, |
|
51 KUidSpeedDialSevenValue, |
|
52 KUidSpeedDialEightValue, |
|
53 KUidSpeedDialNineValue}; |
|
54 |
|
55 CSpeedDialAttributeManager::CSpeedDialAttributeManager( |
|
56 CVPbkContactManager& aContactManager) : |
|
57 iContactManager(aContactManager) |
|
58 { |
|
59 } |
|
60 |
|
61 inline void CSpeedDialAttributeManager::ConstructL() |
|
62 { |
|
63 } |
|
64 |
|
65 CSpeedDialAttributeManager* CSpeedDialAttributeManager::NewL(TAny* aParam) |
|
66 { |
|
67 TParam& param = *static_cast<TParam*>(aParam); |
|
68 CSpeedDialAttributeManager* self = new(ELeave) CSpeedDialAttributeManager( |
|
69 param.iContactManager); |
|
70 CleanupStack::PushL(self); |
|
71 self->ConstructL(); |
|
72 CleanupStack::Pop(self); |
|
73 return self; |
|
74 } |
|
75 |
|
76 CSpeedDialAttributeManager::~CSpeedDialAttributeManager() |
|
77 { |
|
78 } |
|
79 |
|
80 MVPbkContactOperationBase* CSpeedDialAttributeManager::ListContactsL( |
|
81 TUid /*aAttributeType*/, |
|
82 MVPbkContactFindObserver& /*aObserver*/) |
|
83 { |
|
84 __ASSERT_DEBUG(EFalse, User::Leave(KErrNotSupported)); |
|
85 return NULL; |
|
86 } |
|
87 |
|
88 MVPbkContactOperationBase* CSpeedDialAttributeManager::ListContactsL( |
|
89 const MVPbkContactAttribute& /*aAttribute*/, |
|
90 MVPbkContactFindObserver& /*aObserver*/) |
|
91 { |
|
92 __ASSERT_DEBUG(EFalse, User::Leave(KErrNotSupported)); |
|
93 return NULL; |
|
94 } |
|
95 |
|
96 MVPbkContactOperation* CSpeedDialAttributeManager::CreateListContactsOperationL( |
|
97 TUid aAttributeType, |
|
98 MVPbkContactFindObserver& aObserver) |
|
99 { |
|
100 MVPbkContactOperation* result = NULL; |
|
101 |
|
102 if (aAttributeType == CVPbkSpeedDialAttribute::Uid()) |
|
103 { |
|
104 CVPbkSpeedDialAttribute* attribute = CVPbkSpeedDialAttribute::NewL( |
|
105 CVPbkSpeedDialAttribute::KSpeedDialIndexNotDefined); |
|
106 CleanupStack::PushL(attribute); |
|
107 result = CreateListContactsOperationL(*attribute, aObserver); |
|
108 CleanupStack::PopAndDestroy(attribute); |
|
109 } |
|
110 |
|
111 return result; |
|
112 } |
|
113 |
|
114 MVPbkContactOperation* CSpeedDialAttributeManager::CreateListContactsOperationL( |
|
115 const MVPbkContactAttribute& aAttribute, |
|
116 MVPbkContactFindObserver& aObserver) |
|
117 { |
|
118 MVPbkContactOperation* result = NULL; |
|
119 |
|
120 if (aAttribute.AttributeType() == CVPbkSpeedDialAttribute::Uid()) |
|
121 { |
|
122 const CVPbkSpeedDialAttribute& attribute = |
|
123 static_cast<const CVPbkSpeedDialAttribute&>(aAttribute); |
|
124 MVPbkContactStore* store = iContactManager.ContactStoresL().Find( |
|
125 KVPbkDefaultCntDbURI()); |
|
126 if (store) |
|
127 { |
|
128 CContactStore& cntStore = *static_cast<CContactStore*>(store); |
|
129 result = CSpeedDialAttributeOperation::NewListLC( |
|
130 cntStore, |
|
131 attribute, |
|
132 aObserver); |
|
133 // No need to start operation because it is suboperation for |
|
134 // attribute contact manager's find operation and all suboperations |
|
135 // are started by main operation. |
|
136 CleanupStack::Pop(); |
|
137 } |
|
138 } |
|
139 |
|
140 return result; |
|
141 } |
|
142 |
|
143 TBool CSpeedDialAttributeManager::HasContactAttributeL( |
|
144 TUid aAttributeType, |
|
145 const MVPbkStoreContact& aContact) const |
|
146 { |
|
147 TBool result = EFalse; |
|
148 |
|
149 if (dynamic_cast<const CContact*>(&aContact)) |
|
150 { |
|
151 if (aAttributeType == CVPbkSpeedDialAttribute::Uid()) |
|
152 { |
|
153 MVPbkContactStore* store = iContactManager.ContactStoresL().Find( |
|
154 KVPbkDefaultCntDbURI()); |
|
155 if (store) |
|
156 { |
|
157 CContactStore* cntStore = static_cast<CContactStore*>(store); |
|
158 if (&aContact.ContactStore() == cntStore) |
|
159 { |
|
160 const CContact& contact = static_cast<const CContact&>(aContact); |
|
161 CContactItemFieldSet& fields = contact.NativeContact()->CardFields(); |
|
162 const TInt count = fields.Count(); |
|
163 // Loop for every field in contact |
|
164 for (TInt i = 0; i < count && !result; ++i) |
|
165 { |
|
166 // loop for every speed dial index |
|
167 for (TInt n = 1; n <= KMaxSDValue; ++n) |
|
168 { |
|
169 TBuf<KSpeedDialPhoneLength> phoneNumber; |
|
170 TContactItemId cid = cntStore->NativeDatabase(). |
|
171 GetSpeedDialFieldL(n, phoneNumber); |
|
172 |
|
173 if (cid == contact.NativeContact()->Id() && |
|
174 fields[i].ContentType(). |
|
175 ContainsFieldType(TFieldType::Uid(speedDialUids[n]))) |
|
176 { |
|
177 result = ETrue; |
|
178 break; |
|
179 } |
|
180 } |
|
181 } |
|
182 } |
|
183 } |
|
184 } |
|
185 } |
|
186 return result; |
|
187 } |
|
188 |
|
189 TBool CSpeedDialAttributeManager::HasContactAttributeL( |
|
190 const MVPbkContactAttribute& aAttribute, |
|
191 const MVPbkStoreContact& aContact) const |
|
192 { |
|
193 TBool result = EFalse; |
|
194 |
|
195 if (dynamic_cast<const CContact*>(&aContact)) |
|
196 { |
|
197 if (aAttribute.AttributeType() == CVPbkSpeedDialAttribute::Uid()) |
|
198 { |
|
199 const CVPbkSpeedDialAttribute& attribute = |
|
200 static_cast<const CVPbkSpeedDialAttribute&>(aAttribute); |
|
201 if (attribute.Index() == CVPbkSpeedDialAttribute::KSpeedDialIndexNotDefined) |
|
202 { |
|
203 result = HasContactAttributeL(aAttribute.AttributeType(), aContact); |
|
204 } |
|
205 else |
|
206 { |
|
207 MVPbkContactStore* store = iContactManager.ContactStoresL().Find( |
|
208 KVPbkDefaultCntDbURI()); |
|
209 if (store) |
|
210 { |
|
211 CContactStore* cntStore = static_cast<CContactStore*>(store); |
|
212 if (&aContact.ContactStore() == cntStore) |
|
213 { |
|
214 TBuf<KSpeedDialPhoneLength> dummyBuf; |
|
215 TContactItemId cid = cntStore->NativeDatabase(). |
|
216 GetSpeedDialFieldL(attribute.Index(), dummyBuf); |
|
217 const CContact& contact = static_cast<const CContact&>(aContact); |
|
218 if (contact.NativeContact()->Id() == cid) |
|
219 { |
|
220 result = ETrue; |
|
221 } |
|
222 } |
|
223 } |
|
224 } |
|
225 } |
|
226 } |
|
227 return result; |
|
228 } |
|
229 |
|
230 TBool CSpeedDialAttributeManager::HasFieldAttributeL( |
|
231 TUid aAttributeType, |
|
232 const MVPbkStoreContactField& aField) const |
|
233 { |
|
234 TBool result = EFalse; |
|
235 |
|
236 if (dynamic_cast<const TContactField*>(&aField)) |
|
237 { |
|
238 if (aAttributeType == CVPbkSpeedDialAttribute::Uid()) |
|
239 { |
|
240 MVPbkContactStore* store = iContactManager.ContactStoresL().Find( |
|
241 KVPbkDefaultCntDbURI()); |
|
242 if (store) |
|
243 { |
|
244 CContactStore* cntStore = static_cast<CContactStore*>(store); |
|
245 if (&aField.ContactStore() == cntStore) |
|
246 { |
|
247 for (TInt i = 1; i <= KMaxSDValue && !result; ++i) |
|
248 { |
|
249 TBuf<KSpeedDialPhoneLength> phoneNumber; |
|
250 TContactItemId cid = cntStore->NativeDatabase(). |
|
251 GetSpeedDialFieldL(i, phoneNumber); |
|
252 const TContactField& field = static_cast<const TContactField&>(aField); |
|
253 if (cid == static_cast<CContact&>(aField.ParentContact()). |
|
254 NativeContact()->Id() && |
|
255 field.NativeField()->ContentType(). |
|
256 ContainsFieldType(TFieldType::Uid(speedDialUids[i]))) |
|
257 { |
|
258 result = ETrue; |
|
259 } |
|
260 } |
|
261 } |
|
262 } |
|
263 } |
|
264 } |
|
265 return result; |
|
266 } |
|
267 |
|
268 TBool CSpeedDialAttributeManager::HasFieldAttributeL( |
|
269 const MVPbkContactAttribute& aAttribute, |
|
270 const MVPbkStoreContactField& aField) const |
|
271 { |
|
272 TBool result = EFalse; |
|
273 |
|
274 if (dynamic_cast<const TContactField*>(&aField)) |
|
275 { |
|
276 if (aAttribute.AttributeType() == CVPbkSpeedDialAttribute::Uid()) |
|
277 { |
|
278 const CVPbkSpeedDialAttribute& attribute = |
|
279 static_cast<const CVPbkSpeedDialAttribute&>(aAttribute); |
|
280 if (attribute.Index() == CVPbkSpeedDialAttribute::KSpeedDialIndexNotDefined) |
|
281 { |
|
282 result = HasFieldAttributeL(aAttribute.AttributeType(), aField); |
|
283 } |
|
284 else |
|
285 { |
|
286 MVPbkContactStore* store = iContactManager.ContactStoresL().Find( |
|
287 KVPbkDefaultCntDbURI()); |
|
288 if (store) |
|
289 { |
|
290 CContactStore* cntStore = static_cast<CContactStore*>(store); |
|
291 if (&aField.ContactStore() == cntStore) |
|
292 { |
|
293 TBuf<KSpeedDialPhoneLength> phoneNumber; |
|
294 TContactItemId cid = cntStore->NativeDatabase(). |
|
295 GetSpeedDialFieldL(attribute.Index(), phoneNumber); |
|
296 const TContactField& field = static_cast<const TContactField&>(aField); |
|
297 if ((cid == static_cast<CContact&>( |
|
298 aField.ParentContact()).NativeContact()->Id()) && |
|
299 (field.NativeField()->ContentType().ContainsFieldType( |
|
300 TFieldType::Uid(speedDialUids[attribute.Index()])))) |
|
301 { |
|
302 result = ETrue; |
|
303 } |
|
304 } |
|
305 } |
|
306 } |
|
307 } |
|
308 } |
|
309 return result; |
|
310 } |
|
311 |
|
312 MVPbkContactOperationBase* CSpeedDialAttributeManager::SetContactAttributeL( |
|
313 const MVPbkContactLink& /*aContactLink*/, |
|
314 const MVPbkContactAttribute& aAttribute, |
|
315 MVPbkSetAttributeObserver& /*aObserver*/) |
|
316 { |
|
317 MVPbkContactOperationBase* result = NULL; |
|
318 |
|
319 if (aAttribute.AttributeType() == CVPbkSpeedDialAttribute::Uid()) |
|
320 { |
|
321 User::Leave(KErrNotSupported); |
|
322 } |
|
323 |
|
324 return result; |
|
325 } |
|
326 |
|
327 MVPbkContactOperationBase* CSpeedDialAttributeManager::SetFieldAttributeL( |
|
328 MVPbkStoreContactField& aField, |
|
329 const MVPbkContactAttribute& aAttribute, |
|
330 MVPbkSetAttributeObserver& aObserver) |
|
331 { |
|
332 MVPbkContactOperation* result = NULL; |
|
333 |
|
334 if (dynamic_cast<const TContactField*>(&aField)) |
|
335 { |
|
336 if (aAttribute.AttributeType() == CVPbkSpeedDialAttribute::Uid()) |
|
337 { |
|
338 const CVPbkSpeedDialAttribute& attribute = |
|
339 static_cast<const CVPbkSpeedDialAttribute&>(aAttribute); |
|
340 if (attribute.Index() == CVPbkSpeedDialAttribute::KSpeedDialIndexNotDefined) |
|
341 { |
|
342 User::Leave(KErrArgument); |
|
343 } |
|
344 else |
|
345 { |
|
346 MVPbkContactStore* store = iContactManager.ContactStoresL().Find( |
|
347 KVPbkDefaultCntDbURI()); |
|
348 if (store) |
|
349 { |
|
350 VPbkCntModel::CContactStore& cntStore = *static_cast<CContactStore*>(store); |
|
351 result = CSpeedDialAttributeOperation::NewSetLC( |
|
352 cntStore, aField, attribute, aObserver); |
|
353 result->StartL(); |
|
354 CleanupStack::Pop(); // result |
|
355 } |
|
356 else |
|
357 { |
|
358 User::Leave(KErrNotSupported); |
|
359 } |
|
360 } |
|
361 } |
|
362 } |
|
363 return result; |
|
364 } |
|
365 |
|
366 MVPbkContactOperationBase* CSpeedDialAttributeManager::RemoveContactAttributeL( |
|
367 const MVPbkContactLink& /*aContactLink*/, |
|
368 const MVPbkContactAttribute& aAttribute, |
|
369 MVPbkSetAttributeObserver& /*aObserver*/) |
|
370 { |
|
371 MVPbkContactOperationBase* result = NULL; |
|
372 |
|
373 if (aAttribute.AttributeType() == CVPbkSpeedDialAttribute::Uid()) |
|
374 { |
|
375 User::Leave(KErrNotSupported); |
|
376 } |
|
377 |
|
378 return result; |
|
379 } |
|
380 |
|
381 MVPbkContactOperationBase* CSpeedDialAttributeManager::RemoveContactAttributeL( |
|
382 const MVPbkContactLink& /*aContactLink*/, |
|
383 TUid aAttributeType, |
|
384 MVPbkSetAttributeObserver& /*aObserver*/) |
|
385 { |
|
386 MVPbkContactOperationBase* result = NULL; |
|
387 |
|
388 if (aAttributeType == CVPbkSpeedDialAttribute::Uid()) |
|
389 { |
|
390 User::Leave(KErrNotSupported); |
|
391 } |
|
392 |
|
393 return result; |
|
394 } |
|
395 |
|
396 MVPbkContactOperationBase* CSpeedDialAttributeManager::RemoveFieldAttributeL( |
|
397 MVPbkStoreContactField& aField, |
|
398 const MVPbkContactAttribute& aAttribute, |
|
399 MVPbkSetAttributeObserver& aObserver) |
|
400 { |
|
401 MVPbkContactOperation* result = NULL; |
|
402 |
|
403 if (dynamic_cast<TContactField*>(&aField)) |
|
404 { |
|
405 if (aAttribute.AttributeType() == CVPbkSpeedDialAttribute::Uid()) |
|
406 { |
|
407 const CVPbkSpeedDialAttribute& attribute = |
|
408 static_cast<const CVPbkSpeedDialAttribute&>(aAttribute); |
|
409 |
|
410 MVPbkContactStore* store = iContactManager.ContactStoresL().Find( |
|
411 KVPbkDefaultCntDbURI()); |
|
412 if (store) |
|
413 { |
|
414 VPbkCntModel::CContactStore& cntStore = *static_cast<CContactStore*>(store); |
|
415 result = CSpeedDialAttributeOperation::NewRemoveLC( |
|
416 cntStore, aField, attribute, aObserver); |
|
417 result->StartL(); |
|
418 CleanupStack::Pop(); // result |
|
419 } |
|
420 else |
|
421 { |
|
422 User::Leave(KErrNotSupported); |
|
423 } |
|
424 } |
|
425 } |
|
426 return result; |
|
427 } |
|
428 |
|
429 MVPbkContactOperationBase* CSpeedDialAttributeManager::RemoveFieldAttributeL( |
|
430 MVPbkStoreContactField& aField, |
|
431 TUid aAttributeType, |
|
432 MVPbkSetAttributeObserver& aObserver) |
|
433 { |
|
434 MVPbkContactOperationBase* result = NULL; |
|
435 |
|
436 if (dynamic_cast<TContactField*>(&aField)) |
|
437 { |
|
438 if (aAttributeType == CVPbkSpeedDialAttribute::Uid()) |
|
439 { |
|
440 CVPbkSpeedDialAttribute* attribute = CVPbkSpeedDialAttribute::NewL(); |
|
441 CleanupStack::PushL(attribute); |
|
442 result = RemoveFieldAttributeL(aField, *attribute, aObserver); |
|
443 CleanupStack::PopAndDestroy(attribute); |
|
444 } |
|
445 } |
|
446 return result; |
|
447 } |
|
448 |
|
449 MVPbkStoreContactFieldCollection* CSpeedDialAttributeManager::FindFieldsWithAttributeLC( |
|
450 TUid aAttributeType, |
|
451 MVPbkStoreContact& aContact) const |
|
452 { |
|
453 CVPbkContactFieldCollection* result = NULL; |
|
454 |
|
455 if (dynamic_cast<CContact*>(&aContact) && |
|
456 aAttributeType == CVPbkSpeedDialAttribute::Uid()) |
|
457 { |
|
458 result = CVPbkContactFieldCollection::NewLC(aContact); |
|
459 const TInt count = aContact.Fields().FieldCount(); |
|
460 for (TInt i = 0; i < count; ++i) |
|
461 { |
|
462 const MVPbkStoreContactField& field = aContact.Fields().FieldAt(i); |
|
463 if (HasFieldAttributeL(aAttributeType, field)) |
|
464 { |
|
465 MVPbkStoreContactField* clone = field.CloneLC(); |
|
466 result->AppendL(clone); |
|
467 CleanupStack::Pop(); // clone |
|
468 } |
|
469 } |
|
470 } |
|
471 |
|
472 return result; |
|
473 } |
|
474 |
|
475 MVPbkStoreContactFieldCollection* CSpeedDialAttributeManager::FindFieldsWithAttributeLC( |
|
476 const MVPbkContactAttribute& aAttribute, |
|
477 MVPbkStoreContact& aContact) const |
|
478 { |
|
479 CVPbkContactFieldCollection* result = NULL; |
|
480 |
|
481 if (dynamic_cast<CContact*>(&aContact) && |
|
482 aAttribute.AttributeType() == CVPbkSpeedDialAttribute::Uid()) |
|
483 { |
|
484 result = CVPbkContactFieldCollection::NewLC(aContact); |
|
485 const TInt count = aContact.Fields().FieldCount(); |
|
486 for (TInt i = 0; i < count; ++i) |
|
487 { |
|
488 const MVPbkStoreContactField& field = aContact.Fields().FieldAt(i); |
|
489 if (HasFieldAttributeL(aAttribute, field)) |
|
490 { |
|
491 MVPbkStoreContactField* clone = field.CloneLC(); |
|
492 result->AppendL(clone); |
|
493 CleanupStack::Pop(); // clone |
|
494 } |
|
495 } |
|
496 } |
|
497 return result; |
|
498 } |
|
499 |
|
500 MVPbkContactOperationBase* CSpeedDialAttributeManager::HasContactAttributeL( |
|
501 TUid /*aAttributeType*/, |
|
502 const MVPbkStoreContact& /*aContact*/, |
|
503 MVPbkSingleAttributePresenceObserver& /*aObserver*/) const |
|
504 { |
|
505 User::Leave( KErrNotSupported ); |
|
506 return NULL; |
|
507 } |
|
508 |
|
509 MVPbkContactOperationBase* CSpeedDialAttributeManager::HasContactAttributeL( |
|
510 const MVPbkContactAttribute& /*aAttribute*/, |
|
511 const MVPbkStoreContact& /*aContact*/, |
|
512 MVPbkSingleAttributePresenceObserver& /*aObserver*/) const |
|
513 { |
|
514 User::Leave( KErrNotSupported ); |
|
515 return NULL; |
|
516 } |
|
517 |
|
518 MVPbkContactOperationBase* CSpeedDialAttributeManager::HasFieldAttributeL( |
|
519 TUid /*aAttributeType*/, |
|
520 const MVPbkStoreContactField& /*aField*/, |
|
521 MVPbkSingleAttributePresenceObserver& /*aObserver*/) const |
|
522 { |
|
523 User::Leave( KErrNotSupported ); |
|
524 return NULL; |
|
525 } |
|
526 |
|
527 MVPbkContactOperationBase* CSpeedDialAttributeManager::HasFieldAttributeL( |
|
528 const MVPbkContactAttribute& /*aAttribute*/, |
|
529 const MVPbkStoreContactField& /*aField*/, |
|
530 MVPbkSingleAttributePresenceObserver& /*aObserver*/) const |
|
531 { |
|
532 User::Leave( KErrNotSupported ); |
|
533 return NULL; |
|
534 } |
|
535 |
|
536 MVPbkContactOperationBase* CSpeedDialAttributeManager::FindFieldsWithAttributeL( |
|
537 TUid /*aAttributeType*/, |
|
538 MVPbkStoreContact& /*aContact*/, |
|
539 MVPbkMultiAttributePresenceObserver& /*aObserver*/) const |
|
540 { |
|
541 User::Leave( KErrNotSupported ); |
|
542 return NULL; |
|
543 } |
|
544 |
|
545 MVPbkContactOperationBase* CSpeedDialAttributeManager::FindFieldsWithAttributeL( |
|
546 const MVPbkContactAttribute& /*aAttribute*/, |
|
547 MVPbkStoreContact& /*aContact*/, |
|
548 MVPbkMultiAttributePresenceObserver& /*aObserver*/) const |
|
549 { |
|
550 User::Leave( KErrNotSupported ); |
|
551 return NULL; |
|
552 } |
|
553 |
|
554 } // namespace VPbkCntModel |
|
555 |
|
556 // End of File |