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 #pragma once
0007 #include "capalertinfo.h"
0008 #include "caparea.h"
0009 #include "kweathercore/kweathercore_export.h"
0010 #include "pendingcap.h"
0011 #include <QObject>
0012 #include <memory>
0013 namespace KWeatherCore
0014 {
0015 // code name (FIPS6, UGC...)/code value (002050, AKZ155)
0016 using AreaCodeVec = std::vector<std::pair<QString, QString>>;
0017 /**
0018  * @short Class represents single CAP
0019  *
0020  * This class contains the parsed CAP FEED entry
0021  *
0022  * @author Han Young <hanyoung@protonmail.com>
0023  */
0024 class KWEATHERCORE_EXPORT AlertFeedEntry
0025 {
0026     Q_GADGET
0027     Q_PROPERTY(QString title READ title)
0028     Q_PROPERTY(QString summary READ summary)
0029     Q_PROPERTY(QString area READ area)
0030     Q_PROPERTY(QString urgency READ urgency)
0031     Q_PROPERTY(QString severity READ severity)
0032     Q_PROPERTY(QString certainty READ certainty)
0033     Q_PROPERTY(QDateTime date READ date)
0034 public:
0035     /**
0036      * default constructor
0037      */
0038     AlertFeedEntry();
0039     /**
0040      * copy constructor
0041      */
0042     AlertFeedEntry(const AlertFeedEntry &other);
0043     AlertFeedEntry(AlertFeedEntry &&other);
0044     ~AlertFeedEntry();
0045     /**
0046      * title of this entry
0047      */
0048     const QString &title() const;
0049     /**
0050      * summary of this entry
0051      */
0052     const QString &summary() const;
0053     /**
0054      * area name, for accurate location
0055      * use @AreaCodes if possible
0056      */
0057     const QString &area() const;
0058     /**
0059      * urgency
0060      * @return localized, "Unknown" by defaut
0061      */
0062     QString urgency() const;
0063     /**
0064      * severity
0065      * @return localized, "Unknown" by defaut
0066      */
0067     QString severity() const;
0068     /**
0069      * certainty
0070      * @return localized, "Unknown" by defaut
0071      */
0072     QString certainty() const;
0073     /**
0074      * could be date of the alert or the date of this message
0075      * refer to CAP for accurate date
0076      * see @CAP
0077      */
0078     const QDateTime &date() const;
0079     /**
0080      * CAP, request to download CAP file
0081      * @return it is the client's responsibility to delete the
0082      * PendingCAP afterward to avoid memory leak
0083      */
0084     PendingCAP *CAP() const;
0085     /**
0086      * areaCodes
0087      * @return pairs of QString, the first one is code type,
0088      * ie. {"UGC", "AKZ017 AKZ020 AKZ021 AKZ022 AKZ023"}
0089      */
0090     const AreaCodeVec &areaCodes() const;
0091     /**
0092      * area polygon
0093      * @return latitude longitude pairs
0094      */
0095     const CAPPolygon &polygon() const;
0096 
0097     void setTitle(const QString &title);
0098     void setSummary(const QString &summary);
0099     void setArea(const QString &area);
0100     void setUrgency(CAPAlertInfo::Urgency urgency);
0101     void setCertainty(CAPAlertInfo::Certainty certainty);
0102     void setSeverity(CAPAlertInfo::Severity severity);
0103     void setDate(const QDateTime &date);
0104     void setUrl(const QUrl &url);
0105     void setAreaCodes(const AreaCodeVec &areaCodes);
0106     void setAreaCodes(AreaCodeVec &&areaCodes);
0107     void setPolygon(CAPPolygon &&polygon);
0108     AlertFeedEntry &operator=(const AlertFeedEntry &other);
0109     AlertFeedEntry &operator=(AlertFeedEntry &&other);
0110 
0111 private:
0112     class AlertFeedEntryPrivate;
0113     std::unique_ptr<AlertFeedEntryPrivate> d;
0114 };
0115 }