File indexing completed on 2024-05-12 05:22:24

0001 /*
0002  * This file is part of LibKGAPI library
0003  *
0004  * SPDX-FileCopyrightText: 2013 Daniel Vrátil <dvratil@redhat.com>
0005  *
0006  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007  */
0008 
0009 #include "locationdeletejob.h"
0010 #include "latitudeservice.h"
0011 #include "location.h"
0012 
0013 #include <QNetworkRequest>
0014 
0015 using namespace KGAPI2;
0016 
0017 class Q_DECL_HIDDEN LocationDeleteJob::Private
0018 {
0019 public:
0020     Private();
0021 
0022     qulonglong locationId = 0;
0023     bool finished = false;
0024 };
0025 
0026 LocationDeleteJob::Private::Private()
0027 {
0028 }
0029 
0030 LocationDeleteJob::LocationDeleteJob(const AccountPtr &account, QObject *parent)
0031     : DeleteJob(account, parent)
0032     , d(new Private)
0033 {
0034 }
0035 
0036 LocationDeleteJob::LocationDeleteJob(const LocationPtr &location, const AccountPtr &account, QObject *parent)
0037     : DeleteJob(account, parent)
0038     , d(new Private)
0039 {
0040     d->locationId = location->timestamp();
0041 }
0042 
0043 LocationDeleteJob::LocationDeleteJob(qulonglong timestamp, const AccountPtr &account, QObject *parent)
0044     : DeleteJob(account, parent)
0045     , d(new Private)
0046 {
0047     d->locationId = timestamp;
0048 }
0049 
0050 LocationDeleteJob::~LocationDeleteJob()
0051 {
0052     delete d;
0053 }
0054 
0055 void LocationDeleteJob::start()
0056 {
0057     if (d->finished) {
0058         emitFinished();
0059         return;
0060     }
0061 
0062     QUrl url;
0063     if (d->locationId > 0) {
0064         url = LatitudeService::deleteLocationUrl(d->locationId);
0065     } else {
0066         url = LatitudeService::deleteCurrentLocationUrl();
0067     }
0068 
0069     QNetworkRequest request(url);
0070     request.setRawHeader("GData-Version", LatitudeService::APIVersion().toLatin1());
0071 
0072     QStringList headers;
0073     const auto rawHeaderList = request.rawHeaderList();
0074     headers.reserve(rawHeaderList.size());
0075     for (const QByteArray &str : std::as_const(rawHeaderList)) {
0076         headers << QLatin1StringView(str) + QLatin1StringView(": ") + QLatin1StringView(request.rawHeader(str));
0077     }
0078 
0079     enqueueRequest(request);
0080     d->finished = true;
0081 }
0082 
0083 #include "moc_locationdeletejob.cpp"