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 "aboutfetchjob.h" 0010 #include "about.h" 0011 #include "debug.h" 0012 #include "driveservice.h" 0013 #include "utils.h" 0014 0015 #include <QNetworkReply> 0016 #include <QNetworkRequest> 0017 0018 using namespace KGAPI2; 0019 using namespace KGAPI2::Drive; 0020 0021 class Q_DECL_HIDDEN AboutFetchJob::Private 0022 { 0023 public: 0024 Private(); 0025 0026 bool includeSubscribed = true; 0027 qlonglong maxChangeIdCount = 0; 0028 qlonglong startChangeId = 0; 0029 }; 0030 0031 AboutFetchJob::Private::Private() 0032 { 0033 } 0034 0035 AboutFetchJob::AboutFetchJob(const AccountPtr &account, QObject *parent) 0036 : FetchJob(account, parent) 0037 , d(new Private) 0038 { 0039 } 0040 0041 AboutFetchJob::~AboutFetchJob() 0042 { 0043 delete d; 0044 } 0045 0046 void AboutFetchJob::setIncludeSubscribed(bool includeSubscribed) 0047 { 0048 if (isRunning()) { 0049 qCWarning(KGAPIDebug) << "Can't modify includeSubscribed property when job is running"; 0050 return; 0051 } 0052 0053 d->includeSubscribed = includeSubscribed; 0054 } 0055 0056 bool AboutFetchJob::includeSubscribed() const 0057 { 0058 return d->includeSubscribed; 0059 } 0060 0061 void AboutFetchJob::setMaxChangeIdCount(qlonglong maxChangeIdCount) 0062 { 0063 if (isRunning()) { 0064 qCWarning(KGAPIDebug) << "Can't modify maxChangeIdCount property when job is running"; 0065 return; 0066 } 0067 0068 d->maxChangeIdCount = maxChangeIdCount; 0069 } 0070 0071 qlonglong AboutFetchJob::maxChangeIdCount() const 0072 { 0073 return d->maxChangeIdCount; 0074 } 0075 0076 void AboutFetchJob::setStartChangeId(qlonglong startChangeId) 0077 { 0078 if (isRunning()) { 0079 qCWarning(KGAPIDebug) << "Can't modify startChangeId property when job is running"; 0080 return; 0081 } 0082 0083 d->startChangeId = startChangeId; 0084 } 0085 0086 qlonglong AboutFetchJob::startChangeId() const 0087 { 0088 return d->startChangeId; 0089 } 0090 0091 AboutPtr AboutFetchJob::aboutData() const 0092 { 0093 if (isRunning() || items().count() == 0) { 0094 return AboutPtr(); 0095 } 0096 0097 return items().at(0).dynamicCast<About>(); 0098 } 0099 0100 void AboutFetchJob::start() 0101 { 0102 QUrl url = DriveService::fetchAboutUrl(d->includeSubscribed, d->maxChangeIdCount, d->startChangeId); 0103 QNetworkRequest request(url); 0104 0105 enqueueRequest(request); 0106 } 0107 0108 KGAPI2::ObjectsList AboutFetchJob::handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData) 0109 { 0110 ObjectsList items; 0111 0112 const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString(); 0113 ContentType ct = Utils::stringToContentType(contentType); 0114 if (ct == KGAPI2::JSON) { 0115 AboutPtr about = About::fromJSON(rawData); 0116 items << about; 0117 } else { 0118 setError(KGAPI2::InvalidResponse); 0119 setErrorString(tr("Invalid response content type")); 0120 } 0121 0122 emitFinished(); 0123 return items; 0124 } 0125 0126 #include "moc_aboutfetchjob.cpp"