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 #72 from matthewvogt/extend-name-groups
Browse files Browse the repository at this point in the history
[libcontacts] Extend name groups as required for contacts grouping
  • Loading branch information
matthewvogt committed Jan 15, 2014
2 parents 9428d80 + 5c84b84 commit b6957d6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/seasidecache.cpp
Expand Up @@ -95,6 +95,11 @@ const QString aggregateRelationshipType =
const QString syncTargetLocal = QLatin1String("local");
const QString syncTargetWasLocal = QLatin1String("was_local");

int getContactNameGroupCount()
{
return mLocale.exemplarCharactersIndex().count();
}

QStringList getAllContactNameGroups()
{
QStringList groups(mLocale.exemplarCharactersIndex());
Expand Down Expand Up @@ -465,6 +470,7 @@ int bestPhoneNumberMatchLength(const QContact &contact, const QString &match)
}

SeasideCache *SeasideCache::instancePtr = 0;
int SeasideCache::contactNameGroupCount = getContactNameGroupCount();
QStringList SeasideCache::allContactNameGroups = getAllContactNameGroups();

QContactManager* SeasideCache::manager()
Expand Down Expand Up @@ -768,6 +774,7 @@ void SeasideCache::setNameGrouper(SeasideNameGrouper *grouper)
instancePtr->m_nameGrouper.reset(grouper);

allContactNameGroups = instancePtr->m_nameGrouper->allNameGroups();
contactNameGroupCount = allContactNameGroups.count();
if (!allContactNameGroups.contains(QLatin1String("#")))
allContactNameGroups << QLatin1String("#");
}
Expand Down Expand Up @@ -802,9 +809,30 @@ QString SeasideCache::determineNameGroup(const CacheItem *cacheItem)
group = mLocale.indexBucket(cacheItem->displayLabel);
}

if (group.isNull() || !allContactNameGroups.contains(group)) {
group = QString::fromLatin1("#"); // 'other' group
if (!group.isEmpty()) {
if (!allContactNameGroups.contains(group)) {
// If this group is some kind of digit, group under '#'
if (mLocale.toLatinNumbers(group.mid(0, 1)).at(0).isDigit()) {
group = QString();
}
}
}

if (group.isEmpty()) {
group = QString::fromLatin1("#");
} else if (!allContactNameGroups.contains(group)) {
// Insert before the '#' group, which is always last, and after the pre-defined groups
const int maxIndex = allContactNameGroups.count() - 1;
int index = qMin(contactNameGroupCount, maxIndex);
for ( ; index < maxIndex; ++index) {
if (group < allContactNameGroups.at(index)) {
break;
}
}

allContactNameGroups.insert(index, group);
}

return group;
}

Expand Down
1 change: 1 addition & 0 deletions src/seasidecache.h
Expand Up @@ -524,6 +524,7 @@ private slots:
QElapsedTimer m_fetchPostponed;

static SeasideCache *instancePtr;
static int contactNameGroupCount;
static QStringList allContactNameGroups;
};

Expand Down

0 comments on commit b6957d6

Please sign in to comment.