Commit b4947820 authored by chriadam's avatar chriadam

[buteo-sync-plugin-carddav] Improve vCard FN parsing. Contributes to MER#1379

This commit ensures that we decompose FN values into a structured name
detail before storing the resultant contact into our backend.
This allows us to correctly aggregate contacts for which the server
provides an FN but no N property in the vCard.

Contributes to MER#1379
parent 430ad0d5
...@@ -19,7 +19,7 @@ BuildRequires: pkgconfig(accounts-qt5) >= 1.13 ...@@ -19,7 +19,7 @@ BuildRequires: pkgconfig(accounts-qt5) >= 1.13
BuildRequires: pkgconfig(libsignon-qt5) BuildRequires: pkgconfig(libsignon-qt5)
BuildRequires: pkgconfig(libsailfishkeyprovider) BuildRequires: pkgconfig(libsailfishkeyprovider)
BuildRequires: pkgconfig(qtcontacts-sqlite-qt5-extensions) >= 0.2.18 BuildRequires: pkgconfig(qtcontacts-sqlite-qt5-extensions) >= 0.2.18
BuildRequires: pkgconfig(contactcache-qt5) BuildRequires: pkgconfig(contactcache-qt5) >= 0.1.5
Requires: buteo-syncfw-qt5-msyncd Requires: buteo-syncfw-qt5-msyncd
%description %description
......
...@@ -34,6 +34,9 @@ ...@@ -34,6 +34,9 @@
#include <QContact> #include <QContact>
#include <QContactGuid> #include <QContactGuid>
#include <QContactAvatar> #include <QContactAvatar>
#include <QContactDisplayLabel>
#include <QContactName>
#include <QContactNickname>
#include <QVersitWriter> #include <QVersitWriter>
#include <QVersitDocument> #include <QVersitDocument>
...@@ -126,6 +129,34 @@ QPair<QContact, QStringList> CardDavVCardConverter::convertVCardToContact(const ...@@ -126,6 +129,34 @@ QPair<QContact, QStringList> CardDavVCardConverter::convertVCardToContact(const
QStringList unsupportedProperties = m_unsupportedProperties.value(importedContact.detail<QContactGuid>().guid()); QStringList unsupportedProperties = m_unsupportedProperties.value(importedContact.detail<QContactGuid>().guid());
m_unsupportedProperties.clear(); m_unsupportedProperties.clear();
// If the contact has no structured name data, create a best-guess name for it.
// This may be the case if the server provides an FN property but no N property.
QString displaylabelField, nicknameField;
QContactName nameDetail;
Q_FOREACH (const QContactDetail &d, importedContact.details()) {
if (d.type() == QContactDetail::TypeName) {
nameDetail = d;
} else if (d.type() == QContactDetail::TypeDisplayLabel) {
displaylabelField = d.value(QContactDisplayLabel::FieldLabel).toString().trimmed();
} else if (d.type() == QContactDetail::TypeNickname) {
nicknameField = d.value(QContactNickname::FieldNickname).toString().trimmed();
}
}
if (nameDetail.isEmpty() || (nameDetail.firstName().isEmpty() && nameDetail.lastName().isEmpty())) {
// we have no valid name data but we may have display label or nickname data which we can decompose.
if (!displaylabelField.isEmpty()) {
SeasideCache::decomposeDisplayLabel(displaylabelField, &nameDetail);
importedContact.saveDetail(&nameDetail);
LOG_DEBUG("Decomposed vCard display name into structured name:" << nameDetail);
} else if (!nicknameField.isEmpty()) {
SeasideCache::decomposeDisplayLabel(nicknameField, &nameDetail);
importedContact.saveDetail(&nameDetail);
LOG_DEBUG("Decomposed vCard nickname into structured name:" << nameDetail);
} else {
LOG_WARNING("No structured name data exists in the vCard, contact will be unnamed!");
}
}
// mark each detail of the contact as modifiable // mark each detail of the contact as modifiable
Q_FOREACH (QContactDetail det, importedContact.details()) { Q_FOREACH (QContactDetail det, importedContact.details()) {
det.setValue(QContactDetail__FieldModifiable, true); det.setValue(QContactDetail__FieldModifiable, true);
......
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