Changeset View
Changeset View
Standalone View
Standalone View
src/contacts/contactmodifyjob.cpp
Show All 35 Lines | |||||
36 | 36 | | |||
37 | using namespace KGAPI2; | 37 | using namespace KGAPI2; | ||
38 | 38 | | |||
39 | class Q_DECL_HIDDEN ContactModifyJob::Private | 39 | class Q_DECL_HIDDEN ContactModifyJob::Private | ||
40 | { | 40 | { | ||
41 | public: | 41 | public: | ||
42 | Private(ContactModifyJob *parent); | 42 | Private(ContactModifyJob *parent); | ||
43 | void processNextContact(); | 43 | void processNextContact(); | ||
44 | void updatePhoto(const ContactPtr &contact); | ||||
44 | 45 | | |||
45 | QueueHelper<ContactPtr> contacts; | 46 | QueueHelper<ContactPtr> contacts; | ||
46 | ContactPtr lastContact; | 47 | ContactPtr lastContact; | ||
47 | QPair<QByteArray, QString> pendingPhoto; | 48 | QPair<QByteArray, QString> pendingPhoto; | ||
48 | private: | 49 | private: | ||
49 | ContactModifyJob *q; | 50 | ContactModifyJob *q; | ||
50 | }; | 51 | }; | ||
51 | 52 | | |||
Show All 27 Lines | 59 | { | |||
79 | QStringList headers; | 80 | QStringList headers; | ||
80 | auto rawHeaderList = request.rawHeaderList(); | 81 | auto rawHeaderList = request.rawHeaderList(); | ||
81 | headers.reserve(rawHeaderList.size()); | 82 | headers.reserve(rawHeaderList.size()); | ||
82 | for (const QByteArray &str : qAsConst(rawHeaderList)) { | 83 | for (const QByteArray &str : qAsConst(rawHeaderList)) { | ||
83 | headers << QLatin1String(str) + QLatin1String(": ") + QLatin1String(request.rawHeader(str)); | 84 | headers << QLatin1String(str) + QLatin1String(": ") + QLatin1String(request.rawHeader(str)); | ||
84 | } | 85 | } | ||
85 | 86 | | |||
86 | q->enqueueRequest(request, rawData, QStringLiteral("application/atom+xml")); | 87 | q->enqueueRequest(request, rawData, QStringLiteral("application/atom+xml")); | ||
88 | } | ||||
87 | 89 | | |||
90 | void ContactModifyJob::Private::updatePhoto(const ContactPtr &contact) | ||||
91 | { | ||||
88 | const QUrl photoUrl = ContactsService::photoUrl(q->account()->accountName(), contact->uid()); | 92 | const QUrl photoUrl = ContactsService::photoUrl(q->account()->accountName(), contact->uid()); | ||
89 | QNetworkRequest photoRequest(photoUrl); | 93 | QNetworkRequest photoRequest(photoUrl); | ||
90 | if (!contact->photo().isEmpty()) { | 94 | if (!contact->photo().isEmpty()) { | ||
91 | photoRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("image/*")); | 95 | photoRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("image/*")); | ||
92 | pendingPhoto.first = contact->photo().rawData(); | 96 | pendingPhoto.first = contact->photo().rawData(); | ||
93 | pendingPhoto.second = contact->photo().type(); | 97 | pendingPhoto.second = contact->photo().type(); | ||
94 | q->enqueueRequest(photoRequest, pendingPhoto.first, QStringLiteral("modifyImage")); | 98 | q->enqueueRequest(photoRequest, pendingPhoto.first, QStringLiteral("modifyImage")); | ||
95 | } else { | 99 | } else { | ||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | |||||
149 | { | 153 | { | ||
150 | ObjectsList items; | 154 | ObjectsList items; | ||
151 | if (!reply->url().path().contains(QLatin1String("/photos/media/"))) { | 155 | if (!reply->url().path().contains(QLatin1String("/photos/media/"))) { | ||
152 | const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString(); | 156 | const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString(); | ||
153 | ContentType ct = Utils::stringToContentType(contentType); | 157 | ContentType ct = Utils::stringToContentType(contentType); | ||
154 | if (ct == KGAPI2::JSON) { | 158 | if (ct == KGAPI2::JSON) { | ||
155 | d->lastContact = ContactsService::JSONToContact(rawData); | 159 | d->lastContact = ContactsService::JSONToContact(rawData); | ||
156 | items << d->lastContact; | 160 | items << d->lastContact; | ||
157 | d->contacts.currentProcessed(); | | |||
158 | } else if (ct == KGAPI2::XML) { | 161 | } else if (ct == KGAPI2::XML) { | ||
159 | d->lastContact = ContactsService::XMLToContact(rawData); | 162 | d->lastContact = ContactsService::XMLToContact(rawData); | ||
160 | items << d->lastContact; | 163 | items << d->lastContact; | ||
161 | d->contacts.currentProcessed(); | | |||
162 | } else { | 164 | } else { | ||
163 | setError(KGAPI2::InvalidResponse); | 165 | setError(KGAPI2::InvalidResponse); | ||
164 | setErrorString(tr("Invalid response content type")); | 166 | setErrorString(tr("Invalid response content type")); | ||
165 | emitFinished(); | 167 | emitFinished(); | ||
166 | return items; | 168 | return items; | ||
167 | } | 169 | } | ||
170 | d->updatePhoto(d->contacts.current()); | ||||
171 | d->contacts.currentProcessed(); | ||||
168 | } else { | 172 | } else { | ||
169 | if (d->lastContact && !d->pendingPhoto.first.isEmpty()) { | 173 | if (d->lastContact && !d->pendingPhoto.first.isEmpty()) { | ||
170 | KContacts::Picture picture; | 174 | KContacts::Picture picture; | ||
171 | picture.setRawData(d->pendingPhoto.first, d->pendingPhoto.second); | 175 | picture.setRawData(d->pendingPhoto.first, d->pendingPhoto.second); | ||
172 | d->lastContact->setPhoto(picture); | 176 | d->lastContact->setPhoto(picture); | ||
173 | d->pendingPhoto.first.clear(); | 177 | d->pendingPhoto.first.clear(); | ||
174 | d->pendingPhoto.second.clear(); | 178 | d->pendingPhoto.second.clear(); | ||
175 | } | 179 | } | ||
176 | 180 | | |||
177 | // Enqueue next item and picture or finish | 181 | // Enqueue next item and picture or finish | ||
dvratil: Please move the code to a new function (e.g. `Private::updatePhoto(const ContactPtr &contact)`) | |||||
178 | d->processNextContact(); | 182 | d->processNextContact(); | ||
179 | } | 183 | } | ||
180 | 184 | | |||
181 | return items; | 185 | return items; | ||
182 | } | 186 | } | ||
183 | 187 | | |||
184 | 188 | |
Please move the code to a new function (e.g. Private::updatePhoto(const ContactPtr &contact))