KWeatherCore

pendingalerts.cpp
1/*
2 * SPDX-FileCopyrightText: 2021 Han Young <hanyoung@protonmail.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#include "pendingalerts.h"
8#include "reply_p.h"
9
10#include <QNetworkReply>
11
12namespace KWeatherCore
13{
14class PendingAlertsPrivate : public ReplyPrivate
15{
16public:
17 AlertEntries alertEntries;
18 FeedParser *parser = nullptr;
19};
20
21PendingAlerts::PendingAlerts(const QJsonDocument &config, QNetworkReply *reply, QObject *parent)
22 : Reply(new PendingAlertsPrivate, parent)
23{
24 Q_D(PendingAlerts);
25 d->parser = new FeedParser(config, this);
26 if (reply) {
27 connect(reply, &QNetworkReply::finished, this, [this, reply] {
28 Q_D(PendingAlerts);
29 reply->deleteLater();
30 if (reply->error() != QNetworkReply::NoError) {
31 qWarning() << "network error when fetching alerts:" << reply->errorString();
32 d->setError(PendingAlerts::NetworkError, reply->errorString());
33 } else {
34 d->alertEntries = d->parser->parse(reply->readAll());
35 }
36 Q_EMIT finished();
37 });
38 }
39}
40
41PendingAlerts::~PendingAlerts() = default;
42
43AlertEntries PendingAlerts::value() const
44{
45 Q_D(const PendingAlerts);
46 return d->alertEntries;
47}
48}
49
50#include "moc_pendingalerts.cpp"
The PendingAlerts class contains the reply to an asynchronous CAP feed request.
QString errorString() const const
QByteArray readAll()
NetworkError error() const const
void deleteLater()
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
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.