Kgapi

locationfetchhistoryjob.cpp
1/*
2 * This file is part of LibKGAPI library
3 *
4 * SPDX-FileCopyrightText: 2013 Daniel Vrátil <dvratil@redhat.com>
5 *
6 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8
9#include "locationfetchhistoryjob.h"
10#include "debug.h"
11#include "latitudeservice.h"
12#include "utils.h"
13
14#include <QNetworkReply>
15#include <QNetworkRequest>
16
17using namespace KGAPI2;
18
19class Q_DECL_HIDDEN LocationFetchHistoryJob::Private
20{
21public:
22 Private(LocationFetchHistoryJob *parent);
23 QNetworkRequest createRequest(const QUrl &url);
24
25 Latitude::Granularity granularity = Latitude::City;
26 int maxResults = 0;
27 qlonglong minTimestamp = 0;
28 qlonglong maxTimestamp = 0;
29
30private:
32};
33
34LocationFetchHistoryJob::Private::Private(LocationFetchHistoryJob *parent)
35 : q(parent)
36{
37}
38
39QNetworkRequest LocationFetchHistoryJob::Private::createRequest(const QUrl &url)
40{
41 QNetworkRequest request(url);
42 request.setRawHeader("GData-Version", LatitudeService::APIVersion().toLatin1());
43
44 return request;
45}
46
52
57
59{
60 return d->maxResults;
61}
62
64{
65 if (isRunning()) {
66 qCWarning(KGAPIDebug) << "Can't modify maxResults property while job is running";
67 }
68 d->maxResults = results;
69}
70
71Latitude::Granularity LocationFetchHistoryJob::granularity() const
72{
73 return d->granularity;
74}
75
76void LocationFetchHistoryJob::setGranularity(Latitude::Granularity granularity)
77{
78 if (isRunning()) {
79 qCWarning(KGAPIDebug) << "Can't modify maxResults property while job is running";
80 }
81 d->granularity = granularity;
82}
83
85{
86 return d->minTimestamp;
87}
88
89void LocationFetchHistoryJob::setMinTimestamp(qlonglong minTimestamp)
90{
91 if (isRunning()) {
92 qCWarning(KGAPIDebug) << "Can't modify maxResults property while job is running";
93 }
94 d->minTimestamp = minTimestamp;
95}
96
98{
99 return d->maxTimestamp;
100}
101
103{
104 if (isRunning()) {
105 qCWarning(KGAPIDebug) << "Can't modify maxResults property while job is running";
106 }
107 d->maxTimestamp = maxTimestamp;
108}
109
111{
112 const QUrl url = LatitudeService::locationHistoryUrl(d->granularity, d->maxResults, d->maxTimestamp, d->minTimestamp);
113 const QNetworkRequest request = d->createRequest(url);
114
115 enqueueRequest(request);
116}
117
119{
120 FeedData feedData;
121 const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
122 ContentType ct = Utils::stringToContentType(contentType);
124 if (ct == KGAPI2::JSON) {
125 items << LatitudeService::parseLocationJSONFeed(rawData, feedData);
126 } else {
128 setErrorString(tr("Invalid response content type"));
129 emitFinished();
130 }
131
132 if (feedData.nextPageUrl.isValid()) {
133 const QNetworkRequest request = d->createRequest(feedData.nextPageUrl);
134 enqueueRequest(request);
135 }
136
137 return items;
138}
139
140#include "moc_locationfetchhistoryjob.cpp"
Structure to store additional information about a feed.
Definition types.h:24
QUrl nextPageUrl
Link to next page of feed.
Definition types.h:38
Abstract superclass for all jobs that fetch resources from Google.
Definition fetchjob.h:25
virtual ObjectsList items() const
Returns all items fetched by this job.
Definition fetchjob.cpp:41
void setErrorString(const QString &errorString)
Set job error description to errorString.
Definition job.cpp:401
AccountPtr account() const
Returns account used to authenticate requests.
Definition job.cpp:436
virtual void emitFinished()
Emits Job::finished() signal.
Definition job.cpp:493
void setError(KGAPI2::Error error)
Set job error to error.
Definition job.cpp:386
virtual void enqueueRequest(const QNetworkRequest &request, const QByteArray &data=QByteArray(), const QString &contentType=QString())
Enqueues request in dispatcher queue.
Definition job.cpp:513
bool isRunning
Whether the job is running.
Definition job.h:67
A job to fetch all past locations from user's account on Google Latitude.
void setGranularity(Latitude::Granularity granularity)
Sets granularity of the requested results.
void setMinTimestamp(qlonglong minTimestamp)
Sets lower date limit for locations to fetch.
void start() override
KGAPI2::Job::start implementation.
ObjectsList handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData) override
KGAPI2::Job::handleReplyWithItems.
Latitude::Granularity granularity
Granularity of the results.
void setMaxTimestamp(qlonglong maxTimestamp)
Sets upper date limit for locations to fetch.
qlonglong minTimestamp
Oldest location to fetch.
qlonglong maxTimestamp
Newest location to fetch.
LocationFetchHistoryJob(const AccountPtr &account, QObject *parent=nullptr)
Constructs a job that will fetch all past user's locations from Google Latitude service.
int maxResults
Maximum number of results to fetch.
void setMaxResults(int results)
Sets maximum number of locations to fetch.
QString APIVersion()
Supported version of API.
ObjectsList parseLocationJSONFeed(const QByteArray &jsonFeed, FeedData &feedData)
Parses a JSON feed into list of Locations.
QUrl locationHistoryUrl(const Latitude::Granularity granularity, const int maxResults, const qlonglong maxTime, const qlonglong minTime)
Returns URL for fetching history of user's locations.
A job to fetch a single map tile described by a StaticMapUrl.
Definition blog.h:16
@ InvalidResponse
LibKGAPI error - Google returned invalid response.
Definition types.h:183
ContentType
Definition types.h:210
QVariant header(QNetworkRequest::KnownHeaders header) const const
QObject * parent() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
bool isValid() const const
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:59:23 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.