qtmobility/plugins/contacts/qtcontacts-tracker/qcontacttrackerbackend_p.h
changeset 14 6fbed849b4f4
parent 11 06b8e2af4411
child 15 1f895d8a5b2b
equal deleted inserted replaced
11:06b8e2af4411 14:6fbed849b4f4
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 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 #ifndef QCONTACTTRACKERBACKEND_P_H
       
    43 #define QCONTACTTRACKERBACKEND_P_H
       
    44 
       
    45 //
       
    46 //  W A R N I N G
       
    47 //  -------------
       
    48 //
       
    49 // This file is not part of the Qt API.  It exists purely as an
       
    50 // implementation detail.  This header file may change from version to
       
    51 // version without notice, or even be removed.
       
    52 //
       
    53 // We mean it.
       
    54 //
       
    55 
       
    56 #include <QSharedData>
       
    57 #include <QtTracker/Tracker>
       
    58 #include <QtTracker/ontologies/nco.h>
       
    59 #include <QtTracker/QLive>
       
    60 
       
    61 #include <qmobilityglobal.h>
       
    62 #include <qcontactmanagerengine.h>
       
    63 #include <qcontactmanagerenginefactory.h>
       
    64 
       
    65 using namespace SopranoLive;
       
    66 #include "qtrackercontactasyncrequest.h"
       
    67 
       
    68 QTM_BEGIN_NAMESPACE
       
    69 class QContactAbstractRequest;
       
    70 class QContactChangeSet;
       
    71 QTM_END_NAMESPACE
       
    72 
       
    73 QTM_USE_NAMESPACE
       
    74 
       
    75 class QContactTrackerEngineData : public QSharedData
       
    76 {
       
    77 public:
       
    78     QContactTrackerEngineData()
       
    79         : QSharedData(), m_refCount(QAtomicInt(1)),
       
    80         m_engineName(QString("tracker")),
       
    81         m_engineVersion(0)
       
    82     {
       
    83     }
       
    84 
       
    85     QContactTrackerEngineData(const QContactTrackerEngineData& other)
       
    86         : QSharedData(other), m_refCount(QAtomicInt(1)),
       
    87         m_lastUsedId(other.m_lastUsedId),
       
    88         m_definitions(other.m_definitions),
       
    89         m_engineName(other.m_engineName),
       
    90         m_engineVersion(other.m_engineVersion)
       
    91     {
       
    92     }
       
    93 
       
    94     void init();
       
    95 
       
    96     ~QContactTrackerEngineData() {}
       
    97 
       
    98     QAtomicInt m_refCount;
       
    99     mutable QContactLocalId m_lastUsedId;
       
   100     mutable QMap<QString, QContactDetailDefinition> m_definitions;
       
   101     mutable QMap<QContactAbstractRequest*, QTrackerContactAsyncRequest*> m_requests;
       
   102     QString m_engineName;
       
   103     int m_engineVersion;
       
   104 };
       
   105 
       
   106 class QContactTrackerEngine : public QContactManagerEngine
       
   107 {
       
   108 Q_OBJECT
       
   109 
       
   110 public:
       
   111     QContactTrackerEngine(const QString& managerName, int managerVersion, const QMap<QString, QString>& parameters);
       
   112     QContactTrackerEngine(const QMap<QString, QString>& parameters);        // XXX FIXME: I don't think this is used in your factory code either?
       
   113     QContactTrackerEngine(const QContactTrackerEngine& other);              // XXX FIXME: not used in your factory code...?
       
   114     ~QContactTrackerEngine();
       
   115     QContactTrackerEngine& operator=(const QContactTrackerEngine& other);   // XXX FIXME: not used in your factory code...?
       
   116     QContactManagerEngine* clone();                                         // XXX FIXME: no longer part of the engine API
       
   117     void deref();                                                           // XXX FIXME: no longer part of the engine API
       
   118 
       
   119     // sync methods, wrapping async methods & waitForFinished
       
   120     QList<QContactLocalId> contactIds(const QList<QContactSortOrder>& sortOrders, QContactManager::Error* error) const; // XXX FIXME: no longer part of engine API.
       
   121     QList<QContactLocalId> contactIds(const QContactFilter& filter, const QList<QContactSortOrder>& sortOrders, QContactManager::Error* error) const;
       
   122     QList<QContact> contacts(const QContactFilter& filter, const QList<QContactSortOrder>& sortOrders, const QContactFetchHint& fetchHint, QContactManager::Error* error) const;
       
   123     QContact contact(const QContactLocalId& contactId, const QContactFetchHint& fetchHint, QContactManager::Error* error) const;
       
   124 
       
   125     /* Save contacts - single and in batch */
       
   126     bool saveContact( QContact* contact, QContactManager::Error* error);
       
   127     bool saveContacts(QList<QContact>* contacts, QMap<int, QContactManager::Error>* errorMap, QContactManager::Error* error);
       
   128 
       
   129     bool removeContact(const QContactLocalId& contactId, QContactManager::Error* error);
       
   130     bool removeContacts(const QList<QContactLocalId>& contactIds, QMap<int, QContactManager::Error>* errorMap, QContactManager::Error* error) ;
       
   131 
       
   132     /* Definitions - Accessors and Mutators */
       
   133     QMap<QString, QContactDetailDefinition> detailDefinitions(const QString& contactType, QContactManager::Error* error) const;
       
   134 
       
   135     QContactLocalId selfContactId(QContactManager::Error* error) const;
       
   136 
       
   137     /* Asynchronous Request Support */
       
   138     void requestDestroyed(QContactAbstractRequest* req);
       
   139     bool startRequest(QContactAbstractRequest* req);
       
   140     bool waitForRequestFinished(QContactAbstractRequest* req, int msecs);
       
   141 
       
   142     /* Capabilities reporting */
       
   143     bool hasFeature(QContactManager::ManagerFeature feature, const QString& contactType) const;
       
   144 
       
   145     bool isFilterSupported(const QContactFilter& filter) const;
       
   146     QList<QVariant::Type> supportedDataTypes() const;
       
   147 
       
   148     /* Version Reporting */
       
   149     QString managerName() const;
       
   150     int managerVersion() const;
       
   151 
       
   152     /* Synthesise the display label of a contact */
       
   153     QString synthesizedDisplayLabel(const QContact& contact, QContactManager::Error* error) const;
       
   154 
       
   155 
       
   156 
       
   157     /* XXX TODO: pure virtual unimplemented functions! */
       
   158     QMap<QString, QString> managerParameters() const {return QMap<QString,QString>();}
       
   159     bool setSelfContactId(const QContactLocalId&, QContactManager::Error* error) {*error = QContactManager::NotSupportedError; return false;}
       
   160     QList<QContactRelationship> relationships(const QString&, const QContactId&, QContactRelationship::Role, QContactManager::Error* error) const {*error = QContactManager::NotSupportedError; return QList<QContactRelationship>();}
       
   161     bool saveRelationships(QList<QContactRelationship>*, QMap<int, QContactManager::Error>*, QContactManager::Error* error) {*error = QContactManager::NotSupportedError; return false;}
       
   162     bool removeRelationships(const QList<QContactRelationship>&, QMap<int, QContactManager::Error>*, QContactManager::Error* error) {*error = QContactManager::NotSupportedError; return false;}
       
   163     QContact compatibleContact(const QContact&, QContactManager::Error* error) const {*error = QContactManager::NotSupportedError; return QContact();}
       
   164     bool validateContact(const QContact&, QContactManager::Error* error) const {*error = QContactManager::NotSupportedError; return false;}
       
   165     bool validateDefinition(const QContactDetailDefinition&, QContactManager::Error* error) const {*error = QContactManager::NotSupportedError; return false;}
       
   166     QContactDetailDefinition detailDefinition(const QString&, const QString&, QContactManager::Error* error) const {*error = QContactManager::NotSupportedError; return QContactDetailDefinition();}
       
   167     bool saveDetailDefinition(const QContactDetailDefinition&, const QString&, QContactManager::Error* error) {*error = QContactManager::NotSupportedError; return false;}
       
   168     bool removeDetailDefinition(const QString&, const QString&, QContactManager::Error* error) {*error = QContactManager::NotSupportedError; return false;}
       
   169     bool cancelRequest(QContactAbstractRequest*) {return false;}
       
   170     bool isRelationshipTypeSupported(const QString&, const QString&) const {return false;}
       
   171     QStringList supportedContactTypes() const {return (QStringList() << QContactType::TypeContact);}
       
   172 
       
   173 
       
   174 private:
       
   175     //called from both constructors, connecting to all contact NodeList changes signals
       
   176     void connectToSignals();
       
   177     RDFVariable contactDetail2Rdf(const RDFVariable& rdfContact, const QString& definitionName, const QString& fieldName) const;
       
   178     QContact contact_impl(const QContactLocalId& contactId, const QContactFetchHint& fetchHint, QContactManager::Error* error) const;
       
   179 private:
       
   180     QSharedDataPointer<QContactTrackerEngineData> d;
       
   181     const QString contactArchiveFile;
       
   182     const QString contactArchiveDir;
       
   183     friend class ut_qtcontacts_trackerplugin;
       
   184 };
       
   185 
       
   186 class Q_DECL_EXPORT ContactTrackerFactory : public QObject, public QtMobility::QContactManagerEngineFactory
       
   187 {
       
   188     Q_OBJECT
       
   189     Q_INTERFACES(QtMobility::QContactManagerEngineFactory)
       
   190     public:
       
   191         QContactManagerEngine* engine(const QMap<QString, QString>& parameters, QContactManager::Error*);
       
   192         QString managerName() const;
       
   193 };
       
   194 
       
   195 #endif