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