1/****************************************************************************
2**
3** Copyright (C) 2015 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL21$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 or version 3 as published by the Free
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22** following information to ensure the GNU Lesser General Public License
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25**
26** As a special exception, The Qt Company gives you certain additional
27** rights. These rights are described in The Qt Company LGPL Exception
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29**
30** $QT_END_LICENSE$
31**
32****************************************************************************/
33
34#ifndef QCONTACTMALICIOUSPLUGIN_P_H
35#define QCONTACTMALICIOUSPLUGIN_P_H
36
37//
38// W A R N I N G
39// -------------
40//
41// This file is not part of the Qt API. It exists purely as an
42// implementation detail. This header file may change from version to
43// version without notice, or even be removed.
44//
45// We mean it.
46//
47
48#include <QtContacts/qcontactmanager.h>
49#include <QtContacts/qcontactmanagerengine.h>
50#include <QtContacts/qcontactmanagerenginefactory.h>
51
52#include <QObject>
53#include <QString>
54
55QT_BEGIN_NAMESPACE
56class QThread;
57QT_END_NAMESPACE
58
59QTCONTACTS_USE_NAMESPACE
60
61class MaliciousThreadObject;
62class MaliciousAsyncManagerEngine : public QContactManagerEngine
63{
64 Q_OBJECT
65
66public:
67 MaliciousAsyncManagerEngine();
68 ~MaliciousAsyncManagerEngine();
69
70 QString managerName() const;
71 bool startRequest(QContactAbstractRequest* req);
72 bool cancelRequest(QContactAbstractRequest *req);
73
74 QMap<QString, QString> managerParameters() const {return QMap<QString, QString>();}
75 int managerVersion() const {return 0;}
76
77 QList<QContactId> contactIds(const QContactFilter& filter, const QList<QContactSortOrder>& sort, QContactManager::Error* error) const
78 {
79 return QContactManagerEngine::contactIds(filter, sortOrders: sort, error);
80 }
81
82 QList<QContact> contacts(const QContactFilter& filter, const QList<QContactSortOrder>& sort, const QContactFetchHint& fetch, QContactManager::Error* error) const
83 {
84 return QContactManagerEngine::contacts(filter, sortOrders: sort, fetchHint: fetch, error);
85 }
86
87 QContact contact(const QContactId& id, const QContactFetchHint& fetch, QContactManager::Error* error) const
88 {
89 return QContactManagerEngine::contact(contactId: id, fetchHint: fetch, error);
90 }
91
92 bool saveContacts(QList<QContact>* contacts, QMap<int, QContactManager::Error>* errorMap, QContactManager::Error* error)
93 {
94 return QContactManagerEngine::saveContacts(contacts, errorMap, error);
95 }
96
97 bool removeContacts(const QList<QContactId>& contacts, QMap<int, QContactManager::Error>* errorMap, QContactManager::Error* error)
98 {
99 return QContactManagerEngine::removeContacts(contactIds: contacts, errorMap, error);
100 }
101
102 /* "Self" contact id (MyCard) */
103 bool setSelfContactId(const QContactId& id, QContactManager::Error* error)
104 {
105 return QContactManagerEngine::setSelfContactId(contactId: id, error);
106 }
107
108 QContactId selfContactId(QContactManager::Error* error) const
109 {
110 return QContactManagerEngine::selfContactId(error);
111 }
112
113 /* Relationships between contacts */
114 QList<QContactRelationship> relationships(const QString& relType, const QContactId& contactId, QContactRelationship::Role role, QContactManager::Error* error) const
115 {
116 return QContactManagerEngine::relationships(relationshipType: relType, participantId: contactId, role, error);
117 }
118
119 bool saveRelationships(QList<QContactRelationship>* relationships, QMap<int, QContactManager::Error>* errorMap, QContactManager::Error* error)
120 {
121 return QContactManagerEngine::saveRelationships(relationships, errorMap, error);
122 }
123
124 bool removeRelationships(const QList<QContactRelationship>& relationships, QMap<int, QContactManager::Error>* errorMap, QContactManager::Error* error)
125 {
126 return QContactManagerEngine::removeRelationships(relationships, errorMap, error);
127 }
128
129 /* Contact validation */
130 bool validateContact(const QContact& contact, QContactManager::Error* error) const
131 {
132 return QContactManagerEngine::validateContact(contact, error);
133 }
134
135 /* Asynchronous Request Support */
136 void requestDestroyed(QContactAbstractRequest* req);
137 bool waitForRequestFinished(QContactAbstractRequest* req, int msecs) {return QContactManagerEngine::waitForRequestFinished(req, msecs);}
138
139 bool isRelationshipTypeSupported(const QString& relType, QContactType::TypeValues type) const
140 {
141 return QContactManagerEngine::isRelationshipTypeSupported(relationshipType: relType, contactType: type);
142 }
143
144 bool isFilterSupported(const QContactFilter& fil) const
145 {
146 return QContactManagerEngine::isFilterSupported(filter: fil);
147 }
148
149 QList<QVariant::Type> supportedDataTypes() const
150 {
151 return QContactManagerEngine::supportedDataTypes();
152 }
153 QList<QContactType::TypeValues> supportedContactTypes() const
154 {
155 return QContactManagerEngine::supportedContactTypes();
156 }
157
158signals:
159 void doStartRequest(QContactAbstractRequest *req);
160 void doFinishRequest(QContactAbstractRequest *req);
161private:
162 QThread* thread;
163 MaliciousThreadObject* threadObject;
164};
165
166class MaliciousEngineFactory : public QContactManagerEngineFactory
167{
168 Q_OBJECT
169 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QContactManagerEngineFactoryInterface" FILE "malicious.json")
170
171 public:
172 QContactManagerEngine* engine(const QMap<QString, QString>& parameters, QContactManager::Error* error);
173 QString managerName() const;
174
175 private:
176 MaliciousAsyncManagerEngine mame;
177};
178
179#endif
180
181

source code of qtpim/tests/auto/contacts/qcontactasync/maliciousplugin/maliciousplugin_p.h