Kgapi

locationfetchjob.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 "locationfetchjob.h"
10#include "account.h"
11#include "debug.h"
12#include "latitudeservice.h"
13#include "location.h"
14#include "utils.h"
15
16#include <QNetworkReply>
17#include <QNetworkRequest>
18
19using namespace KGAPI2;
20
21class Q_DECL_HIDDEN LocationFetchJob::Private
22{
23public:
24 Private();
25
26 qlonglong timestamp = -1;
27 Latitude::Granularity granularity = Latitude::City;
28};
29
30LocationFetchJob::Private::Private()
31{
32}
33
39
40LocationFetchJob::LocationFetchJob(qlonglong timestamp, const AccountPtr &account, QObject *parent)
41 : FetchJob(account, parent)
42 , d(new Private)
43{
44 d->timestamp = timestamp;
45}
46
51
52Latitude::Granularity LocationFetchJob::granularity() const
53{
54 return d->granularity;
55}
56
57void LocationFetchJob::setGranularity(Latitude::Granularity granularity)
58{
59 if (isRunning()) {
60 qCWarning(KGAPIDebug) << "Can't modify granularity property when the job is running";
61 }
62 d->granularity = granularity;
63}
64
66{
67 QUrl url;
68 if (d->timestamp == -1) {
70 } else {
71 url = LatitudeService::retrieveLocationUrl(d->timestamp, d->granularity);
72 }
73 QNetworkRequest request(url);
74 request.setRawHeader("GData-Version", LatitudeService::APIVersion().toLatin1());
75
76 enqueueRequest(request);
77}
78
80{
81 const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
82 ContentType ct = Utils::stringToContentType(contentType);
84 if (ct == KGAPI2::JSON) {
86 } else {
88 setErrorString(tr("Invalid response content type"));
90 }
91
92 return items;
93}
94
95#include "moc_locationfetchjob.cpp"
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 current or a specific locations from user's account on Google Latitude.
ObjectsList handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData) override
KGAPI2::FetchJob::handleReplyWithItems implementation.
void setGranularity(Latitude::Granularity granularity)
Sets granularity of the requested result.
LocationFetchJob(const AccountPtr &account, QObject *parent=nullptr)
Constructs a job that will fetch users current locations from Google Latitude service.
Latitude::Granularity granularity
Granularity of the results.
~LocationFetchJob() override
Destructor.
void start() override
KGAPI2::Job::start implementation.
Base class for all objects.
Definition object.h:31
QString APIVersion()
Supported version of API.
QUrl retrieveCurrentLocationUrl(const Latitude::Granularity granularity)
Returns URL for fetch current user's location.
QUrl retrieveLocationUrl(const qlonglong id, const Latitude::Granularity granularity)
URL for fetching a specific location.
LocationPtr JSONToLocation(const QByteArray &jsonData)
Parses JSON data into a Location object.
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
void setRawHeader(const QByteArray &headerName, const QByteArray &headerValue)
QObject * parent() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
QSharedPointer< X > dynamicCast() 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.