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 pull request #4 from matthewvogt/export-group-members
[libcontacts] Export name group members for potential filtration
  • Loading branch information
matthewvogt committed Jul 29, 2013
2 parents 4123ad5 + e83f54d commit 4ff8b7c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
37 changes: 22 additions & 15 deletions src/seasidecache.cpp
Expand Up @@ -392,11 +392,11 @@ QList<QChar> SeasideCache::allNameGroups()
return allContactNameGroups;
}

QHash<QChar, int> SeasideCache::nameGroupCounts()
QHash<QChar, QSet<quint32> > SeasideCache::nameGroupMembers()
{
if (instancePtr)
return instancePtr->m_contactNameGroups;
return QHash<QChar, int>();
return QHash<QChar, QSet<quint32> >();
}

SeasideCache::DisplayLabelOrder SeasideCache::displayLabelOrder()
Expand Down Expand Up @@ -459,8 +459,11 @@ SeasideCache::CacheItem *SeasideCache::itemById(int id)

SeasideCache::CacheItem *SeasideCache::existingItem(const ContactIdType &id)
{
quint32 iid = internalId(id);
return existingItem(internalId(id));
}

SeasideCache::CacheItem *SeasideCache::existingItem(quint32 iid)
{
QHash<quint32, CacheItem>::iterator it = instancePtr->m_people.find(iid);
return it != instancePtr->m_people.end()
? &(*it)
Expand Down Expand Up @@ -1115,8 +1118,8 @@ void SeasideCache::contactsAvailable()
// do this even if !roleDataChanged as name groups are affected by other display label changes
QChar newNameGroup = nameGroupForCacheItem(&item);
if (newNameGroup != oldNameGroup) {
addToContactNameGroup(newNameGroup, &modifiedGroups);
removeFromContactNameGroup(oldNameGroup, &modifiedGroups);
addToContactNameGroup(item.iid, newNameGroup, &modifiedGroups);
removeFromContactNameGroup(item.iid, oldNameGroup, &modifiedGroups);
}
}

Expand All @@ -1131,19 +1134,19 @@ void SeasideCache::contactsAvailable()
}
}

void SeasideCache::addToContactNameGroup(const QChar &group, QList<QChar> *modifiedGroups)
void SeasideCache::addToContactNameGroup(quint32 iid, const QChar &group, QList<QChar> *modifiedGroups)
{
if (!group.isNull()) {
m_contactNameGroups[group] += 1;
m_contactNameGroups[group].insert(iid);
if (modifiedGroups && !m_nameGroupChangeListeners.isEmpty())
modifiedGroups->append(group);
}
}

void SeasideCache::removeFromContactNameGroup(const QChar &group, QList<QChar> *modifiedGroups)
void SeasideCache::removeFromContactNameGroup(quint32 iid, const QChar &group, QList<QChar> *modifiedGroups)
{
if (!group.isNull() && m_contactNameGroups.contains(group)) {
m_contactNameGroups[group] -= 1;
m_contactNameGroups[group].remove(iid);
if (modifiedGroups && !m_nameGroupChangeListeners.isEmpty())
modifiedGroups->append(group);
}
Expand All @@ -1154,7 +1157,7 @@ void SeasideCache::notifyNameGroupsChanged(const QList<QChar> &groups)
if (groups.isEmpty() || m_nameGroupChangeListeners.isEmpty())
return;

QHash<QChar, int> updates;
QHash<QChar, QSet<quint32> > updates;
for (int i = 0; i < groups.count(); ++i)
updates[groups[i]] = m_contactNameGroups[groups[i]];

Expand Down Expand Up @@ -1226,9 +1229,11 @@ void SeasideCache::removeRange(

for (int i = 0; i < count; ++i) {
if (filter == FilterAll) {
m_expiredContacts[cacheIds.at(index)] -= 1;
const ContactIdType apiId = cacheIds.at(index);
m_expiredContacts[apiId] -= 1;

removeFromContactNameGroup(nameGroupForCacheItem(existingItem(cacheIds.at(index))), &modifiedNameGroups);
const QChar nameGroup = nameGroupForCacheItem(existingItem(apiId));
removeFromContactNameGroup(internalId(apiId), nameGroup, &modifiedNameGroups);
}

cacheIds.remove(index);
Expand Down Expand Up @@ -1262,9 +1267,11 @@ int SeasideCache::insertRange(
continue;

if (filter == FilterAll) {
m_expiredContacts[queryIds.at(queryIndex + i)] += 1;
const ContactIdType apiId = queryIds.at(queryIndex + i);
m_expiredContacts[apiId] += 1;

addToContactNameGroup(nameGroupForCacheItem(existingItem(queryIds.at(queryIndex + i))), &modifiedNameGroups);
const QChar nameGroup = nameGroupForCacheItem(existingItem(apiId));
addToContactNameGroup(internalId(apiId), nameGroup, &modifiedNameGroups);
}

cacheIds.insert(index + i, queryIds.at(queryIndex + i));
Expand Down Expand Up @@ -1304,7 +1311,7 @@ void SeasideCache::appendContacts(const QList<QContact> &contacts)
cacheItem.contactState = ContactFetched;

if (m_fetchFilter == FilterAll)
addToContactNameGroup(nameGroupForCacheItem(&cacheItem), 0);
addToContactNameGroup(iid, nameGroupForCacheItem(&cacheItem), 0);

foreach (const QContactPhoneNumber &phoneNumber, contact.details<QContactPhoneNumber>()) {
QString normalizedNumber = Normalization::normalizePhoneNumber(phoneNumber.number());
Expand Down
16 changes: 9 additions & 7 deletions src/seasidecache.h
Expand Up @@ -72,7 +72,7 @@ class CONTACTCACHE_EXPORT SeasideNameGroupChangeListener
SeasideNameGroupChangeListener() {}
~SeasideNameGroupChangeListener() {}

virtual void nameGroupsUpdated(const QHash<QChar, int> &groups) = 0;
virtual void nameGroupsUpdated(const QHash<QChar, QSet<quint32> > &groups) = 0;
};

class CONTACTCACHE_EXPORT SeasideCache : public QObject
Expand Down Expand Up @@ -125,14 +125,15 @@ class CONTACTCACHE_EXPORT SeasideCache : public QObject

struct CacheItem
{
CacheItem() : itemData(0), modelData(0), contactState(ContactAbsent) {}
CacheItem(const QContact &contact) : contact(contact), itemData(0), modelData(0), contactState(ContactAbsent) {}
CacheItem() : itemData(0), modelData(0), iid(0), contactState(ContactAbsent) {}
CacheItem(const QContact &contact) : contact(contact), itemData(0), modelData(0), iid(internalId(contact)), contactState(ContactAbsent) {}

ContactIdType apiId() const { return SeasideCache::apiId(contact); }

QContact contact;
ItemData *itemData;
ModelData *modelData;
quint32 iid;
ContactState contactState;
};

Expand Down Expand Up @@ -190,6 +191,7 @@ class CONTACTCACHE_EXPORT SeasideCache : public QObject
static int contactId(const QContact &contact);

static CacheItem *existingItem(const ContactIdType &id);
static CacheItem *existingItem(quint32 iid);
static CacheItem *itemById(const ContactIdType &id);
#ifdef USING_QTPIM
static CacheItem *itemById(int id);
Expand All @@ -198,7 +200,7 @@ class CONTACTCACHE_EXPORT SeasideCache : public QObject
static QContact contactById(const ContactIdType &id);
static QChar nameGroupForCacheItem(CacheItem *cacheItem);
static QList<QChar> allNameGroups();
static QHash<QChar, int> nameGroupCounts();
static QHash<QChar, QSet<quint32> > nameGroupMembers();

static CacheItem *itemByPhoneNumber(const QString &msisdn);
static CacheItem *itemByEmailAddress(const QString &email);
Expand Down Expand Up @@ -274,8 +276,8 @@ private slots:
void removeContactData(const ContactIdType &contactId, FilterType filter);
void makePopulated(FilterType filter);

void addToContactNameGroup(const QChar &group, QList<QChar> *modifiedGroups = 0);
void removeFromContactNameGroup(const QChar &group, QList<QChar> *modifiedGroups = 0);
void addToContactNameGroup(quint32 iid, const QChar &group, QList<QChar> *modifiedGroups = 0);
void removeFromContactNameGroup(quint32 iid, const QChar &group, QList<QChar> *modifiedGroups = 0);
void notifyNameGroupsChanged(const QList<QChar> &groups);

void updateConstituentAggregations(const ContactIdType &contactId);
Expand All @@ -289,7 +291,7 @@ private slots:
QHash<QString, quint32> m_phoneNumberIds;
QHash<QString, quint32> m_emailAddressIds;
QHash<ContactIdType, QContact> m_contactsToSave;
QHash<QChar, int> m_contactNameGroups;
QHash<QChar, QSet<quint32> > m_contactNameGroups;
QList<QContact> m_contactsToCreate;
QList<ContactIdType> m_contactsToRemove;
QList<ContactIdType> m_changedContacts;
Expand Down

0 comments on commit 4ff8b7c

Please sign in to comment.