File indexing completed on 2024-04-28 04:42:41

0001 /*
0002  * SPDX-FileCopyrightText: 2021 Han Young <hanyoung@protonmail.com>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 #include "alertfeedentry.h"
0007 #include "kweathercore_p.h"
0008 #include <QNetworkAccessManager>
0009 #include <QUrl>
0010 namespace KWeatherCore
0011 {
0012 class AlertFeedEntry::AlertFeedEntryPrivate
0013 {
0014 public:
0015     QString title;
0016     QString summary;
0017     QString area;
0018     CAPAlertInfo::Urgency urgency = CAPAlertInfo::Urgency::UnknownUrgency;
0019     CAPAlertInfo::Severity severity = CAPAlertInfo::Severity::UnknownSeverity;
0020     CAPAlertInfo::Certainty certainty = CAPAlertInfo::Certainty::UnknownCertainty;
0021     QDateTime date;
0022     QUrl CAPUrl;
0023     AreaCodeVec areaCodes;
0024     CAPPolygon polygon;
0025 };
0026 
0027 AlertFeedEntry::AlertFeedEntry()
0028     : d(std::make_unique<AlertFeedEntryPrivate>())
0029 {
0030 }
0031 AlertFeedEntry::AlertFeedEntry(const AlertFeedEntry &other)
0032     : d(std::make_unique<AlertFeedEntryPrivate>(*other.d))
0033 {
0034 }
0035 AlertFeedEntry::AlertFeedEntry(AlertFeedEntry &&other) = default;
0036 AlertFeedEntry::~AlertFeedEntry() = default;
0037 const QString &AlertFeedEntry::title() const
0038 {
0039     return d->title;
0040 }
0041 const QString &AlertFeedEntry::summary() const
0042 {
0043     return d->summary;
0044 }
0045 const QString &AlertFeedEntry::area() const
0046 {
0047     return d->area;
0048 }
0049 QString AlertFeedEntry::urgency() const
0050 {
0051     return KWeatherCorePrivate::urgencyToString(d->urgency);
0052 }
0053 QString AlertFeedEntry::severity() const
0054 {
0055     return KWeatherCorePrivate::severityToString(d->severity);
0056 }
0057 QString AlertFeedEntry::certainty() const
0058 {
0059     return KWeatherCorePrivate::certaintyToString(d->certainty);
0060 }
0061 const QDateTime &AlertFeedEntry::date() const
0062 {
0063     return d->date;
0064 }
0065 PendingCAP *AlertFeedEntry::CAP() const
0066 {
0067     QNetworkAccessManager manager;
0068     auto reply = manager.get(QNetworkRequest(d->CAPUrl));
0069     return new PendingCAP(reply);
0070 }
0071 const AreaCodeVec &AlertFeedEntry::areaCodes() const
0072 {
0073     return d->areaCodes;
0074 }
0075 const CAPPolygon &AlertFeedEntry::polygon() const
0076 {
0077     return d->polygon;
0078 }
0079 
0080 void AlertFeedEntry::setTitle(const QString &title)
0081 {
0082     d->title = title;
0083 }
0084 void AlertFeedEntry::setSummary(const QString &summary)
0085 {
0086     d->summary = summary;
0087 }
0088 void AlertFeedEntry::setArea(const QString &area)
0089 {
0090     d->area = area;
0091 }
0092 void AlertFeedEntry::setUrgency(CAPAlertInfo::Urgency urgency)
0093 {
0094     d->urgency = urgency;
0095 }
0096 void AlertFeedEntry::setCertainty(CAPAlertInfo::Certainty certainty)
0097 {
0098     d->certainty = certainty;
0099 }
0100 void AlertFeedEntry::setSeverity(CAPAlertInfo::Severity severity)
0101 {
0102     d->severity = severity;
0103 }
0104 void AlertFeedEntry::setDate(const QDateTime &date)
0105 {
0106     d->date = date;
0107 }
0108 void AlertFeedEntry::setUrl(const QUrl &url)
0109 {
0110     d->CAPUrl = url;
0111 }
0112 void AlertFeedEntry::setAreaCodes(const AreaCodeVec &areaCodes)
0113 {
0114     d->areaCodes = areaCodes;
0115 }
0116 void AlertFeedEntry::setAreaCodes(AreaCodeVec &&areaCodes)
0117 {
0118     d->areaCodes = std::move(areaCodes);
0119 }
0120 void AlertFeedEntry::setPolygon(CAPPolygon &&polygon)
0121 {
0122     d->polygon = std::move(polygon);
0123 }
0124 AlertFeedEntry &AlertFeedEntry::operator=(const AlertFeedEntry &other)
0125 {
0126     *this->d = *other.d;
0127     return *this;
0128 }
0129 AlertFeedEntry &AlertFeedEntry::operator=(AlertFeedEntry &&other) = default;
0130 }
0131 
0132 #include "moc_alertfeedentry.cpp"