7#include "postfetchjob.h"
8#include "bloggerservice.h"
12#include <QNetworkReply>
13#include <QNetworkRequest>
17using namespace KGAPI2::Blogger;
19class Q_DECL_HIDDEN PostFetchJob::Private
22 Private(
const QString &blogId,
const QString &postId, PostFetchJob *parent);
27 bool fetchBodies =
true;
28 bool fetchImages =
true;
30 QStringList filterLabels;
33 StatusFilters statusFilter = All;
36 PostFetchJob *
const q;
39PostFetchJob::Private::Private(
const QString &blogId_,
const QString &postId_, PostFetchJob *parent)
46PostFetchJob::PostFetchJob(
const QString &blogId,
const AccountPtr &account,
QObject *parent)
48 , d(new Private(blogId,
QString(), this))
52PostFetchJob::PostFetchJob(
const QString &blogId,
const QString &postId,
const AccountPtr &account,
QObject *parent)
54 , d(new Private(blogId, postId, this))
58PostFetchJob::~PostFetchJob()
63bool PostFetchJob::fetchBodies()
const
65 return d->fetchBodies;
68void PostFetchJob::setFetchBodies(
bool fetchBodies)
70 d->fetchBodies = fetchBodies;
73bool PostFetchJob::fetchImages()
const
75 return d->fetchImages;
78void PostFetchJob::setFetchImages(
bool fetchImages)
80 d->fetchImages = fetchImages;
83uint PostFetchJob::maxResults()
const
88void PostFetchJob::setMaxResults(uint maxResults)
90 d->maxResults = maxResults;
93QStringList PostFetchJob::filterLabels()
const
95 return d->filterLabels;
98void PostFetchJob::setFilterLabels(
const QStringList &labels)
100 d->filterLabels = labels;
103QDateTime PostFetchJob::startDate()
const
108void PostFetchJob::setStartDate(
const QDateTime &startDate)
110 d->startDate = startDate;
113QDateTime PostFetchJob::endDate()
const
118void PostFetchJob::setEndDate(
const QDateTime &endDate)
120 d->endDate = endDate;
123void PostFetchJob::setStatusFilter(PostFetchJob::StatusFilters filter)
128PostFetchJob::StatusFilters PostFetchJob::statusFilter()
const
130 return d->statusFilter;
133void PostFetchJob::start()
135 QUrl url = BloggerService::fetchPostUrl(d->blogId, d->postId);
136 QUrlQuery
query(url);
137 if (d->postId.isEmpty()) {
138 if (d->startDate.isValid()) {
139 query.addQueryItem(QStringLiteral(
"startDate"), d->startDate.toString(
Qt::ISODate));
141 if (d->endDate.isValid()) {
142 query.addQueryItem(QStringLiteral(
"endDate"), d->endDate.toString(
Qt::ISODate));
144 if (d->maxResults > 0) {
147 if (!d->filterLabels.isEmpty()) {
148 query.addQueryItem(QStringLiteral(
"labels"), d->filterLabels.join(QLatin1Char(
',')));
150 query.addQueryItem(QStringLiteral(
"fetchBodies"), Utils::bool2Str(d->fetchBodies));
151 query.addQueryItem(QStringLiteral(
"fetchImages"), Utils::bool2Str(d->fetchImages));
154 query.addQueryItem(QStringLiteral(
"view"), QStringLiteral(
"ADMIN"));
156 if (d->statusFilter & Draft) {
157 query.addQueryItem(QStringLiteral(
"status"), QStringLiteral(
"draft"));
159 if (d->statusFilter & Live) {
160 query.addQueryItem(QStringLiteral(
"status"), QStringLiteral(
"live"));
162 if (d->statusFilter & Scheduled) {
163 query.addQueryItem(QStringLiteral(
"status"), QStringLiteral(
"scheduled"));
166 const QNetworkRequest request(url);
170ObjectsList PostFetchJob::handleReplyWithItems(
const QNetworkReply *reply,
const QByteArray &rawData)
177 ContentType ct = Utils::stringToContentType(contentType);
178 if (ct == KGAPI2::JSON) {
179 if (d->postId.isEmpty()) {
180 items = Post::fromJSONFeed(rawData, feedData);
182 items << Post::fromJSON(rawData);
192 const QNetworkRequest request(feedData.
nextPageUrl);
201#include "moc_postfetchjob.cpp"
QUrl requestUrl
Original URL of the request.
QUrl nextPageUrl
Link to next page of feed.
Abstract superclass for all jobs that fetch resources from Google.
virtual ObjectsList items() const
Returns all items fetched by this job.
void setErrorString(const QString &errorString)
Set job error description to errorString.
AccountPtr account() const
Returns account used to authenticate requests.
virtual void emitFinished()
Emits Job::finished() signal.
void setError(KGAPI2::Error error)
Set job error to error.
virtual void enqueueRequest(const QNetworkRequest &request, const QByteArray &data=QByteArray(), const QString &contentType=QString())
Enqueues request in dispatcher queue.
KSERVICE_EXPORT KService::List query(FilterFunc filterFunc)
A job to fetch a single map tile described by a StaticMapUrl.
@ InvalidResponse
LibKGAPI error - Google returned invalid response.
QNetworkRequest request() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
QString number(double n, char format, int precision)
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)
bool isValid() const const
void setQuery(const QString &query, ParsingMode mode)
QString toString() const const