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] Skip UID matches where name details differ
UIDs found in VCF are not very reliable; if a UID match is found where
the contacts have name details that do not match, ignore the UID match
and remove the Guid detail from one contact.
  • Loading branch information
matthewvogt committed Jan 15, 2014
1 parent c4febbf commit 2e49ad5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
41 changes: 36 additions & 5 deletions src/seasideimport.cpp
Expand Up @@ -362,7 +362,21 @@ QList<QContact> SeasideImport::buildImportContacts(const QList<QVersitDocument>
QHash<QString, int>::const_iterator git = importGuids.find(guid);
if (git != importGuids.end()) {
previousIndex = git.value();
} else {

if (!emptyName) {
// If we have a GUID match, but names differ, ignore the match
const QContact &previous(importedContacts[previousIndex]);
const QString previousName = contactNameString(previous);
if (!previousName.isEmpty() && (previousName != name)) {
previousIndex = -1;

// Remove the conflicting GUID from this contact
QContactGuid guidDetail = contact.detail<QContactGuid>();
contact.removeDetail(&guidDetail);
}
}
}
if (previousIndex == -1) {
if (!emptyName) {
QHash<QString, int>::const_iterator nit = importNames.find(name);
if (nit != importNames.end()) {
Expand Down Expand Up @@ -413,6 +427,7 @@ QList<QContact> SeasideImport::buildImportContacts(const QList<QVersitDocument>

QHash<QString, QContactId> existingGuids;
QHash<QString, QContactId> existingNames;
QMap<QContactId, QString> existingContactNames;
QHash<QString, QContactId> existingNicknames;

QContactManager *mgr(SeasideCache::manager());
Expand All @@ -426,6 +441,7 @@ QList<QContact> SeasideImport::buildImportContacts(const QList<QVersitDocument>
}
if (!name.isEmpty()) {
existingNames.insert(name, contact.id());
existingContactNames.insert(contact.id(), name);
}
foreach (const QContactNickname &nick, contact.details<QContactNickname>()) {
existingNicknames.insert(nick.nickname(), contact.id());
Expand All @@ -438,17 +454,32 @@ QList<QContact> SeasideImport::buildImportContacts(const QList<QVersitDocument>
it = importedContacts.begin();
while (it != importedContacts.end()) {
const QString guid = (*it).detail<QContactGuid>().guid();
const QString name = contactNameString(*it);
const bool emptyName = name.isEmpty();

QContactId existingId;

QHash<QString, QContactId>::const_iterator git = existingGuids.find(guid);
if (git != existingGuids.end()) {
existingId = *git;
} else {
const bool emptyName = nameIsEmpty((*it).detail<QContactName>());
if (!emptyName) {
const QString name = contactNameString(*it);

if (!emptyName) {
// If we have a GUID match, but names differ, ignore the match
QMap<QContactId, QString>::iterator nit = existingContactNames.find(existingId);
if (nit != existingContactNames.end()) {
const QString &existingName(*nit);
if (!existingName.isEmpty() && (existingName != name)) {
existingId = QContactId();

// Remove the conflicting GUID from this contact
QContactGuid guidDetail = (*it).detail<QContactGuid>();
(*it).removeDetail(&guidDetail);
}
}
}
}
if (existingId.isNull()) {
if (!emptyName) {
QHash<QString, QContactId>::const_iterator nit = existingNames.find(name);
if (nit != existingNames.end()) {
existingId = *nit;
Expand Down
6 changes: 0 additions & 6 deletions tests/tst_seasideimport/tst_seasideimport.cpp
Expand Up @@ -310,12 +310,6 @@ void tst_SeasideImport::nonmergedNickname()

void tst_SeasideImport::nonmergedUid()
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
QSKIP("UID matches should be ignored where QContactName details differ");
#else
QSKIP("UID matches should be ignored where QContactName details differ", SkipAll);
#endif

const char *vCardData =
"BEGIN:VCARD\r\n"
"N:Springfield;Jebediah;;;\r\n"
Expand Down

0 comments on commit 2e49ad5

Please sign in to comment.