phonebookui/pbkcommonui/inc/cntvcarddetailhandler.h
author hgs
Thu, 05 Aug 2010 14:31:09 +0300
changeset 54 47627ab5d7a4
permissions -rw-r--r--
201031
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include <qversitcontactexporter.h>
hgs
parents:
diff changeset
    19
#include <qtcontacts.h>
hgs
parents:
diff changeset
    20
#include <qversitproperty.h>
hgs
parents:
diff changeset
    21
hgs
parents:
diff changeset
    22
#ifndef CNTVCARDDETAILHANDLER_H
hgs
parents:
diff changeset
    23
#define CNTVCARDDETAILHANDLER_H
hgs
parents:
diff changeset
    24
hgs
parents:
diff changeset
    25
class CntVCardDetailHandler : public QVersitContactExporterDetailHandlerV2 
hgs
parents:
diff changeset
    26
{
hgs
parents:
diff changeset
    27
public:
hgs
parents:
diff changeset
    28
    inline CntVCardDetailHandler(){}
hgs
parents:
diff changeset
    29
    inline void detailProcessed(const QContact& contact,
hgs
parents:
diff changeset
    30
                                 const QContactDetail& detail,
hgs
parents:
diff changeset
    31
                                 const QSet<QString>& processedFields,
hgs
parents:
diff changeset
    32
                                 const QVersitDocument& document,
hgs
parents:
diff changeset
    33
                                 QList<QVersitProperty>* toBeRemoved,
hgs
parents:
diff changeset
    34
                                 QList<QVersitProperty>* toBeAdded) 
hgs
parents:
diff changeset
    35
    {
hgs
parents:
diff changeset
    36
        Q_UNUSED(contact)
hgs
parents:
diff changeset
    37
        Q_UNUSED(detail)
hgs
parents:
diff changeset
    38
        Q_UNUSED(processedFields)
hgs
parents:
diff changeset
    39
        Q_UNUSED(document)
hgs
parents:
diff changeset
    40
        Q_UNUSED(toBeRemoved)
hgs
parents:
diff changeset
    41
        Q_UNUSED(toBeAdded)
hgs
parents:
diff changeset
    42
    }
hgs
parents:
diff changeset
    43
    
hgs
parents:
diff changeset
    44
    inline void contactProcessed(const QContact& contact,
hgs
parents:
diff changeset
    45
                                  QVersitDocument* document)
hgs
parents:
diff changeset
    46
    {
hgs
parents:
diff changeset
    47
        Q_UNUSED(contact)
hgs
parents:
diff changeset
    48
        // If there is not a FN or N value use an empty FN value. This ensures
hgs
parents:
diff changeset
    49
        // that the vCard created is valid. vCard standard requires a vCard to
hgs
parents:
diff changeset
    50
        // have atlease a name (N) of formatted name (FN) field to be valid.
hgs
parents:
diff changeset
    51
        bool vCardValid(false);
hgs
parents:
diff changeset
    52
        foreach (const QVersitProperty& property, document->properties()) {
hgs
parents:
diff changeset
    53
            const QString& name = property.name();
hgs
parents:
diff changeset
    54
            if (name == QLatin1String("FN") || name == QLatin1String("N")) {
hgs
parents:
diff changeset
    55
                vCardValid = true;
hgs
parents:
diff changeset
    56
                break;
hgs
parents:
diff changeset
    57
            }
hgs
parents:
diff changeset
    58
        }
hgs
parents:
diff changeset
    59
        
hgs
parents:
diff changeset
    60
        if (!vCardValid) {
hgs
parents:
diff changeset
    61
            QVersitProperty fnProperty;
hgs
parents:
diff changeset
    62
            fnProperty.setName(QLatin1String("FN"));
hgs
parents:
diff changeset
    63
            fnProperty.setValue(QString());
hgs
parents:
diff changeset
    64
            document->addProperty(fnProperty);
hgs
parents:
diff changeset
    65
        }
hgs
parents:
diff changeset
    66
    }
hgs
parents:
diff changeset
    67
};
hgs
parents:
diff changeset
    68
hgs
parents:
diff changeset
    69
#endif