src/contacts/engines/qcontactmemorybackend_p.h
changeset 0 876b1a06bc25
equal deleted inserted replaced
-1:000000000000 0:876b1a06bc25
       
     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 
       
    43 #ifndef QCONTACTMEMORYBACKEND_P_H
       
    44 #define QCONTACTMEMORYBACKEND_P_H
       
    45 
       
    46 //
       
    47 //  W A R N I N G
       
    48 //  -------------
       
    49 //
       
    50 // This file is not part of the Qt API.  It exists purely as an
       
    51 // implementation detail.  This header file may change from version to
       
    52 // version without notice, or even be removed.
       
    53 //
       
    54 // We mean it.
       
    55 //
       
    56 
       
    57 #include <QSharedData>
       
    58 #include <QMap>
       
    59 #include <QMultiMap>
       
    60 #include <QList>
       
    61 #include <QQueue>
       
    62 #include <QPair>
       
    63 #include <QSet>
       
    64 #include <QDateTime>
       
    65 #include <QString>
       
    66 #include <QObject>
       
    67 
       
    68 #include "qcontact.h"
       
    69 #include "qcontactmanager.h"
       
    70 #include "qcontactmanagerengine.h"
       
    71 #include "qcontactdetaildefinition.h"
       
    72 #include "qcontactabstractrequest.h"
       
    73 #include "qcontactchangeset.h"
       
    74 
       
    75 QTM_BEGIN_NAMESPACE
       
    76 
       
    77 class QContactAbstractRequest;
       
    78 class QContactManagerEngine;
       
    79 class QContactMemoryEngineData : public QSharedData
       
    80 {
       
    81 public:
       
    82     QContactMemoryEngineData()
       
    83         : QSharedData(),
       
    84         m_refCount(QAtomicInt(1)),
       
    85         m_selfContactId(0),
       
    86         m_nextContactId(1),
       
    87         m_anonymous(false)
       
    88     {
       
    89     }
       
    90 
       
    91     QContactMemoryEngineData(const QContactMemoryEngineData& other)
       
    92         : QSharedData(other),
       
    93         m_refCount(QAtomicInt(1)),
       
    94         m_selfContactId(other.m_selfContactId),
       
    95         m_nextContactId(other.m_nextContactId),
       
    96         m_anonymous(other.m_anonymous)
       
    97     {
       
    98     }
       
    99 
       
   100     ~QContactMemoryEngineData()
       
   101     {
       
   102     }
       
   103 
       
   104     QAtomicInt m_refCount;
       
   105     QString m_id;                                  // the id parameter value
       
   106 
       
   107     QContactLocalId m_selfContactId;               // the "MyCard" contact id
       
   108     QList<QContact> m_contacts;                    // list of contacts
       
   109     QList<QContactLocalId> m_contactIds;           // list of contact Id's
       
   110     QList<QContactRelationship> m_relationships;   // list of contact relationships
       
   111     QMap<QContactLocalId, QList<QContactRelationship> > m_orderedRelationships; // map of ordered lists of contact relationships
       
   112     QList<QString> m_definitionIds;                // list of definition types (id's)
       
   113     mutable QMap<QString, QMap<QString, QContactDetailDefinition> > m_definitions; // map of contact type to map of definition name to definitions.
       
   114     QContactLocalId m_nextContactId;
       
   115     bool m_anonymous;                              // Is this backend ever shared?
       
   116 
       
   117     void emitSharedSignals(QContactChangeSet* cs)
       
   118     {
       
   119         foreach(QContactManagerEngine* engine, m_sharedEngines)
       
   120             cs->emitSignals(engine);
       
   121     }
       
   122 
       
   123     QList<QContactManagerEngine*> m_sharedEngines;   // The list of engines that share this data
       
   124 };
       
   125 
       
   126 class QContactMemoryEngine : public QContactManagerEngine
       
   127 {
       
   128     Q_OBJECT
       
   129 
       
   130 public:
       
   131     static QContactMemoryEngine *createMemoryEngine(const QMap<QString, QString>& parameters);
       
   132 
       
   133     ~QContactMemoryEngine();
       
   134 
       
   135     /* URI reporting */
       
   136     QString managerName() const;
       
   137     QMap<QString, QString> managerParameters() const;
       
   138     /*! \reimp */
       
   139     int managerVersion() const {return 1;}
       
   140 
       
   141     virtual QList<QContactLocalId> contactIds(const QContactFilter& filter, const QList<QContactSortOrder>& sortOrders, QContactManager::Error* error) const;
       
   142     virtual QList<QContact> contacts(const QContactFilter& filter, const QList<QContactSortOrder>& sortOrders, const QContactFetchHint& fetchHint, QContactManager::Error* error) const;
       
   143     virtual QContact contact(const QContactLocalId& contactId, const QContactFetchHint& fetchHint, QContactManager::Error* error) const;
       
   144 
       
   145     virtual bool saveContacts(QList<QContact>* contacts, QMap<int, QContactManager::Error>* errorMap, QContactManager::Error* error);
       
   146     virtual bool removeContacts(const QList<QContactLocalId>& contactIds, QMap<int, QContactManager::Error>* errorMap, QContactManager::Error* error);
       
   147 
       
   148     /*! \reimp */
       
   149     virtual QContact compatibleContact(const QContact& original, QContactManager::Error* error) const
       
   150     {
       
   151         return QContactManagerEngine::compatibleContact(original, error);
       
   152     }
       
   153 
       
   154     /*! \reimp */
       
   155     virtual QString synthesizedDisplayLabel(const QContact& contact, QContactManager::Error* error) const
       
   156     {
       
   157         return QContactManagerEngine::synthesizedDisplayLabel(contact, error);
       
   158     }
       
   159 
       
   160     /* "Self" contact id (MyCard) */
       
   161     virtual bool setSelfContactId(const QContactLocalId& contactId, QContactManager::Error* error);
       
   162     virtual QContactLocalId selfContactId(QContactManager::Error* error) const;
       
   163 
       
   164     /* Relationships between contacts */
       
   165     virtual QList<QContactRelationship> relationships(const QString& relationshipType, const QContactId& participantId, QContactRelationship::Role role, QContactManager::Error* error) const;
       
   166     virtual bool saveRelationships(QList<QContactRelationship>* relationships, QMap<int, QContactManager::Error>* errorMap, QContactManager::Error* error);
       
   167     virtual bool removeRelationships(const QList<QContactRelationship>& relationships, QMap<int, QContactManager::Error>* errorMap, QContactManager::Error* error);
       
   168 
       
   169     /*! \reimp */
       
   170     virtual bool validateContact(const QContact& contact, QContactManager::Error* error) const
       
   171     {
       
   172         return QContactManagerEngine::validateContact(contact, error);
       
   173     }
       
   174     /*! \reimp */
       
   175     virtual bool validateDefinition(const QContactDetailDefinition& def, QContactManager::Error* error) const
       
   176     {
       
   177         return QContactManagerEngine::validateDefinition(def, error);
       
   178     }
       
   179 
       
   180     /* Definitions - Accessors and Mutators */
       
   181     virtual QMap<QString, QContactDetailDefinition> detailDefinitions(const QString& contactType, QContactManager::Error* error) const;
       
   182     /*! \reimp */
       
   183     virtual QContactDetailDefinition detailDefinition(const QString& definitionId, const QString& contactType, QContactManager::Error* error) const
       
   184     {
       
   185         return QContactManagerEngine::detailDefinition(definitionId, contactType, error);
       
   186     }
       
   187     virtual bool saveDetailDefinition(const QContactDetailDefinition& def, const QString& contactType, QContactManager::Error* error);
       
   188     virtual bool removeDetailDefinition(const QString& definitionId, const QString& contactType, QContactManager::Error* error);
       
   189 
       
   190     /* Asynchronous Request Support */
       
   191     virtual void requestDestroyed(QContactAbstractRequest* req);
       
   192     virtual bool startRequest(QContactAbstractRequest* req);
       
   193     virtual bool cancelRequest(QContactAbstractRequest* req);
       
   194     virtual bool waitForRequestFinished(QContactAbstractRequest* req, int msecs);
       
   195 
       
   196     /* Capabilities reporting */
       
   197     virtual bool hasFeature(QContactManager::ManagerFeature feature, const QString& contactType) const;
       
   198     virtual bool isRelationshipTypeSupported(const QString& relationshipType, const QString& contactType) const;
       
   199     virtual bool isFilterSupported(const QContactFilter& filter) const;
       
   200     virtual QList<QVariant::Type> supportedDataTypes() const;
       
   201     /*! \reimp */
       
   202     virtual QStringList supportedContactTypes() const
       
   203     {
       
   204         return QContactManagerEngine::supportedContactTypes();
       
   205     }
       
   206 
       
   207 protected:
       
   208     QContactMemoryEngine(QContactMemoryEngineData* data);
       
   209 
       
   210 private:
       
   211     /* Implement "signal coalescing" for batch functions via change set */
       
   212     bool saveContact(QContact* theContact, QContactChangeSet& changeSet, QContactManager::Error* error);
       
   213     bool removeContact(const QContactLocalId& contactId, QContactChangeSet& changeSet, QContactManager::Error* error);
       
   214     bool saveDetailDefinition(const QContactDetailDefinition& def, const QString& contactType, QContactChangeSet& changeSet, QContactManager::Error* error);
       
   215     bool removeDetailDefinition(const QString& definitionId, const QString& contactType, QContactChangeSet& changeSet, QContactManager::Error* error);
       
   216     bool saveRelationship(QContactRelationship* relationship, QContactChangeSet& changeSet, QContactManager::Error* error);
       
   217     bool removeRelationship(const QContactRelationship& relationship, QContactChangeSet& changeSet, QContactManager::Error* error);
       
   218 
       
   219     void performAsynchronousOperation(QContactAbstractRequest* request);
       
   220 
       
   221     QContactMemoryEngineData* d;
       
   222     static QMap<QString, QContactMemoryEngineData*> engineDatas;
       
   223 };
       
   224 
       
   225 QTM_END_NAMESPACE
       
   226 
       
   227 #endif
       
   228