plugins/contacts/symbian/plugin/inc/cntsymbianengine.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 #ifndef CNTSYMBIANBACKEND_P_H
       
    43 #define CNTSYMBIANBACKEND_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 <QObject>
       
    58 #include <QQueue>
       
    59 
       
    60 #include <qmobilityglobal.h>
       
    61 #include "qtcontactsglobal.h"
       
    62 #include "qcontact.h"
       
    63 #include "qcontactname.h"
       
    64 #include "qcontactphonenumber.h"
       
    65 #include "qcontactmanager.h"
       
    66 #include "qcontactmanagerengine.h"
       
    67 #include "qcontactmanagerenginefactory.h"
       
    68 
       
    69 QTM_BEGIN_NAMESPACE
       
    70 class QContactChangeSet;
       
    71 class QContactAbstractRequest;
       
    72 QTM_END_NAMESPACE
       
    73 class CntSymbianDatabase;
       
    74 class CntSymbianSrvConnection;
       
    75 class CntTransformContact;
       
    76 class CntSymbianFilter;
       
    77 class CntAbstractContactSorter;
       
    78 class CntRelationship;
       
    79 class CntDisplayLabel;
       
    80 
       
    81 QTM_USE_NAMESPACE
       
    82 
       
    83 #define CNT_SYMBIAN_MANAGER_NAME "symbian"
       
    84 
       
    85 class CntSymbianEngine : public QContactManagerEngine
       
    86 {
       
    87     Q_OBJECT
       
    88 
       
    89 public:
       
    90     CntSymbianEngine(const QMap<QString, QString>& parameters, QContactManager::Error* error);
       
    91     ~CntSymbianEngine();
       
    92     
       
    93     /* URI reporting */
       
    94     QString managerName() const;
       
    95 
       
    96     /* XXX TODO - implement these correctly */
       
    97     int managerVersion() const { return 1;}
       
    98     QContact compatibleContact(const QContact& contact, QContactManager::Error* error) const {return QContactManagerEngine::compatibleContact(contact, error);}
       
    99 
       
   100     /* Functions that are optional in the base API */
       
   101     bool saveRelationship(QContactRelationship* relationship, QContactManager::Error* error);
       
   102     bool removeRelationship(const QContactRelationship& relationship, QContactManager::Error* error);
       
   103     bool saveContact(QContact* contact, QContactManager::Error* error);
       
   104     bool removeContact(const QContactLocalId& contactId, QContactManager::Error* error);
       
   105 
       
   106     /* Contacts - Accessors and Mutators */
       
   107     QList<QContactLocalId> contactIds(const QContactFilter& filter, const QList<QContactSortOrder>& sortOrders, QContactManager::Error* error) const;
       
   108     QList<QContact> contacts(const QContactFilter& filter, const QList<QContactSortOrder>& sortOrders, const QContactFetchHint& fetchHint, QContactManager::Error* error) const;
       
   109     QContact contact(const QContactLocalId& contactId, const QContactFetchHint& fetchHint, QContactManager::Error* error) const;
       
   110 
       
   111     bool saveContacts(QList<QContact>* contacts, QMap<int, QContactManager::Error>* errorMap, QContactManager::Error* error);
       
   112     bool removeContacts(const QList<QContactLocalId>& contactIds, QMap<int, QContactManager::Error>* errorMap, QContactManager::Error* error);
       
   113 
       
   114     /* Synthesize the display label of a contact */
       
   115     QString synthesizedDisplayLabel(const QContact& contact, QContactManager::Error* error) const;
       
   116     
       
   117     /* "Self" contact id (MyCard) */
       
   118     bool setSelfContactId(const QContactLocalId& contactId, QContactManager::Error* error);
       
   119     QContactLocalId selfContactId(QContactManager::Error* error) const;
       
   120     
       
   121     /* Relationships between contacts */
       
   122     QList<QContactRelationship> relationships(const QString& relationshipType, const QContactId& participantId, QContactRelationship::Role role, QContactManager::Error* error) const;
       
   123     bool saveRelationships(QList<QContactRelationship>* relationships, QMap<int, QContactManager::Error>* errorMap, QContactManager::Error* error);
       
   124     bool removeRelationships(const QList<QContactRelationship>& relationships, QMap<int, QContactManager::Error>* errorMap, QContactManager::Error* error);
       
   125 
       
   126     /* Definitions - Accessors and Mutators */
       
   127     QMap<QString, QContactDetailDefinition> detailDefinitions(const QString& contactType, QContactManager::Error* error) const;
       
   128 
       
   129     /* Capabilities reporting */
       
   130     bool hasFeature(QContactManager::ManagerFeature feature, const QString& contactType) const;
       
   131     bool isRelationshipTypeSupported(const QString& relationshipType, const QString& contactType) const;
       
   132     bool isFilterSupported(const QContactFilter& filter) const;
       
   133     QList<QVariant::Type> supportedDataTypes() const;
       
   134 
       
   135 private:
       
   136     QList<QContactLocalId> slowFilter(const QContactFilter& filter, const QList<QContactLocalId>& contacts, QContactManager::Error* error) const;
       
   137     QList<QContactLocalId> slowSort(const QList<QContactLocalId>& contactIds, const QList<QContactSortOrder>& sortOrders, QContactManager::Error* error) const;
       
   138     bool doSaveContact(QContact* contact, QContactChangeSet& changeSet, QContactManager::Error* error);
       
   139 
       
   140     QContact fetchContactL(const QContactLocalId &localId, const QStringList& detailDefinitionsHint) const;
       
   141 
       
   142     /* Add contact */
       
   143     bool addContact(QContact& contact, QContactChangeSet& changeSet, QContactManager::Error* qtError);
       
   144     int addContactL(QContact &contact);
       
   145 
       
   146     /* Update contact */
       
   147     bool updateContact(QContact& contact, QContactChangeSet& changeSet, QContactManager::Error* qtError);
       
   148     void updateContactL(QContact &contact);
       
   149 
       
   150     /* Remove contact */
       
   151     bool removeContact(const QContactLocalId &id, QContactChangeSet& changeSet, QContactManager::Error* qtError);
       
   152     void removeContactL(QContactLocalId id);
       
   153 
       
   154     void updateDisplayLabel(QContact& contact) const;
       
   155 
       
   156     /* Asynchronous Request Support - synchronous versions until thread worker is stable */
       
   157     void requestDestroyed(QContactAbstractRequest* req);
       
   158     bool startRequest(QContactAbstractRequest* req);
       
   159     bool cancelRequest(QContactAbstractRequest* req);
       
   160     bool waitForRequestProgress(QContactAbstractRequest* req, int msecs);
       
   161     bool waitForRequestFinished(QContactAbstractRequest* req, int msecs);
       
   162 
       
   163 private slots:
       
   164     void performAsynchronousOperation();
       
   165 
       
   166 private:
       
   167     CntSymbianDatabase *m_dataBase;
       
   168     CntSymbianSrvConnection *m_srvConnection;
       
   169     QString m_managerUri;
       
   170     CntTransformContact *m_transformContact;
       
   171     CntSymbianFilter *m_contactFilter;
       
   172 #ifndef SYMBIAN_BACKEND_USE_SQLITE    
       
   173     CntAbstractContactSorter *m_contactSorter;
       
   174 #endif    
       
   175     CntRelationship *m_relationship;
       
   176     CntDisplayLabel *m_displayLabel;
       
   177 
       
   178     QQueue<QContactAbstractRequest*> m_asynchronousOperations; // async requests to be performed.
       
   179 #ifdef PBK_UNIT_TEST
       
   180     friend class TestSymbianEngine;
       
   181     friend class TestCntRelationship;
       
   182 #endif  //PBK_UNIT_TEST
       
   183 };
       
   184 #ifndef PBK_UNIT_TEST
       
   185 class CntSymbianFactory : public QObject, public QContactManagerEngineFactory
       
   186 {
       
   187     Q_OBJECT
       
   188     Q_INTERFACES(QtMobility::QContactManagerEngineFactory)
       
   189     public:
       
   190         QContactManagerEngine* engine(const QMap<QString, QString>& parameters, QContactManager::Error* error);
       
   191         QString managerName() const;
       
   192 };
       
   193 #endif  //PBK_UNIT_TEST
       
   194 #endif  //CNTSYMBIANBACKEND_P_H