Commit 2aec0bc4 authored by mvogt's avatar mvogt

[libcontacts] Cache displayLabel with cache item

Remove the older use of custom label field to cache calculated display
label value.
parent 3782204c
......@@ -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
......@@ -888,14 +884,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;
......@@ -1422,6 +1410,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)
......@@ -1535,11 +1524,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
......@@ -1552,28 +1541,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) {
......@@ -2003,16 +1977,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) {
......@@ -2023,6 +1992,8 @@ void SeasideCache::displayLabelOrderChanged()
it->nameGroup = group;
addToContactNameGroup(it->iid, it->nameGroup, &modifiedGroups);
}
contactDataChanged(apiId(it->iid));
}
notifyNameGroupsChanged(modifiedGroups);
......
......@@ -122,7 +122,6 @@ public:
{
virtual ~ItemData() {}
virtual QString getDisplayLabel() const = 0;
virtual void displayLabelOrderChanged(DisplayLabelOrder order) = 0;
virtual void updateContact(const QContact &newContact, QContact *oldContact, ContactState state) = 0;
......@@ -208,6 +207,7 @@ public:
ContactState contactState;
ItemListener *listeners;
QChar nameGroup;
QString displayLabel;
};
struct ContactLinkRequest
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment