Commit c6c48255 authored by mvogt's avatar mvogt

[libcontacts] Use generic version of normalization function

parent c12c0a64
......@@ -12,7 +12,7 @@ BuildRequires: pkgconfig(Qt5Test)
BuildRequires: pkgconfig(Qt5Contacts)
BuildRequires: pkgconfig(Qt5Versit)
BuildRequires: pkgconfig(mlite5)
BuildRequires: pkgconfig(qtcontacts-sqlite-qt5-extensions) >= 0.1.1
BuildRequires: pkgconfig(qtcontacts-sqlite-qt5-extensions) >= 0.1.8
%description
%{summary}.
......
......@@ -11,7 +11,7 @@ BuildRequires: pkgconfig(QtCore)
BuildRequires: pkgconfig(QtContacts)
BuildRequires: pkgconfig(QtVersit)
BuildRequires: pkgconfig(mlite)
BuildRequires: pkgconfig(qtcontacts-sqlite-extensions) >= 0.1.1
BuildRequires: pkgconfig(qtcontacts-sqlite-extensions) >= 0.1.8
%description
%{summary}.
......
/*
* libseaside - Library that provides an interface to the Contacts application
* Copyright (c) 2013, Matt Vogt
*
* This program is licensed under the terms and conditions of the
* Apache License, version 2.0. The full text of the Apache License is at
* http://www.apache.org/licenses/LICENSE-2.0
*
*/
#include "normalization_p.h"
namespace Normalization {
QString normalizePhoneNumber(const QString &input)
{
// Use the same algorithm as maemo localNumber
// Not actually the 'visual-separators' from RFC3966...
// This logic is derived from qtcontacts-tracker
static const QString separators(QString::fromLatin1(" .-()[]"));
static const QString dtmfChars(QString::fromLatin1("pPwWxX"));
// TODO: possibly make this tunable?
static const int maxCharacters = 7;
QString subset;
subset.reserve(input.length());
QString::const_iterator it = input.constBegin(), end = input.constEnd();
for ( ; it != end; ++it) {
if ((*it).isDigit()) {
// Convert to ASCII, capturing unicode digit values
subset.append(QChar::fromLatin1('0' + (*it).digitValue()));
} else if (!separators.contains(*it) &&
(*it).category() != QChar::Other_Format) {
// If this is a DTMF character, stop processing here
if (dtmfChars.contains(*it)) {
break;
} else {
subset.append(*it);
}
}
}
return subset.right(maxCharacters);
}
}
/*
* libseaside - Library that provides an interface to the Contacts application
* Copyright (c) 2013, Matt Vogt
*
* This program is licensed under the terms and conditions of the
* Apache License, version 2.0. The full text of the Apache License is at
* http://www.apache.org/licenses/LICENSE-2.0
*
*/
#ifndef __NORMALIZATION_P_H__
#define __NORMALIZATION_P_H__
#include <QString>
namespace Normalization {
QString normalizePhoneNumber(const QString &input);
}
#endif
......@@ -32,8 +32,8 @@
#include "seasidecache.h"
#include "synchronizelists.h"
#include "normalization_p.h"
#include "qtcontacts-extensions_impl.h"
#include "qcontactstatusflags_impl.h"
#include <QCoreApplication>
......@@ -700,7 +700,7 @@ void SeasideCache::refreshContact(CacheItem *cacheItem)
SeasideCache::CacheItem *SeasideCache::itemByPhoneNumber(const QString &number, bool requireComplete)
{
QString normalizedNumber = Normalization::normalizePhoneNumber(number);
QString normalizedNumber = normalizePhoneNumber(number);
QHash<QString, quint32>::const_iterator it = instancePtr->m_phoneNumberIds.find(normalizedNumber);
if (it != instancePtr->m_phoneNumberIds.end())
return itemById(*it, requireComplete);
......@@ -975,6 +975,14 @@ QString SeasideCache::generateDisplayLabelFromNonNameDetails(const QContact &con
return QString();
}
QString SeasideCache::normalizePhoneNumber(const QString &input)
{
// TODO: use a configuration variable to make this configurable
static const int maxCharacters = 7;
return QtContactsSqliteExtensions::minimizePhoneNumber(input, maxCharacters);
}
static QContactFilter filterForMergeCandidates(const QContact &contact)
{
// Find any contacts that we might merge with the supplied contact
......@@ -1426,12 +1434,12 @@ bool SeasideCache::updateContactIndexing(const QContact &oldContact, const QCont
// Addresses which are no longer in the contact should be de-indexed
QSet<QString> oldPhoneNumbers;
foreach (const QContactPhoneNumber &phoneNumber, oldContact.details<QContactPhoneNumber>()) {
oldPhoneNumbers.insert(Normalization::normalizePhoneNumber(phoneNumber.number()));
oldPhoneNumbers.insert(normalizePhoneNumber(phoneNumber.number()));
}
// Update our address indexes for any address details in this contact
foreach (const QContactPhoneNumber &phoneNumber, contact.details<QContactPhoneNumber>()) {
QString normalizedNumber = Normalization::normalizePhoneNumber(phoneNumber.number());
QString normalizedNumber = normalizePhoneNumber(phoneNumber.number());
m_phoneNumberIds[normalizedNumber] = iid;
modified |= !oldPhoneNumbers.remove(normalizedNumber);
}
......
......@@ -336,6 +336,8 @@ public:
static QString generateDisplayLabel(const QContact &contact, DisplayLabelOrder order = FirstNameFirst);
static QString generateDisplayLabelFromNonNameDetails(const QContact &contact);
static QString normalizePhoneNumber(const QString &input);
bool event(QEvent *event);
// For synchronizeLists()
......
......@@ -10,7 +10,7 @@ target.path = $$PREFIX/lib
INSTALLS += target
# set version for generated pkgconfig files
VERSION=0.0.13
VERSION=0.0.14
QMAKE_PKGCONFIG_INCDIR = $$PREFIX/include/$${PACKAGENAME}
QMAKE_PKGCONFIG_LIBDIR = $$PREFIX/lib
QMAKE_PKGCONFIG_DESTDIR = pkgconfig
......@@ -36,11 +36,9 @@ equals(QT_MAJOR_VERSION, 5) {
DEFINES += CONTACTCACHE_BUILD
SOURCES += \
$$PWD/normalization.cpp \
$$PWD/seasidecache.cpp
HEADERS += \
$$PWD/normalization_p.h \
$$PWD/contactcacheexport.h \
$$PWD/seasidecache.h \
$$PWD/synchronizelists.h \
......
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