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 #18 from matthewvogt/cache-display-label
Browse files Browse the repository at this point in the history
Cache display label
  • Loading branch information
matthewvogt committed Aug 19, 2013
2 parents 3782204 + 4d7ccc7 commit c12c0a6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 47 deletions.
66 changes: 21 additions & 45 deletions src/seasidecache.cpp
Expand Up @@ -571,12 +571,8 @@ QChar SeasideCache::determineNameGroup(const CacheItem *cacheItem)
group = first[0].toUpper();
} else if (!last.isEmpty()) {
group = last[0].toUpper();
} else {
QString displayLabel = (cacheItem->itemData)
? cacheItem->itemData->getDisplayLabel()
: generateDisplayLabel(cacheItem->contact);
if (!displayLabel.isEmpty())
group = displayLabel[0].toUpper();
} else if (!cacheItem->displayLabel.isEmpty()) {
group = cacheItem->displayLabel[0].toUpper();
}

// XXX temporary workaround for non-latin names: use non-name details to try to find a
Expand Down Expand Up @@ -691,12 +687,17 @@ QContact SeasideCache::contactById(const ContactIdType &id)
void SeasideCache::ensureCompletion(CacheItem *cacheItem)
{
if (cacheItem->contactState < ContactRequested) {
cacheItem->contactState = ContactRequested;
instancePtr->m_changedContacts.append(cacheItem->apiId());
instancePtr->fetchContacts();
refreshContact(cacheItem);
}
}

void SeasideCache::refreshContact(CacheItem *cacheItem)
{
cacheItem->contactState = ContactRequested;
instancePtr->m_changedContacts.append(cacheItem->apiId());
instancePtr->fetchContacts();
}

SeasideCache::CacheItem *SeasideCache::itemByPhoneNumber(const QString &number, bool requireComplete)
{
QString normalizedNumber = Normalization::normalizePhoneNumber(number);
Expand Down Expand Up @@ -888,14 +889,6 @@ QString SeasideCache::generateDisplayLabel(const QContact &contact, DisplayLabel
{
QContactName name = contact.detail<QContactName>();

#ifdef USING_QTPIM
QString customLabel = name.value<QString>(QContactName__FieldCustomLabel);
#else
QString customLabel = name.customLabel();
#endif
if (!customLabel.isEmpty())
return customLabel;

QString displayLabel;

QString nameStr1;
Expand Down Expand Up @@ -1422,6 +1415,7 @@ void SeasideCache::updateCache(CacheItem *item, const QContact &contact, bool pa

// Check if the name group has changed
item->nameGroup = determineNameGroup(item);
item->displayLabel = generateDisplayLabel(item->contact, m_displayLabelOrder);
}

bool SeasideCache::updateContactIndexing(const QContact &oldContact, const QContact &contact, quint32 iid, const QSet<DetailTypeId> &queryDetailTypes)
Expand Down Expand Up @@ -1535,11 +1529,11 @@ void SeasideCache::contactsAvailable()
}

QChar oldNameGroup;
QContactName oldName;
QString oldDisplayLabel;

if (preexisting) {
oldNameGroup = item->nameGroup;
oldName = item->contact.detail<QContactName>();
oldDisplayLabel = item->displayLabel;

if (partialFetch) {
// Copy any existing detail types that are in the current record to the new instance
Expand All @@ -1552,28 +1546,13 @@ void SeasideCache::contactsAvailable()
}
}

QContactName newName = contact.detail<QContactName>();

#ifdef USING_QTPIM
if (newName.value<QString>(QContactName__FieldCustomLabel).isEmpty()) {
#else
if (newName.customLabel().isEmpty()) {
#endif
// Maintain the existing custom label value if we have set it
#ifdef USING_QTPIM
newName.setValue(QContactName__FieldCustomLabel, oldName.value(QContactName__FieldCustomLabel));
#else
newName.setCustomLabel(oldName.customLabel());
#endif
contact.saveDetail(&newName);
}

// This is a simplification of reality, should we test more changes?
bool roleDataChanged = (newName != oldName) ||
contact.detail<QContactAvatar>().imageUrl() != item->contact.detail<QContactAvatar>().imageUrl();
bool roleDataChanged = contact.detail<QContactAvatar>().imageUrl() != item->contact.detail<QContactAvatar>().imageUrl();

roleDataChanged |= updateContactIndexing(item->contact, contact, iid, queryDetailTypes);

updateCache(item, contact, partialFetch);
roleDataChanged |= (item->displayLabel != oldDisplayLabel);

// do this even if !roleDataChanged as name groups are affected by other display label changes
if (item->nameGroup != oldNameGroup) {
Expand Down Expand Up @@ -2003,16 +1982,11 @@ void SeasideCache::displayLabelOrderChanged()
for (iterator it = m_people.begin(); it != m_people.end(); ++it) {
if (it->itemData) {
it->itemData->displayLabelOrderChanged(m_displayLabelOrder);
} else {
QContactName name = it->contact.detail<QContactName>();
#ifdef USING_QTPIM
name.setValue(QContactName__FieldCustomLabel, generateDisplayLabel(it->contact));
#else
name.setCustomLabel(generateDisplayLabel(it->contact));
#endif
it->contact.saveDetail(&name);
}

// Regenerate the display label
it->displayLabel = generateDisplayLabel(it->contact, m_displayLabelOrder);

// Update the nameGroup for this contact
const QChar group(determineNameGroup(&*it));
if (group != it->nameGroup) {
Expand All @@ -2023,6 +1997,8 @@ void SeasideCache::displayLabelOrderChanged()
it->nameGroup = group;
addToContactNameGroup(it->iid, it->nameGroup, &modifiedGroups);
}

contactDataChanged(apiId(it->iid));
}

notifyNameGroupsChanged(modifiedGroups);
Expand Down
3 changes: 2 additions & 1 deletion src/seasidecache.h
Expand Up @@ -122,7 +122,6 @@ class CONTACTCACHE_EXPORT SeasideCache : public QObject
{
virtual ~ItemData() {}

virtual QString getDisplayLabel() const = 0;
virtual void displayLabelOrderChanged(DisplayLabelOrder order) = 0;

virtual void updateContact(const QContact &newContact, QContact *oldContact, ContactState state) = 0;
Expand Down Expand Up @@ -208,6 +207,7 @@ class CONTACTCACHE_EXPORT SeasideCache : public QObject
ContactState contactState;
ItemListener *listeners;
QChar nameGroup;
QString displayLabel;
};

struct ContactLinkRequest
Expand Down Expand Up @@ -302,6 +302,7 @@ class CONTACTCACHE_EXPORT SeasideCache : public QObject
static QContact contactById(const ContactIdType &id);

static void ensureCompletion(CacheItem *cacheItem);
static void refreshContact(CacheItem *cacheItem);

static QChar nameGroup(const CacheItem *cacheItem);
static QChar determineNameGroup(const CacheItem *cacheItem);
Expand Down
2 changes: 1 addition & 1 deletion src/src.pro
Expand Up @@ -10,7 +10,7 @@ target.path = $$PREFIX/lib
INSTALLS += target

# set version for generated pkgconfig files
VERSION=0.0.12
VERSION=0.0.13
QMAKE_PKGCONFIG_INCDIR = $$PREFIX/include/$${PACKAGENAME}
QMAKE_PKGCONFIG_LIBDIR = $$PREFIX/lib
QMAKE_PKGCONFIG_DESTDIR = pkgconfig
Expand Down

0 comments on commit c12c0a6

Please sign in to comment.