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