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

Commit

Permalink
Browse files Browse the repository at this point in the history
[libcontacts] Add API for name grouping.
Allow a customized name grouper to be set.
  • Loading branch information
mbrasser-jolla committed Aug 7, 2013
1 parent 947093d commit 7322910
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 4 deletions.
25 changes: 25 additions & 0 deletions src/seasidecache.cpp
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions src/seasidecache.h
Expand Up @@ -33,6 +33,7 @@
#define SEASIDECACHE_H

#include "contactcacheexport.h"
#include "seasidenamegrouper.h"

#include <qtcontacts-extensions.h>
#include <QContactStatusFlags>
Expand Down Expand Up @@ -106,8 +107,8 @@ class CONTACTCACHE_EXPORT SeasideCache : public QObject
};

enum DisplayLabelOrder {
FirstNameFirst,
LastNameFirst
FirstNameFirst = SeasideNameGrouper::FirstNameFirst,
LastNameFirst = SeasideNameGrouper::LastNameFirst
};

enum ContactState {
Expand Down Expand Up @@ -229,6 +230,8 @@ class CONTACTCACHE_EXPORT SeasideCache : public QObject

static void unregisterResolveListener(ResolveListener *listener);

static void setNameGrouper(SeasideNameGrouper *grouper);

static DisplayLabelOrder displayLabelOrder();

static int contactId(const QContact &contact);
Expand Down Expand Up @@ -371,6 +374,7 @@ private slots:
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];
Expand Down
60 changes: 60 additions & 0 deletions src/seasidenamegrouper.h
@@ -0,0 +1,60 @@
/*
* 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
6 changes: 4 additions & 2 deletions src/src.pro
Expand Up @@ -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

0 comments on commit 7322910

Please sign in to comment.