phonebookengines/cntlistmodel/src/cntcache.cpp
changeset 46 efe85016a067
parent 40 b46a585f6909
child 47 7cbcb2896f0e
equal deleted inserted replaced
40:b46a585f6909 46:efe85016a067
    17 */
    17 */
    18 
    18 
    19 #include <hbapplication.h>
    19 #include <hbapplication.h>
    20 #include <qtcontacts.h>
    20 #include <qtcontacts.h>
    21 #include <qcontactmanager.h>
    21 #include <qcontactmanager.h>
       
    22 #include <cntdebug.h>
    22 #include "cntcache.h"
    23 #include "cntcache.h"
    23 #include "cntcache_p.h"
    24 #include "cntcache_p.h"
    24 #include "cntinfoprovider.h"
    25 #include "cntinfoprovider.h"
    25 
    26 
    26 // set the singleton instance pointer to NULL
    27 // set the singleton instance pointer to NULL
    62       mWorker(new CntCacheThread()),
    63       mWorker(new CntCacheThread()),
    63       mNextInfoCacheOrder(CacheOrderStartValue),
    64       mNextInfoCacheOrder(CacheOrderStartValue),
    64       mNextIconCacheOrder(CacheOrderStartValue),
    65       mNextIconCacheOrder(CacheOrderStartValue),
    65       mEmittedContactId(-1)
    66       mEmittedContactId(-1)
    66 {
    67 {
    67     DP_IN("CntCache::CntCache()");
    68     CNT_ENTRY
    68 
    69 
    69     // listen to worker updates
    70     // listen to worker updates
    70     connect(mWorker, SIGNAL(infoFieldUpdated(int, const ContactInfoField&, const QString&)),
    71     connect(mWorker, SIGNAL(infoFieldUpdated(int, const ContactInfoField&, const QString&)),
    71             this, SLOT(onNewInfo(int, const ContactInfoField&, const QString&)));
    72             this, SLOT(onNewInfo(int, const ContactInfoField&, const QString&)));
    72     connect(mWorker, SIGNAL(iconUpdated(const QString&, const HbIcon&)),
    73     connect(mWorker, SIGNAL(iconUpdated(const QString&, const HbIcon&)),
    74     connect(mWorker, SIGNAL(infoCancelled(int)), this, SLOT(onInfoCancelled(int)));
    75     connect(mWorker, SIGNAL(infoCancelled(int)), this, SLOT(onInfoCancelled(int)));
    75     connect(mWorker, SIGNAL(iconCancelled(const QString&)), this, SLOT(onIconCancelled(const QString&)));
    76     connect(mWorker, SIGNAL(iconCancelled(const QString&)), this, SLOT(onIconCancelled(const QString&)));
    76     connect(mWorker, SIGNAL(allJobsDone()), this, SLOT(scheduleOneReadAheadItem()));
    77     connect(mWorker, SIGNAL(allJobsDone()), this, SLOT(scheduleOneReadAheadItem()));
    77 
    78 
    78     // listen to the database for changes to contacts
    79     // listen to the database for changes to contacts
    79     connect(mContactManager, SIGNAL(contactsChanged(const QList<QContactLocalId>&)), this, SLOT(removeContactsFromCache(const QList<QContactLocalId>&)));
    80     connect(mContactManager, SIGNAL(contactsChanged(const QList<QContactLocalId>&)), this, SLOT(updateContactsInCache(const QList<QContactLocalId>&)));
    80     connect(mContactManager, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)), this, SLOT(removeContactsFromCache(const QList<QContactLocalId>&)));
    81     connect(mContactManager, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)), this, SLOT(removeContactsFromCache(const QList<QContactLocalId>&)));
    81 
    82 
    82     // shutdown only when the whole application shuts down
    83     // shutdown only when the whole application shuts down
    83     connect(HbApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(onShutdown()));
    84     connect(HbApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(onShutdown()));
    84 
    85 
    85     DP_OUT("CntCache::CntCache()");
    86     CNT_EXIT
    86 }
    87 }
    87 
    88 
    88 /*!
    89 /*!
    89     Destructs the CntCache singleton instance.
    90     Destructs the CntCache singleton instance.
    90  */
    91  */
    91 CntCache::~CntCache()
    92 CntCache::~CntCache()
    92 {
    93 {
    93     DP_IN("CntCache::~CntCache()");
    94     CNT_ENTRY
    94 
    95 
    95     delete mWorker;
    96     delete mWorker;
    96     delete mContactManager;
    97     delete mContactManager;
    97 
    98     
    98     DP_OUT("CntCache::~CntCache()");
    99     qDeleteAll(mInfoCache);
       
   100     mInfoCache.clear();
       
   101     qDeleteAll(mIconCache);
       
   102     mIconCache.clear();
       
   103 
       
   104     mInstance = NULL;
       
   105 
       
   106     CNT_EXIT
    99 }
   107 }
   100 
   108 
   101 /*! 
   109 /*! 
   102     Fetches information about a contact: name, text (e.g. phone number or
   110     Fetches information about a contact: name, text (e.g. phone number or
   103     social status) and two icons (e.g. avatar, presence). Previously cached
   111     social status) and two icons (e.g. avatar, presence). Previously cached
   113     \param idList a list with all the IDs in the list
   121     \param idList a list with all the IDs in the list
   114     \return a contact with some details filled in
   122     \return a contact with some details filled in
   115  */
   123  */
   116 CntContactInfo CntCache::fetchContactInfo(int row, const QList<QContactLocalId>& idList)
   124 CntContactInfo CntCache::fetchContactInfo(int row, const QList<QContactLocalId>& idList)
   117 {
   125 {
   118     DP_IN("CntCache::fetchContactInfo(" << row << ", idlist[" << idList.count() << "])");
   126     CNT_ENTRY_ARGS(row << "/" << idList.count())
   119 
   127 
   120     Q_ASSERT(row >= 0 && row < idList.count());
   128     Q_ASSERT(row >= 0 && row < idList.count());
   121 
   129 
   122     QString name;
   130     QString name;
   123     QString text = EmptyTextField;
   131     QString text = EmptyTextField;
   178             // ask the worker thread to fetch the information asynchronously
   186             // ask the worker thread to fetch the information asynchronously
   179             mWorker->scheduleInfoJob(contactId);
   187             mWorker->scheduleInfoJob(contactId);
   180         }
   188         }
   181     }
   189     }
   182 
   190 
   183     // cache read-ahead -- items near this fetched item should also be in cache
   191     CNT_EXIT_ARGS("name:" << name << "sec:" << text)
   184     // updateReadAhead(row, idList);
       
   185 
       
   186     DP_OUT("CntCache::fetchContactInfo(" << row << ", idlist[" << idList.count() << "]) : name =" << name);
       
   187 
   192 
   188     return CntContactInfo(contactId, name, text, icons[0], icons[1]);
   193     return CntContactInfo(contactId, name, text, icons[0], icons[1]);
   189 }
   194 }
   190 
   195 
   191 /*! 
   196 /*! 
   192     Clears the cache - both names and icons. This function can be useful
   197     Clears the cache of names (not icons). This function can be useful
   193     for example if application goes to the background and memory needs to
   198     for example when the format of contact names changes.
   194     be freed, or if the format of contact names change.
       
   195  */
   199  */
   196 void CntCache::clearCache()
   200 void CntCache::clearCache()
   197 {
   201 {
   198     DP_IN("CntCache::clearCache()");
   202     CNT_ENTRY
   199 
   203 
   200     // clear info cache
   204     // clear info cache
   201     foreach (CntInfoCacheItem* item, mInfoCache) {
   205     qDeleteAll(mInfoCache);
   202         delete item;
       
   203     }
       
   204     mInfoCache.clear();
   206     mInfoCache.clear();
   205     mNextInfoCacheOrder = CacheOrderStartValue;
   207     mNextInfoCacheOrder = CacheOrderStartValue;
   206 
   208 
   207     // clear icon cache
   209     CNT_EXIT
   208     foreach (CntIconCacheItem* item, mIconCache) {
       
   209         delete item;
       
   210     }
       
   211     mIconCache.clear();
       
   212     mNextIconCacheOrder = CacheOrderStartValue;
       
   213 
       
   214     DP_OUT("CntCache::clearCache()");
       
   215 }
   210 }
   216 
   211 
   217 /*! 
   212 /*! 
   218     Processes a new info field that has arrived from the worker thread.
   213     Processes a new info field that has arrived from the worker thread.
   219     If the contact is in the info cache, then the info cache is updated
   214     If the contact is in the info cache, then the info cache is updated
   223     is if the info is the name of an icon and that icon is not in the icon
   218     is if the info is the name of an icon and that icon is not in the icon
   224     cache. In this case the icon is fetched before a signal is emitted.
   219     cache. In this case the icon is fetched before a signal is emitted.
   225  */
   220  */
   226 void CntCache::onNewInfo(int contactId, const ContactInfoField& infoField, const QString& infoValue)
   221 void CntCache::onNewInfo(int contactId, const ContactInfoField& infoField, const QString& infoValue)
   227 {
   222 {
   228     DP_IN("CntCache::onNewInfo(" << contactId << "," << infoField << "," << infoValue << ")");
   223     CNT_ENTRY_ARGS( "id:" << contactId   << "infotype:" << infoField   << "infovalue:" << infoValue )
   229 
   224 
   230     Q_ASSERT(infoField == ContactInfoTextField || infoField == ContactInfoIcon1Field || infoField == ContactInfoIcon2Field);
   225     Q_ASSERT(infoField == ContactInfoTextField || infoField == ContactInfoIcon1Field || infoField == ContactInfoIcon2Field);
   231 
   226 
   232     bool hasNewInfo;
   227     bool hasNewInfo;
   233 
   228 
   264                 }
   259                 }
   265                 else {
   260                 else {
   266                     hasNewInfo = true;
   261                     hasNewInfo = true;
   267                 }
   262                 }
   268             }
   263             }
       
   264             else if (iconName.startsWith("qtg_", Qt::CaseInsensitive)) {
       
   265                 CntIconCacheItem* iconItem = createIconCacheItem(iconName);
       
   266                 onNewIcon(iconName, HbIcon(iconName)); 
       
   267                 hasNewInfo = true;
       
   268             }
   269             else {
   269             else {
   270                CntIconCacheItem* iconItem = createIconCacheItem(iconName);
   270                 CntIconCacheItem* iconItem = createIconCacheItem(iconName);
   271                iconItem->contactIds.insert(contactId);
   271                 iconItem->contactIds.insert(contactId);
   272                mWorker->scheduleIconJob(iconName);
   272                 mWorker->scheduleIconJob(iconName);
   273                hasNewInfo = false;
   273                 hasNewInfo = false;
   274             }
   274             }
   275         }
   275         }
   276         else {
   276         else {
   277             hasNewInfo = false;
   277             hasNewInfo = false;
   278         }
   278         }
   279     }
   279     }
   280 
   280 
   281     if (hasNewInfo) {
   281     if (hasNewInfo) {
   282         DP("CntCache::onNewInfo() : new info => emitting contactInfoUpdated(" << contactId << ")");
       
   283         emitContactInfoUpdated(contactId);
   282         emitContactInfoUpdated(contactId);
   284     }
   283     }
   285 
   284 
   286     DP_OUT("CntCache::onNewInfo(" << contactId << "," << infoField << "," << infoValue << ")");
   285     CNT_EXIT
   287 }
   286 }
   288 
   287 
   289 /*! 
   288 /*! 
   290     Handle the case where a request for contact info is cancelled by the
   289     Handle the case where a request for contact info is cancelled by the
   291     worker because of too many subsequent requests.
   290     worker because of too many subsequent requests.
   292  */
   291  */
   293 void CntCache::onInfoCancelled(int contactId)
   292 void CntCache::onInfoCancelled(int contactId)
   294 {
   293 {
   295     DP_IN("CntCache::onInfoCancelled(" << contactId << ")");
   294     CNT_ENTRY_ARGS( "id:" << contactId )
   296 
   295 
   297     if (mInfoCache.contains(contactId)) {
   296     if (mInfoCache.contains(contactId)) {
   298         CntInfoCacheItem* item = mInfoCache.take(contactId);
   297         CntInfoCacheItem* item = mInfoCache.take(contactId);
   299         delete item;
   298         delete item;
   300     }
   299     }
   301 
   300 
   302     DP("CntCache::onInfoCancelled() : info cancelled => emitting contactInfoUpdated(" << contactId << ")");
       
   303     emitContactInfoUpdated(contactId);
   301     emitContactInfoUpdated(contactId);
   304 
   302 
   305     DP_OUT("CntCache::onInfoCancelled(" << contactId << ")");
   303     CNT_EXIT
   306 }
   304 }
   307 
   305 
   308 /*! 
   306 /*! 
   309     Processes a new icon that has arrived from the worker thread.
   307     Processes a new icon that has arrived from the worker thread.
   310     The icon cache is updated and a contactInfoUpdated() signal is
   308     The icon cache is updated and a contactInfoUpdated() signal is
   311     emitted for all contacts that use this icon.
   309     emitted for all contacts that use this icon.
   312  */
   310  */
   313 void CntCache::onNewIcon(const QString& iconName, const HbIcon& icon)
   311 void CntCache::onNewIcon(const QString& iconName, const HbIcon& icon)
   314 {
   312 {
   315     DP_IN("CntCache::onNewIcon(" << iconName << ", HbIcon)");
   313     CNT_ENTRY_ARGS( iconName )
   316 
   314 
   317     QSet<int> contactsToNotify;
   315     QSet<int> contactsToNotify;
   318 
   316 
   319     if (mIconCache.contains(iconName)) {
   317     if (mIconCache.contains(iconName)) {
   320         CntIconCacheItem* item = mIconCache.value(iconName);
   318         CntIconCacheItem* item = mIconCache.value(iconName);
   323         contactsToNotify = item->contactIds;
   321         contactsToNotify = item->contactIds;
   324         item->contactIds.clear();
   322         item->contactIds.clear();
   325     }
   323     }
   326 
   324 
   327     foreach (int contactId, contactsToNotify) {
   325     foreach (int contactId, contactsToNotify) {
   328         DP("CntCache::onNewIcon() : new icon => emitting contactInfoUpdated(" << contactId << ")");
       
   329         emitContactInfoUpdated(contactId);
   326         emitContactInfoUpdated(contactId);
   330     }
   327     }
   331 
   328 
   332     DP_OUT("CntCache::onNewIcon(" << iconName << ", HbIcon)");
   329     CNT_EXIT
   333 }
   330 }
   334 
   331 
   335 /*! 
   332 /*! 
   336     Handle the case where a request for an icon is cancelled by the worker because
   333     Handle the case where a request for an icon is cancelled by the worker because
   337     of too many subsequent requests.
   334     of too many subsequent requests.
   338  */
   335  */
   339 void CntCache::onIconCancelled(const QString& iconName)
   336 void CntCache::onIconCancelled(const QString& iconName)
   340 {
   337 {
   341     DP_IN("CntCache::onIconCancelled(" << iconName << ")");
   338     CNT_ENTRY_ARGS( iconName )
   342 
   339 
   343     QSet<int> contactsToNotify;
   340     QSet<int> contactsToNotify;
   344 
   341 
   345     if (mIconCache.contains(iconName)) {
   342     if (mIconCache.contains(iconName)) {
   346         CntIconCacheItem* item = mIconCache.take(iconName);
   343         CntIconCacheItem* item = mIconCache.take(iconName);
   348         item->contactIds.clear();
   345         item->contactIds.clear();
   349         delete item;
   346         delete item;
   350     }
   347     }
   351 
   348 
   352     foreach (int contactId, contactsToNotify) {
   349     foreach (int contactId, contactsToNotify) {
   353         DP("CntCache::onIconCancelled() : icon cancelled => emitting contactInfoUpdated(" << contactId << ")");
       
   354         emitContactInfoUpdated(contactId);
   350         emitContactInfoUpdated(contactId);
   355     }
   351     }
   356 
   352 
   357     DP_OUT("CntCache::onIconCancelled(" << iconName << ")");
   353     CNT_EXIT
       
   354 }
       
   355 
       
   356 /*! 
       
   357     Update contacts in cache.
       
   358     
       
   359     /param contactIds ids of the contact that will be updated
       
   360  */
       
   361 void CntCache::updateContactsInCache(const QList<QContactLocalId>& contactIds)
       
   362 {
       
   363     CNT_ENTRY
       
   364 
       
   365     QString name;
       
   366 
       
   367     foreach (QContactLocalId contactId, contactIds) {
       
   368         if (mInfoCache.contains(contactId) && fetchContactName(contactId, name)) {
       
   369             CntInfoCacheItem* infoItem = mInfoCache.value(contactId);
       
   370             infoItem->name = name;
       
   371             mWorker->scheduleInfoJob(contactId);
       
   372         }
       
   373     }
       
   374 
       
   375     foreach (QContactLocalId contactId, contactIds) {
       
   376         emitContactInfoUpdated(contactId);
       
   377     }
       
   378 
       
   379     CNT_EXIT
   358 }
   380 }
   359 
   381 
   360 /*! 
   382 /*! 
   361     Removes contacts from cache.
   383     Removes contacts from cache.
   362     
   384     
   363     /param contactIds ids of the contact that will be removed
   385     /param contactIds ids of the contact that will be removed
   364  */
   386  */
   365 void CntCache::removeContactsFromCache(const QList<QContactLocalId>& contactIds)
   387 void CntCache::removeContactsFromCache(const QList<QContactLocalId>& contactIds)
   366 {
   388 {
   367     DP_IN("CntCache::removeContactsFromCache(idList[" << contactIds.count() << "])");
   389     CNT_ENTRY
   368 
   390 
   369     foreach (QContactLocalId contactId, contactIds) {
   391     foreach (QContactLocalId contactId, contactIds) {
   370         if (mInfoCache.contains(contactId)) {
   392         if (mInfoCache.contains(contactId)) {
   371             CntInfoCacheItem* item = mInfoCache.take(contactId);
   393             CntInfoCacheItem* item = mInfoCache.take(contactId);
   372             delete item;
   394             delete item;
   375 
   397 
   376     foreach (QContactLocalId contactId, contactIds) {
   398     foreach (QContactLocalId contactId, contactIds) {
   377         emitContactInfoUpdated(contactId);
   399         emitContactInfoUpdated(contactId);
   378     }
   400     }
   379 
   401 
   380     DP_OUT("CntCache::removeContactsFromCache(idList[" << contactIds.count() << "])");
   402     CNT_EXIT
   381 }
   403 }
   382 
   404 
   383 /*! 
   405 /*! 
   384     Uses an optimized function to fetch the name of a contact from
   406     Uses an optimized function to fetch the name of a contact from
   385     the database.
   407     the database.
   388     /param contactName the name will be stored here if the function is successful
   410     /param contactName the name will be stored here if the function is successful
   389     /return true if the name was fetched successfully
   411     /return true if the name was fetched successfully
   390  */
   412  */
   391 bool CntCache::fetchContactName(int contactId, QString& contactName)
   413 bool CntCache::fetchContactName(int contactId, QString& contactName)
   392 {
   414 {
       
   415     CNT_ENTRY_ARGS( contactId )
       
   416 
   393     bool foundContact = false;
   417     bool foundContact = false;
   394     DP_IN("CntCache::fetchContactName(" << contactId << "," << contactName << ")");
       
   395 
   418 
   396     QContactFetchHint nameOnlyFetchHint;
   419     QContactFetchHint nameOnlyFetchHint;
   397     QStringList details;
   420     QStringList details;
   398     details << QContactDisplayLabel::DefinitionName;
   421     details << QContactDisplayLabel::DefinitionName;
   399     nameOnlyFetchHint.setDetailDefinitionsHint(details);
   422     nameOnlyFetchHint.setDetailDefinitionsHint(details);
   400     QContact contact = mContactManager->contact(contactId, nameOnlyFetchHint);
   423     QContact contact = mContactManager->contact(contactId, nameOnlyFetchHint);
   401     
   424     
   402     if (mContactManager->error() == QContactManager::NoError) {
   425     if (mContactManager->error() == QContactManager::NoError) {
   403         contactName = contact.displayLabel();
   426         contactName = contact.displayLabel();
   404         foundContact = true;
   427         foundContact = true;
   405         // TODO: this can be removed once qt mobility is updated (~wk20/10)
   428     }
   406         if (contactName == "Unnamed") {
   429     
   407             contactName = "";
   430     CNT_EXIT_ARGS( foundContact )
   408         }
       
   409     }
       
   410     
       
   411     DP_OUT("CntCache::fetchContactName(" << contactId << "," << contactName << ") : " << foundContact);
       
   412     
   431     
   413     return foundContact;
   432     return foundContact;
   414 }
   433 }
   415 
   434 
   416 /*! 
   435 /*! 
   420     \param mostRecentRow the row of the contact that was most recently fetched
   439     \param mostRecentRow the row of the contact that was most recently fetched
   421     \param idList a list with all the IDs in the list
   440     \param idList a list with all the IDs in the list
   422  */
   441  */
   423 void CntCache::updateReadAheadCache(int mostRecentRow, const QList<QContactLocalId>& idList)
   442 void CntCache::updateReadAheadCache(int mostRecentRow, const QList<QContactLocalId>& idList)
   424 {
   443 {
   425     DP_IN("CntCache::updateReadAheadCache(" << mostRecentRow << ", idList[" << idList.count() << "] )");
   444     CNT_ENTRY_ARGS( mostRecentRow )
       
   445 
   426     int row;
   446     int row;
   427 
   447 
   428     mReadAheadCache.clear();
   448     mReadAheadCache.clear();
   429     
   449     
   430     // step through the area near to last fetch item and make sure all
   450     // step through the area near to last fetch item and make sure all
   454                 mInfoCache.value(contactId)->cacheOrder = mNextInfoCacheOrder++;
   474                 mInfoCache.value(contactId)->cacheOrder = mNextInfoCacheOrder++;
   455             }
   475             }
   456         }
   476         }
   457     }
   477     }
   458 
   478 
   459     DP_OUT("CntCache::updateReadAheadCache(" << mostRecentRow << ", idList[" << idList.count() << "] )");
   479    CNT_EXIT
   460 }
   480 }
   461 
   481 
   462 /*! 
   482 /*! 
   463     Schedules one uncached item in the read-ahead list for retrieval.
   483     Schedules one uncached item in the read-ahead list for retrieval.
   464  */
   484  */
   465 void CntCache::scheduleOneReadAheadItem()
   485 void CntCache::scheduleOneReadAheadItem()
   466 {
   486 {
   467     DP_IN("CntCache::scheduleOneReadAheadItem()");
   487     CNT_ENTRY
   468 
   488 
   469     QString name;
   489     QString name;
   470     
   490     
   471     while (mReadAheadCache.count() > 0) {
   491     while (mReadAheadCache.count() > 0) {
   472         int contactId = mReadAheadCache.takeFirst();
   492         int contactId = mReadAheadCache.takeFirst();
   483                 break;
   503                 break;
   484             }
   504             }
   485         }
   505         }
   486     }
   506     }
   487 
   507 
   488     DP_OUT("CntCache::scheduleOneReadAheadItem()");
   508     CNT_EXIT
   489 }
   509 }
   490 
   510 
   491 /*! 
   511 /*! 
   492     Creates a new item in the info cache. If the cache is full,
   512     Creates a new item in the info cache. If the cache is full,
   493     then the least recently accessed item is removed from cache.
   513     then the least recently accessed item is removed from cache.
   495     /param contactId id of contact for which to create the new cache item
   515     /param contactId id of contact for which to create the new cache item
   496     /return the newly created cache item
   516     /return the newly created cache item
   497  */
   517  */
   498 CntInfoCacheItem* CntCache::createInfoCacheItem(int contactId)
   518 CntInfoCacheItem* CntCache::createInfoCacheItem(int contactId)
   499 {
   519 {
   500     DP_IN("CntCache::createInfoCacheItem(" << contactId << ")");
   520     CNT_ENTRY_ARGS( contactId )
   501 
   521 
   502     if (mInfoCache.count() >= InfoCacheSize) {
   522     if (mInfoCache.count() >= InfoCacheSize) {
   503         // cache is full, so remove the oldest contact
   523         // cache is full, so remove the oldest contact
   504         int minCacheOrder = mNextInfoCacheOrder;
   524         int minCacheOrder = mNextInfoCacheOrder;
   505         CntInfoCacheItem* oldestItem = NULL;
   525         CntInfoCacheItem* oldestItem = NULL;
   526     CntInfoCacheItem* item = new CntInfoCacheItem();
   546     CntInfoCacheItem* item = new CntInfoCacheItem();
   527     item->cacheOrder = mNextInfoCacheOrder++;
   547     item->cacheOrder = mNextInfoCacheOrder++;
   528     item->contactId = contactId;
   548     item->contactId = contactId;
   529     mInfoCache.insert(contactId, item);
   549     mInfoCache.insert(contactId, item);
   530     
   550     
   531     DP_OUT("CntCache::createInfoCacheItem(" << contactId << ")");
   551     CNT_EXIT
   532 
   552 
   533     return item;
   553     return item;
   534 }
   554 }
   535 
   555 
   536 /*! 
   556 /*! 
   540     /param iconName name of the icon for which to create the new cache item
   560     /param iconName name of the icon for which to create the new cache item
   541     /return the newly created cache item
   561     /return the newly created cache item
   542  */
   562  */
   543 CntIconCacheItem* CntCache::createIconCacheItem(const QString& iconName)
   563 CntIconCacheItem* CntCache::createIconCacheItem(const QString& iconName)
   544 {
   564 {
   545     DP_IN("CntCache::createIconCacheItem(" << iconName << ")");
   565     CNT_ENTRY_ARGS( iconName )
   546 
   566 
   547     if (mIconCache.count() >= IconCacheSize) {
   567     if (mIconCache.count() >= IconCacheSize) {
   548         // cache is full, so remove the oldest icon
   568         // cache is full, so remove the oldest icon
   549         int minCacheOrder = mNextIconCacheOrder;
   569         int minCacheOrder = mNextIconCacheOrder;
   550         CntIconCacheItem* oldestItem = NULL;
   570         CntIconCacheItem* oldestItem = NULL;
   572     item->cacheOrder = mNextIconCacheOrder++;
   592     item->cacheOrder = mNextIconCacheOrder++;
   573     item->iconName = iconName;
   593     item->iconName = iconName;
   574     item->isFetched = false;
   594     item->isFetched = false;
   575     mIconCache.insert(iconName, item);
   595     mIconCache.insert(iconName, item);
   576 
   596 
   577     DP_OUT("CntCache::createIconCacheItem(" << iconName << ")");
   597     CNT_EXIT
   578 
   598 
   579     return item;
   599     return item;
   580 }
   600 }
   581 
   601 
   582 /*! 
   602 /*! 
   584     Clients can then request the info via fetchContactInfo() 
   604     Clients can then request the info via fetchContactInfo() 
   585     if they are interested.
   605     if they are interested.
   586  */
   606  */
   587 void CntCache::emitContactInfoUpdated(int contactId)
   607 void CntCache::emitContactInfoUpdated(int contactId)
   588 {
   608 {
       
   609 	CNT_ENTRY_ARGS( contactId )
       
   610 
   589     mEmittedContactId = contactId;
   611     mEmittedContactId = contactId;
   590     emit contactInfoUpdated(contactId);
   612     emit contactInfoUpdated(contactId);
   591     mEmittedContactId = -1;
   613     mEmittedContactId = -1;
       
   614 
       
   615 	CNT_EXIT
   592 }
   616 }
   593 
   617 
   594 /*! 
   618 /*! 
   595     Deletes the cache.
   619     Deletes the cache.
   596  */
   620  */
   597 void CntCache::onShutdown()
   621 void CntCache::onShutdown()
   598 {
   622 {
       
   623 	CNT_ENTRY
       
   624 
   599     delete this;
   625     delete this;
       
   626 
       
   627 	CNT_EXIT
   600 }
   628 }
   601 
   629 
   602 
   630 
   603 /*! 
   631 /*! 
   604     Creates an empty object.
   632     Creates an empty object.