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

Commit

Permalink
Merge pull request #41 from matthewvogt/detail-persistence
Browse files Browse the repository at this point in the history
Detail persistence
  • Loading branch information
matthewvogt committed Oct 2, 2013
2 parents 5e5693d + f25b399 commit 9f2a6e0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 36 deletions.
71 changes: 37 additions & 34 deletions src/seasidecache.cpp
Expand Up @@ -355,7 +355,6 @@ SeasideCache::SeasideCache()
, m_sortPropertyConf(QLatin1String("/org/nemomobile/contacts/sort_property"))
, m_groupPropertyConf(QLatin1String("/org/nemomobile/contacts/group_property"))
#endif
, m_resultsRead(0)
, m_populated(0)
, m_cacheIndex(0)
, m_queryIndex(0)
Expand Down Expand Up @@ -670,6 +669,9 @@ SeasideCache::CacheItem *SeasideCache::itemById(const ContactIdType &id, bool re
} else {
// Insert a new item into the cache if the one doesn't exist.
item = &(instancePtr->m_people[iid]);
item->iid = iid;
item->contactState = ContactAbsent;

#ifdef USING_QTPIM
item->contact.setId(id);
#else
Expand Down Expand Up @@ -1307,8 +1309,6 @@ bool SeasideCache::event(QEvent *event)
m_fetchTypesChanged = false;
m_populateProgress = RefetchFavorites;
} else if (!m_changedContacts.isEmpty() && !m_fetchRequest.isActive()) {
m_resultsRead = 0;

#ifdef USING_QTPIM
QContactIdFilter filter;
#else
Expand Down Expand Up @@ -1364,7 +1364,6 @@ bool SeasideCache::event(QEvent *event)
} else if (m_refreshRequired && !m_contactIdRequest.isActive()) {
m_refreshRequired = false;

m_resultsRead = 0;
m_syncFilter = FilterFavorites;
m_contactIdRequest.setFilter(favoriteFilter());
m_contactIdRequest.setSorting(m_sortOrder);
Expand Down Expand Up @@ -1688,6 +1687,17 @@ bool SeasideCache::updateContactIndexing(const QContact &oldContact, const QCont
return modified;
}

void updateDetailsFromCache(QContact &contact, SeasideCache::CacheItem *item, const QSet<DetailTypeId> &queryDetailTypes)
{
// Copy any existing detail types that are in the current record to the new instance
foreach (const QContactDetail &existing, item->contact.details()) {
if (!queryDetailTypes.contains(detailType(existing))) {
QContactDetail copy(existing);
contact.saveDetail(&copy);
}
}
}

void SeasideCache::contactsAvailable()
{
QContactAbstractRequest *request = static_cast<QContactAbstractRequest *>(sender());
Expand Down Expand Up @@ -1721,39 +1731,29 @@ void SeasideCache::contactsAvailable()
FilterType type(m_populateProgress == FetchFavorites ? FilterFavorites
: (m_populateProgress == FetchMetadata ? FilterAll
: FilterOnline));
appendContacts(contacts, type, partialFetch);
appendContacts(contacts, type, partialFetch, queryDetailTypes);
} else {
// An update.
QSet<QString> modifiedGroups;

for (int i = m_resultsRead; i < contacts.count(); ++i) {
QContact contact = contacts.at(i);
foreach (QContact contact, contacts) {
quint32 iid = internalId(contact);

CacheItem *item = existingItem(iid);
QString oldNameGroup;
QString oldDisplayLabel;

const bool preexisting = (item != 0);
CacheItem *item = existingItem(iid);
if (!item) {
// We haven't seen this contact before
item = &(m_people[iid]);
item->iid = iid;
}

QString oldNameGroup;
QString oldDisplayLabel;

if (preexisting) {
} else {
oldNameGroup = item->nameGroup;
oldDisplayLabel = item->displayLabel;

if (partialFetch) {
// Copy any existing detail types that are in the current record to the new instance
foreach (const QContactDetail &existing, item->contact.details()) {
if (!queryDetailTypes.contains(detailType(existing))) {
QContactDetail copy(existing);
contact.saveDetail(&copy);
}
}
// Update our new instance with any details not returned by the current query
updateDetailsFromCache(contact, item, queryDetailTypes);
}
}

Expand Down Expand Up @@ -1786,7 +1786,7 @@ void SeasideCache::contactsAvailable()
instancePtr->contactDataChanged(item->iid);
}
}
m_resultsRead = contacts.count();

notifyNameGroupsChanged(modifiedGroups);
}
}
Expand Down Expand Up @@ -1913,7 +1913,7 @@ int SeasideCache::insertRange(FilterType filter, int index, int count, const QLi
return end - index + 1;
}

void SeasideCache::appendContacts(const QList<QContact> &contacts, FilterType filterType, bool partialFetch)
void SeasideCache::appendContacts(const QList<QContact> &contacts, FilterType filterType, bool partialFetch, const QSet<DetailTypeId> &queryDetailTypes)
{
if (!contacts.isEmpty()) {
QList<quint32> &cacheIds = m_contacts[filterType];
Expand All @@ -1932,21 +1932,24 @@ void SeasideCache::appendContacts(const QList<QContact> &contacts, FilterType fi

foreach (QContact contact, contacts) {
quint32 iid = internalId(contact);

cacheIds.append(iid);

CacheItem &cacheItem = m_people[iid];

// If we have already requested this contact as a favorite, don't update with fewer details
if ((cacheItem.iid == 0) ||
(cacheItem.contact.detail<QContactFavorite>().isFavorite() == false)) {
cacheItem.iid = iid;
updateContactIndexing(QContact(), contact, iid, QSet<DetailTypeId>(), &cacheItem);
updateCache(&cacheItem, contact, partialFetch);
CacheItem *item = existingItem(iid);
if (!item) {
item = &(m_people[iid]);
item->iid = iid;
} else {
if (partialFetch) {
// Update our new instance with any details not returned by the current query
updateDetailsFromCache(contact, item, queryDetailTypes);
}
}

updateContactIndexing(item->contact, contact, iid, queryDetailTypes, item);
updateCache(item, contact, partialFetch);

if (filterType == FilterAll) {
addToContactNameGroup(iid, nameGroup(&cacheItem), &modifiedGroups);
addToContactNameGroup(iid, nameGroup(item), &modifiedGroups);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/seasidecache.h
Expand Up @@ -390,7 +390,7 @@ private slots:
void keepPopulated(quint32 fetchTypes);

void requestUpdate();
void appendContacts(const QList<QContact> &contacts, FilterType filterType, bool partialFetch);
void appendContacts(const QList<QContact> &contacts, FilterType filterType, bool partialFetch, const QSet<DetailTypeId> &queryDetailTypes);
void fetchContacts();
void updateContacts(const QList<ContactIdType> &contactIds);

Expand Down Expand Up @@ -465,7 +465,6 @@ private slots:
MGConfItem m_sortPropertyConf;
MGConfItem m_groupPropertyConf;
#endif
int m_resultsRead;
int m_populated;
int m_cacheIndex;
int m_queryIndex;
Expand Down

0 comments on commit 9f2a6e0

Please sign in to comment.