9
9
** $QT_BEGIN_LICENSE:LGPL$
10
10
** Commercial Usage
11
** Licensees holding valid Qt Commercial licenses may use this file in
12
** accordance with the Qt Solutions Commercial License Agreement provided
13
** with the Software or, alternatively, in accordance with the terms
11
** Licensees holding valid Qt Commercial licenses may use this file in
12
** accordance with the Qt Commercial License Agreement provided with
13
** the Software or, alternatively, in accordance with the terms
14
14
** contained in a written agreement between you and Nokia.
16
16
** GNU Lesser General Public License Usage
33
33
** ensure the GNU General Public License version 3.0 requirements will be
34
34
** met: http://www.gnu.org/copyleft/gpl.html.
36
** Please note Third Party Software included with Qt Solutions may impose
37
** additional restrictions and it is the user's responsibility to ensure
38
** that they have met the licensing requirements of the GPL, LGPL, or Qt
39
** Solutions Commercial license and the relevant license of the Third
40
** Party Software they are using.
42
36
** If you are unsure which license is appropriate for your use, please
43
37
** contact the sales department at qt-sales@nokia.com.
44
38
** $QT_END_LICENSE$
48
42
#include "qversitcontactexporter.h"
49
43
#include "qversitcontactexporter_p.h"
44
#include "qversitcontactimporter_p.h"
50
45
#include "qversitcontactsdefs_p.h"
51
46
#include "versitutils_p.h"
52
47
#include "qmobilityglobal.h"
94
89
int versitPropertyCount =
95
90
sizeof(versitContactDetailMappings)/sizeof(VersitDetailMapping);
96
for (int i=0; i < versitPropertyCount; i++) {
91
// Put them in in reverse order so the entries at the top of the list take precedence
92
for (int i=versitPropertyCount; i >= 0; i--) {
97
93
mPropertyMappings.insert(
98
94
QLatin1String(versitContactDetailMappings[i].detailDefinitionName),
99
95
QLatin1String(versitContactDetailMappings[i].versitPropertyName));
136
135
QVersitContactExporter::Error* error)
138
137
QList<QContactDetail> allDetails = contact.details();
139
if (allDetails.isEmpty()) {
140
*error = QVersitContactExporter::EmptyContactError;
143
138
foreach (const QContactDetail& detail, allDetails) {
144
139
// If the custom detail handler handles it, we don't have to.
145
140
if (mDetailHandler
226
221
mDetailHandler2->contactProcessed(contact, &document);
229
// Search through the document for FN or N properties. This will find it even if it was added
230
// by a detail handler.
231
if (!documentContainsName(document)) {
232
QVersitProperty nameProperty;
233
nameProperty.setName(QLatin1String("FN"));
234
nameProperty.setValue(QString());
235
document.addProperty(nameProperty);
224
ensureDocumentContainsName(contact, &document);
241
229
* Returns true if and only if \a document has a "FN" or "N" property.
243
bool QVersitContactExporterPrivate::documentContainsName(const QVersitDocument &document)
231
void QVersitContactExporterPrivate::ensureDocumentContainsName(const QContact& contact,
232
QVersitDocument* document)
245
foreach (const QVersitProperty& property, document.properties()) {
234
bool containsN = false;
235
bool containsFN = false;
237
foreach (const QVersitProperty& property, document->properties()) {
246
238
const QString& name = property.name();
247
if (name == QLatin1String("FN") || name == QLatin1String("N"))
239
if (name == QLatin1String("FN")) {
241
fnValue = property.value();
242
} else if (name == QLatin1String("N")) {
247
QVersitProperty fnProperty;
248
fnProperty.setName(QLatin1String("FN"));
249
fnValue = QVersitContactImporterPrivate::synthesizedDisplayLabel(contact);
250
fnProperty.setValue(fnValue);
251
document->addProperty(fnProperty);
255
QVersitProperty nProperty;
256
nProperty.setValueType(QVersitProperty::CompoundType);
257
nProperty.setName(QLatin1String("N"));
258
nProperty.setValue(QStringList() << QString() << QString()
259
<< QString() << QString() << QString());
260
document->addProperty(nProperty);
260
271
QList<QVersitProperty>* generatedProperties,
261
272
QSet<QString>* processedFields)
275
Q_UNUSED(removedProperties);
263
276
QContactName contactName = static_cast<QContactName>(detail);
264
277
if (!contactName.lastName().isEmpty()
265
278
|| !contactName.firstName().isEmpty()
278
291
*generatedProperties << property;
281
// Generate an FN field if none is already there
282
// Don't override previously exported FN properties (eg. exported by a DisplayLabel detail)
283
QVersitProperty fnProperty =
284
VersitUtils::takeProperty(document, QLatin1String("FN"), removedProperties);
285
if (fnProperty.value().isEmpty()) {
286
fnProperty.setName(QLatin1String("FN"));
287
if (!contactName.customLabel().isEmpty()) {
288
fnProperty.setValue(contactName.customLabel());
289
} else if (!contactName.firstName().isEmpty()) {
290
if (!contactName.lastName().isEmpty()) {
291
fnProperty.setValue(QString::fromAscii("%1 %2").arg(contactName.firstName(),
292
contactName.lastName()));
294
fnProperty.setValue(contactName.firstName());
296
} else if (!contactName.lastName().isEmpty()) {
297
fnProperty.setValue(contactName.lastName());
301
*generatedProperties << fnProperty;
302
294
*processedFields << QContactName::FieldLastName
303
295
<< QContactName::FieldFirstName
304
296
<< QContactName::FieldMiddleName