From 15b46be417bf00c4f2024cf86a6265bb9b3520a6 Mon Sep 17 00:00:00 2001 From: Matt Vogt Date: Tue, 7 Jan 2014 15:37:30 -0800 Subject: [PATCH] [libcontacts] Fetch extra details to faciliate search When idle, fetch extra contact details used to populate the search model data set. --- src/seasidecache.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++ src/seasidecache.h | 4 ++- 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/seasidecache.cpp b/src/seasidecache.cpp index b994b9b..3bd859d 100644 --- a/src/seasidecache.cpp +++ b/src/seasidecache.cpp @@ -232,6 +232,33 @@ QContactFetchHint favoriteFetchHint(quint32 fetchTypes = 0) return fetchHint; } +QContactFetchHint extendedMetadataFetchHint(quint32 fetchTypes) +{ + QContactFetchHint fetchHint(basicFetchHint()); + + DetailList types; + + // Only query for the specific types we need + if (fetchTypes & SeasideCache::FetchAccountUri) { + types << detailType(); + } + if (fetchTypes & SeasideCache::FetchPhoneNumber) { + types << detailType(); + } + if (fetchTypes & SeasideCache::FetchEmailAddress) { + types << detailType(); + } + if (fetchTypes & SeasideCache::FetchNickname) { + types << detailType(); + } + if (fetchTypes & SeasideCache::FetchOrganization) { + types << detailType(); + } + + setDetailTypesHint(fetchHint, types); + return fetchHint; +} + QContactFilter allFilter() { return QContactFilter(); @@ -1703,6 +1730,45 @@ bool SeasideCache::event(QEvent *event) } if (!requestPending) { + // No remaining work is pending - do we have any background tasks? + + if (m_keepPopulated) { + // Load extra data items that we want to be able to search on, if not already fetched + const quint32 fetchMask = (SeasideCache::FetchNickname | + SeasideCache::FetchOrganization | + SeasideCache::FetchPhoneNumber | + SeasideCache::FetchEmailAddress | + SeasideCache::FetchAccountUri); + + if ((m_fetchTypes & fetchMask) != fetchMask) { + m_fetchRequest.setFilter(allFilter()); + + quint32 fetchType = 0; + if ((m_fetchTypes & SeasideCache::FetchNickname) == 0) { + fetchType = SeasideCache::FetchNickname; + } else if ((m_fetchTypes & SeasideCache::FetchOrganization) == 0) { + fetchType = SeasideCache::FetchOrganization; + } else if ((m_fetchTypes & SeasideCache::FetchPhoneNumber) == 0) { + fetchType = SeasideCache::FetchPhoneNumber; + m_fetchRequest.setFilter(QContactStatusFlags::matchFlag(QContactStatusFlags::HasPhoneNumber, QContactFilter::MatchContains)); + } else if ((m_fetchTypes & SeasideCache::FetchEmailAddress) == 0) { + fetchType = SeasideCache::FetchEmailAddress; + m_fetchRequest.setFilter(QContactStatusFlags::matchFlag(QContactStatusFlags::HasEmailAddress, QContactFilter::MatchContains)); + } else { + fetchType = SeasideCache::FetchAccountUri; + m_fetchRequest.setFilter(QContactStatusFlags::matchFlag(QContactStatusFlags::HasOnlineAccount, QContactFilter::MatchContains)); + } + + m_fetchRequest.setFetchHint(extendedMetadataFetchHint(fetchType)); + m_fetchRequest.start(); + + m_fetchProcessedCount = 0; + m_fetchTypes |= fetchType; + + return true; + } + } + m_updatesPending = false; // Remove expired contacts when all other activity has been processed diff --git a/src/seasidecache.h b/src/seasidecache.h index ec5c0e7..dd14175 100644 --- a/src/seasidecache.h +++ b/src/seasidecache.h @@ -102,7 +102,9 @@ class CONTACTCACHE_EXPORT SeasideCache : public QObject FetchNone = 0, FetchAccountUri = (1 << 0), FetchPhoneNumber = (1 << 1), - FetchEmailAddress = (1 << 2) + FetchEmailAddress = (1 << 2), + FetchNickname = (1 << 3), + FetchOrganization = (1 << 4) }; enum DisplayLabelOrder {