Merge lp:~renatofilho/address-book-service/fix-edit into lp:address-book-service
- fix-edit
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Bill Filler |
Approved revision: | no longer in the source branch. |
Merged at revision: | 36 |
Proposed branch: | lp:~renatofilho/address-book-service/fix-edit |
Merge into: | lp:address-book-service |
Prerequisite: | lp:~renatofilho/address-book-service/wait-for-server |
Diff against target: |
2729 lines (+1310/-735) 11 files modified
common/vcard-parser.cpp (+46/-8) common/vcard-parser.h (+2/-0) src/addressbook-adaptor.h (+4/-4) src/addressbook.cpp (+68/-70) src/addressbook.h (+8/-3) src/contacts-map.cpp (+11/-0) src/contacts-map.h (+1/-0) src/qindividual.cpp (+1107/-622) src/qindividual.h (+56/-26) src/view-adaptor.h (+2/-2) src/view.cpp (+5/-0) |
To merge this branch: | bzr merge lp:~renatofilho/address-book-service/fix-edit |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot | continuous-integration | Approve | |
Bill Filler (community) | Approve | ||
Review via email: mp+170609@code.launchpad.net |
This proposal supersedes a proposal from 2013-06-17.
Commit message
Added support to edit contacts with multiple persona.
Description of the change
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal | # |
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal | # |
FAILED: Continuous integration, rev:35
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal | # |
PASSED: Continuous integration, rev:36
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:37
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:39
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:40
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:41
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 35. By Renato Araujo Oliveira Filho
-
Fixed qcontacts plugins to wait for server fully start before request any data.
Approved by PS Jenkins bot, Bill Filler.
PS Jenkins bot (ps-jenkins) : | # |
- 36. By Renato Araujo Oliveira Filho
-
Added support to edit contacts with multiple persona.
Approved by PS Jenkins bot, Bill Filler.
Preview Diff
1 | === modified file 'common/vcard-parser.cpp' | |||
2 | --- common/vcard-parser.cpp 2013-05-18 01:11:38 +0000 | |||
3 | +++ common/vcard-parser.cpp 2013-06-20 20:58:26 +0000 | |||
4 | @@ -55,7 +55,7 @@ | |||
5 | 55 | 55 | ||
6 | 56 | if (detail.type() == QContactDetail::TypeExtendedDetail) { | 56 | if (detail.type() == QContactDetail::TypeExtendedDetail) { |
7 | 57 | const QContactExtendedDetail *extendedDetail = static_cast<const QContactExtendedDetail *>(&detail); | 57 | const QContactExtendedDetail *extendedDetail = static_cast<const QContactExtendedDetail *>(&detail); |
9 | 58 | if (extendedDetail->name() == "CLIENTPIDMAP") { | 58 | if (extendedDetail->name() == galera::VCardParser::PidMapFieldName) { |
10 | 59 | QVersitProperty prop; | 59 | QVersitProperty prop; |
11 | 60 | prop.setName(extendedDetail->name()); | 60 | prop.setName(extendedDetail->name()); |
12 | 61 | QStringList value; | 61 | QStringList value; |
13 | @@ -70,11 +70,12 @@ | |||
14 | 70 | } | 70 | } |
15 | 71 | 71 | ||
16 | 72 | if (!detail.detailUri().isEmpty()) { | 72 | if (!detail.detailUri().isEmpty()) { |
22 | 73 | QVersitProperty prop = toBeAdded->takeLast(); | 73 | if (toBeAdded->size() > 0) { |
23 | 74 | QMultiHash<QString, QString> params = prop.parameters(); | 74 | QVersitProperty &prop = toBeAdded->last(); |
24 | 75 | params.insert("PID", detail.detailUri()); | 75 | QMultiHash<QString, QString> params = prop.parameters(); |
25 | 76 | prop.setParameters(params); | 76 | params.insert(galera::VCardParser::PidFieldName, detail.detailUri()); |
26 | 77 | *toBeAdded << prop; | 77 | prop.setParameters(params); |
27 | 78 | } | ||
28 | 78 | } | 79 | } |
29 | 79 | } | 80 | } |
30 | 80 | 81 | ||
31 | @@ -102,16 +103,50 @@ | |||
32 | 102 | Q_UNUSED(document); | 103 | Q_UNUSED(document); |
33 | 103 | Q_UNUSED(contact); | 104 | Q_UNUSED(contact); |
34 | 104 | 105 | ||
36 | 105 | if (!*alreadyProcessed && (property.name() == "CLIENTPIDMAP")) { | 106 | if (!*alreadyProcessed && (property.name() == galera::VCardParser::PidMapFieldName)) { |
37 | 106 | QContactExtendedDetail detail; | 107 | QContactExtendedDetail detail; |
38 | 107 | detail.setName(property.name()); | 108 | detail.setName(property.name()); |
40 | 108 | QStringList value = property.value<QStringList>(); | 109 | QStringList value = property.value<QString>().split(";"); |
41 | 109 | detail.setValue(QContactExtendedDetail::FieldData, value[0]); | 110 | detail.setValue(QContactExtendedDetail::FieldData, value[0]); |
42 | 110 | detail.setValue(QContactExtendedDetail::FieldData + 1, value[1]); | 111 | detail.setValue(QContactExtendedDetail::FieldData + 1, value[1]); |
43 | 111 | *updatedDetails << detail; | 112 | *updatedDetails << detail; |
44 | 112 | *alreadyProcessed = true; | 113 | *alreadyProcessed = true; |
45 | 113 | } | 114 | } |
46 | 114 | 115 | ||
47 | 116 | QString pid = property.parameters().value(galera::VCardParser::PidFieldName); | ||
48 | 117 | if (!pid.isEmpty()) { | ||
49 | 118 | QContactDetail &det = updatedDetails->last(); | ||
50 | 119 | det.setDetailUri(pid); | ||
51 | 120 | } | ||
52 | 121 | |||
53 | 122 | // Remove empty phone and address subtypes | ||
54 | 123 | // Remove this after this fix get merged: https://codereview.qt-project.org/#change,59156 | ||
55 | 124 | if (updatedDetails->size() > 0) { | ||
56 | 125 | QContactDetail &det = updatedDetails->last(); | ||
57 | 126 | switch (det.type()) { | ||
58 | 127 | case QContactDetail::TypePhoneNumber: | ||
59 | 128 | { | ||
60 | 129 | QContactPhoneNumber phone = static_cast<QContactPhoneNumber>(det); | ||
61 | 130 | if (phone.subTypes().isEmpty()) { | ||
62 | 131 | det.setValue(QContactPhoneNumber::FieldSubTypes, QVariant()); | ||
63 | 132 | } | ||
64 | 133 | break; | ||
65 | 134 | } | ||
66 | 135 | case QContactDetail::TypeAddress: | ||
67 | 136 | { | ||
68 | 137 | QContactAddress addr = static_cast<QContactAddress>(det); | ||
69 | 138 | if (addr.subTypes().isEmpty()) { | ||
70 | 139 | det.setValue(QContactAddress::FieldSubTypes, QVariant()); | ||
71 | 140 | } else { | ||
72 | 141 | QSet<int> subtypes = addr.subTypes().toSet(); | ||
73 | 142 | det.setValue(QContactAddress::FieldSubTypes, QVariant::fromValue<QList<int> >(subtypes.toList())); | ||
74 | 143 | } | ||
75 | 144 | break; | ||
76 | 145 | } | ||
77 | 146 | default: | ||
78 | 147 | break; | ||
79 | 148 | } | ||
80 | 149 | } | ||
81 | 115 | } | 150 | } |
82 | 116 | 151 | ||
83 | 117 | virtual void documentProcessed(const QVersitDocument& document, QContact* contact) | 152 | virtual void documentProcessed(const QVersitDocument& document, QContact* contact) |
84 | @@ -125,6 +160,9 @@ | |||
85 | 125 | namespace galera | 160 | namespace galera |
86 | 126 | { | 161 | { |
87 | 127 | 162 | ||
88 | 163 | const QString VCardParser::PidMapFieldName = QString("CLIENTPIDMAP"); | ||
89 | 164 | const QString VCardParser::PidFieldName = QString("PID"); | ||
90 | 165 | |||
91 | 128 | QStringList VCardParser::contactToVcard(QList<QtContacts::QContact> contacts) | 166 | QStringList VCardParser::contactToVcard(QList<QtContacts::QContact> contacts) |
92 | 129 | { | 167 | { |
93 | 130 | QStringList result; | 168 | QStringList result; |
94 | 131 | 169 | ||
95 | === modified file 'common/vcard-parser.h' | |||
96 | --- common/vcard-parser.h 2013-05-18 01:11:38 +0000 | |||
97 | +++ common/vcard-parser.h 2013-06-20 20:58:26 +0000 | |||
98 | @@ -29,6 +29,8 @@ | |||
99 | 29 | class VCardParser | 29 | class VCardParser |
100 | 30 | { | 30 | { |
101 | 31 | public: | 31 | public: |
102 | 32 | static const QString PidMapFieldName; | ||
103 | 33 | static const QString PidFieldName; | ||
104 | 32 | 34 | ||
105 | 33 | static QStringList contactToVcard(QList<QtContacts::QContact> contacts); | 35 | static QStringList contactToVcard(QList<QtContacts::QContact> contacts); |
106 | 34 | static QtContacts::QContact vcardToContact(const QString &vcard); | 36 | static QtContacts::QContact vcardToContact(const QString &vcard); |
107 | 35 | 37 | ||
108 | === modified file 'src/addressbook-adaptor.h' | |||
109 | --- src/addressbook-adaptor.h 2013-06-20 20:58:26 +0000 | |||
110 | +++ src/addressbook-adaptor.h 2013-06-20 20:58:26 +0000 | |||
111 | @@ -99,13 +99,13 @@ | |||
112 | 99 | 99 | ||
113 | 100 | public Q_SLOTS: | 100 | public Q_SLOTS: |
114 | 101 | SourceList availableSources(); | 101 | SourceList availableSources(); |
115 | 102 | QStringList sortFields(); | ||
116 | 103 | QDBusObjectPath query(const QString &clause, const QString &sort, const QStringList &sources); | ||
117 | 104 | int removeContacts(const QStringList &contactIds, const QDBusMessage &message); | ||
118 | 102 | QString createContact(const QString &contact, const QString &source, const QDBusMessage &message); | 105 | QString createContact(const QString &contact, const QString &source, const QDBusMessage &message); |
119 | 106 | QStringList updateContacts(const QStringList &contacts, const QDBusMessage &message); | ||
120 | 103 | QString linkContacts(const QStringList &contacts); | 107 | QString linkContacts(const QStringList &contacts); |
121 | 104 | QDBusObjectPath query(const QString &clause, const QString &sort, const QStringList &sources); | ||
122 | 105 | int removeContacts(const QStringList &contactIds, const QDBusMessage &message); | ||
123 | 106 | QStringList sortFields(); | ||
124 | 107 | bool unlinkContacts(const QString &parentId, const QStringList &contactsIds); | 108 | bool unlinkContacts(const QString &parentId, const QStringList &contactsIds); |
125 | 108 | QStringList updateContacts(const QStringList &contacts, const QDBusMessage &message); | ||
126 | 109 | bool isReady(); | 109 | bool isReady(); |
127 | 110 | 110 | ||
128 | 111 | Q_SIGNALS: | 111 | Q_SIGNALS: |
129 | 112 | 112 | ||
130 | === modified file 'src/addressbook.cpp' | |||
131 | --- src/addressbook.cpp 2013-06-20 20:58:26 +0000 | |||
132 | +++ src/addressbook.cpp 2013-06-20 20:58:26 +0000 | |||
133 | @@ -26,7 +26,6 @@ | |||
134 | 26 | 26 | ||
135 | 27 | #include <QtCore/QPair> | 27 | #include <QtCore/QPair> |
136 | 28 | #include <QtCore/QUuid> | 28 | #include <QtCore/QUuid> |
137 | 29 | #include <QtContacts/QContact> | ||
138 | 30 | 29 | ||
139 | 31 | using namespace QtContacts; | 30 | using namespace QtContacts; |
140 | 32 | 31 | ||
141 | @@ -240,76 +239,75 @@ | |||
142 | 240 | 239 | ||
143 | 241 | QStringList AddressBook::updateContacts(const QStringList &contacts, const QDBusMessage &message) | 240 | QStringList AddressBook::updateContacts(const QStringList &contacts, const QDBusMessage &message) |
144 | 242 | { | 241 | { |
157 | 243 | UpdateContactsData *data = 0; | 242 | //TODO: support multiple update contacts calls |
158 | 244 | 243 | Q_ASSERT(m_updateCommandPendingContacts.isEmpty()); | |
159 | 245 | if (!contacts.isEmpty()) { | 244 | |
160 | 246 | data = new UpdateContactsData; | 245 | qDebug() << "update contacts:" << contacts; |
161 | 247 | data->m_contacts = VCardParser::vcardToContact(contacts); | 246 | m_updateCommandReplyMessage = message; |
162 | 248 | data->m_request = contacts; | 247 | m_updateCommandResult = contacts; |
163 | 249 | data->m_currentIndex = -1; | 248 | m_updateCommandPendingContacts << VCardParser::vcardToContact(contacts); |
164 | 250 | data->m_addressbook = this; | 249 | |
165 | 251 | data->m_message = message; | 250 | updateContactsDone(0, QString()); |
154 | 252 | |||
155 | 253 | } | ||
156 | 254 | updateContacts("", data); | ||
166 | 255 | 251 | ||
167 | 256 | return QStringList(); | 252 | return QStringList(); |
168 | 257 | } | 253 | } |
169 | 258 | 254 | ||
171 | 259 | void AddressBook::updateContacts(const QString &error, void *userData) | 255 | void AddressBook::updateContactsDone(galera::QIndividual *individual, const QString &error) |
172 | 260 | { | 256 | { |
198 | 261 | qDebug() << Q_FUNC_INFO << userData; | 257 | Q_UNUSED(individual); |
199 | 262 | UpdateContactsData *data = static_cast<UpdateContactsData*>(userData); | 258 | qDebug() << Q_FUNC_INFO; |
200 | 263 | QDBusMessage reply; | 259 | |
201 | 264 | 260 | if (!error.isEmpty()) { | |
202 | 265 | if (data) { | 261 | // update the result with the error |
203 | 266 | if (!error.isEmpty()) { | 262 | m_updateCommandResult[m_updateCommandResult.size() - m_updateCommandPendingContacts.size() - 1] = error; |
204 | 267 | data->m_result << error; | 263 | } |
205 | 268 | } else if (data->m_currentIndex > -1) { | 264 | |
206 | 269 | data->m_result << data->m_request[data->m_currentIndex]; | 265 | if (!m_updateCommandPendingContacts.isEmpty()) { |
207 | 270 | } | 266 | QContact newContact = m_updateCommandPendingContacts.takeFirst(); |
208 | 271 | 267 | ContactEntry *entry = m_contacts->value(newContact.detail<QContactGuid>().guid()); | |
209 | 272 | if (!data->m_contacts.isEmpty()) { | 268 | if (entry) { |
210 | 273 | QContact newContact = data->m_contacts.takeFirst(); | 269 | entry->individual()->update(newContact, this, "updateContactsDone(galera::QIndividual*, const QString&)"); //)); |
211 | 274 | data->m_currentIndex++; | 270 | } else { |
212 | 275 | 271 | updateContactsDone(0, "Contact not found!"); | |
213 | 276 | ContactEntry *entry = data->m_addressbook->m_contacts->value(newContact.detail<QContactGuid>().guid()); | 272 | } |
189 | 277 | if (entry) { | ||
190 | 278 | entry->individual()->update(newContact, updateContacts, userData); | ||
191 | 279 | } else { | ||
192 | 280 | updateContacts("Contact not found!", userData); | ||
193 | 281 | } | ||
194 | 282 | return; | ||
195 | 283 | } | ||
196 | 284 | folks_persona_store_flush(folks_individual_aggregator_get_primary_store(data->m_addressbook->m_individualAggregator), 0, 0); | ||
197 | 285 | reply = data->m_message.createReply(data->m_result); | ||
214 | 286 | } else { | 273 | } else { |
216 | 287 | reply = data->m_message.createReply(QStringList()); | 274 | folks_persona_store_flush(folks_individual_aggregator_get_primary_store(m_individualAggregator), 0, 0); |
217 | 275 | QDBusMessage reply = m_updateCommandReplyMessage.createReply(m_updateCommandResult); | ||
218 | 276 | QDBusConnection::sessionBus().send(reply); | ||
219 | 277 | |||
220 | 278 | // clear command data | ||
221 | 279 | m_updateCommandResult.clear(); | ||
222 | 280 | m_updateCommandReplyMessage = QDBusMessage(); | ||
223 | 288 | } | 281 | } |
224 | 289 | |||
225 | 290 | QDBusConnection::sessionBus().send(reply); | ||
226 | 291 | delete data; | ||
227 | 292 | } | 282 | } |
228 | 293 | 283 | ||
229 | 294 | 284 | ||
230 | 295 | QString AddressBook::removeContact(FolksIndividual *individual) | 285 | QString AddressBook::removeContact(FolksIndividual *individual) |
231 | 296 | { | 286 | { |
238 | 297 | Q_ASSERT(m_contacts->contains(individual)); | 287 | if (m_contacts->contains(individual)) { |
239 | 298 | ContactEntry *ci = m_contacts->take(individual); | 288 | ContactEntry *ci = m_contacts->take(individual); |
240 | 299 | if (ci) { | 289 | if (ci) { |
241 | 300 | QString id = QString::fromUtf8(folks_individual_get_id(individual)); | 290 | QString id = QString::fromUtf8(folks_individual_get_id(individual)); |
242 | 301 | delete ci; | 291 | qDebug() << "Remove contact" << id; |
243 | 302 | return id; | 292 | delete ci; |
244 | 293 | return id; | ||
245 | 294 | } | ||
246 | 303 | } | 295 | } |
247 | 304 | return QString(); | 296 | return QString(); |
248 | 305 | } | 297 | } |
249 | 306 | 298 | ||
250 | 307 | QString AddressBook::addContact(FolksIndividual *individual) | 299 | QString AddressBook::addContact(FolksIndividual *individual) |
251 | 308 | { | 300 | { |
256 | 309 | Q_ASSERT(!m_contacts->contains(individual)); | 301 | QString id = QString::fromUtf8(folks_individual_get_id(individual)); |
257 | 310 | m_contacts->insert(new ContactEntry(new QIndividual(individual, m_individualAggregator))); | 302 | ContactEntry *entry = m_contacts->value(id); |
258 | 311 | //TODO: Notify view | 303 | if (entry) { |
259 | 312 | return QString::fromUtf8(folks_individual_get_id(individual)); | 304 | entry->individual()->setIndividual(individual); |
260 | 305 | } else { | ||
261 | 306 | m_contacts->insert(new ContactEntry(new QIndividual(individual, m_individualAggregator))); | ||
262 | 307 | qDebug() << "Add contact" << folks_individual_get_id(individual); | ||
263 | 308 | //TODO: Notify view | ||
264 | 309 | } | ||
265 | 310 | return id; | ||
266 | 313 | } | 311 | } |
267 | 314 | 312 | ||
268 | 315 | void AddressBook::individualsChangedCb(FolksIndividualAggregator *individualAggregator, | 313 | void AddressBook::individualsChangedCb(FolksIndividualAggregator *individualAggregator, |
269 | @@ -322,28 +320,28 @@ | |||
270 | 322 | 320 | ||
271 | 323 | GeeIterator *iter; | 321 | GeeIterator *iter; |
272 | 324 | GeeSet *removed = gee_multi_map_get_keys(changes); | 322 | GeeSet *removed = gee_multi_map_get_keys(changes); |
273 | 325 | iter = gee_iterable_iterator(GEE_ITERABLE(removed)); | ||
274 | 326 | |||
275 | 327 | while(gee_iterator_next(iter)) { | ||
276 | 328 | FolksIndividual *individual = FOLKS_INDIVIDUAL(gee_iterator_get(iter)); | ||
277 | 329 | if (individual) { | ||
278 | 330 | QString id = self->removeContact(individual); | ||
279 | 331 | if(!id.isEmpty()) { | ||
280 | 332 | removedIds << id; | ||
281 | 333 | } | ||
282 | 334 | g_object_unref(individual); | ||
283 | 335 | } | ||
284 | 336 | } | ||
285 | 337 | g_object_unref (iter); | ||
286 | 338 | |||
287 | 339 | GeeCollection *added = gee_multi_map_get_values(changes); | 323 | GeeCollection *added = gee_multi_map_get_values(changes); |
288 | 324 | |||
289 | 340 | iter = gee_iterable_iterator(GEE_ITERABLE(added)); | 325 | iter = gee_iterable_iterator(GEE_ITERABLE(added)); |
290 | 341 | while(gee_iterator_next(iter)) { | 326 | while(gee_iterator_next(iter)) { |
291 | 342 | FolksIndividual *individual = FOLKS_INDIVIDUAL(gee_iterator_get(iter)); | 327 | FolksIndividual *individual = FOLKS_INDIVIDUAL(gee_iterator_get(iter)); |
292 | 343 | if (individual) { | 328 | if (individual) { |
296 | 344 | QString id = self->addContact(individual); | 329 | // add contact to the map |
297 | 345 | if(!id.isEmpty()) { | 330 | addedIds << self->addContact(individual); |
298 | 346 | addedIds << id; | 331 | g_object_unref(individual); |
299 | 332 | } | ||
300 | 333 | } | ||
301 | 334 | g_object_unref (iter); | ||
302 | 335 | |||
303 | 336 | |||
304 | 337 | iter = gee_iterable_iterator(GEE_ITERABLE(removed)); | ||
305 | 338 | while(gee_iterator_next(iter)) { | ||
306 | 339 | FolksIndividual *individual = FOLKS_INDIVIDUAL(gee_iterator_get(iter)); | ||
307 | 340 | if (individual) { | ||
308 | 341 | QString id = QString::fromUtf8(folks_individual_get_id(individual)); | ||
309 | 342 | if (!addedIds.contains(id)) { | ||
310 | 343 | // delete from contact map | ||
311 | 344 | removedIds << self->removeContact(individual); | ||
312 | 347 | } | 345 | } |
313 | 348 | g_object_unref(individual); | 346 | g_object_unref(individual); |
314 | 349 | } | 347 | } |
315 | 350 | 348 | ||
316 | === modified file 'src/addressbook.h' | |||
317 | --- src/addressbook.h 2013-06-20 20:58:26 +0000 | |||
318 | +++ src/addressbook.h 2013-06-20 20:58:26 +0000 | |||
319 | @@ -28,6 +28,8 @@ | |||
320 | 28 | 28 | ||
321 | 29 | #include <QtDBus/QtDBus> | 29 | #include <QtDBus/QtDBus> |
322 | 30 | 30 | ||
323 | 31 | #include <QtContacts/QContact> | ||
324 | 32 | |||
325 | 31 | #include <folks/folks.h> | 33 | #include <folks/folks.h> |
326 | 32 | #include <glib.h> | 34 | #include <glib.h> |
327 | 33 | #include <glib-object.h> | 35 | #include <glib-object.h> |
328 | @@ -37,6 +39,7 @@ | |||
329 | 37 | class View; | 39 | class View; |
330 | 38 | class ContactsMap; | 40 | class ContactsMap; |
331 | 39 | class AddressBookAdaptor; | 41 | class AddressBookAdaptor; |
332 | 42 | class QIndividual; | ||
333 | 40 | 43 | ||
334 | 41 | class AddressBook: public QObject | 44 | class AddressBook: public QObject |
335 | 42 | { | 45 | { |
336 | @@ -60,6 +63,7 @@ | |||
337 | 60 | QString createContact(const QString &contact, const QString &source, const QDBusMessage &message); | 63 | QString createContact(const QString &contact, const QString &source, const QDBusMessage &message); |
338 | 61 | int removeContacts(const QStringList &contactIds, const QDBusMessage &message); | 64 | int removeContacts(const QStringList &contactIds, const QDBusMessage &message); |
339 | 62 | QStringList updateContacts(const QStringList &contacts, const QDBusMessage &message); | 65 | QStringList updateContacts(const QStringList &contacts, const QDBusMessage &message); |
340 | 66 | void updateContactsDone(galera::QIndividual *individual, const QString &error); | ||
341 | 63 | 67 | ||
342 | 64 | private Q_SLOTS: | 68 | private Q_SLOTS: |
343 | 65 | void viewClosed(); | 69 | void viewClosed(); |
344 | @@ -71,14 +75,15 @@ | |||
345 | 71 | bool m_ready; | 75 | bool m_ready; |
346 | 72 | AddressBookAdaptor *m_adaptor; | 76 | AddressBookAdaptor *m_adaptor; |
347 | 73 | 77 | ||
348 | 78 | // Update command | ||
349 | 79 | QDBusMessage m_updateCommandReplyMessage; | ||
350 | 80 | QStringList m_updateCommandResult; | ||
351 | 81 | QList<QtContacts::QContact> m_updateCommandPendingContacts; | ||
352 | 74 | 82 | ||
353 | 75 | void prepareFolks(); | 83 | void prepareFolks(); |
354 | 76 | QString removeContact(FolksIndividual *individual); | 84 | QString removeContact(FolksIndividual *individual); |
355 | 77 | QString addContact(FolksIndividual *individual); | 85 | QString addContact(FolksIndividual *individual); |
356 | 78 | 86 | ||
357 | 79 | |||
358 | 80 | static void updateContacts(const QString &error, void *userData); | ||
359 | 81 | |||
360 | 82 | static void individualsChangedCb(FolksIndividualAggregator *individualAggregator, | 87 | static void individualsChangedCb(FolksIndividualAggregator *individualAggregator, |
361 | 83 | GeeMultiMap *changes, | 88 | GeeMultiMap *changes, |
362 | 84 | AddressBook *self); | 89 | AddressBook *self); |
363 | 85 | 90 | ||
364 | === modified file 'src/contacts-map.cpp' | |||
365 | --- src/contacts-map.cpp 2013-06-11 13:00:01 +0000 | |||
366 | +++ src/contacts-map.cpp 2013-06-20 20:58:26 +0000 | |||
367 | @@ -28,6 +28,7 @@ | |||
368 | 28 | ContactEntry::ContactEntry(QIndividual *individual) | 28 | ContactEntry::ContactEntry(QIndividual *individual) |
369 | 29 | : m_individual(individual) | 29 | : m_individual(individual) |
370 | 30 | { | 30 | { |
371 | 31 | Q_ASSERT(individual); | ||
372 | 31 | } | 32 | } |
373 | 32 | 33 | ||
374 | 33 | ContactEntry::~ContactEntry() | 34 | ContactEntry::~ContactEntry() |
375 | @@ -75,6 +76,16 @@ | |||
376 | 75 | return 0; | 76 | return 0; |
377 | 76 | } | 77 | } |
378 | 77 | 78 | ||
379 | 79 | void ContactsMap::remove(const QString &id) | ||
380 | 80 | { | ||
381 | 81 | ContactEntry *entry = m_idToEntry[id]; | ||
382 | 82 | if (entry) { | ||
383 | 83 | m_individualsToEntry.remove(entry->individual()->individual()); | ||
384 | 84 | m_idToEntry.remove(id); | ||
385 | 85 | delete entry; | ||
386 | 86 | } | ||
387 | 87 | } | ||
388 | 88 | |||
389 | 78 | bool ContactsMap::contains(FolksIndividual *individual) const | 89 | bool ContactsMap::contains(FolksIndividual *individual) const |
390 | 79 | { | 90 | { |
391 | 80 | return m_individualsToEntry.contains(individual); | 91 | return m_individualsToEntry.contains(individual); |
392 | 81 | 92 | ||
393 | === modified file 'src/contacts-map.h' | |||
394 | --- src/contacts-map.h 2013-06-11 13:00:01 +0000 | |||
395 | +++ src/contacts-map.h 2013-06-20 20:58:26 +0000 | |||
396 | @@ -60,6 +60,7 @@ | |||
397 | 60 | ContactEntry *value(FolksIndividual *individual) const; | 60 | ContactEntry *value(FolksIndividual *individual) const; |
398 | 61 | ContactEntry *value(const QString &id) const; | 61 | ContactEntry *value(const QString &id) const; |
399 | 62 | ContactEntry *take(FolksIndividual *individual); | 62 | ContactEntry *take(FolksIndividual *individual); |
400 | 63 | void remove(const QString &id); | ||
401 | 63 | void insert(ContactEntry *entry); | 64 | void insert(ContactEntry *entry); |
402 | 64 | int size() const; | 65 | int size() const; |
403 | 65 | 66 | ||
404 | 66 | 67 | ||
405 | === modified file 'src/qindividual.cpp' | |||
406 | --- src/qindividual.cpp 2013-06-11 21:49:45 +0000 | |||
407 | +++ src/qindividual.cpp 2013-06-20 20:58:26 +0000 | |||
408 | @@ -53,14 +53,14 @@ | |||
409 | 53 | class UpdateContactData | 53 | class UpdateContactData |
410 | 54 | { | 54 | { |
411 | 55 | public: | 55 | public: |
412 | 56 | QContactDetail::DetailType m_currentDetailType; | ||
413 | 57 | QContact m_newContact; | 56 | QContact m_newContact; |
414 | 58 | galera::QIndividual *m_self; | 57 | galera::QIndividual *m_self; |
420 | 59 | FolksPersona *m_persona; | 58 | |
421 | 60 | 59 | QList<QContactDetail> m_details; | |
422 | 61 | QList<QContactDetail> m_detailsChanged; | 60 | QContactDetail m_currentDetail; |
423 | 62 | galera::UpdateDoneCB m_doneCB; | 61 | |
424 | 63 | void *m_doneData; | 62 | QObject *m_object; |
425 | 63 | QMetaMethod m_slot; | ||
426 | 64 | }; | 64 | }; |
427 | 65 | 65 | ||
428 | 66 | #ifdef FOLKS_0_9_0 | 66 | #ifdef FOLKS_0_9_0 |
429 | @@ -82,9 +82,6 @@ | |||
430 | 82 | namespace galera | 82 | namespace galera |
431 | 83 | { | 83 | { |
432 | 84 | 84 | ||
433 | 85 | // TODO: find a better way to link abstract field with details | ||
434 | 86 | #define FOLKS_DATA_FIELD 10000 | ||
435 | 87 | |||
436 | 88 | #ifdef FOLKS_0_9_0 | 85 | #ifdef FOLKS_0_9_0 |
437 | 89 | #define SET_AFD_NEW() \ | 86 | #define SET_AFD_NEW() \ |
438 | 90 | GEE_SET(gee_hash_set_new(FOLKS_TYPE_ABSTRACT_FIELD_DETAILS, \ | 87 | GEE_SET(gee_hash_set_new(FOLKS_TYPE_ABSTRACT_FIELD_DETAILS, \ |
439 | @@ -96,6 +93,16 @@ | |||
440 | 96 | NULL, \ | 93 | NULL, \ |
441 | 97 | NULL)) | 94 | NULL)) |
442 | 98 | 95 | ||
443 | 96 | #define SET_PERSONA_NEW() \ | ||
444 | 97 | GEE_SET(gee_hash_set_new(FOLKS_TYPE_PERSONA, \ | ||
445 | 98 | (GBoxedCopyFunc) g_object_ref, g_object_unref, \ | ||
446 | 99 | NULL, \ | ||
447 | 100 | NULL, \ | ||
448 | 101 | NULL, \ | ||
449 | 102 | NULL, \ | ||
450 | 103 | NULL, \ | ||
451 | 104 | NULL)) | ||
452 | 105 | |||
453 | 99 | #define GEE_MULTI_MAP_AFD_NEW(FOLKS_TYPE) \ | 106 | #define GEE_MULTI_MAP_AFD_NEW(FOLKS_TYPE) \ |
454 | 100 | GEE_MULTI_MAP(gee_hash_multi_map_new(G_TYPE_STRING,\ | 107 | GEE_MULTI_MAP(gee_hash_multi_map_new(G_TYPE_STRING,\ |
455 | 101 | (GBoxedCopyFunc) g_strdup, g_free, \ | 108 | (GBoxedCopyFunc) g_strdup, g_free, \ |
456 | @@ -120,6 +127,13 @@ | |||
457 | 120 | (GHashFunc) folks_abstract_field_details_hash, \ | 127 | (GHashFunc) folks_abstract_field_details_hash, \ |
458 | 121 | (GEqualFunc) folks_abstract_field_details_equal)) | 128 | (GEqualFunc) folks_abstract_field_details_equal)) |
459 | 122 | 129 | ||
460 | 130 | #define SET_PERSONA_NEW() \ | ||
461 | 131 | GEE_SET(gee_hash_set_new(FOLKS_TYPE_PERSONA, \ | ||
462 | 132 | (GBoxedCopyFunc) g_object_ref, g_object_unref, \ | ||
463 | 133 | NULL, \ | ||
464 | 134 | NULL)) | ||
465 | 135 | |||
466 | 136 | |||
467 | 123 | #define GEE_MULTI_MAP_AFD_NEW(FOLKS_TYPE) \ | 137 | #define GEE_MULTI_MAP_AFD_NEW(FOLKS_TYPE) \ |
468 | 124 | GEE_MULTI_MAP(gee_hash_multi_map_new(G_TYPE_STRING, \ | 138 | GEE_MULTI_MAP(gee_hash_multi_map_new(G_TYPE_STRING, \ |
469 | 125 | (GBoxedCopyFunc) g_strdup, \ | 139 | (GBoxedCopyFunc) g_strdup, \ |
470 | @@ -131,16 +145,17 @@ | |||
471 | 131 | (GHashFunc) folks_abstract_field_details_hash, \ | 145 | (GHashFunc) folks_abstract_field_details_hash, \ |
472 | 132 | (GEqualFunc) folks_abstract_field_details_equal)); | 146 | (GEqualFunc) folks_abstract_field_details_equal)); |
473 | 133 | 147 | ||
474 | 148 | |||
475 | 149 | |||
476 | 134 | #endif | 150 | #endif |
477 | 135 | 151 | ||
478 | 136 | 152 | ||
479 | 137 | #define PERSONA_DETAILS_INSERT_STRING_FIELD_DETAILS(\ | 153 | #define PERSONA_DETAILS_INSERT_STRING_FIELD_DETAILS(\ |
481 | 138 | details, key, value, q_type, g_type, member) \ | 154 | details, cDetails, key, value, q_type, g_type, member) \ |
482 | 139 | { \ | 155 | { \ |
485 | 140 | QList<q_type> contactDetails = contact.details<q_type>(); \ | 156 | if(cDetails.size() > 0) { \ |
484 | 141 | if(contactDetails.size() > 0) { \ | ||
486 | 142 | value = QIndividualUtils::gValueSliceNew(G_TYPE_OBJECT); \ | 157 | value = QIndividualUtils::gValueSliceNew(G_TYPE_OBJECT); \ |
488 | 143 | Q_FOREACH(const q_type& detail, contact.details<q_type>()) { \ | 158 | Q_FOREACH(const q_type& detail, cDetails) { \ |
489 | 144 | if(!detail.isEmpty()) { \ | 159 | if(!detail.isEmpty()) { \ |
490 | 145 | QIndividualUtils::gValueGeeSetAddStringFieldDetails(value, (g_type), \ | 160 | QIndividualUtils::gValueGeeSetAddStringFieldDetails(value, (g_type), \ |
491 | 146 | detail.member().toUtf8().data(), \ | 161 | detail.member().toUtf8().data(), \ |
492 | @@ -242,10 +257,53 @@ | |||
493 | 242 | return retval; | 257 | return retval; |
494 | 243 | } | 258 | } |
495 | 244 | 259 | ||
496 | 260 | static FolksAbstractFieldDetails *getDetails(GeeSet *set, const QString &uri) | ||
497 | 261 | { | ||
498 | 262 | Q_ASSERT(set); | ||
499 | 263 | |||
500 | 264 | int pos = 0; | ||
501 | 265 | int size = 0; | ||
502 | 266 | QStringList index = uri.split("."); | ||
503 | 267 | gpointer* values = gee_collection_to_array(GEE_COLLECTION(set), &size); | ||
504 | 268 | |||
505 | 269 | if (size == 0) { | ||
506 | 270 | return 0; | ||
507 | 271 | } else if (index.count() == 2) { | ||
508 | 272 | pos = index[1].toInt() - 1; | ||
509 | 273 | Q_ASSERT(pos >= 0); | ||
510 | 274 | Q_ASSERT(pos < size); | ||
511 | 275 | } | ||
512 | 276 | return FOLKS_ABSTRACT_FIELD_DETAILS(values[pos]); | ||
513 | 277 | } | ||
514 | 278 | |||
515 | 279 | static FolksPersona *personaFromUri(const QString &uri, FolksIndividual *individual, FolksPersona *defaultPersona) | ||
516 | 280 | { | ||
517 | 281 | Q_ASSERT(individual); | ||
518 | 282 | |||
519 | 283 | if (uri.isEmpty()) { | ||
520 | 284 | //TODO | ||
521 | 285 | qWarning() << "NO PERSONA"; | ||
522 | 286 | return defaultPersona; | ||
523 | 287 | } else { | ||
524 | 288 | |||
525 | 289 | GeeSet *personas = folks_individual_get_personas(individual); | ||
526 | 290 | QStringList index = uri.split("."); | ||
527 | 291 | Q_ASSERT(index.count() >= 1); | ||
528 | 292 | int pos = index[0].toInt() - 1; | ||
529 | 293 | int size = 0; | ||
530 | 294 | gpointer* values = gee_collection_to_array(GEE_COLLECTION(personas), &size); | ||
531 | 295 | Q_ASSERT(pos >= 0); | ||
532 | 296 | Q_ASSERT(pos < size); | ||
533 | 297 | |||
534 | 298 | return FOLKS_PERSONA(values[pos]); | ||
535 | 299 | } | ||
536 | 300 | } | ||
537 | 301 | |||
538 | 245 | }; // class | 302 | }; // class |
539 | 246 | 303 | ||
540 | 247 | QIndividual::QIndividual(FolksIndividual *individual, FolksIndividualAggregator *aggregator) | 304 | QIndividual::QIndividual(FolksIndividual *individual, FolksIndividualAggregator *aggregator) |
541 | 248 | : m_individual(individual), | 305 | : m_individual(individual), |
542 | 306 | m_primaryPersona(0), | ||
543 | 249 | m_aggregator(aggregator) | 307 | m_aggregator(aggregator) |
544 | 250 | { | 308 | { |
545 | 251 | g_object_ref(m_individual); | 309 | g_object_ref(m_individual); |
546 | @@ -267,7 +325,6 @@ | |||
547 | 267 | QList<QtContacts::QContactDetail> QIndividual::getClientPidMap() const | 325 | QList<QtContacts::QContactDetail> QIndividual::getClientPidMap() const |
548 | 268 | { | 326 | { |
549 | 269 | QList<QtContacts::QContactDetail> details; | 327 | QList<QtContacts::QContactDetail> details; |
550 | 270 | /* | ||
551 | 271 | int index = 1; | 328 | int index = 1; |
552 | 272 | GeeSet *personas = folks_individual_get_personas(m_individual); | 329 | GeeSet *personas = folks_individual_get_personas(m_individual); |
553 | 273 | GeeIterator *iter = gee_iterable_iterator(GEE_ITERABLE(personas)); | 330 | GeeIterator *iter = gee_iterable_iterator(GEE_ITERABLE(personas)); |
554 | @@ -282,16 +339,75 @@ | |||
555 | 282 | } | 339 | } |
556 | 283 | 340 | ||
557 | 284 | g_object_unref(iter); | 341 | g_object_unref(iter); |
565 | 285 | */ | 342 | return details; |
566 | 286 | return details; | 343 | } |
567 | 287 | } | 344 | |
568 | 288 | 345 | void QIndividual::appendDetailsForPersona(QList<QtContacts::QContactDetail> *list, QtContacts::QContactDetail detail, const QString &personaIndex, bool readOnly) const | |
569 | 289 | 346 | { | |
570 | 290 | QtContacts::QContactDetail QIndividual::getName() const | 347 | if (!detail.isEmpty()) { |
571 | 291 | { | 348 | detail.setDetailUri(personaIndex); |
572 | 349 | if (readOnly) { | ||
573 | 350 | QContactManagerEngine::setDetailAccessConstraints(&detail, QContactDetail::ReadOnly); | ||
574 | 351 | } | ||
575 | 352 | list->append(detail); | ||
576 | 353 | } | ||
577 | 354 | } | ||
578 | 355 | |||
579 | 356 | void QIndividual::appendDetailsForPersona(QList<QtContacts::QContactDetail> *list, QList<QtContacts::QContactDetail> details, const QString &personaIndex, bool readOnly) const | ||
580 | 357 | { | ||
581 | 358 | int subIndex = 1; | ||
582 | 359 | Q_FOREACH(QContactDetail detail, details) { | ||
583 | 360 | appendDetailsForPersona(list, detail, QString("%1.%2").arg(personaIndex).arg(subIndex), readOnly); | ||
584 | 361 | subIndex++; | ||
585 | 362 | } | ||
586 | 363 | } | ||
587 | 364 | |||
588 | 365 | |||
589 | 366 | QList<QContactDetail> QIndividual::getDetails() const | ||
590 | 367 | { | ||
591 | 368 | int personaIndex = 1; | ||
592 | 369 | QList<QContactDetail> details; | ||
593 | 370 | GeeSet *personas = folks_individual_get_personas(m_individual); | ||
594 | 371 | GeeIterator *iter = gee_iterable_iterator(GEE_ITERABLE(personas)); | ||
595 | 372 | |||
596 | 373 | while(gee_iterator_next(iter)) { | ||
597 | 374 | FolksPersona *persona = FOLKS_PERSONA(gee_iterator_get(iter)); | ||
598 | 375 | |||
599 | 376 | int wsize = 0; | ||
600 | 377 | gchar **wproperties = folks_persona_get_writeable_properties(persona, &wsize); | ||
601 | 378 | //"gender", "local-ids", "avatar", "postal-addresses", "urls", "phone-numbers", "structured-name", | ||
602 | 379 | //"anti-links", "im-addresses", "is-favourite", "birthday", "notes", "roles", "email-addresses", | ||
603 | 380 | //"web-service-addresses", "groups", "full-name" | ||
604 | 381 | QStringList wPropList; | ||
605 | 382 | for(int i=0; i < wsize; i++) { | ||
606 | 383 | wPropList << wproperties[i]; | ||
607 | 384 | } | ||
608 | 385 | |||
609 | 386 | QString index = QString::number(personaIndex); | ||
610 | 387 | |||
611 | 388 | appendDetailsForPersona(&details, getPersonaName(persona), index, !wPropList.contains("structured-name")); | ||
612 | 389 | appendDetailsForPersona(&details, getPersonaFullName(persona), index, !wPropList.contains("full-name")); | ||
613 | 390 | appendDetailsForPersona(&details, getPersonaNickName(persona), index, !wPropList.contains("nickname")); | ||
614 | 391 | appendDetailsForPersona(&details, getPersonaBirthday(persona), index, !wPropList.contains("birthday")); | ||
615 | 392 | appendDetailsForPersona(&details, getPersonaRoles(persona), index, !wPropList.contains("roles")); | ||
616 | 393 | appendDetailsForPersona(&details, getPersonaEmails(persona), index, !wPropList.contains("email-addresses")); | ||
617 | 394 | appendDetailsForPersona(&details, getPersonaPhones(persona), index, !wPropList.contains("phone-numbers")); | ||
618 | 395 | appendDetailsForPersona(&details, getPersonaAddresses(persona), index, !wPropList.contains("postal-addresses")); | ||
619 | 396 | appendDetailsForPersona(&details, getPersonaIms(persona), index, !wPropList.contains("im-addresses")); | ||
620 | 397 | appendDetailsForPersona(&details, getPersonaUrls(persona), index, !wPropList.contains("urls")); | ||
621 | 398 | personaIndex++; | ||
622 | 399 | } | ||
623 | 400 | return details; | ||
624 | 401 | } | ||
625 | 402 | |||
626 | 403 | QContactDetail QIndividual::getPersonaName(FolksPersona *persona) const | ||
627 | 404 | { | ||
628 | 405 | if (!FOLKS_IS_NAME_DETAILS(persona)) { | ||
629 | 406 | return QContactDetail(); | ||
630 | 407 | } | ||
631 | 408 | |||
632 | 292 | QContactName detail; | 409 | QContactName detail; |
635 | 293 | FolksStructuredName *sn = folks_name_details_get_structured_name(FOLKS_NAME_DETAILS(m_individual)); | 410 | FolksStructuredName *sn = folks_name_details_get_structured_name(FOLKS_NAME_DETAILS(persona)); |
634 | 294 | |||
636 | 295 | if (sn) { | 411 | if (sn) { |
637 | 296 | const char *name = folks_structured_name_get_given_name(sn); | 412 | const char *name = folks_structured_name_get_given_name(sn); |
638 | 297 | if (name && strlen(name)) { | 413 | if (name && strlen(name)) { |
639 | @@ -317,30 +433,42 @@ | |||
640 | 317 | return detail; | 433 | return detail; |
641 | 318 | } | 434 | } |
642 | 319 | 435 | ||
644 | 320 | QtContacts::QContactDetail QIndividual::getFullName() const | 436 | QtContacts::QContactDetail QIndividual::getPersonaFullName(FolksPersona *persona) const |
645 | 321 | { | 437 | { |
646 | 438 | if (!FOLKS_IS_NAME_DETAILS(persona)) { | ||
647 | 439 | return QContactDetail(); | ||
648 | 440 | } | ||
649 | 441 | |||
650 | 322 | QContactDisplayLabel detail; | 442 | QContactDisplayLabel detail; |
652 | 323 | const gchar *fullName = folks_name_details_get_full_name(FOLKS_NAME_DETAILS(m_individual)); | 443 | const gchar *fullName = folks_name_details_get_full_name(FOLKS_NAME_DETAILS(persona)); |
653 | 324 | if (fullName && strlen(fullName)) { | 444 | if (fullName && strlen(fullName)) { |
654 | 325 | detail.setLabel(QString::fromUtf8(fullName)); | 445 | detail.setLabel(QString::fromUtf8(fullName)); |
655 | 326 | } | 446 | } |
656 | 327 | return detail; | 447 | return detail; |
657 | 328 | } | 448 | } |
658 | 329 | 449 | ||
660 | 330 | QtContacts::QContactDetail QIndividual::getNickname() const | 450 | QtContacts::QContactDetail QIndividual::getPersonaNickName(FolksPersona *persona) const |
661 | 331 | { | 451 | { |
662 | 452 | if (!FOLKS_IS_NAME_DETAILS(persona)) { | ||
663 | 453 | return QContactDetail(); | ||
664 | 454 | } | ||
665 | 455 | |||
666 | 332 | QContactNickname detail; | 456 | QContactNickname detail; |
668 | 333 | const gchar* nickname = folks_name_details_get_nickname(FOLKS_NAME_DETAILS(m_individual)); | 457 | const gchar* nickname = folks_name_details_get_nickname(FOLKS_NAME_DETAILS(persona)); |
669 | 334 | if (nickname && strlen(nickname)) { | 458 | if (nickname && strlen(nickname)) { |
670 | 335 | detail.setNickname(QString::fromUtf8(nickname)); | 459 | detail.setNickname(QString::fromUtf8(nickname)); |
671 | 336 | } | 460 | } |
672 | 337 | return detail; | 461 | return detail; |
673 | 338 | } | 462 | } |
674 | 339 | 463 | ||
676 | 340 | QtContacts::QContactDetail QIndividual::getBirthday() const | 464 | QtContacts::QContactDetail QIndividual::getPersonaBirthday(FolksPersona *persona) const |
677 | 341 | { | 465 | { |
678 | 466 | if (!FOLKS_IS_BIRTHDAY_DETAILS(persona)) { | ||
679 | 467 | return QContactDetail(); | ||
680 | 468 | } | ||
681 | 469 | |||
682 | 342 | QContactBirthday detail; | 470 | QContactBirthday detail; |
684 | 343 | GDateTime* datetime = folks_birthday_details_get_birthday(FOLKS_BIRTHDAY_DETAILS(m_individual)); | 471 | GDateTime* datetime = folks_birthday_details_get_birthday(FOLKS_BIRTHDAY_DETAILS(persona)); |
685 | 344 | if (datetime) { | 472 | if (datetime) { |
686 | 345 | QDate date(g_date_time_get_year(datetime), g_date_time_get_month(datetime), g_date_time_get_day_of_month(datetime)); | 473 | QDate date(g_date_time_get_year(datetime), g_date_time_get_month(datetime), g_date_time_get_day_of_month(datetime)); |
687 | 346 | QTime time(g_date_time_get_hour(datetime), g_date_time_get_minute(datetime), g_date_time_get_second(datetime)); | 474 | QTime time(g_date_time_get_hour(datetime), g_date_time_get_minute(datetime), g_date_time_get_second(datetime)); |
688 | @@ -349,16 +477,20 @@ | |||
689 | 349 | return detail; | 477 | return detail; |
690 | 350 | } | 478 | } |
691 | 351 | 479 | ||
693 | 352 | QtContacts::QContactDetail QIndividual::getPhoto() const | 480 | QtContacts::QContactDetail QIndividual::getPersonaPhoto(FolksPersona *persona) const |
694 | 353 | { | 481 | { |
695 | 354 | // TODO | 482 | // TODO |
696 | 355 | return QContactAvatar(); | 483 | return QContactAvatar(); |
697 | 356 | } | 484 | } |
698 | 357 | 485 | ||
700 | 358 | QList<QtContacts::QContactDetail> QIndividual::getRoles() const | 486 | QList<QtContacts::QContactDetail> QIndividual::getPersonaRoles(FolksPersona *persona) const |
701 | 359 | { | 487 | { |
702 | 488 | if (!FOLKS_IS_ROLE_DETAILS(persona)) { | ||
703 | 489 | return QList<QtContacts::QContactDetail>(); | ||
704 | 490 | } | ||
705 | 491 | |||
706 | 360 | QList<QtContacts::QContactDetail> details; | 492 | QList<QtContacts::QContactDetail> details; |
708 | 361 | GeeSet *roles = folks_role_details_get_roles(FOLKS_ROLE_DETAILS(m_individual)); | 493 | GeeSet *roles = folks_role_details_get_roles(FOLKS_ROLE_DETAILS(persona)); |
709 | 362 | GeeIterator *iter = gee_iterable_iterator(GEE_ITERABLE(roles)); | 494 | GeeIterator *iter = gee_iterable_iterator(GEE_ITERABLE(roles)); |
710 | 363 | 495 | ||
711 | 364 | while(gee_iterator_next(iter)) { | 496 | while(gee_iterator_next(iter)) { |
712 | @@ -366,8 +498,15 @@ | |||
713 | 366 | FolksRole *role = FOLKS_ROLE(folks_abstract_field_details_get_value(fd)); | 498 | FolksRole *role = FOLKS_ROLE(folks_abstract_field_details_get_value(fd)); |
714 | 367 | 499 | ||
715 | 368 | QContactOrganization org; | 500 | QContactOrganization org; |
718 | 369 | org.setName(QString::fromUtf8(folks_role_get_organisation_name(role))); | 501 | QString field; |
719 | 370 | org.setTitle(QString::fromUtf8(folks_role_get_title(role))); | 502 | field = QString::fromUtf8(folks_role_get_organisation_name(role)); |
720 | 503 | if (field.isEmpty()) { | ||
721 | 504 | org.setName(field); | ||
722 | 505 | } | ||
723 | 506 | field = QString::fromUtf8(folks_role_get_title(role)); | ||
724 | 507 | if (!field.isEmpty()) { | ||
725 | 508 | org.setTitle(field); | ||
726 | 509 | } | ||
727 | 371 | parseParameters(org, fd); | 510 | parseParameters(org, fd); |
728 | 372 | 511 | ||
729 | 373 | g_object_unref(fd); | 512 | g_object_unref(fd); |
730 | @@ -379,10 +518,14 @@ | |||
731 | 379 | return details; | 518 | return details; |
732 | 380 | } | 519 | } |
733 | 381 | 520 | ||
735 | 382 | QList<QtContacts::QContactDetail> QIndividual::getEmails() const | 521 | QList<QtContacts::QContactDetail> QIndividual::getPersonaEmails(FolksPersona *persona) const |
736 | 383 | { | 522 | { |
737 | 523 | if (!FOLKS_IS_EMAIL_DETAILS(persona)) { | ||
738 | 524 | return QList<QtContacts::QContactDetail>(); | ||
739 | 525 | } | ||
740 | 526 | |||
741 | 384 | QList<QtContacts::QContactDetail> details; | 527 | QList<QtContacts::QContactDetail> details; |
743 | 385 | GeeSet *emails = folks_email_details_get_email_addresses(FOLKS_EMAIL_DETAILS(m_individual)); | 528 | GeeSet *emails = folks_email_details_get_email_addresses(FOLKS_EMAIL_DETAILS(persona)); |
744 | 386 | GeeIterator *iter = gee_iterable_iterator(GEE_ITERABLE(emails)); | 529 | GeeIterator *iter = gee_iterable_iterator(GEE_ITERABLE(emails)); |
745 | 387 | 530 | ||
746 | 388 | while(gee_iterator_next(iter)) { | 531 | while(gee_iterator_next(iter)) { |
747 | @@ -402,10 +545,14 @@ | |||
748 | 402 | return details; | 545 | return details; |
749 | 403 | } | 546 | } |
750 | 404 | 547 | ||
752 | 405 | QList<QtContacts::QContactDetail> QIndividual::getPhones() const | 548 | QList<QtContacts::QContactDetail> QIndividual::getPersonaPhones(FolksPersona *persona) const |
753 | 406 | { | 549 | { |
754 | 550 | if (!FOLKS_IS_PHONE_DETAILS(persona)) { | ||
755 | 551 | return QList<QtContacts::QContactDetail>(); | ||
756 | 552 | } | ||
757 | 553 | |||
758 | 407 | QList<QtContacts::QContactDetail> details; | 554 | QList<QtContacts::QContactDetail> details; |
760 | 408 | GeeSet *phones = folks_phone_details_get_phone_numbers(FOLKS_PHONE_DETAILS(m_individual)); | 555 | GeeSet *phones = folks_phone_details_get_phone_numbers(FOLKS_PHONE_DETAILS(persona)); |
761 | 409 | GeeIterator *iter = gee_iterable_iterator(GEE_ITERABLE(phones)); | 556 | GeeIterator *iter = gee_iterable_iterator(GEE_ITERABLE(phones)); |
762 | 410 | 557 | ||
763 | 411 | while(gee_iterator_next(iter)) { | 558 | while(gee_iterator_next(iter)) { |
764 | @@ -425,10 +572,14 @@ | |||
765 | 425 | return details; | 572 | return details; |
766 | 426 | } | 573 | } |
767 | 427 | 574 | ||
769 | 428 | QList<QtContacts::QContactDetail> QIndividual::getAddresses() const | 575 | QList<QtContacts::QContactDetail> QIndividual::getPersonaAddresses(FolksPersona *persona) const |
770 | 429 | { | 576 | { |
771 | 577 | if (!FOLKS_IS_POSTAL_ADDRESS_DETAILS(persona)) { | ||
772 | 578 | return QList<QtContacts::QContactDetail>(); | ||
773 | 579 | } | ||
774 | 580 | |||
775 | 430 | QList<QtContacts::QContactDetail> details; | 581 | QList<QtContacts::QContactDetail> details; |
777 | 431 | GeeSet *addresses = folks_postal_address_details_get_postal_addresses(FOLKS_POSTAL_ADDRESS_DETAILS(m_individual)); | 582 | GeeSet *addresses = folks_postal_address_details_get_postal_addresses(FOLKS_POSTAL_ADDRESS_DETAILS(persona)); |
778 | 432 | GeeIterator *iter = gee_iterable_iterator(GEE_ITERABLE(addresses)); | 583 | GeeIterator *iter = gee_iterable_iterator(GEE_ITERABLE(addresses)); |
779 | 433 | 584 | ||
780 | 434 | while(gee_iterator_next(iter)) { | 585 | while(gee_iterator_next(iter)) { |
781 | @@ -476,10 +627,14 @@ | |||
782 | 476 | return details; | 627 | return details; |
783 | 477 | } | 628 | } |
784 | 478 | 629 | ||
786 | 479 | QList<QtContacts::QContactDetail> QIndividual::getIms() const | 630 | QList<QtContacts::QContactDetail> QIndividual::getPersonaIms(FolksPersona *persona) const |
787 | 480 | { | 631 | { |
788 | 632 | if (!FOLKS_IS_IM_DETAILS(persona)) { | ||
789 | 633 | return QList<QtContacts::QContactDetail>(); | ||
790 | 634 | } | ||
791 | 635 | |||
792 | 481 | QList<QtContacts::QContactDetail> details; | 636 | QList<QtContacts::QContactDetail> details; |
794 | 482 | GeeMultiMap *ims = folks_im_details_get_im_addresses(FOLKS_IM_DETAILS(m_individual)); | 637 | GeeMultiMap *ims = folks_im_details_get_im_addresses(FOLKS_IM_DETAILS(persona)); |
795 | 483 | GeeSet *keys = gee_multi_map_get_keys(ims); | 638 | GeeSet *keys = gee_multi_map_get_keys(ims); |
796 | 484 | GeeIterator *iter = gee_iterable_iterator(GEE_ITERABLE(keys)); | 639 | GeeIterator *iter = gee_iterable_iterator(GEE_ITERABLE(keys)); |
797 | 485 | 640 | ||
798 | @@ -508,16 +663,14 @@ | |||
799 | 508 | return details; | 663 | return details; |
800 | 509 | } | 664 | } |
801 | 510 | 665 | ||
803 | 511 | QtContacts::QContactDetail QIndividual::getTimeZone() const | 666 | QList<QtContacts::QContactDetail> QIndividual::getPersonaUrls(FolksPersona *persona) const |
804 | 512 | { | 667 | { |
808 | 513 | //TODO | 668 | if (!FOLKS_IS_URL_DETAILS(persona)) { |
809 | 514 | return QContactDetail(); | 669 | return QList<QtContacts::QContactDetail>(); |
810 | 515 | } | 670 | } |
811 | 516 | 671 | ||
812 | 517 | QList<QtContacts::QContactDetail> QIndividual::getUrls() const | ||
813 | 518 | { | ||
814 | 519 | QList<QtContacts::QContactDetail> details; | 672 | QList<QtContacts::QContactDetail> details; |
816 | 520 | GeeSet *urls = folks_url_details_get_urls(FOLKS_URL_DETAILS(m_individual)); | 673 | GeeSet *urls = folks_url_details_get_urls(FOLKS_URL_DETAILS(persona)); |
817 | 521 | GeeIterator *iter = gee_iterable_iterator(GEE_ITERABLE(urls)); | 674 | GeeIterator *iter = gee_iterable_iterator(GEE_ITERABLE(urls)); |
818 | 522 | 675 | ||
819 | 523 | while(gee_iterator_next(iter)) { | 676 | while(gee_iterator_next(iter)) { |
820 | @@ -635,519 +788,696 @@ | |||
821 | 635 | { | 788 | { |
822 | 636 | m_contact = QContact(); | 789 | m_contact = QContact(); |
823 | 637 | m_contact.appendDetail(getUid()); | 790 | m_contact.appendDetail(getUid()); |
824 | 638 | m_contact.appendDetail(getName()); | ||
825 | 639 | m_contact.appendDetail(getFullName()); | ||
826 | 640 | m_contact.appendDetail(getNickname()); | ||
827 | 641 | m_contact.appendDetail(getBirthday()); | ||
828 | 642 | m_contact.appendDetail(getPhoto()); | ||
829 | 643 | m_contact.appendDetail(getTimeZone()); | ||
830 | 644 | Q_FOREACH(QContactDetail detail, getClientPidMap()) { | 791 | Q_FOREACH(QContactDetail detail, getClientPidMap()) { |
831 | 645 | m_contact.appendDetail(detail); | 792 | m_contact.appendDetail(detail); |
832 | 646 | } | 793 | } |
851 | 647 | Q_FOREACH(QContactDetail detail, getRoles()) { | 794 | |
852 | 648 | m_contact.appendDetail(detail); | 795 | Q_FOREACH(QContactDetail detail, getDetails()) { |
853 | 649 | } | 796 | m_contact.appendDetail(detail); |
854 | 650 | Q_FOREACH(QContactDetail detail, getEmails()) { | 797 | } |
855 | 651 | m_contact.appendDetail(detail); | 798 | } |
856 | 652 | } | 799 | |
857 | 653 | Q_FOREACH(QContactDetail detail, getPhones()) { | 800 | void QIndividual::createPersonaForDetail(QList<QtContacts::QContactDetail> cDetails, ParseDetailsFunc parseFunc, void *data) const |
858 | 654 | m_contact.appendDetail(detail); | 801 | { |
859 | 655 | } | 802 | GHashTable *details = g_hash_table_new_full(g_str_hash, |
860 | 656 | Q_FOREACH(QContactDetail detail, getAddresses()) { | 803 | g_str_equal, |
861 | 657 | m_contact.appendDetail(detail); | 804 | NULL, |
862 | 658 | } | 805 | (GDestroyNotify) QIndividualUtils::gValueSliceFree); |
863 | 659 | Q_FOREACH(QContactDetail detail, getIms()) { | 806 | |
864 | 660 | m_contact.appendDetail(detail); | 807 | parseFunc(details, cDetails); |
865 | 661 | } | 808 | |
866 | 662 | Q_FOREACH(QContactDetail detail, getUrls()) { | 809 | folks_individual_aggregator_add_persona_from_details(m_aggregator, |
867 | 663 | m_contact.appendDetail(detail); | 810 | NULL, // we should pass the m_individual here but due a bug on folks lest do a work around |
868 | 664 | } | 811 | folks_individual_aggregator_get_primary_store(m_aggregator), |
869 | 812 | details, | ||
870 | 813 | (GAsyncReadyCallback) createPersonaDone, | ||
871 | 814 | (void*) data); | ||
872 | 815 | |||
873 | 816 | g_hash_table_destroy(details); | ||
874 | 665 | } | 817 | } |
875 | 666 | 818 | ||
876 | 667 | void QIndividual::updateFullName(const QtContacts::QContactDetail &detail, void* data) | 819 | void QIndividual::updateFullName(const QtContacts::QContactDetail &detail, void* data) |
877 | 668 | { | 820 | { |
881 | 669 | UpdateContactData *udata = static_cast<UpdateContactData*>(data); | 821 | FolksPersona *persona = QIndividualUtils::personaFromUri(detail.detailUri(), m_individual, primaryPersona()); |
882 | 670 | QContactDetail originalLabel = m_contact.detail(QContactDetail::TypeDisplayLabel); | 822 | QContactDetail originalLabel = detailFromUri(QContactDetail::TypeDisplayLabel, detail.detailUri()); |
883 | 671 | if (FOLKS_IS_NAME_DETAILS(udata->m_persona) && (originalLabel != detail)) { | 823 | |
884 | 824 | if (persona == 0) { | ||
885 | 825 | createPersonaForDetail(QList<QContactDetail>() << detail, QIndividual::parseFullNameDetails, data); | ||
886 | 826 | } else if (FOLKS_IS_NAME_DETAILS(persona) && (originalLabel != detail)) { | ||
887 | 827 | qDebug() << "Full Name diff"; | ||
888 | 828 | qDebug() << "\t" << originalLabel << "\n\t" << detail; | ||
889 | 829 | |||
890 | 672 | const QContactDisplayLabel *label = static_cast<const QContactDisplayLabel*>(&detail); | 830 | const QContactDisplayLabel *label = static_cast<const QContactDisplayLabel*>(&detail); |
891 | 673 | 831 | ||
893 | 674 | folks_name_details_change_full_name(FOLKS_NAME_DETAILS(udata->m_persona), | 832 | folks_name_details_change_full_name(FOLKS_NAME_DETAILS(persona), |
894 | 675 | label->label().toUtf8().data(), | 833 | label->label().toUtf8().data(), |
895 | 676 | (GAsyncReadyCallback) updateDetailsDone, | 834 | (GAsyncReadyCallback) updateDetailsDone, |
896 | 677 | data); | 835 | data); |
897 | 678 | } else { | 836 | } else { |
899 | 679 | updateDetailsDone(G_OBJECT(udata->m_persona), NULL, data); | 837 | updateDetailsDone(G_OBJECT(persona), NULL, data); |
900 | 680 | } | 838 | } |
901 | 681 | } | 839 | } |
902 | 682 | 840 | ||
903 | 683 | void QIndividual::updateName(const QtContacts::QContactDetail &detail, void* data) | 841 | void QIndividual::updateName(const QtContacts::QContactDetail &detail, void* data) |
904 | 684 | { | 842 | { |
908 | 685 | UpdateContactData *udata = static_cast<UpdateContactData*>(data); | 843 | FolksPersona *persona = QIndividualUtils::personaFromUri(detail.detailUri(), m_individual, primaryPersona()); |
909 | 686 | QContactDetail originalName = m_contact.detail(QContactDetail::TypeName); | 844 | QContactDetail originalName = detailFromUri(QContactDetail::TypeName, detail.detailUri()); |
910 | 687 | if (FOLKS_IS_NAME_DETAILS(udata->m_persona) && (originalName != detail)) { | 845 | |
911 | 846 | if (persona == 0) { | ||
912 | 847 | createPersonaForDetail(QList<QContactDetail>() << detail, QIndividual::parseNameDetails, data); | ||
913 | 848 | } else if (FOLKS_IS_NAME_DETAILS(persona) && (originalName != detail)) { | ||
914 | 849 | qDebug() << "Name diff"; | ||
915 | 850 | qDebug() << "\t" << originalName << "\n\t" << detail; | ||
916 | 851 | |||
917 | 688 | const QContactName *name = static_cast<const QContactName*>(&detail); | 852 | const QContactName *name = static_cast<const QContactName*>(&detail); |
932 | 689 | FolksStructuredName *sn = folks_name_details_get_structured_name(FOLKS_NAME_DETAILS(m_individual)); | 853 | FolksStructuredName *sn; |
933 | 690 | if (!sn) { | 854 | sn = folks_structured_name_new(name->lastName().toUtf8().data(), |
934 | 691 | sn = folks_structured_name_new(name->lastName().toUtf8().data(), | 855 | name->firstName().toUtf8().data(), |
935 | 692 | name->firstName().toUtf8().data(), | 856 | name->middleName().toUtf8().data(), |
936 | 693 | name->middleName().toUtf8().data(), | 857 | name->prefix().toUtf8().data(), |
937 | 694 | name->prefix().toUtf8().data(), | 858 | name->suffix().toUtf8().data()); |
924 | 695 | name->suffix().toUtf8().data()); | ||
925 | 696 | } else { | ||
926 | 697 | folks_structured_name_set_family_name(sn, name->lastName().toUtf8().data()); | ||
927 | 698 | folks_structured_name_set_given_name(sn, name->firstName().toUtf8().data()); | ||
928 | 699 | folks_structured_name_set_additional_names(sn, name->middleName().toUtf8().data()); | ||
929 | 700 | folks_structured_name_set_prefixes(sn, name->prefix().toUtf8().data()); | ||
930 | 701 | folks_structured_name_set_suffixes(sn, name->suffix().toUtf8().data()); | ||
931 | 702 | } | ||
938 | 703 | 859 | ||
940 | 704 | folks_name_details_change_structured_name(FOLKS_NAME_DETAILS(udata->m_persona), | 860 | folks_name_details_change_structured_name(FOLKS_NAME_DETAILS(persona), |
941 | 705 | sn, | 861 | sn, |
942 | 706 | (GAsyncReadyCallback) updateDetailsDone, | 862 | (GAsyncReadyCallback) updateDetailsDone, |
943 | 707 | data); | 863 | data); |
944 | 864 | |||
945 | 708 | g_object_unref(sn); | 865 | g_object_unref(sn); |
946 | 709 | } else { | 866 | } else { |
948 | 710 | updateDetailsDone(G_OBJECT(udata->m_persona), NULL, data); | 867 | updateDetailsDone(G_OBJECT(persona), NULL, data); |
949 | 711 | } | 868 | } |
950 | 712 | } | 869 | } |
951 | 713 | 870 | ||
952 | 714 | void QIndividual::updateNickname(const QtContacts::QContactDetail &detail, void* data) | 871 | void QIndividual::updateNickname(const QtContacts::QContactDetail &detail, void* data) |
953 | 715 | { | 872 | { |
957 | 716 | UpdateContactData *udata = static_cast<UpdateContactData*>(data); | 873 | FolksPersona *persona = QIndividualUtils::personaFromUri(detail.detailUri(), m_individual, primaryPersona()); |
958 | 717 | QContactDetail originalNickname = m_contact.detail(QContactDetail::TypeNickname); | 874 | QContactDetail originalNickname = detailFromUri(QContactDetail::TypeNickname, detail.detailUri()); |
959 | 718 | if (FOLKS_IS_NAME_DETAILS(udata->m_persona) && (originalNickname != detail)) { | 875 | |
960 | 876 | if (persona == 0) { | ||
961 | 877 | createPersonaForDetail(QList<QContactDetail>() << detail, QIndividual::parseNicknameDetails, data); | ||
962 | 878 | } else if (FOLKS_IS_NAME_DETAILS(persona) && (originalNickname != detail)) { | ||
963 | 719 | const QContactNickname *nickname = static_cast<const QContactNickname*>(&detail); | 879 | const QContactNickname *nickname = static_cast<const QContactNickname*>(&detail); |
965 | 720 | folks_name_details_change_nickname(FOLKS_NAME_DETAILS(udata->m_persona), | 880 | folks_name_details_change_nickname(FOLKS_NAME_DETAILS(persona), |
966 | 721 | nickname->nickname().toUtf8().data(), | 881 | nickname->nickname().toUtf8().data(), |
967 | 722 | (GAsyncReadyCallback) updateDetailsDone, | 882 | (GAsyncReadyCallback) updateDetailsDone, |
968 | 723 | data); | 883 | data); |
969 | 724 | } else { | 884 | } else { |
971 | 725 | updateDetailsDone(G_OBJECT(udata->m_persona), NULL, data); | 885 | updateDetailsDone(G_OBJECT(persona), NULL, data); |
972 | 726 | } | 886 | } |
973 | 727 | } | 887 | } |
974 | 728 | 888 | ||
975 | 729 | void QIndividual::updateBirthday(const QtContacts::QContactDetail &detail, void* data) | 889 | void QIndividual::updateBirthday(const QtContacts::QContactDetail &detail, void* data) |
976 | 730 | { | 890 | { |
980 | 731 | UpdateContactData *udata = static_cast<UpdateContactData*>(data); | 891 | FolksPersona *persona = QIndividualUtils::personaFromUri(detail.detailUri(), m_individual, primaryPersona()); |
981 | 732 | QContactDetail originalBirthday = m_contact.detail(QContactDetail::TypeBirthday); | 892 | QContactDetail originalBirthday = detailFromUri(QContactDetail::TypeBirthday, detail.detailUri()); |
982 | 733 | if (FOLKS_IS_BIRTHDAY_DETAILS(udata->m_persona) && (originalBirthday != detail)) { | 893 | |
983 | 894 | if (persona == 0) { | ||
984 | 895 | createPersonaForDetail(QList<QContactDetail>() << detail, QIndividual::parseBirthdayDetails, data); | ||
985 | 896 | } else if (FOLKS_IS_BIRTHDAY_DETAILS(persona) && (originalBirthday != detail)) { | ||
986 | 734 | const QContactBirthday *birthday = static_cast<const QContactBirthday*>(&detail); | 897 | const QContactBirthday *birthday = static_cast<const QContactBirthday*>(&detail); |
987 | 898 | |||
988 | 735 | GDateTime *dateTime = NULL; | 899 | GDateTime *dateTime = NULL; |
989 | 736 | if (!birthday->isEmpty()) { | 900 | if (!birthday->isEmpty()) { |
990 | 737 | dateTime = g_date_time_new_from_unix_utc(birthday->dateTime().toMSecsSinceEpoch() / 1000); | 901 | dateTime = g_date_time_new_from_unix_utc(birthday->dateTime().toMSecsSinceEpoch() / 1000); |
991 | 738 | } | 902 | } |
993 | 739 | folks_birthday_details_change_birthday(FOLKS_BIRTHDAY_DETAILS(udata->m_persona), | 903 | folks_birthday_details_change_birthday(FOLKS_BIRTHDAY_DETAILS(persona), |
994 | 740 | dateTime, | 904 | dateTime, |
995 | 741 | (GAsyncReadyCallback) updateDetailsDone, | 905 | (GAsyncReadyCallback) updateDetailsDone, |
996 | 742 | data); | 906 | data); |
997 | 743 | g_date_time_unref(dateTime); | 907 | g_date_time_unref(dateTime); |
998 | 744 | } else { | 908 | } else { |
1000 | 745 | updateDetailsDone(G_OBJECT(udata->m_persona), NULL, data); | 909 | updateDetailsDone(G_OBJECT(persona), NULL, data); |
1001 | 746 | } | 910 | } |
1002 | 747 | } | 911 | } |
1003 | 748 | 912 | ||
1004 | 749 | void QIndividual::updatePhoto(const QtContacts::QContactDetail &detail, void* data) | 913 | void QIndividual::updatePhoto(const QtContacts::QContactDetail &detail, void* data) |
1005 | 750 | { | 914 | { |
1009 | 751 | UpdateContactData *udata = static_cast<UpdateContactData*>(data); | 915 | FolksPersona *persona = QIndividualUtils::personaFromUri(detail.detailUri(), m_individual, primaryPersona()); |
1010 | 752 | QContactDetail originalAvatar = m_contact.detail(QContactDetail::TypeAvatar); | 916 | QContactDetail originalAvatar = detailFromUri(QContactDetail::TypeAvatar, detail.detailUri()); |
1011 | 753 | if (FOLKS_IS_AVATAR_DETAILS(udata->m_persona) && (detail != originalAvatar)) { | 917 | |
1012 | 918 | if (persona == 0) { | ||
1013 | 919 | createPersonaForDetail(QList<QContactDetail>() << detail, QIndividual::parsePhotoDetails, data); | ||
1014 | 920 | } else if (FOLKS_IS_AVATAR_DETAILS(persona) && (detail != originalAvatar)) { | ||
1015 | 754 | //TODO: | 921 | //TODO: |
1016 | 755 | //const QContactAvatar *avatar = static_cast<const QContactAvatar*>(&detail); | 922 | //const QContactAvatar *avatar = static_cast<const QContactAvatar*>(&detail); |
1018 | 756 | folks_avatar_details_change_avatar(FOLKS_AVATAR_DETAILS(udata->m_persona), | 923 | folks_avatar_details_change_avatar(FOLKS_AVATAR_DETAILS(persona), |
1019 | 757 | 0, | 924 | 0, |
1020 | 758 | (GAsyncReadyCallback) updateDetailsDone, | 925 | (GAsyncReadyCallback) updateDetailsDone, |
1021 | 759 | data); | 926 | data); |
1022 | 760 | } else { | 927 | } else { |
1024 | 761 | updateDetailsDone(G_OBJECT(udata->m_persona), NULL, data); | 928 | updateDetailsDone(G_OBJECT(persona), NULL, data); |
1025 | 762 | } | 929 | } |
1026 | 763 | } | 930 | } |
1027 | 764 | 931 | ||
1062 | 765 | void QIndividual::updateTimezone(const QtContacts::QContactDetail &detail, void* data) | 932 | void QIndividual::updateRole(QtContacts::QContactDetail detail, void* data) |
1063 | 766 | { | 933 | { |
1064 | 767 | //TODO | 934 | FolksPersona *persona = QIndividualUtils::personaFromUri(detail.detailUri(), m_individual, primaryPersona()); |
1065 | 768 | UpdateContactData *udata = static_cast<UpdateContactData*>(data); | 935 | QContactDetail originalRole = detailFromUri(QContactDetail::TypeOrganization, detail.detailUri()); |
1066 | 769 | updateDetailsDone(G_OBJECT(udata->m_persona), NULL, data); | 936 | |
1067 | 770 | } | 937 | if (!persona) { |
1068 | 771 | 938 | createPersonaForDetail(QList<QContactDetail>() << detail, QIndividual::parseOrganizationDetails, data); | |
1069 | 772 | void QIndividual::updateRoles(QList<QtContacts::QContactDetail> details, void* data) | 939 | } else if (FOLKS_IS_ROLE_DETAILS(persona) && (originalRole != detail)) { |
1070 | 773 | { | 940 | qDebug() << "Role diff"; |
1071 | 774 | UpdateContactData *udata = static_cast<UpdateContactData*>(data); | 941 | qDebug() << "\t" << originalRole << "\n\t" << detail; |
1072 | 775 | QList<QContactDetail> originalOrganizations = m_contact.details(QContactDetail::TypeOrganization); | 942 | |
1073 | 776 | 943 | FolksRoleFieldDetails *roleDetails = 0; | |
1074 | 777 | if (FOLKS_IS_ROLE_DETAILS(udata->m_persona) && !detailListIsEqual(originalOrganizations, details)) { | 944 | const QContactOrganization *cRole = static_cast<const QContactOrganization*>(&detail); |
1075 | 778 | GeeSet *roleSet = SET_AFD_NEW(); | 945 | GeeSet *roleSet = folks_role_details_get_roles(FOLKS_ROLE_DETAILS(persona)); |
1076 | 779 | Q_FOREACH(const QContactDetail& detail, details) { | 946 | |
1077 | 780 | const QContactOrganization *org = static_cast<const QContactOrganization*>(&detail); | 947 | if (!roleSet || (gee_collection_get_size(GEE_COLLECTION(roleSet)) == 0)) { |
1078 | 781 | 948 | roleSet = SET_AFD_NEW(); | |
1079 | 782 | // The role values can not be NULL | 949 | } else { |
1080 | 783 | const gchar* title = org->title().toUtf8().data(); | 950 | roleDetails = FOLKS_ROLE_FIELD_DETAILS(QIndividualUtils::getDetails(roleSet, detail.detailUri())); |
1081 | 784 | const gchar* name = org->name().toUtf8().data(); | 951 | // this will be unref at the end of the function |
1082 | 785 | const gchar* roleName = org->role().toUtf8().data(); | 952 | g_object_ref(roleSet); |
1083 | 786 | 953 | g_object_ref(roleDetails); | |
1084 | 787 | FolksRole *role = folks_role_new(title ? title : "", name ? name : "", ""); | 954 | } |
1085 | 788 | folks_role_set_role(role, roleName ? roleName : ""); | 955 | |
1086 | 789 | 956 | const gchar* title = cRole->title().isEmpty() ? "" : cRole->title().toUtf8().data(); | |
1087 | 790 | FolksRoleFieldDetails *fieldDetails = folks_role_field_details_new(role, NULL); | 957 | const gchar* name = cRole->name().isEmpty() ? "" : cRole->name().toUtf8().data(); |
1088 | 791 | parseContext(FOLKS_ABSTRACT_FIELD_DETAILS(fieldDetails), detail); | 958 | const gchar* roleName = cRole->role().isEmpty() ? "" : cRole->role().toUtf8().data(); |
1089 | 792 | gee_collection_add(GEE_COLLECTION(roleSet), fieldDetails); | 959 | |
1090 | 793 | 960 | FolksRole *roleValue; | |
1091 | 794 | g_object_unref(role); | 961 | if (!roleDetails) { |
1092 | 795 | g_object_unref(fieldDetails); | 962 | roleValue = folks_role_new(title, name, ""); |
1093 | 796 | } | 963 | folks_role_set_role(roleValue, roleName); |
1094 | 797 | 964 | ||
1095 | 798 | folks_role_details_change_roles(FOLKS_ROLE_DETAILS(udata->m_persona), | 965 | roleDetails = folks_role_field_details_new(roleValue, NULL); |
1096 | 966 | gee_collection_add(GEE_COLLECTION(roleSet), roleDetails); | ||
1097 | 967 | } else { | ||
1098 | 968 | roleValue = FOLKS_ROLE(folks_abstract_field_details_get_value(FOLKS_ABSTRACT_FIELD_DETAILS(roleDetails))); | ||
1099 | 969 | folks_role_set_organisation_name(roleValue, name); | ||
1100 | 970 | folks_role_set_title(roleValue, title); | ||
1101 | 971 | folks_role_set_role(roleValue, roleName); | ||
1102 | 972 | } | ||
1103 | 973 | |||
1104 | 974 | parseContext(FOLKS_ABSTRACT_FIELD_DETAILS(roleDetails), detail); | ||
1105 | 975 | folks_role_details_change_roles(FOLKS_ROLE_DETAILS(persona), | ||
1106 | 799 | roleSet, | 976 | roleSet, |
1107 | 800 | (GAsyncReadyCallback) updateDetailsDone, | 977 | (GAsyncReadyCallback) updateDetailsDone, |
1108 | 801 | data); | 978 | data); |
1109 | 979 | |||
1110 | 980 | g_object_unref(roleDetails); | ||
1111 | 802 | g_object_unref(roleSet); | 981 | g_object_unref(roleSet); |
1112 | 982 | g_object_unref(roleValue); | ||
1113 | 803 | } else { | 983 | } else { |
1115 | 804 | updateDetailsDone(G_OBJECT(udata->m_persona), NULL, data); | 984 | updateDetailsDone(G_OBJECT(persona), NULL, data); |
1116 | 805 | } | 985 | } |
1117 | 806 | } | 986 | } |
1118 | 807 | 987 | ||
1120 | 808 | void QIndividual::updateEmails(QList<QtContacts::QContactDetail> details, void* data) | 988 | void QIndividual::updateEmail(QtContacts::QContactDetail detail, void* data) |
1121 | 809 | { | 989 | { |
1138 | 810 | UpdateContactData *udata = static_cast<UpdateContactData*>(data); | 990 | FolksPersona *persona = QIndividualUtils::personaFromUri(detail.detailUri(), m_individual, primaryPersona()); |
1139 | 811 | QList<QContactDetail> originalEmails = m_contact.details(QContactDetail::TypeEmailAddress); | 991 | QContactDetail originalEmail = detailFromUri(QContactDetail::TypeEmailAddress, detail.detailUri()); |
1140 | 812 | 992 | ||
1141 | 813 | if (FOLKS_IS_EMAIL_DETAILS(udata->m_persona) && !detailListIsEqual(originalEmails, details)) { | 993 | if (!persona) { |
1142 | 814 | GeeSet *emailSet = SET_AFD_NEW(); | 994 | createPersonaForDetail(QList<QContactDetail>() << detail, QIndividual::parseEmailDetails, data); |
1143 | 815 | Q_FOREACH(const QContactDetail& detail, details) { | 995 | } else if (FOLKS_IS_EMAIL_DETAILS(persona) && (originalEmail != detail)) { |
1144 | 816 | const QContactEmailAddress *email = static_cast<const QContactEmailAddress*>(&detail); | 996 | qDebug() << "email diff"; |
1145 | 817 | 997 | qDebug() << "\t" << originalEmail << "\n\t" << detail; | |
1146 | 818 | if(!email->isEmpty()) { | 998 | |
1147 | 819 | FolksEmailFieldDetails *emailDetails = folks_email_field_details_new(email->emailAddress().toUtf8().data(), NULL); | 999 | FolksEmailFieldDetails *emailDetails = 0; |
1148 | 820 | parseContext(FOLKS_ABSTRACT_FIELD_DETAILS(emailDetails), detail); | 1000 | const QContactEmailAddress *email = static_cast<const QContactEmailAddress*>(&detail); |
1149 | 821 | gee_collection_add(GEE_COLLECTION(emailSet), emailDetails); | 1001 | GeeSet *emailSet = folks_email_details_get_email_addresses(FOLKS_EMAIL_DETAILS(persona)); |
1150 | 822 | g_object_unref(emailDetails); | 1002 | if (!emailSet || (gee_collection_get_size(GEE_COLLECTION(emailSet)) == 0)) { |
1151 | 823 | } | 1003 | emailSet = SET_AFD_NEW(); |
1152 | 824 | } | 1004 | } else { |
1153 | 825 | folks_email_details_change_email_addresses(FOLKS_EMAIL_DETAILS(udata->m_persona), | 1005 | emailDetails = FOLKS_EMAIL_FIELD_DETAILS(QIndividualUtils::getDetails(emailSet, detail.detailUri())); |
1154 | 1006 | // this will be unref at the end of the function | ||
1155 | 1007 | g_object_ref(emailSet); | ||
1156 | 1008 | g_object_ref(emailDetails); | ||
1157 | 1009 | } | ||
1158 | 1010 | |||
1159 | 1011 | if (!emailDetails) { | ||
1160 | 1012 | emailDetails = folks_email_field_details_new(email->emailAddress().toUtf8().data(), NULL); | ||
1161 | 1013 | gee_collection_add(GEE_COLLECTION(emailSet), emailDetails); | ||
1162 | 1014 | } else { | ||
1163 | 1015 | folks_abstract_field_details_set_value(FOLKS_ABSTRACT_FIELD_DETAILS(emailDetails), | ||
1164 | 1016 | email->emailAddress().toUtf8().data()); | ||
1165 | 1017 | } | ||
1166 | 1018 | |||
1167 | 1019 | folks_email_details_change_email_addresses(FOLKS_EMAIL_DETAILS(persona), | ||
1168 | 826 | emailSet, | 1020 | emailSet, |
1169 | 827 | (GAsyncReadyCallback) updateDetailsDone, | 1021 | (GAsyncReadyCallback) updateDetailsDone, |
1170 | 828 | data); | 1022 | data); |
1171 | 1023 | |||
1172 | 829 | g_object_unref(emailSet); | 1024 | g_object_unref(emailSet); |
1173 | 1025 | g_object_unref(emailDetails); | ||
1174 | 830 | } else { | 1026 | } else { |
1176 | 831 | updateDetailsDone(G_OBJECT(udata->m_persona), NULL, data); | 1027 | updateDetailsDone(G_OBJECT(persona), NULL, data); |
1177 | 832 | } | 1028 | } |
1178 | 833 | } | 1029 | } |
1179 | 834 | 1030 | ||
1181 | 835 | void QIndividual::updatePhones(QList<QtContacts::QContactDetail> details, void* data) | 1031 | void QIndividual::updatePhone(QtContacts::QContactDetail detail, void* data) |
1182 | 836 | { | 1032 | { |
1199 | 837 | UpdateContactData *udata = static_cast<UpdateContactData*>(data); | 1033 | FolksPersona *persona = QIndividualUtils::personaFromUri(detail.detailUri(), m_individual, primaryPersona()); |
1200 | 838 | QList<QContactDetail> originalPhones = m_contact.details(QContactDetail::TypePhoneNumber); | 1034 | QContactDetail originalPhone = detailFromUri(QContactDetail::TypePhoneNumber, detail.detailUri()); |
1201 | 839 | 1035 | // if we do not have a persona for this detail we need to create one | |
1202 | 840 | if (FOLKS_IS_PHONE_DETAILS(udata->m_persona) && !detailListIsEqual(originalPhones, details)) { | 1036 | if (!persona) { |
1203 | 841 | GeeSet *phoneSet = SET_AFD_NEW(); | 1037 | createPersonaForDetail(QList<QContactDetail>() << detail, QIndividual::parsePhoneNumbersDetails, data); |
1204 | 842 | Q_FOREACH(const QContactDetail& detail, details) { | 1038 | } else if (FOLKS_IS_PHONE_DETAILS(persona) && (originalPhone != detail)) { |
1205 | 843 | const QContactPhoneNumber *phone = static_cast<const QContactPhoneNumber*>(&detail); | 1039 | qDebug() << "Phone diff"; |
1206 | 844 | 1040 | qDebug() << "\t" << originalPhone << "\n\t" << detail; | |
1207 | 845 | if(!phone->isEmpty()) { | 1041 | |
1208 | 846 | FolksPhoneFieldDetails *phoneDetails = folks_phone_field_details_new(phone->number().toUtf8().data(), NULL); | 1042 | /// Only update the details on the current persona |
1209 | 847 | parseContext(FOLKS_ABSTRACT_FIELD_DETAILS(phoneDetails), detail); | 1043 | FolksPhoneFieldDetails *phoneDetails = 0; |
1210 | 848 | gee_collection_add(GEE_COLLECTION(phoneSet), phoneDetails); | 1044 | const QContactPhoneNumber *phone = static_cast<const QContactPhoneNumber*>(&detail); |
1211 | 849 | g_object_unref(phoneDetails); | 1045 | GeeSet *phoneSet = folks_phone_details_get_phone_numbers(FOLKS_PHONE_DETAILS(persona)); |
1212 | 850 | } | 1046 | |
1213 | 851 | } | 1047 | if (!phoneSet || (gee_collection_get_size(GEE_COLLECTION(phoneSet)) == 0)) { |
1214 | 852 | folks_phone_details_change_phone_numbers(FOLKS_PHONE_DETAILS(udata->m_persona), | 1048 | phoneSet = SET_AFD_NEW(); |
1215 | 1049 | } else { | ||
1216 | 1050 | phoneDetails = FOLKS_PHONE_FIELD_DETAILS(QIndividualUtils::getDetails(phoneSet, detail.detailUri())); | ||
1217 | 1051 | // this will be unref at the end of the function | ||
1218 | 1052 | g_object_ref(phoneSet); | ||
1219 | 1053 | g_object_ref(phoneDetails); | ||
1220 | 1054 | } | ||
1221 | 1055 | |||
1222 | 1056 | if (!phoneDetails) { | ||
1223 | 1057 | phoneDetails = folks_phone_field_details_new(phone->number().toUtf8().data(), NULL); | ||
1224 | 1058 | gee_collection_add(GEE_COLLECTION(phoneSet), phoneDetails); | ||
1225 | 1059 | } else { | ||
1226 | 1060 | folks_abstract_field_details_set_value(FOLKS_ABSTRACT_FIELD_DETAILS(phoneDetails), | ||
1227 | 1061 | phone->number().toUtf8().data()); | ||
1228 | 1062 | } | ||
1229 | 1063 | |||
1230 | 1064 | parseContext(FOLKS_ABSTRACT_FIELD_DETAILS(phoneDetails), detail); | ||
1231 | 1065 | folks_phone_details_change_phone_numbers(FOLKS_PHONE_DETAILS(persona), | ||
1232 | 853 | phoneSet, | 1066 | phoneSet, |
1233 | 854 | (GAsyncReadyCallback) updateDetailsDone, | 1067 | (GAsyncReadyCallback) updateDetailsDone, |
1234 | 855 | data); | 1068 | data); |
1235 | 1069 | g_object_unref(phoneDetails); | ||
1236 | 856 | g_object_unref(phoneSet); | 1070 | g_object_unref(phoneSet); |
1237 | 857 | } else { | 1071 | } else { |
1288 | 858 | updateDetailsDone(G_OBJECT(udata->m_persona), NULL, data); | 1072 | updateDetailsDone(G_OBJECT(persona), NULL, data); |
1289 | 859 | } | 1073 | } |
1290 | 860 | } | 1074 | } |
1291 | 861 | 1075 | ||
1292 | 862 | bool QIndividual::detailListIsEqual(QList<QtContacts::QContactDetail> original, QList<QtContacts::QContactDetail> details) | 1076 | void QIndividual::updateAddress(QtContacts::QContactDetail detail, void* data) |
1293 | 863 | { | 1077 | { |
1294 | 864 | if (original.size() != details.size()) { | 1078 | FolksPersona *persona = QIndividualUtils::personaFromUri(detail.detailUri(), m_individual, primaryPersona()); |
1295 | 865 | return false; | 1079 | QContactDetail originalAddress = detailFromUri(QContactDetail::TypeAddress, detail.detailUri()); |
1296 | 866 | } | 1080 | |
1297 | 867 | 1081 | if (!persona) { | |
1298 | 868 | Q_FOREACH(const QContactDetail& detail, details) { | 1082 | createPersonaForDetail(QList<QContactDetail>() << detail, QIndividual::parseAddressDetails, data); |
1299 | 869 | if (!original.contains(detail)) { | 1083 | } else if (FOLKS_IS_POSTAL_ADDRESS_DETAILS(persona) && (originalAddress != detail)) { |
1300 | 870 | return false; | 1084 | |
1301 | 871 | } | 1085 | |
1302 | 872 | } | 1086 | FolksPostalAddressFieldDetails *addrDetails = 0; |
1303 | 873 | 1087 | const QContactAddress *addr = static_cast<const QContactAddress*>(&detail); | |
1304 | 874 | return true; | 1088 | const QContactAddress *addro = static_cast<const QContactAddress*>(&originalAddress); |
1305 | 875 | } | 1089 | |
1306 | 876 | 1090 | qDebug() << "Adderess diff"; | |
1307 | 877 | void QIndividual::updateAddresses(QList<QtContacts::QContactDetail> details, void* data) | 1091 | qDebug() << "\t" << *addro << "subtypes:" << addro->subTypes() << "context" << addro->contexts(); |
1308 | 878 | { | 1092 | qDebug() << "\t" << *addr << "subtypes:" << addr->subTypes() << "context" << addr->contexts(); |
1309 | 879 | UpdateContactData *udata = static_cast<UpdateContactData*>(data); | 1093 | |
1310 | 880 | QList<QContactDetail> originalAddress = m_contact.details(QContactDetail::TypeAddress); | 1094 | |
1311 | 881 | 1095 | qDebug() << "SubTypes:" << addr->subTypes(); | |
1312 | 882 | if (FOLKS_IS_POSTAL_ADDRESS_DETAILS(udata->m_persona) && !detailListIsEqual(originalAddress, details)) { | 1096 | GeeSet *addrSet = folks_postal_address_details_get_postal_addresses(FOLKS_POSTAL_ADDRESS_DETAILS(persona)); |
1313 | 883 | GeeSet *addressSet = SET_AFD_NEW(); | 1097 | |
1314 | 884 | Q_FOREACH(const QContactDetail& detail, details) { | 1098 | if (!addrSet || (gee_collection_get_size(GEE_COLLECTION(addrSet)) == 0)) { |
1315 | 885 | const QContactAddress *address = static_cast<const QContactAddress*>(&detail); | 1099 | addrSet = SET_AFD_NEW(); |
1316 | 886 | if (!address->isEmpty()) { | 1100 | } else { |
1317 | 887 | FolksPostalAddress *postalAddress = folks_postal_address_new(address->postOfficeBox().toUtf8().data(), | 1101 | addrDetails = FOLKS_POSTAL_ADDRESS_FIELD_DETAILS(QIndividualUtils::getDetails(addrSet, detail.detailUri())); |
1318 | 888 | NULL, | 1102 | // this will be unref at the end of the function |
1319 | 889 | address->street().toUtf8().data(), | 1103 | g_object_ref(addrSet); |
1320 | 890 | address->locality().toUtf8().data(), | 1104 | g_object_ref(addrDetails); |
1321 | 891 | address->region().toUtf8().data(), | 1105 | } |
1322 | 892 | address->postcode().toUtf8().data(), | 1106 | |
1323 | 893 | address->country().toUtf8().data(), | 1107 | FolksPostalAddress *addrValue; |
1324 | 894 | NULL, | 1108 | if (!addrDetails) { |
1325 | 895 | NULL); | 1109 | addrValue = folks_postal_address_new(addr->postOfficeBox().toUtf8().data(), |
1326 | 896 | FolksPostalAddressFieldDetails *pafd = folks_postal_address_field_details_new(postalAddress, NULL); | 1110 | NULL, |
1327 | 897 | 1111 | addr->street().toUtf8().data(), | |
1328 | 898 | parseContext(FOLKS_ABSTRACT_FIELD_DETAILS(pafd), detail); | 1112 | addr->locality().toUtf8().data(), |
1329 | 899 | gee_collection_add(GEE_COLLECTION(addressSet), pafd); | 1113 | addr->region().toUtf8().data(), |
1330 | 900 | 1114 | addr->postcode().toUtf8().data(), | |
1331 | 901 | g_object_unref(postalAddress); | 1115 | addr->country().toUtf8().data(), |
1332 | 902 | g_object_unref(pafd); | 1116 | NULL, |
1333 | 903 | } | 1117 | NULL); |
1334 | 904 | } | 1118 | addrDetails = folks_postal_address_field_details_new(addrValue, NULL); |
1335 | 905 | 1119 | gee_collection_add(GEE_COLLECTION(addrSet), addrDetails); | |
1336 | 906 | folks_postal_address_details_change_postal_addresses(FOLKS_POSTAL_ADDRESS_DETAILS(udata->m_persona), | 1120 | } else { |
1337 | 907 | addressSet, | 1121 | addrValue = FOLKS_POSTAL_ADDRESS(folks_abstract_field_details_get_value(FOLKS_ABSTRACT_FIELD_DETAILS(addrDetails))); |
1338 | 1122 | Q_ASSERT(addrValue); | ||
1339 | 1123 | folks_postal_address_set_po_box(addrValue, addr->postOfficeBox().toUtf8().data()); | ||
1340 | 1124 | folks_postal_address_set_street(addrValue, addr->street().toUtf8().data()); | ||
1341 | 1125 | folks_postal_address_set_locality(addrValue, addr->locality().toUtf8().data()); | ||
1342 | 1126 | folks_postal_address_set_region(addrValue, addr->region().toUtf8().data()); | ||
1343 | 1127 | folks_postal_address_set_postal_code(addrValue, addr->postcode().toUtf8().data()); | ||
1344 | 1128 | folks_postal_address_set_country(addrValue, addr->country().toUtf8().data()); | ||
1345 | 1129 | } | ||
1346 | 1130 | |||
1347 | 1131 | parseContext(FOLKS_ABSTRACT_FIELD_DETAILS(addrDetails), detail); | ||
1348 | 1132 | folks_postal_address_details_change_postal_addresses(FOLKS_POSTAL_ADDRESS_DETAILS(persona), | ||
1349 | 1133 | addrSet, | ||
1350 | 908 | (GAsyncReadyCallback) updateDetailsDone, | 1134 | (GAsyncReadyCallback) updateDetailsDone, |
1351 | 909 | data); | 1135 | data); |
1353 | 910 | g_object_unref(addressSet); | 1136 | g_object_unref(addrDetails); |
1354 | 1137 | g_object_unref(addrSet); | ||
1355 | 1138 | g_object_unref(addrValue); | ||
1356 | 911 | } else { | 1139 | } else { |
1358 | 912 | updateDetailsDone(G_OBJECT(udata->m_persona), NULL, data); | 1140 | updateDetailsDone(G_OBJECT(persona), NULL, data); |
1359 | 913 | } | 1141 | } |
1360 | 914 | } | 1142 | } |
1361 | 915 | 1143 | ||
1363 | 916 | void QIndividual::updateIms(QList<QtContacts::QContactDetail> details, void* data) | 1144 | void QIndividual::updateIm(QtContacts::QContactDetail detail, void* data) |
1364 | 917 | { | 1145 | { |
1378 | 918 | UpdateContactData *udata = static_cast<UpdateContactData*>(data); | 1146 | FolksPersona *persona = QIndividualUtils::personaFromUri(detail.detailUri(), m_individual, primaryPersona()); |
1379 | 919 | QList<QContactDetail> originalIms = m_contact.details(QContactDetail::TypeOnlineAccount); | 1147 | QContactDetail originalIm = detailFromUri(QContactDetail::TypeOnlineAccount, detail.detailUri()); |
1380 | 920 | 1148 | ||
1381 | 921 | if (FOLKS_IS_IM_DETAILS(udata->m_persona) && !detailListIsEqual(originalIms, details)) { | 1149 | if (!persona) { |
1382 | 922 | GeeMultiMap *imAddressHash = GEE_MULTI_MAP_AFD_NEW(FOLKS_TYPE_IM_FIELD_DETAILS); | 1150 | createPersonaForDetail(QList<QContactDetail>() << detail, QIndividual::parseImDetails, data); |
1383 | 923 | Q_FOREACH(const QContactDetail& detail, details) { | 1151 | } else if (FOLKS_IS_IM_DETAILS(persona) && (originalIm != detail)) { |
1384 | 924 | const QContactOnlineAccount *im = static_cast<const QContactOnlineAccount*>(&detail); | 1152 | qDebug() << "Im diff"; |
1385 | 925 | if (!im->accountUri().isEmpty()) { | 1153 | qDebug() << "\t" << originalIm << "\n\t" << detail; |
1386 | 926 | FolksImFieldDetails *imfd = folks_im_field_details_new(im->accountUri().toUtf8().data(), NULL); | 1154 | |
1387 | 927 | parseContext(FOLKS_ABSTRACT_FIELD_DETAILS(imfd), detail); | 1155 | const QContactOnlineAccount *im = static_cast<const QContactOnlineAccount*>(&detail); |
1388 | 928 | gee_multi_map_set(imAddressHash, | 1156 | GeeMultiMap *imSet = folks_im_details_get_im_addresses(FOLKS_IM_DETAILS(persona)); |
1389 | 929 | onlineAccountProtocolFromEnum(im->protocol()).toUtf8().data(), imfd); | 1157 | |
1390 | 930 | g_object_unref(imfd); | 1158 | if (!imSet || (gee_multi_map_get_size(GEE_MULTI_MAP(imSet)) == 0)) { |
1391 | 1159 | imSet = GEE_MULTI_MAP_AFD_NEW(FOLKS_TYPE_IM_FIELD_DETAILS); | ||
1392 | 1160 | } else { | ||
1393 | 1161 | // We can not relay on the index inside of detailUri because online account are stored in a hash | ||
1394 | 1162 | QContactOnlineAccount oldIm = static_cast<QContactOnlineAccount>(originalIm); | ||
1395 | 1163 | QString oldProtocolName = onlineAccountProtocolFromEnum(oldIm.protocol()); | ||
1396 | 1164 | GeeCollection *value = gee_multi_map_get(imSet, oldProtocolName.toUtf8().data()); | ||
1397 | 1165 | |||
1398 | 1166 | // Remove the old one | ||
1399 | 1167 | if (value) { | ||
1400 | 1168 | // if there is more than one address only remove the correct one | ||
1401 | 1169 | if (gee_collection_get_size(value) > 1) { | ||
1402 | 1170 | gee_collection_remove(value, oldIm.accountUri().toUtf8().data()); | ||
1403 | 1171 | } else { | ||
1404 | 1172 | // otherwise remove the key | ||
1405 | 1173 | gee_multi_map_remove_all(imSet, oldProtocolName.toUtf8().data()); | ||
1406 | 1174 | } | ||
1407 | 931 | } | 1175 | } |
1408 | 1176 | |||
1409 | 1177 | g_object_ref(imSet); | ||
1410 | 932 | } | 1178 | } |
1411 | 933 | 1179 | ||
1414 | 934 | folks_im_details_change_im_addresses(FOLKS_IM_DETAILS(udata->m_persona), | 1180 | // Append the new one |
1415 | 935 | imAddressHash, | 1181 | FolksImFieldDetails *imDetails = folks_im_field_details_new(im->accountUri().toUtf8().data(), NULL); |
1416 | 1182 | parseContext(FOLKS_ABSTRACT_FIELD_DETAILS(imDetails), detail); | ||
1417 | 1183 | |||
1418 | 1184 | gee_multi_map_set(imSet, | ||
1419 | 1185 | onlineAccountProtocolFromEnum(im->protocol()).toUtf8().data(), | ||
1420 | 1186 | imDetails); | ||
1421 | 1187 | |||
1422 | 1188 | folks_im_details_change_im_addresses(FOLKS_IM_DETAILS(persona), | ||
1423 | 1189 | imSet, | ||
1424 | 936 | (GAsyncReadyCallback) updateDetailsDone, | 1190 | (GAsyncReadyCallback) updateDetailsDone, |
1425 | 937 | data); | 1191 | data); |
1427 | 938 | g_object_unref(imAddressHash); | 1192 | g_object_unref(imSet); |
1428 | 1193 | g_object_unref(imDetails); | ||
1429 | 939 | } else { | 1194 | } else { |
1431 | 940 | updateDetailsDone(G_OBJECT(udata->m_persona), NULL, data); | 1195 | updateDetailsDone(G_OBJECT(persona), NULL, data); |
1432 | 941 | } | 1196 | } |
1433 | 942 | } | 1197 | } |
1434 | 943 | 1198 | ||
1436 | 944 | void QIndividual::updateUrls(QList<QtContacts::QContactDetail> details, void* data) | 1199 | void QIndividual::updateUrl(QtContacts::QContactDetail detail, void* data) |
1437 | 945 | { | 1200 | { |
1454 | 946 | UpdateContactData *udata = static_cast<UpdateContactData*>(data); | 1201 | FolksPersona *persona = QIndividualUtils::personaFromUri(detail.detailUri(), m_individual, primaryPersona()); |
1455 | 947 | QList<QContactDetail> originalUrls = m_contact.details(QContactDetail::TypeUrl); | 1202 | QContactDetail originalUrl = detailFromUri(QContactDetail::TypeUrl, detail.detailUri()); |
1456 | 948 | 1203 | ||
1457 | 949 | if (FOLKS_IS_URL_DETAILS(udata->m_persona) && !detailListIsEqual(originalUrls, details)) { | 1204 | if (!persona) { |
1458 | 950 | GeeSet *urlSet = SET_AFD_NEW(); | 1205 | createPersonaForDetail(QList<QContactDetail>() << detail, QIndividual::parseUrlDetails, data); |
1459 | 951 | Q_FOREACH(const QContactDetail& detail, details) { | 1206 | } else if (FOLKS_IS_URL_DETAILS(persona) && (originalUrl != detail)) { |
1460 | 952 | const QContactUrl *url = static_cast<const QContactUrl*>(&detail); | 1207 | qDebug() << "Url diff"; |
1461 | 953 | 1208 | qDebug() << "\t" << originalUrl << "\n\t" << detail; | |
1462 | 954 | if(!url->isEmpty()) { | 1209 | |
1463 | 955 | FolksUrlFieldDetails *urlDetails = folks_url_field_details_new(url->url().toUtf8().data(), NULL); | 1210 | FolksUrlFieldDetails *urlDetails = 0; |
1464 | 956 | parseContext(FOLKS_ABSTRACT_FIELD_DETAILS(urlDetails), detail); | 1211 | const QContactUrl *url = static_cast<const QContactUrl*>(&detail); |
1465 | 957 | gee_collection_add(GEE_COLLECTION(urlSet), urlDetails); | 1212 | GeeSet *urlSet = folks_url_details_get_urls(FOLKS_URL_DETAILS(persona)); |
1466 | 958 | g_object_unref(urlDetails); | 1213 | |
1467 | 959 | } | 1214 | if (!urlSet || (gee_collection_get_size(GEE_COLLECTION(urlSet)) == 0)) { |
1468 | 960 | } | 1215 | urlSet = SET_AFD_NEW(); |
1469 | 961 | folks_url_details_change_urls(FOLKS_URL_DETAILS(udata->m_persona), | 1216 | } else { |
1470 | 1217 | urlDetails = FOLKS_URL_FIELD_DETAILS(QIndividualUtils::getDetails(urlSet, detail.detailUri())); | ||
1471 | 1218 | |||
1472 | 1219 | // this will be unref at the end of the function | ||
1473 | 1220 | g_object_ref(urlSet); | ||
1474 | 1221 | g_object_ref(urlDetails); | ||
1475 | 1222 | } | ||
1476 | 1223 | |||
1477 | 1224 | if (!urlDetails) { | ||
1478 | 1225 | urlDetails = folks_url_field_details_new(url->url().toUtf8().data(), NULL); | ||
1479 | 1226 | gee_collection_add(GEE_COLLECTION(urlSet), urlDetails); | ||
1480 | 1227 | } else { | ||
1481 | 1228 | folks_abstract_field_details_set_value(FOLKS_ABSTRACT_FIELD_DETAILS(urlDetails), | ||
1482 | 1229 | url->url().toUtf8().data()); | ||
1483 | 1230 | } | ||
1484 | 1231 | |||
1485 | 1232 | parseContext(FOLKS_ABSTRACT_FIELD_DETAILS(urlDetails), detail); | ||
1486 | 1233 | folks_url_details_change_urls(FOLKS_URL_DETAILS(persona), | ||
1487 | 962 | urlSet, | 1234 | urlSet, |
1488 | 963 | (GAsyncReadyCallback) updateDetailsDone, | 1235 | (GAsyncReadyCallback) updateDetailsDone, |
1489 | 964 | data); | 1236 | data); |
1490 | 1237 | g_object_unref(urlDetails); | ||
1491 | 965 | g_object_unref(urlSet); | 1238 | g_object_unref(urlSet); |
1492 | 966 | } else { | 1239 | } else { |
1494 | 967 | updateDetailsDone(G_OBJECT(m_individual), NULL, data); | 1240 | updateDetailsDone(G_OBJECT(persona), NULL, data); |
1495 | 968 | } | 1241 | } |
1496 | 969 | } | 1242 | } |
1497 | 970 | 1243 | ||
1499 | 971 | void QIndividual::updateNotes(QList<QtContacts::QContactDetail> details, void* data) | 1244 | void QIndividual::updateNote(QtContacts::QContactDetail detail, void* data) |
1500 | 972 | { | 1245 | { |
1518 | 973 | UpdateContactData *udata = static_cast<UpdateContactData*>(data); | 1246 | FolksPersona *persona = QIndividualUtils::personaFromUri(detail.detailUri(), m_individual, primaryPersona()); |
1519 | 974 | QList<QContactDetail> originalNotes = m_contact.details(QContactDetail::TypeNote); | 1247 | QContactDetail originalNote = detailFromUri(QContactDetail::TypeNote, detail.detailUri()); |
1520 | 975 | 1248 | ||
1521 | 976 | if (FOLKS_IS_NOTE_DETAILS(udata->m_persona) && !detailListIsEqual(originalNotes, details)) { | 1249 | if (!persona) { |
1522 | 977 | GeeSet *noteSet = SET_AFD_NEW(); | 1250 | createPersonaForDetail(QList<QContactDetail>() << detail, QIndividual::parseNoteDetails, data); |
1523 | 978 | Q_FOREACH(const QContactDetail& detail, details) { | 1251 | } else if (FOLKS_IS_URL_DETAILS(persona) && (originalNote != detail)) { |
1524 | 979 | const QContactNote *note = static_cast<const QContactNote*>(&detail); | 1252 | qDebug() << "Note diff"; |
1525 | 980 | 1253 | qDebug() << "\t" << originalNote << "\n\t" << detail; | |
1526 | 981 | if(!note->isEmpty()) { | 1254 | |
1527 | 982 | FolksNoteFieldDetails *noteDetails = folks_note_field_details_new(note->note().toUtf8().data(), NULL, 0); | 1255 | FolksNoteFieldDetails *noteDetails = 0; |
1528 | 983 | 1256 | const QContactNote *note = static_cast<const QContactNote*>(&detail); | |
1529 | 984 | //TODO: set context | 1257 | GeeSet *noteSet = folks_note_details_get_notes(FOLKS_NOTE_DETAILS(persona)); |
1530 | 985 | gee_collection_add(GEE_COLLECTION(noteSet), noteDetails); | 1258 | |
1531 | 986 | g_object_unref(noteDetails); | 1259 | if (!noteSet || (gee_collection_get_size(GEE_COLLECTION(noteSet)) == 0)) { |
1532 | 987 | } | 1260 | noteSet = SET_AFD_NEW(); |
1533 | 988 | } | 1261 | } else { |
1534 | 989 | folks_note_details_change_notes(FOLKS_NOTE_DETAILS(udata->m_persona), | 1262 | noteDetails = FOLKS_NOTE_FIELD_DETAILS(QIndividualUtils::getDetails(noteSet, detail.detailUri())); |
1535 | 1263 | |||
1536 | 1264 | // this will be unref at the end of the function | ||
1537 | 1265 | g_object_ref(noteSet); | ||
1538 | 1266 | g_object_ref(noteDetails); | ||
1539 | 1267 | } | ||
1540 | 1268 | |||
1541 | 1269 | if (!noteDetails) { | ||
1542 | 1270 | noteDetails = folks_note_field_details_new(note->note().toUtf8().data(), NULL, 0); | ||
1543 | 1271 | gee_collection_add(GEE_COLLECTION(noteSet), noteDetails); | ||
1544 | 1272 | } else { | ||
1545 | 1273 | folks_abstract_field_details_set_value(FOLKS_ABSTRACT_FIELD_DETAILS(noteDetails), | ||
1546 | 1274 | note->note().toUtf8().data()); | ||
1547 | 1275 | } | ||
1548 | 1276 | |||
1549 | 1277 | parseContext(FOLKS_ABSTRACT_FIELD_DETAILS(noteDetails), detail); | ||
1550 | 1278 | folks_note_details_change_notes(FOLKS_NOTE_DETAILS(persona), | ||
1551 | 990 | noteSet, | 1279 | noteSet, |
1552 | 991 | (GAsyncReadyCallback) updateDetailsDone, | 1280 | (GAsyncReadyCallback) updateDetailsDone, |
1554 | 992 | data); | 1281 | data);; |
1555 | 1282 | g_object_unref(noteDetails); | ||
1556 | 993 | g_object_unref(noteSet); | 1283 | g_object_unref(noteSet); |
1557 | 994 | } else { | 1284 | } else { |
1562 | 995 | updateDetailsDone(G_OBJECT(m_individual), NULL, data); | 1285 | updateDetailsDone(G_OBJECT(persona), NULL, data); |
1563 | 996 | } | 1286 | } |
1564 | 997 | } | 1287 | } |
1565 | 998 | 1288 | ||
1566 | 1289 | QString QIndividual::callDetailChangeFinish(QtContacts::QContactDetail::DetailType detailType, | ||
1567 | 1290 | FolksPersona *persona, | ||
1568 | 1291 | GAsyncResult *result) | ||
1569 | 1292 | { | ||
1570 | 1293 | Q_ASSERT(persona); | ||
1571 | 1294 | Q_ASSERT(result); | ||
1572 | 1295 | |||
1573 | 1296 | GError *error = 0; | ||
1574 | 1297 | switch(detailType) { | ||
1575 | 1298 | case QContactDetail::TypeAddress: | ||
1576 | 1299 | folks_postal_address_details_change_postal_addresses_finish(FOLKS_POSTAL_ADDRESS_DETAILS(persona), result, &error); | ||
1577 | 1300 | break; | ||
1578 | 1301 | case QContactDetail::TypeAvatar: | ||
1579 | 1302 | folks_avatar_details_change_avatar_finish(FOLKS_AVATAR_DETAILS(persona), result, &error); | ||
1580 | 1303 | break; | ||
1581 | 1304 | case QContactDetail::TypeBirthday: | ||
1582 | 1305 | folks_birthday_details_change_birthday_finish(FOLKS_BIRTHDAY_DETAILS(persona), result, &error); | ||
1583 | 1306 | break; | ||
1584 | 1307 | case QContactDetail::TypeDisplayLabel: | ||
1585 | 1308 | folks_name_details_change_full_name_finish(FOLKS_NAME_DETAILS(persona), result, &error); | ||
1586 | 1309 | break; | ||
1587 | 1310 | case QContactDetail::TypeEmailAddress: | ||
1588 | 1311 | folks_email_details_change_email_addresses_finish(FOLKS_EMAIL_DETAILS(persona), result, &error); | ||
1589 | 1312 | break; | ||
1590 | 1313 | case QContactDetail::TypeName: | ||
1591 | 1314 | folks_name_details_change_structured_name_finish(FOLKS_NAME_DETAILS(persona), result, &error); | ||
1592 | 1315 | break; | ||
1593 | 1316 | case QContactDetail::TypeNickname: | ||
1594 | 1317 | folks_name_details_change_nickname_finish(FOLKS_NAME_DETAILS(persona), result, &error); | ||
1595 | 1318 | break; | ||
1596 | 1319 | case QContactDetail::TypeNote: | ||
1597 | 1320 | folks_note_details_change_notes_finish(FOLKS_NOTE_DETAILS(persona), result, &error); | ||
1598 | 1321 | break; | ||
1599 | 1322 | case QContactDetail::TypeOnlineAccount: | ||
1600 | 1323 | folks_im_details_change_im_addresses_finish(FOLKS_IM_DETAILS(persona), result, &error); | ||
1601 | 1324 | break; | ||
1602 | 1325 | case QContactDetail::TypeOrganization: | ||
1603 | 1326 | folks_role_details_change_roles_finish(FOLKS_ROLE_DETAILS(persona), result, &error); | ||
1604 | 1327 | break; | ||
1605 | 1328 | case QContactDetail::TypePhoneNumber: | ||
1606 | 1329 | folks_phone_details_change_phone_numbers_finish(FOLKS_PHONE_DETAILS(persona), result, &error); | ||
1607 | 1330 | break; | ||
1608 | 1331 | case QContactDetail::TypeUrl: | ||
1609 | 1332 | folks_url_details_change_urls_finish(FOLKS_URL_DETAILS(persona), result, &error); | ||
1610 | 1333 | default: | ||
1611 | 1334 | break; | ||
1612 | 1335 | } | ||
1613 | 1336 | |||
1614 | 1337 | QString errorMessage; | ||
1615 | 1338 | if (error) { | ||
1616 | 1339 | errorMessage = QString::fromUtf8(error->message); | ||
1617 | 1340 | g_error_free(error); | ||
1618 | 1341 | } | ||
1619 | 1342 | return errorMessage; | ||
1620 | 1343 | } | ||
1621 | 1344 | |||
1622 | 1345 | void QIndividual::updateDetailsSendReply(gpointer userdata, const QString &errorMessage) | ||
1623 | 1346 | { | ||
1624 | 1347 | UpdateContactData *data = static_cast<UpdateContactData*>(userdata); | ||
1625 | 1348 | data->m_slot.invoke(data->m_object, | ||
1626 | 1349 | Q_ARG(QIndividual*, data->m_self), Q_ARG(QString, errorMessage)); | ||
1627 | 1350 | delete data; | ||
1628 | 1351 | } | ||
1629 | 1352 | |||
1630 | 1353 | void QIndividual::updateDetailsSendReply(gpointer userdata, GError *error) | ||
1631 | 1354 | { | ||
1632 | 1355 | QString errorMessage; | ||
1633 | 1356 | if (error) { | ||
1634 | 1357 | errorMessage = QString::fromUtf8(error->message); | ||
1635 | 1358 | qWarning() << error->message; | ||
1636 | 1359 | g_error_free(error); | ||
1637 | 1360 | } | ||
1638 | 1361 | updateDetailsSendReply(userdata, errorMessage); | ||
1639 | 1362 | } | ||
1640 | 1363 | |||
1641 | 1364 | |||
1642 | 1365 | void QIndividual::createPersonaDone(GObject *aggregator, GAsyncResult *result, gpointer userdata) | ||
1643 | 1366 | { | ||
1644 | 1367 | qDebug() << Q_FUNC_INFO; | ||
1645 | 1368 | UpdateContactData *data = static_cast<UpdateContactData*>(userdata); | ||
1646 | 1369 | |||
1647 | 1370 | // A new persona was create to store the new data | ||
1648 | 1371 | GError *error = 0; | ||
1649 | 1372 | FolksPersona *newPersona = folks_individual_aggregator_add_persona_from_details_finish(FOLKS_INDIVIDUAL_AGGREGATOR(aggregator), | ||
1650 | 1373 | result, | ||
1651 | 1374 | &error); | ||
1652 | 1375 | if (error) { | ||
1653 | 1376 | updateDetailsSendReply(data, error); | ||
1654 | 1377 | } else { | ||
1655 | 1378 | // Link the new personas | ||
1656 | 1379 | GeeSet *personas = folks_individual_get_personas(data->m_self->m_individual); | ||
1657 | 1380 | GeeSet *newPersonas = SET_PERSONA_NEW(); | ||
1658 | 1381 | gee_collection_add_all(GEE_COLLECTION(newPersonas), GEE_COLLECTION(personas)); | ||
1659 | 1382 | gee_collection_add(GEE_COLLECTION(newPersonas), newPersona); | ||
1660 | 1383 | data->m_self->m_primaryPersona = newPersona; | ||
1661 | 1384 | folks_individual_aggregator_link_personas(data->m_self->m_aggregator, newPersonas, updateDetailsDone, userdata); | ||
1662 | 1385 | } | ||
1663 | 1386 | } | ||
1664 | 999 | 1387 | ||
1665 | 1000 | void QIndividual::updateDetailsDone(GObject *detail, GAsyncResult *result, gpointer userdata) | 1388 | void QIndividual::updateDetailsDone(GObject *detail, GAsyncResult *result, gpointer userdata) |
1666 | 1001 | { | 1389 | { |
1668 | 1002 | GError *error = 0; | 1390 | QString errorMessage; |
1669 | 1003 | UpdateContactData *data = static_cast<UpdateContactData*>(userdata); | 1391 | UpdateContactData *data = static_cast<UpdateContactData*>(userdata); |
1672 | 1004 | 1392 | if (result && !data->m_currentDetail.isEmpty()) { | |
1673 | 1005 | switch(data->m_currentDetailType) { | 1393 | if (FOLKS_IS_PERSONA(detail)) { |
1674 | 1394 | // This is a normal field update | ||
1675 | 1395 | errorMessage = QIndividual::callDetailChangeFinish(data->m_currentDetail.type(), | ||
1676 | 1396 | FOLKS_PERSONA(detail), | ||
1677 | 1397 | result); | ||
1678 | 1398 | } else if (FOLKS_IS_INDIVIDUAL_AGGREGATOR(detail)) { | ||
1679 | 1399 | GError *error = 0; | ||
1680 | 1400 | folks_individual_aggregator_link_personas_finish(FOLKS_INDIVIDUAL_AGGREGATOR(detail), result, &error); | ||
1681 | 1401 | if (error) { | ||
1682 | 1402 | errorMessage = QString::fromUtf8(error->message); | ||
1683 | 1403 | } | ||
1684 | 1404 | } | ||
1685 | 1405 | |||
1686 | 1406 | if (!errorMessage.isEmpty()) { | ||
1687 | 1407 | updateDetailsSendReply(data, errorMessage); | ||
1688 | 1408 | return; | ||
1689 | 1409 | } | ||
1690 | 1410 | } | ||
1691 | 1411 | |||
1692 | 1412 | if (data->m_details.isEmpty()) { | ||
1693 | 1413 | updateDetailsSendReply(data, 0); | ||
1694 | 1414 | return; | ||
1695 | 1415 | } | ||
1696 | 1416 | |||
1697 | 1417 | |||
1698 | 1418 | data->m_currentDetail = data->m_details.takeFirst(); | ||
1699 | 1419 | switch(data->m_currentDetail.type()) { | ||
1700 | 1006 | case QContactDetail::TypeAddress: | 1420 | case QContactDetail::TypeAddress: |
1709 | 1007 | if (result) { | 1421 | data->m_self->updateAddress(data->m_currentDetail, data); |
1702 | 1008 | folks_postal_address_details_change_postal_addresses_finish(FOLKS_POSTAL_ADDRESS_DETAILS(data->m_persona), result, &error); | ||
1703 | 1009 | } | ||
1704 | 1010 | if (!error) { | ||
1705 | 1011 | data->m_currentDetailType = QContactDetail::TypeAvatar; | ||
1706 | 1012 | data->m_self->updatePhoto(data->m_newContact.detail(QContactDetail::TypeAvatar), data); | ||
1707 | 1013 | return; | ||
1708 | 1014 | } | ||
1710 | 1015 | break; | 1422 | break; |
1711 | 1016 | case QContactDetail::TypeAvatar: | 1423 | case QContactDetail::TypeAvatar: |
1720 | 1017 | if (result) { | 1424 | data->m_self->updatePhoto(data->m_currentDetail, data); |
1713 | 1018 | folks_avatar_details_change_avatar_finish(FOLKS_AVATAR_DETAILS(data->m_persona), result, &error); | ||
1714 | 1019 | } | ||
1715 | 1020 | if (!error) { | ||
1716 | 1021 | data->m_currentDetailType = QContactDetail::TypeBirthday; | ||
1717 | 1022 | data->m_self->updateBirthday(data->m_newContact.detail(QContactDetail::TypeBirthday), data); | ||
1718 | 1023 | return; | ||
1719 | 1024 | } | ||
1721 | 1025 | break; | 1425 | break; |
1722 | 1026 | case QContactDetail::TypeBirthday: | 1426 | case QContactDetail::TypeBirthday: |
1731 | 1027 | if (result) { | 1427 | data->m_self->updateBirthday(data->m_currentDetail, data); |
1724 | 1028 | folks_birthday_details_change_birthday_finish(FOLKS_BIRTHDAY_DETAILS(data->m_persona), result, &error); | ||
1725 | 1029 | } | ||
1726 | 1030 | if (!error) { | ||
1727 | 1031 | data->m_currentDetailType = QContactDetail::TypeDisplayLabel; | ||
1728 | 1032 | data->m_self->updateFullName(data->m_newContact.detail(QContactDetail::TypeDisplayLabel), data); | ||
1729 | 1033 | return; | ||
1730 | 1034 | } | ||
1732 | 1035 | break; | 1428 | break; |
1733 | 1036 | case QContactDetail::TypeDisplayLabel: | 1429 | case QContactDetail::TypeDisplayLabel: |
1742 | 1037 | if (result) { | 1430 | data->m_self->updateFullName(data->m_currentDetail, data); |
1735 | 1038 | folks_name_details_change_full_name_finish(FOLKS_NAME_DETAILS(data->m_persona), result, &error); | ||
1736 | 1039 | } | ||
1737 | 1040 | if (!error) { | ||
1738 | 1041 | data->m_currentDetailType = QContactDetail::TypeEmailAddress; | ||
1739 | 1042 | data->m_self->updateEmails(data->m_newContact.details(QContactDetail::TypeEmailAddress), data); | ||
1740 | 1043 | return; | ||
1741 | 1044 | } | ||
1743 | 1045 | break; | 1431 | break; |
1744 | 1046 | |||
1745 | 1047 | case QContactDetail::TypeEmailAddress: | 1432 | case QContactDetail::TypeEmailAddress: |
1754 | 1048 | if (result) { | 1433 | data->m_self->updateEmail(data->m_currentDetail, data); |
1747 | 1049 | folks_email_details_change_email_addresses_finish(FOLKS_EMAIL_DETAILS(data->m_persona), result, &error); | ||
1748 | 1050 | } | ||
1749 | 1051 | if (!error) { | ||
1750 | 1052 | data->m_currentDetailType = QContactDetail::TypeName; | ||
1751 | 1053 | data->m_self->updateName(data->m_newContact.detail(QContactDetail::TypeName), data); | ||
1752 | 1054 | return; | ||
1753 | 1055 | } | ||
1755 | 1056 | break; | 1434 | break; |
1756 | 1057 | case QContactDetail::TypeName: | 1435 | case QContactDetail::TypeName: |
1765 | 1058 | if (result) { | 1436 | data->m_self->updateName(data->m_currentDetail, data); |
1758 | 1059 | folks_name_details_change_structured_name_finish(FOLKS_NAME_DETAILS(data->m_persona), result, &error); | ||
1759 | 1060 | } | ||
1760 | 1061 | if (!error) { | ||
1761 | 1062 | data->m_currentDetailType = QContactDetail::TypeNickname; | ||
1762 | 1063 | data->m_self->updateNickname(data->m_newContact.detail(QContactDetail::TypeNickname), data); | ||
1763 | 1064 | return; | ||
1764 | 1065 | } | ||
1766 | 1066 | break; | 1437 | break; |
1767 | 1067 | case QContactDetail::TypeNickname: | 1438 | case QContactDetail::TypeNickname: |
1776 | 1068 | if (result) { | 1439 | data->m_self->updateNickname(data->m_currentDetail, data); |
1769 | 1069 | folks_name_details_change_nickname_finish(FOLKS_NAME_DETAILS(data->m_persona), result, &error); | ||
1770 | 1070 | } | ||
1771 | 1071 | if (!error) { | ||
1772 | 1072 | data->m_currentDetailType = QContactDetail::TypeNote; | ||
1773 | 1073 | data->m_self->updateNotes(data->m_newContact.details(QContactDetail::TypeNote), data); | ||
1774 | 1074 | return; | ||
1775 | 1075 | } | ||
1777 | 1076 | break; | 1440 | break; |
1778 | 1077 | case QContactDetail::TypeNote: | 1441 | case QContactDetail::TypeNote: |
1787 | 1078 | if (result) { | 1442 | data->m_self->updateNote(data->m_currentDetail, data); |
1780 | 1079 | folks_note_details_change_notes_finish(FOLKS_NOTE_DETAILS(data->m_persona), result, &error); | ||
1781 | 1080 | } | ||
1782 | 1081 | if (!error) { | ||
1783 | 1082 | data->m_currentDetailType = QContactDetail::TypeOnlineAccount; | ||
1784 | 1083 | data->m_self->updateIms(data->m_newContact.details(QContactDetail::TypeOnlineAccount), data); | ||
1785 | 1084 | return; | ||
1786 | 1085 | } | ||
1788 | 1086 | break; | 1443 | break; |
1789 | 1087 | case QContactDetail::TypeOnlineAccount: | 1444 | case QContactDetail::TypeOnlineAccount: |
1798 | 1088 | if (result) { | 1445 | data->m_self->updateIm(data->m_currentDetail, data); |
1791 | 1089 | folks_im_details_change_im_addresses_finish(FOLKS_IM_DETAILS(data->m_persona), result, &error); | ||
1792 | 1090 | } | ||
1793 | 1091 | if (!error) { | ||
1794 | 1092 | data->m_currentDetailType = QContactDetail::TypeOrganization; | ||
1795 | 1093 | data->m_self->updateRoles(data->m_newContact.details(QContactDetail::TypeOrganization), data); | ||
1796 | 1094 | return; | ||
1797 | 1095 | } | ||
1799 | 1096 | break; | 1446 | break; |
1800 | 1097 | case QContactDetail::TypeOrganization: | 1447 | case QContactDetail::TypeOrganization: |
1809 | 1098 | if (result) { | 1448 | data->m_self->updateRole(data->m_currentDetail, data); |
1802 | 1099 | folks_role_details_change_roles_finish(FOLKS_ROLE_DETAILS(data->m_persona), result, &error); | ||
1803 | 1100 | } | ||
1804 | 1101 | if (!error) { | ||
1805 | 1102 | data->m_currentDetailType = QContactDetail::TypePhoneNumber; | ||
1806 | 1103 | data->m_self->updatePhones(data->m_newContact.details(QContactDetail::TypePhoneNumber), data); | ||
1807 | 1104 | return; | ||
1808 | 1105 | } | ||
1810 | 1106 | break; | 1449 | break; |
1811 | 1107 | case QContactDetail::TypePhoneNumber: | 1450 | case QContactDetail::TypePhoneNumber: |
1820 | 1108 | if (result) { | 1451 | data->m_self->updatePhone(data->m_currentDetail, data); |
1813 | 1109 | folks_phone_details_change_phone_numbers_finish(FOLKS_PHONE_DETAILS(data->m_persona), result, &error); | ||
1814 | 1110 | } | ||
1815 | 1111 | if (!error) { | ||
1816 | 1112 | data->m_currentDetailType = QContactDetail::TypeUrl; | ||
1817 | 1113 | data->m_self->updateUrls(data->m_newContact.details(QContactDetail::TypeUrl), data); | ||
1818 | 1114 | return; | ||
1819 | 1115 | } | ||
1821 | 1116 | break; | 1452 | break; |
1822 | 1117 | case QContactDetail::TypeUrl: | 1453 | case QContactDetail::TypeUrl: |
1826 | 1118 | if (result) { | 1454 | data->m_self->updateUrl(data->m_currentDetail, data); |
1827 | 1119 | folks_url_details_change_urls_finish(FOLKS_URL_DETAILS(data->m_persona), result, &error); | 1455 | break; |
1825 | 1120 | } | ||
1828 | 1121 | default: | 1456 | default: |
1829 | 1457 | qWarning() << "Update not implemented for" << data->m_currentDetail.type(); | ||
1830 | 1458 | updateDetailsDone(0, 0, data); | ||
1831 | 1122 | break; | 1459 | break; |
1832 | 1123 | } | 1460 | } |
1833 | 1124 | |||
1834 | 1125 | QString errorMessage; | ||
1835 | 1126 | if (error) { | ||
1836 | 1127 | errorMessage = QString::fromUtf8(error->message); | ||
1837 | 1128 | g_error_free(error); | ||
1838 | 1129 | } | ||
1839 | 1130 | |||
1840 | 1131 | qDebug() << "Update done" << errorMessage; | ||
1841 | 1132 | data->m_doneCB(errorMessage, data->m_doneData); | ||
1842 | 1133 | delete data; | ||
1843 | 1134 | } | 1461 | } |
1844 | 1135 | 1462 | ||
1847 | 1136 | 1463 | bool QIndividual::update(const QtContacts::QContact &newContact, QObject *object, const QString &slot) | |
1846 | 1137 | bool QIndividual::update(const QtContacts::QContact &newContact, UpdateDoneCB cb, void* userData) | ||
1848 | 1138 | { | 1464 | { |
1849 | 1465 | int slotIndex = object->metaObject()->indexOfSlot(QMetaObject::normalizedSignature(slot.toUtf8().data())); | ||
1850 | 1466 | if (slotIndex == -1) { | ||
1851 | 1467 | qWarning() << "Invalid slot:" << slot << "for object" << object; | ||
1852 | 1468 | return false; | ||
1853 | 1469 | } | ||
1854 | 1470 | |||
1855 | 1139 | QContact &originalContact = contact(); | 1471 | QContact &originalContact = contact(); |
1856 | 1140 | if (newContact != originalContact) { | 1472 | if (newContact != originalContact) { |
1857 | 1141 | 1473 | ||
1858 | 1142 | UpdateContactData *data = new UpdateContactData; | 1474 | UpdateContactData *data = new UpdateContactData; |
1860 | 1143 | data->m_currentDetailType = QContactDetail::TypeAddress; | 1475 | data->m_details = newContact.details(); |
1861 | 1144 | data->m_newContact = newContact; | 1476 | data->m_newContact = newContact; |
1862 | 1145 | data->m_self = this; | 1477 | data->m_self = this; |
1868 | 1146 | data->m_doneCB = cb; | 1478 | data->m_object = object; |
1869 | 1147 | data->m_doneData = userData; | 1479 | data->m_slot = object->metaObject()->method(slotIndex); |
1870 | 1148 | data->m_persona = primaryPersona(); | 1480 | updateDetailsDone(0, 0, data); |
1866 | 1149 | |||
1867 | 1150 | updateAddresses(newContact.details(QContactDetail::TypeAddress), data); | ||
1871 | 1151 | return true; | 1481 | return true; |
1872 | 1152 | } else { | 1482 | } else { |
1873 | 1153 | qDebug() << "Contact is equal"; | 1483 | qDebug() << "Contact is equal"; |
1874 | @@ -1160,10 +1490,26 @@ | |||
1875 | 1160 | return m_individual; | 1490 | return m_individual; |
1876 | 1161 | } | 1491 | } |
1877 | 1162 | 1492 | ||
1879 | 1163 | bool QIndividual::update(const QString &vcard, UpdateDoneCB cb, void* data) | 1493 | void QIndividual::setIndividual(FolksIndividual *individual) |
1880 | 1494 | { | ||
1881 | 1495 | if (m_individual != individual) { | ||
1882 | 1496 | if (m_individual) { | ||
1883 | 1497 | g_object_unref(m_individual); | ||
1884 | 1498 | } | ||
1885 | 1499 | m_individual = individual; | ||
1886 | 1500 | if (m_individual) { | ||
1887 | 1501 | g_object_ref(m_individual); | ||
1888 | 1502 | } | ||
1889 | 1503 | // initialize qcontact | ||
1890 | 1504 | m_contact = QContact(); | ||
1891 | 1505 | updateContact(); | ||
1892 | 1506 | } | ||
1893 | 1507 | } | ||
1894 | 1508 | |||
1895 | 1509 | bool QIndividual::update(const QString &vcard, QObject *object, const QString &slot) | ||
1896 | 1164 | { | 1510 | { |
1897 | 1165 | QContact contact = VCardParser::vcardToContact(vcard); | 1511 | QContact contact = VCardParser::vcardToContact(vcard); |
1899 | 1166 | return update(contact, cb, data); | 1512 | return update(contact, object, slot); |
1900 | 1167 | } | 1513 | } |
1901 | 1168 | 1514 | ||
1902 | 1169 | QStringList QIndividual::listParameters(FolksAbstractFieldDetails *details) | 1515 | QStringList QIndividual::listParameters(FolksAbstractFieldDetails *details) |
1903 | @@ -1362,6 +1708,8 @@ | |||
1904 | 1362 | { | 1708 | { |
1905 | 1363 | static QMap<QString, int> map; | 1709 | static QMap<QString, int> map; |
1906 | 1364 | 1710 | ||
1907 | 1711 | qDebug() << "PArse paramater:" << parameters; | ||
1908 | 1712 | |||
1909 | 1365 | // populate the map once | 1713 | // populate the map once |
1910 | 1366 | if (map.isEmpty()) { | 1714 | if (map.isEmpty()) { |
1911 | 1367 | map["home"] = QContactDetail::ContextHome; | 1715 | map["home"] = QContactDetail::ContextHome; |
1912 | @@ -1372,9 +1720,9 @@ | |||
1913 | 1372 | QList<int> values; | 1720 | QList<int> values; |
1914 | 1373 | QStringList accepted; | 1721 | QStringList accepted; |
1915 | 1374 | Q_FOREACH(const QString ¶m, parameters) { | 1722 | Q_FOREACH(const QString ¶m, parameters) { |
1917 | 1375 | if (map.contains(param)) { | 1723 | if (map.contains(param.toLower())) { |
1918 | 1376 | accepted << param; | 1724 | accepted << param; |
1920 | 1377 | values << map[param]; | 1725 | values << map[param.toLower()]; |
1921 | 1378 | } | 1726 | } |
1922 | 1379 | } | 1727 | } |
1923 | 1380 | 1728 | ||
1924 | @@ -1382,6 +1730,8 @@ | |||
1925 | 1382 | parameters.removeOne(param); | 1730 | parameters.removeOne(param); |
1926 | 1383 | } | 1731 | } |
1927 | 1384 | 1732 | ||
1928 | 1733 | qDebug() << "PArseed paramater (DONE):" << parameters; | ||
1929 | 1734 | |||
1930 | 1385 | return values; | 1735 | return values; |
1931 | 1386 | } | 1736 | } |
1932 | 1387 | 1737 | ||
1933 | @@ -1407,8 +1757,8 @@ | |||
1934 | 1407 | 1757 | ||
1935 | 1408 | QList<int> subTypes; | 1758 | QList<int> subTypes; |
1936 | 1409 | Q_FOREACH(const QString ¶m, params) { | 1759 | Q_FOREACH(const QString ¶m, params) { |
1939 | 1410 | if (mapTypes.contains(param)) { | 1760 | if (mapTypes.contains(param.toLower())) { |
1940 | 1411 | subTypes << mapTypes[param]; | 1761 | subTypes << mapTypes[param.toLower()]; |
1941 | 1412 | } else { | 1762 | } else { |
1942 | 1413 | qWarning() << "Invalid phone parameter:" << param; | 1763 | qWarning() << "Invalid phone parameter:" << param; |
1943 | 1414 | } | 1764 | } |
1944 | @@ -1434,8 +1784,8 @@ | |||
1945 | 1434 | QList<int> values; | 1784 | QList<int> values; |
1946 | 1435 | 1785 | ||
1947 | 1436 | Q_FOREACH(const QString ¶m, parameters) { | 1786 | Q_FOREACH(const QString ¶m, parameters) { |
1950 | 1437 | if (map.contains(param)) { | 1787 | if (map.contains(param.toLower())) { |
1951 | 1438 | values << map[param]; | 1788 | values << map[param.toLower()]; |
1952 | 1439 | } else { | 1789 | } else { |
1953 | 1440 | qWarning() << "invalid Address subtype" << param; | 1790 | qWarning() << "invalid Address subtype" << param; |
1954 | 1441 | } | 1791 | } |
1955 | @@ -1461,8 +1811,8 @@ | |||
1956 | 1461 | QSet<int> values; | 1811 | QSet<int> values; |
1957 | 1462 | 1812 | ||
1958 | 1463 | Q_FOREACH(const QString ¶m, parameters) { | 1813 | Q_FOREACH(const QString ¶m, parameters) { |
1961 | 1464 | if (map.contains(param)) { | 1814 | if (map.contains(param.toLower())) { |
1962 | 1465 | values << map[param]; | 1815 | values << map[param.toLower()]; |
1963 | 1466 | } else { | 1816 | } else { |
1964 | 1467 | qWarning() << "invalid IM subtype" << param; | 1817 | qWarning() << "invalid IM subtype" << param; |
1965 | 1468 | } | 1818 | } |
1966 | @@ -1497,8 +1847,8 @@ | |||
1967 | 1497 | map["yahoo"] = QContactOnlineAccount::ProtocolYahoo; | 1847 | map["yahoo"] = QContactOnlineAccount::ProtocolYahoo; |
1968 | 1498 | } | 1848 | } |
1969 | 1499 | 1849 | ||
1972 | 1500 | if (map.contains(protocol)) { | 1850 | if (map.contains(protocol.toLower())) { |
1973 | 1501 | return map[protocol]; | 1851 | return map[protocol.toLower()]; |
1974 | 1502 | } else { | 1852 | } else { |
1975 | 1503 | qWarning() << "invalid IM protocol" << protocol; | 1853 | qWarning() << "invalid IM protocol" << protocol; |
1976 | 1504 | } | 1854 | } |
1977 | @@ -1532,31 +1882,26 @@ | |||
1978 | 1532 | return map[QContactOnlineAccount::ProtocolUnknown]; | 1882 | return map[QContactOnlineAccount::ProtocolUnknown]; |
1979 | 1533 | } | 1883 | } |
1980 | 1534 | 1884 | ||
1982 | 1535 | GHashTable *QIndividual::parseDetails(const QtContacts::QContact &contact) | 1885 | GHashTable *QIndividual::parseAddressDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails) |
1983 | 1536 | { | 1886 | { |
1998 | 1537 | GHashTable *details = g_hash_table_new_full(g_str_hash, | 1887 | if(cDetails.size() == 0) { |
1999 | 1538 | g_str_equal, | 1888 | return details; |
2000 | 1539 | NULL, | 1889 | } |
2001 | 1540 | (GDestroyNotify) QIndividualUtils::gValueSliceFree); | 1890 | |
2002 | 1541 | GValue *value; | 1891 | GValue *value = QIndividualUtils::gValueSliceNew(G_TYPE_OBJECT); |
2003 | 1542 | 1892 | ||
2004 | 1543 | /* | 1893 | Q_FOREACH(const QContactDetail& detail, cDetails) { |
2005 | 1544 | * Addresses | 1894 | if(!detail.isEmpty()) { |
2006 | 1545 | */ | 1895 | QContactAddress address = static_cast<QContactAddress>(detail); |
1993 | 1546 | QList<QContactAddress> addresses = contact.details<QContactAddress>(); | ||
1994 | 1547 | if(addresses.size() > 0) { | ||
1995 | 1548 | value = QIndividualUtils::gValueSliceNew(G_TYPE_OBJECT); | ||
1996 | 1549 | Q_FOREACH(const QContactAddress& address, addresses) { | ||
1997 | 1550 | if(!address.isEmpty()) { | ||
2007 | 1551 | FolksPostalAddress *postalAddress = folks_postal_address_new(address.postOfficeBox().toUtf8().data(), | 1896 | FolksPostalAddress *postalAddress = folks_postal_address_new(address.postOfficeBox().toUtf8().data(), |
2016 | 1552 | NULL, // extension | 1897 | NULL, // extension |
2017 | 1553 | address.street().toUtf8().data(), | 1898 | address.street().toUtf8().data(), |
2018 | 1554 | address.locality().toUtf8().data(), | 1899 | address.locality().toUtf8().data(), |
2019 | 1555 | address.region().toUtf8().data(), | 1900 | address.region().toUtf8().data(), |
2020 | 1556 | address.postcode().toUtf8().data(), | 1901 | address.postcode().toUtf8().data(), |
2021 | 1557 | address.country().toUtf8().data(), | 1902 | address.country().toUtf8().data(), |
2022 | 1558 | NULL, // address format | 1903 | NULL, // address format |
2023 | 1559 | NULL); //UID | 1904 | NULL); //UID |
2024 | 1560 | 1905 | ||
2025 | 1561 | GeeCollection *collection = (GeeCollection*) g_value_get_object(value); | 1906 | GeeCollection *collection = (GeeCollection*) g_value_get_object(value); |
2026 | 1562 | if(collection == NULL) { | 1907 | if(collection == NULL) { |
2027 | @@ -1570,188 +1915,318 @@ | |||
2028 | 1570 | 1915 | ||
2029 | 1571 | g_object_unref(pafd); | 1916 | g_object_unref(pafd); |
2030 | 1572 | g_object_unref(postalAddress); | 1917 | g_object_unref(postalAddress); |
2031 | 1573 | } | ||
2032 | 1574 | } | 1918 | } |
2033 | 1575 | QIndividualUtils::personaDetailsInsert(details, FOLKS_PERSONA_DETAIL_POSTAL_ADDRESSES, value); | 1919 | QIndividualUtils::personaDetailsInsert(details, FOLKS_PERSONA_DETAIL_POSTAL_ADDRESSES, value); |
2034 | 1576 | } | 1920 | } |
2035 | 1577 | 1921 | ||
2074 | 1578 | 1922 | return details; | |
2075 | 1579 | /* | 1923 | } |
2076 | 1580 | * Avatar | 1924 | |
2077 | 1581 | */ | 1925 | GHashTable *QIndividual::parsePhotoDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails) |
2078 | 1582 | QContactAvatar avatar = contact.detail<QContactAvatar>(); | 1926 | { |
2079 | 1583 | if(!avatar.isEmpty()) { | 1927 | if(cDetails.size() == 0) { |
2080 | 1584 | value = QIndividualUtils::gValueSliceNew(G_TYPE_FILE_ICON); | 1928 | return details; |
2081 | 1585 | QUrl avatarUri = avatar.imageUrl(); | 1929 | } |
2082 | 1586 | if(!avatarUri.isEmpty()) { | 1930 | |
2083 | 1587 | QString formattedUri = avatarUri.toString(QUrl::RemoveUserInfo); | 1931 | Q_FOREACH(const QContactDetail& detail, cDetails) { |
2084 | 1588 | if(!formattedUri.isEmpty()) { | 1932 | QContactAvatar avatar = static_cast<QContactAvatar>(detail); |
2085 | 1589 | GFile *avatarFile = g_file_new_for_uri(formattedUri.toUtf8().data()); | 1933 | if(!avatar.isEmpty()) { |
2086 | 1590 | GFileIcon *avatarFileIcon = G_FILE_ICON(g_file_icon_new(avatarFile)); | 1934 | GValue *value = QIndividualUtils::gValueSliceNew(G_TYPE_FILE_ICON); |
2087 | 1591 | g_value_take_object(value, avatarFileIcon); | 1935 | QUrl avatarUri = avatar.imageUrl(); |
2088 | 1592 | 1936 | if(!avatarUri.isEmpty()) { | |
2089 | 1593 | QIndividualUtils::personaDetailsInsert(details, FOLKS_PERSONA_DETAIL_AVATAR, value); | 1937 | QString formattedUri = avatarUri.toString(QUrl::RemoveUserInfo); |
2090 | 1594 | g_clear_object((GObject**) &avatarFile); | 1938 | if(!formattedUri.isEmpty()) { |
2091 | 1595 | } | 1939 | GFile *avatarFile = g_file_new_for_uri(formattedUri.toUtf8().data()); |
2092 | 1596 | } | 1940 | GFileIcon *avatarFileIcon = G_FILE_ICON(g_file_icon_new(avatarFile)); |
2093 | 1597 | } | 1941 | g_value_take_object(value, avatarFileIcon); |
2094 | 1598 | 1942 | ||
2095 | 1599 | /* | 1943 | QIndividualUtils::personaDetailsInsert(details, FOLKS_PERSONA_DETAIL_AVATAR, value); |
2096 | 1600 | * Birthday | 1944 | g_clear_object((GObject**) &avatarFile); |
2097 | 1601 | */ | 1945 | } |
2098 | 1602 | QContactBirthday birthday = contact.detail<QContactBirthday>(); | 1946 | } else { |
2099 | 1603 | if(!birthday.isEmpty()) { | 1947 | g_object_unref(value); |
2100 | 1604 | value = QIndividualUtils::gValueSliceNew(G_TYPE_DATE_TIME); | 1948 | } |
2101 | 1605 | GDateTime *dateTime = g_date_time_new_from_unix_utc(birthday.dateTime().toMSecsSinceEpoch() / 1000); | 1949 | } |
2102 | 1606 | g_value_set_boxed(value, dateTime); | 1950 | } |
2103 | 1607 | 1951 | ||
2104 | 1608 | QIndividualUtils::personaDetailsInsert(details, FOLKS_PERSONA_DETAIL_BIRTHDAY, value); | 1952 | return details; |
2105 | 1609 | g_date_time_unref(dateTime); | 1953 | } |
2106 | 1610 | } | 1954 | |
2107 | 1611 | 1955 | GHashTable *QIndividual::parseBirthdayDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails) | |
2108 | 1612 | /* | 1956 | { |
2109 | 1613 | * Email addresses | 1957 | if(cDetails.size() == 0) { |
2110 | 1614 | */ | 1958 | return details; |
2111 | 1615 | PERSONA_DETAILS_INSERT_STRING_FIELD_DETAILS(details, | 1959 | } |
2112 | 1960 | |||
2113 | 1961 | Q_FOREACH(const QContactDetail& detail, cDetails) { | ||
2114 | 1962 | QContactBirthday birthday = static_cast<QContactBirthday>(detail); | ||
2115 | 1963 | if(!birthday.isEmpty()) { | ||
2116 | 1964 | GValue *value = QIndividualUtils::gValueSliceNew(G_TYPE_DATE_TIME); | ||
2117 | 1965 | GDateTime *dateTime = g_date_time_new_from_unix_utc(birthday.dateTime().toMSecsSinceEpoch() / 1000); | ||
2118 | 1966 | g_value_set_boxed(value, dateTime); | ||
2119 | 1967 | |||
2120 | 1968 | QIndividualUtils::personaDetailsInsert(details, FOLKS_PERSONA_DETAIL_BIRTHDAY, value); | ||
2121 | 1969 | g_date_time_unref(dateTime); | ||
2122 | 1970 | } | ||
2123 | 1971 | } | ||
2124 | 1972 | |||
2125 | 1973 | return details; | ||
2126 | 1974 | } | ||
2127 | 1975 | |||
2128 | 1976 | GHashTable *QIndividual::parseEmailDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails) | ||
2129 | 1977 | { | ||
2130 | 1978 | if(cDetails.size() == 0) { | ||
2131 | 1979 | return details; | ||
2132 | 1980 | } | ||
2133 | 1981 | |||
2134 | 1982 | GValue *value; | ||
2135 | 1983 | PERSONA_DETAILS_INSERT_STRING_FIELD_DETAILS(details, cDetails, | ||
2136 | 1616 | FOLKS_PERSONA_DETAIL_EMAIL_ADDRESSES, value, QContactEmailAddress, | 1984 | FOLKS_PERSONA_DETAIL_EMAIL_ADDRESSES, value, QContactEmailAddress, |
2137 | 1617 | FOLKS_TYPE_EMAIL_FIELD_DETAILS, emailAddress); | 1985 | FOLKS_TYPE_EMAIL_FIELD_DETAILS, emailAddress); |
2198 | 1618 | 1986 | return details; | |
2199 | 1619 | /* | 1987 | } |
2200 | 1620 | * Favorite | 1988 | |
2201 | 1621 | */ | 1989 | GHashTable *QIndividual::parseFavoriteDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails) |
2202 | 1622 | QContactFavorite favorite = contact.detail<QContactFavorite>(); | 1990 | { |
2203 | 1623 | if(!favorite.isEmpty()) { | 1991 | if(cDetails.size() == 0) { |
2204 | 1624 | value = QIndividualUtils::gValueSliceNew(G_TYPE_BOOLEAN); | 1992 | return details; |
2205 | 1625 | g_value_set_boolean(value, favorite.isFavorite()); | 1993 | } |
2206 | 1626 | 1994 | ||
2207 | 1627 | QIndividualUtils::personaDetailsInsert(details, FOLKS_PERSONA_DETAIL_IS_FAVOURITE, value); | 1995 | Q_FOREACH(const QContactDetail& detail, cDetails) { |
2208 | 1628 | } | 1996 | QContactFavorite favorite = static_cast<QContactFavorite>(detail); |
2209 | 1629 | 1997 | if(!favorite.isEmpty()) { | |
2210 | 1630 | /* | 1998 | GValue *value = QIndividualUtils::gValueSliceNew(G_TYPE_BOOLEAN); |
2211 | 1631 | * Gender | 1999 | g_value_set_boolean(value, favorite.isFavorite()); |
2212 | 1632 | */ | 2000 | |
2213 | 1633 | QContactGender gender = contact.detail<QContactGender>(); | 2001 | QIndividualUtils::personaDetailsInsert(details, FOLKS_PERSONA_DETAIL_IS_FAVOURITE, value); |
2214 | 1634 | if(!gender.isEmpty()) { | 2002 | } |
2215 | 1635 | value = QIndividualUtils::gValueSliceNew(FOLKS_TYPE_GENDER); | 2003 | } |
2216 | 1636 | FolksGender genderEnum = FOLKS_GENDER_UNSPECIFIED; | 2004 | |
2217 | 1637 | if(gender.gender() == QContactGender::GenderMale) { | 2005 | return details; |
2218 | 1638 | genderEnum = FOLKS_GENDER_MALE; | 2006 | } |
2219 | 1639 | } else if(gender.gender() == QContactGender::GenderFemale) { | 2007 | |
2220 | 1640 | genderEnum = FOLKS_GENDER_FEMALE; | 2008 | GHashTable *QIndividual::parseGenderDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails) |
2221 | 1641 | } | 2009 | { |
2222 | 1642 | g_value_set_enum(value, genderEnum); | 2010 | if(cDetails.size() == 0) { |
2223 | 1643 | 2011 | return details; | |
2224 | 1644 | QIndividualUtils::personaDetailsInsert(details, FOLKS_PERSONA_DETAIL_GENDER, value); | 2012 | } |
2225 | 1645 | } | 2013 | |
2226 | 1646 | 2014 | Q_FOREACH(const QContactDetail& detail, cDetails) { | |
2227 | 1647 | /* | 2015 | QContactGender gender = static_cast<QContactDetail>(detail); |
2228 | 1648 | * Names | 2016 | if(!gender.isEmpty()) { |
2229 | 1649 | */ | 2017 | GValue *value = QIndividualUtils::gValueSliceNew(FOLKS_TYPE_GENDER); |
2230 | 1650 | QContactName name = contact.detail<QContactName>(); | 2018 | FolksGender genderEnum = FOLKS_GENDER_UNSPECIFIED; |
2231 | 1651 | if(!name.isEmpty()) { | 2019 | if(gender.gender() == QContactGender::GenderMale) { |
2232 | 1652 | value = QIndividualUtils::gValueSliceNew(FOLKS_TYPE_STRUCTURED_NAME); | 2020 | genderEnum = FOLKS_GENDER_MALE; |
2233 | 1653 | FolksStructuredName *sn = folks_structured_name_new(name.lastName().toUtf8().data(), | 2021 | } else if(gender.gender() == QContactGender::GenderFemale) { |
2234 | 1654 | name.firstName().toUtf8().data(), | 2022 | genderEnum = FOLKS_GENDER_FEMALE; |
2235 | 1655 | name.middleName().toUtf8().data(), | 2023 | } |
2236 | 1656 | name.prefix().toUtf8().data(), | 2024 | g_value_set_enum(value, genderEnum); |
2237 | 1657 | name.suffix().toUtf8().data()); | 2025 | |
2238 | 1658 | g_value_take_object(value, sn); | 2026 | QIndividualUtils::personaDetailsInsert(details, FOLKS_PERSONA_DETAIL_GENDER, value); |
2239 | 1659 | QIndividualUtils::personaDetailsInsert(details, FOLKS_PERSONA_DETAIL_STRUCTURED_NAME, value); | 2027 | } |
2240 | 1660 | } | 2028 | } |
2241 | 1661 | 2029 | ||
2242 | 1662 | QContactDisplayLabel displayLabel = contact.detail<QContactDisplayLabel>(); | 2030 | return details; |
2243 | 1663 | if(!displayLabel.label().isEmpty()) { | 2031 | } |
2244 | 1664 | value = QIndividualUtils::gValueSliceNew(G_TYPE_STRING); | 2032 | |
2245 | 1665 | g_value_set_string(value, displayLabel.label().toUtf8().data()); | 2033 | GHashTable *QIndividual::parseNameDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails) |
2246 | 1666 | QIndividualUtils::personaDetailsInsert(details, FOLKS_PERSONA_DETAIL_FULL_NAME, value); | 2034 | { |
2247 | 1667 | 2035 | if(cDetails.size() == 0) { | |
2248 | 1668 | // FIXME: check if those values should all be set to the same thing | 2036 | return details; |
2249 | 1669 | value = QIndividualUtils::gValueSliceNew(G_TYPE_STRING); | 2037 | } |
2250 | 1670 | g_value_set_string(value, displayLabel.label().toUtf8().data()); | 2038 | |
2251 | 1671 | QIndividualUtils::personaDetailsInsert(details, FOLKS_PERSONA_DETAIL_ALIAS, value); | 2039 | Q_FOREACH(const QContactDetail& detail, cDetails) { |
2252 | 1672 | } | 2040 | QContactName name = static_cast<QContactName>(detail); |
2253 | 1673 | 2041 | if(!name.isEmpty()) { | |
2254 | 1674 | /* | 2042 | GValue *value = QIndividualUtils::gValueSliceNew(FOLKS_TYPE_STRUCTURED_NAME); |
2255 | 1675 | * Notes | 2043 | FolksStructuredName *sn = folks_structured_name_new(name.lastName().toUtf8().data(), |
2256 | 1676 | */ | 2044 | name.firstName().toUtf8().data(), |
2257 | 1677 | PERSONA_DETAILS_INSERT_STRING_FIELD_DETAILS(details, | 2045 | name.middleName().toUtf8().data(), |
2258 | 2046 | name.prefix().toUtf8().data(), | ||
2259 | 2047 | name.suffix().toUtf8().data()); | ||
2260 | 2048 | g_value_take_object(value, sn); | ||
2261 | 2049 | QIndividualUtils::personaDetailsInsert(details, FOLKS_PERSONA_DETAIL_STRUCTURED_NAME, value); | ||
2262 | 2050 | } | ||
2263 | 2051 | } | ||
2264 | 2052 | |||
2265 | 2053 | return details; | ||
2266 | 2054 | } | ||
2267 | 2055 | |||
2268 | 2056 | GHashTable *QIndividual::parseFullNameDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails) | ||
2269 | 2057 | { | ||
2270 | 2058 | if(cDetails.size() == 0) { | ||
2271 | 2059 | return details; | ||
2272 | 2060 | } | ||
2273 | 2061 | |||
2274 | 2062 | Q_FOREACH(const QContactDetail& detail, cDetails) { | ||
2275 | 2063 | QContactDisplayLabel displayLabel = static_cast<QContactDisplayLabel>(detail); | ||
2276 | 2064 | if(!displayLabel.label().isEmpty()) { | ||
2277 | 2065 | GValue *value = QIndividualUtils::gValueSliceNew(G_TYPE_STRING); | ||
2278 | 2066 | g_value_set_string(value, displayLabel.label().toUtf8().data()); | ||
2279 | 2067 | QIndividualUtils::personaDetailsInsert(details, FOLKS_PERSONA_DETAIL_FULL_NAME, value); | ||
2280 | 2068 | |||
2281 | 2069 | // FIXME: check if those values should all be set to the same thing | ||
2282 | 2070 | value = QIndividualUtils::gValueSliceNew(G_TYPE_STRING); | ||
2283 | 2071 | g_value_set_string(value, displayLabel.label().toUtf8().data()); | ||
2284 | 2072 | QIndividualUtils::personaDetailsInsert(details, FOLKS_PERSONA_DETAIL_ALIAS, value); | ||
2285 | 2073 | } | ||
2286 | 2074 | } | ||
2287 | 2075 | |||
2288 | 2076 | return details; | ||
2289 | 2077 | } | ||
2290 | 2078 | |||
2291 | 2079 | GHashTable *QIndividual::parseNicknameDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails) | ||
2292 | 2080 | { | ||
2293 | 2081 | if(cDetails.size() == 0) { | ||
2294 | 2082 | return details; | ||
2295 | 2083 | } | ||
2296 | 2084 | |||
2297 | 2085 | Q_FOREACH(const QContactDetail& detail, cDetails) { | ||
2298 | 2086 | QContactNickname nickname = static_cast<QContactNickname>(detail); | ||
2299 | 2087 | if(!nickname.nickname().isEmpty()) { | ||
2300 | 2088 | GValue *value = QIndividualUtils::gValueSliceNew(G_TYPE_STRING); | ||
2301 | 2089 | g_value_set_string(value, nickname.nickname().toUtf8().data()); | ||
2302 | 2090 | QIndividualUtils::personaDetailsInsert(details, FOLKS_PERSONA_DETAIL_NICKNAME, value); | ||
2303 | 2091 | |||
2304 | 2092 | // FIXME: check if those values should all be set to the same thing | ||
2305 | 2093 | value = QIndividualUtils::gValueSliceNew(G_TYPE_STRING); | ||
2306 | 2094 | g_value_set_string(value, nickname.nickname().toUtf8().data()); | ||
2307 | 2095 | QIndividualUtils::personaDetailsInsert(details, FOLKS_PERSONA_DETAIL_ALIAS, value); | ||
2308 | 2096 | } | ||
2309 | 2097 | } | ||
2310 | 2098 | |||
2311 | 2099 | return details; | ||
2312 | 2100 | } | ||
2313 | 2101 | |||
2314 | 2102 | GHashTable *QIndividual::parseNoteDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails) | ||
2315 | 2103 | { | ||
2316 | 2104 | if(cDetails.size() == 0) { | ||
2317 | 2105 | return details; | ||
2318 | 2106 | } | ||
2319 | 2107 | |||
2320 | 2108 | GValue *value; | ||
2321 | 2109 | PERSONA_DETAILS_INSERT_STRING_FIELD_DETAILS(details, cDetails, | ||
2322 | 1678 | FOLKS_PERSONA_DETAIL_NOTES, value, QContactNote, | 2110 | FOLKS_PERSONA_DETAIL_NOTES, value, QContactNote, |
2323 | 1679 | FOLKS_TYPE_NOTE_FIELD_DETAILS, note); | 2111 | FOLKS_TYPE_NOTE_FIELD_DETAILS, note); |
2324 | 1680 | 2112 | ||
2397 | 1681 | 2113 | return details; | |
2398 | 1682 | 2114 | } | |
2399 | 1683 | /* | 2115 | |
2400 | 1684 | * OnlineAccounts | 2116 | GHashTable *QIndividual::parseImDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails) |
2401 | 1685 | */ | 2117 | { |
2402 | 1686 | QList<QContactOnlineAccount> accounts = contact.details<QContactOnlineAccount>(); | 2118 | if(cDetails.size() == 0) { |
2403 | 1687 | if(!accounts.isEmpty()) { | 2119 | return details; |
2404 | 1688 | QMultiMap<QString, QString> providerUidMap; | 2120 | } |
2405 | 1689 | 2121 | ||
2406 | 1690 | Q_FOREACH(const QContactOnlineAccount &account, accounts) { | 2122 | QMultiMap<QString, QString> providerUidMap; |
2407 | 1691 | if (!account.isEmpty()) { | 2123 | Q_FOREACH(const QContactDetail &detail, cDetails) { |
2408 | 1692 | providerUidMap.insert(onlineAccountProtocolFromEnum(account.protocol()), account.accountUri()); | 2124 | QContactOnlineAccount account = static_cast<QContactOnlineAccount>(detail); |
2409 | 1693 | } | 2125 | if (!account.isEmpty()) { |
2410 | 1694 | } | 2126 | providerUidMap.insert(onlineAccountProtocolFromEnum(account.protocol()), account.accountUri()); |
2411 | 1695 | 2127 | } | |
2412 | 1696 | if(!providerUidMap.isEmpty()) { | 2128 | } |
2413 | 1697 | //TODO: add account type and subtype | 2129 | |
2414 | 1698 | value = QIndividualUtils::asvSetStrNew(providerUidMap); | 2130 | if(!providerUidMap.isEmpty()) { |
2415 | 1699 | QIndividualUtils::personaDetailsInsert(details, FOLKS_PERSONA_DETAIL_IM_ADDRESSES, value); | 2131 | //TODO: add account type and subtype |
2416 | 1700 | } | 2132 | GValue *value = QIndividualUtils::asvSetStrNew(providerUidMap); |
2417 | 1701 | } | 2133 | QIndividualUtils::personaDetailsInsert(details, FOLKS_PERSONA_DETAIL_IM_ADDRESSES, value); |
2418 | 1702 | 2134 | } | |
2419 | 1703 | /* | 2135 | |
2420 | 1704 | * Organization | 2136 | return details; |
2421 | 1705 | */ | 2137 | } |
2422 | 1706 | QList<QContactOrganization> orgs = contact.details<QContactOrganization>(); | 2138 | |
2423 | 1707 | if(orgs.size() > 0) { | 2139 | GHashTable *QIndividual::parseOrganizationDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails) |
2424 | 1708 | value = QIndividualUtils::gValueSliceNew(G_TYPE_OBJECT); | 2140 | { |
2425 | 1709 | Q_FOREACH(const QContactOrganization& org, orgs) { | 2141 | if(cDetails.size() == 0) { |
2426 | 1710 | if(!org.isEmpty()) { | 2142 | return details; |
2427 | 1711 | FolksRole *role = folks_role_new(org.title().toUtf8().data(), | 2143 | } |
2428 | 1712 | org.name().toUtf8().data(), | 2144 | |
2429 | 1713 | NULL); | 2145 | GValue *value = QIndividualUtils::gValueSliceNew(G_TYPE_OBJECT); |
2430 | 1714 | folks_role_set_role(role, org.role().toUtf8().data()); | 2146 | Q_FOREACH(const QContactDetail& detail, cDetails) { |
2431 | 1715 | 2147 | QContactOrganization org = static_cast<QContactOrganization>(detail); | |
2432 | 1716 | GeeCollection *collection = (GeeCollection*) g_value_get_object(value); | 2148 | if(!org.isEmpty()) { |
2433 | 1717 | if(collection == NULL) { | 2149 | FolksRole *role = folks_role_new(org.title().toUtf8().data(), |
2434 | 1718 | collection = GEE_COLLECTION(SET_AFD_NEW()); | 2150 | org.name().toUtf8().data(), |
2435 | 1719 | g_value_take_object(value, collection); | 2151 | NULL); |
2436 | 1720 | } | 2152 | folks_role_set_role(role, org.role().toUtf8().data()); |
2437 | 1721 | FolksRoleFieldDetails *rfd = folks_role_field_details_new(role, NULL); | 2153 | |
2438 | 1722 | parseContext(FOLKS_ABSTRACT_FIELD_DETAILS(rfd), org); | 2154 | GeeCollection *collection = (GeeCollection*) g_value_get_object(value); |
2439 | 1723 | gee_collection_add(collection, rfd); | 2155 | if(collection == NULL) { |
2440 | 1724 | 2156 | collection = GEE_COLLECTION(SET_AFD_NEW()); | |
2441 | 1725 | g_object_unref(rfd); | 2157 | g_value_take_object(value, collection); |
2442 | 1726 | g_object_unref(role); | 2158 | } |
2443 | 1727 | } | 2159 | FolksRoleFieldDetails *rfd = folks_role_field_details_new(role, NULL); |
2444 | 1728 | } | 2160 | parseContext(FOLKS_ABSTRACT_FIELD_DETAILS(rfd), org); |
2445 | 1729 | QIndividualUtils::personaDetailsInsert(details, FOLKS_PERSONA_DETAIL_ROLES, value); | 2161 | gee_collection_add(collection, rfd); |
2446 | 1730 | } | 2162 | |
2447 | 1731 | 2163 | g_object_unref(rfd); | |
2448 | 1732 | /* | 2164 | g_object_unref(role); |
2449 | 1733 | * Phone Numbers | 2165 | } |
2450 | 1734 | */ | 2166 | } |
2451 | 1735 | QList<QContactPhoneNumber> phones = contact.details<QContactPhoneNumber>(); | 2167 | QIndividualUtils::personaDetailsInsert(details, FOLKS_PERSONA_DETAIL_ROLES, value); |
2452 | 1736 | if (phones.size() > 0) { | 2168 | |
2453 | 1737 | value = QIndividualUtils::gValueSliceNew(G_TYPE_OBJECT); | 2169 | return details; |
2454 | 1738 | Q_FOREACH(const QContactPhoneNumber &phone, phones) { | 2170 | } |
2455 | 1739 | if(!phone.isEmpty()) { | 2171 | |
2456 | 1740 | QIndividualUtils::gValueGeeSetAddStringFieldDetails(value, | 2172 | GHashTable *QIndividual::parsePhoneNumbersDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails) |
2457 | 1741 | FOLKS_TYPE_PHONE_FIELD_DETAILS, | 2173 | { |
2458 | 1742 | phone.number().toUtf8().data(), | 2174 | if(cDetails.size() == 0) { |
2459 | 1743 | phone); | 2175 | return details; |
2460 | 1744 | } | 2176 | } |
2461 | 1745 | } | 2177 | |
2462 | 1746 | QIndividualUtils::personaDetailsInsert(details, FOLKS_PERSONA_DETAIL_PHONE_NUMBERS, value); | 2178 | GValue *value = QIndividualUtils::gValueSliceNew(G_TYPE_OBJECT); |
2463 | 1747 | } | 2179 | Q_FOREACH(const QContactDetail &detail, cDetails) { |
2464 | 1748 | 2180 | QContactPhoneNumber phone = static_cast<QContactPhoneNumber>(detail); | |
2465 | 1749 | /* | 2181 | if(!phone.isEmpty()) { |
2466 | 1750 | * URLs | 2182 | QIndividualUtils::gValueGeeSetAddStringFieldDetails(value, |
2467 | 1751 | */ | 2183 | FOLKS_TYPE_PHONE_FIELD_DETAILS, |
2468 | 1752 | PERSONA_DETAILS_INSERT_STRING_FIELD_DETAILS(details, | 2184 | phone.number().toUtf8().data(), |
2469 | 2185 | phone); | ||
2470 | 2186 | } | ||
2471 | 2187 | } | ||
2472 | 2188 | QIndividualUtils::personaDetailsInsert(details, FOLKS_PERSONA_DETAIL_PHONE_NUMBERS, value); | ||
2473 | 2189 | |||
2474 | 2190 | return details; | ||
2475 | 2191 | } | ||
2476 | 2192 | |||
2477 | 2193 | GHashTable *QIndividual::parseUrlDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails) | ||
2478 | 2194 | { | ||
2479 | 2195 | if(cDetails.size() == 0) { | ||
2480 | 2196 | return details; | ||
2481 | 2197 | } | ||
2482 | 2198 | |||
2483 | 2199 | GValue *value; | ||
2484 | 2200 | PERSONA_DETAILS_INSERT_STRING_FIELD_DETAILS(details, cDetails, | ||
2485 | 1753 | FOLKS_PERSONA_DETAIL_URLS, value, QContactUrl, | 2201 | FOLKS_PERSONA_DETAIL_URLS, value, QContactUrl, |
2486 | 1754 | FOLKS_TYPE_URL_FIELD_DETAILS, url); | 2202 | FOLKS_TYPE_URL_FIELD_DETAILS, url); |
2487 | 2203 | |||
2488 | 2204 | return details; | ||
2489 | 2205 | } | ||
2490 | 2206 | |||
2491 | 2207 | |||
2492 | 2208 | GHashTable *QIndividual::parseDetails(const QtContacts::QContact &contact) | ||
2493 | 2209 | { | ||
2494 | 2210 | GHashTable *details = g_hash_table_new_full(g_str_hash, | ||
2495 | 2211 | g_str_equal, | ||
2496 | 2212 | NULL, | ||
2497 | 2213 | (GDestroyNotify) QIndividualUtils::gValueSliceFree); | ||
2498 | 2214 | |||
2499 | 2215 | parseAddressDetails(details, contact.details(QContactAddress::Type)); | ||
2500 | 2216 | parsePhotoDetails(details, contact.details(QContactAvatar::Type)); | ||
2501 | 2217 | parseBirthdayDetails(details, contact.details(QContactBirthday::Type)); | ||
2502 | 2218 | parseEmailDetails(details, contact.details(QContactEmailAddress::Type)); | ||
2503 | 2219 | parseFavoriteDetails(details, contact.details(QContactFavorite::Type)); | ||
2504 | 2220 | parseGenderDetails(details, contact.details(QContactGender::Type)); | ||
2505 | 2221 | parseNameDetails(details, contact.details(QContactName::Type)); | ||
2506 | 2222 | parseFullNameDetails(details, contact.details(QContactDisplayLabel::Type)); | ||
2507 | 2223 | parseNicknameDetails(details, contact.details(QContactNickname::Type)); | ||
2508 | 2224 | parseNoteDetails(details, contact.details(QContactNote::Type)); | ||
2509 | 2225 | parseImDetails(details, contact.details(QContactOnlineAccount::Type)); | ||
2510 | 2226 | parseOrganizationDetails(details, contact.details(QContactOrganization::Type)); | ||
2511 | 2227 | parsePhoneNumbersDetails(details, contact.details(QContactPhoneNumber::Type)); | ||
2512 | 2228 | parseUrlDetails(details, contact.details(QContactUrl::Type)); | ||
2513 | 2229 | |||
2514 | 1755 | return details; | 2230 | return details; |
2515 | 1756 | } | 2231 | } |
2516 | 1757 | 2232 | ||
2517 | @@ -1761,29 +2236,39 @@ | |||
2518 | 1761 | { | 2236 | { |
2519 | 1762 | } | 2237 | } |
2520 | 1763 | 2238 | ||
2522 | 1764 | FolksPersona* QIndividual::primaryPersona() const | 2239 | FolksPersona* QIndividual::primaryPersona() |
2523 | 1765 | { | 2240 | { |
2526 | 1766 | if(m_individual == 0) { | 2241 | Q_ASSERT(m_individual); |
2527 | 1767 | return 0; | 2242 | |
2528 | 2243 | if (m_primaryPersona) { | ||
2529 | 2244 | return m_primaryPersona; | ||
2530 | 1768 | } | 2245 | } |
2531 | 1769 | 2246 | ||
2532 | 1770 | FolksPersona *retval = NULL; | ||
2533 | 1771 | GeeSet *personas = folks_individual_get_personas(m_individual); | 2247 | GeeSet *personas = folks_individual_get_personas(m_individual); |
2534 | 1772 | GeeIterator *iter = gee_iterable_iterator(GEE_ITERABLE(personas)); | 2248 | GeeIterator *iter = gee_iterable_iterator(GEE_ITERABLE(personas)); |
2535 | 2249 | FolksPersonaStore *primaryStore = folks_individual_aggregator_get_primary_store(m_aggregator); | ||
2536 | 1773 | 2250 | ||
2538 | 1774 | while(retval == NULL && gee_iterator_next(iter)) { | 2251 | while(m_primaryPersona == NULL && gee_iterator_next(iter)) { |
2539 | 1775 | FolksPersona *persona = FOLKS_PERSONA(gee_iterator_get(iter)); | 2252 | FolksPersona *persona = FOLKS_PERSONA(gee_iterator_get(iter)); |
2540 | 1776 | FolksPersonaStore *primaryStore = folks_individual_aggregator_get_primary_store(m_aggregator); | ||
2541 | 1777 | if(folks_persona_get_store(persona) == primaryStore) { | 2253 | if(folks_persona_get_store(persona) == primaryStore) { |
2544 | 1778 | retval = persona; | 2254 | m_primaryPersona = persona; |
2545 | 1779 | g_object_ref(retval); | 2255 | g_object_ref (persona); |
2546 | 1780 | } | 2256 | } |
2547 | 1781 | |||
2548 | 1782 | g_object_unref(persona); | 2257 | g_object_unref(persona); |
2549 | 1783 | } | 2258 | } |
2550 | 1784 | g_object_unref (iter); | 2259 | g_object_unref (iter); |
2551 | 1785 | 2260 | ||
2553 | 1786 | return retval; | 2261 | return m_primaryPersona; |
2554 | 2262 | } | ||
2555 | 2263 | |||
2556 | 2264 | QtContacts::QContactDetail QIndividual::detailFromUri(QtContacts::QContactDetail::DetailType type, const QString &uri) const | ||
2557 | 2265 | { | ||
2558 | 2266 | Q_FOREACH(QContactDetail detail, m_contact.details(type)) { | ||
2559 | 2267 | if (detail.detailUri() == uri) { | ||
2560 | 2268 | return detail; | ||
2561 | 2269 | } | ||
2562 | 2270 | } | ||
2563 | 2271 | return m_contact.detail(type); | ||
2564 | 1787 | } | 2272 | } |
2565 | 1788 | 2273 | ||
2566 | 1789 | } //namespace | 2274 | } //namespace |
2567 | 1790 | 2275 | ||
2568 | === modified file 'src/qindividual.h' | |||
2569 | --- src/qindividual.h 2013-06-11 13:00:01 +0000 | |||
2570 | +++ src/qindividual.h 2013-06-20 20:58:26 +0000 | |||
2571 | @@ -31,7 +31,7 @@ | |||
2572 | 31 | 31 | ||
2573 | 32 | namespace galera | 32 | namespace galera |
2574 | 33 | { | 33 | { |
2576 | 34 | typedef void (*UpdateDoneCB)(const QString&, void*); | 34 | typedef GHashTable* (ParseDetailsFunc)(GHashTable*, const QList<QtContacts::QContactDetail> &); |
2577 | 35 | 35 | ||
2578 | 36 | typedef QList<QtVersit::QVersitProperty> PropertyList; | 36 | typedef QList<QtVersit::QVersitProperty> PropertyList; |
2579 | 37 | class QIndividual | 37 | class QIndividual |
2580 | @@ -59,40 +59,47 @@ | |||
2581 | 59 | 59 | ||
2582 | 60 | QtContacts::QContact &contact(); | 60 | QtContacts::QContact &contact(); |
2583 | 61 | QtContacts::QContact copy(Fields fields = QIndividual::All); | 61 | QtContacts::QContact copy(Fields fields = QIndividual::All); |
2586 | 62 | bool update(const QString &vcard, UpdateDoneCB cb, void* data); | 62 | bool update(const QString &vcard, QObject *object, const QString &slot); |
2587 | 63 | bool update(const QtContacts::QContact &contact, UpdateDoneCB cb, void* data); | 63 | bool update(const QtContacts::QContact &contact, QObject *object, const QString &slot); |
2588 | 64 | FolksIndividual *individual() const; | 64 | FolksIndividual *individual() const; |
2589 | 65 | void setIndividual(FolksIndividual *individual); | ||
2590 | 65 | 66 | ||
2591 | 66 | static GHashTable *parseDetails(const QtContacts::QContact &contact); | 67 | static GHashTable *parseDetails(const QtContacts::QContact &contact); |
2592 | 67 | |||
2593 | 68 | private: | 68 | private: |
2594 | 69 | FolksIndividual *m_individual; | 69 | FolksIndividual *m_individual; |
2595 | 70 | FolksPersona *m_primaryPersona; | ||
2596 | 70 | FolksIndividualAggregator *m_aggregator; | 71 | FolksIndividualAggregator *m_aggregator; |
2597 | 71 | QtContacts::QContact m_contact; | 72 | QtContacts::QContact m_contact; |
2598 | 72 | QMap<QString, QPair<QtContacts::QContactDetail, FolksAbstractFieldDetails*> > m_fieldsMap; | 73 | QMap<QString, QPair<QtContacts::QContactDetail, FolksAbstractFieldDetails*> > m_fieldsMap; |
2600 | 73 | unsigned int m_fieldMapNextKey; | 74 | |
2601 | 74 | 75 | ||
2602 | 75 | bool fieldsContains(Fields fields, Field value) const; | 76 | bool fieldsContains(Fields fields, Field value) const; |
2603 | 76 | QList<QtVersit::QVersitProperty> parseFieldList(const QString &fieldName, GeeSet *values) const; | 77 | QList<QtVersit::QVersitProperty> parseFieldList(const QString &fieldName, GeeSet *values) const; |
2604 | 77 | QMultiHash<QString, QString> parseDetails(FolksAbstractFieldDetails *details) const; | 78 | QMultiHash<QString, QString> parseDetails(FolksAbstractFieldDetails *details) const; |
2605 | 78 | void updateContact(); | 79 | void updateContact(); |
2607 | 79 | FolksPersona *primaryPersona() const; | 80 | |
2608 | 81 | FolksPersona *primaryPersona(); | ||
2609 | 82 | QtContacts::QContactDetail detailFromUri(QtContacts::QContactDetail::DetailType type, const QString &uri) const; | ||
2610 | 80 | 83 | ||
2611 | 81 | // QContact | 84 | // QContact |
2612 | 85 | QList<QtContacts::QContactDetail> getDetails() const; | ||
2613 | 86 | void appendDetailsForPersona(QList<QtContacts::QContactDetail> *list, QtContacts::QContactDetail detail, const QString &personaIndex, bool readOnly) const; | ||
2614 | 87 | void appendDetailsForPersona(QList<QtContacts::QContactDetail> *list, QList<QtContacts::QContactDetail> details, const QString &personaIndex, bool readOnly) const; | ||
2615 | 88 | |||
2616 | 82 | QtContacts::QContactDetail getUid() const; | 89 | QtContacts::QContactDetail getUid() const; |
2617 | 83 | QList<QtContacts::QContactDetail> getClientPidMap() const; | 90 | QList<QtContacts::QContactDetail> getClientPidMap() const; |
2630 | 84 | QtContacts::QContactDetail getName() const; | 91 | QtContacts::QContactDetail getPersonaName(FolksPersona *persona) const; |
2631 | 85 | QtContacts::QContactDetail getFullName() const; | 92 | QtContacts::QContactDetail getPersonaFullName(FolksPersona *persona) const; |
2632 | 86 | QtContacts::QContactDetail getNickname() const; | 93 | QtContacts::QContactDetail getPersonaNickName(FolksPersona *persona) const; |
2633 | 87 | QtContacts::QContactDetail getBirthday() const; | 94 | QtContacts::QContactDetail getPersonaBirthday(FolksPersona *persona) const; |
2634 | 88 | QtContacts::QContactDetail getPhoto() const; | 95 | QtContacts::QContactDetail getPersonaPhoto(FolksPersona *persona) const; |
2635 | 89 | QList<QtContacts::QContactDetail> getRoles() const; | 96 | //TODO: organization |
2636 | 90 | QList<QtContacts::QContactDetail> getEmails() const; | 97 | QList<QtContacts::QContactDetail> getPersonaRoles(FolksPersona *persona) const; |
2637 | 91 | QList<QtContacts::QContactDetail> getPhones() const; | 98 | QList<QtContacts::QContactDetail> getPersonaEmails(FolksPersona *persona) const; |
2638 | 92 | QList<QtContacts::QContactDetail> getAddresses() const; | 99 | QList<QtContacts::QContactDetail> getPersonaPhones(FolksPersona *persona) const; |
2639 | 93 | QList<QtContacts::QContactDetail> getIms() const; | 100 | QList<QtContacts::QContactDetail> getPersonaAddresses(FolksPersona *persona) const; |
2640 | 94 | QtContacts::QContactDetail getTimeZone() const; | 101 | QList<QtContacts::QContactDetail> getPersonaIms(FolksPersona *persona) const; |
2641 | 95 | QList<QtContacts::QContactDetail> getUrls() const; | 102 | QList<QtContacts::QContactDetail> getPersonaUrls(FolksPersona *persona) const; |
2642 | 96 | 103 | ||
2643 | 97 | 104 | ||
2644 | 98 | // update | 105 | // update |
2645 | @@ -102,15 +109,38 @@ | |||
2646 | 102 | void updateBirthday(const QtContacts::QContactDetail &detail, void* data); | 109 | void updateBirthday(const QtContacts::QContactDetail &detail, void* data); |
2647 | 103 | void updatePhoto(const QtContacts::QContactDetail &detail, void* data); | 110 | void updatePhoto(const QtContacts::QContactDetail &detail, void* data); |
2648 | 104 | void updateTimezone(const QtContacts::QContactDetail &detail, void* data); | 111 | void updateTimezone(const QtContacts::QContactDetail &detail, void* data); |
2656 | 105 | void updateRoles(QList<QtContacts::QContactDetail> details, void* data); | 112 | void updateRole(QtContacts::QContactDetail detail, void* data); |
2657 | 106 | void updatePhones(QList<QtContacts::QContactDetail> details, void* data); | 113 | void updatePhone(QtContacts::QContactDetail detail, void* data); |
2658 | 107 | void updateEmails(QList<QtContacts::QContactDetail> details, void* data); | 114 | void updateEmail(QtContacts::QContactDetail detail, void* data); |
2659 | 108 | void updateIms(QList<QtContacts::QContactDetail> details, void* data); | 115 | void updateIm(QtContacts::QContactDetail detail, void* data); |
2660 | 109 | void updateUrls(QList<QtContacts::QContactDetail> details, void* data); | 116 | void updateUrl(QtContacts::QContactDetail details, void* data); |
2661 | 110 | void updateNotes(QList<QtContacts::QContactDetail> details, void* data); | 117 | void updateNote(QtContacts::QContactDetail detail, void* data); |
2662 | 111 | void updateAddresses(QList<QtContacts::QContactDetail> details, void* data); | 118 | void updateAddress(QtContacts::QContactDetail detail, void* data); |
2663 | 119 | void createPersonaForDetail(QList<QtContacts::QContactDetail> detail, ParseDetailsFunc parseFunc, void *data) const; | ||
2664 | 120 | |||
2665 | 121 | static void createPersonaDone(GObject *detail, GAsyncResult *result, gpointer userdata); | ||
2666 | 112 | static void updateDetailsDone(GObject *detail, GAsyncResult *result, gpointer userdata); | 122 | static void updateDetailsDone(GObject *detail, GAsyncResult *result, gpointer userdata); |
2668 | 113 | static bool detailListIsEqual(QList<QtContacts::QContactDetail> original, QList<QtContacts::QContactDetail> details); | 123 | static void updateDetailsSendReply(gpointer userdata, GError *error); |
2669 | 124 | static void updateDetailsSendReply(gpointer userdata, const QString &errorMessage); | ||
2670 | 125 | static QString callDetailChangeFinish(QtContacts::QContactDetail::DetailType type, FolksPersona *persona, GAsyncResult *result); | ||
2671 | 126 | //static bool detailListIsEqual(QList<QtContacts::QContactDetail> original, QList<QtContacts::QContactDetail> details); | ||
2672 | 127 | |||
2673 | 128 | // translate details | ||
2674 | 129 | static GHashTable *parseAddressDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails); | ||
2675 | 130 | static GHashTable *parsePhotoDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails); | ||
2676 | 131 | static GHashTable *parsePhoneNumbersDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails); | ||
2677 | 132 | static GHashTable *parseOrganizationDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails); | ||
2678 | 133 | static GHashTable *parseImDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails); | ||
2679 | 134 | static GHashTable *parseNoteDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails); | ||
2680 | 135 | static GHashTable *parseFullNameDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails); | ||
2681 | 136 | static GHashTable *parseNicknameDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails); | ||
2682 | 137 | static GHashTable *parseNameDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails); | ||
2683 | 138 | static GHashTable *parseGenderDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails); | ||
2684 | 139 | static GHashTable *parseFavoriteDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails); | ||
2685 | 140 | static GHashTable *parseEmailDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails); | ||
2686 | 141 | static GHashTable *parseBirthdayDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails); | ||
2687 | 142 | static GHashTable *parseUrlDetails(GHashTable *details, const QList<QtContacts::QContactDetail> &cDetails); | ||
2688 | 143 | |||
2689 | 114 | 144 | ||
2690 | 115 | // parse context and parameters | 145 | // parse context and parameters |
2691 | 116 | static void parseParameters(QtContacts::QContactDetail &detail, FolksAbstractFieldDetails *fd); | 146 | static void parseParameters(QtContacts::QContactDetail &detail, FolksAbstractFieldDetails *fd); |
2692 | 117 | 147 | ||
2693 | === modified file 'src/view-adaptor.h' | |||
2694 | --- src/view-adaptor.h 2013-06-13 14:00:42 +0000 | |||
2695 | +++ src/view-adaptor.h 2013-06-20 20:58:26 +0000 | |||
2696 | @@ -45,7 +45,7 @@ | |||
2697 | 45 | " <arg direction=\"out\" type=\"i\" name=\"pos\"/>\n" | 45 | " <arg direction=\"out\" type=\"i\" name=\"pos\"/>\n" |
2698 | 46 | " <arg direction=\"out\" type=\"i\" name=\"lenght\"/>\n" | 46 | " <arg direction=\"out\" type=\"i\" name=\"lenght\"/>\n" |
2699 | 47 | " </signal>\n" | 47 | " </signal>\n" |
2701 | 48 | " <signal name=\"contactsCreated\">\n" | 48 | " <signal name=\"contactsAdded\">\n" |
2702 | 49 | " <arg direction=\"out\" type=\"i\" name=\"pos\"/>\n" | 49 | " <arg direction=\"out\" type=\"i\" name=\"pos\"/>\n" |
2703 | 50 | " <arg direction=\"out\" type=\"i\" name=\"lenght\"/>\n" | 50 | " <arg direction=\"out\" type=\"i\" name=\"lenght\"/>\n" |
2704 | 51 | " </signal>\n" | 51 | " </signal>\n" |
2705 | @@ -81,7 +81,7 @@ | |||
2706 | 81 | void close(); | 81 | void close(); |
2707 | 82 | 82 | ||
2708 | 83 | Q_SIGNALS: | 83 | Q_SIGNALS: |
2710 | 84 | void contactsCreated(int pos, int lenght); | 84 | void contactsAdded(int pos, int lenght); |
2711 | 85 | void contactsRemoved(int pos, int lenght); | 85 | void contactsRemoved(int pos, int lenght); |
2712 | 86 | void contactsUpdated(int pos, int lenght); | 86 | void contactsUpdated(int pos, int lenght); |
2713 | 87 | 87 | ||
2714 | 88 | 88 | ||
2715 | === modified file 'src/view.cpp' | |||
2716 | --- src/view.cpp 2013-06-13 14:35:08 +0000 | |||
2717 | +++ src/view.cpp 2013-06-20 20:58:26 +0000 | |||
2718 | @@ -166,6 +166,11 @@ | |||
2719 | 166 | } | 166 | } |
2720 | 167 | 167 | ||
2721 | 168 | QStringList ret = VCardParser::contactToVcard(contacts); | 168 | QStringList ret = VCardParser::contactToVcard(contacts); |
2722 | 169 | qDebug() << "fetch" << ret; | ||
2723 | 170 | QList<QContact> cs = VCardParser::vcardToContact(ret); | ||
2724 | 171 | QStringList ret2 = VCardParser::contactToVcard(cs); | ||
2725 | 172 | qDebug() << "fetch2" << ret2; | ||
2726 | 173 | |||
2727 | 169 | QDBusMessage reply = message.createReply(ret); | 174 | QDBusMessage reply = message.createReply(ret); |
2728 | 170 | QDBusConnection::sessionBus().send(reply); | 175 | QDBusConnection::sessionBus().send(reply); |
2729 | 171 | return ret; | 176 | return ret; |
FAILED: Continuous integration, rev:34 jenkins. qa.ubuntu. com/job/ address- book-service- ci/19/ jenkins. qa.ubuntu. com/job/ address- book-service- saucy-amd64- ci/19/console jenkins. qa.ubuntu. com/job/ address- book-service- saucy-armhf- ci/19/console jenkins. qa.ubuntu. com/job/ address- book-service- saucy-i386- ci/19/console
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild: s-jenkins: 8080/job/ address- book-service- ci/19/rebuild
http://