| author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> | 
| Wed, 23 Jun 2010 18:09:17 +0300 | |
| changeset 43 | 35b64624a9e7 | 
| parent 31 | ebfee66fde93 | 
| child 44 | 36f374c67aa8 | 
| permissions | -rw-r--r-- | 
| 31 | 1 | /* | 
| 2 | * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). | |
| 3 | * All rights reserved. | |
| 4 | * This component and the accompanying materials are made available | |
| 5 | * under the terms of "Eclipse Public License v1.0" | |
| 6 | * which accompanies this distribution, and is available | |
| 7 | * at the URL "http://www.eclipse.org/legal/epl-v10.html". | |
| 8 | * | |
| 9 | * Initial Contributors: | |
| 10 | * Nokia Corporation - initial contribution. | |
| 11 | * | |
| 12 | * Contributors: | |
| 13 | * | |
| 14 | * Description: CS Conversation Cache class. | |
| 15 | * This cache all the conversation from plugins | |
| 16 | * and responds to the client request | |
| 17 | * | |
| 18 | */ | |
| 19 | ||
| 20 | // INCLUDE FILES | |
| 21 | ||
| 22 | // SYSTEM INCLUDE FILES | |
| 23 | #include <ccsclientconversation.h> | |
| 24 | #include <ccsconversationentry.h> | |
| 25 | #include <ccsdefs.h> | |
| 26 | #include <telconfigcrkeys.h> // KCRUidTelephonyConfiguration | |
| 27 | #include <centralrepository.h> | |
| 43 
35b64624a9e7
Revision: 201023
 Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> parents: 
31diff
changeset | 28 | #include <xqconversions.h> | 
| 31 | 29 | // USER INCLUDE FILES | 
| 30 | #include "ccsconversationcache.h" | |
| 31 | #include "ccsconversationcachehelper.h" | |
| 32 | #include "ccsconversationcontact.h" | |
| 33 | #include "ccsconversation.h" | |
| 34 | #include "ccscontactsmanager.h" | |
| 35 | #include "ccscontactsresolver.h" | |
| 36 | #include "ccsconversationevent.h" | |
| 37 | #include "ccsserver.h" | |
| 38 | #include "ccsdebug.h" | |
| 39 | ||
| 40 | // ============================== MEMBER FUNCTIONS ============================ | |
| 41 | ||
| 42 | // ---------------------------------------------------------------------------- | |
| 43 | // CCsConversationCache::NewL | |
| 44 | // Two Phase Construction | |
| 45 | // ---------------------------------------------------------------------------- | |
| 46 | CCsConversationCache* | |
| 47 | CCsConversationCache::NewL(CCsContactsManager* aContactManager, | |
| 48 | CCsServer* aCsServer) | |
| 49 | {
 | |
| 50 |     PRINT ( _L("Enter CCsConversationCache::NewL") );
 | |
| 51 | ||
| 52 | CCsConversationCache* self = | |
| 53 | new (ELeave) CCsConversationCache(aContactManager, aCsServer); | |
| 54 | CleanupStack::PushL(self); | |
| 55 | self->ConstructL(); | |
| 56 | CleanupStack::Pop(self); | |
| 57 | ||
| 58 |     PRINT ( _L("End CCsConversationCache::NewL") );
 | |
| 59 | ||
| 60 | return self; | |
| 61 | } | |
| 62 | ||
| 63 | // ---------------------------------------------------------------------------- | |
| 64 | // CCsConversationCache::CCsConversationCache | |
| 65 | // Construtor | |
| 66 | // ---------------------------------------------------------------------------- | |
| 67 | CCsConversationCache::CCsConversationCache(CCsContactsManager* aContactManager, | |
| 68 | CCsServer* aCsServer) : | |
| 69 | iCsServer(aCsServer), iContactsManager(aContactManager) | |
| 70 | {
 | |
| 71 | } | |
| 72 | ||
| 73 | // ---------------------------------------------------------------------------- | |
| 74 | // CCsConversationCache::ConstructL | |
| 75 | // Second phase constructor | |
| 76 | // ---------------------------------------------------------------------------- | |
| 77 | void CCsConversationCache::ConstructL() | |
| 78 | {
 | |
| 79 |     PRINT ( _L("Enter CCsConversationCache::ConstructL") );
 | |
| 80 | ||
| 81 | // Register for events from contact manager | |
| 82 | iContactsManager->addObserver(this); | |
| 83 | ||
| 84 | // initialize the main cache entries | |
| 85 | iConversationList = new (ELeave) RPointerArray<CCsConversation> (); | |
| 86 | ||
| 87 | // initialize the class helper class | |
| 88 | iConversationCacheHelper = CCsConversationCacheHelper::NewL(this); | |
| 89 | ||
| 90 | iMatchDigitCount = KDefaultGsmNumberMatchLength; | |
| 91 | ||
| 92 | // Read the amount of digits to be used in contact matching | |
| 93 | // The key is owned by PhoneApp | |
| 94 | CRepository* repository = CRepository::NewLC(KCRUidTelConfiguration); | |
| 95 | if (repository->Get(KTelMatchDigits, iMatchDigitCount) == KErrNone) | |
| 96 |     {
 | |
| 97 | // Min is 7 | |
| 98 | iMatchDigitCount = Max(iMatchDigitCount, KDefaultGsmNumberMatchLength); | |
| 99 | } | |
| 100 | CleanupStack::PopAndDestroy(); // repository | |
| 101 | ||
| 102 |     PRINT ( _L("End CCsConversationCache::ConstructL") );
 | |
| 103 | } | |
| 104 | ||
| 105 | // ---------------------------------------------------------------------------- | |
| 106 | // CCsConversationCache::CCsConversationCache | |
| 107 | // Destructor | |
| 108 | // ---------------------------------------------------------------------------- | |
| 109 | CCsConversationCache::~CCsConversationCache() | |
| 110 | {
 | |
| 111 |     PRINT ( _L("Enter CCsConversationCache::~CCsConversationCache") );
 | |
| 112 | ||
| 113 | if (iContactsManager) | |
| 114 |     {
 | |
| 115 | iContactsManager->removeObserver(this); | |
| 116 | } | |
| 117 | ||
| 118 | // delete the set of all conversations | |
| 119 | if (iConversationList) | |
| 120 |     {
 | |
| 121 | iConversationList->ResetAndDestroy(); | |
| 122 | iConversationList->Close(); | |
| 123 | delete iConversationList; | |
| 124 | iConversationList = NULL; | |
| 125 | } | |
| 126 | ||
| 127 | if (iConversationCacheHelper) | |
| 128 |     {
 | |
| 129 | delete iConversationCacheHelper; | |
| 130 | iConversationCacheHelper = NULL; | |
| 131 | } | |
| 132 | ||
| 133 |     PRINT ( _L("End CCsConversationCache::~CCsConversationCache") );
 | |
| 134 | } | |
| 135 | ||
| 136 | // ---------------------------------------------------------------------------- | |
| 137 | // CCsConversationCache::GetConversationListL | |
| 138 | // Get Conversation list with contact details | |
| 139 | // for all stored conversations | |
| 140 | // This API can be used to prepare conversation list | |
| 141 | // ---------------------------------------------------------------------------- | |
| 142 | void CCsConversationCache::GetConversationListL(RPointerArray< | |
| 143 | CCsClientConversation>* aClientConversationList) | |
| 144 | {
 | |
| 145 | TInt totalConversation = iConversationList->Count(); | |
| 146 | ||
| 147 | // Write the contact display names | |
| 148 | for (TInt loop = 0; loop < totalConversation; loop++) | |
| 149 |     {
 | |
| 150 | CCsConversation* conversation = | |
| 151 | static_cast<CCsConversation*> ( (*iConversationList)[loop]); | |
| 152 | ||
| 153 | // The check is needed to avoid crash while internalizing resulting | |
| 154 | // from the row added for unknown drafts | |
| 155 | if (conversation->GetEntryCount()) | |
| 156 |         {
 | |
| 157 | CCsClientConversation* clientConversation = | |
| 158 | CreateClientConvLC(conversation, | |
| 159 | conversation->GetLatestEntryL()); | |
| 160 | aClientConversationList->Append(clientConversation); | |
| 161 | CleanupStack::Pop(); | |
| 162 | } | |
| 163 | } | |
| 164 | ||
| 165 |     PRINT1 ( _L("CCsConversationCache::GetConversationEntryListL - conversationCount:%d"),
 | |
| 166 | totalConversation ); | |
| 167 | } | |
| 168 | ||
| 169 | // ---------------------------------------------------------------------------- | |
| 170 | // CCsConversationCache::GetConversationUnreadListL | |
| 171 | // Get Conversation list with contact details and unread conversation | |
| 172 | // for all stored conversations | |
| 173 | // This API can be used to prepare conversation list | |
| 174 | // ---------------------------------------------------------------------------- | |
| 175 | void CCsConversationCache::GetConversationUnreadListL(RPointerArray< | |
| 176 | CCsClientConversation>* aClientConversationList) | |
| 177 |     {
 | |
| 178 | TInt conversationCount = iConversationList->Count(); | |
| 179 | ||
| 180 | // Write the contact display names | |
| 181 | for (TInt loop = 0; loop < conversationCount; loop++) | |
| 182 |         {
 | |
| 183 | CCsConversation* conversation = | |
| 184 | static_cast<CCsConversation*> ((*iConversationList)[loop]); | |
| 185 | ||
| 186 | // The check is needed to avoid crash while internalizing resulting | |
| 187 | // from the row added for unknown drafts | |
| 188 | if (conversation->GetEntryCount() && conversation->GetUnreadMessageCount()) | |
| 189 |             {
 | |
| 190 | CCsClientConversation* clientConversation = CreateClientConvLC( | |
| 191 | conversation, conversation->GetLatestUnreadEntryL()); | |
| 192 | aClientConversationList->Append(clientConversation); | |
| 193 | CleanupStack::Pop(); | |
| 194 | } | |
| 195 | } | |
| 196 | ||
| 197 |     PRINT1 ( _L("CCsConversationCache::GetConversationUnreadListL - conversationCount:%d"),
 | |
| 198 | conversationCount ); | |
| 199 | } | |
| 200 | ||
| 201 | // ---------------------------------------------------------------------------- | |
| 202 | // CCsConversationCache::GetConversationsL | |
| 203 | // Get All Conversations for a given conversation Id | |
| 204 | // the return list is set inside aConversationEntryList | |
| 205 | // ---------------------------------------------------------------------------- | |
| 206 | void CCsConversationCache::GetConversationsL( | |
| 207 | const CCsClientConversation* aClientConversation, | |
| 208 | RPointerArray<CCsConversationEntry>* aConversationEntryList) | |
| 209 | {
 | |
| 210 | TInt totalConversation = iConversationList->Count(); | |
| 211 | ||
| 212 | // Get the entry id from Client Conversation for which conversations are required | |
| 213 | TCsConversationEntryID conversationEntryID = | |
| 214 | aClientConversation->GetConversationEntryId(); | |
| 215 | ||
| 216 | // Write the contact display names | |
| 217 | for (TInt loop = 0; loop < totalConversation; loop++) | |
| 218 |     {
 | |
| 219 | //match entry ID; | |
| 220 | CCsConversation* conversation = | |
| 221 | static_cast<CCsConversation*> ( (*iConversationList)[loop]); | |
| 222 | ||
| 223 | if (conversationEntryID == conversation->GetConversationId()) | |
| 224 |         {
 | |
| 225 | // search the conversation id and get the list inside | |
| 226 | conversation->GetEntryListL(aConversationEntryList); | |
| 227 | break; | |
| 228 | } | |
| 229 | } | |
| 230 |     PRINT1 ( _L("CCsConversationCache::GetConversationsL - conversationCount:%d"),
 | |
| 231 | totalConversation ); | |
| 232 | } | |
| 233 | ||
| 234 | // ---------------------------------------------------------------------------- | |
| 235 | // CCsConversationCache::HandleConversations | |
| 236 | // Called from server. This is to handle the event callback from plugin dll | |
| 237 | // The idea is to add entries to the cache and at the same time update the clients | |
| 238 | // ---------------------------------------------------------------------------- | |
| 239 | void CCsConversationCache::HandleConversations(const RPointerArray< | |
| 240 | CCsConversationEntry>& aConversationEntryLists, | |
| 241 | const TUint32 aConversationEvent) | |
| 242 | {
 | |
| 243 | // get count | |
| 244 | TInt count = aConversationEntryLists.Count(); | |
| 245 | ||
| 246 | // go through each conversation entry | |
| 247 | // add it into queue, event list | |
| 248 | for (TInt loop = 0; loop < count; loop++) | |
| 249 |     {
 | |
| 250 | //get copy of conversation event | |
| 251 | TInt error; | |
| 252 | CCsConversationEvent* conEvent = NULL; | |
| 253 | CCsClientConversation* clientCon = NULL; | |
| 254 | CCsConversationEntry* conEntry = aConversationEntryLists[loop]; | |
| 255 | ||
| 256 | if (aConversationEntryLists[loop]) | |
| 257 |         {
 | |
| 258 | TRAP( | |
| 259 | error, | |
| 260 | conEvent = CCsConversationEvent::NewL(); | |
| 261 | CleanupStack::PushL(conEvent); | |
| 262 | //create clientconversation | |
| 263 | clientCon = CCsClientConversation::NewL(); | |
| 264 | CleanupStack::PushL(clientCon); | |
| 265 | clientCon->SetConversationEntryL(conEntry); | |
| 266 | //set conversation entry | |
| 267 | conEvent->SetClientConversationL(*clientCon); | |
| 268 | //set event | |
| 269 | conEvent->SetEvent(aConversationEvent); | |
| 270 | //add entry | |
| 271 | iConversationCacheHelper->ConversationEventList()->AppendL(conEvent); | |
| 272 | CleanupStack::PopAndDestroy(clientCon); | |
| 273 | CleanupStack::Pop(conEvent)); | |
| 274 | ||
| 275 | if (error != KErrNone) | |
| 276 |             {
 | |
| 277 |                 PRINT1 ( _L("CCsConversationCache::HandleConversation - Error:%d"),
 | |
| 278 | error ); | |
| 279 | continue; | |
| 280 | } | |
| 281 | } | |
| 282 | } | |
| 283 | iConversationCacheHelper->StartCacheUpdate(); | |
| 284 | } | |
| 285 | ||
| 286 | // ---------------------------------------------------------------------------- | |
| 287 | // CCsConversationCache::GetTotalUnreadCount | |
| 288 | // Pending event count | |
| 289 | // ---------------------------------------------------------------------------- | |
| 290 | TUint32 CCsConversationCache::GetTotalUnreadCount() | |
| 291 |     {
 | |
| 292 | TUint32 totalUnread = 0; | |
| 293 | ||
| 294 | for (TInt loop = 0; loop < iConversationList->Count(); ++loop) | |
| 295 |         {
 | |
| 296 | CCsConversation* conversation = | |
| 297 | static_cast<CCsConversation*> ((*iConversationList)[loop]); | |
| 298 | totalUnread += conversation->GetUnreadMessageCount(); | |
| 299 | } | |
| 300 | return totalUnread; | |
| 301 | } | |
| 302 | ||
| 303 | // ---------------------------------------------------------------------------- | |
| 304 | // CCsConversationCache::NotifyL | |
| 305 | // Send the notification client | |
| 306 | // ---------------------------------------------------------------------------- | |
| 307 | void CCsConversationCache::NotifyL(CCsClientConversation* aConversation, | |
| 308 | TUint32 aEvent) | |
| 309 | {
 | |
| 310 | iCsServer->NotifySessions(aConversation, aEvent); | |
| 311 | } | |
| 312 | ||
| 313 | // ---------------------------------------------------------------------------- | |
| 314 | // CCsConversationCache::CachingCompletedL | |
| 315 | // This is called from cache helper after it resolves all events from plugin | |
| 316 | // ---------------------------------------------------------------------------- | |
| 317 | void CCsConversationCache::CachingCompletedL() | |
| 318 | {
 | |
| 319 | // Not supported | |
| 320 | } | |
| 321 | ||
| 322 | // ---------------------------------------------------------------------------- | |
| 323 | // CCsConversationCache::FindConversation | |
| 324 | // Find a conversation based on contact Id | |
| 325 | // ---------------------------------------------------------------------------- | |
| 326 | TInt CCsConversationCache::FindConversation(TInt32 aContactId) | |
| 327 | {
 | |
| 328 | if (aContactId == KErrNotFound) | |
| 329 | return KErrNotFound; | |
| 330 | ||
| 331 | TInt totalConversations = iConversationList->Count(); | |
| 332 | ||
| 333 | for (TInt index = 0; index < totalConversations; index++) | |
| 334 |     {
 | |
| 335 | CCsConversation* conversation = | |
| 336 | static_cast<CCsConversation*> ( (*iConversationList)[index]); | |
| 337 | ||
| 338 | CCsConversationContact* inCache = conversation->GetContact(); | |
| 339 | ||
| 340 | TInt32 idInCache = inCache->GetContactId(); | |
| 341 | ||
| 342 | if (idInCache == KErrNotFound) | |
| 343 | continue; | |
| 344 | ||
| 345 | if (idInCache == aContactId) | |
| 346 |         {
 | |
| 347 | return index; | |
| 348 | } | |
| 349 | } | |
| 350 | return KErrNotFound; | |
| 351 | } | |
| 352 | ||
| 353 | // ---------------------------------------------------------------------------- | |
| 354 | // CCsConversationCache::FindConversation | |
| 355 | // Find a conversation based on phone number | |
| 356 | // ---------------------------------------------------------------------------- | |
| 357 | TInt CCsConversationCache::FindConversation(TDesC& aPhoneNumber) | |
| 358 | {
 | |
| 359 | TInt count = iConversationList->Count(); | |
| 360 | ||
| 361 | for (TInt cIndex = 0; cIndex < count; cIndex++) | |
| 362 |     {
 | |
| 363 | CCsConversation* conversation = | |
| 364 | static_cast<CCsConversation*> ( (*iConversationList)[cIndex]); | |
| 365 | ||
| 366 | CCsConversationContact* inCache = conversation->GetContact(); | |
| 367 | ||
| 368 | if (inCache->MatchPhoneNumber(aPhoneNumber, iMatchDigitCount)) | |
| 369 |         {
 | |
| 370 | return cIndex; | |
| 371 | } | |
| 372 | } | |
| 373 | return KErrNotFound; | |
| 374 | } | |
| 375 | ||
| 376 | // ---------------------------------------------------------------------------- | |
| 377 | // CCsConversationCache::RedoResolvingL | |
| 378 | // Redo contact resolving for the conversation at this index | |
| 379 | // ---------------------------------------------------------------------------- | |
| 380 | void CCsConversationCache::RedoResolvingL(TInt aIndex) | |
| 381 | {
 | |
| 382 | // Recover the associated conversation object | |
| 383 | CCsConversation* conversation = | |
| 384 | static_cast<CCsConversation*> ( (*iConversationList)[aIndex]); | |
| 385 | ||
| 386 | // Get the conversation entries | |
| 387 | RPointerArray<CCsConversationEntry> entryList; | |
| 388 | conversation->GetEntryListL(&entryList); | |
| 389 | ||
| 390 | // Handle as if they are new conversations | |
| 391 | HandleConversations(entryList, KConversationEventNew); | |
| 392 | ||
| 393 | // Send a notification for delete conversation | |
| 394 | CCsConversationEntry* convEntry = conversation->GetLatestEntryL(); | |
| 395 | ||
| 396 | if (iConversationCacheHelper->IsNotifyRequiredL(conversation, | |
| 397 | convEntry, | |
| 398 | KConversationListEventDelete, | |
| 399 | conversation->GetUnreadMessageCount())) | |
| 400 |     {
 | |
| 401 | //clone conversation and send update to client | |
| 402 | CCsClientConversation* clientConv = CreateClientConvLC(conversation, | |
| 403 | convEntry); | |
| 404 | NotifyL(clientConv, KConversationListEventDelete); | |
| 405 | CleanupStack::PopAndDestroy(clientConv); | |
| 406 | } | |
| 407 | ||
| 408 | iConversationList->Remove(aIndex); | |
| 409 | entryList.ResetAndDestroy(); | |
| 410 | ||
| 411 | delete conversation; | |
| 412 | } | |
| 413 | ||
| 414 | // ---------------------------------------------------------------------------- | |
| 415 | // CCsConversationCache::CreateClientConvLC | |
| 416 | // create CCsConversation from CCsConversation and CCsConversationEntry | |
| 417 | // ---------------------------------------------------------------------------- | |
| 418 | CCsClientConversation* CCsConversationCache::CreateClientConvLC( | |
| 419 | const CCsConversation* aConversation, | |
| 420 | const CCsConversationEntry* aConversationEntry) | |
| 421 | {
 | |
| 422 | //create clientconversation | |
| 423 | CCsClientConversation* clientConversation = CCsClientConversation::NewL(); | |
| 424 | CleanupStack::PushL(clientConversation); | |
| 425 | ||
| 426 | clientConversation->SetDisplayNameL(aConversation->GetDisplayName()); | |
| 427 | clientConversation->SetConversationEntryId(aConversation->GetConversationId()); | |
| 428 | clientConversation->SetConversationEntryL(aConversationEntry); | |
| 429 | clientConversation->SetContactId(aConversation->GetContactId()); | |
| 430 | clientConversation->SetUnreadMessageCount(aConversation->GetUnreadMessageCount()); | |
| 431 | ||
| 432 | return clientConversation; | |
| 433 | } | |
| 434 | ||
| 435 | // ---------------------------------------------------------------------------- | |
| 436 | // CCsConversationCache::MarkConversationAsDeleted | |
| 437 | // ---------------------------------------------------------------------------- | |
| 438 | void CCsConversationCache::MarkConversationAsDeleted(TInt aConversationId, | |
| 439 | TBool aDeleted) | |
| 440 | {
 | |
| 441 | TInt conversationCount = iConversationList->Count(); | |
| 442 | ||
| 443 | for (TInt loop = 0; loop < conversationCount; loop++) | |
| 444 |     {
 | |
| 445 | CCsConversation* conversation = | |
| 446 | static_cast<CCsConversation*> ( (*iConversationList)[loop]); | |
| 447 | TInt id = conversation->GetConversationId(); | |
| 448 | ||
| 449 | if (id == aConversationId) | |
| 450 |         {
 | |
| 451 | conversation->MarkDeleted(aDeleted); | |
| 452 | break; | |
| 453 | } | |
| 454 | } | |
| 455 | } | |
| 456 | ||
| 457 | // ---------------------------------------------------------------------------- | |
| 458 | // CCsConversationCache::IsDeleted | |
| 459 | // ---------------------------------------------------------------------------- | |
| 460 | TBool CCsConversationCache::IsDeleted(TInt aConversationId) | |
| 461 | {
 | |
| 462 | TInt conversationCount = iConversationList->Count(); | |
| 463 | ||
| 464 | for (TInt loop = 0; loop < conversationCount; loop++) | |
| 465 |     {
 | |
| 466 | CCsConversation* conversation = | |
| 467 | static_cast<CCsConversation*> ( (*iConversationList)[loop]); | |
| 468 | TInt id = conversation->GetConversationId(); | |
| 469 | ||
| 470 | if (id == aConversationId) | |
| 471 |         {
 | |
| 472 | return conversation->IsDeleted(); | |
| 473 | } | |
| 474 | } | |
| 475 | return EFalse; | |
| 476 | } | |
| 477 | ||
| 478 | // ---------------------------------------------------------------------------- | |
| 479 | // CCsConversationCache::ConversationList | |
| 480 | // Pls refer to .h file | |
| 481 | // ---------------------------------------------------------------------------- | |
| 482 | RPointerArray<CCsConversation>* | |
| 483 | CCsConversationCache::ConversationList() | |
| 484 | {
 | |
| 485 | return iConversationList; | |
| 486 | } | |
| 487 | ||
| 488 | // ---------------------------------------------------------------------------- | |
| 489 | // CCsConversationCache::getContactsManager | |
| 490 | // Pls refer to .h file | |
| 491 | // ---------------------------------------------------------------------------- | |
| 492 | CCsContactsManager* | |
| 493 | CCsConversationCache::ContactsManager() const | |
| 494 | {
 | |
| 495 | return iContactsManager; | |
| 496 | } | |
| 497 | // ---------------------------------------------------------------------------- | |
| 498 | // CCsConversationCache::HandleAddContact | |
| 499 | // Pls refer to .h file | |
| 500 | // ---------------------------------------------------------------------------- | |
| 501 | void CCsConversationCache::HandleAddContact(CCsContactDetail& aDetail) | |
| 502 | {
 | |
| 503 | //handle addition of new contact | |
| 504 | ||
| 505 | QStringList phoneNumberList = aDetail.addressList; | |
| 506 | TInt totalPhoneNumber = phoneNumberList.count(); | |
| 507 | ||
| 508 | // Get the conversation indexes for the phone numbers | |
| 509 | RArray<TInt> conversationIndex; | |
| 510 | ||
| 511 | for (int i = 0; i < totalPhoneNumber; i++) | |
| 512 |     {
 | |
| 513 | QString phoneNumber = phoneNumberList.at(i); | |
| 514 | HBufC* phoneNumber_s60 = | |
| 43 
35b64624a9e7
Revision: 201023
 Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> parents: 
31diff
changeset | 515 | XQConversions::qStringToS60Desc(phoneNumber); | 
| 31 | 516 | TInt cIndex = FindConversation(*phoneNumber_s60); | 
| 517 | if (cIndex != KErrNotFound) | |
| 518 |         {
 | |
| 519 | if (conversationIndex.Find(cIndex) == KErrNotFound) | |
| 520 |             {
 | |
| 521 | conversationIndex.Append(cIndex); | |
| 522 | } | |
| 523 | } | |
| 524 | delete phoneNumber_s60; | |
| 525 | } | |
| 526 | ||
| 527 | // Sort the conversationIndex | |
| 528 | conversationIndex.Sort(); | |
| 529 | ||
| 530 | // Redo contact resolving for the affected conversations | |
| 531 | for ( TInt i = conversationIndex.Count() - 1; i >= 0 ; i-- ) | |
| 532 |     {
 | |
| 533 | RedoResolvingL(conversationIndex[i]); | |
| 534 | } | |
| 535 | ||
| 536 | conversationIndex.Reset(); | |
| 537 | } | |
| 538 | ||
| 539 | // ---------------------------------------------------------------------------- | |
| 540 | // CCsConversationCache::HandleContactChange | |
| 541 | // Pls refer to .h file | |
| 542 | // ---------------------------------------------------------------------------- | |
| 543 | void CCsConversationCache::HandleContactChange(CCsContactDetail& aDetail) | |
| 544 | {
 | |
| 545 | //handle contact change | |
| 546 | QStringList phoneNumberList = aDetail.addressList; | |
| 547 | int countNumberList = phoneNumberList.count(); | |
| 548 | ||
| 549 | // Get the conversation indexes for the phone numbers | |
| 550 | RArray<TInt> conversationIndex; | |
| 551 | for (int i=0; i < countNumberList ; i++) | |
| 552 |     {
 | |
| 553 | QString phoneNumber = phoneNumberList.at(i); | |
| 554 | HBufC* phoneNumber_s60 = | |
| 43 
35b64624a9e7
Revision: 201023
 Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> parents: 
31diff
changeset | 555 | XQConversions::qStringToS60Desc(phoneNumber); | 
| 31 | 556 | |
| 557 | TInt cIndex = FindConversation(*phoneNumber_s60); | |
| 558 | if ( cIndex != KErrNotFound ) | |
| 559 |         {
 | |
| 560 | conversationIndex.InsertInOrder(cIndex); | |
| 561 | } | |
| 562 | delete phoneNumber_s60; | |
| 563 | } | |
| 564 | ||
| 565 | // Get the conversation index corresponding to the contact Id | |
| 566 | TInt linkIdIndex = FindConversation(aDetail.contactId); | |
| 567 | if (linkIdIndex != KErrNotFound) | |
| 568 |     {
 | |
| 569 | conversationIndex.InsertInOrder(linkIdIndex); | |
| 570 | } | |
| 571 | ||
| 572 | // Redo contact resolving for the affected conversations | |
| 573 | for ( TInt i = conversationIndex.Count() - 1; i >= 0 ; i-- ) | |
| 574 |     {
 | |
| 575 | RedoResolvingL(conversationIndex[i]); | |
| 576 | } | |
| 577 | ||
| 578 | conversationIndex.Reset(); | |
| 579 | } | |
| 580 | ||
| 581 | // ---------------------------------------------------------------------------- | |
| 582 | // CCsConversationCache::HandleDeleteContact | |
| 583 | // Pls refer to .h file | |
| 584 | // ---------------------------------------------------------------------------- | |
| 585 | void CCsConversationCache::HandleDeleteContact(CCsContactDetail& aDetail) | |
| 586 | {
 | |
| 587 | //handle if contact is deleted | |
| 588 | TInt cIndex = FindConversation(aDetail.contactId); | |
| 589 | if (cIndex == KErrNotFound) | |
| 590 |     {
 | |
| 591 | // No need to handle this change | |
| 592 | return; | |
| 593 | } | |
| 594 | ||
| 595 | // Redo resolving for the affected conversation | |
| 596 | RedoResolvingL(cIndex); | |
| 597 | } | |
| 598 | ||
| 599 | // ---------------------------------------------------------------------------- | |
| 600 | // CCsConversationCache::GetConversationIdL | |
| 601 | // ---------------------------------------------------------------------------- | |
| 602 | TInt CCsConversationCache::GetConversationIdL(TInt aContactId) | |
| 603 |     {
 | |
| 604 | TInt conversationCount = iConversationList->Count(); | |
| 605 | ||
| 606 | for ( TInt loop= 0; loop < conversationCount; loop++ ) | |
| 607 |        {
 | |
| 608 | CCsConversation* conversation = | |
| 609 | static_cast<CCsConversation*>((*iConversationList)[loop]); | |
| 610 | TInt contactId = conversation->GetContactId(); | |
| 611 | ||
| 612 | if ( contactId == aContactId ) | |
| 613 |            {
 | |
| 614 | return conversation->GetConversationId(); | |
| 615 | } | |
| 616 | } | |
| 617 | ||
| 618 | return -1; | |
| 619 | } | |
| 620 | ||
| 621 | // ---------------------------------------------------------------------------- | |
| 622 | // CCsConversationCache::GetConversationIdFromAddressL | |
| 623 | // ---------------------------------------------------------------------------- | |
| 624 | TInt CCsConversationCache::GetConversationIdFromAddressL(TDesC& aContactAddress) | |
| 625 |     {
 | |
| 626 | TInt conversationCount = iConversationList->Count(); | |
| 627 | ||
| 628 | for ( TInt loop= 0; loop < conversationCount; loop++ ) | |
| 629 |     {
 | |
| 630 | CCsConversation* conversation = | |
| 631 | static_cast<CCsConversation*>((*iConversationList)[loop]); | |
| 632 | CCsConversationContact* contact = conversation->GetContact(); | |
| 633 | if(contact->MatchPhoneNumber(aContactAddress,iMatchDigitCount)) | |
| 634 |             {
 | |
| 635 | return conversation->GetConversationId(); | |
| 636 | } | |
| 637 | } | |
| 638 | return -1; | |
| 639 | } | |
| 640 | ||
| 641 | // ---------------------------------------------------------------------------- | |
| 642 | // CCsConversationCache::GetConversationFromMessageIdL | |
| 643 | // --------------------------------------------------------------------------- | |
| 644 | CCsClientConversation* CCsConversationCache::GetConversationFromMessageIdL(TInt aMessageId) | |
| 645 | {
 | |
| 646 | TInt conversationCount = iConversationList->Count(); | |
| 647 | ||
| 648 | for ( TInt loop = 0; loop < conversationCount; loop++ ) | |
| 649 |     {
 | |
| 650 | CCsConversation* conversation = | |
| 651 | static_cast<CCsConversation*>((*iConversationList)[loop]); | |
| 652 | ||
| 653 | // Get the conversation entries | |
| 654 | RPointerArray<CCsConversationEntry> entryList; | |
| 655 | conversation->GetEntryListL(&entryList); | |
| 656 | ||
| 657 | for ( TInt loop1 = 0; loop1 < entryList.Count(); loop1++ ) | |
| 658 |         {
 | |
| 659 | TInt messageId = entryList[loop1]->EntryId(); | |
| 660 | if ( messageId == aMessageId ) | |
| 661 |             {
 | |
| 662 | CCsClientConversation *clientConv = CreateClientConvLC(conversation, entryList[loop1]); | |
| 663 | CleanupStack::Pop(); | |
| 664 | return clientConv; | |
| 665 | } | |
| 666 | } | |
| 667 | } | |
| 668 | return NULL; | |
| 669 | } | |
| 670 | ||
| 671 | //end of file |