diff --git a/rpm/libcontacts-qt5.spec b/rpm/libcontacts-qt5.spec index ec91418..c8a4ea0 100644 --- a/rpm/libcontacts-qt5.spec +++ b/rpm/libcontacts-qt5.spec @@ -12,6 +12,7 @@ BuildRequires: pkgconfig(Qt5Test) BuildRequires: pkgconfig(Qt5Contacts) BuildRequires: pkgconfig(Qt5Versit) BuildRequires: pkgconfig(mlite5) +BuildRequires: pkgconfig(mlocale5) BuildRequires: pkgconfig(qtcontacts-sqlite-qt5-extensions) >= 0.1.8 %description diff --git a/src/seasidecache.cpp b/src/seasidecache.cpp index 2092497..fb3f84d 100644 --- a/src/seasidecache.cpp +++ b/src/seasidecache.cpp @@ -67,12 +67,16 @@ #include +#include + #ifdef USING_QTPIM QTVERSIT_USE_NAMESPACE #endif namespace { +ML10N::MLocale mLocale; + const QString aggregateRelationshipType = #ifdef USING_QTPIM QContactRelationship::Aggregates(); @@ -83,39 +87,10 @@ const QString aggregateRelationshipType = const QString syncTargetLocal = QLatin1String("local"); const QString syncTargetWasLocal = QLatin1String("was_local"); -QList getAllContactNameGroups() -{ - QList groups; - groups << QLatin1Char('A') - << QLatin1Char('B') - << QLatin1Char('C') - << QLatin1Char('D') - << QLatin1Char('E') - << QLatin1Char('F') - << QLatin1Char('G') - << QLatin1Char('H') - << QLatin1Char('I') - << QLatin1Char('J') - << QLatin1Char('K') - << QLatin1Char('L') - << QLatin1Char('M') - << QLatin1Char('N') - << QLatin1Char('O') - << QLatin1Char('P') - << QLatin1Char('Q') - << QLatin1Char('R') - << QLatin1Char('S') - << QLatin1Char('T') - << QLatin1Char('U') - << QLatin1Char('V') - << QLatin1Char('W') - << QLatin1Char('X') - << QLatin1Char('Y') - << QLatin1Char('Z') - << QChar(0x00c5) // Å - << QChar(0x00c4) // Ä - << QChar(0x00d6) // Ö - << QLatin1Char('#'); +QStringList getAllContactNameGroups() +{ + QStringList groups(mLocale.exemplarCharactersIndex()); + groups.append(QString::fromLatin1("#")); return groups; } @@ -307,7 +282,7 @@ bool ignoreContactForNameGroups(const QContact &contact) } SeasideCache *SeasideCache::instancePtr = 0; -QList SeasideCache::allContactNameGroups = getAllContactNameGroups(); +QStringList SeasideCache::allContactNameGroups = getAllContactNameGroups(); SeasideCache* SeasideCache::instance() { @@ -583,29 +558,29 @@ void SeasideCache::setNameGrouper(SeasideNameGrouper *grouper) instancePtr->m_nameGrouper.reset(grouper); allContactNameGroups = getAllContactNameGroups(); - QList groups = instancePtr->m_nameGrouper->allNameGroups(); + QStringList groups = instancePtr->m_nameGrouper->allNameGroups(); for (int i = groups.count() - 1; i > -1; --i) { - const QChar &group = groups.at(i); + const QString &group = groups.at(i); if (!allContactNameGroups.contains(group)) allContactNameGroups.prepend(group); } } -QChar SeasideCache::nameGroup(const CacheItem *cacheItem) +QString SeasideCache::nameGroup(const CacheItem *cacheItem) { if (!cacheItem) - return QChar(); + return QString(); return cacheItem->nameGroup; } -QChar SeasideCache::determineNameGroup(const CacheItem *cacheItem) +QString SeasideCache::determineNameGroup(const CacheItem *cacheItem) { if (!cacheItem) - return QChar(); + return QString(); if (!instancePtr->m_nameGrouper.isNull()) { - QChar group = instancePtr->m_nameGrouper->nameGroupForContact(cacheItem->contact, instancePtr->m_groupProperty); + QString group = instancePtr->m_nameGrouper->nameGroupForContact(cacheItem->contact, instancePtr->m_groupProperty); if (!group.isNull()) { return group; } @@ -614,37 +589,36 @@ QChar SeasideCache::determineNameGroup(const CacheItem *cacheItem) const QContactName name(cacheItem->contact.detail()); const QString nameProperty(instancePtr->m_groupProperty == QString::fromLatin1("firstName") ? name.firstName() : name.lastName()); - QChar group; + QString group; if (!nameProperty.isEmpty()) { - group = nameProperty[0].toUpper(); + group = mLocale.indexBucket(nameProperty); } else if (!cacheItem->displayLabel.isEmpty()) { - group = cacheItem->displayLabel[0].toUpper(); + group = mLocale.indexBucket(cacheItem->displayLabel); } - // XXX temporary workaround for non-latin names: use non-name details to try to find a - // latin character group - if (!group.isNull() && group.toLatin1() != group) { + if (group.isNull() || !allContactNameGroups.contains(group)) { QString displayLabel = generateDisplayLabelFromNonNameDetails(cacheItem->contact); if (!displayLabel.isEmpty()) - group = displayLabel[0].toUpper(); + group = mLocale.indexBucket(displayLabel); } - if (group.isNull() || !allContactNameGroups.contains(group)) { - group = QLatin1Char('#'); // 'other' group + group = QString::fromLatin1("#"); // 'other' group } return group; } -QList SeasideCache::allNameGroups() +QStringList SeasideCache::allNameGroups() { + if (!instancePtr) + new SeasideCache; return allContactNameGroups; } -QHash > SeasideCache::nameGroupMembers() +QHash > SeasideCache::nameGroupMembers() { if (instancePtr) return instancePtr->m_contactNameGroups; - return QHash >(); + return QHash >(); } SeasideCache::DisplayLabelOrder SeasideCache::displayLabelOrder() @@ -892,9 +866,9 @@ void SeasideCache::removeContactData( m_contacts[filter].remove(row); if (filter == FilterAll) { - const QChar group(nameGroup(existingItem(contactId))); + const QString group(nameGroup(existingItem(contactId))); if (!group.isNull()) { - QSet modifiedNameGroups; + QSet modifiedNameGroups; removeFromContactNameGroup(internalId(contactId), group, &modifiedNameGroups); notifyNameGroupsChanged(modifiedNameGroups); } @@ -1642,7 +1616,7 @@ void SeasideCache::contactsAvailable() appendContacts(contacts, type, partialFetch); } else { // An update. - QSet modifiedGroups; + QSet modifiedGroups; for (int i = m_resultsRead; i < contacts.count(); ++i) { QContact contact = contacts.at(i); @@ -1658,7 +1632,7 @@ void SeasideCache::contactsAvailable() item->iid = iid; } - QChar oldNameGroup; + QString oldNameGroup; QString oldDisplayLabel; if (preexisting) { @@ -1710,7 +1684,7 @@ void SeasideCache::contactsAvailable() } } -void SeasideCache::addToContactNameGroup(quint32 iid, const QChar &group, QSet *modifiedGroups) +void SeasideCache::addToContactNameGroup(quint32 iid, const QString &group, QSet *modifiedGroups) { if (!group.isNull()) { QSet &set(m_contactNameGroups[group]); @@ -1723,7 +1697,7 @@ void SeasideCache::addToContactNameGroup(quint32 iid, const QChar &group, QSet *modifiedGroups) +void SeasideCache::removeFromContactNameGroup(quint32 iid, const QString &group, QSet *modifiedGroups) { if (!group.isNull()) { QSet &set(m_contactNameGroups[group]); @@ -1735,13 +1709,13 @@ void SeasideCache::removeFromContactNameGroup(quint32 iid, const QChar &group, Q } } -void SeasideCache::notifyNameGroupsChanged(const QSet &groups) +void SeasideCache::notifyNameGroupsChanged(const QSet &groups) { if (groups.isEmpty() || m_nameGroupChangeListeners.isEmpty()) return; - QHash > updates; - foreach (const QChar &group, groups) + QHash > updates; + foreach (const QString &group, groups) updates.insert(group, m_contactNameGroups[group]); for (int i = 0; i < m_nameGroupChangeListeners.count(); ++i) @@ -1785,14 +1759,14 @@ void SeasideCache::removeRange(FilterType filter, int index, int count) for (int i = 0; i < models.count(); ++i) models[i]->sourceAboutToRemoveItems(index, index + count - 1); - QSet modifiedNameGroups; + QSet modifiedNameGroups; for (int i = 0; i < count; ++i) { if (filter == FilterAll) { const ContactIdType apiId = cacheIds.at(index); m_expiredContacts[apiId] -= 1; - const QChar group(nameGroup(existingItem(apiId))); + const QString group(nameGroup(existingItem(apiId))); if (!group.isNull()) { removeFromContactNameGroup(internalId(apiId), group, &modifiedNameGroups); } @@ -1853,7 +1827,7 @@ void SeasideCache::appendContacts(const QList &contacts, FilterType fi int end = cacheIds.count() + contacts.count() - m_appendIndex - 1; if (begin <= end) { - QSet modifiedGroups; + QSet modifiedGroups; for (int i = 0; i < models.count(); ++i) models.at(i)->sourceAboutToInsertItems(begin, end); @@ -2139,7 +2113,7 @@ void SeasideCache::displayLabelOrderChanged() if (displayLabelOrder.isValid() && displayLabelOrder.toInt() != m_displayLabelOrder) { m_displayLabelOrder = static_cast(displayLabelOrder.toInt()); - QSet modifiedGroups; + QSet modifiedGroups; // Update the display labels typedef QHash::iterator iterator; @@ -2158,7 +2132,7 @@ void SeasideCache::displayLabelOrderChanged() } // If the contact's name group is derived from display label, it may have changed - const QChar group(determineNameGroup(&*it)); + const QString group(determineNameGroup(&*it)); if (group != it->nameGroup) { if (!ignoreContactForNameGroups(it->contact)) { if (!it->nameGroup.isNull()) { @@ -2230,12 +2204,12 @@ void SeasideCache::groupPropertyChanged() m_groupProperty = newProperty; // Update the name groups - QSet modifiedGroups; + QSet modifiedGroups; typedef QHash::iterator iterator; for (iterator it = m_people.begin(); it != m_people.end(); ++it) { // Update the nameGroup for this contact - const QChar group(determineNameGroup(&*it)); + const QString group(determineNameGroup(&*it)); if (group != it->nameGroup) { if (!ignoreContactForNameGroups(it->contact)) { if (!it->nameGroup.isNull()) { diff --git a/src/seasidecache.h b/src/seasidecache.h index d3da5a1..62639a3 100644 --- a/src/seasidecache.h +++ b/src/seasidecache.h @@ -82,7 +82,7 @@ class CONTACTCACHE_EXPORT SeasideNameGroupChangeListener SeasideNameGroupChangeListener() {} ~SeasideNameGroupChangeListener() {} - virtual void nameGroupsUpdated(const QHash > &groups) = 0; + virtual void nameGroupsUpdated(const QHash > &groups) = 0; }; class CONTACTCACHE_EXPORT SeasideCache : public QObject @@ -206,7 +206,7 @@ class CONTACTCACHE_EXPORT SeasideCache : public QObject quint64 statusFlags; ContactState contactState; ItemListener *listeners; - QChar nameGroup; + QString nameGroup; QString displayLabel; }; @@ -308,11 +308,11 @@ class CONTACTCACHE_EXPORT SeasideCache : public QObject static void ensureCompletion(CacheItem *cacheItem); static void refreshContact(CacheItem *cacheItem); - static QChar nameGroup(const CacheItem *cacheItem); - static QChar determineNameGroup(const CacheItem *cacheItem); + static QString nameGroup(const CacheItem *cacheItem); + static QString determineNameGroup(const CacheItem *cacheItem); - static QList allNameGroups(); - static QHash > nameGroupMembers(); + static QStringList allNameGroups(); + static QHash > nameGroupMembers(); static CacheItem *itemByPhoneNumber(const QString &number, bool requireComplete = true); static CacheItem *itemByEmailAddress(const QString &address, bool requireComplete = true); @@ -413,9 +413,9 @@ private slots: void removeContactData(const ContactIdType &contactId, FilterType filter); void makePopulated(FilterType filter); - void addToContactNameGroup(quint32 iid, const QChar &group, QSet *modifiedGroups = 0); - void removeFromContactNameGroup(quint32 iid, const QChar &group, QSet *modifiedGroups = 0); - void notifyNameGroupsChanged(const QSet &groups); + void addToContactNameGroup(quint32 iid, const QString &group, QSet *modifiedGroups = 0); + void removeFromContactNameGroup(quint32 iid, const QString &group, QSet *modifiedGroups = 0); + void notifyNameGroupsChanged(const QSet &groups); void updateConstituentAggregations(const ContactIdType &contactId); void completeContactAggregation(const ContactIdType &contact1Id, const ContactIdType &contact2Id); @@ -431,7 +431,7 @@ private slots: QHash m_emailAddressIds; QHash, quint32> m_onlineAccountIds; QHash m_contactsToSave; - QHash > m_contactNameGroups; + QHash > m_contactNameGroups; QList m_contactsToCreate; QList m_contactsToRemove; QList m_changedContacts; @@ -501,7 +501,7 @@ private slots: QElapsedTimer m_fetchPostponed; static SeasideCache *instancePtr; - static QList allContactNameGroups; + static QStringList allContactNameGroups; }; #endif diff --git a/src/seasidenamegrouper.h b/src/seasidenamegrouper.h index e61ee97..d8d3846 100644 --- a/src/seasidenamegrouper.h +++ b/src/seasidenamegrouper.h @@ -34,7 +34,6 @@ #include "contactcacheexport.h" -#include #include #include @@ -50,8 +49,8 @@ class CONTACTCACHE_EXPORT SeasideNameGrouper SeasideNameGrouper() {} virtual ~SeasideNameGrouper() {} - virtual QChar nameGroupForContact(const QContact &contact, const QString &groupProperty) const = 0; - virtual QList allNameGroups() const = 0; + virtual QString nameGroupForContact(const QContact &contact, const QString &groupProperty) const = 0; + virtual QStringList allNameGroups() const = 0; }; #endif // SEASIDENAMEGROUPER_H diff --git a/src/src.pro b/src/src.pro index 0f967ae..4f99f7e 100644 --- a/src/src.pro +++ b/src/src.pro @@ -31,6 +31,7 @@ equals(QT_MAJOR_VERSION, 5) { } else { warning("mlite not available. Some functionality may not work as expected.") } + PKGCONFIG += mlocale5 } DEFINES += CONTACTCACHE_BUILD