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

Commit

Permalink
[libcontacts] Add a grouping property configuration
Browse files Browse the repository at this point in the history
Allow grouping policy to be configured independently from sorting
and display label order.
  • Loading branch information
matthewvogt committed Aug 30, 2013
1 parent d93e74f commit 1a9afbc
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
50 changes: 42 additions & 8 deletions src/seasidecache.cpp
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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<QContactName>());
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()) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<QChar> modifiedGroups;

typedef QHash<quint32, CacheItem>::iterator iterator;
Expand All @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions src/seasidecache.h
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -368,6 +370,7 @@ private slots:
#endif
void displayLabelOrderChanged();
void sortPropertyChanged();
void groupPropertyChanged();

private:
enum PopulateProgress {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 1a9afbc

Please sign in to comment.