diff --git a/src/seasidecache.cpp b/src/seasidecache.cpp index 86c15b4..2d1190c 100644 --- a/src/seasidecache.cpp +++ b/src/seasidecache.cpp @@ -333,6 +333,7 @@ SeasideCache::SeasideCache() #ifdef HAS_MLITE , m_displayLabelOrderConf(QLatin1String("/org/nemomobile/contacts/display_label_order")) , m_sortPropertyConf(QLatin1String("/org/nemomobile/contacts/sort_property")) + , m_groupPropertyConf(QLatin1String("/org/nemomobile/contacts/group_property")) #endif , m_resultsRead(0) , m_populated(0) @@ -342,6 +343,7 @@ SeasideCache::SeasideCache() , m_syncFilter(FilterNone) , m_displayLabelOrder(FirstNameFirst) , m_sortProperty(QString::fromLatin1("firstName")) + , m_groupProperty(QString::fromLatin1("firstName")) , m_keepPopulated(false) , m_populateProgress(Unpopulated) , m_fetchTypes(0) @@ -367,6 +369,11 @@ SeasideCache::SeasideCache() QVariant sortPropertyConf = m_sortPropertyConf.value(); if (sortPropertyConf.isValid()) m_sortProperty = sortPropertyConf.toString(); + + connect(&m_groupPropertyConf, SIGNAL(valueChanged()), this, SLOT(groupPropertyChanged())); + QVariant groupPropertyConf = m_groupPropertyConf.value(); + if (groupPropertyConf.isValid()) + m_groupProperty = groupPropertyConf.toString(); #endif #ifdef USING_QTPIM @@ -556,14 +563,14 @@ QChar SeasideCache::determineNameGroup(const CacheItem *cacheItem) return QChar(); if (!instancePtr->m_nameGrouper.isNull()) { - QChar group = instancePtr->m_nameGrouper->nameGroupForContact(cacheItem->contact, instancePtr->m_sortProperty); + QChar group = instancePtr->m_nameGrouper->nameGroupForContact(cacheItem->contact, instancePtr->m_groupProperty); if (!group.isNull()) { return group; } } const QContactName name(cacheItem->contact.detail()); - const QString nameProperty(instancePtr->m_sortProperty == QString::fromLatin1("firstName") ? name.firstName() : name.lastName()); + const QString nameProperty(instancePtr->m_groupProperty == QString::fromLatin1("firstName") ? name.firstName() : name.lastName()); QChar group; if (!nameProperty.isEmpty()) { @@ -608,6 +615,11 @@ QString SeasideCache::sortProperty() return instancePtr->m_sortProperty; } +QString SeasideCache::groupProperty() +{ + return instancePtr->m_groupProperty; +} + int SeasideCache::contactId(const QContact &contact) { quint32 internal = internalId(contact); @@ -2053,7 +2065,33 @@ void SeasideCache::sortPropertyChanged() m_sortProperty = newProperty; setSortOrder(m_sortProperty); - // Name grouping is also currently specified by the 'sort property' setting + for (int i = 0; i < FilterTypesCount; ++i) { + for (int j = 0; j < m_models[i].count(); ++j) + m_models[i].at(j)->updateSortProperty(); + } + + // Update the sorted list order + m_refreshRequired = true; + requestUpdate(); + } +#endif +} + +void SeasideCache::groupPropertyChanged() +{ +#ifdef HAS_MLITE + QVariant groupProperty = m_groupPropertyConf.value(); + if (groupProperty.isValid() && groupProperty.toString() != m_groupProperty) { + const QString newProperty(groupProperty.toString()); + if ((newProperty != QString::fromLatin1("firstName")) && + (newProperty != QString::fromLatin1("lastName"))) { + qWarning() << "Invalid group property configuration:" << newProperty; + return; + } + + m_groupProperty = newProperty; + + // Update the name groups QSet modifiedGroups; typedef QHash::iterator iterator; @@ -2074,12 +2112,8 @@ void SeasideCache::sortPropertyChanged() for (int i = 0; i < FilterTypesCount; ++i) { for (int j = 0; j < m_models[i].count(); ++j) - m_models[i].at(j)->updateSortProperty(); + m_models[i].at(j)->updateGroupProperty(); } - - // Update the sorted list order - m_refreshRequired = true; - requestUpdate(); } #endif } diff --git a/src/seasidecache.h b/src/seasidecache.h index 0092c4e..2fe4747 100644 --- a/src/seasidecache.h +++ b/src/seasidecache.h @@ -238,6 +238,7 @@ class CONTACTCACHE_EXPORT SeasideCache : public QObject virtual void makePopulated() = 0; virtual void updateDisplayLabelOrder() = 0; virtual void updateSortProperty() = 0; + virtual void updateGroupProperty() = 0; }; struct ResolveListener @@ -289,6 +290,7 @@ class CONTACTCACHE_EXPORT SeasideCache : public QObject static DisplayLabelOrder displayLabelOrder(); static QString sortProperty(); + static QString groupProperty(); static int contactId(const QContact &contact); @@ -368,6 +370,7 @@ private slots: #endif void displayLabelOrderChanged(); void sortPropertyChanged(); + void groupPropertyChanged(); private: enum PopulateProgress { @@ -461,6 +464,7 @@ private slots: #ifdef HAS_MLITE MGConfItem m_displayLabelOrderConf; MGConfItem m_sortPropertyConf; + MGConfItem m_groupPropertyConf; #endif int m_resultsRead; int m_populated; @@ -470,6 +474,7 @@ private slots: FilterType m_syncFilter; DisplayLabelOrder m_displayLabelOrder; QString m_sortProperty; + QString m_groupProperty; bool m_keepPopulated; PopulateProgress m_populateProgress; quint32 m_fetchTypes;