Changeset View
Changeset View
Standalone View
Standalone View
src/contacts/contactmodifyjob.cpp
Show First 20 Lines • Show All 78 Lines • ▼ Show 20 Line(s) | 58 | { | |||
---|---|---|---|---|---|
79 | QStringList headers; | 79 | QStringList headers; | ||
80 | auto rawHeaderList = request.rawHeaderList(); | 80 | auto rawHeaderList = request.rawHeaderList(); | ||
81 | headers.reserve(rawHeaderList.size()); | 81 | headers.reserve(rawHeaderList.size()); | ||
82 | for (const QByteArray &str : qAsConst(rawHeaderList)) { | 82 | for (const QByteArray &str : qAsConst(rawHeaderList)) { | ||
83 | headers << QLatin1String(str) + QLatin1String(": ") + QLatin1String(request.rawHeader(str)); | 83 | headers << QLatin1String(str) + QLatin1String(": ") + QLatin1String(request.rawHeader(str)); | ||
84 | } | 84 | } | ||
85 | 85 | | |||
86 | q->enqueueRequest(request, rawData, QStringLiteral("application/atom+xml")); | 86 | q->enqueueRequest(request, rawData, QStringLiteral("application/atom+xml")); | ||
87 | | ||||
88 | const QUrl photoUrl = ContactsService::photoUrl(q->account()->accountName(), contact->uid()); | | |||
89 | QNetworkRequest photoRequest(photoUrl); | | |||
90 | if (!contact->photo().isEmpty()) { | | |||
91 | photoRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("image/*")); | | |||
92 | pendingPhoto.first = contact->photo().rawData(); | | |||
93 | pendingPhoto.second = contact->photo().type(); | | |||
94 | q->enqueueRequest(photoRequest, pendingPhoto.first, QStringLiteral("modifyImage")); | | |||
95 | } else { | | |||
96 | q->enqueueRequest(photoRequest, QByteArray(), QStringLiteral("deleteImage")); | | |||
97 | } | | |||
98 | } | 87 | } | ||
99 | 88 | | |||
100 | 89 | | |||
101 | ContactModifyJob::ContactModifyJob(const ContactsList& contacts, const AccountPtr& account, QObject* parent): | 90 | ContactModifyJob::ContactModifyJob(const ContactsList& contacts, const AccountPtr& account, QObject* parent): | ||
102 | ModifyJob(account, parent), | 91 | ModifyJob(account, parent), | ||
103 | d(new Private(this)) | 92 | d(new Private(this)) | ||
104 | { | 93 | { | ||
105 | d->contacts = contacts; | 94 | d->contacts = contacts; | ||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
149 | { | 138 | { | ||
150 | ObjectsList items; | 139 | ObjectsList items; | ||
151 | if (!reply->url().path().contains(QLatin1String("/photos/media/"))) { | 140 | if (!reply->url().path().contains(QLatin1String("/photos/media/"))) { | ||
152 | const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString(); | 141 | const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString(); | ||
153 | ContentType ct = Utils::stringToContentType(contentType); | 142 | ContentType ct = Utils::stringToContentType(contentType); | ||
154 | if (ct == KGAPI2::JSON) { | 143 | if (ct == KGAPI2::JSON) { | ||
155 | d->lastContact = ContactsService::JSONToContact(rawData); | 144 | d->lastContact = ContactsService::JSONToContact(rawData); | ||
156 | items << d->lastContact; | 145 | items << d->lastContact; | ||
157 | d->contacts.currentProcessed(); | | |||
158 | } else if (ct == KGAPI2::XML) { | 146 | } else if (ct == KGAPI2::XML) { | ||
159 | d->lastContact = ContactsService::XMLToContact(rawData); | 147 | d->lastContact = ContactsService::XMLToContact(rawData); | ||
160 | items << d->lastContact; | 148 | items << d->lastContact; | ||
161 | d->contacts.currentProcessed(); | | |||
162 | } else { | 149 | } else { | ||
163 | setError(KGAPI2::InvalidResponse); | 150 | setError(KGAPI2::InvalidResponse); | ||
164 | setErrorString(tr("Invalid response content type")); | 151 | setErrorString(tr("Invalid response content type")); | ||
165 | emitFinished(); | 152 | emitFinished(); | ||
166 | return items; | 153 | return items; | ||
167 | } | 154 | } | ||
155 | ContactPtr contact = d->contacts.current(); | ||||
156 | const QUrl photoUrl = ContactsService::photoUrl(account()->accountName(), contact->uid()); | ||||
157 | QNetworkRequest photoRequest(photoUrl); | ||||
158 | if (!contact->photo().isEmpty()) { | ||||
159 | photoRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("image/*")); | ||||
160 | d->pendingPhoto.first = contact->photo().rawData(); | ||||
161 | d->pendingPhoto.second = contact->photo().type(); | ||||
162 | enqueueRequest(photoRequest, d->pendingPhoto.first, QStringLiteral("modifyImage")); | ||||
163 | } else { | ||||
164 | enqueueRequest(photoRequest, QByteArray(), QStringLiteral("deleteImage")); | ||||
165 | } | ||||
166 | d->contacts.currentProcessed(); | ||||
dvratil: Please move the code to a new function (e.g. `Private::updatePhoto(const ContactPtr &contact)`) | |||||
168 | } else { | 167 | } else { | ||
169 | if (d->lastContact && !d->pendingPhoto.first.isEmpty()) { | 168 | if (d->lastContact && !d->pendingPhoto.first.isEmpty()) { | ||
170 | KContacts::Picture picture; | 169 | KContacts::Picture picture; | ||
171 | picture.setRawData(d->pendingPhoto.first, d->pendingPhoto.second); | 170 | picture.setRawData(d->pendingPhoto.first, d->pendingPhoto.second); | ||
172 | d->lastContact->setPhoto(picture); | 171 | d->lastContact->setPhoto(picture); | ||
173 | d->pendingPhoto.first.clear(); | 172 | d->pendingPhoto.first.clear(); | ||
174 | d->pendingPhoto.second.clear(); | 173 | d->pendingPhoto.second.clear(); | ||
175 | } | 174 | } | ||
Show All 9 Lines |
Please move the code to a new function (e.g. Private::updatePhoto(const ContactPtr &contact))