qtmobility/src/versit/qversitcontactexporter.cpp
changeset 1 2b40d63a9c3d
child 4 90517678cc4f
equal deleted inserted replaced
0:cfcbf08528c4 1:2b40d63a9c3d
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 
       
    43 #include "qversitcontactexporter.h"
       
    44 #include "qversitcontactexporter_p.h"
       
    45 #include "qmobilityglobal.h"
       
    46 
       
    47 #include <qcontact.h>
       
    48 #include <qcontactdetail.h>
       
    49 
       
    50 QTM_USE_NAMESPACE
       
    51 
       
    52 /*!
       
    53   \class QVersitContactExporterDetailHandler
       
    54   \preliminary
       
    55   \brief The QVersitContactExporterDetailHandler class is an interface for clients wishing to
       
    56   implement custom export behaviour for certain contact details.
       
    57   \ingroup versit
       
    58 
       
    59   \sa QVersitContactExporter
       
    60  */
       
    61 
       
    62 /*!
       
    63  * \fn virtual QVersitContactExporterDetailHandler::~QVersitContactExporterDetailHandler()
       
    64  * Frees any memory in use by this handler.
       
    65  */
       
    66 
       
    67 /*!
       
    68  * \fn virtual bool QVersitContactExporterDetailHandler::preProcessDetail(const QContact& contact, const QContactDetail& detail, QVersitDocument* document) = 0;
       
    69  * Process \a detail and update \a document with the corresponding QVersitProperty(s).
       
    70  * \a contact provides the context within which the detail was found.
       
    71  *
       
    72  * Returns true if the detail has been handled and requires no furthur processing, false otherwise.
       
    73  *
       
    74  * This function is called on every QContactDetail encountered during an export.  Supply this
       
    75  * function and return true to implement custom export behaviour.
       
    76  */
       
    77 
       
    78 /*!
       
    79  * \fn virtual bool QVersitContactExporterDetailHandler::postProcessDetail(const QContact& contact, const QContactDetail& detail, bool alreadyProcessed, QVersitDocument* document) = 0;
       
    80  * Process \a detail and update \a document with the corresponding QVersitProperty(s).
       
    81  * \a contact provides the context within which the detail was found.
       
    82  * \a alreadyProcessed is true if the detail has already been processed either by
       
    83  * \l preProcessDetail() or by QVersitContactExporter itself.
       
    84  *
       
    85  * Returns true if the detail has been handled, false otherwise.
       
    86  *
       
    87  * This function is called on every \l QContactDetail encountered during an export.  This can be
       
    88  * used to implement support for QContactDetails not supported by QVersitContactExporter.
       
    89  */
       
    90 
       
    91 /*!
       
    92  * \class QVersitContactExporter
       
    93  * \preliminary
       
    94  * \brief The QVersitContactExporter class converts \l {QContact}{QContacts} into
       
    95  * \l {QVersitDocument}{QVersitDocuments}.
       
    96  * \ingroup versit
       
    97  *
       
    98  * A \l QVersitResourceHandler is associated with the exporter to supply the behaviour for loading
       
    99  * files from persistent storage.  By default, this is set to a \l QVersitDefaultResourceHandler,
       
   100  * which supports basic resource loading from the file system.  An alternative resource handler
       
   101  * can be specified with setResourceHandler().
       
   102  *
       
   103  * By associating a \l QVersitContactExporterDetailHandler with the exporter using
       
   104  * setDetailHandler(), the client can pass in a handler to override the processing of details and/or
       
   105  * handle details that QVersitContactExporter doesn't support.
       
   106  *
       
   107  * An example detail handler that logs unknown properties:
       
   108  * \snippet ../../doc/src/snippets/qtversitdocsample/qtversitdocsample.cpp Detail handler
       
   109  *
       
   110  * An example usage of QVersitContactExporter
       
   111  * \snippet ../../doc/src/snippets/qtversitdocsample/qtversitdocsample.cpp Export example
       
   112  *
       
   113  * \sa QVersitDocument, QVersitProperty, QVersitContactExporterDetailHandler, QVersitResourceHandler
       
   114  */
       
   115 
       
   116 /*!
       
   117  * Constructs a new contact exporter
       
   118  */
       
   119 QVersitContactExporter::QVersitContactExporter()
       
   120     : d(new QVersitContactExporterPrivate())
       
   121 {
       
   122 }
       
   123 
       
   124 /*!
       
   125  * Frees any memory in use by this contact exporter.
       
   126  */
       
   127 QVersitContactExporter::~QVersitContactExporter()
       
   128 {
       
   129     delete d;
       
   130 }
       
   131 
       
   132 /*!
       
   133  * Converts \a contacts into a list of corresponding QVersitDocuments, using the format given by
       
   134  * \a versitType.
       
   135  */
       
   136 QList<QVersitDocument> QVersitContactExporter::exportContacts(
       
   137     const QList<QContact>& contacts,
       
   138     QVersitDocument::VersitType versitType)
       
   139 {
       
   140     QList<QVersitDocument> list;
       
   141     foreach (QContact contact, contacts) {
       
   142         QVersitDocument versitDocument;
       
   143         versitDocument.setType(versitType);
       
   144         d->exportContact(contact, versitDocument);
       
   145         list.append(versitDocument);
       
   146     }
       
   147 
       
   148     return list;
       
   149 }
       
   150 
       
   151 /*!
       
   152  * Sets \a handler to be the handler for processing QContactDetails, or 0 to have no handler.
       
   153  *
       
   154  * Does not take ownership of the handler.  The client should ensure the handler remains valid for
       
   155  * the lifetime of the exporter.
       
   156  */
       
   157 void QVersitContactExporter::setDetailHandler(QVersitContactExporterDetailHandler* handler)
       
   158 {
       
   159     d->mDetailHandler = handler;
       
   160 }
       
   161 
       
   162 /*!
       
   163  * Gets the handler for processing QContactDetails.
       
   164  */
       
   165 QVersitContactExporterDetailHandler* QVersitContactExporter::detailHandler() const
       
   166 {
       
   167     return d->mDetailHandler;
       
   168 }
       
   169 
       
   170 /*!
       
   171  * Sets \a handler to be the handler to load files with, or 0 to have no handler.
       
   172  *
       
   173  * Does not take ownership of the handler.  The client should ensure the handler remains valid for
       
   174  * the lifetime of the exporter.
       
   175  */
       
   176 void QVersitContactExporter::setResourceHandler(QVersitResourceHandler* handler)
       
   177 {
       
   178     d->mResourceHandler = handler;
       
   179 }
       
   180 
       
   181 /*!
       
   182  * Returns the associated resource handler.
       
   183  */
       
   184 QVersitResourceHandler* QVersitContactExporter::resourceHandler() const
       
   185 {
       
   186     return d->mResourceHandler;
       
   187 }