File indexing completed on 2024-05-12 05:22:16
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 "appfetchjob.h" 0010 #include "app.h" 0011 #include "driveservice.h" 0012 #include "utils.h" 0013 0014 #include <QNetworkReply> 0015 #include <QNetworkRequest> 0016 0017 using namespace KGAPI2; 0018 using namespace KGAPI2::Drive; 0019 0020 class Q_DECL_HIDDEN AppFetchJob::Private 0021 { 0022 public: 0023 QString appId; 0024 }; 0025 0026 AppFetchJob::AppFetchJob(const AccountPtr &account, QObject *parent) 0027 : FetchJob(account, parent) 0028 , d(new Private) 0029 { 0030 } 0031 0032 AppFetchJob::AppFetchJob(const QString &appId, const AccountPtr &account, QObject *parent) 0033 : FetchJob(account, parent) 0034 , d(new Private) 0035 { 0036 d->appId = appId; 0037 } 0038 0039 AppFetchJob::~AppFetchJob() 0040 { 0041 delete d; 0042 } 0043 0044 void AppFetchJob::start() 0045 { 0046 QUrl url; 0047 if (d->appId.isEmpty()) { 0048 url = DriveService::fetchAppsUrl(); 0049 } else { 0050 url = DriveService::fetchAppUrl(d->appId); 0051 } 0052 QNetworkRequest request(url); 0053 0054 enqueueRequest(request); 0055 } 0056 0057 ObjectsList AppFetchJob::handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData) 0058 { 0059 ObjectsList items; 0060 0061 const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString(); 0062 ContentType ct = Utils::stringToContentType(contentType); 0063 if (ct == KGAPI2::JSON) { 0064 if (d->appId.isEmpty()) { 0065 items << App::fromJSONFeed(rawData); 0066 } else { 0067 items << App::fromJSON(rawData); 0068 } 0069 } else { 0070 setError(KGAPI2::InvalidResponse); 0071 setErrorString(tr("Invalid response content type")); 0072 } 0073 0074 emitFinished(); 0075 return items; 0076 } 0077 0078 #include "moc_appfetchjob.cpp"