~chris.gagnon/+junk/qtpim-coverage

« back to all changes in this revision

Viewing changes to tests/auto/contacts/qcontactmanagerplugins/dummyplugin/dummyplugin.cpp

  • Committer: chris.gagnon
  • Date: 2013-12-10 23:09:37 UTC
  • Revision ID: chris.gagnon@canonical.com-20131210230937-2akf1ft1edcttk87
first post

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the test suite of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:LGPL$
 
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 Digia.  For licensing terms and
 
14
** conditions see http://qt.digia.com/licensing.  For further information
 
15
** use the contact form at http://qt.digia.com/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 as published by the Free Software
 
20
** Foundation and appearing in the file LICENSE.LGPL included in the
 
21
** packaging of this file.  Please review the following information to
 
22
** ensure the GNU Lesser General Public License version 2.1 requirements
 
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
24
**
 
25
** In addition, as a special exception, Digia gives you certain additional
 
26
** rights.  These rights are described in the Digia Qt LGPL Exception
 
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
28
**
 
29
** GNU General Public License Usage
 
30
** Alternatively, this file may be used under the terms of the GNU
 
31
** General Public License version 3.0 as published by the Free Software
 
32
** Foundation and appearing in the file LICENSE.GPL included in the
 
33
** packaging of this file.  Please review the following information to
 
34
** ensure the GNU General Public License version 3.0 requirements will be
 
35
** met: http://www.gnu.org/copyleft/gpl.html.
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
 
 
43
/* We build multiple plugins with the same code, just different names */
 
44
#ifndef DUMMYPLUGINTARGET
 
45
#define DUMMYPLUGINTARGET contacts_testdummy
 
46
#endif
 
47
 
 
48
#define makestr(x) (#x)
 
49
#define makename(x) makestr(x)
 
50
 
 
51
#include "qcontactmanager.h"
 
52
#include "qcontactmanagerengine.h"
 
53
#include "qcontactmanagerenginefactory.h"
 
54
 
 
55
#include "dummyplugin.h"
 
56
 
 
57
QTCONTACTS_USE_NAMESPACE
 
58
 
 
59
QContactManagerEngine* DummyEngineFactory::engine(const QMap<QString, QString>& parameters, QContactManager::Error* error)
 
60
{
 
61
    return new DummyEngine(parameters, error);
 
62
}
 
63
 
 
64
QString DummyEngineFactory::managerName() const
 
65
{
 
66
#ifdef DUMMYPLUGINNAME
 
67
    return QString(makename(DUMMYPLUGINNAME));
 
68
#else
 
69
    return QString();
 
70
#endif
 
71
}
 
72
 
 
73
DummyEngine::DummyEngine(const QMap<QString, QString>& parameters, QContactManager::Error* error)
 
74
{
 
75
    Q_UNUSED(parameters);
 
76
    *error = QContactManager::AlreadyExistsError; // Another random choice
 
77
}
 
78
 
 
79
DummyEngine::DummyEngine(const DummyEngine& other)
 
80
    : QContactManagerEngine()
 
81
{
 
82
    Q_UNUSED(other);
 
83
}
 
84
 
 
85
DummyEngine& DummyEngine::operator=(const DummyEngine& other)
 
86
{
 
87
    Q_UNUSED(other);
 
88
    return *this;
 
89
}
 
90
 
 
91
DummyEngine::~DummyEngine()
 
92
{
 
93
}
 
94
 
 
95
QContactManagerEngine* DummyEngine::clone()
 
96
{
 
97
    // Disallow sharing
 
98
    return new DummyEngine(*this);
 
99
}
 
100
 
 
101
void DummyEngine::deref()
 
102
{
 
103
    delete this;
 
104
}
 
105
 
 
106
QString DummyEngine::managerName() const
 
107
{
 
108
#ifdef DUMMYPLUGINNAME
 
109
    return QString(makename(DUMMYPLUGINNAME));
 
110
#else
 
111
    return QString();
 
112
#endif
 
113
}
 
114
 
 
115
QList<QContactId> DummyEngine::contacts(QContactManager::Error* error) const
 
116
{
 
117
    QList<QContactId> allCIds;
 
118
 
 
119
    if (allCIds.count() > 0 && *error == QContactManager::NoError)
 
120
        *error = QContactManager::DoesNotExistError;
 
121
 
 
122
    return allCIds;
 
123
}
 
124
 
 
125
QContact DummyEngine::contact(const QContactId& contactId, QContactManager::Error* error) const
 
126
{
 
127
    Q_UNUSED(contactId);
 
128
    *error = QContactManager::DoesNotExistError;
 
129
    return QContact();
 
130
}
 
131
 
 
132
QContact DummyEngine::contact(const QContactId& contactId, const QContactFetchHint& fetchHint, QContactManager::Error* error) const
 
133
{
 
134
    Q_UNUSED(contactId);
 
135
    Q_UNUSED(fetchHint);
 
136
    *error = QContactManager::DoesNotExistError;
 
137
    return QContact();
 
138
}
 
139
 
 
140
bool DummyEngine::saveContact(QContact* contact, bool batch, QContactManager::Error* error)
 
141
{
 
142
    // ensure that the contact's details conform to their definitions
 
143
    if (!validateContact(*contact, error)) {
 
144
        *error = QContactManager::InvalidDetailError;
 
145
        return false;
 
146
    }
 
147
 
 
148
    // success!
 
149
    QContactId newId;
 
150
    contact->setId(newId);
 
151
    *error = QContactManager::NoError;
 
152
 
 
153
    // if we need to emit signals (ie, this isn't part of a batch operation)
 
154
    // then emit the correct one.
 
155
    if (!batch) {
 
156
        QList<QContactId> emitList;
 
157
        emitList.append(contact->id());
 
158
        emit contactsAdded(emitList);
 
159
    }
 
160
 
 
161
    return true;
 
162
}
 
163
 
 
164
bool DummyEngine::removeContact(const QContactId& contactId, bool batch, QContactManager::Error* error)
 
165
{
 
166
    /* TODO: fix this
 
167
    if (contactId != "5") {
 
168
        *error = QContactManager::DoesNotExistError;
 
169
        return false;
 
170
    }*/
 
171
 
 
172
    *error = QContactManager::NoError;
 
173
 
 
174
    // if we need to emit signals (ie, this isn't part of a batch operation)
 
175
    // then emit the correct one.
 
176
    if (!batch) {
 
177
        QList<QContactId> emitList;
 
178
        emitList.append(contactId);
 
179
        emit contactsRemoved(emitList);
 
180
    }
 
181
 
 
182
    return true;
 
183
}
 
184
 
 
185
/*! Returns the capabilities of the in-memory engine. */
 
186
QStringList DummyEngine::capabilities() const
 
187
{
 
188
    QStringList caplist;
 
189
    caplist << "Locking" << "Batch" << "ReadOnly" << "Filtering" << "Sorting" << "Preferences";
 
190
    // ie, doesn't support: Changelog, Volatile, Asynchronous.
 
191
    return caplist;
 
192
}
 
193
 
 
194
/*!
 
195
 * Returns a list of definition identifiers which are natively (fast) filterable
 
196
 * on the default backend store managed by the manager from which the capabilities object was accessed
 
197
 */
 
198
QStringList DummyEngine::fastFilterableDefinitions() const
 
199
{
 
200
    QStringList fastlist;
 
201
    fastlist << "Name::First" << "Name::Last" << "PhoneNumber::PhoneNumber" << "EmailAddress::EmailAddress";
 
202
    return fastlist;
 
203
}
 
204
 
 
205
/*!
 
206
 * Returns the list of data types supported by the vCard engine
 
207
 */
 
208
QList<QVariant::Type> DummyEngine::supportedDataTypes() const
 
209
{
 
210
    QList<QVariant::Type> st;
 
211
    st.append(QVariant::String);
 
212
    st.append(QVariant::Date);
 
213
    st.append(QVariant::DateTime);
 
214
 
 
215
    return st;
 
216
}
 
217
 
 
218
QContactEngineId* DummyEngineFactory::createContactEngineId(const QMap<QString, QString>& parameters, const QString& engineIdString) const
 
219
{
 
220
   return 0;
 
221
}
 
222
 
 
223
#include "moc_dummyplugin.cpp"