~ubuntu-branches/ubuntu/quantal/qtmobility/quantal

« back to all changes in this revision

Viewing changes to src/versit/qversitcontactexporter_p.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-11-16 16:18:07 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20101116161807-k2dzt2nyse975r3l
Tags: 1.1.0-0ubuntu1
* New upstream release
* Syncronise with Debian, no remaining changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
**
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.
15
15
**
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.
35
35
**
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.
41
 
**
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$
47
41
 
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"
83
78
/*!
84
79
 * Constructor.
85
80
 */
86
 
QVersitContactExporterPrivate::QVersitContactExporterPrivate(const QString& profile) :
 
81
QVersitContactExporterPrivate::QVersitContactExporterPrivate(const QStringList& profiles) :
87
82
    mDetailHandler(NULL),
88
83
    mDetailHandler2(NULL),
89
84
    mDetailHandlerVersion(0),
93
88
    // Detail mappings
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));
115
111
                QLatin1String(versitSubTypeMappings[i].versitString));
116
112
    }
117
113
 
118
 
    mPluginDetailHandlers = QVersitContactPluginLoader::instance()->createContactHandlers(profile);
 
114
    mPluginDetailHandlers = QVersitContactPluginLoader::instance()->createContactHandlers(profiles);
119
115
}
120
116
 
121
117
/*!
124
120
QVersitContactExporterPrivate::~QVersitContactExporterPrivate()
125
121
{
126
122
    delete mDefaultResourceHandler;
 
123
    foreach (QVersitContactHandler* pluginHandler, mPluginDetailHandlers) {
 
124
        delete pluginHandler;
 
125
    }
127
126
}
128
127
 
129
128
 
136
135
    QVersitContactExporter::Error* error)
137
136
{
138
137
    QList<QContactDetail> allDetails = contact.details();
139
 
    if (allDetails.isEmpty()) {
140
 
        *error = QVersitContactExporter::EmptyContactError;
141
 
        return false;
142
 
    }
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);
227
222
    }
228
223
 
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);
236
 
    }
 
224
    ensureDocumentContainsName(contact, &document);
237
225
    return true;
238
226
}
239
227
 
240
228
/*!
241
229
 * Returns true if and only if \a document has a "FN" or "N" property.
242
230
 */
243
 
bool QVersitContactExporterPrivate::documentContainsName(const QVersitDocument &document)
 
231
void QVersitContactExporterPrivate::ensureDocumentContainsName(const QContact& contact,
 
232
                                                               QVersitDocument* document)
244
233
{
245
 
    foreach (const QVersitProperty& property, document.properties()) {
 
234
    bool containsN = false;
 
235
    bool containsFN = false;
 
236
    QString fnValue;
 
237
    foreach (const QVersitProperty& property, document->properties()) {
246
238
        const QString& name = property.name();
247
 
        if (name == QLatin1String("FN") || name == QLatin1String("N"))
248
 
            return true;
249
 
    }
250
 
    return false;
 
239
        if (name == QLatin1String("FN")) {
 
240
            containsFN = true;
 
241
            fnValue = property.value();
 
242
        } else if (name == QLatin1String("N")) {
 
243
            containsN = true;
 
244
        }
 
245
    }
 
246
    if (!containsFN) {
 
247
        QVersitProperty fnProperty;
 
248
        fnProperty.setName(QLatin1String("FN"));
 
249
        fnValue = QVersitContactImporterPrivate::synthesizedDisplayLabel(contact);
 
250
        fnProperty.setValue(fnValue);
 
251
        document->addProperty(fnProperty);
 
252
    }
 
253
 
 
254
    if (!containsN) {
 
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);
 
261
    }
251
262
}
252
263
 
253
264
/*!
260
271
    QList<QVersitProperty>* generatedProperties,
261
272
    QSet<QString>* processedFields)
262
273
{
 
274
    Q_UNUSED(document);
 
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;
279
292
    }
280
293
 
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()));
293
 
            } else {
294
 
                fnProperty.setValue(contactName.firstName());
295
 
            }
296
 
        } else if (!contactName.lastName().isEmpty()) {
297
 
            fnProperty.setValue(contactName.lastName());
298
 
        }
299
 
    }
300
 
 
301
 
    *generatedProperties << fnProperty;
302
294
    *processedFields << QContactName::FieldLastName
303
295
                     << QContactName::FieldFirstName
304
296
                     << QContactName::FieldMiddleName