File indexing completed on 2024-04-28 04:42:43
0001 /* 0002 * SPDX-FileCopyrightText: 2021 Han Young <hanyoung@protonmail.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 #include "pendingcap.h" 0007 #include "capalertmessage.h" 0008 #include "capparser.h" 0009 #include "reply_p.h" 0010 0011 #include <QNetworkReply> 0012 0013 namespace KWeatherCore 0014 { 0015 class PendingCAPPrivate : public ReplyPrivate 0016 { 0017 public: 0018 QByteArray data; 0019 }; 0020 0021 CAPAlertMessage PendingCAP::value() const 0022 { 0023 Q_D(const PendingCAP); 0024 if (d->data.isEmpty()) { 0025 return {}; 0026 } 0027 0028 CAPParser parser(d->data); 0029 return parser.parse(); 0030 } 0031 PendingCAP::PendingCAP(QNetworkReply *reply, QObject *parent) 0032 : Reply(new PendingCAPPrivate, parent) 0033 { 0034 connect(reply, &QNetworkReply::finished, this, [this, reply] { 0035 Q_D(PendingCAP); 0036 reply->deleteLater(); 0037 if (reply->error() != QNetworkReply::NoError) { 0038 qWarning() << "network error when fetching alerts:" << reply->errorString(); 0039 d->setError(PendingCAP::NetworkError, reply->errorString()); 0040 } else { 0041 d->data = reply->readAll(); 0042 } 0043 Q_EMIT finished(); 0044 }); 0045 } 0046 0047 PendingCAP::~PendingCAP() = default; 0048 } 0049 0050 #include "moc_pendingcap.cpp"