File indexing completed on 2025-01-19 04:28:13
0001 /** 0002 * SPDX-FileCopyrightText: 2021 Bart De Vries <bart@mogwai.be> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #include "devicerequest.h" 0008 0009 #include <QJsonArray> 0010 #include <QJsonDocument> 0011 #include <QJsonObject> 0012 #include <QNetworkReply> 0013 0014 #include "synclogging.h" 0015 0016 DeviceRequest::DeviceRequest(SyncUtils::Provider provider, QNetworkReply *reply, QObject *parent) 0017 : GenericRequest(provider, reply, parent) 0018 { 0019 } 0020 0021 QVector<SyncUtils::Device> DeviceRequest::devices() const 0022 { 0023 return m_devices; 0024 } 0025 0026 void DeviceRequest::processResults() 0027 { 0028 if (m_reply->error()) { 0029 m_error = m_reply->error(); 0030 m_errorString = m_reply->errorString(); 0031 qCDebug(kastsSync) << "m_reply error" << m_reply->errorString(); 0032 } else if (!m_abort) { 0033 QJsonParseError *error = nullptr; 0034 QJsonDocument data = QJsonDocument::fromJson(m_reply->readAll(), error); 0035 if (error) { 0036 qCDebug(kastsSync) << "parse error" << error->errorString(); 0037 m_error = 1; 0038 m_errorString = error->errorString(); 0039 } else if (!m_abort) { 0040 for (auto jsonDevice : data.array()) { 0041 SyncUtils::Device device; 0042 device.id = jsonDevice.toObject().value(QStringLiteral("id")).toString(); 0043 device.caption = jsonDevice.toObject().value(QStringLiteral("caption")).toString(); 0044 device.type = jsonDevice.toObject().value(QStringLiteral("type")).toString(); 0045 device.subscriptions = jsonDevice.toObject().value(QStringLiteral("subscriptions")).toInt(); 0046 0047 m_devices += device; 0048 } 0049 } 0050 } 0051 Q_EMIT finished(); 0052 m_reply->deleteLater(); 0053 deleteLater(); 0054 }