Changeset View
Changeset View
Standalone View
Standalone View
src/calendar/eventfetchjob.cpp
Show All 33 Lines | |||||
34 | using namespace KGAPI2; | 34 | using namespace KGAPI2; | ||
35 | 35 | | |||
36 | class Q_DECL_HIDDEN EventFetchJob::Private | 36 | class Q_DECL_HIDDEN EventFetchJob::Private | ||
37 | { | 37 | { | ||
38 | public: | 38 | public: | ||
39 | QString calendarId; | 39 | QString calendarId; | ||
40 | QString eventId; | 40 | QString eventId; | ||
41 | QString filter; | 41 | QString filter; | ||
42 | QString syncToken; | ||||
42 | bool fetchDeleted = true; | 43 | bool fetchDeleted = true; | ||
43 | quint64 updatedTimestamp = 0; | 44 | quint64 updatedTimestamp = 0; | ||
44 | quint64 timeMin = 0; | 45 | quint64 timeMin = 0; | ||
45 | quint64 timeMax = 0; | 46 | quint64 timeMax = 0; | ||
46 | }; | 47 | }; | ||
47 | 48 | | |||
48 | EventFetchJob::EventFetchJob(const QString& calendarId, const AccountPtr& account, QObject* parent): | 49 | EventFetchJob::EventFetchJob(const QString& calendarId, const AccountPtr& account, QObject* parent): | ||
49 | FetchJob(account, parent), | 50 | FetchJob(account, parent), | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 97 | { | |||
102 | d->timeMax = timestamp; | 103 | d->timeMax = timestamp; | ||
103 | } | 104 | } | ||
104 | 105 | | |||
105 | quint64 EventFetchJob::timeMax() const | 106 | quint64 EventFetchJob::timeMax() const | ||
106 | { | 107 | { | ||
107 | return d->timeMax; | 108 | return d->timeMax; | ||
108 | } | 109 | } | ||
109 | 110 | | |||
111 | void EventFetchJob::setSyncToken(const QString& syncToken) | ||||
112 | { | ||||
113 | d->syncToken = syncToken; | ||||
114 | } | ||||
115 | | ||||
116 | QString EventFetchJob::syncToken() | ||||
117 | { | ||||
118 | return d->syncToken; | ||||
119 | } | ||||
120 | | ||||
110 | void EventFetchJob::setTimeMin(quint64 timestamp) | 121 | void EventFetchJob::setTimeMin(quint64 timestamp) | ||
111 | { | 122 | { | ||
112 | if (isRunning()) { | 123 | if (isRunning()) { | ||
113 | qCWarning(KGAPIDebug) << "Can't modify timeMin property when job is running"; | 124 | qCWarning(KGAPIDebug) << "Can't modify timeMin property when job is running"; | ||
114 | return; | 125 | return; | ||
115 | } | 126 | } | ||
116 | 127 | | |||
117 | d->timeMin = timestamp; | 128 | d->timeMin = timestamp; | ||
Show All 24 Lines | 152 | { | |||
142 | QUrl url; | 153 | QUrl url; | ||
143 | if (d->eventId.isEmpty()) { | 154 | if (d->eventId.isEmpty()) { | ||
144 | url = CalendarService::fetchEventsUrl(d->calendarId); | 155 | url = CalendarService::fetchEventsUrl(d->calendarId); | ||
145 | QUrlQuery query(url); | 156 | QUrlQuery query(url); | ||
146 | query.addQueryItem(QStringLiteral("showDeleted"), Utils::bool2Str(d->fetchDeleted)); | 157 | query.addQueryItem(QStringLiteral("showDeleted"), Utils::bool2Str(d->fetchDeleted)); | ||
147 | if (!d->filter.isEmpty()) { | 158 | if (!d->filter.isEmpty()) { | ||
148 | query.addQueryItem(QStringLiteral("q"), d->filter); | 159 | query.addQueryItem(QStringLiteral("q"), d->filter); | ||
149 | } | 160 | } | ||
161 | if (d->syncToken.isEmpty()) { | ||||
150 | if (d->updatedTimestamp > 0) { | 162 | if (d->updatedTimestamp > 0) { | ||
151 | query.addQueryItem(QStringLiteral("updatedMin"), Utils::ts2Str(d->updatedTimestamp)); | 163 | query.addQueryItem(QStringLiteral("updatedMin"), Utils::ts2Str(d->updatedTimestamp)); | ||
152 | } | 164 | } | ||
153 | if (d->timeMin > 0) { | 165 | if (d->timeMin > 0) { | ||
154 | query.addQueryItem(QStringLiteral("timeMin"), Utils::ts2Str(d->timeMin)); | 166 | query.addQueryItem(QStringLiteral("timeMin"), Utils::ts2Str(d->timeMin)); | ||
155 | } | 167 | } | ||
156 | if (d->timeMax > 0) { | 168 | if (d->timeMax > 0) { | ||
157 | query.addQueryItem(QStringLiteral("timeMax"), Utils::ts2Str(d->timeMax)); | 169 | query.addQueryItem(QStringLiteral("timeMax"), Utils::ts2Str(d->timeMax)); | ||
158 | } | 170 | } | ||
171 | } else { | ||||
172 | query.addQueryItem(QStringLiteral("syncToken"), d->syncToken); | ||||
173 | } | ||||
159 | url.setQuery(query); | 174 | url.setQuery(query); | ||
160 | } else { | 175 | } else { | ||
161 | url = CalendarService::fetchEventUrl(d->calendarId, d->eventId); | 176 | url = CalendarService::fetchEventUrl(d->calendarId, d->eventId); | ||
162 | } | 177 | } | ||
163 | const QNetworkRequest request = CalendarService::prepareRequest(url); | 178 | const QNetworkRequest request = CalendarService::prepareRequest(url); | ||
164 | enqueueRequest(request); | 179 | enqueueRequest(request); | ||
165 | } | 180 | } | ||
166 | 181 | | |||
167 | ObjectsList EventFetchJob::handleReplyWithItems(const QNetworkReply *reply, const QByteArray& rawData) | 182 | ObjectsList EventFetchJob::handleReplyWithItems(const QNetworkReply *reply, const QByteArray& rawData) | ||
168 | { | 183 | { | ||
169 | if (reply->error() == QNetworkReply::ContentGoneError | 184 | if (reply->error() == QNetworkReply::ContentGoneError | ||
170 | || reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == Gone) { | 185 | || reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == Gone) { | ||
171 | // Full sync required by server, redo request with no updatedMin | 186 | // Full sync required by server, redo request with no updatedMin and no syncToken | ||
172 | d->updatedTimestamp = 0; | 187 | d->updatedTimestamp = 0; | ||
188 | d->syncToken.clear(); | ||||
dvratil: Use `d->syncToken.clear()` | |||||
173 | start(); | 189 | start(); | ||
174 | // Errors are not cleared on success | 190 | // Errors are not cleared on success | ||
175 | // Do it here or else the job will fail | 191 | // Do it here or else the job will fail | ||
176 | setError(KGAPI2::NoError); | 192 | setError(KGAPI2::NoError); | ||
177 | setErrorString(QString()); | 193 | setErrorString(QString()); | ||
178 | return ObjectsList(); | 194 | return ObjectsList(); | ||
179 | } | 195 | } | ||
180 | 196 | | |||
181 | FeedData feedData; | 197 | FeedData feedData; | ||
182 | feedData.requestUrl = reply->url(); | 198 | feedData.requestUrl = reply->url(); | ||
183 | ObjectsList items; | 199 | ObjectsList items; | ||
184 | const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString(); | 200 | const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString(); | ||
185 | ContentType ct = Utils::stringToContentType(contentType); | 201 | ContentType ct = Utils::stringToContentType(contentType); | ||
186 | if (ct == KGAPI2::JSON) { | 202 | if (ct == KGAPI2::JSON) { | ||
187 | if (d->eventId.isEmpty()) { | 203 | if (d->eventId.isEmpty()) { | ||
188 | items = CalendarService::parseEventJSONFeed(rawData, feedData); | 204 | items = CalendarService::parseEventJSONFeed(rawData, feedData); | ||
189 | } else { | 205 | } else { | ||
190 | items << CalendarService::JSONToEvent(rawData).dynamicCast<Object>(); | 206 | items << CalendarService::JSONToEvent(rawData).dynamicCast<Object>(); | ||
191 | } | 207 | } | ||
208 | d->syncToken = feedData.syncToken; | ||||
192 | } else { | 209 | } else { | ||
193 | setError(KGAPI2::InvalidResponse); | 210 | setError(KGAPI2::InvalidResponse); | ||
194 | setErrorString(tr("Invalid response content type")); | 211 | setErrorString(tr("Invalid response content type")); | ||
195 | emitFinished(); | 212 | emitFinished(); | ||
196 | return items; | 213 | return items; | ||
197 | } | 214 | } | ||
198 | 215 | | |||
199 | if (feedData.nextPageUrl.isValid()) { | 216 | if (feedData.nextPageUrl.isValid()) { | ||
200 | const auto request = CalendarService::prepareRequest(feedData.nextPageUrl); | 217 | const auto request = CalendarService::prepareRequest(feedData.nextPageUrl); | ||
201 | enqueueRequest(request); | 218 | enqueueRequest(request); | ||
202 | } | 219 | } | ||
203 | 220 | | |||
204 | return items; | 221 | return items; | ||
205 | } | 222 | } | ||
206 | 223 | | |||
207 | 224 | |
Use d->syncToken.clear()