Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'mer-1545' into 'master'
[libcontacts] Ensure cache is instantiated before resolution attempt. Contributes to MER#1545



See merge request !3
  • Loading branch information
matthewvogt committed Mar 25, 2016
2 parents 1c1120c + 42d6a12 commit 3712c49
Showing 1 changed file with 34 additions and 23 deletions.
57 changes: 34 additions & 23 deletions src/seasidecache.cpp
Expand Up @@ -517,6 +517,9 @@ QContactManager* SeasideCache::manager()

SeasideCache* SeasideCache::instance()
{
if (!instancePtr) {
instancePtr = new SeasideCache;
}
return instancePtr;
}

Expand Down Expand Up @@ -563,9 +566,6 @@ SeasideCache::SeasideCache()
, m_contactsUpdated(false)
, m_displayOff(false)
{
Q_ASSERT(!instancePtr);
instancePtr = this;

m_timer.start();
m_fetchPostponed.invalidate();

Expand Down Expand Up @@ -656,13 +656,12 @@ void SeasideCache::checkForExpiry()

void SeasideCache::registerModel(ListModel *model, FilterType type, FetchDataType requiredTypes, FetchDataType extraTypes)
{
if (!instancePtr) {
new SeasideCache;
} else {
instancePtr->m_expiryTimer.stop();
for (int i = 0; i < FilterTypesCount; ++i)
instancePtr->m_models[i].removeAll(model);
}
// Ensure the cache has been instantiated
instance();

instancePtr->m_expiryTimer.stop();
for (int i = 0; i < FilterTypesCount; ++i)
instancePtr->m_models[i].removeAll(model);

instancePtr->m_models[type].append(model);

Expand All @@ -683,11 +682,10 @@ void SeasideCache::unregisterModel(ListModel *model)

void SeasideCache::registerUser(QObject *user)
{
if (!instancePtr) {
new SeasideCache;
} else {
instancePtr->m_expiryTimer.stop();
}
// Ensure the cache has been instantiated
instance();

instancePtr->m_expiryTimer.stop();
instancePtr->m_users.insert(user);
}

Expand All @@ -700,8 +698,9 @@ void SeasideCache::unregisterUser(QObject *user)

void SeasideCache::registerNameGroupChangeListener(SeasideNameGroupChangeListener *listener)
{
if (!instancePtr)
new SeasideCache;
// Ensure the cache has been instantiated
instance();

instancePtr->m_nameGroupChangeListeners.append(listener);
}

Expand All @@ -714,8 +713,9 @@ void SeasideCache::unregisterNameGroupChangeListener(SeasideNameGroupChangeListe

void SeasideCache::registerChangeListener(ChangeListener *listener)
{
if (!instancePtr)
new SeasideCache;
// Ensure the cache has been instantiated
instance();

instancePtr->m_changeListeners.append(listener);
}

Expand Down Expand Up @@ -772,8 +772,9 @@ void SeasideCache::unregisterResolveListener(ResolveListener *listener)

void SeasideCache::setNameGrouper(SeasideNameGrouper *grouper)
{
if (!instancePtr)
new SeasideCache;
// Ensure the cache has been instantiated
instance();

instancePtr->m_nameGrouper.reset(grouper);

allContactNameGroups = instancePtr->m_nameGrouper->allNameGroups();
Expand Down Expand Up @@ -841,8 +842,9 @@ QString SeasideCache::determineNameGroup(const CacheItem *cacheItem)

QStringList SeasideCache::allNameGroups()
{
if (!instancePtr)
new SeasideCache;
// Ensure the cache has been instantiated
instance();

return allContactNameGroups;
}

Expand Down Expand Up @@ -999,6 +1001,9 @@ SeasideCache::CacheItem *SeasideCache::itemByOnlineAccount(const QString &localU

SeasideCache::CacheItem *SeasideCache::resolvePhoneNumber(ResolveListener *listener, const QString &number, bool requireComplete)
{
// Ensure the cache has been instantiated
instance();

CacheItem *item = itemByPhoneNumber(number, requireComplete);
if (!item) {
// Don't bother trying to resolve an invalid number
Expand All @@ -1023,6 +1028,9 @@ SeasideCache::CacheItem *SeasideCache::resolvePhoneNumber(ResolveListener *liste

SeasideCache::CacheItem *SeasideCache::resolveEmailAddress(ResolveListener *listener, const QString &address, bool requireComplete)
{
// Ensure the cache has been instantiated
instance();

CacheItem *item = itemByEmailAddress(address, requireComplete);
if (!item) {
instancePtr->resolveAddress(listener, address, QString(), requireComplete);
Expand All @@ -1034,6 +1042,9 @@ SeasideCache::CacheItem *SeasideCache::resolveEmailAddress(ResolveListener *list

SeasideCache::CacheItem *SeasideCache::resolveOnlineAccount(ResolveListener *listener, const QString &localUid, const QString &remoteUid, bool requireComplete)
{
// Ensure the cache has been instantiated
instance();

CacheItem *item = itemByOnlineAccount(localUid, remoteUid, requireComplete);
if (!item) {
instancePtr->resolveAddress(listener, localUid, remoteUid, requireComplete);
Expand Down

0 comments on commit 3712c49

Please sign in to comment.