|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @internalComponent |
|
19 @released |
|
20 */ |
|
21 |
|
22 |
|
23 #include "clplanalyserproxy.h" |
|
24 #include <cntitem.h> |
|
25 #include <cntfldst.h> |
|
26 |
|
27 /** |
|
28 CLplAnalyserProxy constructor. |
|
29 */ |
|
30 CLplAnalyserProxy::CLplAnalyserProxy(MIniFileManager& aIniManager, MContactDbObserver& aCntDbObserver, MLplPersistenceBroker& aBroker, MLplTransactionManager& aTranMan, MLplContactProperties& aProperties) |
|
31 : |
|
32 CLplGenericProxy(aBroker, aTranMan), |
|
33 iCntDbObserver(aCntDbObserver), |
|
34 iIniManager(aIniManager), |
|
35 iProperties(aProperties) |
|
36 { |
|
37 } |
|
38 |
|
39 |
|
40 /** |
|
41 Create a new Contact item. |
|
42 */ |
|
43 TContactItemId CLplAnalyserProxy::CreateL(CContactItem& aItem, TUint aSessionId) |
|
44 { |
|
45 #if defined(__PROFILE_DEBUG__) |
|
46 RDebug::Print(_L("[CNTMODEL] MTD: CLplAnalyserProxy::CreateL")); |
|
47 #endif |
|
48 |
|
49 // Delegate creation to generic proxy. |
|
50 TContactItemId cntId = CLplGenericProxy::CreateL(aItem, aSessionId); |
|
51 |
|
52 // Notify observer of the change. |
|
53 switch(aItem.Type().iUid) |
|
54 { |
|
55 case KUidContactCardTemplateValue: |
|
56 { |
|
57 NotifyObserverL(EContactDbObserverEventTemplateAdded, aItem.Id()); |
|
58 } |
|
59 break; |
|
60 case KUidContactGroupValue: |
|
61 { |
|
62 NotifyObserverL(EContactDbObserverEventGroupAdded, aItem.Id()); |
|
63 } |
|
64 break; |
|
65 case KUidContactCardValue: |
|
66 case KUidContactOwnCardValue: |
|
67 case KUidContactICCEntryValue: |
|
68 { |
|
69 NotifyObserverL(EContactDbObserverEventContactAdded, aItem.Id()); |
|
70 } |
|
71 break; |
|
72 default: |
|
73 break; |
|
74 }; |
|
75 |
|
76 return(cntId); |
|
77 } |
|
78 |
|
79 |
|
80 /** |
|
81 Update an existing Contact item (or parts of it as specified by the view |
|
82 definition). |
|
83 */ |
|
84 void CLplAnalyserProxy::UpdateL(CContactItem& aItem, TUint aSessionId, TBool aSpeeDailUpdate) |
|
85 { |
|
86 // Delegate update to generic proxy. |
|
87 CLplGenericProxy::UpdateL(aItem, aSessionId); |
|
88 |
|
89 // Notify observer of the change. |
|
90 switch(aItem.Type().iUid) |
|
91 { |
|
92 case KUidContactTemplateValue: |
|
93 case KUidContactCardTemplateValue: |
|
94 { |
|
95 NotifyObserverL(EContactDbObserverEventTemplateChanged, aItem.Id()); |
|
96 } |
|
97 break; |
|
98 case KUidContactOwnCardValue: |
|
99 { |
|
100 NotifyObserverL(EContactDbObserverEventOwnCardChanged, aItem.Id()); |
|
101 // If an item with a speed dial is updated then update the speed |
|
102 // dials. |
|
103 (void)CheckSpeedDialUpdatesL(aItem); |
|
104 } |
|
105 break; |
|
106 case KUidContactGroupValue: |
|
107 { |
|
108 NotifyObserverL(EContactDbObserverEventGroupChanged, aItem.Id()); |
|
109 } |
|
110 break; |
|
111 case KUidContactCardValue: |
|
112 case KUidContactICCEntryValue: |
|
113 { |
|
114 // If an item with a speed dial is updated then update the speed |
|
115 // dials. |
|
116 if (!CheckSpeedDialUpdatesL(aItem) || !aSpeeDailUpdate) |
|
117 { |
|
118 NotifyObserverL(EContactDbObserverEventContactChanged, aItem.Id()); |
|
119 } |
|
120 } |
|
121 break; |
|
122 default: |
|
123 break; |
|
124 }; |
|
125 } |
|
126 |
|
127 |
|
128 /** |
|
129 Delete a Contact item. |
|
130 */ |
|
131 CContactItem* CLplAnalyserProxy::DeleteLC(TContactItemId aItemId, TUint aSessionId, TCntSendEventAction aEventType) |
|
132 { |
|
133 // Delegate delete to generic proxy. |
|
134 CContactItem* item = CLplGenericProxy::DeleteLC(aItemId, aSessionId, aEventType); |
|
135 |
|
136 // Notify observer of the change. |
|
137 switch(item->Type().iUid) |
|
138 { |
|
139 case KUidContactCardTemplateValue: |
|
140 { |
|
141 NotifyObserverL(EContactDbObserverEventTemplateDeleted, item->Id()); |
|
142 // If the prefered template is deleted then do the appropriate |
|
143 // follow up actions. |
|
144 CheckPrefTemplateDeleteL(aItemId); |
|
145 } |
|
146 break; |
|
147 case KUidContactOwnCardValue: |
|
148 { |
|
149 if (aEventType == ESendEvent) |
|
150 { |
|
151 NotifyObserverL(EContactDbObserverEventOwnCardDeleted, item->Id()); |
|
152 } |
|
153 else if (aEventType == ESendUnknownChangesEvent) |
|
154 { |
|
155 NotifyObserverL(EContactDbObserverEventUnknownChanges, KNullContactId); |
|
156 } |
|
157 |
|
158 // If an item with a speed dial is deleted then update the speed |
|
159 // dials. |
|
160 CheckSpeedDialDeletesL(aItemId); |
|
161 // Resets the Own Card ID to be KNullContactId. |
|
162 iProperties.SetOwnCardIdL(KNullContactId); |
|
163 } |
|
164 break; |
|
165 case KUidContactGroupValue: |
|
166 { |
|
167 NotifyObserverL(EContactDbObserverEventGroupDeleted, item->Id()); |
|
168 } |
|
169 break; |
|
170 case KUidContactCardValue: |
|
171 case KUidContactICCEntryValue: |
|
172 { |
|
173 // If an item with a speed dial is deleted then update the speed |
|
174 // dials. |
|
175 (void)CheckSpeedDialDeletesL(aItemId); |
|
176 if (aEventType == ESendEvent) |
|
177 { |
|
178 NotifyObserverL(EContactDbObserverEventContactDeleted, item->Id()); |
|
179 } |
|
180 else if (aEventType == ESendUnknownChangesEvent) |
|
181 { |
|
182 NotifyObserverL(EContactDbObserverEventUnknownChanges, KNullContactId); |
|
183 } |
|
184 } |
|
185 break; |
|
186 default: |
|
187 break; |
|
188 }; |
|
189 |
|
190 // Check if we deleted the current item (managed by initialisation file |
|
191 // manager). |
|
192 iIniManager.DeleteNotifyL(aItemId); |
|
193 |
|
194 return(item); |
|
195 } |
|
196 |
|
197 |
|
198 /** |
|
199 Change the type of an existing Contact item. |
|
200 */ |
|
201 void CLplAnalyserProxy::ChangeTypeL(TContactItemId aItemId, TUid aNewType) |
|
202 { |
|
203 // Delegate type change to generic proxy. |
|
204 CLplGenericProxy::ChangeTypeL(aItemId, aNewType); |
|
205 |
|
206 // If a Contact item is changed to be the Own Card then we need to notify |
|
207 // observers of the change. |
|
208 if (aNewType.iUid == KUidContactOwnCardValue) |
|
209 { |
|
210 NotifyObserverL(EContactDbObserverEventOwnCardChanged, aItemId); |
|
211 } |
|
212 } |
|
213 |
|
214 |
|
215 /** |
|
216 Set the connection ID to be used when notifying observer of a database event |
|
217 (unless a specific connection ID is specified when calling NotifyObserverL()). |
|
218 */ |
|
219 void CLplAnalyserProxy::SetConnectionId(TInt aConnectionId) |
|
220 { |
|
221 iConnectionId = aConnectionId; |
|
222 } |
|
223 |
|
224 |
|
225 /** |
|
226 Notify observer of database event. |
|
227 */ |
|
228 void CLplAnalyserProxy::NotifyObserverL(const TContactDbObserverEventType aType, const TContactItemId aContactId, const TUint aConnectionId) |
|
229 { |
|
230 #if defined(__PROFILE_DEBUG__) |
|
231 RDebug::Print(_L("[CNTMODEL] MTD: CLplAnalyserProxy::NotifyObserverL")); |
|
232 #endif |
|
233 |
|
234 TContactDbObserverEvent event; |
|
235 event.iType = aType; |
|
236 event.iContactId = aContactId; |
|
237 |
|
238 if(!aConnectionId) |
|
239 { |
|
240 event.iConnectionId = iConnectionId; |
|
241 } |
|
242 else |
|
243 { |
|
244 event.iConnectionId = aConnectionId; |
|
245 } |
|
246 |
|
247 iCntDbObserver.HandleDatabaseEventL(event); |
|
248 |
|
249 // Reset connection ID. |
|
250 iConnectionId = 0; |
|
251 } |
|
252 |
|
253 |
|
254 TBool CLplAnalyserProxy::CheckSpeedDialUpdatesL(CContactItem& aItem) |
|
255 { |
|
256 TBool retValue = EFalse; |
|
257 |
|
258 // Check if the specified Contact ID is present in the speed dial array. |
|
259 // The method returns the number of occurances: if zero then this contact |
|
260 // is not in the speed dial table. |
|
261 CArrayFix<TInt>* speedDialIndices = iIniManager.SpeedDialIndicesForContactIdLC(aItem.Id()); |
|
262 |
|
263 // Because this contact has one or more speed dial entries we need to ensure |
|
264 // that the server-side speed dial array is kept up to date with any changes |
|
265 // by the client. |
|
266 for(TInt count = speedDialIndices->Count() -1 ; count>=0; --count) |
|
267 { |
|
268 // So there is at least one speed dial with the particular contact ID. |
|
269 // Fetch speed dial index from array returned by server. |
|
270 TInt speedDialIndex = speedDialIndices->At(count); |
|
271 // Fetch phone number associated with speed dial position. |
|
272 TUid fieldTypeUid = SpeedDialFieldUidFromSpeedDialPosition(speedDialIndex); |
|
273 TInt fieldPos = aItem.CardFields().Find(fieldTypeUid); |
|
274 |
|
275 // Check if the phone number field associated with the speed dial has |
|
276 // been updated. |
|
277 if (fieldPos >= KErrNone) |
|
278 { |
|
279 // Get the requested field (i.e. the field containing the number for |
|
280 // the speed dial). |
|
281 CContactItemField& speeddialField = aItem.CardFields()[fieldPos]; |
|
282 // Check if it is a text field otherwise leave. |
|
283 if (speeddialField.StorageType() != KStorageTypeText) |
|
284 { |
|
285 User::Leave(KErrUnknown); |
|
286 } |
|
287 // Fetch phone number associated with speed dial position. |
|
288 // Truncate it if its length is > KSpeedDialPhoneLength |
|
289 TInt numLen = Min(speeddialField.TextStorage()->Text().Length(), KSpeedDialPhoneLength ); |
|
290 TPtrC phoneNumber(speeddialField.TextStorage()->Text().Mid(0, numLen)); |
|
291 // Update the server with the value of this speed dial. |
|
292 iIniManager.SetSpeedDialIdForPositionL(speedDialIndex, aItem.Id(), phoneNumber, iConnectionId, ETrue); |
|
293 retValue = ETrue; |
|
294 } |
|
295 else |
|
296 { |
|
297 // The phone number field associated with the speed dial has been |
|
298 // deleted. |
|
299 iIniManager.SetSpeedDialIdForPositionL(speedDialIndex, KNullContactId, KNullDesC(), iConnectionId, ETrue); |
|
300 retValue = ETrue; |
|
301 } |
|
302 } |
|
303 |
|
304 CleanupStack::PopAndDestroy(speedDialIndices); |
|
305 |
|
306 return retValue; |
|
307 } |
|
308 |
|
309 |
|
310 TBool CLplAnalyserProxy::CheckSpeedDialDeletesL(TContactItemId aItemId) |
|
311 { |
|
312 TBool retValue = EFalse; |
|
313 // Check if the specified contact ID is present in the speed dial array. |
|
314 // The method returns the number of occurances: if zero then this contact |
|
315 // is not in the speed dial table. |
|
316 CArrayFix<TInt>* speedDialIndices = iIniManager.SpeedDialIndicesForContactIdLC(aItemId); |
|
317 |
|
318 // Because this contact has one or more speed dial entries we need to ensure |
|
319 // that the server-side speed dial array is kept up to date with any changes |
|
320 // by the client. |
|
321 for(TInt count = speedDialIndices->Count() -1 ; count>=0; --count) |
|
322 { |
|
323 // Fetch speed dial index. |
|
324 TInt speedDialIndex = speedDialIndices->At(count); |
|
325 // Update the speed dial. |
|
326 iIniManager.SetSpeedDialIdForPositionL(speedDialIndex, KNullContactId, KNullDesC(), iConnectionId, ETrue); |
|
327 retValue = ETrue; |
|
328 } |
|
329 |
|
330 CleanupStack::PopAndDestroy(speedDialIndices); |
|
331 |
|
332 return retValue; |
|
333 } |
|
334 |
|
335 |
|
336 void CLplAnalyserProxy::CheckPrefTemplateDeleteL(TContactItemId aItemId) |
|
337 { |
|
338 if (iProperties.CardTemplatePrefIdL() == aItemId) |
|
339 { |
|
340 // Make sure the Own Card ID is persisted and up to date. |
|
341 iProperties.SetCardTemplatePrefIdL(KNullContactId); |
|
342 // There was no notification in the old contacts model but there |
|
343 // probably should have been. |
|
344 NotifyObserverL(EContactDbObserverEventPreferredTemplateChanged, aItemId); |
|
345 } |
|
346 } |
|
347 |
|
348 |
|
349 /** |
|
350 Static utility method to map a speed dial index onto a field type UID. |
|
351 |
|
352 Note: this method is duplicated, should be refactored into shared code/library. |
|
353 */ |
|
354 TUid CLplAnalyserProxy::SpeedDialFieldUidFromSpeedDialPosition(TInt aSpeedDialPosition) |
|
355 { |
|
356 TUid fieldTypeUid = KNullUid; |
|
357 switch (aSpeedDialPosition) |
|
358 { |
|
359 case 1: |
|
360 fieldTypeUid = KUidSpeedDialOne; |
|
361 break; |
|
362 case 2: |
|
363 fieldTypeUid = KUidSpeedDialTwo; |
|
364 break; |
|
365 case 3: |
|
366 fieldTypeUid = KUidSpeedDialThree; |
|
367 break; |
|
368 case 4: |
|
369 fieldTypeUid = KUidSpeedDialFour; |
|
370 break; |
|
371 case 5: |
|
372 fieldTypeUid = KUidSpeedDialFive; |
|
373 break; |
|
374 case 6: |
|
375 fieldTypeUid = KUidSpeedDialSix; |
|
376 break; |
|
377 case 7: |
|
378 fieldTypeUid = KUidSpeedDialSeven; |
|
379 break; |
|
380 case 8: |
|
381 fieldTypeUid = KUidSpeedDialEight; |
|
382 break; |
|
383 case 9: |
|
384 fieldTypeUid = KUidSpeedDialNine; |
|
385 break; |
|
386 } |
|
387 return fieldTypeUid; |
|
388 } |
|
389 |
|
390 |
|
391 /** |
|
392 Rollback the current transation in the Persistence Layer. |
|
393 */ |
|
394 void CLplAnalyserProxy::RollbackCurrentTransactionL(TUint aSessionId) |
|
395 { |
|
396 // Delegate rollback to generic proxy. |
|
397 CLplGenericProxy::RollbackCurrentTransactionL(aSessionId); |
|
398 // Notify observer of the rollback. |
|
399 NotifyObserverL(EContactDbObserverEventRollback, 0); |
|
400 } |