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
[libcontacts] Fetch extra details to faciliate search
When idle, fetch extra contact details used to populate the search model
data set.
  • Loading branch information
matthewvogt committed Jan 9, 2014
1 parent f08f29e commit 15b46be
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
66 changes: 66 additions & 0 deletions src/seasidecache.cpp
Expand Up @@ -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<QContactOnlineAccount>();
}
if (fetchTypes & SeasideCache::FetchPhoneNumber) {
types << detailType<QContactPhoneNumber>();
}
if (fetchTypes & SeasideCache::FetchEmailAddress) {
types << detailType<QContactEmailAddress>();
}
if (fetchTypes & SeasideCache::FetchNickname) {
types << detailType<QContactNickname>();
}
if (fetchTypes & SeasideCache::FetchOrganization) {
types << detailType<QContactOrganization>();
}

setDetailTypesHint(fetchHint, types);
return fetchHint;
}

QContactFilter allFilter()
{
return QContactFilter();
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/seasidecache.h
Expand Up @@ -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 {
Expand Down

0 comments on commit 15b46be

Please sign in to comment.