Commit 2e49ad58 authored by mvogt's avatar mvogt

[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.
parent c4febbf6
......@@ -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()) {
......@@ -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());
......@@ -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());
......@@ -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;
......
......@@ -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"
......
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