qtmobility/tests/auto/qcontactmanagerplugins/dummyplugin/dummyplugin.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 5 453da2cfceef
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
    55 QTM_USE_NAMESPACE
    55 QTM_USE_NAMESPACE
    56 
    56 
    57 class DummyEngine : public QContactManagerEngine
    57 class DummyEngine : public QContactManagerEngine
    58 {
    58 {
    59 public:
    59 public:
    60     DummyEngine(const QMap<QString, QString>& parameters, QContactManager::Error& error);
    60     DummyEngine(const QMap<QString, QString>& parameters, QContactManager::Error* error);
    61     DummyEngine(const DummyEngine& other);
    61     DummyEngine(const DummyEngine& other);
    62     ~DummyEngine();
    62     ~DummyEngine();
    63     DummyEngine& operator=(const DummyEngine& other);
    63     DummyEngine& operator=(const DummyEngine& other);
    64     QContactManagerEngine* clone();
    64     QContactManagerEngine* clone();
    65     void deref();
    65     void deref();
    66     QString managerName() const;
    66     QString managerName() const;
    67 
    67 
    68     /* Contacts - Accessors and Mutators */
    68     /* Contacts - Accessors and Mutators */
    69     QList<QContactLocalId> contacts(QContactManager::Error& error) const;
    69     QList<QContactLocalId> contacts(QContactManager::Error* error) const;
    70     QContact contact(const QContactLocalId& contactId, QContactManager::Error& error) const;
    70     QContact contact(const QContactLocalId& contactId, QContactManager::Error* error) const;
    71     QContact contact(const QContactLocalId& contactId, const QStringList& definitionRestrictions, QContactManager::Error& error) const;
    71     QContact contact(const QContactLocalId& contactId, const QContactFetchHint& fetchHint, QContactManager::Error* error) const;
    72     bool saveContact(QContact* contact, bool batch, QContactManager::Error& error);
    72     bool saveContact(QContact* contact, bool batch, QContactManager::Error* error);
    73     bool removeContact(const QContactLocalId& contactId, bool batch, QContactManager::Error& error);
    73     bool removeContact(const QContactLocalId& contactId, bool batch, QContactManager::Error* error);
    74 
    74 
    75     /* Capabilities reporting */
    75     /* Capabilities reporting */
    76     QStringList capabilities() const;
    76     QStringList capabilities() const;
    77     QStringList fastFilterableDefinitions() const;
    77     QStringList fastFilterableDefinitions() const;
    78     QList<QVariant::Type> supportedDataTypes() const;
    78     QList<QVariant::Type> supportedDataTypes() const;
       
    79 
       
    80     QMap<QString, QString> managerParameters() const {return QMap<QString, QString>();}
       
    81     int managerVersion() const {return 0;}
       
    82 
       
    83     QList<QContactLocalId> contactIds(const QContactFilter&, const QList<QContactSortOrder>&, QContactManager::Error* error) const
       
    84     {
       
    85         *error = QContactManager::NotSupportedError;
       
    86         return QList<QContactLocalId>();
       
    87     }
       
    88 
       
    89     QList<QContact> contacts(const QContactFilter&, const QList<QContactSortOrder>&, const QContactFetchHint&, QContactManager::Error* error) const
       
    90     {
       
    91         *error = QContactManager::NotSupportedError;
       
    92         return QList<QContact>();
       
    93     }
       
    94 
       
    95     bool saveContacts(QList<QContact>*, QMap<int, QContactManager::Error>*, QContactManager::Error* error)
       
    96     {
       
    97         *error = QContactManager::NotSupportedError;
       
    98         return false;
       
    99     }
       
   100 
       
   101     bool removeContacts(const QList<QContactLocalId>&, QMap<int, QContactManager::Error>*, QContactManager::Error* error)
       
   102     {
       
   103         *error = QContactManager::NotSupportedError;
       
   104         return false;
       
   105     }
       
   106 
       
   107     QContact conformingContact(const QContact&, QContactManager::Error* error)
       
   108     {
       
   109         *error = QContactManager::NotSupportedError;
       
   110         return QContact();
       
   111     }
       
   112 
       
   113     /* Synthesize the display label of a contact */
       
   114     virtual QString synthesizedDisplayLabel(const QContact&, QContactManager::Error* error) const
       
   115     {
       
   116         *error = QContactManager::NotSupportedError;
       
   117         return QString();
       
   118     }
       
   119 
       
   120     /* "Self" contact id (MyCard) */
       
   121     virtual bool setSelfContactId(const QContactLocalId&, QContactManager::Error* error)
       
   122     {
       
   123         *error = QContactManager::NotSupportedError;
       
   124         return false;
       
   125     }
       
   126 
       
   127     virtual QContactLocalId selfContactId(QContactManager::Error* error) const
       
   128     {
       
   129         *error = QContactManager::NotSupportedError;
       
   130         return 0;
       
   131     }
       
   132 
       
   133     /* Relationships between contacts */
       
   134     virtual QList<QContactRelationship> relationships(const QString&, const QContactId&, QContactRelationship::Role, QContactManager::Error* error) const
       
   135     {
       
   136         *error = QContactManager::NotSupportedError;
       
   137         return QList<QContactRelationship>();
       
   138     }
       
   139 
       
   140     virtual bool saveRelationships(QList<QContactRelationship>*, QMap<int, QContactManager::Error>*, QContactManager::Error* error)
       
   141     {
       
   142         *error = QContactManager::NotSupportedError;
       
   143         return false;
       
   144     }
       
   145 
       
   146     virtual bool removeRelationships(const QList<QContactRelationship>&, QMap<int, QContactManager::Error>*, QContactManager::Error* error)
       
   147     {
       
   148         *error = QContactManager::NotSupportedError;
       
   149         return false;
       
   150     }
       
   151 
       
   152     /* Validation for saving */
       
   153     virtual QContact compatibleContact(const QContact&, QContactManager::Error* error) const
       
   154     {
       
   155         *error =  QContactManager::NotSupportedError;
       
   156         return QContact();
       
   157     }
       
   158 
       
   159     virtual bool validateContact(const QContact&, QContactManager::Error* error) const
       
   160     {
       
   161         *error = QContactManager::NotSupportedError;
       
   162         return false;
       
   163     }
       
   164 
       
   165     virtual bool validateDefinition(const QContactDetailDefinition&, QContactManager::Error* error) const
       
   166     {
       
   167         *error = QContactManager::NotSupportedError;
       
   168         return false;
       
   169     }
       
   170 
       
   171     /* Definitions - Accessors and Mutators */
       
   172     virtual QMap<QString, QContactDetailDefinition> detailDefinitions(const QString&, QContactManager::Error* error) const
       
   173     {
       
   174         *error = QContactManager::NotSupportedError;
       
   175         return QMap<QString, QContactDetailDefinition>();
       
   176     }
       
   177 
       
   178     virtual QContactDetailDefinition detailDefinition(const QString&, const QString&, QContactManager::Error* error) const
       
   179     {
       
   180         *error = QContactManager::NotSupportedError;
       
   181         return QContactDetailDefinition();
       
   182     }
       
   183 
       
   184     virtual bool saveDetailDefinition(const QContactDetailDefinition&, const QString&, QContactManager::Error* error)
       
   185     {
       
   186         *error = QContactManager::NotSupportedError;
       
   187         return false;
       
   188     }
       
   189 
       
   190     virtual bool removeDetailDefinition(const QString&, const QString&, QContactManager::Error* error)
       
   191     {
       
   192         *error = QContactManager::NotSupportedError;
       
   193         return false;
       
   194     }
       
   195 
       
   196     /* Asynchronous Request Support */
       
   197     virtual void requestDestroyed(QContactAbstractRequest*) {}
       
   198     virtual bool startRequest(QContactAbstractRequest*) {return false;}
       
   199     virtual bool cancelRequest(QContactAbstractRequest*) {return false;}
       
   200     virtual bool waitForRequestFinished(QContactAbstractRequest*, int) {return false;}
       
   201 
       
   202     /* Capabilities reporting */
       
   203     virtual bool hasFeature(QContactManager::ManagerFeature, const QString&) const
       
   204     {
       
   205         return false;
       
   206     }
       
   207 
       
   208     virtual bool isRelationshipTypeSupported(const QString&, const QString&) const
       
   209     {
       
   210         return false;
       
   211     }
       
   212 
       
   213     virtual bool isFilterSupported(const QContactFilter&) const
       
   214     {
       
   215         return false;
       
   216     }
       
   217 
       
   218     virtual QStringList supportedContactTypes() const
       
   219     {
       
   220         return QStringList();
       
   221     }
       
   222 
    79 };
   223 };
    80 
   224 
    81 class Q_DECL_EXPORT DummyEngineFactory : public QObject, public QContactManagerEngineFactory
   225 class Q_DECL_EXPORT DummyEngineFactory : public QObject, public QContactManagerEngineFactory
    82 {
   226 {
    83     Q_OBJECT
   227     Q_OBJECT
    84     Q_INTERFACES(QtMobility::QContactManagerEngineFactory)
   228     Q_INTERFACES(QtMobility::QContactManagerEngineFactory)
    85     public:
   229     public:
    86         QContactManagerEngine* engine(const QMap<QString, QString>& parameters, QContactManager::Error& error);
   230         QContactManagerEngine* engine(const QMap<QString, QString>& parameters, QContactManager::Error* error);
    87         QString managerName() const;
   231         QString managerName() const;
    88 };
   232 };
    89 
   233 
    90 QContactManagerEngine* DummyEngineFactory::engine(const QMap<QString, QString>& parameters, QContactManager::Error& error)
   234 QContactManagerEngine* DummyEngineFactory::engine(const QMap<QString, QString>& parameters, QContactManager::Error* error)
    91 {
   235 {
    92     return new DummyEngine(parameters, error);
   236     return new DummyEngine(parameters, error);
    93 }
   237 }
    94 
   238 
    95 QString DummyEngineFactory::managerName() const
   239 QString DummyEngineFactory::managerName() const
   100     return QString();
   244     return QString();
   101 #endif
   245 #endif
   102 }
   246 }
   103 Q_EXPORT_PLUGIN2(DUMMYPLUGINTARGET, DummyEngineFactory);
   247 Q_EXPORT_PLUGIN2(DUMMYPLUGINTARGET, DummyEngineFactory);
   104 
   248 
   105 DummyEngine::DummyEngine(const QMap<QString, QString>& parameters, QContactManager::Error& error)
   249 DummyEngine::DummyEngine(const QMap<QString, QString>& parameters, QContactManager::Error* error)
   106 {
   250 {
   107     Q_UNUSED(parameters);
   251     Q_UNUSED(parameters);
   108     error = QContactManager::AlreadyExistsError; // Another random choice
   252     *error = QContactManager::AlreadyExistsError; // Another random choice
   109 }
   253 }
   110 
   254 
   111 DummyEngine::DummyEngine(const DummyEngine& other)
   255 DummyEngine::DummyEngine(const DummyEngine& other)
   112     : QContactManagerEngine()
   256     : QContactManagerEngine()
   113 {
   257 {
   142 #else
   286 #else
   143     return QString();
   287     return QString();
   144 #endif
   288 #endif
   145 }
   289 }
   146 
   290 
   147 QList<QContactLocalId> DummyEngine::contacts(QContactManager::Error& error) const
   291 QList<QContactLocalId> DummyEngine::contacts(QContactManager::Error* error) const
   148 {
   292 {
   149     QList<QContactLocalId> allCIds;
   293     QList<QContactLocalId> allCIds;
   150 
   294 
   151     if (allCIds.count() > 0 && error == QContactManager::NoError)
   295     if (allCIds.count() > 0 && *error == QContactManager::NoError)
   152         error = QContactManager::DoesNotExistError;
   296         *error = QContactManager::DoesNotExistError;
   153 
   297 
   154     return allCIds;
   298     return allCIds;
   155 }
   299 }
   156 
   300 
   157 QContact DummyEngine::contact(const QContactLocalId& contactId, QContactManager::Error& error) const
   301 QContact DummyEngine::contact(const QContactLocalId& contactId, QContactManager::Error* error) const
   158 {
   302 {
   159     Q_UNUSED(contactId);
   303     Q_UNUSED(contactId);
   160     error = QContactManager::DoesNotExistError;
   304     *error = QContactManager::DoesNotExistError;
   161     return QContact();
   305     return QContact();
   162 }
   306 }
   163 
   307 
   164 QContact DummyEngine::contact(const QContactLocalId& contactId, const QStringList& definitionRestrictions, QContactManager::Error& error) const
   308 QContact DummyEngine::contact(const QContactLocalId& contactId, const QContactFetchHint& fetchHint, QContactManager::Error* error) const
   165 {
   309 {
   166     Q_UNUSED(contactId);
   310     Q_UNUSED(contactId);
   167     Q_UNUSED(definitionRestrictions);
   311     Q_UNUSED(fetchHint);
   168     error = QContactManager::DoesNotExistError;
   312     *error = QContactManager::DoesNotExistError;
   169     return QContact();
   313     return QContact();
   170 }
   314 }
   171 
   315 
   172 bool DummyEngine::saveContact(QContact* contact, bool batch, QContactManager::Error& error)
   316 bool DummyEngine::saveContact(QContact* contact, bool batch, QContactManager::Error* error)
   173 {
   317 {
   174     // ensure that the contact's details conform to their definitions
   318     // ensure that the contact's details conform to their definitions
   175     if (!validateContact(*contact, error)) {
   319     if (!validateContact(*contact, error)) {
   176         error = QContactManager::InvalidDetailError;
   320         *error = QContactManager::InvalidDetailError;
   177         return false;
   321         return false;
   178     }
   322     }
   179 
   323 
   180     // success!
   324     // success!
   181     QContactId newId;
   325     QContactId newId;
   182     newId.setManagerUri(managerUri());
   326     newId.setManagerUri(managerUri());
   183     newId.setLocalId(5);
   327     newId.setLocalId(5);
   184     contact->setId(newId);
   328     contact->setId(newId);
   185     error = QContactManager::NoError;
   329     *error = QContactManager::NoError;
   186 
   330 
   187     // if we need to emit signals (ie, this isn't part of a batch operation)
   331     // if we need to emit signals (ie, this isn't part of a batch operation)
   188     // then emit the correct one.
   332     // then emit the correct one.
   189     if (!batch) {
   333     if (!batch) {
   190         QList<QContactLocalId> emitList;
   334         QList<QContactLocalId> emitList;
   193     }
   337     }
   194 
   338 
   195     return true;
   339     return true;
   196 }
   340 }
   197 
   341 
   198 bool DummyEngine::removeContact(const QContactLocalId& contactId, bool batch, QContactManager::Error& error)
   342 bool DummyEngine::removeContact(const QContactLocalId& contactId, bool batch, QContactManager::Error* error)
   199 {
   343 {
   200     if (contactId != 5) {
   344     if (contactId != 5) {
   201         error = QContactManager::DoesNotExistError;
   345         *error = QContactManager::DoesNotExistError;
   202         return false;
   346         return false;
   203     }
   347     }
   204 
   348 
   205     error = QContactManager::NoError;
   349     *error = QContactManager::NoError;
   206 
   350 
   207     // if we need to emit signals (ie, this isn't part of a batch operation)
   351     // if we need to emit signals (ie, this isn't part of a batch operation)
   208     // then emit the correct one.
   352     // then emit the correct one.
   209     if (!batch) {
   353     if (!batch) {
   210         QList<QContactLocalId> emitList;
   354         QList<QContactLocalId> emitList;