File indexing completed on 2025-01-05 04:29:53
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 "updatesyncrequest.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 UpdateSyncRequest::UpdateSyncRequest(SyncUtils::Provider provider, QNetworkReply *reply, QObject *parent) 0019 : GenericRequest(provider, reply, parent) 0020 { 0021 } 0022 0023 bool UpdateSyncRequest::success() const 0024 { 0025 return m_success; 0026 } 0027 0028 QVector<QStringList> UpdateSyncRequest::syncedDevices() const 0029 { 0030 return m_syncedDevices; 0031 } 0032 0033 QStringList UpdateSyncRequest::unsyncedDevices() const 0034 { 0035 return m_unsyncedDevices; 0036 } 0037 0038 void UpdateSyncRequest::processResults() 0039 { 0040 if (m_reply->error()) { 0041 m_error = m_reply->error(); 0042 m_errorString = m_reply->errorString(); 0043 qCDebug(kastsSync) << "m_reply error" << m_reply->errorString(); 0044 } else if (!m_abort) { 0045 QJsonParseError *error = nullptr; 0046 QJsonDocument data = QJsonDocument::fromJson(m_reply->readAll(), error); 0047 if (error) { 0048 qCDebug(kastsSync) << "parse error" << error->errorString(); 0049 m_error = 1; 0050 m_errorString = error->errorString(); 0051 } else if (!m_abort) { 0052 for (auto jsonGroup : data.object().value(QStringLiteral("synchronized")).toArray()) { 0053 QStringList syncedGroup; 0054 for (auto jsonDevice : jsonGroup.toArray()) { 0055 syncedGroup += jsonDevice.toString(); 0056 } 0057 m_syncedDevices += syncedGroup; 0058 } 0059 for (auto jsonDevice : data.object().value(QStringLiteral("not-synchronized")).toArray()) { 0060 m_unsyncedDevices += jsonDevice.toString(); 0061 } 0062 m_success = true; 0063 } 0064 } 0065 Q_EMIT finished(); 0066 m_reply->deleteLater(); 0067 deleteLater(); 0068 }