Kgapi

locationfetchjob.cpp
1 /*
2  * This file is part of LibKGAPI library
3  *
4  * SPDX-FileCopyrightText: 2013 Daniel Vrátil <[email protected]>
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 "latitudeservice.h"
11 #include "account.h"
12 #include "../debug.h"
13 #include "location.h"
14 #include "utils.h"
15 
16 #include <QNetworkRequest>
17 #include <QNetworkReply>
18 
19 
20 using namespace KGAPI2;
21 
22 class Q_DECL_HIDDEN LocationFetchJob::Private
23 {
24  public:
25  Private();
26 
27  qlonglong timestamp = -1;
28  Latitude::Granularity granularity = Latitude::City;
29 };
30 
31 LocationFetchJob::Private::Private()
32 {
33 }
34 
36  FetchJob(account, parent),
37  d(new Private)
38 {
39 }
40 
42  FetchJob(account, parent),
43  d(new Private)
44 {
45  d->timestamp = timestamp;
46 }
47 
49 {
50  delete d;
51 }
52 
53 Latitude::Granularity LocationFetchJob::granularity() const
54 {
55  return d->granularity;
56 }
57 
58 void LocationFetchJob::setGranularity(Latitude::Granularity granularity)
59 {
60  if (isRunning()) {
61  qCWarning(KGAPIDebug) << "Can't modify granularity property when the job is running";
62  }
63  d->granularity = granularity;
64 }
65 
67 {
68  QUrl url;
69  if (d->timestamp == -1) {
70  url = LatitudeService::retrieveCurrentLocationUrl(d->granularity);
71  } else {
72  url = LatitudeService::retrieveLocationUrl(d->timestamp, d->granularity);
73  }
74  QNetworkRequest request(url);
75  request.setRawHeader("GData-Version", LatitudeService::APIVersion().toLatin1());
76 
77  enqueueRequest(request);
78 }
79 
81 {
82  const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
83  ContentType ct = Utils::stringToContentType(contentType);
85  if (ct == KGAPI2::JSON) {
87  } else {
89  setErrorString(tr("Invalid response content type"));
90  emitFinished();
91  }
92 
93  return items;
94 }
95 
96 #include "moc_locationfetchjob.cpp"
void setGranularity(Latitude::Granularity granularity)
Sets granularity of the requested result.
AccountPtr account() const
Returns account used to authenticate requests.
Definition: job.cpp:425
bool isRunning() const
Whether job is running.
Base class for all objects.
Definition: object.h:31
A job to fetch current or a specific locations from user&#39;s account on Google Latitude.
Latitude::Granularity granularity() const
Returns granularity of the requested location.
QUrl retrieveLocationUrl(const qlonglong id, const Latitude::Granularity granularity)
URL for fetching a specific location.
QString tr(const char *sourceText, const char *disambiguation, int n)
QUrl retrieveCurrentLocationUrl(const Latitude::Granularity granularity)
Returns URL for fetch current user&#39;s location.
void start() override
KGAPI2::Job::start implementation.
ObjectsList handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData) override
KGAPI2::FetchJob::handleReplyWithItems implementation.
virtual ObjectsList items() const
Returns all items fetched by this job.
Definition: fetchjob.cpp:41
LocationPtr JSONToLocation(const QByteArray &jsonData)
Parses JSON data into a Location object.
virtual void enqueueRequest(const QNetworkRequest &request, const QByteArray &data=QByteArray(), const QString &contentType=QString())
Enqueues request in dispatcher queue.
Definition: job.cpp:497
A job to fetch a single map tile described by a StaticMapUrl.
Definition: blog.h:16
LibKGAPI error - Google returned invalid response.
Definition: types.h:180
~LocationFetchJob() override
Destructor.
QString APIVersion()
Supported version of API.
QVariant header(QNetworkRequest::KnownHeaders header) const const
virtual void emitFinished()
Emits Job::finished() signal.
Definition: job.cpp:479
void setErrorString(const QString &errorString)
Set job error description to errorString.
Definition: job.cpp:390
QSharedPointer< X > dynamicCast() const const
void setRawHeader(const QByteArray &headerName, const QByteArray &headerValue)
void setError(KGAPI2::Error error)
Set job error to error.
Definition: job.cpp:375
Abstract superclass for all jobs that fetch resources from Google.
Definition: fetchjob.h:24
LocationFetchJob(const AccountPtr &account, QObject *parent=nullptr)
Constructs a job that will fetch users current locations from Google Latitude service.
QObject * parent() const const
QString toString() const const
ContentType
Definition: types.h:207
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed Jan 20 2021 23:16:12 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.