Merge lp:~renatofilho/address-book-service/dummy-mode into lp:address-book-service

Proposed by Renato Araujo Oliveira Filho
Status: Superseded
Proposed branch: lp:~renatofilho/address-book-service/dummy-mode
Merge into: lp:address-book-service
Diff against target: 2155 lines (+1105/-550)
27 files modified
3rd_party/folks/dummy/backend/CMakeLists.txt (+2/-0)
3rd_party/folks/dummy/backend/dummy-backend-factory.vala (+38/-1)
README.test (+31/-0)
common/dbus-service-defs.h (+1/-0)
debian/address-book-service-dummy.install (+1/-0)
debian/address-book-service.install (+1/-1)
debian/control (+9/-0)
lib/addressbook.cpp (+11/-5)
lib/addressbook.h (+5/-1)
qcontacts/CMakeLists.txt (+12/-4)
qcontacts/contacts-service.cpp (+135/-158)
qcontacts/contacts-service.h (+18/-11)
qcontacts/qcontactfetchbyidrequest-data.cpp (+55/-0)
qcontacts/qcontactfetchbyidrequest-data.h (+46/-0)
qcontacts/qcontactfetchrequest-data.cpp (+118/-0)
qcontacts/qcontactfetchrequest-data.h (+82/-0)
qcontacts/qcontactremoverequest-data.cpp (+61/-0)
qcontacts/qcontactremoverequest-data.h (+49/-0)
qcontacts/qcontactrequest-data.cpp (+117/-0)
qcontacts/qcontactrequest-data.h (+81/-0)
qcontacts/qcontactsaverequest-data.cpp (+146/-0)
qcontacts/qcontactsaverequest-data.h (+72/-0)
qcontacts/request-data.cpp (+0/-236)
qcontacts/request-data.h (+0/-100)
tests/unittest/base-client-test.cpp (+9/-1)
tests/unittest/dummy-backend.cpp (+5/-31)
tests/unittest/dummy-backend.h (+0/-1)
To merge this branch: bzr merge lp:~renatofilho/address-book-service/dummy-mode
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Omer Akram (community) Needs Fixing
Review via email: mp+208459@code.launchpad.net

This proposal has been superseded by a proposal from 2014-03-17.

Commit message

Allow change the service name using env var "CANONICAL_PIN_SERVICE_NAME";

This is necessary for test purpose.

Description of the change

Running the address-book-service and qtcontacts in dummy mode.

Running address-book-service
===========================

# export CANONICAL_PIN_SERVICE_NAME="com.canonical.test.pim"
# export FOLKS_BACKEND_PATH="/usr/lib/address-book-service/dummy.so"
# export FOLKS_BACKENDS_ALLOWED="dummy"
# export FOLKS_PRIMARY_STORE="dummy"
# /usr/libexec/address-book-service

CANONICAL_PIN_SERVICE_NAME
 - Defines a new address book DBus service name

FOLKS_BACKEND_PATH
 - Defines the path used by folks to find the backend

FOLKS_BACKENDS_ALLOWED
 - Defines which backend folks is allowed to load

FOLKS_PRIMARY_STORE
 - Defines which persona store should be used as primary store

Running any address-book client
===============================

# export CANONICAL_PIN_SERVICE_NAME="com.canonical.test.pim"

CANONICAL_PIN_SERVICE_NAME
 - Defines a new address book DBus service name, should be the same as the server

To post a comment you must log in.
101. By Renato Araujo Oliveira Filho

Created README.test with instructions of how to run the server in dummy mode.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
102. By Renato Araujo Oliveira Filho

Fixed install file for dummy backend.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
103. By Renato Araujo Oliveira Filho

Merged mainline.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Allan LeSage (allanlesage) wrote :

renato this test failure appears legitimate, I'm witnessing on my device too--have you looked into?

104. By Renato Araujo Oliveira Filho

Keep URLS as read-only fields on dummy backend, for testing purpose

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Omer Akram (om26er) wrote :

one tests failed for me

om26er@chaotic:~/code/canonical/qa/address-book-work/dummy-mode$ ctest
Test project /home/om26er/code/canonical/qa/address-book-work/dummy-mode
    Start 1: clause-test
1/8 Test #1: clause-test ...................... Passed 0.01 sec
    Start 2: sort-clause-test
2/8 Test #2: sort-clause-test ................. Passed 0.01 sec
    Start 3: fetch-hint-test
3/8 Test #3: fetch-hint-test .................. Passed 0.00 sec
    Start 4: contactmap-test
4/8 Test #4: contactmap-test .................. Passed 0.03 sec
    Start 5: addressbook-test
5/8 Test #5: addressbook-test ................. Passed 2.70 sec
    Start 6: service-life-cycle-test
6/8 Test #6: service-life-cycle-test ..........***Failed 0.24 sec
    Start 7: readonly-prop-test
7/8 Test #7: readonly-prop-test ............... Passed 0.08 sec
    Start 8: contact-link-test
8/8 Test #8: contact-link-test ................ Passed 0.10 sec

88% tests passed, 1 tests failed out of 8

Total Test time (real) = 3.19 sec

The following tests FAILED:
   6 - service-life-cycle-test (Failed)
Errors while running CTest

Revision history for this message
Omer Akram (om26er) wrote :

So I think I have found a bug. When I start address-book-service as documented by you I still never see com.canonical.test.pim interface and address-book-service still have com.canonical.pim -- note I don't have any existing running address-book-service to begin with.

Revision history for this message
Omer Akram (om26er) :
review: Needs Fixing
105. By Renato Araujo Oliveira Filho

Updated README.test with the correct variable name.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
106. By Renato Araujo Oliveira Filho

Removed folks dummy plugin from the main service package.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
107. By Renato Araujo Oliveira Filho

Added back address-book-service binary on install file.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
108. By Renato Araujo Oliveira Filho

Merged lp:~renatofilho/address-book-service/add-multiple-contacts

109. By Renato Araujo Oliveira Filho

Merged parent "lp:~renatofilho/address-book-service/add-multiple-contacts"

110. By Renato Araujo Oliveira Filho

Merged "lp:~renatofilho/address-book-service/add-multiple-contacts"

111. By Renato Araujo Oliveira Filho

Merged parent branch: lp:~renatofilho/address-book-service/add-multiple-contacts

112. By Renato Araujo Oliveira Filho

Added support for preload data during the server startup: ADDRESS_BOOK_SERVICE_DEMO_DATA

113. By Renato Araujo Oliveira Filho

Merged parent branch.

114. By Renato Araujo Oliveira Filho

Removed use of old macro.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '3rd_party/folks/dummy/backend/CMakeLists.txt'
2--- 3rd_party/folks/dummy/backend/CMakeLists.txt 2013-10-29 16:29:27 +0000
3+++ 3rd_party/folks/dummy/backend/CMakeLists.txt 2014-03-17 16:52:27 +0000
4@@ -39,5 +39,7 @@
5 ${FOLKS_LIBRARIES}
6 )
7
8+install(TARGETS dummy LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/address-book-service/)
9+
10
11
12
13=== modified file '3rd_party/folks/dummy/backend/dummy-backend-factory.vala'
14--- 3rd_party/folks/dummy/backend/dummy-backend-factory.vala 2013-11-11 14:21:24 +0000
15+++ 3rd_party/folks/dummy/backend/dummy-backend-factory.vala 2014-03-17 16:52:27 +0000
16@@ -25,6 +25,7 @@
17 */
18
19 using Folks;
20+using Gee;
21
22 /**
23 * The dummy backend module entry point.
24@@ -34,7 +35,43 @@
25 */
26 public void module_init (BackendStore backend_store)
27 {
28- backend_store.add_backend (new FolksDummy.Backend ());
29+ string[] writable_properties =
30+ {
31+ Folks.PersonaStore.detail_key (PersonaDetail.AVATAR),
32+ Folks.PersonaStore.detail_key (PersonaDetail.BIRTHDAY),
33+ Folks.PersonaStore.detail_key (PersonaDetail.EMAIL_ADDRESSES),
34+ Folks.PersonaStore.detail_key (PersonaDetail.FULL_NAME),
35+ Folks.PersonaStore.detail_key (PersonaDetail.GENDER),
36+ Folks.PersonaStore.detail_key (PersonaDetail.IM_ADDRESSES),
37+ Folks.PersonaStore.detail_key (PersonaDetail.IS_FAVOURITE),
38+ Folks.PersonaStore.detail_key (PersonaDetail.NICKNAME),
39+ Folks.PersonaStore.detail_key (PersonaDetail.PHONE_NUMBERS),
40+ Folks.PersonaStore.detail_key (PersonaDetail.POSTAL_ADDRESSES),
41+ Folks.PersonaStore.detail_key (PersonaDetail.ROLES),
42+ Folks.PersonaStore.detail_key (PersonaDetail.STRUCTURED_NAME),
43+ Folks.PersonaStore.detail_key (PersonaDetail.LOCAL_IDS),
44+ Folks.PersonaStore.detail_key (PersonaDetail.LOCATION),
45+ Folks.PersonaStore.detail_key (PersonaDetail.WEB_SERVICE_ADDRESSES),
46+ Folks.PersonaStore.detail_key (PersonaDetail.NOTES),
47+ // Keep URLS as read-only fields for testing purpose
48+ //Folks.PersonaStore.detail_key (PersonaDetail.URLS),
49+ Folks.PersonaStore.detail_key (PersonaDetail.GROUPS),
50+ null
51+ };
52+
53+ /* Create a new persona store. */
54+ var dummy_persona_store =
55+ new FolksDummy.PersonaStore ("dummy-store", "Dummy personas", writable_properties);
56+ dummy_persona_store.persona_type = typeof (FolksDummy.FullPersona);
57+
58+ /* Register it with the backend. */
59+ var persona_stores = new HashSet<PersonaStore> ();
60+ persona_stores.add (dummy_persona_store);
61+
62+ var backend = new FolksDummy.Backend ();
63+ backend.register_persona_stores (persona_stores);
64+ dummy_persona_store.reach_quiescence();
65+ backend_store.add_backend (backend);
66 }
67
68 /**
69
70=== added file 'README.test'
71--- README.test 1970-01-01 00:00:00 +0000
72+++ README.test 2014-03-17 16:52:27 +0000
73@@ -0,0 +1,31 @@
74+Running the address-book-service and qtcontacts in dummy mode.
75+
76+Running address-book-service
77+===========================
78+
79+# export CANONICAL_PIN_SERVICE_NAME="com.canonical.test.pim"
80+# export FOLKS_BACKEND_PATH="/usr/lib/address-book-service/dummy.so"
81+# export FOLKS_BACKENDS_ALLOWED="dummy"
82+# export FOLKS_PRIMARY_STORE="dummy"
83+# /usr/libexec/address-book-service
84+
85+CANONICAL_PIN_SERVICE_NAME
86+ - Defines a new address book DBus service name
87+
88+FOLKS_BACKEND_PATH
89+ - Defines the path used by folks to find the backend
90+
91+FOLKS_BACKENDS_ALLOWED
92+ - Defines which backend folks is allowed to load
93+
94+FOLKS_PRIMARY_STORE
95+ - Defines which persona store should be used as primary store
96+
97+Running any address-book client
98+===============================
99+
100+# export CANONICAL_PIN_SERVICE_NAME="com.canonical.test.pim"
101+
102+CANONICAL_PIN_SERVICE_NAME
103+ - Defines a new address book DBus service name, should be the same as the server
104+
105
106=== modified file 'common/dbus-service-defs.h'
107--- common/dbus-service-defs.h 2013-06-07 18:54:26 +0000
108+++ common/dbus-service-defs.h 2014-03-17 16:52:27 +0000
109@@ -19,6 +19,7 @@
110 #ifndef __DBUS_SERVICE_DEFS_H__
111 #define __DBUS_SERVICE_DEFS_H__
112
113+#define ALTERNATIVE_CPIM_SERVICE_NAME "CANONICAL_PIN_SERVICE_NAME"
114 #define CPIM_SERVICE_NAME "com.canonical.pim"
115 #define CPIM_ADDRESSBOOK_OBJECT_PATH "/com/canonical/pim/AddressBook"
116 #define CPIM_ADDRESSBOOK_IFACE_NAME "com.canonical.pim.AddressBook"
117
118=== added file 'debian/address-book-service-dummy.install'
119--- debian/address-book-service-dummy.install 1970-01-01 00:00:00 +0000
120+++ debian/address-book-service-dummy.install 2014-03-17 16:52:27 +0000
121@@ -0,0 +1,1 @@
122+usr/lib/*/address-book-service/dummy.so
123
124=== modified file 'debian/address-book-service.install'
125--- debian/address-book-service.install 2013-07-17 20:53:00 +0000
126+++ debian/address-book-service.install 2014-03-17 16:52:27 +0000
127@@ -1,3 +1,3 @@
128-usr/lib/*/address-book-service/*
129+usr/lib/*/address-book-service/address-book-service
130 usr/share/dbus-1/services/com.canonical.pim.service
131 upstart/address-book-service.conf /usr/share/upstart/sessions
132
133=== modified file 'debian/control'
134--- debian/control 2013-10-30 00:19:00 +0000
135+++ debian/control 2014-03-17 16:52:27 +0000
136@@ -28,6 +28,15 @@
137 Description: Ubuntu contact service
138 A contact aggregator service, that exports all contact information through dbus.
139
140+Package: address-book-service-dummy
141+Architecture: any
142+Multi-Arch: same
143+Depends: ${misc:Depends},
144+ ${shlibs:Depends},
145+Description: A fork of folks dummy backend
146+ A fork of folks dummy backend to be used as standalone backend to test address-book-service.
147+
148+
149 Package: qtcontact5-galera
150 Architecture: any
151 Multi-Arch: same
152
153=== modified file 'lib/addressbook.cpp'
154--- lib/addressbook.cpp 2014-02-24 12:21:08 +0000
155+++ lib/addressbook.cpp 2014-03-17 16:52:27 +0000
156@@ -117,6 +117,12 @@
157 m_notifyIsQuiescentHandlerId(0),
158 m_connection(QDBusConnection::sessionBus())
159 {
160+ if (qEnvironmentVariableIsSet(ALTERNATIVE_CPIM_SERVICE_NAME)) {
161+ m_serviceName = qgetenv(ALTERNATIVE_CPIM_SERVICE_NAME);
162+ qDebug() << "Using alternative service name:" << m_serviceName;
163+ } else {
164+ m_serviceName = CPIM_SERVICE_NAME;
165+ }
166 prepareUnixSignals();
167 }
168
169@@ -137,11 +143,11 @@
170
171 bool AddressBook::registerObject(QDBusConnection &connection)
172 {
173- if (connection.interface()->isServiceRegistered(CPIM_SERVICE_NAME)) {
174+ if (connection.interface()->isServiceRegistered(m_serviceName)) {
175 qWarning() << "Galera pin service already registered";
176 return false;
177- } else if (!connection.registerService(CPIM_SERVICE_NAME)) {
178- qWarning() << "Could not register service!" << CPIM_SERVICE_NAME;
179+ } else if (!connection.registerService(m_serviceName)) {
180+ qWarning() << "Could not register service!" << m_serviceName;
181 return false;
182 }
183
184@@ -204,8 +210,8 @@
185 m_connection.interface()->isValid()) {
186
187 m_connection.unregisterObject(objectPath());
188- if (m_connection.interface()->isServiceRegistered(CPIM_SERVICE_NAME)) {
189- m_connection.unregisterService(CPIM_SERVICE_NAME);
190+ if (m_connection.interface()->isServiceRegistered(m_serviceName)) {
191+ m_connection.unregisterService(m_serviceName);
192 }
193 }
194
195
196=== modified file 'lib/addressbook.h'
197--- lib/addressbook.h 2014-02-09 00:22:52 +0000
198+++ lib/addressbook.h 2014-03-17 16:52:27 +0000
199@@ -102,8 +102,12 @@
200
201 // Unix signals
202 static int m_sigQuitFd[2];
203-
204 QSocketNotifier *m_snQuit;
205+
206+ // dbus service name
207+ QString m_serviceName;
208+
209+
210 // Disable copy contructor
211 AddressBook(const AddressBook&);
212
213
214=== modified file 'qcontacts/CMakeLists.txt'
215--- qcontacts/CMakeLists.txt 2013-06-12 22:41:11 +0000
216+++ qcontacts/CMakeLists.txt 2014-03-17 16:52:27 +0000
217@@ -2,19 +2,27 @@
218
219 set(QCONTACTS_BACKEND_SRCS
220 qcontact-backend.cpp
221- qcontact-engineid.cpp
222+ qcontact-engineid.cpp
223+ qcontactfetchrequest-data.cpp
224+ qcontactfetchbyidrequest-data.cpp
225+ qcontactremoverequest-data.cpp
226+ qcontactrequest-data.cpp
227+ qcontactsaverequest-data.cpp
228 contacts-service.cpp
229- request-data.cpp
230 )
231
232 set(QCONTACTS_BACKEND_HDRS
233 qcontact-backend.h
234 qcontact-engineid.h
235+ qcontactfetchrequest-data.h
236+ qcontactfetchbyidrequest-data.h
237+ qcontactremoverequest-data.h
238+ qcontactrequest-data.h
239+ qcontactsaverequest-data.h
240 contacts-service.h
241- request-data.h
242 )
243
244-add_library(${QCONTACTS_BACKEND} MODULE
245+add_library(${QCONTACTS_BACKEND} SHARED
246 ${QCONTACTS_BACKEND_SRCS}
247 ${QCONTACTS_BACKEND_HDRS}
248 )
249
250=== modified file 'qcontacts/contacts-service.cpp'
251--- qcontacts/contacts-service.cpp 2014-02-27 02:20:32 +0000
252+++ qcontacts/contacts-service.cpp 2014-03-17 16:52:27 +0000
253@@ -18,7 +18,11 @@
254
255 #include "contacts-service.h"
256 #include "qcontact-engineid.h"
257-#include "request-data.h"
258+#include "qcontactrequest-data.h"
259+#include "qcontactfetchrequest-data.h"
260+#include "qcontactfetchbyidrequest-data.h"
261+#include "qcontactremoverequest-data.h"
262+#include "qcontactsaverequest-data.h"
263
264 #include "common/vcard-parser.h"
265 #include "common/filter.h"
266@@ -34,6 +38,7 @@
267 #include <QtDBus/QDBusPendingReply>
268 #include <QtDBus/QDBusConnectionInterface>
269
270+#include <QtContacts/QContact>
271 #include <QtContacts/QContactChangeSet>
272 #include <QtContacts/QContactName>
273 #include <QtContacts/QContactPhoneNumber>
274@@ -58,9 +63,13 @@
275 m_serviceIsReady(false),
276 m_iface(0)
277 {
278- RequestData::registerMetaType();
279+ if (qEnvironmentVariableIsSet(ALTERNATIVE_CPIM_SERVICE_NAME)) {
280+ m_serviceName = qgetenv(ALTERNATIVE_CPIM_SERVICE_NAME);
281+ } else {
282+ m_serviceName = CPIM_SERVICE_NAME;
283+ }
284
285- m_serviceWatcher = new QDBusServiceWatcher(CPIM_SERVICE_NAME,
286+ m_serviceWatcher = new QDBusServiceWatcher(m_serviceName,
287 QDBusConnection::sessionBus(),
288 QDBusServiceWatcher::WatchForOwnerChange,
289 this);
290@@ -94,7 +103,7 @@
291 void GaleraContactsService::serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner)
292 {
293 Q_UNUSED(oldOwner);
294- if (name == CPIM_SERVICE_NAME) {
295+ if (name == m_serviceName) {
296 if (!newOwner.isEmpty()) {
297 // service appear
298 initialize();
299@@ -119,7 +128,7 @@
300 void GaleraContactsService::initialize()
301 {
302 if (m_iface.isNull()) {
303- m_iface = QSharedPointer<QDBusInterface>(new QDBusInterface(CPIM_SERVICE_NAME,
304+ m_iface = QSharedPointer<QDBusInterface>(new QDBusInterface(m_serviceName,
305 CPIM_ADDRESSBOOK_OBJECT_PATH,
306 CPIM_ADDRESSBOOK_IFACE_NAME));
307 if (!m_iface->lastError().isValid()) {
308@@ -137,10 +146,10 @@
309
310 void GaleraContactsService::deinitialize()
311 {
312- Q_FOREACH(RequestData* rData, m_runningRequests) {
313+ Q_FOREACH(QContactRequestData* rData, m_runningRequests) {
314 rData->cancel();
315 rData->request()->waitForFinished();
316- rData->setError(QContactManager::UnspecifiedError);
317+ rData->finish(QContactManager::UnspecifiedError);
318 }
319
320 if (!m_iface.isNull()) {
321@@ -167,7 +176,7 @@
322 {
323 if (!isOnline()) {
324 qWarning() << "Server is not online";
325- RequestData::setError(request);
326+ QContactFetchByIdRequestData::notifyError(request);
327 return;
328 }
329
330@@ -177,26 +186,28 @@
331 QDBusMessage result = m_iface->call("query", filterStr, "", QStringList());
332 if (result.type() == QDBusMessage::ErrorMessage) {
333 qWarning() << result.errorName() << result.errorMessage();
334- RequestData::setError(request);
335+ QContactFetchByIdRequestData::notifyError(request);
336 return;
337 }
338+
339 QDBusObjectPath viewObjectPath = result.arguments()[0].value<QDBusObjectPath>();
340- QDBusInterface *view = new QDBusInterface(CPIM_SERVICE_NAME,
341+ QDBusInterface *view = new QDBusInterface(m_serviceName,
342 viewObjectPath.path(),
343 CPIM_ADDRESSBOOK_VIEW_IFACE_NAME);
344
345- RequestData *requestData = new RequestData(request, view, FetchHint());
346- m_runningRequests << requestData;
347- QMetaObject::invokeMethod(this, "fetchContactsPage", Qt::QueuedConnection, Q_ARG(galera::RequestData*, requestData));
348+ QContactFetchByIdRequestData *data = new QContactFetchByIdRequestData(request, view);
349+ m_runningRequests << data;
350+ fetchContactsPage(data);
351 }
352
353 void GaleraContactsService::fetchContacts(QtContacts::QContactFetchRequest *request)
354 {
355 if (!isOnline()) {
356 qWarning() << "Server is not online";
357- RequestData::setError(request);
358+ QContactFetchRequestData::notifyError(request);
359 return;
360 }
361+
362 QString sortStr = SortClause(request->sorting()).toString();
363 QString filterStr = Filter(request->filter()).toString();
364 FetchHint fetchHint = FetchHint(request->fetchHint()).toString();
365@@ -204,26 +215,27 @@
366 QDBusPendingCall pcall = m_iface->asyncCall("query", filterStr, sortStr, QStringList());
367 if (pcall.isError()) {
368 qWarning() << pcall.error().name() << pcall.error().message();
369- RequestData::setError(request);
370+ QContactFetchRequestData::notifyError(request);
371 return;
372 }
373
374- RequestData *requestData = new RequestData(request, 0, fetchHint);
375- m_runningRequests << requestData;
376+ QContactFetchRequestData *data = new QContactFetchRequestData(request, 0, fetchHint);
377+ m_runningRequests << data;
378
379 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, 0);
380+ data->updateWatcher(watcher);
381 QObject::connect(watcher, &QDBusPendingCallWatcher::finished,
382 [=](QDBusPendingCallWatcher *call) {
383- this->fetchContactsContinue(requestData, call);
384+ this->fetchContactsContinue(data, call);
385 });
386 }
387
388
389-void GaleraContactsService::fetchContactsContinue(RequestData *request,
390+void GaleraContactsService::fetchContactsContinue(QContactFetchRequestData *data,
391 QDBusPendingCallWatcher *call)
392 {
393- if (!request->isLive()) {
394- destroyRequest(request);
395+ if (!data->isLive()) {
396+ destroyRequest(data);
397 return;
398 }
399
400@@ -231,47 +243,51 @@
401
402 if (reply.isError()) {
403 qWarning() << reply.error().name() << reply.error().message();
404- destroyRequest(request);
405+ destroyRequest(data);
406 } else {
407 QDBusObjectPath viewObjectPath = reply.value();
408- QDBusInterface *view = new QDBusInterface(CPIM_SERVICE_NAME,
409+ QDBusInterface *view = new QDBusInterface(m_serviceName,
410 viewObjectPath.path(),
411 CPIM_ADDRESSBOOK_VIEW_IFACE_NAME);
412- request->updateView(view);
413- QMetaObject::invokeMethod(this, "fetchContactsPage", Qt::QueuedConnection, Q_ARG(galera::RequestData*, request));
414+ data->updateView(view);
415+ fetchContactsPage(data);
416 }
417 }
418
419-void GaleraContactsService::fetchContactsPage(RequestData *request)
420+void GaleraContactsService::fetchContactsPage(QContactFetchRequestData *data)
421 {
422- if (!isOnline() || !request->isLive()) {
423+ if (!isOnline() || !data->isLive()) {
424 qWarning() << "Server is not online";
425- destroyRequest(request);
426+ destroyRequest(data);
427 return;
428 }
429
430 // Load contacs async
431- QDBusPendingCall pcall = request->view()->asyncCall("contactsDetails", request->fields(), request->offset(), FETCH_PAGE_SIZE);
432+ QDBusPendingCall pcall = data->view()->asyncCall("contactsDetails",
433+ data->fields(),
434+ data->offset(),
435+ FETCH_PAGE_SIZE);
436 if (pcall.isError()) {
437 qWarning() << pcall.error().name() << pcall.error().message();
438- request->setError(QContactManager::UnspecifiedError);
439- destroyRequest(request);
440+ data->finish(QContactManager::UnspecifiedError);
441+ destroyRequest(data);
442 return;
443 }
444
445 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, 0);
446 QObject::connect(watcher, &QDBusPendingCallWatcher::finished,
447 [=](QDBusPendingCallWatcher *call) {
448- this->fetchContactsDone(request, call);
449+ this->fetchContactsDone(data, call);
450 });
451
452- request->updateWatcher(watcher);
453+ data->updateWatcher(watcher);
454 }
455
456-void GaleraContactsService::fetchContactsDone(RequestData *request, QDBusPendingCallWatcher *call)
457+void GaleraContactsService::fetchContactsDone(QContactFetchRequestData *data,
458+ QDBusPendingCallWatcher *call)
459 {
460- if (!request->isLive()) {
461- destroyRequest(request);
462+ if (!data->isLive()) {
463+ destroyRequest(data);
464 return;
465 }
466
467@@ -316,187 +332,155 @@
468 }
469 }
470
471- request->update(contacts, opState, opError);
472+ data->update(contacts, opState, opError);
473
474 if (opState == QContactAbstractRequest::ActiveState) {
475- request->updateOffset(FETCH_PAGE_SIZE);
476- request->updateWatcher(0);
477-
478- QMetaObject::invokeMethod(this, "fetchContactsPage", Qt::QueuedConnection, Q_ARG(galera::RequestData*, request));
479+ data->updateOffset(FETCH_PAGE_SIZE);
480+ data->updateWatcher(0);
481+ fetchContactsPage(data);
482 } else {
483- destroyRequest(request);
484+ destroyRequest(data);
485 }
486 }
487
488 void GaleraContactsService::saveContact(QtContacts::QContactSaveRequest *request)
489 {
490- QList<QContact> contacts = request->contacts();
491- QStringList vcards = VCardParser::contactToVcard(contacts);
492-
493- if (vcards.size() != contacts.size()) {
494- qWarning() << "Fail to convert contacts";
495- return;
496- }
497-
498- QStringList oldContacts;
499- QStringList newContacts;
500-
501- for(int i=0, iMax=contacts.size(); i < iMax; i++) {
502- if (contacts.at(i).id().isNull()) {
503- newContacts << vcards[i];
504- } else {
505- oldContacts << vcards[i];
506- }
507- }
508-
509- if (!oldContacts.isEmpty()) {
510- updateContacts(request, oldContacts);
511- }
512-
513- if (!newContacts.isEmpty()) {
514- createContacts(request, newContacts);
515- }
516-}
517-void GaleraContactsService::createContacts(QtContacts::QContactSaveRequest *request, QStringList &contacts)
518-{
519- if (!isOnline()) {
520- qWarning() << "Server is not online";
521- RequestData::setError(request);
522- return;
523- }
524-
525- if (contacts.count() > 1) {
526- qWarning() << "TODO: implement contact creation support to more then one contact.";
527- return;
528- }
529-
530- Q_FOREACH(QString contact, contacts) {
531- QDBusPendingCall pcall = m_iface->asyncCall("createContact", contact, "");
532- QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, 0);
533- RequestData *requestData = new RequestData(request, watcher);
534- m_runningRequests << requestData;
535- QObject::connect(watcher, &QDBusPendingCallWatcher::finished,
536- [=](QDBusPendingCallWatcher *call) {
537- this->createContactsDone(requestData, call);
538- });
539-
540- }
541-}
542-
543-void GaleraContactsService::createContactsDone(RequestData *request, QDBusPendingCallWatcher *call)
544-{
545- if (!request->isLive()) {
546- destroyRequest(request);
547+ QContactSaveRequestData *data = new QContactSaveRequestData(request);
548+ m_runningRequests << data;
549+
550+ // firts create the new contacts
551+ data->prepareToCreate();
552+ createContactsStart(data);
553+}
554+
555+void GaleraContactsService::createContactsStart(QContactSaveRequestData *data)
556+{
557+ if (!data->isLive()) {
558+ data->finish(QContactManager::UnspecifiedError);
559+ destroyRequest(data);
560+ return;
561+ }
562+
563+ if(!data->hasNext()) {
564+ // go to update contacts
565+ data->prepareToUpdate();
566+ updateContacts(data);
567+ return;
568+ }
569+
570+ QString contact = data->nextContact();
571+
572+ QDBusPendingCall pcall = m_iface->asyncCall("createContact", contact, "");
573+ QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, 0);
574+ data->updateWatcher(watcher);
575+ QObject::connect(watcher, &QDBusPendingCallWatcher::finished,
576+ [=](QDBusPendingCallWatcher *call) {
577+ this->createContactsDone(data, call);
578+ });
579+
580+}
581+
582+void GaleraContactsService::createContactsDone(QContactSaveRequestData *data,
583+ QDBusPendingCallWatcher *call)
584+{
585+ if (!data->isLive()) {
586+ data->finish(QContactManager::UnspecifiedError);
587+ destroyRequest(data);
588 return;
589 }
590
591 QDBusPendingReply<QString> reply = *call;
592- QList<QContact> contacts;
593- QContactManager::Error opError = QContactManager::NoError;
594-
595 if (reply.isError()) {
596 qWarning() << reply.error().name() << reply.error().message();
597- opError = QContactManager::UnspecifiedError;
598+ data->notifyUpdateError(QContactManager::UnspecifiedError);
599 } else {
600 const QString id = reply.value();
601 if (!id.isEmpty()) {
602- contacts = static_cast<QtContacts::QContactSaveRequest *>(request->request())->contacts();
603 GaleraEngineId *engineId = new GaleraEngineId(id, m_managerUri);
604- QContactId contactId(engineId);
605- contacts[0].setId(QContactId(contactId));
606+ data->updateCurrentContactId(engineId);
607 } else {
608- opError = QContactManager::UnspecifiedError;
609+ data->notifyUpdateError(QContactManager::UnspecifiedError);
610 }
611 }
612
613- request->update(contacts, QContactAbstractRequest::FinishedState, opError);
614- destroyRequest(request);
615+ // go to next contact
616+ createContactsStart(data);
617 }
618
619 void GaleraContactsService::removeContact(QContactRemoveRequest *request)
620 {
621 if (!isOnline()) {
622 qWarning() << "Server is not online";
623- RequestData::setError(request);
624+ QContactRemoveRequestData::notifyError(request);
625 return;
626 }
627
628- QStringList ids;
629-
630- Q_FOREACH(QContactId contactId, request->contactIds()) {
631- // TODO: find a better way to get the contactId
632- ids << contactId.toString().split(":").last();
633- }
634-
635- QDBusPendingCall pcall = m_iface->asyncCall("removeContacts", ids);
636+ QContactRemoveRequestData *data = new QContactRemoveRequestData(request);
637+ m_runningRequests << data;
638+
639+ QDBusPendingCall pcall = m_iface->asyncCall("removeContacts", data->pendingIds());
640 if (pcall.isError()) {
641 qWarning() << "Error" << pcall.error().name() << pcall.error().message();
642- RequestData::setError(request);
643+ data->finish(QContactManager::UnspecifiedError);
644+ destroyRequest(data);
645 } else {
646 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, 0);
647- RequestData *requestData = new RequestData(request, watcher);
648- m_runningRequests << requestData;
649+ data->updateWatcher(watcher);
650 QObject::connect(watcher, &QDBusPendingCallWatcher::finished,
651 [=](QDBusPendingCallWatcher *call) {
652- this->removeContactDone(requestData, call);
653+ this->removeContactDone(data, call);
654 });
655 }
656 }
657
658-void GaleraContactsService::removeContactDone(RequestData *request, QDBusPendingCallWatcher *call)
659+void GaleraContactsService::removeContactDone(QContactRemoveRequestData *data, QDBusPendingCallWatcher *call)
660 {
661- if (!request->isLive()) {
662- destroyRequest(request);
663+ if (!data->isLive()) {
664+ destroyRequest(data);
665 return;
666 }
667
668 QDBusPendingReply<int> reply = *call;
669- QContactManager::Error opError = QContactManager::NoError;
670- QMap<int, QContactManager::Error> errorMap;
671-
672 if (reply.isError()) {
673 qWarning() << reply.error().name() << reply.error().message();
674- opError = QContactManager::UnspecifiedError;
675+ data->finish(QContactManager::UnspecifiedError);
676+ } else {
677+ data->finish();
678 }
679-
680- request->update(QContactAbstractRequest::FinishedState, opError);
681- destroyRequest(request);
682+ destroyRequest(data);
683 }
684
685-void GaleraContactsService::updateContacts(QtContacts::QContactSaveRequest *request, QStringList &contacts)
686+void GaleraContactsService::updateContacts(QContactSaveRequestData *data)
687 {
688 if (!isOnline()) {
689- qWarning() << "Server is not online";
690- RequestData::setError(request);
691+ destroyRequest(data);
692 return;
693 }
694
695- QDBusPendingCall pcall = m_iface->asyncCall("updateContacts", contacts);
696+ QDBusPendingCall pcall = m_iface->asyncCall("updateContacts", data->allPendingContacts());
697 if (pcall.isError()) {
698 qWarning() << "Error" << pcall.error().name() << pcall.error().message();
699- RequestData::setError(request);
700+ data->finish(QtContacts::QContactManager::UnspecifiedError);
701+ destroyRequest(data);
702 } else {
703 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, 0);
704- RequestData *requestData = new RequestData(request, watcher);
705- m_runningRequests << requestData;
706+ data->updateWatcher(watcher);
707 QObject::connect(watcher, &QDBusPendingCallWatcher::finished,
708 [=](QDBusPendingCallWatcher *call) {
709- this->updateContactDone(requestData, call);
710+ this->updateContactDone(data, call);
711 });
712 }
713 }
714
715
716-void GaleraContactsService::updateContactDone(RequestData *request, QDBusPendingCallWatcher *call)
717+void GaleraContactsService::updateContactDone(QContactSaveRequestData *data, QDBusPendingCallWatcher *call)
718 {
719- if (!request->isLive()) {
720- destroyRequest(request);
721+ if (!data->isLive()) {
722+ destroyRequest(data);
723 return;
724 }
725
726 QDBusPendingReply<QStringList> reply = *call;
727- QList<QContact> contacts;
728- QMap<int, QContactManager::Error> saveError;
729 QContactManager::Error opError = QContactManager::NoError;
730
731 if (reply.isError()) {
732@@ -504,23 +488,16 @@
733 opError = QContactManager::UnspecifiedError;
734 } else {
735 const QStringList vcards = reply.value();
736- if (!vcards.isEmpty()) {
737- QMap<int, QVersitContactImporter::Error> importErrors;
738- //TODO report parse errors
739- contacts = VCardParser::vcardToContact(vcards);
740- Q_FOREACH(int key, importErrors.keys()) {
741- saveError.insert(key, QContactManager::BadArgumentError);
742- }
743- }
744+ data->updatePendingContacts(vcards);
745 }
746
747- request->update(contacts, QContactAbstractRequest::FinishedState, opError, saveError);
748- destroyRequest(request);
749+ data->finish(opError);
750+ destroyRequest(data);
751 }
752
753 void GaleraContactsService::cancelRequest(QtContacts::QContactAbstractRequest *request)
754 {
755- Q_FOREACH(RequestData* rData, m_runningRequests) {
756+ Q_FOREACH(QContactRequestData *rData, m_runningRequests) {
757 if (rData->request() == request) {
758 rData->cancel();
759 return;
760@@ -530,7 +507,7 @@
761
762 void GaleraContactsService::waitRequest(QtContacts::QContactAbstractRequest *request)
763 {
764- Q_FOREACH(RequestData* rData, m_runningRequests) {
765+ Q_FOREACH(QContactRequestData *rData, m_runningRequests) {
766 if (rData->request() == request) {
767 rData->wait();
768 return;
769@@ -584,7 +561,7 @@
770 }
771 }
772
773-void GaleraContactsService::destroyRequest(RequestData *request)
774+void GaleraContactsService::destroyRequest(QContactRequestData *request)
775 {
776 m_runningRequests.remove(request);
777 delete request;
778
779=== modified file 'qcontacts/contacts-service.h'
780--- qcontacts/contacts-service.h 2014-02-24 12:39:48 +0000
781+++ qcontacts/contacts-service.h 2014-03-17 16:52:27 +0000
782@@ -39,7 +39,11 @@
783 using namespace QtContacts; // necessary for signal signatures
784
785 namespace galera {
786-class RequestData;
787+
788+class QContactRequestData;
789+class QContactSaveRequestData;
790+class QContactFetchRequestData;
791+class QContactRemoveRequestData;
792
793 class GaleraContactsService : public QObject
794 {
795@@ -80,7 +84,8 @@
796 bool m_serviceIsReady;
797
798 QSharedPointer<QDBusInterface> m_iface;
799- QSet<RequestData*> m_runningRequests;
800+ QString m_serviceName;
801+ QSet<QContactRequestData*> m_runningRequests;
802 QQueue<QPointer<QtContacts::QContactAbstractRequest> > m_pendingRequests;
803
804 Q_INVOKABLE void initialize();
805@@ -89,24 +94,26 @@
806 bool isOnline() const;
807
808 void fetchContacts(QtContacts::QContactFetchRequest *request);
809- void fetchContactsContinue(RequestData *request,
810+ void fetchContactsContinue(QContactFetchRequestData *data,
811 QDBusPendingCallWatcher *call);
812 void fetchContactsById(QtContacts::QContactFetchByIdRequest *request);
813- Q_INVOKABLE void fetchContactsPage(galera::RequestData *request);
814- void fetchContactsDone(RequestData *request, QDBusPendingCallWatcher *call);
815+ void fetchContactsPage(QContactFetchRequestData *data);
816+ void fetchContactsDone(QContactFetchRequestData *data, QDBusPendingCallWatcher *call);
817
818 void saveContact(QtContacts::QContactSaveRequest *request);
819- void createContacts(QtContacts::QContactSaveRequest *request, QStringList &contacts);
820- void updateContacts(QtContacts::QContactSaveRequest *request, QStringList &contacts);
821- void updateContactDone(RequestData *request, QDBusPendingCallWatcher *call);
822- void createContactsDone(RequestData *request, QDBusPendingCallWatcher *call);
823+ void createContacts(QContactSaveRequestData *data);
824+ void createContactsStart(QContactSaveRequestData *data);
825+ void updateContacts(QContactSaveRequestData *data);
826+ void updateContactDone(QContactSaveRequestData *data, QDBusPendingCallWatcher *call);
827+ void createContactsDone(QContactSaveRequestData *data, QDBusPendingCallWatcher *call);
828
829 void removeContact(QtContacts::QContactRemoveRequest *request);
830- void removeContactDone(RequestData *request, QDBusPendingCallWatcher *call);
831+ void removeContactDone(QContactRemoveRequestData *data, QDBusPendingCallWatcher *call);
832
833- void destroyRequest(RequestData *request);
834+ void destroyRequest(QContactRequestData *request);
835
836 QList<QContactId> parseIds(QStringList ids) const;
837+
838 };
839
840 }
841
842=== added file 'qcontacts/qcontactfetchbyidrequest-data.cpp'
843--- qcontacts/qcontactfetchbyidrequest-data.cpp 1970-01-01 00:00:00 +0000
844+++ qcontacts/qcontactfetchbyidrequest-data.cpp 2014-03-17 16:52:27 +0000
845@@ -0,0 +1,55 @@
846+/*
847+ * Copyright 2013 Canonical Ltd.
848+ *
849+ * This file is part of contact-service-app.
850+ *
851+ * contact-service-app is free software; you can redistribute it and/or modify
852+ * it under the terms of the GNU General Public License as published by
853+ * the Free Software Foundation; version 3.
854+ *
855+ * contact-service-app is distributed in the hope that it will be useful,
856+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
857+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
858+ * GNU General Public License for more details.
859+ *
860+ * You should have received a copy of the GNU General Public License
861+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
862+ */
863+
864+#include "qcontactfetchbyidrequest-data.h"
865+
866+#include <QtCore/QDebug>
867+
868+#include <QtContacts/QContactManagerEngine>
869+
870+using namespace QtContacts;
871+namespace galera
872+{
873+
874+QContactFetchByIdRequestData::QContactFetchByIdRequestData(QContactFetchByIdRequest *request,
875+ QDBusInterface *view)
876+ : QContactFetchRequestData(request, view)
877+{
878+}
879+
880+void QContactFetchByIdRequestData::notifyError(QContactFetchByIdRequest *request,
881+ QContactManager::Error error)
882+{
883+ QContactManagerEngine::updateContactFetchByIdRequest(request,
884+ QList<QContact>(),
885+ error,
886+ QMap<int, QContactManager::Error>(),
887+ QContactAbstractRequest::FinishedState);
888+}
889+
890+void QContactFetchByIdRequestData::updateRequest(QContactAbstractRequest::State state, QContactManager::Error error, QMap<int, QContactManager::Error> errorMap)
891+{
892+ QContactManagerEngine::updateContactFetchByIdRequest(static_cast<QContactFetchByIdRequest*>(m_request.data()),
893+ m_result,
894+ error,
895+ errorMap,
896+ state);
897+}
898+
899+
900+} //namespace
901
902=== added file 'qcontacts/qcontactfetchbyidrequest-data.h'
903--- qcontacts/qcontactfetchbyidrequest-data.h 1970-01-01 00:00:00 +0000
904+++ qcontacts/qcontactfetchbyidrequest-data.h 2014-03-17 16:52:27 +0000
905@@ -0,0 +1,46 @@
906+/*
907+ * Copyright 2013 Canonical Ltd.
908+ *
909+ * This file is part of contact-service-app.
910+ *
911+ * contact-service-app is free software; you can redistribute it and/or modify
912+ * it under the terms of the GNU General Public License as published by
913+ * the Free Software Foundation; version 3.
914+ *
915+ * contact-service-app is distributed in the hope that it will be useful,
916+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
917+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
918+ * GNU General Public License for more details.
919+ *
920+ * You should have received a copy of the GNU General Public License
921+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
922+ */
923+
924+#ifndef __GALERA_QCONTACTFETCHREQUESTBYID_DATA_H__
925+#define __GALERA_QCONTACTFETCHREQUESTBYID_DATA_H__
926+
927+#include "qcontactfetchrequest-data.h"
928+
929+#include <common/fetch-hint.h>
930+#include <QtContacts/QContactFetchByIdRequest>
931+
932+namespace galera
933+{
934+class QContactFetchByIdRequestData : public QContactFetchRequestData
935+{
936+public:
937+ QContactFetchByIdRequestData(QtContacts::QContactFetchByIdRequest *request,
938+ QDBusInterface *view);
939+
940+ static void notifyError(QtContacts::QContactFetchByIdRequest *request,
941+ QtContacts::QContactManager::Error error = QtContacts::QContactManager::NotSupportedError);
942+
943+protected:
944+ virtual void updateRequest(QtContacts::QContactAbstractRequest::State state,
945+ QtContacts::QContactManager::Error error,
946+ QMap<int, QtContacts::QContactManager::Error> errorMap);
947+};
948+
949+}
950+
951+#endif
952
953=== added file 'qcontacts/qcontactfetchrequest-data.cpp'
954--- qcontacts/qcontactfetchrequest-data.cpp 1970-01-01 00:00:00 +0000
955+++ qcontacts/qcontactfetchrequest-data.cpp 2014-03-17 16:52:27 +0000
956@@ -0,0 +1,118 @@
957+/*
958+ * Copyright 2013 Canonical Ltd.
959+ *
960+ * This file is part of contact-service-app.
961+ *
962+ * contact-service-app is free software; you can redistribute it and/or modify
963+ * it under the terms of the GNU General Public License as published by
964+ * the Free Software Foundation; version 3.
965+ *
966+ * contact-service-app is distributed in the hope that it will be useful,
967+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
968+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
969+ * GNU General Public License for more details.
970+ *
971+ * You should have received a copy of the GNU General Public License
972+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
973+ */
974+
975+#include "qcontactfetchrequest-data.h"
976+
977+#include <QtCore/QDebug>
978+#include <QtContacts/QContactManagerEngine>
979+
980+using namespace QtContacts;
981+namespace galera
982+{
983+
984+QContactFetchRequestData::QContactFetchRequestData(QContactAbstractRequest *request,
985+ QDBusInterface *view,
986+ const FetchHint &hint)
987+ : QContactRequestData(request),
988+ m_view(0),
989+ m_offset(0),
990+ m_hint(hint)
991+{
992+ if (view) {
993+ updateView(view);
994+ }
995+}
996+
997+QContactFetchRequestData::~QContactFetchRequestData()
998+{
999+}
1000+
1001+int QContactFetchRequestData::offset() const
1002+{
1003+ return m_offset;
1004+}
1005+
1006+QDBusInterface* QContactFetchRequestData::view() const
1007+{
1008+ return m_view.data();
1009+}
1010+
1011+void QContactFetchRequestData::updateView(QDBusInterface* view)
1012+{
1013+ m_view = QSharedPointer<QDBusInterface>(view, QContactFetchRequestData::deleteView);
1014+}
1015+
1016+QStringList QContactFetchRequestData::fields() const
1017+{
1018+ return m_hint.fields();
1019+}
1020+
1021+void QContactFetchRequestData::updateOffset(int offset)
1022+{
1023+ m_offset += offset;
1024+}
1025+
1026+QList<QContact> QContactFetchRequestData::result() const
1027+{
1028+ return m_result;
1029+}
1030+
1031+void QContactFetchRequestData::update(QContactAbstractRequest::State state,
1032+ QContactManager::Error error,
1033+ QMap<int, QContactManager::Error> errorMap)
1034+{
1035+ if (error != QtContacts::QContactManager::NoError) {
1036+ m_result.clear();
1037+ }
1038+ QContactRequestData::update(state, error, errorMap);
1039+}
1040+
1041+void QContactFetchRequestData::update(QList<QContact> result,
1042+ QContactAbstractRequest::State state,
1043+ QContactManager::Error error,
1044+ QMap<int, QContactManager::Error> errorMap)
1045+{
1046+ m_result = result;
1047+ QContactRequestData::update(state, error, errorMap);
1048+}
1049+
1050+void QContactFetchRequestData::notifyError(QContactFetchRequest *request, QContactManager::Error error)
1051+{
1052+ QContactManagerEngine::updateContactFetchRequest(request,
1053+ QList<QContact>(),
1054+ error,
1055+ QContactAbstractRequest::FinishedState);
1056+}
1057+
1058+void QContactFetchRequestData::updateRequest(QContactAbstractRequest::State state, QContactManager::Error error, QMap<int, QContactManager::Error> errorMap)
1059+{
1060+ QContactManagerEngine::updateContactFetchRequest(static_cast<QContactFetchRequest*>(m_request.data()),
1061+ m_result,
1062+ error,
1063+ state);
1064+}
1065+
1066+void QContactFetchRequestData::deleteView(QDBusInterface *view)
1067+{
1068+ if (view) {
1069+ view->call("close");
1070+ view->deleteLater();
1071+ }
1072+}
1073+
1074+} //namespace
1075
1076=== added file 'qcontacts/qcontactfetchrequest-data.h'
1077--- qcontacts/qcontactfetchrequest-data.h 1970-01-01 00:00:00 +0000
1078+++ qcontacts/qcontactfetchrequest-data.h 2014-03-17 16:52:27 +0000
1079@@ -0,0 +1,82 @@
1080+/*
1081+ * Copyright 2013 Canonical Ltd.
1082+ *
1083+ * This file is part of contact-service-app.
1084+ *
1085+ * contact-service-app is free software; you can redistribute it and/or modify
1086+ * it under the terms of the GNU General Public License as published by
1087+ * the Free Software Foundation; version 3.
1088+ *
1089+ * contact-service-app is distributed in the hope that it will be useful,
1090+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1091+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1092+ * GNU General Public License for more details.
1093+ *
1094+ * You should have received a copy of the GNU General Public License
1095+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1096+ */
1097+
1098+#ifndef __GALERA_QCONTACTFETCHREQUEST_DATA_H__
1099+#define __GALERA_QCONTACTFETCHREQUEST_DATA_H__
1100+
1101+#include "qcontactrequest-data.h"
1102+#include <common/fetch-hint.h>
1103+
1104+#include <QtCore/QList>
1105+#include <QtCore/QSharedPointer>
1106+
1107+#include <QtContacts/QContactAbstractRequest>
1108+#include <QtContacts/QContactFetchRequest>
1109+
1110+#include <QtDBus/QDBusInterface>
1111+
1112+namespace galera
1113+{
1114+class QContactFetchRequestData : public QContactRequestData
1115+{
1116+public:
1117+ QContactFetchRequestData(QtContacts::QContactAbstractRequest *request,
1118+ QDBusInterface *view,
1119+ const FetchHint &hint = FetchHint());
1120+ ~QContactFetchRequestData();
1121+
1122+ QStringList fields() const;
1123+
1124+ void updateOffset(int offset);
1125+ int offset() const;
1126+
1127+ void updateView(QDBusInterface *view);
1128+ QDBusInterface* view() const;
1129+
1130+ QList<QtContacts::QContact> result() const;
1131+
1132+ void update(QList<QtContacts::QContact> result,
1133+ QtContacts::QContactAbstractRequest::State state,
1134+ QtContacts::QContactManager::Error error = QtContacts::QContactManager::NoError,
1135+ QMap<int, QtContacts::QContactManager::Error> errorMap = QMap<int, QtContacts::QContactManager::Error>());
1136+
1137+ static void notifyError(QtContacts::QContactFetchRequest *request,
1138+ QtContacts::QContactManager::Error error = QtContacts::QContactManager::NotSupportedError);
1139+
1140+protected:
1141+ QList<QtContacts::QContact> m_result;
1142+
1143+ virtual void updateRequest(QtContacts::QContactAbstractRequest::State state,
1144+ QtContacts::QContactManager::Error error,
1145+ QMap<int, QtContacts::QContactManager::Error> errorMap);
1146+
1147+ virtual void update(QtContacts::QContactAbstractRequest::State state,
1148+ QtContacts::QContactManager::Error error = QtContacts::QContactManager::NoError,
1149+ QMap<int, QtContacts::QContactManager::Error> errorMap = QMap<int, QtContacts::QContactManager::Error>());
1150+
1151+private:
1152+ QSharedPointer<QDBusInterface> m_view;
1153+ int m_offset;
1154+ FetchHint m_hint;
1155+
1156+ static void deleteView(QDBusInterface *view);
1157+};
1158+
1159+}
1160+
1161+#endif
1162
1163=== added file 'qcontacts/qcontactremoverequest-data.cpp'
1164--- qcontacts/qcontactremoverequest-data.cpp 1970-01-01 00:00:00 +0000
1165+++ qcontacts/qcontactremoverequest-data.cpp 2014-03-17 16:52:27 +0000
1166@@ -0,0 +1,61 @@
1167+/*
1168+ * Copyright 2013 Canonical Ltd.
1169+ *
1170+ * This file is part of contact-service-app.
1171+ *
1172+ * contact-service-app is free software; you can redistribute it and/or modify
1173+ * it under the terms of the GNU General Public License as published by
1174+ * the Free Software Foundation; version 3.
1175+ *
1176+ * contact-service-app is distributed in the hope that it will be useful,
1177+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1178+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1179+ * GNU General Public License for more details.
1180+ *
1181+ * You should have received a copy of the GNU General Public License
1182+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1183+ */
1184+
1185+#include "qcontactremoverequest-data.h"
1186+
1187+#include <QtCore/QDebug>
1188+
1189+#include <QtContacts/QContactManagerEngine>
1190+
1191+using namespace QtContacts;
1192+
1193+namespace galera
1194+{
1195+
1196+QContactRemoveRequestData::QContactRemoveRequestData(QContactRemoveRequest *request)
1197+ : QContactRequestData(request)
1198+{
1199+ Q_FOREACH(QContactId contactId, request->contactIds()) {
1200+ m_pendingIds << contactId.toString().split(":").last();
1201+ }
1202+}
1203+
1204+QStringList QContactRemoveRequestData::pendingIds() const
1205+{
1206+ return m_pendingIds;
1207+}
1208+
1209+void QContactRemoveRequestData::notifyError(QContactRemoveRequest *request, QContactManager::Error error)
1210+{
1211+ QContactManagerEngine::updateContactRemoveRequest(request,
1212+ error,
1213+ QMap<int, QContactManager::Error>(),
1214+ QContactAbstractRequest::FinishedState);
1215+}
1216+
1217+void QContactRemoveRequestData::updateRequest(QContactAbstractRequest::State state,
1218+ QContactManager::Error error,
1219+ QMap<int, QContactManager::Error> errorMap)
1220+{
1221+ QContactManagerEngine::updateContactRemoveRequest(static_cast<QContactRemoveRequest*>(m_request.data()),
1222+ error,
1223+ errorMap,
1224+ state);
1225+}
1226+
1227+} //namespace
1228
1229=== added file 'qcontacts/qcontactremoverequest-data.h'
1230--- qcontacts/qcontactremoverequest-data.h 1970-01-01 00:00:00 +0000
1231+++ qcontacts/qcontactremoverequest-data.h 2014-03-17 16:52:27 +0000
1232@@ -0,0 +1,49 @@
1233+/*
1234+ * Copyright 2013 Canonical Ltd.
1235+ *
1236+ * This file is part of contact-service-app.
1237+ *
1238+ * contact-service-app is free software; you can redistribute it and/or modify
1239+ * it under the terms of the GNU General Public License as published by
1240+ * the Free Software Foundation; version 3.
1241+ *
1242+ * contact-service-app is distributed in the hope that it will be useful,
1243+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1244+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1245+ * GNU General Public License for more details.
1246+ *
1247+ * You should have received a copy of the GNU General Public License
1248+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1249+ */
1250+
1251+#ifndef __GALERA_QCONTACTREMOVEREQUEST_DATA_H__
1252+#define __GALERA_QCONTACTREMOVEREQUEST_DATA_H__
1253+
1254+#include "qcontactrequest-data.h"
1255+
1256+#include <QtCore/QStringList>
1257+
1258+#include <QtContacts/QContactRemoveRequest>
1259+
1260+namespace galera
1261+{
1262+class QContactRemoveRequestData : public QContactRequestData
1263+{
1264+public:
1265+ QContactRemoveRequestData(QtContacts::QContactRemoveRequest *request);
1266+ QStringList pendingIds() const;
1267+
1268+ static void notifyError(QtContacts::QContactRemoveRequest *request,
1269+ QtContacts::QContactManager::Error error = QtContacts::QContactManager::NotSupportedError);
1270+protected:
1271+ virtual void updateRequest(QtContacts::QContactAbstractRequest::State state,
1272+ QtContacts::QContactManager::Error error,
1273+ QMap<int, QtContacts::QContactManager::Error> errorMap);
1274+
1275+private:
1276+ QStringList m_pendingIds;
1277+};
1278+
1279+}
1280+
1281+#endif
1282
1283=== added file 'qcontacts/qcontactrequest-data.cpp'
1284--- qcontacts/qcontactrequest-data.cpp 1970-01-01 00:00:00 +0000
1285+++ qcontacts/qcontactrequest-data.cpp 2014-03-17 16:52:27 +0000
1286@@ -0,0 +1,117 @@
1287+/*
1288+ * Copyright 2013 Canonical Ltd.
1289+ *
1290+ * This file is part of contact-service-app.
1291+ *
1292+ * contact-service-app is free software; you can redistribute it and/or modify
1293+ * it under the terms of the GNU General Public License as published by
1294+ * the Free Software Foundation; version 3.
1295+ *
1296+ * contact-service-app is distributed in the hope that it will be useful,
1297+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1298+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1299+ * GNU General Public License for more details.
1300+ *
1301+ * You should have received a copy of the GNU General Public License
1302+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1303+ */
1304+
1305+#include "qcontactrequest-data.h"
1306+
1307+#include <QtCore/QDebug>
1308+#include <QtContacts/QContactManagerEngine>
1309+
1310+using namespace QtContacts;
1311+namespace galera
1312+{
1313+
1314+QContactRequestData::QContactRequestData(QContactAbstractRequest *request,
1315+ QDBusPendingCallWatcher *watcher)
1316+ : m_request(request),
1317+ m_canceled(false),
1318+ m_eventLoop(0)
1319+{
1320+ updateWatcher(watcher);
1321+}
1322+
1323+QContactRequestData::~QContactRequestData()
1324+{
1325+ if (!m_request.isNull() && m_canceled) {
1326+ update(QContactAbstractRequest::CanceledState);
1327+ }
1328+ m_request.clear();
1329+}
1330+
1331+QContactAbstractRequest* QContactRequestData::request() const
1332+{
1333+ return m_request.data();
1334+}
1335+
1336+bool QContactRequestData::isLive() const
1337+{
1338+ return !m_request.isNull() &&
1339+ (m_request->state() == QContactAbstractRequest::ActiveState);
1340+}
1341+
1342+void QContactRequestData::cancel()
1343+{
1344+ m_watcher.clear();
1345+ m_canceled = true;
1346+}
1347+
1348+bool QContactRequestData::canceled() const
1349+{
1350+ return m_canceled;
1351+}
1352+
1353+void QContactRequestData::wait()
1354+{
1355+ if (m_eventLoop) {
1356+ qWarning() << "Recursive wait call";
1357+ Q_ASSERT(false);
1358+ }
1359+
1360+ if (isLive()) {
1361+ QEventLoop eventLoop;
1362+ m_eventLoop = &eventLoop;
1363+ eventLoop.exec();
1364+ m_eventLoop = 0;
1365+ }
1366+}
1367+
1368+void QContactRequestData::finish(QContactManager::Error error)
1369+{
1370+ update(QContactAbstractRequest::FinishedState, error, m_errorMap);
1371+}
1372+
1373+void QContactRequestData::updateWatcher(QDBusPendingCallWatcher *watcher)
1374+{
1375+ m_watcher.clear();
1376+ if (watcher) {
1377+ m_watcher = QSharedPointer<QDBusPendingCallWatcher>(watcher, QContactRequestData::deleteWatcher);
1378+ }
1379+}
1380+
1381+void QContactRequestData::update(QContactAbstractRequest::State state,
1382+ QContactManager::Error error,
1383+ QMap<int, QContactManager::Error> errorMap)
1384+{
1385+ if (!isLive()) {
1386+ return;
1387+ }
1388+
1389+ updateRequest(state, error, errorMap);
1390+
1391+ if (m_eventLoop && (state != QContactAbstractRequest::ActiveState)) {
1392+ m_eventLoop->quit();
1393+ }
1394+}
1395+
1396+void QContactRequestData::deleteWatcher(QDBusPendingCallWatcher *watcher)
1397+{
1398+ if (watcher) {
1399+ watcher->deleteLater();
1400+ }
1401+}
1402+
1403+} //namespace
1404
1405=== added file 'qcontacts/qcontactrequest-data.h'
1406--- qcontacts/qcontactrequest-data.h 1970-01-01 00:00:00 +0000
1407+++ qcontacts/qcontactrequest-data.h 2014-03-17 16:52:27 +0000
1408@@ -0,0 +1,81 @@
1409+/*
1410+ * Copyright 2013 Canonical Ltd.
1411+ *
1412+ * This file is part of contact-service-app.
1413+ *
1414+ * contact-service-app is free software; you can redistribute it and/or modify
1415+ * it under the terms of the GNU General Public License as published by
1416+ * the Free Software Foundation; version 3.
1417+ *
1418+ * contact-service-app is distributed in the hope that it will be useful,
1419+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1420+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1421+ * GNU General Public License for more details.
1422+ *
1423+ * You should have received a copy of the GNU General Public License
1424+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1425+ */
1426+
1427+#ifndef __GALERA_QCONTACTREQUEST_DATA_H__
1428+#define __GALERA_QCONTACTREQUEST_DATA_H__
1429+
1430+#include <common/fetch-hint.h>
1431+
1432+#include <QtCore/QList>
1433+#include <QtCore/QSharedPointer>
1434+#include <QtCore/QEventLoop>
1435+#include <QtCore/QPointer>
1436+
1437+#include <QtContacts/QContactAbstractRequest>
1438+
1439+#include <QtDBus/QDBusInterface>
1440+#include <QtDBus/QDBusPendingCallWatcher>
1441+
1442+namespace galera
1443+{
1444+class QContactRequestData
1445+{
1446+public:
1447+ QContactRequestData(QtContacts::QContactAbstractRequest *request, QDBusPendingCallWatcher *watcher = 0);
1448+ virtual ~QContactRequestData();
1449+
1450+ QtContacts::QContactAbstractRequest* request() const;
1451+
1452+ void updateWatcher(QDBusPendingCallWatcher *watcher);
1453+
1454+ bool isLive() const;
1455+ void cancel();
1456+ bool canceled() const;
1457+ void wait();
1458+ void finish(QtContacts::QContactManager::Error error = QtContacts::QContactManager::NoError);
1459+
1460+ virtual void update(QtContacts::QContactAbstractRequest::State state,
1461+ QtContacts::QContactManager::Error error = QtContacts::QContactManager::NoError,
1462+ QMap<int, QtContacts::QContactManager::Error> errorMap = QMap<int, QtContacts::QContactManager::Error>());
1463+
1464+protected:
1465+ QPointer<QtContacts::QContactAbstractRequest> m_request;
1466+ QMap<int, QtContacts::QContactManager::Error> m_errorMap;
1467+
1468+ virtual void updateRequest(QtContacts::QContactAbstractRequest::State state,
1469+ QtContacts::QContactManager::Error error,
1470+ QMap<int, QtContacts::QContactManager::Error> errorMap) = 0;
1471+
1472+private:
1473+ QSharedPointer<QDBusPendingCallWatcher> m_watcher;
1474+ bool m_canceled;
1475+ QEventLoop *m_eventLoop;
1476+
1477+ void init(QtContacts::QContactAbstractRequest *request,
1478+ QDBusInterface *view,
1479+ QDBusPendingCallWatcher *watcher);
1480+
1481+ static void deleteRequest(QtContacts::QContactAbstractRequest *obj);
1482+ static void deleteWatcher(QDBusPendingCallWatcher *watcher);
1483+};
1484+
1485+}
1486+
1487+Q_DECLARE_METATYPE(galera::QContactRequestData*)
1488+
1489+#endif
1490
1491=== added file 'qcontacts/qcontactsaverequest-data.cpp'
1492--- qcontacts/qcontactsaverequest-data.cpp 1970-01-01 00:00:00 +0000
1493+++ qcontacts/qcontactsaverequest-data.cpp 2014-03-17 16:52:27 +0000
1494@@ -0,0 +1,146 @@
1495+/*
1496+ * Copyright 2013 Canonical Ltd.
1497+ *
1498+ * This file is part of contact-service-app.
1499+ *
1500+ * contact-service-app is free software; you can redistribute it and/or modify
1501+ * it under the terms of the GNU General Public License as published by
1502+ * the Free Software Foundation; version 3.
1503+ *
1504+ * contact-service-app is distributed in the hope that it will be useful,
1505+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1506+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1507+ * GNU General Public License for more details.
1508+ *
1509+ * You should have received a copy of the GNU General Public License
1510+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1511+ */
1512+
1513+#include "qcontactsaverequest-data.h"
1514+#include "common/vcard-parser.h"
1515+#include "qcontact-engineid.h"
1516+
1517+#include <QtCore/QDebug>
1518+
1519+#include <QtContacts/QContactManagerEngine>
1520+
1521+#include <QtVersit/QVersitContactImporter>
1522+
1523+using namespace QtContacts;
1524+using namespace QtVersit;
1525+
1526+namespace galera
1527+{
1528+
1529+QContactSaveRequestData::QContactSaveRequestData(QContactSaveRequest *request)
1530+ : QContactRequestData(request)
1531+{
1532+ int index = 0;
1533+ Q_FOREACH(const QContact &contact, request->contacts()) {
1534+ if (contact.id().isNull()) {
1535+ m_contactsToCreate.insert(index, contact);
1536+ } else {
1537+ m_contactsToUpdate.insert(index, contact);
1538+ }
1539+ index++;
1540+ }
1541+}
1542+
1543+void QContactSaveRequestData::prepareContacts(QMap<int, QtContacts::QContact> contacts)
1544+{
1545+ if (!contacts.isEmpty()) {
1546+ QStringList vcards = VCardParser::contactToVcard(contacts.values());
1547+ if (vcards.count() != contacts.count()) {
1548+ qWarning() << "Fail to parse contacts to Update";
1549+ return;
1550+ }
1551+ int i = 0;
1552+ Q_FOREACH(int index, contacts.keys()) {
1553+ m_pendingContacts.insert(index, vcards[i]);
1554+ }
1555+ }
1556+}
1557+
1558+void QContactSaveRequestData::prepareToUpdate()
1559+{
1560+ Q_ASSERT(m_pendingContacts.count() == 0);
1561+ prepareContacts(m_contactsToUpdate);
1562+}
1563+
1564+void QContactSaveRequestData::prepareToCreate()
1565+{
1566+ Q_ASSERT(m_pendingContacts.count() == 0);
1567+ prepareContacts(m_contactsToCreate);
1568+ qDebug() << "Contacts to create" << m_pendingContacts.count();
1569+}
1570+
1571+
1572+bool QContactSaveRequestData::hasNext() const
1573+{
1574+ return (m_pendingContacts.count() > 0);
1575+}
1576+
1577+QString QContactSaveRequestData::nextContact()
1578+{
1579+ Q_ASSERT(m_pendingContacts.count() > 0);
1580+ qDebug() << "SIZEEEE" << m_pendingContacts.count() << "Has next:" << hasNext();
1581+ m_currentContact = m_pendingContacts.begin();
1582+
1583+ qDebug() << "next contact" << m_currentContact.key() << m_currentContact.value();
1584+ return m_currentContact.value();
1585+}
1586+
1587+void QContactSaveRequestData::updateCurrentContactId(GaleraEngineId *engineId)
1588+{
1589+ QContactId contactId(engineId);
1590+ QContact &contact = m_contactsToCreate[m_currentContact.key()];
1591+ contact.setId(contactId);
1592+ m_pendingContacts.remove(m_currentContact.key());
1593+ qDebug() << "After update id" << m_pendingContacts.count();
1594+}
1595+
1596+void QContactSaveRequestData::updatePendingContacts(QStringList vcards)
1597+{
1598+ if (!vcards.isEmpty()) {
1599+ QList<QContact> contacts = VCardParser::vcardToContact(vcards);
1600+ if (contacts.count() != m_pendingContacts.count()) {
1601+ qWarning() << "Fail to parse vcards to contacts";
1602+ }
1603+
1604+ // update the contacts on update list
1605+ QList<int> indexs = m_contactsToUpdate.keys();
1606+ Q_FOREACH(const QContact &contact, contacts) {
1607+ m_contactsToUpdate.insert(indexs.takeFirst(), contact);
1608+ }
1609+ }
1610+}
1611+
1612+void QContactSaveRequestData::notifyUpdateError(QContactManager::Error error)
1613+{
1614+ m_contactsToUpdate.remove(m_currentContact.key());
1615+ m_errorMap.insert(m_currentContact.key(), error);
1616+ m_pendingContacts.remove(m_currentContact.key());
1617+}
1618+
1619+QStringList QContactSaveRequestData::allPendingContacts() const
1620+{
1621+ return m_pendingContacts.values();
1622+}
1623+
1624+void QContactSaveRequestData::updateRequest(QContactAbstractRequest::State state, QContactManager::Error error, QMap<int, QContactManager::Error> errorMap)
1625+{
1626+ // join back contacts to update and create
1627+ QMap<int, QtContacts::QContact> allContacts = m_contactsToUpdate;
1628+
1629+ Q_FOREACH(int key, m_contactsToCreate.keys()) {
1630+ allContacts.insert(key, m_contactsToCreate[key]);
1631+ }
1632+
1633+ QContactManagerEngine::updateContactSaveRequest(static_cast<QContactSaveRequest*>(m_request.data()),
1634+ allContacts.values(),
1635+ error,
1636+ errorMap,
1637+ state);
1638+}
1639+
1640+} //namespace
1641
1642=== added file 'qcontacts/qcontactsaverequest-data.h'
1643--- qcontacts/qcontactsaverequest-data.h 1970-01-01 00:00:00 +0000
1644+++ qcontacts/qcontactsaverequest-data.h 2014-03-17 16:52:27 +0000
1645@@ -0,0 +1,72 @@
1646+/*
1647+ * Copyright 2013 Canonical Ltd.
1648+ *
1649+ * This file is part of contact-service-app.
1650+ *
1651+ * contact-service-app is free software; you can redistribute it and/or modify
1652+ * it under the terms of the GNU General Public License as published by
1653+ * the Free Software Foundation; version 3.
1654+ *
1655+ * contact-service-app is distributed in the hope that it will be useful,
1656+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1657+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1658+ * GNU General Public License for more details.
1659+ *
1660+ * You should have received a copy of the GNU General Public License
1661+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1662+ */
1663+
1664+#ifndef __GALERA_QCONTACTSAVEREQUESTDATA_DATA_H__
1665+#define __GALERA_QCONTACTSAVEREQUESTDATA_DATA_H__
1666+
1667+
1668+#include "qcontactrequest-data.h"
1669+#include <common/fetch-hint.h>
1670+
1671+#include <QtCore/QList>
1672+
1673+#include <QtContacts/QContactSaveRequest>
1674+
1675+namespace galera
1676+{
1677+class GaleraEngineId;
1678+
1679+class QContactSaveRequestData : public QContactRequestData
1680+{
1681+public:
1682+ QContactSaveRequestData(QtContacts::QContactSaveRequest *request);
1683+
1684+ void prepareToUpdate();
1685+ void updatePendingContacts(QStringList vcards);
1686+
1687+ void prepareToCreate();
1688+ void updateCurrentContactId(GaleraEngineId *engineId);
1689+
1690+ void notifyUpdateError(QtContacts::QContactManager::Error error);
1691+
1692+ bool hasNext() const;
1693+ QString nextContact();
1694+
1695+ void notifyError(QtContacts::QContactManager::Error error);
1696+ QStringList allPendingContacts() const;
1697+
1698+protected:
1699+ virtual void updateRequest(QtContacts::QContactAbstractRequest::State state,
1700+ QtContacts::QContactManager::Error error,
1701+ QMap<int, QtContacts::QContactManager::Error> errorMap);
1702+
1703+private:
1704+ QMap<int, QtContacts::QContact> m_contactsToUpdate;
1705+ QMap<int, QtContacts::QContact> m_contactsToCreate;
1706+
1707+ QMap<int, QString> m_pendingContacts;
1708+ QMap<int, QString>::Iterator m_currentContact;
1709+
1710+ void prepareContacts(QMap<int, QtContacts::QContact> contacts);
1711+};
1712+
1713+}
1714+
1715+Q_DECLARE_METATYPE(galera::QContactSaveRequestData*)
1716+
1717+#endif
1718
1719=== removed file 'qcontacts/request-data.cpp'
1720--- qcontacts/request-data.cpp 2014-02-04 19:12:46 +0000
1721+++ qcontacts/request-data.cpp 1970-01-01 00:00:00 +0000
1722@@ -1,236 +0,0 @@
1723-/*
1724- * Copyright 2013 Canonical Ltd.
1725- *
1726- * This file is part of contact-service-app.
1727- *
1728- * contact-service-app is free software; you can redistribute it and/or modify
1729- * it under the terms of the GNU General Public License as published by
1730- * the Free Software Foundation; version 3.
1731- *
1732- * contact-service-app is distributed in the hope that it will be useful,
1733- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1734- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1735- * GNU General Public License for more details.
1736- *
1737- * You should have received a copy of the GNU General Public License
1738- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1739- */
1740-
1741-#include "request-data.h"
1742-
1743-#include <QtCore/QDebug>
1744-#include <QtContacts/QContactManagerEngine>
1745-
1746-using namespace QtContacts;
1747-namespace galera
1748-{
1749-
1750-RequestData::RequestData(QContactAbstractRequest *request,
1751- QDBusInterface *view,
1752- const FetchHint &hint,
1753- QDBusPendingCallWatcher *watcher)
1754- : m_offset(0),
1755- m_hint(hint),
1756- m_canceled(false),
1757- m_eventLoop(0)
1758-{
1759- init(request, view, watcher);
1760-}
1761-
1762-RequestData::RequestData(QtContacts::QContactAbstractRequest *request,
1763- QDBusPendingCallWatcher *watcher)
1764- : m_offset(0),
1765- m_canceled(false),
1766- m_eventLoop(0)
1767-{
1768- init(request, 0, watcher);
1769-}
1770-
1771-RequestData::~RequestData()
1772-{
1773- if (!m_request.isNull() && m_canceled) {
1774- update(QContactAbstractRequest::CanceledState);
1775- }
1776- m_request.clear();
1777-}
1778-
1779-void RequestData::init(QtContacts::QContactAbstractRequest *request,
1780- QDBusInterface *view,
1781- QDBusPendingCallWatcher *watcher)
1782-{
1783- m_request = request;
1784-
1785- if (view) {
1786- updateView(view);
1787- }
1788-
1789- if (watcher) {
1790- m_watcher = QSharedPointer<QDBusPendingCallWatcher>(watcher, RequestData::deleteWatcher);
1791- }
1792-
1793-}
1794-
1795-QContactAbstractRequest* RequestData::request() const
1796-{
1797- return m_request.data();
1798-}
1799-
1800-int RequestData::offset() const
1801-{
1802- return m_offset;
1803-}
1804-
1805-bool RequestData::isLive() const
1806-{
1807- return !m_request.isNull() &&
1808- (m_request->state() == QContactAbstractRequest::ActiveState);
1809-}
1810-
1811-void RequestData::cancel()
1812-{
1813- m_watcher.clear();
1814- m_canceled = true;
1815-}
1816-
1817-bool RequestData::canceled() const
1818-{
1819- return m_canceled;
1820-}
1821-
1822-void RequestData::wait()
1823-{
1824- if (m_eventLoop) {
1825- qWarning() << "Recursive wait call";
1826- Q_ASSERT(false);
1827- }
1828-
1829- if (isLive()) {
1830- QEventLoop eventLoop;
1831- m_eventLoop = &eventLoop;
1832- eventLoop.exec();
1833- m_eventLoop = 0;
1834- }
1835-}
1836-
1837-QDBusInterface* RequestData::view() const
1838-{
1839- return m_view.data();
1840-}
1841-
1842-void RequestData::updateView(QDBusInterface* view)
1843-{
1844- m_view = QSharedPointer<QDBusInterface>(view, RequestData::deleteView);
1845-}
1846-
1847-QStringList RequestData::fields() const
1848-{
1849- return m_hint.fields();
1850-}
1851-
1852-void RequestData::updateWatcher(QDBusPendingCallWatcher *watcher)
1853-{
1854- m_watcher.clear();
1855- if (watcher) {
1856- m_watcher = QSharedPointer<QDBusPendingCallWatcher>(watcher, RequestData::deleteWatcher);
1857- }
1858-}
1859-
1860-void RequestData::updateOffset(int offset)
1861-{
1862- m_offset += offset;
1863-}
1864-
1865-QList<QContact> RequestData::result() const
1866-{
1867- return m_result;
1868-}
1869-
1870-void RequestData::setError(QContactManager::Error error)
1871-{
1872- m_result.clear();
1873- update(QContactAbstractRequest::FinishedState, error);
1874- if (m_eventLoop) {
1875- m_eventLoop->quit();
1876- }
1877-}
1878-
1879-void RequestData::update(QList<QContact> result,
1880- QContactAbstractRequest::State state,
1881- QContactManager::Error error,
1882- QMap<int, QContactManager::Error> errorMap)
1883-{
1884- m_result = result;
1885- update(state, error, errorMap);
1886-}
1887-
1888-void RequestData::update(QContactAbstractRequest::State state,
1889- QContactManager::Error error,
1890- QMap<int, QContactManager::Error> errorMap)
1891-{
1892- if (!isLive()) {
1893- return;
1894- }
1895-
1896- switch (m_request->type()) {
1897- case QContactAbstractRequest::ContactFetchRequest:
1898- QContactManagerEngine::updateContactFetchRequest(static_cast<QContactFetchRequest*>(m_request.data()),
1899- m_result,
1900- error,
1901- state);
1902- break;
1903- case QContactAbstractRequest::ContactFetchByIdRequest:
1904- QContactManagerEngine::updateContactFetchByIdRequest(static_cast<QContactFetchByIdRequest*>(m_request.data()),
1905- m_result,
1906- error,
1907- errorMap,
1908- state);
1909- break;
1910- case QContactAbstractRequest::ContactSaveRequest:
1911- QContactManagerEngine::updateContactSaveRequest(static_cast<QContactSaveRequest*>(m_request.data()),
1912- m_result,
1913- error,
1914- QMap<int, QContactManager::Error>(),
1915- state);
1916- case QContactAbstractRequest::ContactRemoveRequest:
1917- QContactManagerEngine::updateContactRemoveRequest(static_cast<QContactRemoveRequest*>(m_request.data()),
1918- error,
1919- errorMap,
1920- state);
1921- break;
1922- default:
1923- break;
1924- }
1925-
1926- if (m_eventLoop && (state != QContactAbstractRequest::ActiveState)) {
1927- m_eventLoop->quit();
1928- }
1929-}
1930-
1931-
1932-void RequestData::registerMetaType()
1933-{
1934- qRegisterMetaType<galera::RequestData*>();
1935-}
1936-
1937-void RequestData::setError(QContactAbstractRequest *request, QContactManager::Error error)
1938-{
1939- RequestData r(request);
1940- r.setError(error);
1941-}
1942-
1943-void RequestData::deleteView(QDBusInterface *view)
1944-{
1945- if (view) {
1946- view->call("close");
1947- view->deleteLater();
1948- }
1949-}
1950-
1951-void RequestData::deleteWatcher(QDBusPendingCallWatcher *watcher)
1952-{
1953- if (watcher) {
1954- watcher->deleteLater();
1955- }
1956-}
1957-
1958-} //namespace
1959
1960=== removed file 'qcontacts/request-data.h'
1961--- qcontacts/request-data.h 2013-09-10 18:44:50 +0000
1962+++ qcontacts/request-data.h 1970-01-01 00:00:00 +0000
1963@@ -1,100 +0,0 @@
1964-/*
1965- * Copyright 2013 Canonical Ltd.
1966- *
1967- * This file is part of contact-service-app.
1968- *
1969- * contact-service-app is free software; you can redistribute it and/or modify
1970- * it under the terms of the GNU General Public License as published by
1971- * the Free Software Foundation; version 3.
1972- *
1973- * contact-service-app is distributed in the hope that it will be useful,
1974- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1975- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1976- * GNU General Public License for more details.
1977- *
1978- * You should have received a copy of the GNU General Public License
1979- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1980- */
1981-
1982-#ifndef __GALERA_REQUEST_DATA_H__
1983-#define __GALERA_REQUEST_DATA_H__
1984-
1985-#include <common/fetch-hint.h>
1986-
1987-#include <QtCore/QList>
1988-#include <QtCore/QSharedPointer>
1989-#include <QtCore/QPointer>
1990-#include <QtCore/QEventLoop>
1991-
1992-#include <QtContacts/QContactAbstractRequest>
1993-
1994-#include <QtDBus/QDBusInterface>
1995-#include <QtDBus/QDBusPendingCallWatcher>
1996-
1997-namespace galera
1998-{
1999-class RequestData
2000-{
2001-public:
2002- RequestData(QtContacts::QContactAbstractRequest *request,
2003- QDBusInterface *view,
2004- const FetchHint &hint,
2005- QDBusPendingCallWatcher *watcher=0);
2006-
2007- RequestData(QtContacts::QContactAbstractRequest *request,
2008- QDBusPendingCallWatcher *watcher=0);
2009-
2010-
2011- ~RequestData();
2012-
2013- QtContacts::QContactAbstractRequest* request() const;
2014- QDBusInterface* view() const;
2015- QStringList fields() const;
2016-
2017-
2018- void updateWatcher(QDBusPendingCallWatcher *watcher);
2019- void updateView(QDBusInterface* view);
2020-
2021- void updateOffset(int offset);
2022- int offset() const;
2023- bool isLive() const;
2024- void cancel();
2025- bool canceled() const;
2026- void wait();
2027-
2028- QList<QtContacts::QContact> result() const;
2029-
2030- void setError(QtContacts::QContactManager::Error error);
2031- void update(QList<QtContacts::QContact> result,
2032- QtContacts::QContactAbstractRequest::State state,
2033- QtContacts::QContactManager::Error error = QtContacts::QContactManager::NoError,
2034- QMap<int, QtContacts::QContactManager::Error> errorMap = QMap<int, QtContacts::QContactManager::Error>());
2035- void update(QtContacts::QContactAbstractRequest::State state,
2036- QtContacts::QContactManager::Error error = QtContacts::QContactManager::NoError,
2037- QMap<int, QtContacts::QContactManager::Error> errorMap = QMap<int, QtContacts::QContactManager::Error>());
2038-
2039- static void setError(QtContacts::QContactAbstractRequest *request,
2040- QtContacts::QContactManager::Error error = QtContacts::QContactManager::UnspecifiedError);
2041- static void registerMetaType();
2042-
2043-private:
2044- QPointer<QtContacts::QContactAbstractRequest> m_request;
2045- QSharedPointer<QDBusInterface> m_view;
2046- QSharedPointer<QDBusPendingCallWatcher> m_watcher;
2047- QList<QtContacts::QContact> m_result;
2048- int m_offset;
2049- FetchHint m_hint;
2050- bool m_canceled;
2051- QEventLoop *m_eventLoop;
2052-
2053- void init(QtContacts::QContactAbstractRequest *request, QDBusInterface *view, QDBusPendingCallWatcher *watcher);
2054- static void deleteRequest(QtContacts::QContactAbstractRequest *obj);
2055- static void deleteView(QDBusInterface *view);
2056- static void deleteWatcher(QDBusPendingCallWatcher *watcher);
2057-};
2058-
2059-}
2060-
2061-Q_DECLARE_METATYPE(galera::RequestData*)
2062-
2063-#endif
2064
2065=== modified file 'tests/unittest/base-client-test.cpp'
2066--- tests/unittest/base-client-test.cpp 2013-11-05 19:26:25 +0000
2067+++ tests/unittest/base-client-test.cpp 2014-03-17 16:52:27 +0000
2068@@ -30,7 +30,15 @@
2069 void BaseClientTest::initTestCase()
2070 {
2071 galera::Source::registerMetaType();
2072- m_serverIface = new QDBusInterface(CPIM_SERVICE_NAME,
2073+
2074+ QString serviceName;
2075+ if (qEnvironmentVariableIsSet(ALTERNATIVE_CPIM_SERVICE_NAME)) {
2076+ serviceName = qgetenv(ALTERNATIVE_CPIM_SERVICE_NAME);
2077+ } else {
2078+ serviceName = CPIM_SERVICE_NAME;
2079+ }
2080+
2081+ m_serverIface = new QDBusInterface(serviceName,
2082 CPIM_ADDRESSBOOK_OBJECT_PATH,
2083 CPIM_ADDRESSBOOK_IFACE_NAME);
2084 QVERIFY(!m_serverIface->lastError().isValid());
2085
2086=== modified file 'tests/unittest/dummy-backend.cpp'
2087--- tests/unittest/dummy-backend.cpp 2014-02-13 14:32:48 +0000
2088+++ tests/unittest/dummy-backend.cpp 2014-03-17 16:52:27 +0000
2089@@ -147,8 +147,12 @@
2090
2091 m_backend = FOLKS_DUMMY_BACKEND(folks_backend_store_dup_backend_by_name(m_backendStore, "dummy"));
2092
2093+ // get the primary store
2094+ GeeMap *stores = folks_backend_get_persona_stores(FOLKS_BACKEND(m_backend));
2095+ m_primaryPersonaStore = FOLKS_DUMMY_PERSONA_STORE(gee_map_get(stores, "dummy-store"));
2096+ qDebug() << "Primary store:" << (void*) m_primaryPersonaStore;
2097+
2098 Q_ASSERT(m_backend != 0);
2099- configurePrimaryStore();
2100 m_isReady = true;
2101 Q_EMIT ready();
2102 }
2103@@ -210,40 +214,10 @@
2104 return i->id();
2105 }
2106
2107-void DummyBackendProxy::configurePrimaryStore()
2108-{
2109- static const char* writableProperties[] = {
2110- folks_persona_store_detail_key(FOLKS_PERSONA_DETAIL_FULL_NAME),
2111- folks_persona_store_detail_key(FOLKS_PERSONA_DETAIL_ALIAS),
2112- folks_persona_store_detail_key(FOLKS_PERSONA_DETAIL_NICKNAME),
2113- folks_persona_store_detail_key(FOLKS_PERSONA_DETAIL_STRUCTURED_NAME),
2114- folks_persona_store_detail_key(FOLKS_PERSONA_DETAIL_IS_FAVOURITE),
2115- folks_persona_store_detail_key(FOLKS_PERSONA_DETAIL_EMAIL_ADDRESSES),
2116- folks_persona_store_detail_key(FOLKS_PERSONA_DETAIL_PHONE_NUMBERS),
2117- 0
2118- };
2119-
2120- m_primaryPersonaStore = folks_dummy_persona_store_new("dummy-store",
2121- "Dummy personas",
2122- const_cast<char**>(writableProperties), 7);
2123- folks_dummy_persona_store_set_persona_type(m_primaryPersonaStore, FOLKS_DUMMY_TYPE_FULL_PERSONA);
2124- folks_dummy_persona_store_update_trust_level(m_primaryPersonaStore, FOLKS_PERSONA_STORE_TRUST_FULL);
2125-
2126- GeeHashSet *personaStores = gee_hash_set_new(FOLKS_TYPE_PERSONA_STORE,
2127- (GBoxedCopyFunc) g_object_ref, g_object_unref,
2128- NULL, NULL, NULL, NULL, NULL, NULL);
2129-
2130- gee_abstract_collection_add(GEE_ABSTRACT_COLLECTION(personaStores), m_primaryPersonaStore);
2131- folks_dummy_backend_register_persona_stores(m_backend, GEE_SET(personaStores), true);
2132- folks_dummy_persona_store_reach_quiescence(m_primaryPersonaStore);
2133- g_object_unref(personaStores);
2134-}
2135-
2136 void DummyBackendProxy::backendEnabled(FolksBackendStore *backendStore,
2137 GAsyncResult *res,
2138 DummyBackendProxy *self)
2139 {
2140- folks_backend_store_enable_backend_finish(backendStore, res);
2141 self->m_eventLoop->quit();
2142 self->m_eventLoop = 0;
2143 }
2144
2145=== modified file 'tests/unittest/dummy-backend.h'
2146--- tests/unittest/dummy-backend.h 2014-02-11 17:58:56 +0000
2147+++ tests/unittest/dummy-backend.h 2014-03-17 16:52:27 +0000
2148@@ -77,7 +77,6 @@
2149
2150 bool registerObject();
2151 void initFolks();
2152- void configurePrimaryStore();
2153 void initEnviroment();
2154 void prepareAggregator();
2155 static void mkpath(const QString &path);

Subscribers

People subscribed via source and target branches