Merge lp:~renatofilho/address-book-service/create-source into lp:address-book-service
- create-source
- Merge into trunk
Proposed by
Renato Araujo Oliveira Filho
Status: | Superseded |
---|---|
Proposed branch: | lp:~renatofilho/address-book-service/create-source |
Merge into: | lp:address-book-service |
Diff against target: |
2318 lines (+905/-330) 22 files modified
3rd_party/folks/dummy/lib/dummy-full-persona.vala (+12/-1) 3rd_party/folks/dummy/lib/dummy-persona.vala (+33/-3) CMakeLists.txt (+1/-0) debian/changelog (+16/-0) debian/control (+1/-0) lib/CMakeLists.txt (+2/-0) lib/addressbook-adaptor.cpp (+10/-0) lib/addressbook-adaptor.h (+6/-0) lib/addressbook.cpp (+175/-72) lib/addressbook.h (+9/-3) lib/contacts-map.cpp (+44/-22) lib/contacts-map.h (+9/-3) lib/qindividual.cpp (+181/-137) lib/qindividual.h (+19/-6) lib/update-contact-request.cpp (+173/-72) lib/update-contact-request.h (+17/-7) lib/view.cpp (+3/-1) tests/unittest/CMakeLists.txt (+3/-0) tests/unittest/addressbook-test.cpp (+42/-2) tests/unittest/contact-link-test.cpp (+100/-0) tests/unittest/dummy-backend.cpp (+36/-1) tests/unittest/dummy-backend.h (+13/-0) |
To merge this branch: | bzr merge lp:~renatofilho/address-book-service/create-source |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot | continuous-integration | Approve | |
Ubuntu Phablet Team | Pending | ||
Review via email: mp+206826@code.launchpad.net |
This proposal has been superseded by a proposal from 2014-02-18.
Commit message
Implemented createSource functionality.
Description of the change
To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : | # |
review:
Approve
(continuous-integration)
- 100. By Renato Araujo Oliveira Filho
-
Merged parent branch.
- 101. By Renato Araujo Oliveira Filho
-
Merged parent branch.
- 102. By Renato Araujo Oliveira Filho
-
Merged mainline.
- 103. By Renato Araujo Oliveira Filho
-
Attempt to fix power pc build
- 104. By Renato Araujo Oliveira Filho
-
Attempt to fix powerpc tests.
- 105. By Renato Araujo Oliveira Filho
-
Attempt to fix powerpc tests.
- 106. By Renato Araujo Oliveira Filho
-
Moved DirtyContactsNotify class to a individual file and make it a QObject.
- 107. By Renato Araujo Oliveira Filho
-
Make sure that the temporary directory is created.
- 108. By Renato Araujo Oliveira Filho
-
Make the dummy backend start async in an attempt to fix powerPC tests.
- 109. By Renato Araujo Oliveira Filho
-
Added debug messages.
- 110. By Renato Araujo Oliveira Filho
-
Skip tests when running on PPC machines.
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/lib/dummy-full-persona.vala' | |||
2 | --- 3rd_party/folks/dummy/lib/dummy-full-persona.vala 2013-12-13 14:24:51 +0000 | |||
3 | +++ 3rd_party/folks/dummy/lib/dummy-full-persona.vala 2014-02-18 00:13:04 +0000 | |||
4 | @@ -72,6 +72,15 @@ | |||
5 | 72 | PostalAddressDetails, | 72 | PostalAddressDetails, |
6 | 73 | WebServiceDetails | 73 | WebServiceDetails |
7 | 74 | { | 74 | { |
8 | 75 | private const string[] _default_linkable_properties = | ||
9 | 76 | { | ||
10 | 77 | "im-addresses", | ||
11 | 78 | "email-addresses", | ||
12 | 79 | "local-ids", | ||
13 | 80 | "web-service-addresses" | ||
14 | 81 | }; | ||
15 | 82 | |||
16 | 83 | |||
17 | 75 | /** | 84 | /** |
18 | 76 | * Create a new ‘full’ persona. | 85 | * Create a new ‘full’ persona. |
19 | 77 | * | 86 | * |
20 | @@ -88,7 +97,8 @@ | |||
21 | 88 | * @since UNRELEASED | 97 | * @since UNRELEASED |
22 | 89 | */ | 98 | */ |
23 | 90 | public FullPersona (PersonaStore store, string contact_id, | 99 | public FullPersona (PersonaStore store, string contact_id, |
25 | 91 | bool is_user = false, string[] linkable_properties = {}) | 100 | bool is_user = false, |
26 | 101 | string[] linkable_properties = {}) | ||
27 | 92 | { | 102 | { |
28 | 93 | base (store, contact_id, is_user, linkable_properties); | 103 | base (store, contact_id, is_user, linkable_properties); |
29 | 94 | } | 104 | } |
30 | @@ -104,6 +114,7 @@ | |||
31 | 104 | this._groups_ro = this._groups.read_only_view; | 114 | this._groups_ro = this._groups.read_only_view; |
32 | 105 | this._roles_ro = this._roles.read_only_view; | 115 | this._roles_ro = this._roles.read_only_view; |
33 | 106 | this._anti_links_ro = this._anti_links.read_only_view; | 116 | this._anti_links_ro = this._anti_links.read_only_view; |
34 | 117 | this.update_linkable_properties(FullPersona._default_linkable_properties); | ||
35 | 107 | } | 118 | } |
36 | 108 | 119 | ||
37 | 109 | private HashMultiMap<string, WebServiceFieldDetails> _web_service_addresses = | 120 | private HashMultiMap<string, WebServiceFieldDetails> _web_service_addresses = |
38 | 110 | 121 | ||
39 | === modified file '3rd_party/folks/dummy/lib/dummy-persona.vala' | |||
40 | --- 3rd_party/folks/dummy/lib/dummy-persona.vala 2013-12-13 14:24:51 +0000 | |||
41 | +++ 3rd_party/folks/dummy/lib/dummy-persona.vala 2014-02-18 00:13:04 +0000 | |||
42 | @@ -53,7 +53,6 @@ | |||
43 | 53 | public class FolksDummy.Persona : Folks.Persona | 53 | public class FolksDummy.Persona : Folks.Persona |
44 | 54 | { | 54 | { |
45 | 55 | private string[] _linkable_properties = new string[0]; | 55 | private string[] _linkable_properties = new string[0]; |
46 | 56 | |||
47 | 57 | /** | 56 | /** |
48 | 58 | * {@inheritDoc} | 57 | * {@inheritDoc} |
49 | 59 | * | 58 | * |
50 | @@ -96,8 +95,8 @@ | |||
51 | 96 | * | 95 | * |
52 | 97 | * @since UNRELEASED | 96 | * @since UNRELEASED |
53 | 98 | */ | 97 | */ |
56 | 99 | public Persona (PersonaStore store, string contact_id, bool is_user = false, | 98 | public Persona (PersonaStore store, string contact_id, |
57 | 100 | string[] linkable_properties = {}) | 99 | bool is_user = false, string[] linkable_properties = {}) |
58 | 101 | { | 100 | { |
59 | 102 | var uid = Folks.Persona.build_uid (BACKEND_NAME, store.id, contact_id); | 101 | var uid = Folks.Persona.build_uid (BACKEND_NAME, store.id, contact_id); |
60 | 103 | var iid = store.id + ":" + contact_id; | 102 | var iid = store.id + ":" + contact_id; |
61 | @@ -233,6 +232,37 @@ | |||
62 | 233 | } | 232 | } |
63 | 234 | } | 233 | } |
64 | 235 | 234 | ||
65 | 235 | public void update_linkable_properties (string[] linkable_properties) | ||
66 | 236 | { | ||
67 | 237 | var new_linkable_properties = new HashSet<string> (); | ||
68 | 238 | new_linkable_properties.add_all_array(linkable_properties); | ||
69 | 239 | |||
70 | 240 | /* Check for changes. */ | ||
71 | 241 | var changed = false; | ||
72 | 242 | |||
73 | 243 | |||
74 | 244 | if (this._linkable_properties.length != new_linkable_properties.size) | ||
75 | 245 | { | ||
76 | 246 | changed = true; | ||
77 | 247 | } | ||
78 | 248 | else | ||
79 | 249 | { | ||
80 | 250 | foreach (var p in this._linkable_properties) | ||
81 | 251 | { | ||
82 | 252 | if (new_linkable_properties.contains (p) == false) | ||
83 | 253 | { | ||
84 | 254 | changed = true; | ||
85 | 255 | break; | ||
86 | 256 | } | ||
87 | 257 | } | ||
88 | 258 | } | ||
89 | 259 | if (changed == true) | ||
90 | 260 | { | ||
91 | 261 | this._linkable_properties = new_linkable_properties.to_array (); | ||
92 | 262 | this.notify_property ("linkable-properties"); | ||
93 | 263 | } | ||
94 | 264 | } | ||
95 | 265 | |||
96 | 236 | /** | 266 | /** |
97 | 237 | * Delay between property changes and notifications. | 267 | * Delay between property changes and notifications. |
98 | 238 | * | 268 | * |
99 | 239 | 269 | ||
100 | === modified file 'CMakeLists.txt' | |||
101 | --- CMakeLists.txt 2013-11-06 14:42:23 +0000 | |||
102 | +++ CMakeLists.txt 2014-02-18 00:13:04 +0000 | |||
103 | @@ -14,6 +14,7 @@ | |||
104 | 14 | pkg_check_modules(GLIB REQUIRED glib-2.0>=2.32) | 14 | pkg_check_modules(GLIB REQUIRED glib-2.0>=2.32) |
105 | 15 | pkg_check_modules(GIO REQUIRED gio-2.0>=2.32) | 15 | pkg_check_modules(GIO REQUIRED gio-2.0>=2.32) |
106 | 16 | pkg_check_modules(FOLKS REQUIRED folks>=0.9.0) | 16 | pkg_check_modules(FOLKS REQUIRED folks>=0.9.0) |
107 | 17 | pkg_check_modules(FOLKS_EDS REQUIRED folks-eds) | ||
108 | 17 | 18 | ||
109 | 18 | if(FOLKS_VERSION VERSION_LESS "0.9.5") | 19 | if(FOLKS_VERSION VERSION_LESS "0.9.5") |
110 | 19 | set(FOLKS_VERSION_LESS_THAN_0_9_5 "1") | 20 | set(FOLKS_VERSION_LESS_THAN_0_9_5 "1") |
111 | 20 | 21 | ||
112 | === modified file 'debian/changelog' | |||
113 | --- debian/changelog 2014-02-13 16:49:03 +0000 | |||
114 | +++ debian/changelog 2014-02-18 00:13:04 +0000 | |||
115 | @@ -1,3 +1,19 @@ | |||
116 | 1 | address-book-service (0.1.1) UNRELEASED; urgency=medium | ||
117 | 2 | |||
118 | 3 | * Avoid the persona to get linked automatically during the contact create or | ||
119 | 4 | edit. | ||
120 | 5 | * Create test to remove contacts functionality. | ||
121 | 6 | * Updated dummy backend code. | ||
122 | 7 | * Created test for add contacts. | ||
123 | 8 | * Rewrite unit test to work in a server/client way. | ||
124 | 9 | * Moved static address-book-service-lib to a different directory. | ||
125 | 10 | * Fork dummy backend from folks tree as a temporary solution before its get | ||
126 | 11 | release on folks. | ||
127 | 12 | * Check if query was destroyed on client side before delete it on the server | ||
128 | 13 | side. | ||
129 | 14 | |||
130 | 15 | -- Renato Araujo Oliveira Filho <renato@ubuntu> Fri, 24 Jan 2014 08:04:56 -0300 | ||
131 | 16 | |||
132 | 1 | address-book-service (0.1.0+14.04.20140213-0ubuntu1) trusty; urgency=low | 17 | address-book-service (0.1.0+14.04.20140213-0ubuntu1) trusty; urgency=low |
133 | 2 | 18 | ||
134 | 3 | [ Renato Araujo Oliveira Filho ] | 19 | [ Renato Araujo Oliveira Filho ] |
135 | 4 | 20 | ||
136 | === modified file 'debian/control' | |||
137 | --- debian/control 2013-10-30 00:19:00 +0000 | |||
138 | +++ debian/control 2014-02-18 00:13:04 +0000 | |||
139 | @@ -7,6 +7,7 @@ | |||
140 | 7 | debhelper (>= 9), | 7 | debhelper (>= 9), |
141 | 8 | gobject-introspection (>= 1.31.0-2~), | 8 | gobject-introspection (>= 1.31.0-2~), |
142 | 9 | libfolks-dev, | 9 | libfolks-dev, |
143 | 10 | libfolks-eds-dev, | ||
144 | 10 | libgee-0.8-dev (>= 0.8.4), | 11 | libgee-0.8-dev (>= 0.8.4), |
145 | 11 | qt5-default, | 12 | qt5-default, |
146 | 12 | qt5-qmake, | 13 | qt5-qmake, |
147 | 13 | 14 | ||
148 | === modified file 'lib/CMakeLists.txt' | |||
149 | --- lib/CMakeLists.txt 2013-10-30 19:07:49 +0000 | |||
150 | +++ lib/CMakeLists.txt 2014-02-18 00:13:04 +0000 | |||
151 | @@ -38,6 +38,7 @@ | |||
152 | 38 | ${GLIB_LIBRARIES} | 38 | ${GLIB_LIBRARIES} |
153 | 39 | ${GIO_LIBRARIES} | 39 | ${GIO_LIBRARIES} |
154 | 40 | ${FOLKS_LIBRARIES} | 40 | ${FOLKS_LIBRARIES} |
155 | 41 | ${FOLKS_EDS_LIBRARIES} | ||
156 | 41 | ) | 42 | ) |
157 | 42 | 43 | ||
158 | 43 | qt5_use_modules(${CONTACTS_SERVICE_LIB} Core Contacts DBus Versit) | 44 | qt5_use_modules(${CONTACTS_SERVICE_LIB} Core Contacts DBus Versit) |
159 | @@ -48,4 +49,5 @@ | |||
160 | 48 | ${GLIB_INCLUDE_DIRS} | 49 | ${GLIB_INCLUDE_DIRS} |
161 | 49 | ${GIO_INCLUDE_DIRS} | 50 | ${GIO_INCLUDE_DIRS} |
162 | 50 | ${FOLKS_INCLUDE_DIRS} | 51 | ${FOLKS_INCLUDE_DIRS} |
163 | 52 | ${FOLKS_EDS_INCLUDE_DIRS} | ||
164 | 51 | ) | 53 | ) |
165 | 52 | 54 | ||
166 | === modified file 'lib/addressbook-adaptor.cpp' | |||
167 | --- lib/addressbook-adaptor.cpp 2013-11-04 18:34:43 +0000 | |||
168 | +++ lib/addressbook-adaptor.cpp 2014-02-18 00:13:04 +0000 | |||
169 | @@ -54,6 +54,16 @@ | |||
170 | 54 | return Source(); | 54 | return Source(); |
171 | 55 | } | 55 | } |
172 | 56 | 56 | ||
173 | 57 | Source AddressBookAdaptor::createSource(const QString &sourceName, const QDBusMessage &message) | ||
174 | 58 | { | ||
175 | 59 | message.setDelayedReply(true); | ||
176 | 60 | QMetaObject::invokeMethod(m_addressBook, "createSource", | ||
177 | 61 | Qt::QueuedConnection, | ||
178 | 62 | Q_ARG(const QString&, sourceName), | ||
179 | 63 | Q_ARG(const QDBusMessage&, message)); | ||
180 | 64 | return Source(); | ||
181 | 65 | } | ||
182 | 66 | |||
183 | 57 | QString AddressBookAdaptor::createContact(const QString &contact, const QString &source, const QDBusMessage &message) | 67 | QString AddressBookAdaptor::createContact(const QString &contact, const QString &source, const QDBusMessage &message) |
184 | 58 | { | 68 | { |
185 | 59 | message.setDelayedReply(true); | 69 | message.setDelayedReply(true); |
186 | 60 | 70 | ||
187 | === modified file 'lib/addressbook-adaptor.h' | |||
188 | --- lib/addressbook-adaptor.h 2013-11-01 01:10:12 +0000 | |||
189 | +++ lib/addressbook-adaptor.h 2014-02-18 00:13:04 +0000 | |||
190 | @@ -62,6 +62,11 @@ | |||
191 | 62 | " <arg direction=\"out\" type=\"(sb)\"/>\n" | 62 | " <arg direction=\"out\" type=\"(sb)\"/>\n" |
192 | 63 | " <annotation value=\"Source\" name=\"com.trolltech.QtDBus.QtTypeName.Out0\"/>\n" | 63 | " <annotation value=\"Source\" name=\"com.trolltech.QtDBus.QtTypeName.Out0\"/>\n" |
193 | 64 | " </method>\n" | 64 | " </method>\n" |
194 | 65 | " <method name=\"createSource\">\n" | ||
195 | 66 | " <arg direction=\"in\" type=\"s\"/>\n" | ||
196 | 67 | " <arg direction=\"out\" type=\"(sb)\"/>\n" | ||
197 | 68 | " <annotation value=\"Source\" name=\"com.trolltech.QtDBus.QtTypeName.Out0\"/>\n" | ||
198 | 69 | " </method>\n" | ||
199 | 65 | " <method name=\"sortFields\">\n" | 70 | " <method name=\"sortFields\">\n" |
200 | 66 | " <arg direction=\"out\" type=\"as\"/>\n" | 71 | " <arg direction=\"out\" type=\"as\"/>\n" |
201 | 67 | " </method>\n" | 72 | " </method>\n" |
202 | @@ -103,6 +108,7 @@ | |||
203 | 103 | public Q_SLOTS: | 108 | public Q_SLOTS: |
204 | 104 | SourceList availableSources(const QDBusMessage &message); | 109 | SourceList availableSources(const QDBusMessage &message); |
205 | 105 | Source source(const QDBusMessage &message); | 110 | Source source(const QDBusMessage &message); |
206 | 111 | Source createSource(const QString &sourceName, const QDBusMessage &message); | ||
207 | 106 | QStringList sortFields(); | 112 | QStringList sortFields(); |
208 | 107 | QDBusObjectPath query(const QString &clause, const QString &sort, const QStringList &sources); | 113 | QDBusObjectPath query(const QString &clause, const QString &sort, const QStringList &sources); |
209 | 108 | int removeContacts(const QStringList &contactIds, const QDBusMessage &message); | 114 | int removeContacts(const QStringList &contactIds, const QDBusMessage &message); |
210 | 109 | 115 | ||
211 | === modified file 'lib/addressbook.cpp' | |||
212 | --- lib/addressbook.cpp 2013-11-05 19:26:25 +0000 | |||
213 | +++ lib/addressbook.cpp 2014-02-18 00:13:04 +0000 | |||
214 | @@ -31,6 +31,8 @@ | |||
215 | 31 | #include <signal.h> | 31 | #include <signal.h> |
216 | 32 | #include <sys/socket.h> | 32 | #include <sys/socket.h> |
217 | 33 | 33 | ||
218 | 34 | #include <folks/folks-eds.h> | ||
219 | 35 | |||
220 | 34 | //this timeout represents how long the server will wait for changes on the contact before notify the client | 36 | //this timeout represents how long the server will wait for changes on the contact before notify the client |
221 | 35 | #define NOTIFY_CONTACTS_TIMEOUT 500 | 37 | #define NOTIFY_CONTACTS_TIMEOUT 500 |
222 | 36 | 38 | ||
223 | @@ -38,6 +40,14 @@ | |||
224 | 38 | 40 | ||
225 | 39 | namespace | 41 | namespace |
226 | 40 | { | 42 | { |
227 | 43 | |||
228 | 44 | class CreateContactData | ||
229 | 45 | { | ||
230 | 46 | public: | ||
231 | 47 | QDBusMessage m_message; | ||
232 | 48 | galera::AddressBook *m_addressbook; | ||
233 | 49 | }; | ||
234 | 50 | |||
235 | 41 | class UpdateContactsData | 51 | class UpdateContactsData |
236 | 42 | { | 52 | { |
237 | 43 | public: | 53 | public: |
238 | @@ -58,6 +68,14 @@ | |||
239 | 58 | int m_sucessCount; | 68 | int m_sucessCount; |
240 | 59 | }; | 69 | }; |
241 | 60 | 70 | ||
242 | 71 | class CreateSourceData | ||
243 | 72 | { | ||
244 | 73 | public: | ||
245 | 74 | QString sourceName; | ||
246 | 75 | galera::AddressBook *m_addressbook; | ||
247 | 76 | QDBusMessage m_message; | ||
248 | 77 | }; | ||
249 | 78 | |||
250 | 61 | } | 79 | } |
251 | 62 | 80 | ||
252 | 63 | namespace galera | 81 | namespace galera |
253 | @@ -242,6 +260,37 @@ | |||
254 | 242 | return Source(); | 260 | return Source(); |
255 | 243 | } | 261 | } |
256 | 244 | 262 | ||
257 | 263 | Source AddressBook::createSource(const QString &sourceId, const QDBusMessage &message) | ||
258 | 264 | { | ||
259 | 265 | CreateSourceData *data = new CreateSourceData; | ||
260 | 266 | data->m_addressbook = this; | ||
261 | 267 | data->m_message = message; | ||
262 | 268 | data->sourceName = sourceId; | ||
263 | 269 | edsf_persona_store_create_address_book(sourceId.toUtf8().data(), | ||
264 | 270 | (GAsyncReadyCallback) AddressBook::createSourceDone, | ||
265 | 271 | data); | ||
266 | 272 | return Source(); | ||
267 | 273 | } | ||
268 | 274 | |||
269 | 275 | void AddressBook::createSourceDone(GObject *source, | ||
270 | 276 | GAsyncResult *res, | ||
271 | 277 | void *data) | ||
272 | 278 | { | ||
273 | 279 | CreateSourceData *cData = static_cast<CreateSourceData*>(data); | ||
274 | 280 | GError *error = 0; | ||
275 | 281 | Source src; | ||
276 | 282 | edsf_persona_store_create_address_book_finish(res, &error); | ||
277 | 283 | if (error) { | ||
278 | 284 | qWarning() << "Fail to create source" << error->message; | ||
279 | 285 | g_error_free(error); | ||
280 | 286 | } else { | ||
281 | 287 | src = Source(cData->sourceName, false); | ||
282 | 288 | } | ||
283 | 289 | QDBusMessage reply = cData->m_message.createReply(QVariant::fromValue<Source>(src)); | ||
284 | 290 | QDBusConnection::sessionBus().send(reply); | ||
285 | 291 | delete cData; | ||
286 | 292 | } | ||
287 | 293 | |||
288 | 245 | void AddressBook::getSource(const QDBusMessage &message, bool onlyTheDefault) | 294 | void AddressBook::getSource(const QDBusMessage &message, bool onlyTheDefault) |
289 | 246 | { | 295 | { |
290 | 247 | FolksBackendStore *backendStore = folks_backend_store_dup(); | 296 | FolksBackendStore *backendStore = folks_backend_store_dup(); |
291 | @@ -338,13 +387,15 @@ | |||
292 | 338 | if (!qcontact.isEmpty()) { | 387 | if (!qcontact.isEmpty()) { |
293 | 339 | GHashTable *details = QIndividual::parseDetails(qcontact); | 388 | GHashTable *details = QIndividual::parseDetails(qcontact); |
294 | 340 | //TOOD: lookup for source and use the correct store | 389 | //TOOD: lookup for source and use the correct store |
296 | 341 | QDBusMessage *cpy = new QDBusMessage(message); | 390 | CreateContactData *data = new CreateContactData; |
297 | 391 | data->m_message = message; | ||
298 | 392 | data->m_addressbook = this; | ||
299 | 342 | folks_individual_aggregator_add_persona_from_details(m_individualAggregator, | 393 | folks_individual_aggregator_add_persona_from_details(m_individualAggregator, |
300 | 343 | NULL, //parent | 394 | NULL, //parent |
301 | 344 | folks_individual_aggregator_get_primary_store(m_individualAggregator), | 395 | folks_individual_aggregator_get_primary_store(m_individualAggregator), |
302 | 345 | details, | 396 | details, |
303 | 346 | (GAsyncReadyCallback) createContactDone, | 397 | (GAsyncReadyCallback) createContactDone, |
305 | 347 | (void*) cpy); | 398 | (void*) data); |
306 | 348 | g_hash_table_destroy(details); | 399 | g_hash_table_destroy(details); |
307 | 349 | return ""; | 400 | return ""; |
308 | 350 | } | 401 | } |
309 | @@ -429,6 +480,28 @@ | |||
310 | 429 | } | 480 | } |
311 | 430 | } | 481 | } |
312 | 431 | 482 | ||
313 | 483 | void AddressBook::addAntiLinksDone(FolksAntiLinkable *antilinkable, | ||
314 | 484 | GAsyncResult *result, | ||
315 | 485 | void *data) | ||
316 | 486 | { | ||
317 | 487 | CreateContactData *createData = static_cast<CreateContactData*>(data); | ||
318 | 488 | QDBusMessage reply; | ||
319 | 489 | |||
320 | 490 | GError *error = 0; | ||
321 | 491 | folks_anti_linkable_change_anti_links_finish(antilinkable, result, &error); | ||
322 | 492 | if (error) { | ||
323 | 493 | qWarning() << "Fail to anti link pesona" << folks_persona_get_display_id(FOLKS_PERSONA(antilinkable)) << error->message; | ||
324 | 494 | reply = createData->m_message.createErrorReply("Fail to anti link pesona:", error->message); | ||
325 | 495 | g_error_free(error); | ||
326 | 496 | } else { | ||
327 | 497 | FolksIndividual *individual = folks_persona_get_individual(FOLKS_PERSONA(antilinkable)); | ||
328 | 498 | // return the result/contactId to the client | ||
329 | 499 | reply = createData->m_message.createReply(QString::fromUtf8(folks_individual_get_id(individual))); | ||
330 | 500 | } | ||
331 | 501 | QDBusConnection::sessionBus().send(reply); | ||
332 | 502 | delete createData; | ||
333 | 503 | } | ||
334 | 504 | |||
335 | 432 | QStringList AddressBook::sortFields() | 505 | QStringList AddressBook::sortFields() |
336 | 433 | { | 506 | { |
337 | 434 | return SortClause::supportedFields(); | 507 | return SortClause::supportedFields(); |
338 | @@ -455,25 +528,26 @@ | |||
339 | 455 | m_updateCommandResult = contacts; | 528 | m_updateCommandResult = contacts; |
340 | 456 | m_updateCommandPendingContacts << VCardParser::vcardToContact(contacts); | 529 | m_updateCommandPendingContacts << VCardParser::vcardToContact(contacts); |
341 | 457 | 530 | ||
344 | 458 | updateContactsDone(0, QString()); | 531 | updateContactsDone("", ""); |
343 | 459 | |||
345 | 460 | return QStringList(); | 532 | return QStringList(); |
346 | 461 | } | 533 | } |
347 | 462 | 534 | ||
349 | 463 | void AddressBook::updateContactsDone(galera::QIndividual *individual, const QString &error) | 535 | void AddressBook::updateContactsDone(const QString &contactId, |
350 | 536 | const QString &error) | ||
351 | 464 | { | 537 | { |
352 | 465 | Q_UNUSED(individual); | ||
353 | 466 | qDebug() << Q_FUNC_INFO; | 538 | qDebug() << Q_FUNC_INFO; |
354 | 467 | |||
355 | 468 | int currentContactIndex = m_updateCommandResult.size() - m_updateCommandPendingContacts.size() - 1; | 539 | int currentContactIndex = m_updateCommandResult.size() - m_updateCommandPendingContacts.size() - 1; |
356 | 469 | 540 | ||
357 | 470 | if (!error.isEmpty()) { | 541 | if (!error.isEmpty()) { |
358 | 471 | // update the result with the error | 542 | // update the result with the error |
359 | 472 | m_updateCommandResult[currentContactIndex] = error; | 543 | m_updateCommandResult[currentContactIndex] = error; |
361 | 473 | } else if (individual){ | 544 | } else if (!contactId.isEmpty()){ |
362 | 474 | // update the result with the new contact info | 545 | // update the result with the new contact info |
365 | 475 | m_updatedIds << individual->id(); | 546 | m_updatedIds << contactId; |
366 | 476 | QStringList newContacts = VCardParser::contactToVcard(QList<QContact>() << individual->contact()); | 547 | ContactEntry *entry = m_contacts->value(contactId); |
367 | 548 | Q_ASSERT(entry); | ||
368 | 549 | QContact contact = entry->individual()->contact(); | ||
369 | 550 | QStringList newContacts = VCardParser::contactToVcard(QList<QContact>() << contact); | ||
370 | 477 | if (newContacts.length() == 1) { | 551 | if (newContacts.length() == 1) { |
371 | 478 | m_updateCommandResult[currentContactIndex] = newContacts[0]; | 552 | m_updateCommandResult[currentContactIndex] = newContacts[0]; |
372 | 479 | } else { | 553 | } else { |
373 | @@ -485,12 +559,13 @@ | |||
374 | 485 | QContact newContact = m_updateCommandPendingContacts.takeFirst(); | 559 | QContact newContact = m_updateCommandPendingContacts.takeFirst(); |
375 | 486 | ContactEntry *entry = m_contacts->value(newContact.detail<QContactGuid>().guid()); | 560 | ContactEntry *entry = m_contacts->value(newContact.detail<QContactGuid>().guid()); |
376 | 487 | if (entry) { | 561 | if (entry) { |
378 | 488 | entry->individual()->update(newContact, this, SLOT(updateContactsDone(galera::QIndividual*,QString))); | 562 | entry->individual()->update(newContact, this, |
379 | 563 | SLOT(updateContactsDone(QString,QString))); | ||
380 | 489 | } else { | 564 | } else { |
382 | 490 | updateContactsDone(0, "Contact not found!"); | 565 | updateContactsDone("", "Contact not found!"); |
383 | 491 | } | 566 | } |
384 | 492 | } else { | 567 | } else { |
386 | 493 | folks_persona_store_flush(folks_individual_aggregator_get_primary_store(m_individualAggregator), 0, 0); | 568 | |
387 | 494 | QDBusMessage reply = m_updateCommandReplyMessage.createReply(m_updateCommandResult); | 569 | QDBusMessage reply = m_updateCommandReplyMessage.createReply(m_updateCommandResult); |
388 | 495 | QDBusConnection::sessionBus().send(reply); | 570 | QDBusConnection::sessionBus().send(reply); |
389 | 496 | 571 | ||
390 | @@ -504,17 +579,13 @@ | |||
391 | 504 | } | 579 | } |
392 | 505 | } | 580 | } |
393 | 506 | 581 | ||
394 | 507 | |||
395 | 508 | QString AddressBook::removeContact(FolksIndividual *individual) | 582 | QString AddressBook::removeContact(FolksIndividual *individual) |
396 | 509 | { | 583 | { |
405 | 510 | if (m_contacts->contains(individual)) { | 584 | QString contactId = QString::fromUtf8(folks_individual_get_id(individual)); |
406 | 511 | ContactEntry *ci = m_contacts->take(individual); | 585 | ContactEntry *ci = m_contacts->take(contactId); |
407 | 512 | if (ci) { | 586 | if (ci) { |
408 | 513 | QString id = QString::fromUtf8(folks_individual_get_id(individual)); | 587 | delete ci; |
409 | 514 | qDebug() << "Remove contact" << id; | 588 | return contactId; |
402 | 515 | delete ci; | ||
403 | 516 | return id; | ||
404 | 517 | } | ||
410 | 518 | } | 589 | } |
411 | 519 | return QString(); | 590 | return QString(); |
412 | 520 | } | 591 | } |
413 | @@ -526,7 +597,6 @@ | |||
414 | 526 | if (entry) { | 597 | if (entry) { |
415 | 527 | entry->individual()->setIndividual(individual); | 598 | entry->individual()->setIndividual(individual); |
416 | 528 | } else { | 599 | } else { |
417 | 529 | Q_ASSERT(!m_contacts->contains(individual)); | ||
418 | 530 | QIndividual *i = new QIndividual(individual, m_individualAggregator); | 600 | QIndividual *i = new QIndividual(individual, m_individualAggregator); |
419 | 531 | i->addListener(this, SLOT(individualChanged(QIndividual*))); | 601 | i->addListener(this, SLOT(individualChanged(QIndividual*))); |
420 | 532 | m_contacts->insert(new ContactEntry(i)); | 602 | m_contacts->insert(new ContactEntry(i)); |
421 | @@ -540,51 +610,72 @@ | |||
422 | 540 | AddressBook *self) | 610 | AddressBook *self) |
423 | 541 | { | 611 | { |
424 | 542 | qDebug() << Q_FUNC_INFO; | 612 | qDebug() << Q_FUNC_INFO; |
459 | 543 | QStringList removedIds; | 613 | Q_UNUSED(individualAggregator); |
460 | 544 | QStringList addedIds; | 614 | |
461 | 545 | 615 | QSet<QString> removedIds; | |
462 | 546 | GeeIterator *iter; | 616 | QSet<QString> addedIds; |
463 | 547 | GeeSet *removed = gee_multi_map_get_keys(changes); | 617 | QSet<QString> updatedIds; |
464 | 548 | GeeCollection *added = gee_multi_map_get_values(changes); | 618 | |
465 | 549 | 619 | GeeSet *keys = gee_multi_map_get_keys(changes); | |
466 | 550 | iter = gee_iterable_iterator(GEE_ITERABLE(added)); | 620 | GeeIterator *iter = gee_iterable_iterator(GEE_ITERABLE(keys)); |
467 | 551 | while(gee_iterator_next(iter)) { | 621 | |
468 | 552 | FolksIndividual *individual = FOLKS_INDIVIDUAL(gee_iterator_get(iter)); | 622 | while(gee_iterator_next(iter)) { |
469 | 553 | if (individual) { | 623 | FolksIndividual *individualKey = FOLKS_INDIVIDUAL(gee_iterator_get(iter)); |
470 | 554 | // add contact to the map | 624 | GeeCollection *values = gee_multi_map_get(changes, individualKey); |
471 | 555 | addedIds << self->addContact(individual); | 625 | GeeIterator *iterV; |
472 | 556 | g_object_unref(individual); | 626 | |
473 | 557 | } | 627 | iterV = gee_iterable_iterator(GEE_ITERABLE(values)); |
474 | 558 | } | 628 | while(gee_iterator_next(iterV)) { |
475 | 559 | g_object_unref (iter); | 629 | FolksIndividual *individualValue = FOLKS_INDIVIDUAL(gee_iterator_get(iterV)); |
476 | 560 | 630 | ||
477 | 561 | 631 | // contact added | |
478 | 562 | iter = gee_iterable_iterator(GEE_ITERABLE(removed)); | 632 | if (individualKey == 0) { |
479 | 563 | while(gee_iterator_next(iter)) { | 633 | addedIds << self->addContact(individualValue); |
480 | 564 | FolksIndividual *individual = FOLKS_INDIVIDUAL(gee_iterator_get(iter)); | 634 | } else if (individualValue != 0){ |
481 | 565 | if (individual) { | 635 | qDebug() << "Link changes"; |
482 | 566 | QString id = QString::fromUtf8(folks_individual_get_id(individual)); | 636 | QString idValue = QString::fromUtf8(folks_individual_get_id(individualValue)); |
483 | 567 | if (!addedIds.contains(id)) { | 637 | if (self->m_contacts->value(idValue)) { |
484 | 568 | // delete from contact map | 638 | updatedIds << self->addContact(individualValue); |
485 | 569 | removedIds << self->removeContact(individual); | 639 | } else { |
486 | 570 | } | 640 | addedIds << self->addContact(individualValue); |
487 | 571 | g_object_unref(individual); | 641 | } |
488 | 572 | } | 642 | } |
489 | 573 | } | 643 | |
490 | 574 | g_object_unref (iter); | 644 | if (individualValue) { |
491 | 575 | 645 | g_object_unref(individualValue); | |
492 | 576 | //TODO: check for linked and unliked contacts | 646 | } |
493 | 647 | } | ||
494 | 648 | |||
495 | 649 | g_object_unref(iterV); | ||
496 | 650 | g_object_unref(values); | ||
497 | 651 | |||
498 | 652 | if (individualKey) { | ||
499 | 653 | QString id = QString::fromUtf8(folks_individual_get_id(individualKey)); | ||
500 | 654 | if (!addedIds.contains(id) && | ||
501 | 655 | !updatedIds.contains(id)) { | ||
502 | 656 | removedIds << self->removeContact(individualKey); | ||
503 | 657 | } | ||
504 | 658 | g_object_unref(individualKey); | ||
505 | 659 | } | ||
506 | 660 | } | ||
507 | 661 | |||
508 | 662 | g_object_unref(keys); | ||
509 | 663 | |||
510 | 577 | if (!removedIds.isEmpty() && self->m_ready) { | 664 | if (!removedIds.isEmpty() && self->m_ready) { |
512 | 578 | Q_EMIT self->m_adaptor->contactsRemoved(removedIds); | 665 | Q_EMIT self->m_adaptor->contactsRemoved(removedIds.toList()); |
513 | 579 | } | 666 | } |
514 | 580 | 667 | ||
515 | 581 | if (!addedIds.isEmpty() && self->m_ready) { | 668 | if (!addedIds.isEmpty() && self->m_ready) { |
521 | 582 | Q_EMIT self->m_adaptor->contactsAdded(addedIds); | 669 | Q_EMIT self->m_adaptor->contactsAdded(addedIds.toList()); |
522 | 583 | } | 670 | } |
523 | 584 | 671 | ||
524 | 585 | g_object_unref(added); | 672 | if (!updatedIds.isEmpty() && self->m_ready) { |
525 | 586 | g_object_unref(removed); | 673 | Q_EMIT self->m_adaptor->contactsUpdated(updatedIds.toList()); |
526 | 674 | } | ||
527 | 675 | |||
528 | 587 | qDebug() << "Added" << addedIds; | 676 | qDebug() << "Added" << addedIds; |
529 | 677 | qDebug() << "Removed" << removedIds; | ||
530 | 678 | qDebug() << "Changed" << updatedIds; | ||
531 | 588 | } | 679 | } |
532 | 589 | 680 | ||
533 | 590 | void AddressBook::prepareFolksDone(GObject *source, | 681 | void AddressBook::prepareFolksDone(GObject *source, |
534 | @@ -598,29 +689,41 @@ | |||
535 | 598 | 689 | ||
536 | 599 | void AddressBook::createContactDone(FolksIndividualAggregator *individualAggregator, | 690 | void AddressBook::createContactDone(FolksIndividualAggregator *individualAggregator, |
537 | 600 | GAsyncResult *res, | 691 | GAsyncResult *res, |
539 | 601 | QDBusMessage *msg) | 692 | void *data) |
540 | 602 | { | 693 | { |
542 | 603 | qDebug() << "Create Contact Done" << msg; | 694 | CreateContactData *createData = static_cast<CreateContactData*>(data); |
543 | 695 | |||
544 | 604 | FolksPersona *persona; | 696 | FolksPersona *persona; |
545 | 605 | GError *error = NULL; | 697 | GError *error = NULL; |
546 | 606 | QDBusMessage reply; | 698 | QDBusMessage reply; |
547 | 607 | persona = folks_individual_aggregator_add_persona_from_details_finish(individualAggregator, res, &error); | 699 | persona = folks_individual_aggregator_add_persona_from_details_finish(individualAggregator, res, &error); |
548 | 608 | if (error != NULL) { | 700 | if (error != NULL) { |
549 | 609 | qWarning() << "Failed to create individual from contact:" << error->message; | 701 | qWarning() << "Failed to create individual from contact:" << error->message; |
551 | 610 | reply = msg->createErrorReply("Failed to create individual from contact", error->message); | 702 | reply = createData->m_message.createErrorReply("Failed to create individual from contact", error->message); |
552 | 611 | g_clear_error(&error); | 703 | g_clear_error(&error); |
553 | 612 | } else if (persona == NULL) { | 704 | } else if (persona == NULL) { |
554 | 613 | qWarning() << "Failed to create individual from contact: Persona already exists"; | 705 | qWarning() << "Failed to create individual from contact: Persona already exists"; |
556 | 614 | reply = msg->createErrorReply("Failed to create individual from contact", "Contact already exists"); | 706 | reply = createData->m_message.createErrorReply("Failed to create individual from contact", "Contact already exists"); |
557 | 707 | } else if (QIndividual::autoLinkEnabled()){ | ||
558 | 708 | FolksIndividual *individual = folks_persona_get_individual(persona); | ||
559 | 709 | reply = createData->m_message.createReply(QString::fromUtf8(folks_individual_get_id(individual))); | ||
560 | 615 | } else { | 710 | } else { |
565 | 616 | qDebug() << "Persona created:" << persona; | 711 | // avoid the new persona get linked |
566 | 617 | FolksIndividual *individual; | 712 | GeeHashSet *antiLinks = gee_hash_set_new(G_TYPE_STRING, |
567 | 618 | individual = folks_persona_get_individual(persona); | 713 | (GBoxedCopyFunc) g_strdup, |
568 | 619 | reply = msg->createReply(QString::fromUtf8(folks_individual_get_id(individual))); | 714 | g_free, |
569 | 715 | NULL, NULL, NULL, NULL, NULL, NULL); | ||
570 | 716 | gee_collection_add(GEE_COLLECTION(antiLinks), "*"); | ||
571 | 717 | folks_anti_linkable_change_anti_links(FOLKS_ANTI_LINKABLE(persona), | ||
572 | 718 | GEE_SET(antiLinks), | ||
573 | 719 | (GAsyncReadyCallback) addAntiLinksDone, | ||
574 | 720 | data); | ||
575 | 721 | g_object_unref(antiLinks); | ||
576 | 722 | return; | ||
577 | 620 | } | 723 | } |
578 | 621 | //TODO: use dbus connection | 724 | //TODO: use dbus connection |
579 | 622 | QDBusConnection::sessionBus().send(reply); | 725 | QDBusConnection::sessionBus().send(reply); |
581 | 623 | delete msg; | 726 | delete createData; |
582 | 624 | } | 727 | } |
583 | 625 | 728 | ||
584 | 626 | void AddressBook::isQuiescentChanged(GObject *source, GParamSpec *param, AddressBook *self) | 729 | void AddressBook::isQuiescentChanged(GObject *source, GParamSpec *param, AddressBook *self) |
585 | 627 | 730 | ||
586 | === modified file 'lib/addressbook.h' | |||
587 | --- lib/addressbook.h 2013-11-01 13:15:51 +0000 | |||
588 | +++ lib/addressbook.h 2014-02-18 00:13:04 +0000 | |||
589 | @@ -69,10 +69,11 @@ | |||
590 | 69 | void shutdown(); | 69 | void shutdown(); |
591 | 70 | SourceList availableSources(const QDBusMessage &message); | 70 | SourceList availableSources(const QDBusMessage &message); |
592 | 71 | Source source(const QDBusMessage &message); | 71 | Source source(const QDBusMessage &message); |
593 | 72 | Source createSource(const QString &sourceId, const QDBusMessage &message); | ||
594 | 72 | QString createContact(const QString &contact, const QString &source, const QDBusMessage &message); | 73 | QString createContact(const QString &contact, const QString &source, const QDBusMessage &message); |
595 | 73 | int removeContacts(const QStringList &contactIds, const QDBusMessage &message); | 74 | int removeContacts(const QStringList &contactIds, const QDBusMessage &message); |
596 | 74 | QStringList updateContacts(const QStringList &contacts, const QDBusMessage &message); | 75 | QStringList updateContacts(const QStringList &contacts, const QDBusMessage &message); |
598 | 75 | void updateContactsDone(galera::QIndividual *individual, const QString &error); | 76 | void updateContactsDone(const QString &contactId, const QString &error); |
599 | 76 | 77 | ||
600 | 77 | private Q_SLOTS: | 78 | private Q_SLOTS: |
601 | 78 | void viewClosed(); | 79 | void viewClosed(); |
602 | @@ -139,11 +140,16 @@ | |||
603 | 139 | AddressBook *self); | 140 | AddressBook *self); |
604 | 140 | static void createContactDone(FolksIndividualAggregator *individualAggregator, | 141 | static void createContactDone(FolksIndividualAggregator *individualAggregator, |
605 | 141 | GAsyncResult *res, | 142 | GAsyncResult *res, |
607 | 142 | QDBusMessage *msg); | 143 | void *data); |
608 | 143 | static void removeContactDone(FolksIndividualAggregator *individualAggregator, | 144 | static void removeContactDone(FolksIndividualAggregator *individualAggregator, |
609 | 144 | GAsyncResult *result, | 145 | GAsyncResult *result, |
610 | 145 | void *data); | 146 | void *data); |
612 | 146 | 147 | static void addAntiLinksDone(FolksAntiLinkable *antilinkable, | |
613 | 148 | GAsyncResult *result, | ||
614 | 149 | void *data); | ||
615 | 150 | static void createSourceDone(GObject *source, | ||
616 | 151 | GAsyncResult *res, | ||
617 | 152 | void *data); | ||
618 | 147 | friend class DirtyContactsNotify; | 153 | friend class DirtyContactsNotify; |
619 | 148 | }; | 154 | }; |
620 | 149 | 155 | ||
621 | 150 | 156 | ||
622 | === modified file 'lib/contacts-map.cpp' | |||
623 | --- lib/contacts-map.cpp 2013-11-06 18:49:59 +0000 | |||
624 | +++ lib/contacts-map.cpp 2014-02-18 00:13:04 +0000 | |||
625 | @@ -33,7 +33,7 @@ | |||
626 | 33 | 33 | ||
627 | 34 | ContactEntry::~ContactEntry() | 34 | ContactEntry::~ContactEntry() |
628 | 35 | { | 35 | { |
630 | 36 | delete m_individual; | 36 | delete m_individual; |
631 | 37 | } | 37 | } |
632 | 38 | 38 | ||
633 | 39 | QIndividual *ContactEntry::individual() const | 39 | QIndividual *ContactEntry::individual() const |
634 | @@ -52,11 +52,6 @@ | |||
635 | 52 | clear(); | 52 | clear(); |
636 | 53 | } | 53 | } |
637 | 54 | 54 | ||
638 | 55 | ContactEntry *ContactsMap::value(FolksIndividual *individual) const | ||
639 | 56 | { | ||
640 | 57 | return m_individualsToEntry[individual]; | ||
641 | 58 | } | ||
642 | 59 | |||
643 | 60 | ContactEntry *ContactsMap::value(const QString &id) const | 55 | ContactEntry *ContactsMap::value(const QString &id) const |
644 | 61 | { | 56 | { |
645 | 62 | return m_idToEntry[id]; | 57 | return m_idToEntry[id]; |
646 | @@ -64,32 +59,33 @@ | |||
647 | 64 | 59 | ||
648 | 65 | ContactEntry *ContactsMap::take(FolksIndividual *individual) | 60 | ContactEntry *ContactsMap::take(FolksIndividual *individual) |
649 | 66 | { | 61 | { |
654 | 67 | if (m_individualsToEntry.remove(individual)) { | 62 | QString contactId = QString::fromUtf8(folks_individual_get_id(individual)); |
655 | 68 | return m_idToEntry.take(folks_individual_get_id(individual)); | 63 | return take(contactId); |
656 | 69 | } | 64 | } |
657 | 70 | return 0; | 65 | |
658 | 66 | ContactEntry *ContactsMap::take(const QString &id) | ||
659 | 67 | { | ||
660 | 68 | QMutexLocker locker(&m_mutex); | ||
661 | 69 | return m_idToEntry.take(id); | ||
662 | 71 | } | 70 | } |
663 | 72 | 71 | ||
664 | 73 | void ContactsMap::remove(const QString &id) | 72 | void ContactsMap::remove(const QString &id) |
665 | 74 | { | 73 | { |
667 | 75 | ContactEntry *entry = m_idToEntry[id]; | 74 | QMutexLocker locker(&m_mutex); |
668 | 75 | ContactEntry *entry = m_idToEntry.value(id,0); | ||
669 | 76 | if (entry) { | 76 | if (entry) { |
670 | 77 | m_individualsToEntry.remove(entry->individual()->individual()); | ||
671 | 78 | m_idToEntry.remove(id); | 77 | m_idToEntry.remove(id); |
672 | 79 | delete entry; | 78 | delete entry; |
673 | 80 | } | 79 | } |
674 | 81 | } | 80 | } |
675 | 82 | 81 | ||
676 | 83 | bool ContactsMap::contains(FolksIndividual *individual) const | ||
677 | 84 | { | ||
678 | 85 | return m_individualsToEntry.contains(individual); | ||
679 | 86 | } | ||
680 | 87 | |||
681 | 88 | void ContactsMap::insert(ContactEntry *entry) | 82 | void ContactsMap::insert(ContactEntry *entry) |
682 | 89 | { | 83 | { |
683 | 84 | QMutexLocker locker(&m_mutex); | ||
684 | 90 | FolksIndividual *fIndividual = entry->individual()->individual(); | 85 | FolksIndividual *fIndividual = entry->individual()->individual(); |
687 | 91 | m_idToEntry.insert(folks_individual_get_id(fIndividual), entry); | 86 | if (fIndividual) { |
688 | 92 | m_individualsToEntry.insert(fIndividual, entry); | 87 | m_idToEntry.insert(folks_individual_get_id(fIndividual), entry); |
689 | 88 | } | ||
690 | 93 | } | 89 | } |
691 | 94 | 90 | ||
692 | 95 | int ContactsMap::size() const | 91 | int ContactsMap::size() const |
693 | @@ -99,16 +95,25 @@ | |||
694 | 99 | 95 | ||
695 | 100 | void ContactsMap::clear() | 96 | void ContactsMap::clear() |
696 | 101 | { | 97 | { |
697 | 98 | QMutexLocker locker(&m_mutex); | ||
698 | 102 | QList<ContactEntry*> entries = m_idToEntry.values(); | 99 | QList<ContactEntry*> entries = m_idToEntry.values(); |
699 | 103 | m_idToEntry.clear(); | 100 | m_idToEntry.clear(); |
700 | 104 | m_individualsToEntry.clear(); | ||
701 | 105 | |||
702 | 106 | qDeleteAll(entries); | 101 | qDeleteAll(entries); |
703 | 107 | } | 102 | } |
704 | 108 | 103 | ||
705 | 104 | void ContactsMap::lock() | ||
706 | 105 | { | ||
707 | 106 | m_mutex.lock(); | ||
708 | 107 | } | ||
709 | 108 | |||
710 | 109 | void ContactsMap::unlock() | ||
711 | 110 | { | ||
712 | 111 | m_mutex.unlock(); | ||
713 | 112 | } | ||
714 | 113 | |||
715 | 109 | QList<ContactEntry*> ContactsMap::values() const | 114 | QList<ContactEntry*> ContactsMap::values() const |
716 | 110 | { | 115 | { |
718 | 111 | return m_individualsToEntry.values(); | 116 | return m_idToEntry.values(); |
719 | 112 | } | 117 | } |
720 | 113 | 118 | ||
721 | 114 | ContactEntry *ContactsMap::valueFromVCard(const QString &vcard) const | 119 | ContactEntry *ContactsMap::valueFromVCard(const QString &vcard) const |
722 | @@ -125,4 +130,21 @@ | |||
723 | 125 | return 0; | 130 | return 0; |
724 | 126 | } | 131 | } |
725 | 127 | 132 | ||
726 | 133 | bool ContactsMap::contains(FolksIndividual *individual) const | ||
727 | 134 | { | ||
728 | 135 | QString contactId = QString::fromUtf8(folks_individual_get_id(individual)); | ||
729 | 136 | return contains(contactId); | ||
730 | 137 | } | ||
731 | 138 | |||
732 | 139 | bool ContactsMap::contains(const QString &id) const | ||
733 | 140 | { | ||
734 | 141 | return m_idToEntry.contains(id); | ||
735 | 142 | } | ||
736 | 143 | |||
737 | 144 | ContactEntry *ContactsMap::value(FolksIndividual *individual) const | ||
738 | 145 | { | ||
739 | 146 | QString contactId = QString::fromUtf8(folks_individual_get_id(individual)); | ||
740 | 147 | return m_idToEntry.value(contactId, 0); | ||
741 | 148 | } | ||
742 | 149 | |||
743 | 128 | } //namespace | 150 | } //namespace |
744 | 129 | 151 | ||
745 | === modified file 'lib/contacts-map.h' | |||
746 | --- lib/contacts-map.h 2013-11-05 00:25:03 +0000 | |||
747 | +++ lib/contacts-map.h 2014-02-18 00:13:04 +0000 | |||
748 | @@ -22,6 +22,7 @@ | |||
749 | 22 | #include <QtCore/QString> | 22 | #include <QtCore/QString> |
750 | 23 | #include <QtCore/QStringList> | 23 | #include <QtCore/QStringList> |
751 | 24 | #include <QtCore/QHash> | 24 | #include <QtCore/QHash> |
752 | 25 | #include <QtCore/QMutex> | ||
753 | 25 | 26 | ||
754 | 26 | #include <folks/folks.h> | 27 | #include <folks/folks.h> |
755 | 27 | #include <glib.h> | 28 | #include <glib.h> |
756 | @@ -57,20 +58,25 @@ | |||
757 | 57 | ContactEntry *valueFromVCard(const QString &vcard) const; | 58 | ContactEntry *valueFromVCard(const QString &vcard) const; |
758 | 58 | 59 | ||
759 | 59 | bool contains(FolksIndividual *individual) const; | 60 | bool contains(FolksIndividual *individual) const; |
760 | 61 | bool contains(const QString &id) const; | ||
761 | 62 | |||
762 | 60 | ContactEntry *value(FolksIndividual *individual) const; | 63 | ContactEntry *value(FolksIndividual *individual) const; |
763 | 61 | ContactEntry *value(const QString &id) const; | 64 | ContactEntry *value(const QString &id) const; |
764 | 65 | |||
765 | 62 | ContactEntry *take(FolksIndividual *individual); | 66 | ContactEntry *take(FolksIndividual *individual); |
766 | 67 | ContactEntry *take(const QString &id); | ||
767 | 68 | |||
768 | 63 | void remove(const QString &id); | 69 | void remove(const QString &id); |
769 | 64 | void insert(ContactEntry *entry); | 70 | void insert(ContactEntry *entry); |
770 | 65 | int size() const; | 71 | int size() const; |
771 | 66 | void clear(); | 72 | void clear(); |
774 | 67 | 73 | void lock(); | |
775 | 68 | 74 | void unlock(); | |
776 | 69 | QList<ContactEntry*> values() const; | 75 | QList<ContactEntry*> values() const; |
777 | 70 | 76 | ||
778 | 71 | private: | 77 | private: |
779 | 72 | QHash<FolksIndividual *, ContactEntry*> m_individualsToEntry; | ||
780 | 73 | QHash<QString, ContactEntry*> m_idToEntry; | 78 | QHash<QString, ContactEntry*> m_idToEntry; |
781 | 79 | QMutex m_mutex; | ||
782 | 74 | }; | 80 | }; |
783 | 75 | 81 | ||
784 | 76 | } //namespace | 82 | } //namespace |
785 | 77 | 83 | ||
786 | === modified file 'lib/qindividual.cpp' | |||
787 | --- lib/qindividual.cpp 2013-11-05 00:25:03 +0000 | |||
788 | +++ lib/qindividual.cpp 2014-02-18 00:13:04 +0000 | |||
789 | @@ -118,15 +118,15 @@ | |||
790 | 118 | 118 | ||
791 | 119 | namespace galera | 119 | namespace galera |
792 | 120 | { | 120 | { |
793 | 121 | bool QIndividual::m_autoLink = false; | ||
794 | 121 | 122 | ||
795 | 122 | QIndividual::QIndividual(FolksIndividual *individual, FolksIndividualAggregator *aggregator) | 123 | QIndividual::QIndividual(FolksIndividual *individual, FolksIndividualAggregator *aggregator) |
798 | 123 | : m_individual(individual), | 124 | : m_individual(0), |
797 | 124 | m_primaryPersona(0), | ||
799 | 125 | m_aggregator(aggregator), | 125 | m_aggregator(aggregator), |
801 | 126 | m_contact(0) | 126 | m_contact(0), |
802 | 127 | m_currentUpdate(0) | ||
803 | 127 | { | 128 | { |
806 | 128 | g_object_ref(m_individual); | 129 | setIndividual(individual); |
805 | 129 | updateContact(); | ||
807 | 130 | } | 130 | } |
808 | 131 | 131 | ||
809 | 132 | void QIndividual::notifyUpdate() | 132 | void QIndividual::notifyUpdate() |
810 | @@ -139,20 +139,20 @@ | |||
811 | 139 | 139 | ||
812 | 140 | QIndividual::~QIndividual() | 140 | QIndividual::~QIndividual() |
813 | 141 | { | 141 | { |
816 | 142 | if (m_contact) { | 142 | if (m_currentUpdate) { |
817 | 143 | delete m_contact; | 143 | m_currentUpdate->disconnect(m_updateConnection); |
818 | 144 | // this will leave the update object to destroy itself | ||
819 | 145 | // this is necessary because the individual can be destroyed during a update | ||
820 | 146 | // Eg. If the individual get linked | ||
821 | 147 | m_currentUpdate->deatach(); | ||
822 | 148 | m_currentUpdate = 0; | ||
823 | 144 | } | 149 | } |
826 | 145 | Q_ASSERT(m_individual); | 150 | clear(); |
825 | 146 | g_object_unref(m_individual); | ||
827 | 147 | } | 151 | } |
828 | 148 | 152 | ||
829 | 149 | QString QIndividual::id() const | 153 | QString QIndividual::id() const |
830 | 150 | { | 154 | { |
836 | 151 | if (m_individual) { | 155 | return m_id; |
832 | 152 | return QString::fromUtf8(folks_individual_get_id(m_individual)); | ||
833 | 153 | } else { | ||
834 | 154 | return ""; | ||
835 | 155 | } | ||
837 | 156 | } | 156 | } |
838 | 157 | 157 | ||
839 | 158 | QtContacts::QContactDetail QIndividual::getUid() const | 158 | QtContacts::QContactDetail QIndividual::getUid() const |
840 | @@ -167,25 +167,17 @@ | |||
841 | 167 | 167 | ||
842 | 168 | QList<QtContacts::QContactDetail> QIndividual::getClientPidMap() const | 168 | QList<QtContacts::QContactDetail> QIndividual::getClientPidMap() const |
843 | 169 | { | 169 | { |
844 | 170 | QList<QtContacts::QContactDetail> details; | ||
845 | 171 | int index = 1; | 170 | int index = 1; |
851 | 172 | GeeSet *personas = folks_individual_get_personas(m_individual); | 171 | QList<QContactDetail> details; |
847 | 173 | if (!personas) { | ||
848 | 174 | return details; | ||
849 | 175 | } | ||
850 | 176 | GeeIterator *iter = gee_iterable_iterator(GEE_ITERABLE(personas)); | ||
852 | 177 | 172 | ||
854 | 178 | while(gee_iterator_next(iter)) { | 173 | Q_FOREACH(const QString id, m_personas.keys()) { |
855 | 179 | QContactExtendedDetail detail; | 174 | QContactExtendedDetail detail; |
857 | 180 | FolksPersona *persona = FOLKS_PERSONA(gee_iterator_get(iter)); | 175 | |
858 | 181 | detail.setName("CLIENTPIDMAP"); | 176 | detail.setName("CLIENTPIDMAP"); |
859 | 182 | detail.setValue(QContactExtendedDetail::FieldData, index++); | 177 | detail.setValue(QContactExtendedDetail::FieldData, index++); |
861 | 183 | detail.setValue(QContactExtendedDetail::FieldData + 1, QString::fromUtf8(folks_persona_get_uid(persona))); | 178 | detail.setValue(QContactExtendedDetail::FieldData + 1, id); |
862 | 184 | details << detail; | 179 | details << detail; |
863 | 185 | g_object_unref(persona); | ||
864 | 186 | } | 180 | } |
865 | 187 | |||
866 | 188 | g_object_unref(iter); | ||
867 | 189 | return details; | 181 | return details; |
868 | 190 | } | 182 | } |
869 | 191 | 183 | ||
870 | @@ -360,9 +352,13 @@ | |||
871 | 360 | g_free(uri); | 352 | g_free(uri); |
872 | 361 | g_object_unref(cache); | 353 | g_object_unref(cache); |
873 | 362 | } | 354 | } |
874 | 355 | // Avoid to set a empty url | ||
875 | 356 | if (url.isEmpty()) { | ||
876 | 357 | return avatar; | ||
877 | 358 | } | ||
878 | 363 | avatar.setImageUrl(QUrl(url)); | 359 | avatar.setImageUrl(QUrl(url)); |
879 | 360 | avatar.setDetailUri(QString("%1.1").arg(index)); | ||
880 | 364 | } | 361 | } |
881 | 365 | avatar.setDetailUri(QString("%1.1").arg(index)); | ||
882 | 366 | return avatar; | 362 | return avatar; |
883 | 367 | } | 363 | } |
884 | 368 | 364 | ||
885 | @@ -744,40 +740,64 @@ | |||
886 | 744 | 740 | ||
887 | 745 | QtContacts::QContact &QIndividual::contact() | 741 | QtContacts::QContact &QIndividual::contact() |
888 | 746 | { | 742 | { |
890 | 747 | if (!m_contact) { | 743 | if (!m_contact && m_individual) { |
891 | 744 | updatePersonas(); | ||
892 | 748 | updateContact(); | 745 | updateContact(); |
893 | 749 | } | 746 | } |
894 | 750 | return *m_contact; | 747 | return *m_contact; |
895 | 751 | } | 748 | } |
896 | 752 | 749 | ||
897 | 750 | void QIndividual::updatePersonas() | ||
898 | 751 | { | ||
899 | 752 | Q_FOREACH(FolksPersona *p, m_personas.values()) { | ||
900 | 753 | g_object_unref(p); | ||
901 | 754 | } | ||
902 | 755 | |||
903 | 756 | GeeSet *personas = folks_individual_get_personas(m_individual); | ||
904 | 757 | if (!personas) { | ||
905 | 758 | return; | ||
906 | 759 | } | ||
907 | 760 | |||
908 | 761 | GeeIterator *iter = gee_iterable_iterator(GEE_ITERABLE(personas)); | ||
909 | 762 | while(gee_iterator_next(iter)) { | ||
910 | 763 | FolksPersona *persona = FOLKS_PERSONA(gee_iterator_get(iter)); | ||
911 | 764 | g_signal_connect(G_OBJECT(persona), "notify::avatar", | ||
912 | 765 | (GCallback) QIndividual::folksPersonaChanged, | ||
913 | 766 | const_cast<QIndividual*>(this)); | ||
914 | 767 | |||
915 | 768 | m_personas.insert(QString::fromUtf8(folks_persona_get_iid(persona)), persona); | ||
916 | 769 | } | ||
917 | 770 | |||
918 | 771 | g_object_unref(iter); | ||
919 | 772 | } | ||
920 | 773 | |||
921 | 753 | void QIndividual::updateContact() | 774 | void QIndividual::updateContact() |
922 | 754 | { | 775 | { |
924 | 755 | Q_ASSERT(m_individual); | 776 | // disconnect any previous handler |
925 | 777 | Q_FOREACH(FolksPersona *p, m_notifyConnections.keys()) { | ||
926 | 778 | Q_FOREACH(int handlerId, m_notifyConnections.value(p)) { | ||
927 | 779 | g_signal_handler_disconnect(p, handlerId); | ||
928 | 780 | } | ||
929 | 781 | m_notifyConnections.remove(p); | ||
930 | 782 | } | ||
931 | 783 | |||
932 | 784 | if (m_contact) { | ||
933 | 785 | delete m_contact; | ||
934 | 786 | m_contact = 0; | ||
935 | 787 | } | ||
936 | 756 | 788 | ||
937 | 757 | m_contact = new QContact(); | 789 | m_contact = new QContact(); |
938 | 790 | if (!m_individual) { | ||
939 | 791 | return; | ||
940 | 792 | } | ||
941 | 793 | |||
942 | 758 | m_contact->appendDetail(getUid()); | 794 | m_contact->appendDetail(getUid()); |
943 | 759 | Q_FOREACH(QContactDetail detail, getClientPidMap()) { | 795 | Q_FOREACH(QContactDetail detail, getClientPidMap()) { |
944 | 760 | m_contact->appendDetail(detail); | 796 | m_contact->appendDetail(detail); |
945 | 761 | } | 797 | } |
946 | 762 | 798 | ||
947 | 763 | int personaIndex = 1; | 799 | int personaIndex = 1; |
965 | 764 | GeeSet *personas = folks_individual_get_personas(m_individual); | 800 | Q_FOREACH(FolksPersona *persona, m_personas.values()) { |
949 | 765 | Q_ASSERT(personas); | ||
950 | 766 | GeeIterator *iter = gee_iterable_iterator(GEE_ITERABLE(personas)); | ||
951 | 767 | |||
952 | 768 | FolksPersona *persona; | ||
953 | 769 | |||
954 | 770 | // disconnect any previous handler | ||
955 | 771 | Q_FOREACH(gpointer persona, m_notifyConnections.keys()) { | ||
956 | 772 | Q_FOREACH(int handlerId, m_notifyConnections[persona]) { | ||
957 | 773 | g_signal_handler_disconnect(persona, handlerId); | ||
958 | 774 | } | ||
959 | 775 | } | ||
960 | 776 | |||
961 | 777 | m_notifyConnections.clear(); | ||
962 | 778 | |||
963 | 779 | while(gee_iterator_next(iter)) { | ||
964 | 780 | persona = FOLKS_PERSONA(gee_iterator_get(iter)); | ||
966 | 781 | Q_ASSERT(FOLKS_IS_PERSONA(persona)); | 801 | Q_ASSERT(FOLKS_IS_PERSONA(persona)); |
967 | 782 | 802 | ||
968 | 783 | int wsize = 0; | 803 | int wsize = 0; |
969 | @@ -790,25 +810,27 @@ | |||
970 | 790 | wPropList << wproperties[i]; | 810 | wPropList << wproperties[i]; |
971 | 791 | } | 811 | } |
972 | 792 | 812 | ||
992 | 793 | appendDetailsForPersona(m_contact, | 813 | // vcard only support one of these details by contact |
993 | 794 | getPersonaName(persona, personaIndex), | 814 | if (personaIndex == 1) { |
994 | 795 | !wPropList.contains("structured-name")); | 815 | appendDetailsForPersona(m_contact, |
995 | 796 | appendDetailsForPersona(m_contact, | 816 | getPersonaName(persona, personaIndex), |
996 | 797 | getPersonaFullName(persona, personaIndex), | 817 | !wPropList.contains("structured-name")); |
997 | 798 | !wPropList.contains("full-name")); | 818 | appendDetailsForPersona(m_contact, |
998 | 799 | appendDetailsForPersona(m_contact, | 819 | getPersonaFullName(persona, personaIndex), |
999 | 800 | getPersonaNickName(persona, personaIndex), | 820 | !wPropList.contains("full-name")); |
1000 | 801 | !wPropList.contains("structured-name")); | 821 | appendDetailsForPersona(m_contact, |
1001 | 802 | appendDetailsForPersona(m_contact, | 822 | getPersonaNickName(persona, personaIndex), |
1002 | 803 | getPersonaBirthday(persona, personaIndex), | 823 | !wPropList.contains("structured-name")); |
1003 | 804 | !wPropList.contains("birthday")); | 824 | appendDetailsForPersona(m_contact, |
1004 | 805 | appendDetailsForPersona(m_contact, | 825 | getPersonaBirthday(persona, personaIndex), |
1005 | 806 | getPersonaPhoto(persona, personaIndex), | 826 | !wPropList.contains("birthday")); |
1006 | 807 | !wPropList.contains("avatar")); | 827 | appendDetailsForPersona(m_contact, |
1007 | 808 | appendDetailsForPersona(m_contact, | 828 | getPersonaPhoto(persona, personaIndex), |
1008 | 809 | getPersonaFavorite(persona, personaIndex), | 829 | !wPropList.contains("avatar")); |
1009 | 810 | !wPropList.contains("is-favourite")); | 830 | appendDetailsForPersona(m_contact, |
1010 | 811 | 831 | getPersonaFavorite(persona, personaIndex), | |
1011 | 832 | !wPropList.contains("is-favourite")); | ||
1012 | 833 | } | ||
1013 | 812 | 834 | ||
1014 | 813 | QList<QContactDetail> details; | 835 | QList<QContactDetail> details; |
1015 | 814 | QContactDetail prefDetail; | 836 | QContactDetail prefDetail; |
1016 | @@ -855,33 +877,34 @@ | |||
1017 | 855 | !wPropList.contains("urls")); | 877 | !wPropList.contains("urls")); |
1018 | 856 | personaIndex++; | 878 | personaIndex++; |
1019 | 857 | 879 | ||
1020 | 880 | QList<int> ids = m_notifyConnections.value(persona); | ||
1021 | 881 | |||
1022 | 858 | // for now we are getting updated only about avatar changes | 882 | // for now we are getting updated only about avatar changes |
1028 | 859 | int handlerId = g_signal_connect(G_OBJECT(persona), "notify::avatar", | 883 | ids << g_signal_connect(G_OBJECT(persona), "notify::avatar", |
1029 | 860 | (GCallback) QIndividual::folksPersonaChanged, | 884 | (GCallback) QIndividual::folksPersonaChanged, |
1030 | 861 | const_cast<QIndividual*>(this)); | 885 | const_cast<QIndividual*>(this)); |
1026 | 862 | QList<int> ids = m_notifyConnections[persona]; | ||
1027 | 863 | ids << handlerId; | ||
1031 | 864 | m_notifyConnections[persona] = ids; | 886 | m_notifyConnections[persona] = ids; |
1032 | 865 | |||
1033 | 866 | g_object_unref(persona); | ||
1034 | 867 | } | 887 | } |
1035 | 868 | |||
1036 | 869 | g_object_unref(iter); | ||
1037 | 870 | } | 888 | } |
1038 | 871 | 889 | ||
1039 | 872 | bool QIndividual::update(const QtContacts::QContact &newContact, QObject *object, const char *slot) | 890 | bool QIndividual::update(const QtContacts::QContact &newContact, QObject *object, const char *slot) |
1040 | 873 | { | 891 | { |
1041 | 874 | QContact &originalContact = contact(); | 892 | QContact &originalContact = contact(); |
1042 | 875 | if (newContact != originalContact) { | 893 | if (newContact != originalContact) { |
1044 | 876 | UpdateContactRequest *request = new UpdateContactRequest(newContact, this, object, slot); | 894 | // only suppport one update by time |
1045 | 895 | Q_ASSERT(m_currentUpdate == 0); | ||
1046 | 896 | m_currentUpdate = new UpdateContactRequest(newContact, this, object, slot); | ||
1047 | 897 | m_updateConnection = QObject::connect(m_currentUpdate, | ||
1048 | 898 | &UpdateContactRequest::done, | ||
1049 | 899 | [this] (const QString &errorMessage) { | ||
1050 | 877 | 900 | ||
1051 | 878 | QObject::connect(request, &UpdateContactRequest::done, [request, this] (const QString &errorMessage) { | ||
1052 | 879 | if (errorMessage.isEmpty()) { | 901 | if (errorMessage.isEmpty()) { |
1053 | 880 | this->updateContact(); | 902 | this->updateContact(); |
1054 | 881 | } | 903 | } |
1056 | 882 | request->deleteLater(); | 904 | m_currentUpdate->deleteLater(); |
1057 | 905 | m_currentUpdate = 0; | ||
1058 | 883 | }); | 906 | }); |
1060 | 884 | request->start(); | 907 | m_currentUpdate->start(); |
1061 | 885 | return true; | 908 | return true; |
1062 | 886 | } else { | 909 | } else { |
1063 | 887 | qDebug() << "Contact is equal"; | 910 | qDebug() << "Contact is equal"; |
1064 | @@ -895,31 +918,40 @@ | |||
1065 | 895 | return update(contact, object, slot); | 918 | return update(contact, object, slot); |
1066 | 896 | } | 919 | } |
1067 | 897 | 920 | ||
1068 | 898 | |||
1069 | 899 | FolksIndividual *QIndividual::individual() const | 921 | FolksIndividual *QIndividual::individual() const |
1070 | 900 | { | 922 | { |
1071 | 901 | return m_individual; | 923 | return m_individual; |
1072 | 902 | } | 924 | } |
1073 | 903 | 925 | ||
1093 | 904 | FolksPersona *QIndividual::getPersona(int index) const | 926 | QList<FolksPersona *> QIndividual::personas() const |
1094 | 905 | { | 927 | { |
1095 | 906 | int size = 0; | 928 | return m_personas.values(); |
1096 | 907 | FolksPersona *persona = 0; | 929 | } |
1097 | 908 | GeeSet *personas = folks_individual_get_personas(m_individual); | 930 | |
1098 | 909 | gpointer* values = gee_collection_to_array(GEE_COLLECTION(personas), &size); | 931 | void QIndividual::clearPersonas() |
1099 | 910 | 932 | { | |
1100 | 911 | if ((index > 0) && (index <= size)) { | 933 | Q_FOREACH(FolksPersona *p, m_personas.values()) { |
1101 | 912 | persona = FOLKS_PERSONA(values[index - 1]); | 934 | Q_FOREACH(int handlerId, m_notifyConnections.value(p)) { |
1102 | 913 | } | 935 | g_signal_handler_disconnect(p, handlerId); |
1103 | 914 | 936 | } | |
1104 | 915 | g_free(values); | 937 | m_notifyConnections.remove(p); |
1105 | 916 | return persona; | 938 | g_object_unref(p); |
1106 | 917 | } | 939 | } |
1107 | 918 | 940 | m_personas.clear(); | |
1108 | 919 | int QIndividual::personaCount() const | 941 | } |
1109 | 920 | { | 942 | |
1110 | 921 | GeeSet *personas = folks_individual_get_personas(m_individual); | 943 | void QIndividual::clear() |
1111 | 922 | return gee_collection_get_size(GEE_COLLECTION(personas)); | 944 | { |
1112 | 945 | clearPersonas(); | ||
1113 | 946 | if (m_individual) { | ||
1114 | 947 | g_object_unref(m_individual); | ||
1115 | 948 | m_individual = 0; | ||
1116 | 949 | } | ||
1117 | 950 | |||
1118 | 951 | if (m_contact) { | ||
1119 | 952 | delete m_contact; | ||
1120 | 953 | m_contact = 0; | ||
1121 | 954 | } | ||
1122 | 923 | } | 955 | } |
1123 | 924 | 956 | ||
1124 | 925 | void QIndividual::addListener(QObject *object, const char *slot) | 957 | void QIndividual::addListener(QObject *object, const char *slot) |
1125 | @@ -932,27 +964,45 @@ | |||
1126 | 932 | } | 964 | } |
1127 | 933 | } | 965 | } |
1128 | 934 | 966 | ||
1129 | 967 | bool QIndividual::isValid() const | ||
1130 | 968 | { | ||
1131 | 969 | return (m_individual != 0); | ||
1132 | 970 | } | ||
1133 | 971 | |||
1134 | 972 | void QIndividual::flush() | ||
1135 | 973 | { | ||
1136 | 974 | // flush the folks persona store | ||
1137 | 975 | folks_persona_store_flush(folks_individual_aggregator_get_primary_store(m_aggregator), 0, 0); | ||
1138 | 976 | |||
1139 | 977 | // cause the contact info to be reload | ||
1140 | 978 | if (m_contact) { | ||
1141 | 979 | delete m_contact; | ||
1142 | 980 | m_contact = 0; | ||
1143 | 981 | } | ||
1144 | 982 | } | ||
1145 | 983 | |||
1146 | 935 | void QIndividual::setIndividual(FolksIndividual *individual) | 984 | void QIndividual::setIndividual(FolksIndividual *individual) |
1147 | 936 | { | 985 | { |
1148 | 937 | if (m_individual != individual) { | 986 | if (m_individual != individual) { |
1151 | 938 | if (m_individual) { | 987 | clear(); |
1152 | 939 | g_object_unref(m_individual); | 988 | |
1153 | 989 | if (individual) { | ||
1154 | 990 | QString newId = QString::fromUtf8(folks_individual_get_id(individual)); | ||
1155 | 991 | if (!m_id.isEmpty()) { | ||
1156 | 992 | // we can only update to individual with the same id | ||
1157 | 993 | Q_ASSERT(newId == m_id); | ||
1158 | 994 | } else { | ||
1159 | 995 | m_id = newId; | ||
1160 | 996 | } | ||
1161 | 940 | } | 997 | } |
1162 | 998 | |||
1163 | 941 | m_individual = individual; | 999 | m_individual = individual; |
1164 | 942 | if (m_individual) { | 1000 | if (m_individual) { |
1165 | 943 | g_object_ref(m_individual); | 1001 | g_object_ref(m_individual); |
1166 | 944 | } | 1002 | } |
1167 | 945 | |||
1168 | 946 | // initialize qcontact | ||
1169 | 947 | if (m_contact) { | ||
1170 | 948 | delete m_contact; | ||
1171 | 949 | m_contact = 0; | ||
1172 | 950 | } | ||
1173 | 951 | updateContact(); | ||
1174 | 952 | } | 1003 | } |
1175 | 953 | } | 1004 | } |
1176 | 954 | 1005 | ||
1177 | 955 | |||
1178 | 956 | GHashTable *QIndividual::parseAddressDetails(GHashTable *details, | 1006 | GHashTable *QIndividual::parseAddressDetails(GHashTable *details, |
1179 | 957 | const QList<QtContacts::QContactDetail> &cDetails, | 1007 | const QList<QtContacts::QContactDetail> &cDetails, |
1180 | 958 | const QtContacts::QContactDetail &prefDetail) | 1008 | const QtContacts::QContactDetail &prefDetail) |
1181 | @@ -982,13 +1032,15 @@ | |||
1182 | 982 | g_value_take_object(value, collection); | 1032 | g_value_take_object(value, collection); |
1183 | 983 | } | 1033 | } |
1184 | 984 | 1034 | ||
1190 | 985 | FolksPostalAddressFieldDetails *pafd = folks_postal_address_field_details_new(postalAddress, NULL); | 1035 | if (!folks_postal_address_is_empty(postalAddress)) { |
1191 | 986 | DetailContextParser::parseContext(FOLKS_ABSTRACT_FIELD_DETAILS(pafd), | 1036 | FolksPostalAddressFieldDetails *pafd = folks_postal_address_field_details_new(postalAddress, NULL); |
1192 | 987 | address, | 1037 | DetailContextParser::parseContext(FOLKS_ABSTRACT_FIELD_DETAILS(pafd), |
1193 | 988 | detail == prefDetail); | 1038 | address, |
1194 | 989 | gee_collection_add(collection, pafd); | 1039 | detail == prefDetail); |
1195 | 1040 | gee_collection_add(collection, pafd); | ||
1196 | 1041 | g_object_unref(pafd); | ||
1197 | 1042 | } | ||
1198 | 990 | 1043 | ||
1199 | 991 | g_object_unref(pafd); | ||
1200 | 992 | g_object_unref(postalAddress); | 1044 | g_object_unref(postalAddress); |
1201 | 993 | } | 1045 | } |
1202 | 994 | GeeUtils::personaDetailsInsert(details, FOLKS_PERSONA_DETAIL_POSTAL_ADDRESSES, value); | 1046 | GeeUtils::personaDetailsInsert(details, FOLKS_PERSONA_DETAIL_POSTAL_ADDRESSES, value); |
1203 | @@ -1293,7 +1345,6 @@ | |||
1204 | 1293 | return details; | 1345 | return details; |
1205 | 1294 | } | 1346 | } |
1206 | 1295 | 1347 | ||
1207 | 1296 | |||
1208 | 1297 | GHashTable *QIndividual::parseDetails(const QtContacts::QContact &contact) | 1348 | GHashTable *QIndividual::parseDetails(const QtContacts::QContact &contact) |
1209 | 1298 | { | 1349 | { |
1210 | 1299 | GHashTable *details = g_hash_table_new_full(g_str_hash, | 1350 | GHashTable *details = g_hash_table_new_full(g_str_hash, |
1211 | @@ -1309,7 +1360,6 @@ | |||
1212 | 1309 | parseFullNameDetails(details, contact.details(QContactDisplayLabel::Type)); | 1360 | parseFullNameDetails(details, contact.details(QContactDisplayLabel::Type)); |
1213 | 1310 | parseNicknameDetails(details, contact.details(QContactNickname::Type)); | 1361 | parseNicknameDetails(details, contact.details(QContactNickname::Type)); |
1214 | 1311 | 1362 | ||
1215 | 1312 | |||
1216 | 1313 | parseAddressDetails(details, | 1363 | parseAddressDetails(details, |
1217 | 1314 | contact.details(QContactAddress::Type), | 1364 | contact.details(QContactAddress::Type), |
1218 | 1315 | contact.preferredDetail(VCardParser::PreferredActionNames[QContactAddress::Type])); | 1365 | contact.preferredDetail(VCardParser::PreferredActionNames[QContactAddress::Type])); |
1219 | @@ -1335,29 +1385,23 @@ | |||
1220 | 1335 | return details; | 1385 | return details; |
1221 | 1336 | } | 1386 | } |
1222 | 1337 | 1387 | ||
1223 | 1388 | void QIndividual::enableAutoLink(bool flag) | ||
1224 | 1389 | { | ||
1225 | 1390 | m_autoLink = flag; | ||
1226 | 1391 | } | ||
1227 | 1392 | |||
1228 | 1393 | bool QIndividual::autoLinkEnabled() | ||
1229 | 1394 | { | ||
1230 | 1395 | return m_autoLink; | ||
1231 | 1396 | } | ||
1232 | 1397 | |||
1233 | 1338 | FolksPersona* QIndividual::primaryPersona() | 1398 | FolksPersona* QIndividual::primaryPersona() |
1234 | 1339 | { | 1399 | { |
1256 | 1340 | Q_ASSERT(m_individual); | 1400 | if (m_personas.size() > 0) { |
1257 | 1341 | 1401 | return m_personas.begin().value(); | |
1258 | 1342 | if (m_primaryPersona) { | 1402 | } else { |
1259 | 1343 | return m_primaryPersona; | 1403 | return 0; |
1260 | 1344 | } | 1404 | } |
1240 | 1345 | |||
1241 | 1346 | GeeSet *personas = folks_individual_get_personas(m_individual); | ||
1242 | 1347 | GeeIterator *iter = gee_iterable_iterator(GEE_ITERABLE(personas)); | ||
1243 | 1348 | FolksPersonaStore *primaryStore = folks_individual_aggregator_get_primary_store(m_aggregator); | ||
1244 | 1349 | |||
1245 | 1350 | while(m_primaryPersona == NULL && gee_iterator_next(iter)) { | ||
1246 | 1351 | FolksPersona *persona = FOLKS_PERSONA(gee_iterator_get(iter)); | ||
1247 | 1352 | if(folks_persona_get_store(persona) == primaryStore) { | ||
1248 | 1353 | m_primaryPersona = persona; | ||
1249 | 1354 | g_object_ref (persona); | ||
1250 | 1355 | } | ||
1251 | 1356 | g_object_unref(persona); | ||
1252 | 1357 | } | ||
1253 | 1358 | g_object_unref(iter); | ||
1254 | 1359 | |||
1255 | 1360 | return m_primaryPersona; | ||
1261 | 1361 | } | 1405 | } |
1262 | 1362 | 1406 | ||
1263 | 1363 | QtContacts::QContactDetail QIndividual::detailFromUri(QtContacts::QContactDetail::DetailType type, const QString &uri) const | 1407 | QtContacts::QContactDetail QIndividual::detailFromUri(QtContacts::QContactDetail::DetailType type, const QString &uri) const |
1264 | 1364 | 1408 | ||
1265 | === modified file 'lib/qindividual.h' | |||
1266 | --- lib/qindividual.h 2013-10-30 19:07:49 +0000 | |||
1267 | +++ lib/qindividual.h 2014-02-18 00:13:04 +0000 | |||
1268 | @@ -33,6 +33,8 @@ | |||
1269 | 33 | { | 33 | { |
1270 | 34 | typedef GHashTable* (*ParseDetailsFunc)(GHashTable*, const QList<QtContacts::QContactDetail> &); | 34 | typedef GHashTable* (*ParseDetailsFunc)(GHashTable*, const QList<QtContacts::QContactDetail> &); |
1271 | 35 | 35 | ||
1272 | 36 | class UpdateContactRequest; | ||
1273 | 37 | |||
1274 | 36 | class QIndividual | 38 | class QIndividual |
1275 | 37 | { | 39 | { |
1276 | 38 | public: | 40 | public: |
1277 | @@ -46,20 +48,28 @@ | |||
1278 | 46 | bool update(const QtContacts::QContact &contact, QObject *object, const char *slot); | 48 | bool update(const QtContacts::QContact &contact, QObject *object, const char *slot); |
1279 | 47 | void setIndividual(FolksIndividual *individual); | 49 | void setIndividual(FolksIndividual *individual); |
1280 | 48 | FolksIndividual *individual() const; | 50 | FolksIndividual *individual() const; |
1284 | 49 | 51 | QList<FolksPersona*> personas() const; | |
1282 | 50 | FolksPersona *getPersona(int index) const; | ||
1283 | 51 | int personaCount() const; | ||
1285 | 52 | void addListener(QObject *object, const char *slot); | 52 | void addListener(QObject *object, const char *slot); |
1286 | 53 | bool isValid() const; | ||
1287 | 54 | void flush(); | ||
1288 | 53 | 55 | ||
1289 | 54 | static GHashTable *parseDetails(const QtContacts::QContact &contact); | 56 | static GHashTable *parseDetails(const QtContacts::QContact &contact); |
1290 | 57 | |||
1291 | 58 | // enable or disable auto-link | ||
1292 | 59 | static void enableAutoLink(bool flag); | ||
1293 | 60 | static bool autoLinkEnabled(); | ||
1294 | 61 | |||
1295 | 55 | private: | 62 | private: |
1296 | 56 | FolksIndividual *m_individual; | 63 | FolksIndividual *m_individual; |
1297 | 57 | FolksPersona *m_primaryPersona; | ||
1298 | 58 | FolksIndividualAggregator *m_aggregator; | 64 | FolksIndividualAggregator *m_aggregator; |
1299 | 59 | QtContacts::QContact *m_contact; | 65 | QtContacts::QContact *m_contact; |
1301 | 60 | QMap<QString, QPair<QtContacts::QContactDetail, FolksAbstractFieldDetails*> > m_fieldsMap; | 66 | UpdateContactRequest *m_currentUpdate; |
1302 | 61 | QList<QPair<QObject*, QMetaMethod> > m_listeners; | 67 | QList<QPair<QObject*, QMetaMethod> > m_listeners; |
1304 | 62 | QMap<gpointer, QList<int> > m_notifyConnections; | 68 | QMap<QString, FolksPersona*> m_personas; |
1305 | 69 | QMap<FolksPersona*, QList<int> > m_notifyConnections; | ||
1306 | 70 | QString m_id; | ||
1307 | 71 | QMetaObject::Connection m_updateConnection; | ||
1308 | 72 | static bool m_autoLink; | ||
1309 | 63 | 73 | ||
1310 | 64 | QIndividual(); | 74 | QIndividual(); |
1311 | 65 | QIndividual(const QIndividual &); | 75 | QIndividual(const QIndividual &); |
1312 | @@ -68,6 +78,9 @@ | |||
1313 | 68 | 78 | ||
1314 | 69 | QMultiHash<QString, QString> parseDetails(FolksAbstractFieldDetails *details) const; | 79 | QMultiHash<QString, QString> parseDetails(FolksAbstractFieldDetails *details) const; |
1315 | 70 | void updateContact(); | 80 | void updateContact(); |
1316 | 81 | void updatePersonas(); | ||
1317 | 82 | void clearPersonas(); | ||
1318 | 83 | void clear(); | ||
1319 | 71 | 84 | ||
1320 | 72 | FolksPersona *primaryPersona(); | 85 | FolksPersona *primaryPersona(); |
1321 | 73 | QtContacts::QContactDetail detailFromUri(QtContacts::QContactDetail::DetailType type, const QString &uri) const; | 86 | QtContacts::QContactDetail detailFromUri(QtContacts::QContactDetail::DetailType type, const QString &uri) const; |
1322 | 74 | 87 | ||
1323 | === modified file 'lib/update-contact-request.cpp' | |||
1324 | --- lib/update-contact-request.cpp 2013-10-30 19:07:49 +0000 | |||
1325 | +++ lib/update-contact-request.cpp 2014-02-18 00:13:04 +0000 | |||
1326 | @@ -27,19 +27,16 @@ | |||
1327 | 27 | 27 | ||
1328 | 28 | using namespace QtContacts; | 28 | using namespace QtContacts; |
1329 | 29 | 29 | ||
1330 | 30 | namespace { | ||
1331 | 31 | |||
1332 | 32 | |||
1333 | 33 | |||
1334 | 34 | } | ||
1335 | 35 | |||
1336 | 36 | namespace galera { | 30 | namespace galera { |
1337 | 37 | 31 | ||
1338 | 38 | UpdateContactRequest::UpdateContactRequest(QtContacts::QContact newContact, QIndividual *parent, QObject *listener, const char *slot) | 32 | UpdateContactRequest::UpdateContactRequest(QtContacts::QContact newContact, QIndividual *parent, QObject *listener, const char *slot) |
1339 | 39 | : QObject(), | 33 | : QObject(), |
1340 | 34 | m_parent(parent), | ||
1341 | 35 | m_object(listener), | ||
1342 | 36 | m_currentPersona(0), | ||
1343 | 37 | m_eventLoop(0), | ||
1344 | 40 | m_newContact(newContact), | 38 | m_newContact(newContact), |
1347 | 41 | m_parent(parent), | 39 | m_currentPersonaIndex(0) |
1346 | 42 | m_object(listener) | ||
1348 | 43 | { | 40 | { |
1349 | 44 | int slotIndex = listener->metaObject()->indexOfSlot(++slot); | 41 | int slotIndex = listener->metaObject()->indexOfSlot(++slot); |
1350 | 45 | if (slotIndex == -1) { | 42 | if (slotIndex == -1) { |
1351 | @@ -49,18 +46,67 @@ | |||
1352 | 49 | } | 46 | } |
1353 | 50 | } | 47 | } |
1354 | 51 | 48 | ||
1355 | 49 | UpdateContactRequest::~UpdateContactRequest() | ||
1356 | 50 | { | ||
1357 | 51 | // check if there is a operation running | ||
1358 | 52 | if (m_currentPersona != 0) { | ||
1359 | 53 | wait(); | ||
1360 | 54 | } | ||
1361 | 55 | } | ||
1362 | 56 | |||
1363 | 52 | void UpdateContactRequest::invokeSlot(const QString &errorMessage) | 57 | void UpdateContactRequest::invokeSlot(const QString &errorMessage) |
1364 | 53 | { | 58 | { |
1368 | 54 | if (m_slot.isValid()) { | 59 | if (m_slot.isValid() && m_parent) { |
1369 | 55 | m_slot.invoke(m_object, Q_ARG(galera::QIndividual*, m_parent), Q_ARG(QString, errorMessage)); | 60 | m_slot.invoke(m_object, Q_ARG(QString, m_parent->id()), |
1370 | 56 | } | 61 | Q_ARG(QString, errorMessage)); |
1371 | 62 | } else if (m_parent == 0) { | ||
1372 | 63 | // the object was detached we need to destroy it | ||
1373 | 64 | deleteLater(); | ||
1374 | 65 | } | ||
1375 | 66 | |||
1376 | 67 | if (m_eventLoop) { | ||
1377 | 68 | m_eventLoop->quit(); | ||
1378 | 69 | } | ||
1379 | 70 | |||
1380 | 57 | Q_EMIT done(errorMessage); | 71 | Q_EMIT done(errorMessage); |
1381 | 58 | } | 72 | } |
1382 | 59 | 73 | ||
1383 | 60 | void UpdateContactRequest::start() | 74 | void UpdateContactRequest::start() |
1384 | 61 | { | 75 | { |
1385 | 62 | m_currentDetailType = QContactDetail::TypeAddress; | 76 | m_currentDetailType = QContactDetail::TypeAddress; |
1387 | 63 | updatePersona(1); | 77 | m_personas = m_parent->personas(); |
1388 | 78 | m_originalContact = m_parent->contact(); | ||
1389 | 79 | m_currentPersonaIndex = 0; | ||
1390 | 80 | updatePersona(); | ||
1391 | 81 | } | ||
1392 | 82 | |||
1393 | 83 | void UpdateContactRequest::wait() | ||
1394 | 84 | { | ||
1395 | 85 | Q_ASSERT(m_eventLoop == 0); | ||
1396 | 86 | QEventLoop eventLoop; | ||
1397 | 87 | m_eventLoop = &eventLoop; | ||
1398 | 88 | eventLoop.exec(); | ||
1399 | 89 | m_eventLoop = 0; | ||
1400 | 90 | } | ||
1401 | 91 | |||
1402 | 92 | void UpdateContactRequest::deatach() | ||
1403 | 93 | { | ||
1404 | 94 | m_parent = 0; | ||
1405 | 95 | } | ||
1406 | 96 | |||
1407 | 97 | bool UpdateContactRequest::isEqual(const QtContacts::QContactDetail &detailA, | ||
1408 | 98 | const QtContacts::QContactDetail &detailB) | ||
1409 | 99 | { | ||
1410 | 100 | if (detailA.type() != detailB.type()) { | ||
1411 | 101 | return false; | ||
1412 | 102 | } | ||
1413 | 103 | |||
1414 | 104 | switch(detailA.type()) { | ||
1415 | 105 | case QContactDetail::TypeFavorite: | ||
1416 | 106 | return detailA.value(QContactFavorite::FieldFavorite) == detailB.value(QContactFavorite::FieldFavorite); | ||
1417 | 107 | default: | ||
1418 | 108 | return (detailA == detailB); | ||
1419 | 109 | } | ||
1420 | 64 | } | 110 | } |
1421 | 65 | 111 | ||
1422 | 66 | bool UpdateContactRequest::isEqual(QList<QtContacts::QContactDetail> listA, | 112 | bool UpdateContactRequest::isEqual(QList<QtContacts::QContactDetail> listA, |
1423 | @@ -71,7 +117,7 @@ | |||
1424 | 71 | } | 117 | } |
1425 | 72 | 118 | ||
1426 | 73 | for(int i=0; i < listA.size(); i++) { | 119 | for(int i=0; i < listA.size(); i++) { |
1428 | 74 | if (listA[i] != listB[i]) { | 120 | if (!isEqual(listA[i], listB[i])) { |
1429 | 75 | return false; | 121 | return false; |
1430 | 76 | } | 122 | } |
1431 | 77 | } | 123 | } |
1432 | @@ -116,7 +162,8 @@ | |||
1433 | 116 | } | 162 | } |
1434 | 117 | 163 | ||
1435 | 118 | Q_FOREACH(QContactDetail det, contact.details(type)) { | 164 | Q_FOREACH(QContactDetail det, contact.details(type)) { |
1437 | 119 | if ((includeEmptyPersona && det.detailUri().isEmpty()) || checkPersona(det, persona)) { | 165 | if ((includeEmptyPersona && det.detailUri().isEmpty()) || |
1438 | 166 | checkPersona(det, persona)) { | ||
1439 | 120 | if (!det.isEmpty()) { | 167 | if (!det.isEmpty()) { |
1440 | 121 | personaDetails << det; | 168 | personaDetails << det; |
1441 | 122 | if (pref && det == globalPref) { | 169 | if (pref && det == globalPref) { |
1442 | @@ -132,19 +179,19 @@ | |||
1443 | 132 | int persona, | 179 | int persona, |
1444 | 133 | QtContacts::QContactDetail *pref) const | 180 | QtContacts::QContactDetail *pref) const |
1445 | 134 | { | 181 | { |
1447 | 135 | return detailsFromPersona(m_parent->contact(), type, persona, false, pref); | 182 | return detailsFromPersona(m_originalContact, type, persona, false, pref); |
1448 | 136 | } | 183 | } |
1449 | 137 | 184 | ||
1450 | 138 | QList<QtContacts::QContactDetail> UpdateContactRequest::detailsFromPersona(QtContacts::QContactDetail::DetailType type, | 185 | QList<QtContacts::QContactDetail> UpdateContactRequest::detailsFromPersona(QtContacts::QContactDetail::DetailType type, |
1451 | 139 | int persona, | 186 | int persona, |
1452 | 140 | QtContacts::QContactDetail *pref) const | 187 | QtContacts::QContactDetail *pref) const |
1453 | 141 | { | 188 | { |
1455 | 142 | return detailsFromPersona(m_newContact, type, persona, true, pref); | 189 | // only return new details for the first persona, this will avoid to create the details for all personas |
1456 | 190 | return detailsFromPersona(m_newContact, type, persona, (persona==1), pref); | ||
1457 | 143 | } | 191 | } |
1458 | 144 | 192 | ||
1459 | 145 | void UpdateContactRequest::updateAddress() | 193 | void UpdateContactRequest::updateAddress() |
1460 | 146 | { | 194 | { |
1461 | 147 | FolksPersona *persona = m_parent->getPersona(m_currentPersonaIndex); | ||
1462 | 148 | QContactDetail originalPref; | 195 | QContactDetail originalPref; |
1463 | 149 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypeAddress, | 196 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypeAddress, |
1464 | 150 | m_currentPersonaIndex, | 197 | m_currentPersonaIndex, |
1465 | @@ -154,8 +201,8 @@ | |||
1466 | 154 | m_currentPersonaIndex, | 201 | m_currentPersonaIndex, |
1467 | 155 | &prefDetail); | 202 | &prefDetail); |
1468 | 156 | 203 | ||
1471 | 157 | if (persona && | 204 | if (m_currentPersona && |
1472 | 158 | FOLKS_IS_POSTAL_ADDRESS_DETAILS(persona) && | 205 | FOLKS_IS_POSTAL_ADDRESS_DETAILS(m_currentPersona) && |
1473 | 159 | !isEqual(originalDetails, originalPref, newDetails, prefDetail)) { | 206 | !isEqual(originalDetails, originalPref, newDetails, prefDetail)) { |
1474 | 160 | qDebug() << "Adderess diff"; | 207 | qDebug() << "Adderess diff"; |
1475 | 161 | GeeSet *newSet = SET_AFD_NEW(); | 208 | GeeSet *newSet = SET_AFD_NEW(); |
1476 | @@ -188,7 +235,7 @@ | |||
1477 | 188 | g_object_unref(pa); | 235 | g_object_unref(pa); |
1478 | 189 | } | 236 | } |
1479 | 190 | 237 | ||
1481 | 191 | folks_postal_address_details_change_postal_addresses(FOLKS_POSTAL_ADDRESS_DETAILS(persona), | 238 | folks_postal_address_details_change_postal_addresses(FOLKS_POSTAL_ADDRESS_DETAILS(m_currentPersona), |
1482 | 192 | newSet, | 239 | newSet, |
1483 | 193 | (GAsyncReadyCallback) updateDetailsDone, | 240 | (GAsyncReadyCallback) updateDetailsDone, |
1484 | 194 | this); | 241 | this); |
1485 | @@ -200,12 +247,15 @@ | |||
1486 | 200 | 247 | ||
1487 | 201 | void UpdateContactRequest::updateAvatar() | 248 | void UpdateContactRequest::updateAvatar() |
1488 | 202 | { | 249 | { |
1489 | 203 | FolksPersona *persona = m_parent->getPersona(m_currentPersonaIndex); | ||
1490 | 204 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypeAvatar, m_currentPersonaIndex, 0); | 250 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypeAvatar, m_currentPersonaIndex, 0); |
1491 | 205 | QList<QContactDetail> newDetails = detailsFromPersona(QContactDetail::TypeAvatar, m_currentPersonaIndex, 0); | 251 | QList<QContactDetail> newDetails = detailsFromPersona(QContactDetail::TypeAvatar, m_currentPersonaIndex, 0); |
1492 | 206 | 252 | ||
1495 | 207 | if (persona && FOLKS_IS_AVATAR_DETAILS(persona) && !isEqual(originalDetails, newDetails)) { | 253 | if (m_currentPersona && |
1496 | 208 | qDebug() << "avatar diff"; | 254 | FOLKS_IS_AVATAR_DETAILS(m_currentPersona) && |
1497 | 255 | !isEqual(originalDetails, newDetails)) { | ||
1498 | 256 | qDebug() << "avatar diff:" | ||
1499 | 257 | << "\n\t" << originalDetails.size() << (originalDetails.size() > 0 ? originalDetails[0] : QContactDetail()) << "\n" | ||
1500 | 258 | << "\n\t" << newDetails.size() << (newDetails.size() > 0 ? newDetails[0] : QContactDetail()); | ||
1501 | 209 | //Only supports one avatar | 259 | //Only supports one avatar |
1502 | 210 | QUrl avatarUri; | 260 | QUrl avatarUri; |
1503 | 211 | if (newDetails.count()) { | 261 | if (newDetails.count()) { |
1504 | @@ -225,7 +275,7 @@ | |||
1505 | 225 | } | 275 | } |
1506 | 226 | } | 276 | } |
1507 | 227 | 277 | ||
1509 | 228 | folks_avatar_details_change_avatar(FOLKS_AVATAR_DETAILS(persona), | 278 | folks_avatar_details_change_avatar(FOLKS_AVATAR_DETAILS(m_currentPersona), |
1510 | 229 | G_LOADABLE_ICON(avatarFileIcon), | 279 | G_LOADABLE_ICON(avatarFileIcon), |
1511 | 230 | (GAsyncReadyCallback) updateDetailsDone, | 280 | (GAsyncReadyCallback) updateDetailsDone, |
1512 | 231 | this); | 281 | this); |
1513 | @@ -239,11 +289,12 @@ | |||
1514 | 239 | 289 | ||
1515 | 240 | void UpdateContactRequest::updateBirthday() | 290 | void UpdateContactRequest::updateBirthday() |
1516 | 241 | { | 291 | { |
1517 | 242 | FolksPersona *persona = m_parent->getPersona(m_currentPersonaIndex); | ||
1518 | 243 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypeBirthday, m_currentPersonaIndex, 0); | 292 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypeBirthday, m_currentPersonaIndex, 0); |
1519 | 244 | QList<QContactDetail> newDetails = detailsFromPersona(QContactDetail::TypeBirthday, m_currentPersonaIndex, 0); | 293 | QList<QContactDetail> newDetails = detailsFromPersona(QContactDetail::TypeBirthday, m_currentPersonaIndex, 0); |
1520 | 245 | 294 | ||
1522 | 246 | if (persona && FOLKS_IS_BIRTHDAY_DETAILS(persona) && !isEqual(originalDetails, newDetails)) { | 295 | if (m_currentPersona && |
1523 | 296 | FOLKS_IS_BIRTHDAY_DETAILS(m_currentPersona) && | ||
1524 | 297 | !isEqual(originalDetails, newDetails)) { | ||
1525 | 247 | qDebug() << "birthday diff"; | 298 | qDebug() << "birthday diff"; |
1526 | 248 | //Only supports one birthday | 299 | //Only supports one birthday |
1527 | 249 | QDateTime dateTimeBirthday; | 300 | QDateTime dateTimeBirthday; |
1528 | @@ -258,7 +309,7 @@ | |||
1529 | 258 | if (dateTimeBirthday.isValid()) { | 309 | if (dateTimeBirthday.isValid()) { |
1530 | 259 | dateTime = g_date_time_new_from_unix_utc(dateTimeBirthday.toMSecsSinceEpoch() / 1000); | 310 | dateTime = g_date_time_new_from_unix_utc(dateTimeBirthday.toMSecsSinceEpoch() / 1000); |
1531 | 260 | } | 311 | } |
1533 | 261 | folks_birthday_details_change_birthday(FOLKS_BIRTHDAY_DETAILS(persona), | 312 | folks_birthday_details_change_birthday(FOLKS_BIRTHDAY_DETAILS(m_currentPersona), |
1534 | 262 | dateTime, | 313 | dateTime, |
1535 | 263 | (GAsyncReadyCallback) updateDetailsDone, | 314 | (GAsyncReadyCallback) updateDetailsDone, |
1536 | 264 | this); | 315 | this); |
1537 | @@ -272,12 +323,15 @@ | |||
1538 | 272 | 323 | ||
1539 | 273 | void UpdateContactRequest::updateFullName() | 324 | void UpdateContactRequest::updateFullName() |
1540 | 274 | { | 325 | { |
1541 | 275 | FolksPersona *persona = m_parent->getPersona(m_currentPersonaIndex); | ||
1542 | 276 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypeDisplayLabel, m_currentPersonaIndex, 0); | 326 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypeDisplayLabel, m_currentPersonaIndex, 0); |
1543 | 277 | QList<QContactDetail> newDetails = detailsFromPersona(QContactDetail::TypeDisplayLabel, m_currentPersonaIndex, 0); | 327 | QList<QContactDetail> newDetails = detailsFromPersona(QContactDetail::TypeDisplayLabel, m_currentPersonaIndex, 0); |
1544 | 278 | 328 | ||
1547 | 279 | if (persona && FOLKS_IS_NAME_DETAILS(persona) && !isEqual(originalDetails, newDetails)) { | 329 | if (m_currentPersona && |
1548 | 280 | qDebug() << "Full Name diff"; | 330 | FOLKS_IS_NAME_DETAILS(m_currentPersona) && |
1549 | 331 | !isEqual(originalDetails, newDetails)) { | ||
1550 | 332 | qDebug() << "Full Name diff:" | ||
1551 | 333 | << "\n\t" << originalDetails.size() << (originalDetails.size() > 0 ? originalDetails[0] : QContactDetail()) << "\n" | ||
1552 | 334 | << "\n\t" << newDetails.size() << (newDetails.size() > 0 ? newDetails[0] : QContactDetail()); | ||
1553 | 281 | //Only supports one fullName | 335 | //Only supports one fullName |
1554 | 282 | QString fullName; | 336 | QString fullName; |
1555 | 283 | if (newDetails.count()) { | 337 | if (newDetails.count()) { |
1556 | @@ -286,7 +340,7 @@ | |||
1557 | 286 | } | 340 | } |
1558 | 287 | 341 | ||
1559 | 288 | QByteArray fullNameUtf8 = fullName.toUtf8(); | 342 | QByteArray fullNameUtf8 = fullName.toUtf8(); |
1561 | 289 | folks_name_details_change_full_name(FOLKS_NAME_DETAILS(persona), | 343 | folks_name_details_change_full_name(FOLKS_NAME_DETAILS(m_currentPersona), |
1562 | 290 | fullNameUtf8.constData(), | 344 | fullNameUtf8.constData(), |
1563 | 291 | (GAsyncReadyCallback) updateDetailsDone, | 345 | (GAsyncReadyCallback) updateDetailsDone, |
1564 | 292 | this); | 346 | this); |
1565 | @@ -297,7 +351,6 @@ | |||
1566 | 297 | 351 | ||
1567 | 298 | void UpdateContactRequest::updateEmail() | 352 | void UpdateContactRequest::updateEmail() |
1568 | 299 | { | 353 | { |
1569 | 300 | FolksPersona *persona = m_parent->getPersona(m_currentPersonaIndex); | ||
1570 | 301 | QContactDetail originalPref; | 354 | QContactDetail originalPref; |
1571 | 302 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypeEmailAddress, | 355 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypeEmailAddress, |
1572 | 303 | m_currentPersonaIndex, | 356 | m_currentPersonaIndex, |
1573 | @@ -308,8 +361,8 @@ | |||
1574 | 308 | m_currentPersonaIndex, | 361 | m_currentPersonaIndex, |
1575 | 309 | &prefDetail); | 362 | &prefDetail); |
1576 | 310 | 363 | ||
1579 | 311 | if (persona && | 364 | if (m_currentPersona && |
1580 | 312 | FOLKS_IS_EMAIL_DETAILS(persona) && | 365 | FOLKS_IS_EMAIL_DETAILS(m_currentPersona) && |
1581 | 313 | !isEqual(originalDetails, originalPref, newDetails, prefDetail)) { | 366 | !isEqual(originalDetails, originalPref, newDetails, prefDetail)) { |
1582 | 314 | qDebug() << "email diff"; | 367 | qDebug() << "email diff"; |
1583 | 315 | GeeSet *newSet = SET_AFD_NEW(); | 368 | GeeSet *newSet = SET_AFD_NEW(); |
1584 | @@ -325,7 +378,7 @@ | |||
1585 | 325 | g_object_unref(field); | 378 | g_object_unref(field); |
1586 | 326 | } | 379 | } |
1587 | 327 | 380 | ||
1589 | 328 | folks_email_details_change_email_addresses(FOLKS_EMAIL_DETAILS(persona), | 381 | folks_email_details_change_email_addresses(FOLKS_EMAIL_DETAILS(m_currentPersona), |
1590 | 329 | newSet, | 382 | newSet, |
1591 | 330 | (GAsyncReadyCallback) updateDetailsDone, | 383 | (GAsyncReadyCallback) updateDetailsDone, |
1592 | 331 | this); | 384 | this); |
1593 | @@ -337,11 +390,12 @@ | |||
1594 | 337 | 390 | ||
1595 | 338 | void UpdateContactRequest::updateName() | 391 | void UpdateContactRequest::updateName() |
1596 | 339 | { | 392 | { |
1597 | 340 | FolksPersona *persona = m_parent->getPersona(m_currentPersonaIndex); | ||
1598 | 341 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypeName, m_currentPersonaIndex, 0); | 393 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypeName, m_currentPersonaIndex, 0); |
1599 | 342 | QList<QContactDetail> newDetails = detailsFromPersona(QContactDetail::TypeName, m_currentPersonaIndex, 0); | 394 | QList<QContactDetail> newDetails = detailsFromPersona(QContactDetail::TypeName, m_currentPersonaIndex, 0); |
1600 | 343 | 395 | ||
1602 | 344 | if (persona && FOLKS_IS_NAME_DETAILS(persona) && !isEqual(originalDetails, newDetails)) { | 396 | if (m_currentPersona && |
1603 | 397 | FOLKS_IS_NAME_DETAILS(m_currentPersona) && | ||
1604 | 398 | !isEqual(originalDetails, newDetails)) { | ||
1605 | 345 | qDebug() << "Name diff"; | 399 | qDebug() << "Name diff"; |
1606 | 346 | //Only supports one fullName | 400 | //Only supports one fullName |
1607 | 347 | FolksStructuredName *sn = 0; | 401 | FolksStructuredName *sn = 0; |
1608 | @@ -360,7 +414,7 @@ | |||
1609 | 360 | suffix.constData()); | 414 | suffix.constData()); |
1610 | 361 | } | 415 | } |
1611 | 362 | 416 | ||
1613 | 363 | folks_name_details_change_structured_name(FOLKS_NAME_DETAILS(persona), | 417 | folks_name_details_change_structured_name(FOLKS_NAME_DETAILS(m_currentPersona), |
1614 | 364 | sn, | 418 | sn, |
1615 | 365 | (GAsyncReadyCallback) updateDetailsDone, | 419 | (GAsyncReadyCallback) updateDetailsDone, |
1616 | 366 | this); | 420 | this); |
1617 | @@ -374,11 +428,12 @@ | |||
1618 | 374 | 428 | ||
1619 | 375 | void UpdateContactRequest::updateNickname() | 429 | void UpdateContactRequest::updateNickname() |
1620 | 376 | { | 430 | { |
1621 | 377 | FolksPersona *persona = m_parent->getPersona(m_currentPersonaIndex); | ||
1622 | 378 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypeNickname, m_currentPersonaIndex, 0); | 431 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypeNickname, m_currentPersonaIndex, 0); |
1623 | 379 | QList<QContactDetail> newDetails = detailsFromPersona(QContactDetail::TypeNickname, m_currentPersonaIndex, 0); | 432 | QList<QContactDetail> newDetails = detailsFromPersona(QContactDetail::TypeNickname, m_currentPersonaIndex, 0); |
1624 | 380 | 433 | ||
1626 | 381 | if (persona && FOLKS_IS_NAME_DETAILS(persona) && !isEqual(originalDetails, newDetails)) { | 434 | if (m_currentPersona && |
1627 | 435 | FOLKS_IS_NAME_DETAILS(m_currentPersona) && | ||
1628 | 436 | !isEqual(originalDetails, newDetails)) { | ||
1629 | 382 | qDebug() << "Nickname diff"; | 437 | qDebug() << "Nickname diff"; |
1630 | 383 | //Only supports one fullName | 438 | //Only supports one fullName |
1631 | 384 | QString nicknameValue; | 439 | QString nicknameValue; |
1632 | @@ -388,7 +443,7 @@ | |||
1633 | 388 | } | 443 | } |
1634 | 389 | 444 | ||
1635 | 390 | QByteArray nicknameValueUtf8 = nicknameValue.toUtf8(); | 445 | QByteArray nicknameValueUtf8 = nicknameValue.toUtf8(); |
1637 | 391 | folks_name_details_change_nickname(FOLKS_NAME_DETAILS(persona), | 446 | folks_name_details_change_nickname(FOLKS_NAME_DETAILS(m_currentPersona), |
1638 | 392 | nicknameValueUtf8.constData(), | 447 | nicknameValueUtf8.constData(), |
1639 | 393 | (GAsyncReadyCallback) updateDetailsDone, | 448 | (GAsyncReadyCallback) updateDetailsDone, |
1640 | 394 | this); | 449 | this); |
1641 | @@ -399,14 +454,13 @@ | |||
1642 | 399 | 454 | ||
1643 | 400 | void UpdateContactRequest::updateNote() | 455 | void UpdateContactRequest::updateNote() |
1644 | 401 | { | 456 | { |
1645 | 402 | FolksPersona *persona = m_parent->getPersona(m_currentPersonaIndex); | ||
1646 | 403 | QContactDetail originalPref; | 457 | QContactDetail originalPref; |
1647 | 404 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypeNote, m_currentPersonaIndex, &originalPref); | 458 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypeNote, m_currentPersonaIndex, &originalPref); |
1648 | 405 | QContactDetail prefDetail; | 459 | QContactDetail prefDetail; |
1649 | 406 | QList<QContactDetail> newDetails = detailsFromPersona(QContactDetail::TypeNote, m_currentPersonaIndex, &prefDetail); | 460 | QList<QContactDetail> newDetails = detailsFromPersona(QContactDetail::TypeNote, m_currentPersonaIndex, &prefDetail); |
1650 | 407 | 461 | ||
1653 | 408 | if (persona && | 462 | if (m_currentPersona && |
1654 | 409 | FOLKS_IS_EMAIL_DETAILS(persona) && | 463 | FOLKS_IS_EMAIL_DETAILS(m_currentPersona) && |
1655 | 410 | !isEqual(originalDetails, originalPref, newDetails, prefDetail)) { | 464 | !isEqual(originalDetails, originalPref, newDetails, prefDetail)) { |
1656 | 411 | qDebug() << "notes diff"; | 465 | qDebug() << "notes diff"; |
1657 | 412 | GeeSet *newSet = SET_AFD_NEW(); | 466 | GeeSet *newSet = SET_AFD_NEW(); |
1658 | @@ -422,7 +476,7 @@ | |||
1659 | 422 | g_object_unref(field); | 476 | g_object_unref(field); |
1660 | 423 | } | 477 | } |
1661 | 424 | 478 | ||
1663 | 425 | folks_note_details_change_notes(FOLKS_NOTE_DETAILS(persona), | 479 | folks_note_details_change_notes(FOLKS_NOTE_DETAILS(m_currentPersona), |
1664 | 426 | newSet, | 480 | newSet, |
1665 | 427 | (GAsyncReadyCallback) updateDetailsDone, | 481 | (GAsyncReadyCallback) updateDetailsDone, |
1666 | 428 | this); | 482 | this); |
1667 | @@ -434,7 +488,6 @@ | |||
1668 | 434 | 488 | ||
1669 | 435 | void UpdateContactRequest::updateOnlineAccount() | 489 | void UpdateContactRequest::updateOnlineAccount() |
1670 | 436 | { | 490 | { |
1671 | 437 | FolksPersona *persona = m_parent->getPersona(m_currentPersonaIndex); | ||
1672 | 438 | QContactDetail originalPref; | 491 | QContactDetail originalPref; |
1673 | 439 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypeOnlineAccount, | 492 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypeOnlineAccount, |
1674 | 440 | m_currentPersonaIndex, | 493 | m_currentPersonaIndex, |
1675 | @@ -444,8 +497,8 @@ | |||
1676 | 444 | m_currentPersonaIndex, | 497 | m_currentPersonaIndex, |
1677 | 445 | &prefDetail); | 498 | &prefDetail); |
1678 | 446 | 499 | ||
1681 | 447 | if (persona && | 500 | if (m_currentPersona && |
1682 | 448 | FOLKS_IS_IM_DETAILS(persona) && | 501 | FOLKS_IS_IM_DETAILS(m_currentPersona) && |
1683 | 449 | !isEqual(originalDetails, originalPref, newDetails, prefDetail)) { | 502 | !isEqual(originalDetails, originalPref, newDetails, prefDetail)) { |
1684 | 450 | qDebug() << "OnlineAccounts diff"; | 503 | qDebug() << "OnlineAccounts diff"; |
1685 | 451 | GeeMultiMap *imMap = GEE_MULTI_MAP_AFD_NEW(FOLKS_TYPE_IM_FIELD_DETAILS); | 504 | GeeMultiMap *imMap = GEE_MULTI_MAP_AFD_NEW(FOLKS_TYPE_IM_FIELD_DETAILS); |
1686 | @@ -467,7 +520,7 @@ | |||
1687 | 467 | } | 520 | } |
1688 | 468 | } | 521 | } |
1689 | 469 | 522 | ||
1691 | 470 | folks_im_details_change_im_addresses(FOLKS_IM_DETAILS(persona), | 523 | folks_im_details_change_im_addresses(FOLKS_IM_DETAILS(m_currentPersona), |
1692 | 471 | imMap, | 524 | imMap, |
1693 | 472 | (GAsyncReadyCallback) updateDetailsDone, | 525 | (GAsyncReadyCallback) updateDetailsDone, |
1694 | 473 | this); | 526 | this); |
1695 | @@ -480,7 +533,6 @@ | |||
1696 | 480 | 533 | ||
1697 | 481 | void UpdateContactRequest::updateOrganization() | 534 | void UpdateContactRequest::updateOrganization() |
1698 | 482 | { | 535 | { |
1699 | 483 | FolksPersona *persona = m_parent->getPersona(m_currentPersonaIndex); | ||
1700 | 484 | QContactDetail originalPref; | 536 | QContactDetail originalPref; |
1701 | 485 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypeOrganization, | 537 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypeOrganization, |
1702 | 486 | m_currentPersonaIndex, | 538 | m_currentPersonaIndex, |
1703 | @@ -490,8 +542,8 @@ | |||
1704 | 490 | m_currentPersonaIndex, | 542 | m_currentPersonaIndex, |
1705 | 491 | &prefDetail); | 543 | &prefDetail); |
1706 | 492 | 544 | ||
1709 | 493 | if (persona && | 545 | if (m_currentPersona && |
1710 | 494 | FOLKS_IS_ROLE_DETAILS(persona) && | 546 | FOLKS_IS_ROLE_DETAILS(m_currentPersona) && |
1711 | 495 | !isEqual(originalDetails, originalPref, newDetails, prefDetail)) { | 547 | !isEqual(originalDetails, originalPref, newDetails, prefDetail)) { |
1712 | 496 | qDebug() << "Organization diff"; | 548 | qDebug() << "Organization diff"; |
1713 | 497 | GeeSet *newSet = SET_AFD_NEW(); | 549 | GeeSet *newSet = SET_AFD_NEW(); |
1714 | @@ -515,7 +567,7 @@ | |||
1715 | 515 | g_object_unref(roleValue); | 567 | g_object_unref(roleValue); |
1716 | 516 | } | 568 | } |
1717 | 517 | 569 | ||
1719 | 518 | folks_role_details_change_roles(FOLKS_ROLE_DETAILS(persona), | 570 | folks_role_details_change_roles(FOLKS_ROLE_DETAILS(m_currentPersona), |
1720 | 519 | newSet, | 571 | newSet, |
1721 | 520 | (GAsyncReadyCallback) updateDetailsDone, | 572 | (GAsyncReadyCallback) updateDetailsDone, |
1722 | 521 | this); | 573 | this); |
1723 | @@ -528,7 +580,6 @@ | |||
1724 | 528 | 580 | ||
1725 | 529 | void UpdateContactRequest::updatePhone() | 581 | void UpdateContactRequest::updatePhone() |
1726 | 530 | { | 582 | { |
1727 | 531 | FolksPersona *persona = m_parent->getPersona(m_currentPersonaIndex); | ||
1728 | 532 | QContactDetail originalPref; | 583 | QContactDetail originalPref; |
1729 | 533 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypePhoneNumber, | 584 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypePhoneNumber, |
1730 | 534 | m_currentPersonaIndex, | 585 | m_currentPersonaIndex, |
1731 | @@ -538,10 +589,13 @@ | |||
1732 | 538 | m_currentPersonaIndex, | 589 | m_currentPersonaIndex, |
1733 | 539 | &prefDetail); | 590 | &prefDetail); |
1734 | 540 | 591 | ||
1737 | 541 | if (persona && | 592 | if (m_currentPersona && |
1738 | 542 | FOLKS_IS_PHONE_DETAILS(persona) && | 593 | FOLKS_IS_PHONE_DETAILS(m_currentPersona) && |
1739 | 543 | !isEqual(originalDetails, originalPref, newDetails, prefDetail)) { | 594 | !isEqual(originalDetails, originalPref, newDetails, prefDetail)) { |
1741 | 544 | qDebug() << "Phone diff"; | 595 | qDebug() << "Phone diff:" |
1742 | 596 | << "\n\t" << originalDetails.size() << (originalDetails.size() > 0 ? originalDetails[0] : QContactDetail()) << "\n" | ||
1743 | 597 | << "\n\t" << newDetails.size() << (newDetails.size() > 0 ? newDetails[0] : QContactDetail()); | ||
1744 | 598 | |||
1745 | 545 | GeeSet *newSet = SET_AFD_NEW(); | 599 | GeeSet *newSet = SET_AFD_NEW(); |
1746 | 546 | 600 | ||
1747 | 547 | Q_FOREACH(QContactDetail newDetail, newDetails) { | 601 | Q_FOREACH(QContactDetail newDetail, newDetails) { |
1748 | @@ -555,7 +609,7 @@ | |||
1749 | 555 | g_object_unref(field); | 609 | g_object_unref(field); |
1750 | 556 | } | 610 | } |
1751 | 557 | 611 | ||
1753 | 558 | folks_phone_details_change_phone_numbers(FOLKS_PHONE_DETAILS(persona), | 612 | folks_phone_details_change_phone_numbers(FOLKS_PHONE_DETAILS(m_currentPersona), |
1754 | 559 | newSet, | 613 | newSet, |
1755 | 560 | (GAsyncReadyCallback) updateDetailsDone, | 614 | (GAsyncReadyCallback) updateDetailsDone, |
1756 | 561 | this); | 615 | this); |
1757 | @@ -567,7 +621,6 @@ | |||
1758 | 567 | 621 | ||
1759 | 568 | void UpdateContactRequest::updateUrl() | 622 | void UpdateContactRequest::updateUrl() |
1760 | 569 | { | 623 | { |
1761 | 570 | FolksPersona *persona = m_parent->getPersona(m_currentPersonaIndex); | ||
1762 | 571 | QContactDetail originalPref; | 624 | QContactDetail originalPref; |
1763 | 572 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypeUrl, | 625 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypeUrl, |
1764 | 573 | m_currentPersonaIndex, | 626 | m_currentPersonaIndex, |
1765 | @@ -578,8 +631,8 @@ | |||
1766 | 578 | m_currentPersonaIndex, | 631 | m_currentPersonaIndex, |
1767 | 579 | &prefDetail); | 632 | &prefDetail); |
1768 | 580 | 633 | ||
1771 | 581 | if (persona && | 634 | if (m_currentPersona && |
1772 | 582 | FOLKS_IS_PHONE_DETAILS(persona) && | 635 | FOLKS_IS_URL_DETAILS(m_currentPersona) && |
1773 | 583 | !isEqual(originalDetails, originalPref, newDetails, prefDetail)) { | 636 | !isEqual(originalDetails, originalPref, newDetails, prefDetail)) { |
1774 | 584 | qDebug() << "Url diff"; | 637 | qDebug() << "Url diff"; |
1775 | 585 | GeeSet *newSet = SET_AFD_NEW(); | 638 | GeeSet *newSet = SET_AFD_NEW(); |
1776 | @@ -595,7 +648,7 @@ | |||
1777 | 595 | g_object_unref(field); | 648 | g_object_unref(field); |
1778 | 596 | } | 649 | } |
1779 | 597 | 650 | ||
1781 | 598 | folks_url_details_change_urls(FOLKS_URL_DETAILS(persona), | 651 | folks_url_details_change_urls(FOLKS_URL_DETAILS(m_currentPersona), |
1782 | 599 | newSet, | 652 | newSet, |
1783 | 600 | (GAsyncReadyCallback) updateDetailsDone, | 653 | (GAsyncReadyCallback) updateDetailsDone, |
1784 | 601 | this); | 654 | this); |
1785 | @@ -607,19 +660,23 @@ | |||
1786 | 607 | 660 | ||
1787 | 608 | void UpdateContactRequest::updateFavorite() | 661 | void UpdateContactRequest::updateFavorite() |
1788 | 609 | { | 662 | { |
1789 | 610 | FolksPersona *persona = m_parent->getPersona(m_currentPersonaIndex); | ||
1790 | 611 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypeFavorite, m_currentPersonaIndex, 0); | 663 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypeFavorite, m_currentPersonaIndex, 0); |
1791 | 612 | QList<QContactDetail> newDetails = detailsFromPersona(QContactDetail::TypeFavorite, m_currentPersonaIndex, 0); | 664 | QList<QContactDetail> newDetails = detailsFromPersona(QContactDetail::TypeFavorite, m_currentPersonaIndex, 0); |
1792 | 613 | 665 | ||
1795 | 614 | if (persona && FOLKS_IS_FAVOURITE_DETAILS(persona) && !isEqual(originalDetails, newDetails)) { | 666 | if (m_currentPersona && |
1796 | 615 | qDebug() << "Favorite diff"; | 667 | FOLKS_IS_FAVOURITE_DETAILS(m_currentPersona) && |
1797 | 668 | !isEqual(originalDetails, newDetails)) { | ||
1798 | 669 | qDebug() << "Favorite diff:" | ||
1799 | 670 | << "\n\t" << originalDetails.size() << (originalDetails.size() > 0 ? originalDetails[0] : QContactDetail()) << "\n" | ||
1800 | 671 | << "\n\t" << newDetails.size() << (newDetails.size() > 0 ? newDetails[0] : QContactDetail()); | ||
1801 | 672 | |||
1802 | 616 | //Only supports one fullName | 673 | //Only supports one fullName |
1803 | 617 | bool isFavorite = false; | 674 | bool isFavorite = false; |
1804 | 618 | if (newDetails.count()) { | 675 | if (newDetails.count()) { |
1805 | 619 | QContactFavorite favorite = static_cast<QContactFavorite>(newDetails[0]); | 676 | QContactFavorite favorite = static_cast<QContactFavorite>(newDetails[0]); |
1806 | 620 | isFavorite = favorite.isFavorite(); | 677 | isFavorite = favorite.isFavorite(); |
1807 | 621 | } | 678 | } |
1809 | 622 | folks_favourite_details_change_is_favourite(FOLKS_FAVOURITE_DETAILS(persona), | 679 | folks_favourite_details_change_is_favourite(FOLKS_FAVOURITE_DETAILS(m_currentPersona), |
1810 | 623 | isFavorite, | 680 | isFavorite, |
1811 | 624 | (GAsyncReadyCallback) updateDetailsDone, | 681 | (GAsyncReadyCallback) updateDetailsDone, |
1812 | 625 | this); | 682 | this); |
1813 | @@ -628,14 +685,44 @@ | |||
1814 | 628 | } | 685 | } |
1815 | 629 | } | 686 | } |
1816 | 630 | 687 | ||
1818 | 631 | void UpdateContactRequest::updatePersona(int index) | 688 | void UpdateContactRequest::updatePersona() |
1819 | 632 | { | 689 | { |
1821 | 633 | if (index > m_parent->personaCount()) { | 690 | if (m_personas.size() <= m_currentPersonaIndex) { |
1822 | 691 | m_currentPersona = 0; | ||
1823 | 692 | if (m_parent) { | ||
1824 | 693 | m_parent->flush(); | ||
1825 | 694 | } | ||
1826 | 634 | invokeSlot(); | 695 | invokeSlot(); |
1827 | 635 | } else { | 696 | } else { |
1829 | 636 | m_currentPersonaIndex = index; | 697 | m_currentPersona = m_personas[m_currentPersonaIndex]; |
1830 | 637 | m_currentDetailType = QContactDetail::TypeUndefined; | 698 | m_currentDetailType = QContactDetail::TypeUndefined; |
1832 | 638 | updateDetailsDone(0, 0, this); | 699 | m_currentPersonaIndex++; |
1833 | 700 | |||
1834 | 701 | if (QIndividual::autoLinkEnabled()) { | ||
1835 | 702 | updateDetailsDone(0, 0, this); | ||
1836 | 703 | } else { | ||
1837 | 704 | // all personas edited by the user will have the auto link disabled | ||
1838 | 705 | GeeSet *antiLinks; | ||
1839 | 706 | antiLinks = GEE_SET(gee_hash_set_new(G_TYPE_STRING, | ||
1840 | 707 | (GBoxedCopyFunc) g_strdup, | ||
1841 | 708 | g_free, | ||
1842 | 709 | NULL, NULL, NULL, NULL, NULL, NULL)); | ||
1843 | 710 | |||
1844 | 711 | GeeSet *oldLinks = folks_anti_linkable_get_anti_links(FOLKS_ANTI_LINKABLE(m_currentPersona)); | ||
1845 | 712 | if (oldLinks && | ||
1846 | 713 | gee_collection_contains(GEE_COLLECTION(antiLinks), "*")) { | ||
1847 | 714 | updateDetailsDone(0, 0, this); | ||
1848 | 715 | return; | ||
1849 | 716 | } else if (oldLinks) { | ||
1850 | 717 | gee_collection_add_all(GEE_COLLECTION(antiLinks), GEE_COLLECTION(oldLinks)); | ||
1851 | 718 | } | ||
1852 | 719 | gee_collection_add(GEE_COLLECTION(antiLinks), "*"); | ||
1853 | 720 | |||
1854 | 721 | folks_anti_linkable_change_anti_links(FOLKS_ANTI_LINKABLE(m_currentPersona), | ||
1855 | 722 | antiLinks, | ||
1856 | 723 | (GAsyncReadyCallback) folksAddAntiLinksDone, | ||
1857 | 724 | this); | ||
1858 | 725 | } | ||
1859 | 639 | } | 726 | } |
1860 | 640 | } | 727 | } |
1861 | 641 | 728 | ||
1862 | @@ -780,8 +867,9 @@ | |||
1863 | 780 | updateDetailsDone(0, 0, self); | 867 | updateDetailsDone(0, 0, self); |
1864 | 781 | break; | 868 | break; |
1865 | 782 | case QContactDetail::TypeVersion: | 869 | case QContactDetail::TypeVersion: |
1868 | 783 | self->m_currentPersonaIndex += 1; | 870 | g_object_unref(self->m_currentPersona); |
1869 | 784 | self->updatePersona(self->m_currentPersonaIndex); | 871 | self->m_currentPersona = 0; |
1870 | 872 | self->updatePersona(); | ||
1871 | 785 | break; | 873 | break; |
1872 | 786 | default: | 874 | default: |
1873 | 787 | qWarning() << "Update not implemented for" << self->m_currentDetailType; | 875 | qWarning() << "Update not implemented for" << self->m_currentDetailType; |
1874 | @@ -790,4 +878,17 @@ | |||
1875 | 790 | } | 878 | } |
1876 | 791 | } | 879 | } |
1877 | 792 | 880 | ||
1878 | 881 | void UpdateContactRequest::folksAddAntiLinksDone(FolksAntiLinkable *antilinkable, | ||
1879 | 882 | GAsyncResult *result, | ||
1880 | 883 | UpdateContactRequest *self) | ||
1881 | 884 | { | ||
1882 | 885 | GError *error = 0; | ||
1883 | 886 | folks_anti_linkable_change_anti_links_finish(antilinkable, result, &error); | ||
1884 | 887 | if (error) { | ||
1885 | 888 | qWarning() << "Error during the anti link operation:" << error->message; | ||
1886 | 889 | g_error_free(error); | ||
1887 | 890 | } | ||
1888 | 891 | updateDetailsDone(0, 0, self); | ||
1889 | 793 | } | 892 | } |
1890 | 893 | |||
1891 | 894 | } // namespace | ||
1892 | 794 | 895 | ||
1893 | === modified file 'lib/update-contact-request.h' | |||
1894 | --- lib/update-contact-request.h 2013-10-30 19:07:49 +0000 | |||
1895 | +++ lib/update-contact-request.h 2014-02-18 00:13:04 +0000 | |||
1896 | @@ -23,6 +23,7 @@ | |||
1897 | 23 | #include <QtCore/QString> | 23 | #include <QtCore/QString> |
1898 | 24 | #include <QtCore/QList> | 24 | #include <QtCore/QList> |
1899 | 25 | #include <QtCore/QMetaMethod> | 25 | #include <QtCore/QMetaMethod> |
1900 | 26 | #include <QtCore/QEventLoop> | ||
1901 | 26 | 27 | ||
1902 | 27 | #include <QtContacts/QContact> | 28 | #include <QtContacts/QContact> |
1903 | 28 | 29 | ||
1904 | @@ -38,20 +39,26 @@ | |||
1905 | 38 | 39 | ||
1906 | 39 | public: | 40 | public: |
1907 | 40 | UpdateContactRequest(QtContacts::QContact newContact, QIndividual *parent, QObject *listener, const char *slot); | 41 | UpdateContactRequest(QtContacts::QContact newContact, QIndividual *parent, QObject *listener, const char *slot); |
1909 | 41 | 42 | ~UpdateContactRequest(); | |
1910 | 42 | void start(); | 43 | void start(); |
1911 | 44 | void wait(); | ||
1912 | 45 | void deatach(); | ||
1913 | 43 | 46 | ||
1914 | 44 | Q_SIGNALS: | 47 | Q_SIGNALS: |
1915 | 45 | void done(const QString &errorMessage); | 48 | void done(const QString &errorMessage); |
1916 | 46 | 49 | ||
1917 | 47 | private: | 50 | private: |
1918 | 51 | QIndividual *m_parent; | ||
1919 | 52 | QObject *m_object; | ||
1920 | 53 | FolksPersona *m_currentPersona; | ||
1921 | 54 | QEventLoop *m_eventLoop; | ||
1922 | 55 | |||
1923 | 56 | QList<FolksPersona*> m_personas; | ||
1924 | 57 | QtContacts::QContact m_originalContact; | ||
1925 | 48 | QtContacts::QContact m_newContact; | 58 | QtContacts::QContact m_newContact; |
1926 | 49 | int m_currentDetailType; | 59 | int m_currentDetailType; |
1927 | 60 | QMetaMethod m_slot; | ||
1928 | 50 | int m_currentPersonaIndex; | 61 | int m_currentPersonaIndex; |
1929 | 51 | int m_maxPersona; | ||
1930 | 52 | QIndividual *m_parent; | ||
1931 | 53 | QObject *m_object; | ||
1932 | 54 | QMetaMethod m_slot; | ||
1933 | 55 | 62 | ||
1934 | 56 | void invokeSlot(const QString &errorMessage = QString()); | 63 | void invokeSlot(const QString &errorMessage = QString()); |
1935 | 57 | 64 | ||
1936 | @@ -61,6 +68,8 @@ | |||
1937 | 61 | const QtContacts::QContactDetail &prefB); | 68 | const QtContacts::QContactDetail &prefB); |
1938 | 62 | static bool isEqual(QList<QtContacts::QContactDetail> listA, | 69 | static bool isEqual(QList<QtContacts::QContactDetail> listA, |
1939 | 63 | QList<QtContacts::QContactDetail> listB); | 70 | QList<QtContacts::QContactDetail> listB); |
1940 | 71 | static bool isEqual(const QtContacts::QContactDetail &detailA, | ||
1941 | 72 | const QtContacts::QContactDetail &detailB); | ||
1942 | 64 | static bool checkPersona(QtContacts::QContactDetail &det, int persona); | 73 | static bool checkPersona(QtContacts::QContactDetail &det, int persona); |
1943 | 65 | static QList<QtContacts::QContactDetail> detailsFromPersona(const QtContacts::QContact &contact, | 74 | static QList<QtContacts::QContactDetail> detailsFromPersona(const QtContacts::QContact &contact, |
1944 | 66 | QtContacts::QContactDetail::DetailType type, | 75 | QtContacts::QContactDetail::DetailType type, |
1945 | @@ -74,7 +83,8 @@ | |||
1946 | 74 | int persona, | 83 | int persona, |
1947 | 75 | QtContacts::QContactDetail *pref) const; | 84 | QtContacts::QContactDetail *pref) const; |
1948 | 76 | 85 | ||
1950 | 77 | void updatePersona(int index); | 86 | |
1951 | 87 | void updatePersona(); | ||
1952 | 78 | void updateAddress(); | 88 | void updateAddress(); |
1953 | 79 | void updateAvatar(); | 89 | void updateAvatar(); |
1954 | 80 | void updateBirthday(); | 90 | void updateBirthday(); |
1955 | @@ -94,7 +104,7 @@ | |||
1956 | 94 | GAsyncResult *result); | 104 | GAsyncResult *result); |
1957 | 95 | 105 | ||
1958 | 96 | static void updateDetailsDone(GObject *detail, GAsyncResult *result, gpointer userdata); | 106 | static void updateDetailsDone(GObject *detail, GAsyncResult *result, gpointer userdata); |
1960 | 97 | 107 | static void folksAddAntiLinksDone(FolksAntiLinkable *antilinkable, GAsyncResult *result, UpdateContactRequest *self); | |
1961 | 98 | }; | 108 | }; |
1962 | 99 | 109 | ||
1963 | 100 | } | 110 | } |
1964 | 101 | 111 | ||
1965 | === modified file 'lib/view.cpp' | |||
1966 | --- lib/view.cpp 2013-10-30 19:07:49 +0000 | |||
1967 | +++ lib/view.cpp 2014-02-18 00:13:04 +0000 | |||
1968 | @@ -108,11 +108,13 @@ | |||
1969 | 108 | protected: | 108 | protected: |
1970 | 109 | void run() | 109 | void run() |
1971 | 110 | { | 110 | { |
1972 | 111 | m_allContacts->lock(); | ||
1973 | 111 | Q_FOREACH(ContactEntry *entry, m_allContacts->values()) | 112 | Q_FOREACH(ContactEntry *entry, m_allContacts->values()) |
1974 | 112 | { | 113 | { |
1975 | 113 | m_stoppedLock.lockForRead(); | 114 | m_stoppedLock.lockForRead(); |
1976 | 114 | if (m_stopped) { | 115 | if (m_stopped) { |
1977 | 115 | m_stoppedLock.unlock(); | 116 | m_stoppedLock.unlock(); |
1978 | 117 | m_allContacts->unlock(); | ||
1979 | 116 | return; | 118 | return; |
1980 | 117 | } | 119 | } |
1981 | 118 | m_stoppedLock.unlock(); | 120 | m_stoppedLock.unlock(); |
1982 | @@ -121,8 +123,8 @@ | |||
1983 | 121 | m_contacts << entry; | 123 | m_contacts << entry; |
1984 | 122 | } | 124 | } |
1985 | 123 | } | 125 | } |
1986 | 124 | |||
1987 | 125 | chageSort(m_sortClause); | 126 | chageSort(m_sortClause); |
1988 | 127 | m_allContacts->unlock(); | ||
1989 | 126 | } | 128 | } |
1990 | 127 | 129 | ||
1991 | 128 | private: | 130 | private: |
1992 | 129 | 131 | ||
1993 | === modified file 'tests/unittest/CMakeLists.txt' | |||
1994 | --- tests/unittest/CMakeLists.txt 2013-11-01 01:10:12 +0000 | |||
1995 | +++ tests/unittest/CMakeLists.txt 2014-02-18 00:13:04 +0000 | |||
1996 | @@ -70,6 +70,9 @@ | |||
1997 | 70 | 70 | ||
1998 | 71 | declare_test(addressbook-test True ${BASE_CLIENT_TEST_SRC}) | 71 | declare_test(addressbook-test True ${BASE_CLIENT_TEST_SRC}) |
1999 | 72 | declare_test(service-life-cycle-test True ${BASE_CLIENT_TEST_SRC}) | 72 | declare_test(service-life-cycle-test True ${BASE_CLIENT_TEST_SRC}) |
2000 | 73 | # Disable test until the new folks arrive on jenkins | ||
2001 | 74 | #declare_test(contact-link-test True ${BASE_CLIENT_TEST_SRC}) | ||
2002 | 75 | |||
2003 | 73 | elseif() | 76 | elseif() |
2004 | 74 | message(STATUS "DBus test runner not found. Some tests will be disabled") | 77 | message(STATUS "DBus test runner not found. Some tests will be disabled") |
2005 | 75 | endif() | 78 | endif() |
2006 | 76 | 79 | ||
2007 | === modified file 'tests/unittest/addressbook-test.cpp' | |||
2008 | --- tests/unittest/addressbook-test.cpp 2013-12-13 19:06:57 +0000 | |||
2009 | +++ tests/unittest/addressbook-test.cpp 2014-02-18 00:13:04 +0000 | |||
2010 | @@ -111,7 +111,7 @@ | |||
2011 | 111 | m_resultBasicVcard = QStringLiteral("BEGIN:VCARD\r\n" | 111 | m_resultBasicVcard = QStringLiteral("BEGIN:VCARD\r\n" |
2012 | 112 | "VERSION:3.0\r\n" | 112 | "VERSION:3.0\r\n" |
2013 | 113 | "UID:%1\r\n" | 113 | "UID:%1\r\n" |
2015 | 114 | "CLIENTPIDMAP:1;dummy:dummy-store:0\r\n" | 114 | "CLIENTPIDMAP:1;dummy:dummy-store:%2\r\n" |
2016 | 115 | "N;PID=1.1:Tal;Fulano_;de;;\r\n" | 115 | "N;PID=1.1:Tal;Fulano_;de;;\r\n" |
2017 | 116 | "FN;PID=1.1:Fulano_ Tal\r\n" | 116 | "FN;PID=1.1:Fulano_ Tal\r\n" |
2018 | 117 | "X-QTPROJECT-FAVORITE;PID=1.1:false;0\r\n" | 117 | "X-QTPROJECT-FAVORITE;PID=1.1:false;0\r\n" |
2019 | @@ -213,7 +213,7 @@ | |||
2020 | 213 | 213 | ||
2021 | 214 | // user returned id to fill the new vcard | 214 | // user returned id to fill the new vcard |
2022 | 215 | QString newContactId = reply.value(); | 215 | QString newContactId = reply.value(); |
2024 | 216 | QString newVcard = m_resultBasicVcard.arg(newContactId); | 216 | QString newVcard = m_resultBasicVcard.arg(newContactId).arg(0); |
2025 | 217 | 217 | ||
2026 | 218 | // try create a contact with the same id | 218 | // try create a contact with the same id |
2027 | 219 | QDBusReply<QString> reply2 = m_serverIface->call("createContact", newVcard, "dummy-store"); | 219 | QDBusReply<QString> reply2 = m_serverIface->call("createContact", newVcard, "dummy-store"); |
2028 | @@ -267,6 +267,46 @@ | |||
2029 | 267 | QDBusReply<QStringList> replyList = m_dummyIface->call("listContacts"); | 267 | QDBusReply<QStringList> replyList = m_dummyIface->call("listContacts"); |
2030 | 268 | QCOMPARE(replyList.value().count(), 0); | 268 | QCOMPARE(replyList.value().count(), 0); |
2031 | 269 | } | 269 | } |
2032 | 270 | |||
2033 | 271 | void testUpdateContact() | ||
2034 | 272 | { | ||
2035 | 273 | // create a basic contact | ||
2036 | 274 | QDBusReply<QString> replyAdd = m_serverIface->call("createContact", m_basicVcard, "dummy-store"); | ||
2037 | 275 | QString newContactId = replyAdd.value(); | ||
2038 | 276 | |||
2039 | 277 | // update the contact phone number | ||
2040 | 278 | QString vcard = m_resultBasicVcard.arg(newContactId).arg(3); | ||
2041 | 279 | vcard = vcard.replace("8888888", "0000000"); | ||
2042 | 280 | QList<QtContacts::QContact> contacts = galera::VCardParser::vcardToContact(QStringList() << vcard); | ||
2043 | 281 | QtContacts::QContact contactUpdated = contacts[0]; | ||
2044 | 282 | |||
2045 | 283 | // spy 'contactsUpdated' signal | ||
2046 | 284 | QSignalSpy updateContactSpy(m_serverIface, SIGNAL(contactsUpdated(const QStringList &))); | ||
2047 | 285 | QDBusReply<QStringList> replyUpdate = m_serverIface->call("updateContacts", QStringList() << vcard); | ||
2048 | 286 | QStringList result = replyUpdate.value(); | ||
2049 | 287 | QCOMPARE(result.size(), 1); | ||
2050 | 288 | |||
2051 | 289 | // check if contact returned by update function contains the new data | ||
2052 | 290 | contacts = galera::VCardParser::vcardToContact(result); | ||
2053 | 291 | QtContacts::QContact contactUpdatedResult = contacts[0]; | ||
2054 | 292 | compareContact(contactUpdatedResult, contactUpdated); | ||
2055 | 293 | |||
2056 | 294 | // check if the 'contactsUpdated' signal was fired with the correct args | ||
2057 | 295 | QTRY_COMPARE(updateContactSpy.count(), 1); | ||
2058 | 296 | QList<QVariant> args = updateContactSpy.takeFirst(); | ||
2059 | 297 | QCOMPARE(args.count(), 1); | ||
2060 | 298 | QStringList ids = args[0].toStringList(); | ||
2061 | 299 | QCOMPARE(ids[0], newContactId); | ||
2062 | 300 | |||
2063 | 301 | // check if the contact was updated into the backend | ||
2064 | 302 | QDBusReply<QStringList> replyList = m_dummyIface->call("listContacts"); | ||
2065 | 303 | result = replyList.value(); | ||
2066 | 304 | QCOMPARE(result.count(), 1); | ||
2067 | 305 | |||
2068 | 306 | contacts = galera::VCardParser::vcardToContact(result); | ||
2069 | 307 | contactUpdatedResult = contacts[0]; | ||
2070 | 308 | compareContact(contactUpdatedResult, contactUpdated); | ||
2071 | 309 | } | ||
2072 | 270 | }; | 310 | }; |
2073 | 271 | 311 | ||
2074 | 272 | QTEST_MAIN(AddressBookTest) | 312 | QTEST_MAIN(AddressBookTest) |
2075 | 273 | 313 | ||
2076 | === added file 'tests/unittest/contact-link-test.cpp' | |||
2077 | --- tests/unittest/contact-link-test.cpp 1970-01-01 00:00:00 +0000 | |||
2078 | +++ tests/unittest/contact-link-test.cpp 2014-02-18 00:13:04 +0000 | |||
2079 | @@ -0,0 +1,100 @@ | |||
2080 | 1 | /* | ||
2081 | 2 | * Copyright 2013 Canonical Ltd. | ||
2082 | 3 | * | ||
2083 | 4 | * This file is part of contact-service-app. | ||
2084 | 5 | * | ||
2085 | 6 | * contact-service-app is free software; you can redistribute it and/or modify | ||
2086 | 7 | * it under the terms of the GNU General Public License as published by | ||
2087 | 8 | * the Free Software Foundation; version 3. | ||
2088 | 9 | * | ||
2089 | 10 | * contact-service-app is distributed in the hope that it will be useful, | ||
2090 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2091 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2092 | 13 | * GNU General Public License for more details. | ||
2093 | 14 | * | ||
2094 | 15 | * You should have received a copy of the GNU General Public License | ||
2095 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2096 | 17 | */ | ||
2097 | 18 | |||
2098 | 19 | #include "base-client-test.h" | ||
2099 | 20 | #include "lib/source.h" | ||
2100 | 21 | #include "lib/qindividual.h" | ||
2101 | 22 | #include "common/dbus-service-defs.h" | ||
2102 | 23 | #include "common/vcard-parser.h" | ||
2103 | 24 | |||
2104 | 25 | #include <QObject> | ||
2105 | 26 | #include <QtDBus> | ||
2106 | 27 | #include <QtTest> | ||
2107 | 28 | #include <QDebug> | ||
2108 | 29 | #include <QtVersit> | ||
2109 | 30 | |||
2110 | 31 | class ContactLinkTest : public BaseClientTest | ||
2111 | 32 | { | ||
2112 | 33 | Q_OBJECT | ||
2113 | 34 | private: | ||
2114 | 35 | QString m_vcard; | ||
2115 | 36 | |||
2116 | 37 | private Q_SLOTS: | ||
2117 | 38 | void initTestCase() | ||
2118 | 39 | { | ||
2119 | 40 | BaseClientTest::initTestCase(); | ||
2120 | 41 | m_vcard = QStringLiteral("BEGIN:VCARD\n" | ||
2121 | 42 | "VERSION:3.0\n" | ||
2122 | 43 | "N:tal;fulano_;de;;\n" | ||
2123 | 44 | "EMAIL:email@ubuntu.com\n" | ||
2124 | 45 | "TEL;PID=1.1;TYPE=ISDN:33331410\n" | ||
2125 | 46 | "END:VCARD"); | ||
2126 | 47 | } | ||
2127 | 48 | |||
2128 | 49 | void testCreateContactWithSameEmail() | ||
2129 | 50 | { | ||
2130 | 51 | // call create contact | ||
2131 | 52 | QDBusReply<QString> reply = m_serverIface->call("createContact", m_vcard, "dummy-store"); | ||
2132 | 53 | |||
2133 | 54 | // check if the returned id is valid | ||
2134 | 55 | QString contactAId = reply.value(); | ||
2135 | 56 | QVERIFY(!contactAId.isEmpty()); | ||
2136 | 57 | |||
2137 | 58 | QString vcardB = m_vcard.replace("fulano", "contact"); | ||
2138 | 59 | reply = m_serverIface->call("createContact", vcardB, "dummy-store"); | ||
2139 | 60 | |||
2140 | 61 | // check if the returned id is valid | ||
2141 | 62 | QString contactBId = reply.value(); | ||
2142 | 63 | QVERIFY(!contactBId.isEmpty()); | ||
2143 | 64 | |||
2144 | 65 | QVERIFY(contactAId != contactBId); | ||
2145 | 66 | } | ||
2146 | 67 | |||
2147 | 68 | void testAppendOtherContactEmail() | ||
2148 | 69 | { | ||
2149 | 70 | // call create contact | ||
2150 | 71 | QDBusReply<QString> reply = m_serverIface->call("createContact", m_vcard, "dummy-store"); | ||
2151 | 72 | |||
2152 | 73 | // check if the returned id is valid | ||
2153 | 74 | QString contactAId = reply.value(); | ||
2154 | 75 | QVERIFY(!contactAId.isEmpty()); | ||
2155 | 76 | |||
2156 | 77 | // add a contact with diff email | ||
2157 | 78 | QString vcardB = m_vcard.replace("fulano", "contact").replace("email","email2"); | ||
2158 | 79 | reply = m_serverIface->call("createContact", vcardB, "dummy-store"); | ||
2159 | 80 | |||
2160 | 81 | // check if the returned id is valid | ||
2161 | 82 | QString contactBId = reply.value(); | ||
2162 | 83 | QVERIFY(!contactBId.isEmpty()); | ||
2163 | 84 | |||
2164 | 85 | // udate contactB with same email as contactA | ||
2165 | 86 | vcardB = m_vcard.replace("fulano", "contact"); | ||
2166 | 87 | reply = m_serverIface->call("createContact", vcardB, "dummy-store"); | ||
2167 | 88 | |||
2168 | 89 | // check if the returned id is valid | ||
2169 | 90 | contactBId = reply.value(); | ||
2170 | 91 | QVERIFY(!contactBId.isEmpty()); | ||
2171 | 92 | |||
2172 | 93 | // check if id still different | ||
2173 | 94 | QVERIFY(contactAId != contactBId); | ||
2174 | 95 | } | ||
2175 | 96 | }; | ||
2176 | 97 | |||
2177 | 98 | QTEST_MAIN(ContactLinkTest) | ||
2178 | 99 | |||
2179 | 100 | #include "contact-link-test.moc" | ||
2180 | 0 | 101 | ||
2181 | === modified file 'tests/unittest/dummy-backend.cpp' | |||
2182 | --- tests/unittest/dummy-backend.cpp 2013-12-13 19:57:13 +0000 | |||
2183 | +++ tests/unittest/dummy-backend.cpp 2014-02-18 00:13:04 +0000 | |||
2184 | @@ -192,6 +192,24 @@ | |||
2185 | 192 | return QString(); | 192 | return QString(); |
2186 | 193 | } | 193 | } |
2187 | 194 | 194 | ||
2188 | 195 | void DummyBackendProxy::contactUpdated(const QString &contactId, | ||
2189 | 196 | const QString &errorMsg) | ||
2190 | 197 | { | ||
2191 | 198 | m_contactUpdated = true; | ||
2192 | 199 | } | ||
2193 | 200 | |||
2194 | 201 | QString DummyBackendProxy::updateContact(const QString &contactId, | ||
2195 | 202 | const QtContacts::QContact &qcontact) | ||
2196 | 203 | { | ||
2197 | 204 | galera::QIndividual *i = m_contacts.value(contactId); | ||
2198 | 205 | Q_ASSERT(i); | ||
2199 | 206 | ScopedEventLoop loop(&m_eventLoop); | ||
2200 | 207 | m_contactUpdated = false; | ||
2201 | 208 | i->update(qcontact, this, SLOT(contactUpdated(QString,QString))); | ||
2202 | 209 | loop.exec(); | ||
2203 | 210 | return i->id(); | ||
2204 | 211 | } | ||
2205 | 212 | |||
2206 | 195 | void DummyBackendProxy::configurePrimaryStore() | 213 | void DummyBackendProxy::configurePrimaryStore() |
2207 | 196 | { | 214 | { |
2208 | 197 | static const char* writableProperties[] = { | 215 | static const char* writableProperties[] = { |
2209 | @@ -205,6 +223,7 @@ | |||
2210 | 205 | "Dummy personas", | 223 | "Dummy personas", |
2211 | 206 | const_cast<char**>(writableProperties), 4); | 224 | const_cast<char**>(writableProperties), 4); |
2212 | 207 | folks_dummy_persona_store_set_persona_type(m_primaryPersonaStore, FOLKS_DUMMY_TYPE_FULL_PERSONA); | 225 | folks_dummy_persona_store_set_persona_type(m_primaryPersonaStore, FOLKS_DUMMY_TYPE_FULL_PERSONA); |
2213 | 226 | folks_dummy_persona_store_update_trust_level(m_primaryPersonaStore, FOLKS_PERSONA_STORE_TRUST_FULL); | ||
2214 | 208 | 227 | ||
2215 | 209 | GeeHashSet *personaStores = gee_hash_set_new(FOLKS_TYPE_PERSONA_STORE, | 228 | GeeHashSet *personaStores = gee_hash_set_new(FOLKS_TYPE_PERSONA_STORE, |
2216 | 210 | (GBoxedCopyFunc) g_object_ref, g_object_unref, | 229 | (GBoxedCopyFunc) g_object_ref, g_object_unref, |
2217 | @@ -349,9 +368,12 @@ | |||
2218 | 349 | GeeMultiMap *changes, | 368 | GeeMultiMap *changes, |
2219 | 350 | DummyBackendProxy *self) | 369 | DummyBackendProxy *self) |
2220 | 351 | { | 370 | { |
2221 | 371 | Q_UNUSED(individualAggregator); | ||
2222 | 372 | |||
2223 | 352 | GeeIterator *iter; | 373 | GeeIterator *iter; |
2224 | 353 | GeeSet *removed = gee_multi_map_get_keys(changes); | 374 | GeeSet *removed = gee_multi_map_get_keys(changes); |
2225 | 354 | GeeCollection *added = gee_multi_map_get_values(changes); | 375 | GeeCollection *added = gee_multi_map_get_values(changes); |
2226 | 376 | QStringList addedIds; | ||
2227 | 355 | 377 | ||
2228 | 356 | iter = gee_iterable_iterator(GEE_ITERABLE(added)); | 378 | iter = gee_iterable_iterator(GEE_ITERABLE(added)); |
2229 | 357 | while(gee_iterator_next(iter)) { | 379 | while(gee_iterator_next(iter)) { |
2230 | @@ -359,6 +381,7 @@ | |||
2231 | 359 | if (individual) { | 381 | if (individual) { |
2232 | 360 | galera::QIndividual *idv = new galera::QIndividual(individual, self->m_aggregator); | 382 | galera::QIndividual *idv = new galera::QIndividual(individual, self->m_aggregator); |
2233 | 361 | self->m_contacts.insert(idv->id(), idv); | 383 | self->m_contacts.insert(idv->id(), idv); |
2234 | 384 | addedIds << idv->id(); | ||
2235 | 362 | g_object_unref(individual); | 385 | g_object_unref(individual); |
2236 | 363 | } | 386 | } |
2237 | 364 | } | 387 | } |
2238 | @@ -369,7 +392,7 @@ | |||
2239 | 369 | FolksIndividual *individual = FOLKS_INDIVIDUAL(gee_iterator_get(iter)); | 392 | FolksIndividual *individual = FOLKS_INDIVIDUAL(gee_iterator_get(iter)); |
2240 | 370 | if (individual) { | 393 | if (individual) { |
2241 | 371 | QString id = QString::fromUtf8(folks_individual_get_id(individual)); | 394 | QString id = QString::fromUtf8(folks_individual_get_id(individual)); |
2243 | 372 | if (self->m_contacts.contains(id)) { | 395 | if (!addedIds.contains(id) && self->m_contacts.contains(id)) { |
2244 | 373 | delete self->m_contacts.take(id); | 396 | delete self->m_contacts.take(id); |
2245 | 374 | } | 397 | } |
2246 | 375 | g_object_unref(individual); | 398 | g_object_unref(individual); |
2247 | @@ -426,3 +449,15 @@ | |||
2248 | 426 | QList<QtContacts::QContact> contacts = galera::VCardParser::vcardToContact(QStringList() << vcard); | 449 | QList<QtContacts::QContact> contacts = galera::VCardParser::vcardToContact(QStringList() << vcard); |
2249 | 427 | return m_proxy->createContact(contacts[0]); | 450 | return m_proxy->createContact(contacts[0]); |
2250 | 428 | } | 451 | } |
2251 | 452 | |||
2252 | 453 | QString DummyBackendAdaptor::updateContact(const QString &contactId, const QString &vcard) | ||
2253 | 454 | { | ||
2254 | 455 | QList<QtContacts::QContact> contacts = galera::VCardParser::vcardToContact(QStringList() << vcard); | ||
2255 | 456 | return m_proxy->updateContact(contactId, contacts[0]); | ||
2256 | 457 | } | ||
2257 | 458 | |||
2258 | 459 | void DummyBackendAdaptor::enableAutoLink(bool flag) | ||
2259 | 460 | { | ||
2260 | 461 | galera::QIndividual::enableAutoLink(flag); | ||
2261 | 462 | } | ||
2262 | 463 | |||
2263 | 429 | 464 | ||
2264 | === modified file 'tests/unittest/dummy-backend.h' | |||
2265 | --- tests/unittest/dummy-backend.h 2013-11-11 14:21:24 +0000 | |||
2266 | +++ tests/unittest/dummy-backend.h 2014-02-18 00:13:04 +0000 | |||
2267 | @@ -46,6 +46,7 @@ | |||
2268 | 46 | bool isReady() const; | 46 | bool isReady() const; |
2269 | 47 | 47 | ||
2270 | 48 | QString createContact(const QtContacts::QContact &qcontact); | 48 | QString createContact(const QtContacts::QContact &qcontact); |
2271 | 49 | QString updateContact(const QString &contactId, const QtContacts::QContact &qcontact); | ||
2272 | 49 | QList<QtContacts::QContact> contacts() const; | 50 | QList<QtContacts::QContact> contacts() const; |
2273 | 50 | QList<galera::QIndividual*> individuals() const; | 51 | QList<galera::QIndividual*> individuals() const; |
2274 | 51 | 52 | ||
2275 | @@ -55,6 +56,7 @@ | |||
2276 | 55 | void shutdown(); | 56 | void shutdown(); |
2277 | 56 | QStringList listContacts() const; | 57 | QStringList listContacts() const; |
2278 | 57 | void reset(); | 58 | void reset(); |
2279 | 59 | void contactUpdated(const QString &contactId, const QString &errorMsg); | ||
2280 | 58 | 60 | ||
2281 | 59 | Q_SIGNALS: | 61 | Q_SIGNALS: |
2282 | 60 | void ready(); | 62 | void ready(); |
2283 | @@ -71,6 +73,7 @@ | |||
2284 | 71 | bool m_isReady; | 73 | bool m_isReady; |
2285 | 72 | int m_individualsChangedDetailedId; | 74 | int m_individualsChangedDetailedId; |
2286 | 73 | QHash<QString, galera::QIndividual*> m_contacts; | 75 | QHash<QString, galera::QIndividual*> m_contacts; |
2287 | 76 | bool m_contactUpdated; | ||
2288 | 74 | 77 | ||
2289 | 75 | bool registerObject(); | 78 | bool registerObject(); |
2290 | 76 | void initFolks(); | 79 | void initFolks(); |
2291 | @@ -108,10 +111,18 @@ | |||
2292 | 108 | " <arg direction=\"out\" type=\"b\"/>\n" | 111 | " <arg direction=\"out\" type=\"b\"/>\n" |
2293 | 109 | " </method>\n" | 112 | " </method>\n" |
2294 | 110 | " <method name=\"quit\"/>\n" | 113 | " <method name=\"quit\"/>\n" |
2295 | 114 | " <method name=\"enableAutoLink\">\n" | ||
2296 | 115 | " <arg direction=\"in\" type=\"b\"/>\n" | ||
2297 | 116 | " </method>\n" | ||
2298 | 111 | " <method name=\"createContact\">\n" | 117 | " <method name=\"createContact\">\n" |
2299 | 112 | " <arg direction=\"in\" type=\"s\"/>\n" | 118 | " <arg direction=\"in\" type=\"s\"/>\n" |
2300 | 113 | " <arg direction=\"out\" type=\"s\"/>\n" | 119 | " <arg direction=\"out\" type=\"s\"/>\n" |
2301 | 114 | " </method>\n" | 120 | " </method>\n" |
2302 | 121 | " <method name=\"updateContact\">\n" | ||
2303 | 122 | " <arg direction=\"in\" type=\"s\"/>\n" | ||
2304 | 123 | " <arg direction=\"in\" type=\"s\"/>\n" | ||
2305 | 124 | " <arg direction=\"out\" type=\"s\"/>\n" | ||
2306 | 125 | " </method>\n" | ||
2307 | 115 | " <method name=\"listContacts\">\n" | 126 | " <method name=\"listContacts\">\n" |
2308 | 116 | " <arg direction=\"out\" type=\"as\"/>\n" | 127 | " <arg direction=\"out\" type=\"as\"/>\n" |
2309 | 117 | " </method>\n" | 128 | " </method>\n" |
2310 | @@ -130,6 +141,8 @@ | |||
2311 | 130 | void reset(); | 141 | void reset(); |
2312 | 131 | QStringList listContacts(); | 142 | QStringList listContacts(); |
2313 | 132 | QString createContact(const QString &vcard); | 143 | QString createContact(const QString &vcard); |
2314 | 144 | QString updateContact(const QString &contactId, const QString &vcard); | ||
2315 | 145 | void enableAutoLink(bool flag); | ||
2316 | 133 | 146 | ||
2317 | 134 | Q_SIGNALS: | 147 | Q_SIGNALS: |
2318 | 135 | void ready(); | 148 | void ready(); |
PASSED: Continuous integration, rev:99 jenkins. qa.ubuntu. com/job/ address- book-service- ci/152/ jenkins. qa.ubuntu. com/job/ address- book-service- trusty- amd64-ci/ 59 jenkins. qa.ubuntu. com/job/ address- book-service- trusty- armhf-ci/ 59 jenkins. qa.ubuntu. com/job/ address- book-service- trusty- armhf-ci/ 59/artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ address- book-service- trusty- i386-ci/ 60
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/address- book-service- ci/152/ rebuild
http://