|
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: Storage service view implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "cvimpststorageserviceview.h" |
|
21 |
|
22 #include "cvimpststoragecontactlist.h" |
|
23 #include "cvimpststoragecontact.h" |
|
24 #include "mvimpststoragevpbkcontactstore.h" |
|
25 #include "cvimpststoragevpbkserverstore.h" |
|
26 #include "cvimpststoragevpbklocalstore.h" |
|
27 #include "cvimpststoragecontactsorter.h" |
|
28 #include "cvimpststorageactivehandler.h" |
|
29 #include "mvimpststoragecontactsobserver.h" |
|
30 #include "vimpststorageutils.h" |
|
31 |
|
32 #include <MVPbkStoreContact.h> |
|
33 #include <VPbkContactStoreUris.h> |
|
34 #include <TVPbkContactStoreUriPtr.h> |
|
35 #include "vimpstdebugtrace.h" |
|
36 #include "tvimpstconsts.h" |
|
37 #include "mvimpststoragecontact.h" |
|
38 |
|
39 |
|
40 // ============================ MEMBER FUNCTIONS =============================== |
|
41 |
|
42 |
|
43 // panic handler |
|
44 GLDEF_C void Panic( TVIMPSTStoragePanics aPanic ) |
|
45 { |
|
46 User::Panic( KPanicCategory, aPanic ); |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CVIMPSTStorageServiceView::CVIMPSTStorageServiceView |
|
51 // C++ default constructor can NOT contain any code, that |
|
52 // might leave. |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 CVIMPSTStorageServiceView::CVIMPSTStorageServiceView(TUint32 aServiceId) : |
|
56 iServiceId(aServiceId), |
|
57 iOwnContact( NULL ), |
|
58 iUnNamedText( NULL ) |
|
59 { |
|
60 TRACE( T_LIT("CVIMPSTStorageServiceView::CVIMPSTStorageServiceView()") ); |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CVIMPSTStorageServiceView::ConstructL |
|
65 // Symbian 2nd phase constructor can leave. |
|
66 // The constructor also does synchronizing with Phone Book by removing the |
|
67 // deleted elements from the persistent storage |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 void CVIMPSTStorageServiceView::ConstructL(const TDesC& aStoreName, const TDesC& aServiceName) |
|
71 { |
|
72 TRACE( T_LIT("CVIMPSTStorageServiceView::ConstructL() begin") ); |
|
73 |
|
74 iActiveHandler = CVIMPSTStorageActiveHandler::NewL(this); |
|
75 |
|
76 // create sorter for contacts |
|
77 iContactSorter = CVIMPSTStorageContactSorter::NewL(); |
|
78 |
|
79 //set the sorting algorithem to order by presence. |
|
80 iContactSorter->SetSortAlgorithm( MVIMPSTStorageContact::ECompareByPresence); |
|
81 |
|
82 TRACE( T_LIT("SubServiceType() Type : %S"), &aStoreName ); |
|
83 //find whether its a local store or xsp store |
|
84 if ( VPbkContactStoreUris::DefaultCntDbUri().CompareC( aStoreName, 1, NULL ) |
|
85 != 0 ) |
|
86 { |
|
87 TRACE( T_LIT("CVIMPSTStorageServiceView::ConstructL() service store created") ); |
|
88 //Create XSP Store |
|
89 iVPbkContactStore = |
|
90 CVIMPSTStorageVPbkServerStore::NewL(aStoreName,aServiceName ,*this ); |
|
91 } |
|
92 else |
|
93 { |
|
94 TRACE( T_LIT("CVIMPSTStorageServiceView::ConstructL() local store created ") ); |
|
95 //Create Local Contacts.cdb store |
|
96 iVPbkContactStore = CVIMPSTStorageVPbkLocalStore::NewL(VPbkContactStoreUris::DefaultCntDbUri(), |
|
97 aServiceName, |
|
98 *this ); |
|
99 } |
|
100 TRACE( T_LIT("CVIMPSTStorageServiceView::ConstructL() end") );; |
|
101 } |
|
102 |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // CVIMPSTStorageServiceView::NewL |
|
106 // Two-phased constructor. |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 CVIMPSTStorageServiceView* CVIMPSTStorageServiceView::NewL(TUint32 aServiceId, |
|
110 const TDesC& aStoreName, |
|
111 const TDesC& aServiceName) |
|
112 { |
|
113 TRACE( T_LIT("CVIMPSTStorageServiceView::NewL() begin") ); |
|
114 |
|
115 CVIMPSTStorageServiceView* self = new( ELeave ) CVIMPSTStorageServiceView(aServiceId); |
|
116 CleanupStack::PushL( self ); |
|
117 self->ConstructL(aStoreName, aServiceName); |
|
118 CleanupStack::Pop( self ); |
|
119 TRACE( T_LIT("CVIMPSTStorageServiceView::NewL() end") ); |
|
120 return self; |
|
121 } |
|
122 // ----------------------------------------------------------------------------- |
|
123 // CVIMPSTStorageServiceView::~CVIMPSTStorageServiceView |
|
124 // Two-phased constructor. |
|
125 // ----------------------------------------------------------------------------- |
|
126 // Destructor |
|
127 CVIMPSTStorageServiceView::~CVIMPSTStorageServiceView() |
|
128 { |
|
129 TRACE( T_LIT("CVIMPSTStorageServiceView::~CVIMPSTStorageServiceView() begin") ); |
|
130 if( iActiveHandler ) |
|
131 { |
|
132 iActiveHandler->Cancel(); |
|
133 delete iActiveHandler; |
|
134 } |
|
135 |
|
136 iContactListArray.ResetAndDestroy(); |
|
137 |
|
138 delete iOwnContact; |
|
139 delete iContactSorter; |
|
140 delete iVPbkContactStore; |
|
141 iContactObservers.Reset(); |
|
142 iContactObservers.Close(); |
|
143 |
|
144 if(iUnNamedText) |
|
145 { |
|
146 delete iUnNamedText; |
|
147 iUnNamedText = NULL; |
|
148 } |
|
149 |
|
150 TRACE( T_LIT("CVIMPSTStorageServiceView::~CVIMPSTStorageServiceView() end") ); |
|
151 } |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CVIMPSTStorageServiceView::AddObserverL |
|
154 // From MVIMPSTStorageServiceView |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 void CVIMPSTStorageServiceView::AddObserverL( MVIMPSTStorageContactsObserver* |
|
158 aObserver ) |
|
159 { |
|
160 TRACE( T_LIT("CVIMPSTStorageServiceView::AddObserverL() begin") ); |
|
161 User::LeaveIfError( aObserver ? KErrNone : KErrArgument ); |
|
162 TInt index = iContactObservers.Find( aObserver ); |
|
163 if( index == KErrNotFound ) |
|
164 { |
|
165 TRACE( T_LIT("CVIMPSTStorageServiceView::AddObserverL() aObserver added ") ); |
|
166 User::LeaveIfError( iContactObservers.Append( aObserver ) ); |
|
167 } |
|
168 TRACE( T_LIT("CVIMPSTStorageServiceView::AddObserverL() end") ); |
|
169 } |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // CVIMPSTStorageServiceView::RemoveObserverL |
|
173 // From MVIMPSTStorageServiceView |
|
174 // ----------------------------------------------------------------------------- |
|
175 void CVIMPSTStorageServiceView::RemoveObserver( MVIMPSTStorageContactsObserver* |
|
176 aObserver ) |
|
177 { |
|
178 TRACE( T_LIT("CVIMPSTStorageServiceView::RemoveObserver() begin") ); |
|
179 __ASSERT_ALWAYS( aObserver, Panic( EObserverIsNull )); |
|
180 const TInt index( iContactObservers.Find( aObserver ) ); |
|
181 if ( index >=0) |
|
182 { |
|
183 TRACE( T_LIT("CVIMPSTStorageServiceView::RemoveObserver() aObserver found") ); |
|
184 iContactObservers.Remove( index ); |
|
185 iContactObservers.Compress(); |
|
186 } |
|
187 TRACE( T_LIT("CVIMPSTStorageServiceView::RemoveObserver() begin") ); |
|
188 } |
|
189 |
|
190 // ----------------------------------------------------------------------------- |
|
191 // CVIMPSTStorageServiceView::SetUnnamedTextL |
|
192 // From MVIMPSTStorageServiceView |
|
193 // ----------------------------------------------------------------------------- |
|
194 void CVIMPSTStorageServiceView::SetUnnamedTextL(HBufC* aUnnamedText ) |
|
195 { |
|
196 // takes ownership |
|
197 iUnNamedText = aUnnamedText; |
|
198 } |
|
199 // ----------------------------------------------------------------------------- |
|
200 // CVIMPSTStorageServiceView::CreateContactListL |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 MVIMPSTStorageContactList* CVIMPSTStorageServiceView::CreateContactListL( |
|
204 const TDesC& aContactListId, |
|
205 const TDesC& aDisplayName ) |
|
206 { |
|
207 TRACE( T_LIT("CVIMPSTStorageServiceView::CreateContactListL() begin") ); |
|
208 CVIMPSTStorageContactList* contactList = |
|
209 CVIMPSTStorageContactList::NewLC(*iContactSorter, |
|
210 aContactListId, |
|
211 aDisplayName ); |
|
212 |
|
213 TIdentityRelation< CVIMPSTStorageContactList > findBy( |
|
214 CVIMPSTStorageServiceView::ContactListFindByContactListId); |
|
215 TInt indexOfList( iContactListArray.Find( contactList, findBy ) ); |
|
216 if( indexOfList == KErrNotFound ) |
|
217 { |
|
218 TRACE( T_LIT("CVIMPSTStorageServiceView::CreateContactListL() list not exist in list") ); |
|
219 TLinearOrder< CVIMPSTStorageContactList > order( |
|
220 CVIMPSTStorageServiceView::ContactListOrderByDisplayName ); |
|
221 iContactListArray.InsertInOrderAllowRepeats( contactList, order ); |
|
222 CleanupStack::Pop( contactList ); |
|
223 TRACE( T_LIT("CVIMPSTStorageServiceView::CreateContactListL() new list created") ); |
|
224 } |
|
225 else |
|
226 { |
|
227 TRACE( T_LIT("CVIMPSTStorageServiceView::CreateContactListL() list already exist in list") ); |
|
228 CleanupStack::PopAndDestroy( contactList ); |
|
229 contactList = iContactListArray[ indexOfList ]; |
|
230 } |
|
231 TRACE( T_LIT("CVIMPSTStorageServiceView::CreateContactListL() end") ); |
|
232 return contactList; |
|
233 } |
|
234 |
|
235 // ----------------------------------------------------------------------------- |
|
236 // CVIMPSTStorageServiceView::RemoveContactList |
|
237 // ----------------------------------------------------------------------------- |
|
238 // |
|
239 void CVIMPSTStorageServiceView::RemoveContactList( const TDesC& aContactListId ) |
|
240 { |
|
241 TRACE( T_LIT("CVIMPSTStorageServiceView::RemoveContactList() begin") ); |
|
242 TInt pos( FindContactListById( aContactListId ) ); |
|
243 if( pos >= 0 ) |
|
244 { |
|
245 TRACE( T_LIT("CVIMPSTStorageServiceView::RemoveContactList() aContactListId found") ); |
|
246 delete iContactListArray[ pos ]; |
|
247 iContactListArray.Remove( pos ); |
|
248 iContactListArray.Compress(); |
|
249 } |
|
250 TRACE( T_LIT("CVIMPSTStorageServiceView::RemoveContactList() end") ); |
|
251 } |
|
252 |
|
253 // ----------------------------------------------------------------------------- |
|
254 // CVIMPSTStorageServiceView::ListCount |
|
255 // Count of contactlists |
|
256 // ----------------------------------------------------------------------------- |
|
257 // |
|
258 TInt CVIMPSTStorageServiceView::ListCount() const |
|
259 { |
|
260 TRACE( T_LIT("CVIMPSTStorageServiceView::ListCount()") ); |
|
261 return iContactListArray.Count(); |
|
262 } |
|
263 |
|
264 // ----------------------------------------------------------------------------- |
|
265 // CVIMPSTStorageServiceView::ListAt |
|
266 // Reference to contact list |
|
267 // ----------------------------------------------------------------------------- |
|
268 // |
|
269 MVIMPSTStorageContactList& CVIMPSTStorageServiceView::ListAt( TInt aIndex ) const |
|
270 { |
|
271 TRACE( T_LIT("CVIMPSTStorageServiceView::ListAt() begin") ); |
|
272 // User::LeaveIfError( aIndex < iContactListArray.Count() ? KErrNone : KErrArgument ); |
|
273 __ASSERT_ALWAYS( (aIndex < iContactListArray.Count() && aIndex >=0 ), Panic( EContactsArrayOutOfSync )); |
|
274 TRACE( T_LIT("CVIMPSTStorageServiceView::ListAt() end") ); |
|
275 return *iContactListArray[ aIndex ]; |
|
276 } |
|
277 // ----------------------------------------------------------------------------- |
|
278 // CVIMPSTStorageServiceView::ContactCount |
|
279 // Count of contacts |
|
280 // ----------------------------------------------------------------------------- |
|
281 // |
|
282 TInt CVIMPSTStorageServiceView::ContactCount( TBool aSkipOfflineContacts ) const |
|
283 { |
|
284 TRACE( T_LIT("CVIMPSTStorageServiceView::ListAt() begin") ); |
|
285 TInt contactCount( 0 ); |
|
286 TInt count( iContactListArray.Count() ); |
|
287 for( TInt a( 0 ); a < count; ++a ) |
|
288 { |
|
289 contactCount += iContactListArray[ a ]->ContactCount( aSkipOfflineContacts, |
|
290 EFalse ); |
|
291 } |
|
292 TRACE( T_LIT("CVIMPSTStorageServiceView::ListAt() contactCount = %d") ,contactCount ); |
|
293 TRACE( T_LIT("CVIMPSTStorageServiceView::ListAt() end") ); |
|
294 return contactCount; |
|
295 } |
|
296 |
|
297 // ----------------------------------------------------------------------------- |
|
298 // CVIMPSTStorageServiceView::UpdatepresenceL |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 MVIMPSTStorageContact* CVIMPSTStorageServiceView::UpdatePresenceL( |
|
302 const TDesC& aContactId, |
|
303 TVIMPSTEnums::TOnlineStatus aStatus, |
|
304 const TDesC& aStatusText, |
|
305 const TDesC8& aAvatarData, |
|
306 TBool aIsClearingAvatar /*= EFalse*/) |
|
307 { |
|
308 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdatePresenceL() begin") ); |
|
309 MVIMPSTStorageContact* contact = NULL; |
|
310 if( iOwnContact && ( aContactId.Compare( iOwnContact->UserId() ) == 0 ) ) |
|
311 { |
|
312 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdatePresenceL() own Item presence") ); |
|
313 if( aAvatarData.Compare(iOwnContact->AvatarContent() ) != 0 ) |
|
314 { |
|
315 if((aIsClearingAvatar)||(aAvatarData.Length() > 0)) |
|
316 { |
|
317 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdatePresenceL() own avatar change NotifyAllObserversL") ); |
|
318 iOwnContact->SetAvatarContentL( aAvatarData ,*iVPbkContactStore ); |
|
319 NotifyAllObserversL(TVIMPSTEnums::EStorageAvatarChange,NULL,iOwnContact,0); |
|
320 } |
|
321 } |
|
322 if( ( iOwnContact->OnlineStatus() != aStatus ) || ( aStatusText.Compare( iOwnContact->StatusText() ) != 0 ) ) |
|
323 { |
|
324 // own presence has changes |
|
325 // update to own presence |
|
326 iOwnContact->SetOnlineStatus( aStatus ); |
|
327 iOwnContact->SetStatusTextL(aStatusText); |
|
328 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdatePresenceL() own presene NotifyAllObserversL") ); |
|
329 NotifyAllObserversL(TVIMPSTEnums::EStorageOwnPresenceChange,NULL, iOwnContact,0); |
|
330 } |
|
331 contact = iOwnContact; |
|
332 } |
|
333 else |
|
334 { |
|
335 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdatePresenceL() contact item ") ); |
|
336 contact = FindContactByUserId( aContactId ); |
|
337 if(contact) |
|
338 { |
|
339 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdatePresenceL() contact exist ") ); |
|
340 TInt index = KErrNotFound; |
|
341 TVIMPSTEnums::TOnlineStatus oldOnlineStatus = contact->OnlineStatus(); |
|
342 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdatePresenceL() contact oldOnlineStatus = %d"), oldOnlineStatus ); |
|
343 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdatePresenceL() contact new presence = %d"), aStatus ); |
|
344 //status text can be different for the sam status hence not inside the if condition. |
|
345 if( oldOnlineStatus != aStatus ) |
|
346 { |
|
347 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdatePresenceL() contact presence change ") ); |
|
348 contact->SetOnlineStatus( aStatus ); |
|
349 TInt count = iContactListArray.Count(); |
|
350 for(TInt i = 0; i < count; i++) |
|
351 { |
|
352 index = iContactListArray[i]->FindIndexOfContact(contact); |
|
353 if(KErrNotFound != index ) |
|
354 { |
|
355 iContactListArray[i]->ResortContact(contact); |
|
356 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdatePresenceL() contact ResortContact ") ); |
|
357 // get the index of the sorted contact, as after sorting the |
|
358 // index would have changed based on presence. |
|
359 // break after the contact list is found and the contact is found |
|
360 break; |
|
361 } |
|
362 } |
|
363 contact->SetStatusTextL(aStatusText); |
|
364 if(aAvatarData.Length()>0) |
|
365 { |
|
366 TInt oldIndex = IndexOfContact (contact); |
|
367 contact->SetAvatarContentL( aAvatarData ,*iVPbkContactStore); |
|
368 NotifyAllObserversL(TVIMPSTEnums::EStorageAvatarChange,NULL, contact, oldIndex ); |
|
369 } |
|
370 |
|
371 // once this event occued ,apply the sorting |
|
372 NotifyAllObserversWithDelay(TVIMPSTEnums::EStorageMultiplePresenceChange,NULL, contact, -1); |
|
373 } |
|
374 else if( aStatusText.Compare( contact->StatusText() ) != 0 ) |
|
375 { |
|
376 TInt oldIndex = IndexOfContact (contact); |
|
377 contact->SetStatusTextL(aStatusText); |
|
378 NotifyAllObserversL(TVIMPSTEnums::EStoragePresenceChange,NULL, contact, oldIndex ); |
|
379 } |
|
380 else if( aAvatarData.Length() && aAvatarData.Compare( contact->AvatarContent() ) != 0 ) |
|
381 { |
|
382 TInt oldIndex = IndexOfContact (contact); |
|
383 contact->SetAvatarContentL( aAvatarData ,*iVPbkContactStore); |
|
384 NotifyAllObserversL(TVIMPSTEnums::EStorageAvatarChange,NULL, contact, oldIndex ); |
|
385 } |
|
386 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdatePresenceL() aStatusText = %S "), &aStatusText ); |
|
387 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdatePresenceL() NotifyAllObserversL called") ); |
|
388 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdatePresenceL() NotifyAllObserversL finish") ); |
|
389 } |
|
390 } |
|
391 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdatePresenceL() end") ); |
|
392 return contact; |
|
393 } |
|
394 |
|
395 // ----------------------------------------------------------------------------- |
|
396 // CVIMPSTStorageServiceView::UpdateAvatarL |
|
397 // ----------------------------------------------------------------------------- |
|
398 // |
|
399 MVIMPSTStorageContact* CVIMPSTStorageServiceView::UpdateAvatarL(const TDesC& aContactId, |
|
400 const TDesC8& aAvatarData ) |
|
401 { |
|
402 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdateAvatarL() begin") ); |
|
403 MVIMPSTStorageContact* contact = NULL; |
|
404 if( iOwnContact && ( aContactId.Compare( iOwnContact->UserId() ) == 0 ) ) |
|
405 { |
|
406 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdateAvatarL() own avatar") ); |
|
407 iOwnContact->SetAvatarContentL( aAvatarData ,*iVPbkContactStore); |
|
408 NotifyAllObserversL(TVIMPSTEnums::EStorageOwnPresenceChange,NULL, iOwnContact,0); |
|
409 contact = iOwnContact; |
|
410 } |
|
411 else |
|
412 { |
|
413 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdateAvatarL() buddy avatar") ); |
|
414 contact = FindContactByUserId( aContactId ); |
|
415 if(contact) |
|
416 { |
|
417 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdateAvatarL() contact exit") ); |
|
418 contact->SetAvatarContentL( aAvatarData ,*iVPbkContactStore); |
|
419 TInt index = IndexOfContact(contact); |
|
420 NotifyAllObserversL(TVIMPSTEnums::EStorageAvatarChange,NULL, contact,index); |
|
421 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdateAvatarL() NotifyAllObserversL called") ); |
|
422 } |
|
423 } |
|
424 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdateAvatarL() end") ); |
|
425 return contact; |
|
426 } |
|
427 |
|
428 // ----------------------------------------------------------------------------- |
|
429 // CVIMPSTStorageServiceView::FindContactListInternal |
|
430 // ----------------------------------------------------------------------------- |
|
431 // |
|
432 CVIMPSTStorageContactList* CVIMPSTStorageServiceView::FindContactListInternal( |
|
433 const TDesC& aListId ) |
|
434 { |
|
435 TRACE( T_LIT("CVIMPSTStorageServiceView::FindContactListInternal begin") ); |
|
436 TInt contactListIndex( FindContactListById( aListId ) ); |
|
437 TRACE( T_LIT("CVIMPSTStorageServiceView::FindContactListInternal end ") ); |
|
438 return ( contactListIndex >= 0 ? iContactListArray[ contactListIndex ] : NULL ); |
|
439 } |
|
440 |
|
441 // ----------------------------------------------------------------------------- |
|
442 // CVIMPSTStorageServiceView::FindContactList |
|
443 // ----------------------------------------------------------------------------- |
|
444 // |
|
445 MVIMPSTStorageContactList* CVIMPSTStorageServiceView::FindContactList( const TDesC& aListId ) |
|
446 { |
|
447 TRACE( T_LIT("CVIMPSTStorageServiceView::FindContactList") ); |
|
448 return FindContactListInternal( aListId ); |
|
449 } |
|
450 |
|
451 // ----------------------------------------------------------------------------- |
|
452 // CVIMPSTStorageServiceView::FindContactListById |
|
453 // ----------------------------------------------------------------------------- |
|
454 // |
|
455 TInt CVIMPSTStorageServiceView::FindContactListById(const TDesC& aListId ) |
|
456 { |
|
457 TRACE( T_LIT("CVIMPSTStorageServiceView::FindContactList begin") ); |
|
458 TInt index = KErrNotFound; |
|
459 TInt count( iContactListArray.Count() ); |
|
460 TRACE( T_LIT("CVIMPSTStorageServiceView::FindContactList count = %d"), count ); |
|
461 for( TInt i= 0 ; i < count ; i++ ) |
|
462 { |
|
463 if( KErrNone == VIMPSTStorageUtils::NeutralCompare( |
|
464 aListId, |
|
465 iContactListArray[ i ]->ListId(), EFalse ) ) |
|
466 { |
|
467 TRACE( T_LIT("CVIMPSTStorageServiceView::FindContactList contact list found") ); |
|
468 index = i; |
|
469 break; |
|
470 } |
|
471 } |
|
472 TRACE( T_LIT("CVIMPSTStorageServiceView::FindContactList end") ); |
|
473 return index; |
|
474 } |
|
475 |
|
476 // ----------------------------------------------------------------------------- |
|
477 // CVIMPSTStorageServiceView::FindContactListById |
|
478 // ----------------------------------------------------------------------------- |
|
479 // |
|
480 MVIMPSTStorageContact* CVIMPSTStorageServiceView::FindContactByLink(const MVPbkContactLink& aContactLink ) |
|
481 { |
|
482 TRACE( T_LIT("CVIMPSTStorageServiceView::FindContactByLink begin") ); |
|
483 MVIMPSTStorageContact* contact = NULL; |
|
484 TInt count( iContactListArray.Count() ); |
|
485 for( TInt i= 0 ; i < count ; i++ ) |
|
486 { |
|
487 CVIMPSTStorageContactList* contactList = iContactListArray[ i ]; |
|
488 contact = contactList->FindContactByContactLink( aContactLink ); |
|
489 if( contact ) |
|
490 { |
|
491 TRACE( T_LIT("CVIMPSTStorageServiceView::FindContactByLink contact found = %d "), i ); |
|
492 break; |
|
493 } |
|
494 } |
|
495 TRACE( T_LIT("CVIMPSTStorageServiceView::FindContactByLink end") ); |
|
496 return contact; |
|
497 } |
|
498 |
|
499 // ----------------------------------------------------------------------------- |
|
500 // CVIMPSTStorageServiceView::GetServiceId |
|
501 // ----------------------------------------------------------------------------- |
|
502 // |
|
503 TUint32 CVIMPSTStorageServiceView::GetServiceId() |
|
504 { |
|
505 TRACE( T_LIT("CVIMPSTStorageServiceView::GetServiceId") ); |
|
506 return iServiceId; |
|
507 } |
|
508 |
|
509 // ----------------------------------------------------------------------------- |
|
510 // CVIMPSTStorageServiceView::LocalStore |
|
511 // ----------------------------------------------------------------------------- |
|
512 // |
|
513 TBool CVIMPSTStorageServiceView::IsLocalStore() const |
|
514 { |
|
515 TRACE( T_LIT("CVIMPSTStorageServiceView::IsLocalStore") ); |
|
516 return iVPbkContactStore->LocalStore(); |
|
517 } |
|
518 // ----------------------------------------------------------------------------- |
|
519 // CVIMPSTStorageServiceView::OwnContactL |
|
520 // ----------------------------------------------------------------------------- |
|
521 // |
|
522 MVIMPSTStorageContact& CVIMPSTStorageServiceView::OwnContactL() |
|
523 { |
|
524 TRACE( T_LIT("CVIMPSTStorageServiceView::OwnContact begin") ); |
|
525 if( !iOwnContact ) |
|
526 { |
|
527 iOwnContact = CVIMPSTStorageContact::NewL(KNullDesC, |
|
528 KNullDesC ) ; |
|
529 } |
|
530 TRACE( T_LIT("CVIMPSTStorageServiceView::OwnContact end") ); |
|
531 return *iOwnContact; |
|
532 } |
|
533 |
|
534 // ----------------------------------------------------------------------------- |
|
535 // CVIMPSTStorageServiceView::SetOwnUserIdL |
|
536 // ----------------------------------------------------------------------------- |
|
537 // |
|
538 void CVIMPSTStorageServiceView::SetOwnUserIdL(const TDesC& aUserId ) |
|
539 { |
|
540 TRACE( T_LIT("CVIMPSTStorageServiceView::SetOwnUserIdL begin") ); |
|
541 if( !iOwnContact ) |
|
542 { |
|
543 iOwnContact = CVIMPSTStorageContact::NewL(aUserId, |
|
544 KNullDesC |
|
545 ) ; |
|
546 TRACE( T_LIT("CVIMPSTStorageServiceView::SetOwnUserIdL iOwnContact created") ); |
|
547 } |
|
548 else if( aUserId.Compare( iOwnContact->UserId() ) != 0 ) |
|
549 { |
|
550 TRACE( T_LIT("CVIMPSTStorageServiceView::SetOwnUserIdL iOwnContact was existing") ); |
|
551 iOwnContact->SetUserIdL( aUserId ); |
|
552 iOwnContact->SetAvatarContentL(KNullDesC8,*iVPbkContactStore ); |
|
553 iVPbkContactStore->RemoveAllVPbkContactsL(); // if user id is changed remove all contacts |
|
554 NotifyAllObserversL( TVIMPSTEnums::EStorageEventOwnUserChanged,NULL,iOwnContact,0 ); |
|
555 TRACE( T_LIT("CVIMPSTStorageServiceView::SetOwnUserIdL NotifyAllObserversL delivered") ); |
|
556 } |
|
557 TRACE( T_LIT("CVIMPSTStorageServiceView::SetOwnUserIdL end") ); |
|
558 } |
|
559 // ----------------------------------------------------------------------------- |
|
560 // CVIMPSTStorageServiceView::FindContactByUserId |
|
561 // From MVIMPSTStorageServiceView. |
|
562 // Try to load with given ID, return NULL if not found. |
|
563 // ----------------------------------------------------------------------------- |
|
564 MVIMPSTStorageContact* CVIMPSTStorageServiceView::FindContactByUserId( const TDesC& aUserId ) |
|
565 { |
|
566 TRACE( T_LIT("CVIMPSTStorageServiceView::FindContactByUserId begin") ); |
|
567 MVIMPSTStorageContact* contact = NULL; |
|
568 CVIMPSTStorageContactList* contactList = NULL; |
|
569 TInt count( iContactListArray.Count() ); |
|
570 for( TInt a( 0 ); a < count; ++a ) |
|
571 { |
|
572 contactList = iContactListArray[ a ]; |
|
573 contact = contactList->FindContact( aUserId ); |
|
574 if( contact ) |
|
575 { |
|
576 TRACE( T_LIT("CVIMPSTStorageServiceView::FindContactByUserId contact found ") ); |
|
577 break; |
|
578 } |
|
579 } |
|
580 TRACE( T_LIT("CVIMPSTStorageServiceView::FindContactByUserId end") ); |
|
581 return contact; |
|
582 } |
|
583 // ----------------------------------------------------------------------------- |
|
584 // CVIMPSTStorageServiceView::FindContactByUserId |
|
585 // From MVIMPSTStorageServiceView. |
|
586 // Try to load with given ID, return NULL if not found. |
|
587 // ----------------------------------------------------------------------------- |
|
588 MVIMPSTStorageContact* CVIMPSTStorageServiceView::FindCacheContactByUserId( const TDesC& aUserId ) |
|
589 { |
|
590 TRACE( T_LIT("CVIMPSTStorageServiceView::FindCacheContactByUserId") ); |
|
591 return FindContactByUserId( aUserId ); |
|
592 } |
|
593 |
|
594 // ----------------------------------------------------------------------------- |
|
595 // CVIMPSTStorageServiceView::FindCacheContactByLink |
|
596 // From MVIMPSTStorageServiceView. |
|
597 // Try to load with given ID, return NULL if not found. |
|
598 // ----------------------------------------------------------------------------- |
|
599 MVIMPSTStorageContact* CVIMPSTStorageServiceView::FindCacheContactByLink(const MVPbkContactLink& aContactLink ) |
|
600 { |
|
601 TRACE( T_LIT("CVIMPSTStorageServiceView::FindCacheContactByLink ") ); |
|
602 return FindContactByLink( aContactLink ); |
|
603 } |
|
604 // ----------------------------------------------------------------------------- |
|
605 // CVIMPSTStorageServiceView::CreateContactL |
|
606 // ----------------------------------------------------------------------------- |
|
607 // |
|
608 MVIMPSTStorageContact* CVIMPSTStorageServiceView::CreateNewContactL(const TDesC& aUserId, |
|
609 const TDesC& aDisplayName /*= KNullDesC*/, |
|
610 TBool aIsInvitationItem /*=EFalse*/, |
|
611 TBool aInvitationAutoAccept /*= EFalse */) |
|
612 { |
|
613 TRACE( T_LIT("CVIMPSTStorageServiceView::CreateNewContactL begin") ); |
|
614 // This will create a contact in the CDB file. It returns MVPbkContactLink link to the CDB file. |
|
615 MVIMPSTStorageContact* contact = FindCacheContactByUserId( aUserId ); |
|
616 if( !contact ) |
|
617 { |
|
618 iIsInvitationItem = aIsInvitationItem; |
|
619 TRACE( T_LIT("CVIMPSTStorageServiceView::CreateNewContactL contact does not exist in list") ); |
|
620 iVPbkContactStore->CreateVPbkContactL( aUserId ,aDisplayName, aInvitationAutoAccept ); |
|
621 TRACE( T_LIT("CVIMPSTStorageServiceView::CreateNewContactL new contact created") ); |
|
622 } |
|
623 TRACE( T_LIT("CVIMPSTStorageServiceView::CreateNewContactL end") ); |
|
624 return contact; |
|
625 } |
|
626 |
|
627 // ----------------------------------------------------------------------------- |
|
628 // CVIMPSTStorageServiceView::CreateNewFetchContactsL |
|
629 // ----------------------------------------------------------------------------- |
|
630 // |
|
631 void CVIMPSTStorageServiceView::CreateNewFetchContactsL( RArray <TPtrC> &aFirstNameList, |
|
632 RArray <TPtrC> &aServiceField ) |
|
633 { |
|
634 TRACE( T_LIT("CVIMPSTStorageServiceView::CreateNewFetchContactsL begin") ); |
|
635 if( !iVPbkContactStore->LocalStore() ) |
|
636 { |
|
637 RemoveAllCacheContactsL(); |
|
638 } |
|
639 iVPbkContactStore->AddVPbkFetchContactsL( aFirstNameList, aServiceField ); |
|
640 TRACE( T_LIT("CVIMPSTStorageServiceView::CreateNewFetchContactsL end") ); |
|
641 } |
|
642 |
|
643 // ----------------------------------------------------------------------------- |
|
644 // CVIMPSTStorageServiceView::RemoveContactL |
|
645 // From MVIMPSTStorageServiceView. |
|
646 // Try to load with given ID, return NULL if not found. |
|
647 // ----------------------------------------------------------------------------- |
|
648 |
|
649 TInt CVIMPSTStorageServiceView::RemoveContactL( MVIMPSTStorageContact* aContact ) |
|
650 { |
|
651 TRACE( T_LIT("CVIMPSTStorageServiceView::RemoveContactL begin") ); |
|
652 TInt error = KErrArgument; |
|
653 if( aContact ) |
|
654 { |
|
655 TRACE( T_LIT("CVIMPSTStorageServiceView::RemoveContactL contact found") ); |
|
656 error = iVPbkContactStore->RemoveVPbkContactL( *aContact->ContactLink() ); |
|
657 } |
|
658 TRACE( T_LIT("CVIMPSTStorageServiceView::RemoveContactL end") ); |
|
659 return error; |
|
660 } |
|
661 |
|
662 |
|
663 // ----------------------------------------------------------------------------- |
|
664 // CVIMPSTStorageServiceView::RetriveLinkXSPIdsL |
|
665 // ----------------------------------------------------------------------------- |
|
666 // |
|
667 TInt CVIMPSTStorageServiceView::RetriveLinkXSPIdsL(const TDesC8& aContactPackLink ) |
|
668 { |
|
669 TRACE( T_LIT("CVIMPSTStorageServiceView::RetriveLinkXSPIdsL") ); |
|
670 // return the no of retrived xsp of contacts |
|
671 return iVPbkContactStore->RetrieveVPbkXSPIdL( aContactPackLink ); |
|
672 } |
|
673 |
|
674 // --------------------------------------------------------------------------- |
|
675 // CVIMPSTStorageServiceView::GetRetrieveXSPIdL |
|
676 // --------------------------------------------------------------------------- |
|
677 // |
|
678 const TDesC& CVIMPSTStorageServiceView::GetRetrieveXSPIdL(TInt aIndex ) |
|
679 { |
|
680 TRACE( T_LIT("CVIMPSTStorageServiceView::GetRetrieveXSPIdL aIndex = %d"),aIndex ); |
|
681 return iVPbkContactStore->GetRetrieveVPbkXSPIdL( aIndex ); |
|
682 } |
|
683 |
|
684 // ----------------------------------------------------------------------------- |
|
685 // CVIMPSTStorageServiceView::CreateNewContactFromRetrivedIdL |
|
686 // ----------------------------------------------------------------------------- |
|
687 // |
|
688 TInt CVIMPSTStorageServiceView::CreateNewContactFromRetrivedIdL( TInt aIndexToUse ) |
|
689 { |
|
690 TRACE( T_LIT("CVIMPSTStorageServiceView::CreateNewContactFromRetrivedIdL aIndexToUse = %d"),aIndexToUse ); |
|
691 // This will create a contact in the CDB file. It returns MVPbkContactLink link to the CDB file. |
|
692 return iVPbkContactStore->CreateRetriveVPbkContactL( aIndexToUse ); |
|
693 } |
|
694 // ----------------------------------------------------------------------------- |
|
695 // CVIMPSTStorageServiceView::DeleteNewContactFromRetrivedIdL |
|
696 // ----------------------------------------------------------------------------- |
|
697 // |
|
698 TInt CVIMPSTStorageServiceView::DeleteNewContactFromRetrivedIdL( TInt aIndexToUse ) |
|
699 { |
|
700 TRACE( T_LIT("CVIMPSTStorageServiceView::DeleteNewContactFromRetrivedIdL aIndexToUse = %d"),aIndexToUse ); |
|
701 // This will create a contact in the CDB file. It returns MVPbkContactLink link to the CDB file. |
|
702 return iVPbkContactStore->deleteRetriveVPbkContactL( aIndexToUse ); |
|
703 } |
|
704 |
|
705 // ---------------------------------------------------------- |
|
706 // CVIMPSTStorageServiceView::DeleteDatabaseL |
|
707 // ---------------------------------------------------------- |
|
708 void CVIMPSTStorageServiceView::DeleteDatabaseL() |
|
709 { |
|
710 TRACE( T_LIT("CVIMPSTStorageServiceView::DeleteDatabaseL") ); |
|
711 iVPbkContactStore->DeleteDatabaseL(); |
|
712 } |
|
713 |
|
714 //================================================== from writer interface======================= |
|
715 // ----------------------------------------------------------------------------- |
|
716 // CVIMPSTStorageServiceView::UpdateCacheContactL |
|
717 // ----------------------------------------------------------------------------- |
|
718 // |
|
719 MVIMPSTStorageContact* CVIMPSTStorageServiceView::UpdateCacheContactL(const MVPbkContactLink& aContactLink, |
|
720 const TDesC& aUserId, |
|
721 const TDesC& aDisplayName, |
|
722 const TDesC8& aAvatarContent) |
|
723 { |
|
724 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdateCacheContactL begin") ); |
|
725 MVIMPSTStorageContact* contact = FindContactByLink(aContactLink); |
|
726 if( contact ) |
|
727 { |
|
728 TInt oldIndex = IndexOfContact( contact ); |
|
729 TBool sortNeeded = EFalse; |
|
730 if( contact->UserId().Compare( aUserId) != 0 ) |
|
731 { |
|
732 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdateCacheContactL user id changed") ); |
|
733 NotifyAllObserversL( TVIMPSTEnums::EStorageEventUserIdPreChange,NULL, contact,oldIndex); |
|
734 contact->SetUserIdL( aUserId ); |
|
735 if(aUserId.Length()== 0) |
|
736 { |
|
737 sortNeeded = ETrue; |
|
738 contact->SetOnlineStatus(TVIMPSTEnums::EUnknown); |
|
739 } |
|
740 NotifyAllObserversL( TVIMPSTEnums::EStorageEventUserIdPostChange,NULL, contact,oldIndex); |
|
741 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdateCacheContactL NotifyAllObserversL delivered") ); |
|
742 } |
|
743 if(contact->Name().Compare(aDisplayName) != 0 ) |
|
744 { |
|
745 sortNeeded = ETrue; |
|
746 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdateCacheContactL display name changed") ); |
|
747 if( aDisplayName.Length() <= 0 && iUnNamedText ) |
|
748 { |
|
749 contact->SetNameL( *iUnNamedText ); |
|
750 } |
|
751 else |
|
752 { |
|
753 contact->SetNameL( aDisplayName ); |
|
754 } |
|
755 } |
|
756 if(sortNeeded) |
|
757 { |
|
758 TInt index = KErrNotFound; |
|
759 TInt count = iContactListArray.Count(); |
|
760 for(TInt i = 0; i < count; i++) |
|
761 { |
|
762 index = iContactListArray[i]->FindIndexOfContact(contact); |
|
763 if(KErrNotFound != index ) |
|
764 { |
|
765 iContactListArray[i]->ResortContact(contact); |
|
766 // get the index of the sorted contact, as after sorting the |
|
767 // index would have changed based on presence. |
|
768 // break after the contact list is found and the contact is found |
|
769 break; |
|
770 } |
|
771 } |
|
772 NotifyAllObserversL( TVIMPSTEnums::EStorageEventContactChange,NULL,contact, oldIndex ); |
|
773 } |
|
774 if( contact->AvatarContent().Compare( aAvatarContent ) != 0 ) |
|
775 { |
|
776 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdateCacheContactL user id changed") ); |
|
777 contact->SetAvatarContentL( aAvatarContent,*iVPbkContactStore ); |
|
778 NotifyAllObserversL( TVIMPSTEnums::EStorageAvatarChange,NULL, contact, KErrNotFound); |
|
779 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdateCacheContactL NotifyAllObserversL delivered") ); |
|
780 } |
|
781 } |
|
782 TRACE( T_LIT("CVIMPSTStorageServiceView::UpdateCacheContactL end") ); |
|
783 return contact; |
|
784 } |
|
785 // ----------------------------------------------------------------------------- |
|
786 // CVIMPSTStorageServiceView::AddContactToCacheL |
|
787 // ----------------------------------------------------------------------------- |
|
788 MVIMPSTStorageContact* CVIMPSTStorageServiceView::AddContactToCacheL (const MVPbkContactLink& aContactLink, |
|
789 const TDesC& aUserId, |
|
790 const TDesC& aDisplayName, |
|
791 const TDesC8& aAvatarContent, |
|
792 TVIMPSTEnums::TVIMPSTStorgaeEventType aType ) |
|
793 { |
|
794 TRACE( T_LIT("CVIMPSTStorageServiceView::AddContactToCacheL begin") ); |
|
795 TRACE( T_LIT("CVIMPSTStorageServiceView::AddContactToCacheL user id: %S"), &aUserId); |
|
796 TRACE( T_LIT("CVIMPSTStorageServiceView::AddContactToCacheL storageeventtype: %d"), aType ); |
|
797 MVIMPSTStorageContactList* contactList = FindContactListInternal( KFriendList ); |
|
798 if( !contactList ) |
|
799 { |
|
800 contactList = CreateContactListL(KFriendList,KNullDesC); |
|
801 } |
|
802 TRACE( T_LIT("CVIMPSTStorageServiceView::AddContactToCacheL before findcontactlink") ); |
|
803 MVIMPSTStorageContact* contact = FindContactByLink(aContactLink); |
|
804 TRACE( T_LIT("CVIMPSTStorageServiceView::AddContactToCacheL after findcontactlink ") ); |
|
805 if( !contact ) |
|
806 { |
|
807 TRACE( T_LIT("CVIMPSTStorageServiceView::AddContactToCacheL contact not exist ") ); |
|
808 TInt error = KErrGeneral; |
|
809 TInt index = KErrNotFound; |
|
810 if( aDisplayName.Length() <= 0 && iUnNamedText ) |
|
811 { |
|
812 TRACE( T_LIT("CVIMPSTStorageServiceView::AddContactToCacheL no display name ") ); |
|
813 contact = CVIMPSTStorageContact::NewLC( aUserId, *iUnNamedText , aContactLink ,aAvatarContent ); |
|
814 } |
|
815 else |
|
816 { |
|
817 TRACE( T_LIT("CVIMPSTStorageServiceView::AddContactToCacheL has display name ") ); |
|
818 contact = CVIMPSTStorageContact::NewLC( aUserId, aDisplayName , aContactLink, aAvatarContent); |
|
819 } |
|
820 // if the xsp id is numm, then the presence state should be EUnknown; |
|
821 if(0 == aUserId.Length()) |
|
822 { |
|
823 contact->SetOnlineStatus(TVIMPSTEnums::EUnknown); |
|
824 } |
|
825 else if( aType == TVIMPSTEnums::EStorageEventContactAddition && !iIsInvitationItem ) |
|
826 { |
|
827 // if a invitation item getting accepted do not set to pending again |
|
828 // if user has choosen add contact set the default status as pending |
|
829 // to avoid any kind of flickering |
|
830 contact->SetOnlineStatus(TVIMPSTEnums::EPending); |
|
831 } |
|
832 error = contactList->AddStorageContactToCacheL( contact, index ); |
|
833 TRACE( T_LIT("CVIMPSTStorageServiceView::AddContactToCacheL AddStorageContactToCacheL error= %d "),error ); |
|
834 if( error == KErrNone ) |
|
835 { |
|
836 TRACE( T_LIT("CVIMPSTStorageServiceView::AddContactToCacheL success ") ); |
|
837 CleanupStack::Pop(); // contact |
|
838 TInt count = iContactListArray.Count(); |
|
839 for(TInt i = 0; i < count; i++) |
|
840 { |
|
841 index = iContactListArray[i]->FindIndexOfContact(contact); |
|
842 if(KErrNotFound != index ) |
|
843 { |
|
844 iContactListArray[i]->ResortContact(contact); |
|
845 TRACE( T_LIT("CVIMPSTStorageServiceView::AddContactToCacheL() contact ResortContact ") ); |
|
846 // get the index of the sorted contact, as after sorting the |
|
847 // index would have changed based on presence. |
|
848 // break after the contact list is found and the contact is found |
|
849 break; |
|
850 } |
|
851 } |
|
852 index = IndexOfContact(contact); |
|
853 NotifyAllObserversL( aType,NULL, contact, index ); |
|
854 } |
|
855 else |
|
856 { |
|
857 TRACE( T_LIT("CVIMPSTStorageServiceView::AddContactToCacheL not success ") ); |
|
858 CleanupStack::PopAndDestroy(); // contact |
|
859 contact = NULL; |
|
860 } |
|
861 } |
|
862 iIsInvitationItem = EFalse; // reset the flag |
|
863 TRACE( T_LIT("CVIMPSTStorageServiceView::AddContactToCacheL end") ); |
|
864 return contact; |
|
865 } |
|
866 // ----------------------------------------------------------------------------- |
|
867 // CVIMPSTStorageServiceView::AddStorageContactToCacheL |
|
868 // ----------------------------------------------------------------------------- |
|
869 // |
|
870 TInt CVIMPSTStorageServiceView::AddStorageContactToCacheL(MVIMPSTStorageContact* aContactToAdd ) |
|
871 { |
|
872 TRACE( T_LIT("CVIMPSTStorageServiceView::AddStorageContactToCacheL begin") ); |
|
873 TInt error = KErrGeneral; |
|
874 MVIMPSTStorageContactList* contactList = FindContactListInternal( KFriendList ); |
|
875 if( !contactList ) |
|
876 { |
|
877 contactList = CreateContactListL(KFriendList,KNullDesC); // create the default list :TODO chnage to proper sol |
|
878 } |
|
879 if( aContactToAdd ) |
|
880 { |
|
881 if( aContactToAdd->Name().Length() <= 0 && iUnNamedText ) |
|
882 { |
|
883 aContactToAdd->SetNameL( *iUnNamedText ); |
|
884 } |
|
885 TInt index = KErrNotFound; |
|
886 TRACE( T_LIT("CVIMPSTStorageServiceView::AddStorageContactToCacheL online status = %d "), TVIMPSTEnums::EPending); |
|
887 // if the userid(xsp field is null then the presence is unknown.) |
|
888 if(aContactToAdd->UserId().Length() == 0) |
|
889 { |
|
890 aContactToAdd->SetOnlineStatus(TVIMPSTEnums::EUnknown); |
|
891 } |
|
892 else |
|
893 { |
|
894 aContactToAdd->SetOnlineStatus(TVIMPSTEnums::EPending); |
|
895 } |
|
896 error = contactList->AddStorageContactToCacheL( aContactToAdd, index ); // aContactToAdd ownership is transfered |
|
897 TRACE( T_LIT("CVIMPSTStorageServiceView::AddStorageContactToCacheL index = %d "),index ); |
|
898 if( error == KErrNone ) |
|
899 { |
|
900 TInt count = iContactListArray.Count(); |
|
901 for(TInt i = 0; i < count; i++) |
|
902 { |
|
903 index = iContactListArray[i]->FindIndexOfContact(aContactToAdd); |
|
904 if(KErrNotFound != index ) |
|
905 { |
|
906 iContactListArray[i]->ResortContact(aContactToAdd); |
|
907 TRACE( T_LIT("CVIMPSTStorageServiceView::AddContactToCacheL() contact ResortContact ") ); |
|
908 // get the index of the sorted contact, as after sorting the |
|
909 // index would have changed based on presence. |
|
910 // break after the contact list is found and the contact is found |
|
911 break; |
|
912 } |
|
913 } |
|
914 index = IndexOfContact(aContactToAdd); |
|
915 NotifyAllObserversL( TVIMPSTEnums::EStorageEventContactAddition,NULL, aContactToAdd, index ); |
|
916 } |
|
917 } |
|
918 TRACE( T_LIT("CVIMPSTStorageServiceView::AddStorageContactToCacheL error = %d "),error ); |
|
919 TRACE( T_LIT("CVIMPSTStorageServiceView::AddStorageContactToCacheL end") ); |
|
920 return error; |
|
921 } |
|
922 // ----------------------------------------------------------------------------- |
|
923 // CVIMPSTStorageServiceView::RemoveContactFromCacheL |
|
924 // From MVIMPSTStorageServiceView. |
|
925 // Try to load with given ID, return NULL if not found. |
|
926 // ----------------------------------------------------------------------------- |
|
927 |
|
928 TInt CVIMPSTStorageServiceView::RemoveContactFromCacheL(const MVPbkContactLink& aContactLink, |
|
929 TVIMPSTEnums::TVIMPSTStorgaeEventType aType) |
|
930 { |
|
931 TRACE( T_LIT("CVIMPSTStorageServiceView::RemoveContactFromCacheL begin") ); |
|
932 TInt error = KErrNotFound; |
|
933 MVIMPSTStorageContactList* contactList = FindContactListInternal( KFriendList ); |
|
934 if( !contactList ) |
|
935 { |
|
936 contactList = CreateContactListL( KFriendList,KNullDesC ); // create the default list :TODO chnage to proper sol |
|
937 } |
|
938 MVIMPSTStorageContact* contact = FindContactByLink(aContactLink); |
|
939 if( contact ) |
|
940 { |
|
941 // do not change the order of below line |
|
942 // contact can be access just before deletion but not after delete from cache |
|
943 if( aType == TVIMPSTEnums::EStorageEventDeleteFromPbk ) |
|
944 { |
|
945 // in EStorageEventDeleteFromPbk event ,caller should not remove from his local list |
|
946 // this just to inform that if user caller want to do any pre operation like unsubscriibtion etc |
|
947 NotifyAllObserversL( aType ,NULL,contact,0); //contact is still valid |
|
948 } |
|
949 TInt index = 0; |
|
950 error = contactList->RemoveContactFromCacheL( aContactLink, index ); |
|
951 NotifyAllObserversL( TVIMPSTEnums::EStorageEventContactDelete ,NULL,NULL,index); //contact is not valid ,deleted |
|
952 } |
|
953 TRACE( T_LIT("CVIMPSTStorageServiceView::RemoveContactFromCacheL error = %d "),error ); |
|
954 TRACE( T_LIT("CVIMPSTStorageServiceView::RemoveContactFromCacheL begin") ); |
|
955 return error; |
|
956 } |
|
957 // ----------------------------------------------------------------------------- |
|
958 // CVIMPSTStorageServiceView::RemoveAllCacheContactsL |
|
959 // ----------------------------------------------------------------------------- |
|
960 // |
|
961 void CVIMPSTStorageServiceView::RemoveAllCacheContactsL() |
|
962 { |
|
963 TRACE( T_LIT("CVIMPSTStorageServiceView::RemoveContactFromCacheL begin") ); |
|
964 TRACE( T_LIT("CVIMPSTStorageServiceView::RemoveContactFromCacheL count = %d"), iContactListArray.Count()); |
|
965 iContactListArray.ResetAndDestroy(); |
|
966 TRACE( T_LIT("CVIMPSTStorageServiceView::RemoveContactFromCacheL remove sucess") ); |
|
967 NotifyAllObserversL(TVIMPSTEnums::EStorageAllContactRemoved,NULL,NULL,0 ); |
|
968 TRACE( T_LIT("CVIMPSTStorageServiceView::RemoveContactFromCacheL begin") ); |
|
969 } |
|
970 |
|
971 // ----------------------------------------------------------------------------- |
|
972 // CVIMPSTStorageServiceView::GetDefaultContactListL |
|
973 // ----------------------------------------------------------------------------- |
|
974 // |
|
975 MVIMPSTStorageContactList* CVIMPSTStorageServiceView::GetDefaultContactListL() |
|
976 { |
|
977 TRACE( T_LIT("CVIMPSTStorageServiceView::GetDefaultContactListL begin") ); |
|
978 MVIMPSTStorageContactList* contactList = FindContactListInternal( KFriendList ); |
|
979 TRACE( T_LIT("CVIMPSTStorageServiceView::GetDefaultContactListL end") ); |
|
980 return contactList; |
|
981 } |
|
982 // ----------------------------------------------------------------------------- |
|
983 // CVIMPSTStorageServiceView::NotifyServiceViewL |
|
984 // ----------------------------------------------------------------------------- |
|
985 // |
|
986 void CVIMPSTStorageServiceView::NotifyServiceViewL( TVIMPSTEnums::TVIMPSTStorgaeEventType aEventType, |
|
987 MVIMPSTStorageContact* aContact /*= NULL */ ) |
|
988 { |
|
989 TRACE( T_LIT("CVIMPSTStorageServiceView::NotifyServiceViewL begin") ); |
|
990 NotifyAllObserversL(aEventType,NULL, aContact,0 ); |
|
991 TRACE( T_LIT("CVIMPSTStorageServiceView::NotifyServiceViewL end") ); |
|
992 } |
|
993 |
|
994 //================================================== from writer interface end =========================== |
|
995 // TLinearOrder |
|
996 // ----------------------------------------------------------------------------- |
|
997 // CVIMPSTStorageServiceView::ContactListOrderByDisplayName |
|
998 // ----------------------------------------------------------------------------- |
|
999 // |
|
1000 TInt CVIMPSTStorageServiceView::ContactListOrderByDisplayName( |
|
1001 const CVIMPSTStorageContactList& aContactListA, |
|
1002 const CVIMPSTStorageContactList& aContactListB ) |
|
1003 { |
|
1004 TRACE( T_LIT("CVIMPSTStorageServiceView::ContactListOrderByDisplayName") ); |
|
1005 return aContactListA.DisplayName().CompareC( aContactListB.DisplayName() ); |
|
1006 } |
|
1007 |
|
1008 // TIdentityRelation |
|
1009 // ----------------------------------------------------------------------------- |
|
1010 // CVIMPSTStorageServiceView::ContactListFindByContactListId |
|
1011 // ----------------------------------------------------------------------------- |
|
1012 // |
|
1013 TBool CVIMPSTStorageServiceView::ContactListFindByContactListId( |
|
1014 const CVIMPSTStorageContactList& aContactListA, |
|
1015 const CVIMPSTStorageContactList& aContactListB ) |
|
1016 { |
|
1017 TRACE( T_LIT("CVIMPSTStorageServiceView::ContactListFindByContactListId start") ); |
|
1018 const MVIMPSTStorageContactList& listA = aContactListA; |
|
1019 const MVIMPSTStorageContactList& listB = aContactListB; |
|
1020 TRACE( T_LIT("CVIMPSTStorageServiceView::ContactListFindByContactListId return") ); |
|
1021 return ( VIMPSTStorageUtils::NeutralCompare( listA.ListId(), |
|
1022 listB.ListId(), EFalse ) == 0 ); |
|
1023 } |
|
1024 // ----------------------------------------------------------------------------- |
|
1025 // CVIMPSTStorageServiceView::Count |
|
1026 // Returns item count |
|
1027 // (other items were commented in a header). |
|
1028 // ----------------------------------------------------------------------------- |
|
1029 // |
|
1030 TInt CVIMPSTStorageServiceView::Count() const |
|
1031 { |
|
1032 TRACE( T_LIT("CVIMPSTStorageServiceView::Count start") ); |
|
1033 // fetch contact list count from storage |
|
1034 // and add contact counts from expanded contact lists |
|
1035 TInt listCount( ListCount() ); |
|
1036 TInt itemCount( 0 ); |
|
1037 TInt contactCount = 0; |
|
1038 for( TInt i(0); i<listCount; ++i ) |
|
1039 { |
|
1040 MVIMPSTStorageContactList& list = ListAt(i); |
|
1041 contactCount = list.Count() ; |
|
1042 ++itemCount; |
|
1043 if( contactCount > 0 ) |
|
1044 { |
|
1045 // if list is expanded, add count of count of contacts |
|
1046 // in this list to item count |
|
1047 itemCount += contactCount; |
|
1048 //check for this |
|
1049 } |
|
1050 } |
|
1051 TRACE( T_LIT("CVIMPSTStorageServiceView::itemCount =%d"),itemCount ); |
|
1052 TRACE( T_LIT("CVIMPSTStorageServiceView::Count end") ); |
|
1053 return itemCount; |
|
1054 } |
|
1055 |
|
1056 // ----------------------------------------------------------------------------- |
|
1057 // CVIMPSTStorageServiceView::Item |
|
1058 // Returns item at given index |
|
1059 // (other items were commented in a header). |
|
1060 // ----------------------------------------------------------------------------- |
|
1061 // |
|
1062 MVIMPSTStorageItemModel::SItem CVIMPSTStorageServiceView::Item( TInt aIndex ) const |
|
1063 { |
|
1064 TRACE( T_LIT("CVIMPSTStorageServiceView::Item start") ); |
|
1065 MVIMPSTStorageItemModel::SItem item; |
|
1066 item.iType = MVIMPSTStorageItemModel::EInvalid; |
|
1067 item.iContactList = NULL; |
|
1068 item.iContact = NULL; |
|
1069 TInt contactCount = 0; |
|
1070 TInt count( 0 ); |
|
1071 TInt listCount( ListCount() ); |
|
1072 for( TInt i( 0 ); i < listCount; ++i ) |
|
1073 { |
|
1074 MVIMPSTStorageContactList& list = ListAt( i ); |
|
1075 item.iContactList = &list; |
|
1076 |
|
1077 ++count; |
|
1078 if( count > aIndex ) |
|
1079 { |
|
1080 // there's a list in given index |
|
1081 item.iType = MVIMPSTStorageItemModel::EContactList; |
|
1082 TRACE( T_LIT("CVIMPSTStorageServiceView::Item end") ); |
|
1083 return item; |
|
1084 } |
|
1085 contactCount = list.Count() ; |
|
1086 if( contactCount > 0 ) |
|
1087 { |
|
1088 // list is expanded, consider also contacts in this list |
|
1089 if( count + contactCount > aIndex ) |
|
1090 { |
|
1091 // there's a contact in given index |
|
1092 TInt contactIndex( aIndex - count ); |
|
1093 item.iType = MVIMPSTStorageItemModel::EContactItem; |
|
1094 item.iContact = &list[contactIndex]; |
|
1095 TRACE( T_LIT("CVIMPSTStorageServiceView::Item end") ); |
|
1096 return item; |
|
1097 } |
|
1098 // add expanded list's contact count |
|
1099 count += contactCount; |
|
1100 } |
|
1101 } |
|
1102 // not found |
|
1103 TRACE( T_LIT("CVIMPSTStorageServiceView::Item end") ); |
|
1104 return item; |
|
1105 } |
|
1106 |
|
1107 // ----------------------------------------------------------------------------- |
|
1108 // CVIMPSTStorageServiceView::IndexOfContact |
|
1109 // Gets index of contact in list |
|
1110 // (other items were commented in a header). |
|
1111 // ----------------------------------------------------------------------------- |
|
1112 // |
|
1113 TInt CVIMPSTStorageServiceView::IndexOfContact( MVIMPSTStorageContact* aContact ) const |
|
1114 { |
|
1115 TRACE( T_LIT("CVIMPSTStorageServiceView::IndexOfContact begin") ); |
|
1116 TInt listCount( ListCount() ); |
|
1117 TInt itemCount( 0 ); |
|
1118 TInt contactCount = 0; |
|
1119 TInt indexOfContact = KErrNotFound; |
|
1120 for( TInt i(0); i < listCount; ++i ) |
|
1121 { |
|
1122 MVIMPSTStorageContactList& list = ListAt(i); |
|
1123 contactCount = list.Count( ) ; |
|
1124 indexOfContact = list.FindIndexOfContact( aContact ); |
|
1125 // if we're showing all contacts or |
|
1126 // there are online contacts in this list, |
|
1127 // the list-item is shown => increase count check this? |
|
1128 //itemCount; //++itemCount; |
|
1129 if( indexOfContact != KErrNotFound ) |
|
1130 { |
|
1131 // add earlier items to index. |
|
1132 indexOfContact += itemCount; |
|
1133 break; |
|
1134 } |
|
1135 else |
|
1136 { |
|
1137 itemCount += contactCount; |
|
1138 } |
|
1139 //add the code for if contact not found in first list |
|
1140 } |
|
1141 TRACE( T_LIT("CVIMPSTStorageServiceView::IndexOfContact indexOfContact = %d"), indexOfContact ); |
|
1142 TRACE( T_LIT("CVIMPSTStorageServiceView::IndexOfContact end") ); |
|
1143 return indexOfContact; |
|
1144 } |
|
1145 |
|
1146 // ----------------------------------------------------------------------------- |
|
1147 // CVIMPSTStorageServiceView::IndexOfList |
|
1148 // Gets index of contact in list |
|
1149 // (other items were commented in a header). |
|
1150 // ----------------------------------------------------------------------------- |
|
1151 // |
|
1152 TInt CVIMPSTStorageServiceView::IndexOfList( MVIMPSTStorageContactList* aList, |
|
1153 TBool /*aIgnoreOwnItem = EFalse*/, |
|
1154 TBool /*aIgnoreEmptyLists = ETrue*/ ) const |
|
1155 { |
|
1156 TRACE( T_LIT("CVIMPSTStorageServiceView::IndexOfList begin") ); |
|
1157 TInt listCount( ListCount() ); |
|
1158 TInt itemCount( 0 ); |
|
1159 for( TInt i(0); i<listCount; ++i ) |
|
1160 { |
|
1161 MVIMPSTStorageContactList& list = ListAt(i); |
|
1162 if( &list == aList ) |
|
1163 { |
|
1164 TRACE( T_LIT("CVIMPSTStorageServiceView::IndexOfList list matched")); |
|
1165 break; |
|
1166 } |
|
1167 else |
|
1168 { |
|
1169 // list will be consider for calculating the index |
|
1170 // at initial state of fetching the list.count will be zero |
|
1171 // because all the lists will be fetched first and the contacts |
|
1172 itemCount = itemCount+ list.Count() + 1; |
|
1173 } |
|
1174 } |
|
1175 TRACE( T_LIT("CVIMPSTStorageServiceView::IndexOfList itemCount = %d"),itemCount ); |
|
1176 TRACE( T_LIT("CVIMPSTStorageServiceView::IndexOfList end") ); |
|
1177 return itemCount; |
|
1178 } |
|
1179 // ----------------------------------------------------------------------------- |
|
1180 // CVIMPSTContactListModel::MdcaCount |
|
1181 // (other items were commented in a header). |
|
1182 // ----------------------------------------------------------------------------- |
|
1183 // |
|
1184 TInt CVIMPSTStorageServiceView::MdcaCount() const |
|
1185 { |
|
1186 TRACE( T_LIT("CVIMPSTStorageServiceView::MdcaCount") ); |
|
1187 return Count(); |
|
1188 } |
|
1189 |
|
1190 // ----------------------------------------------------------------------------- |
|
1191 // CVIMPSTContactListModel::MdcaPoint |
|
1192 // (other items were commented in a header). |
|
1193 // ----------------------------------------------------------------------------- |
|
1194 // |
|
1195 TPtrC CVIMPSTStorageServiceView::MdcaPoint( TInt /*aIndex */) const |
|
1196 { |
|
1197 TRACE( T_LIT("CVIMPSTStorageServiceView::MdcaPoint") ); |
|
1198 // These will be filtered out |
|
1199 return KNullDesC(); |
|
1200 } |
|
1201 // ----------------------------------------------------------------------------- |
|
1202 // CVIMPSTStorageServiceView::Sort |
|
1203 /// KNullDesC -> sort all |
|
1204 // ----------------------------------------------------------------------------- |
|
1205 // |
|
1206 void CVIMPSTStorageServiceView::Sort( const TDesC& aContactListId /* = KNullDesC */ ) |
|
1207 { |
|
1208 TRACE( T_LIT("CVIMPSTStorageServiceView::Sort() begin") ); |
|
1209 if( aContactListId.Length() != 0 ) |
|
1210 { |
|
1211 MVIMPSTStorageContactList* list = FindContactList( aContactListId ); |
|
1212 if( list ) |
|
1213 { |
|
1214 TRACE( T_LIT("CVIMPSTStorageServiceView::Sort() list sort") ); |
|
1215 list->Sort(); |
|
1216 } |
|
1217 } |
|
1218 else |
|
1219 { |
|
1220 TInt count( iContactListArray.Count() ); |
|
1221 for( TInt a( 0 ); a < count; ++a ) |
|
1222 { |
|
1223 MVIMPSTStorageContactList& list = *iContactListArray[ a ]; |
|
1224 TRACE( T_LIT("CVIMPSTStorageServiceView::Sort() all list sort") ); |
|
1225 list.Sort(); |
|
1226 } |
|
1227 } |
|
1228 TRACE( T_LIT("CVIMPSTStorageServiceView::Sort() end") ); |
|
1229 } |
|
1230 |
|
1231 |
|
1232 // ----------------------------------------------------------------------------- |
|
1233 // CVIMPSTStorageServiceView::NotifyAllObservers |
|
1234 // ----------------------------------------------------------------------------- |
|
1235 // |
|
1236 void CVIMPSTStorageServiceView::NotifyAllObserversL( TVIMPSTEnums::TVIMPSTStorgaeEventType aType, |
|
1237 MVIMPSTStorageContactList *aList, |
|
1238 MVIMPSTStorageContact* aContact, |
|
1239 TInt aContactIndex ) |
|
1240 { |
|
1241 TRACE( T_LIT("CVIMPSTStorageServiceView::NotifyAllObserversL() begin") ); |
|
1242 TInt count = iContactObservers.Count(); |
|
1243 for( TInt i=0; i<count; i++ ) |
|
1244 { |
|
1245 iContactObservers[i]->HandleStorageChangeL( aType, aList, aContact, aContactIndex ); |
|
1246 } |
|
1247 TRACE( T_LIT("CVIMPSTStorageServiceView::NotifyAllObserversL() end") ); |
|
1248 } |
|
1249 |
|
1250 // ----------------------------------------------------------------------------- |
|
1251 // CVIMPSTStorageServiceView::NotifyAllObserversWithDelay |
|
1252 // ----------------------------------------------------------------------------- |
|
1253 // |
|
1254 void CVIMPSTStorageServiceView::NotifyAllObserversWithDelay( TVIMPSTEnums::TVIMPSTStorgaeEventType aType, |
|
1255 MVIMPSTStorageContactList *aList, |
|
1256 MVIMPSTStorageContact* aContact, |
|
1257 TInt aContactIndex ) |
|
1258 { |
|
1259 TRACE( T_LIT("CVIMPSTStorageServiceView::NotifyAllObserversWithDelay() begin") ); |
|
1260 if(iActiveHandler->IsActive() ) |
|
1261 { |
|
1262 iActiveHandler->Cancel(); |
|
1263 } |
|
1264 iActiveHandler->IssueRequest( aType, aList, aContact, aContactIndex ); |
|
1265 TRACE( T_LIT("CVIMPSTStorageServiceView::NotifyAllObserversWithDelay() end") ); |
|
1266 } |
|
1267 |
|
1268 // ----------------------------------------------------------------------------- |
|
1269 // CVIMPSTStorageServiceView::HandleDelayedNotificationL |
|
1270 // ----------------------------------------------------------------------------- |
|
1271 // |
|
1272 void CVIMPSTStorageServiceView::HandleDelayedNotificationL(TVIMPSTEnums::TVIMPSTStorgaeEventType aType, |
|
1273 MVIMPSTStorageContactList *aList, |
|
1274 MVIMPSTStorageContact* aContact, |
|
1275 TInt aContactIndex) |
|
1276 { |
|
1277 TRACE( T_LIT("CVIMPSTStorageServiceView::HandleDelayedNotificationL() begin") ); |
|
1278 NotifyAllObserversL( aType, aList, aContact, aContactIndex ); |
|
1279 TRACE( T_LIT("CVIMPSTStorageServiceView::HandleDelayedNotificationL() end") ); |
|
1280 } |
|
1281 // End of File |