Commit 73229100 authored by Michael Brasser's avatar Michael Brasser

[libcontacts] Add API for name grouping.

Allow a customized name grouper to be set.
parent 947093db
......@@ -521,11 +521,36 @@ void SeasideCache::unregisterResolveListener(ResolveListener *listener)
}
}
void SeasideCache::setNameGrouper(SeasideNameGrouper *grouper)
{
if (!instancePtr)
new SeasideCache;
instancePtr->m_nameGrouper.reset(grouper);
allContactNameGroups = getAllContactNameGroups();
QList<QChar> groups = instancePtr->m_nameGrouper->allNameGroups();
for (int i = groups.count() - 1; i > -1; --i) {
const QChar &group = groups.at(i);
if (!allContactNameGroups.contains(group))
allContactNameGroups.prepend(group);
}
}
QChar SeasideCache::nameGroupForCacheItem(CacheItem *cacheItem)
{
if (!cacheItem)
return QChar();
if (!instancePtr)
new SeasideCache;
if (!instancePtr->m_nameGrouper.isNull()) {
SeasideNameGrouper::DisplayLabelOrder order = (SeasideNameGrouper::DisplayLabelOrder)(int)SeasideCache::displayLabelOrder();
QChar group = instancePtr->m_nameGrouper->nameGroupForContact(cacheItem->contact, order);
if (!group.isNull())
return group;
}
QChar group;
QString first;
QString last;
......
......@@ -33,6 +33,7 @@
#define SEASIDECACHE_H
#include "contactcacheexport.h"
#include "seasidenamegrouper.h"
#include <qtcontacts-extensions.h>
#include <QContactStatusFlags>
......@@ -106,8 +107,8 @@ public:
};
enum DisplayLabelOrder {
FirstNameFirst,
LastNameFirst
FirstNameFirst = SeasideNameGrouper::FirstNameFirst,
LastNameFirst = SeasideNameGrouper::LastNameFirst
};
enum ContactState {
......@@ -229,6 +230,8 @@ public:
static void unregisterResolveListener(ResolveListener *listener);
static void setNameGrouper(SeasideNameGrouper *grouper);
static DisplayLabelOrder displayLabelOrder();
static int contactId(const QContact &contact);
......@@ -371,6 +374,7 @@ private:
QList<QPair<ContactLinkRequest, ContactLinkRequest> > m_contactPairsToLink;
QList<QContactRelationship> m_relationshipsToSave;
QList<QContactRelationship> m_relationshipsToRemove;
QScopedPointer<SeasideNameGrouper> m_nameGrouper;
QList<SeasideNameGroupChangeListener*> m_nameGroupChangeListeners;
QList<ChangeListener*> m_changeListeners;
QVector<ContactIdType> m_contacts[FilterTypesCount];
......
/*
* Copyright (C) 2013 Jolla Mobile <michael.brasser@jollamobile.com>
*
* You may use this file under the terms of the BSD license as follows:
*
* "Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
*/
#ifndef SEASIDENAMEGROUPER_H
#define SEASIDENAMEGROUPER_H
#include <QChar>
#include <QList>
#include <QContact>
#ifdef USING_QTPIM
QTCONTACTS_USE_NAMESPACE
#else
QTM_USE_NAMESPACE
#endif
class CONTACTCACHE_EXPORT SeasideNameGrouper
{
public:
SeasideNameGrouper() {}
virtual ~SeasideNameGrouper() {}
enum DisplayLabelOrder {
FirstNameFirst,
LastNameFirst
};
virtual QChar nameGroupForContact(const QContact &contact, DisplayLabelOrder order) const = 0;
virtual QList<QChar> allNameGroups() const = 0;
};
#endif // SEASIDENAMEGROUPER_H
......@@ -43,11 +43,13 @@ HEADERS += \
$$PWD/normalization_p.h \
$$PWD/contactcacheexport.h \
$$PWD/seasidecache.h \
$$PWD/synchronizelists.h
$$PWD/synchronizelists.h \
$$PWD/seasidenamegrouper.h
headers.files = \
$$PWD/contactcacheexport.h \
$$PWD/seasidecache.h \
$$PWD/synchronizelists.h
$$PWD/synchronizelists.h \
$$PWD/seasidenamegrouper.h
headers.path = $$PREFIX/include/$$TARGET
INSTALLS += headers
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