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 "syncrequest.h" 0008 0009 #include <QJsonArray> 0010 #include <QJsonDocument> 0011 #include <QJsonObject> 0012 #include <QNetworkReply> 0013 #include <QStringList> 0014 #include <QVector> 0015 0016 #include "synclogging.h" 0017 0018 SyncRequest::SyncRequest(SyncUtils::Provider provider, QNetworkReply *reply, QObject *parent) 0019 : GenericRequest(provider, reply, parent) 0020 { 0021 } 0022 0023 QVector<QStringList> SyncRequest::syncedDevices() const 0024 { 0025 return m_syncedDevices; 0026 } 0027 0028 QStringList SyncRequest::unsyncedDevices() const 0029 { 0030 return m_unsyncedDevices; 0031 } 0032 0033 void SyncRequest::processResults() 0034 { 0035 if (m_reply->error()) { 0036 m_error = m_reply->error(); 0037 m_errorString = m_reply->errorString(); 0038 qCDebug(kastsSync) << "m_reply error" << m_reply->errorString(); 0039 } else if (!m_abort) { 0040 QJsonParseError *error = nullptr; 0041 QJsonDocument data = QJsonDocument::fromJson(m_reply->readAll(), error); 0042 if (error) { 0043 qCDebug(kastsSync) << "parse error" << error->errorString(); 0044 m_error = 1; 0045 m_errorString = error->errorString(); 0046 } else if (!m_abort) { 0047 for (auto jsonGroup : data.object().value(QStringLiteral("synchronized")).toArray()) { 0048 QStringList syncedGroup; 0049 for (auto jsonDevice : jsonGroup.toArray()) { 0050 syncedGroup += jsonDevice.toString(); 0051 } 0052 m_syncedDevices += syncedGroup; 0053 } 0054 for (auto jsonDevice : data.object().value(QStringLiteral("not-synchronized")).toArray()) { 0055 m_unsyncedDevices += jsonDevice.toString(); 0056 } 0057 } 0058 } 0059 Q_EMIT finished(); 0060 m_reply->deleteLater(); 0061 deleteLater(); 0062 }