KWeatherCore

pendingcap.cpp
1/*
2 * SPDX-FileCopyrightText: 2021 Han Young <hanyoung@protonmail.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6#include "pendingcap.h"
7#include "capalertmessage.h"
8#include "capparser.h"
9#include "reply_p.h"
10
11#include <QNetworkReply>
12
13namespace KWeatherCore
14{
15class PendingCAPPrivate : public ReplyPrivate
16{
17public:
18 QByteArray data;
19};
20
22{
23 Q_D(const PendingCAP);
24 if (d->data.isEmpty()) {
25 return {};
26 }
27
28 CAPParser parser(d->data);
29 return parser.parse();
30}
31PendingCAP::PendingCAP(QNetworkReply *reply, QObject *parent)
32 : Reply(new PendingCAPPrivate, parent)
33{
34 connect(reply, &QNetworkReply::finished, this, [this, reply] {
36 reply->deleteLater();
37 if (reply->error() != QNetworkReply::NoError) {
38 qWarning() << "network error when fetching alerts:" << reply->errorString();
39 d->setError(PendingCAP::NetworkError, reply->errorString());
40 } else {
41 d->data = reply->readAll();
42 }
44 });
45}
46
47PendingCAP::~PendingCAP() = default;
48}
49
50#include "moc_pendingcap.cpp"
Represents a single CAP Alert Message.
Parser for CAP Alert Messages.
Definition capparser.h:27
The PendingAlerts class contains the reply to an asynchronous CAP request.
Definition pendingcap.h:25
CAPAlertMessage value() const
value pointer to the shared alerts data the pointer is nullptr until finished() raised
Base class for all asynchronous jobs.
Definition reply.h:24
void finished()
Emitted once the job has been finished, either successfully or with an error.
@ NetworkError
Network operation failed.
Definition reply.h:32
QString errorString() const const
QByteArray readAll()
NetworkError error() const const
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void deleteLater()
QChar * data()
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 12:02:06 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.