File indexing completed on 2024-04-28 04:42:41
0001 /* 0002 * SPDX-FileCopyrightText: 2021 Han Young <hanyoung@protonmail.com> 0003 * SPDX-FileCopyrightText: 2021 Anjani Kumar <anjanik012@gmail.com> 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 #pragma once 0007 #include "capnamedvalue.h" 0008 #include "kweathercore/kweathercore_export.h" 0009 #include <QDateTime> 0010 #include <QObject> 0011 #include <QString> 0012 #include <tuple> 0013 #include <vector> 0014 0015 namespace KWeatherCore 0016 { 0017 class CAPAlertInfoPrivate; 0018 class CAPArea; 0019 /** 0020 * @short Represents a single CAP alert message info element. 0021 * 0022 * @see CAPAlertMessage 0023 * @see https://docs.oasis-open.org/emergency/cap/v1.2/CAP-v1.2.html ยง3.2.2 0024 * @author Han Young <hanyoung@protonmail.com> 0025 * @author Anjani Kumar <anjanik012@gmail.com> 0026 */ 0027 class KWEATHERCORE_EXPORT CAPAlertInfo 0028 { 0029 Q_GADGET 0030 Q_PROPERTY(QString headline READ headline) 0031 Q_PROPERTY(QString description READ description) 0032 Q_PROPERTY(QString event READ event) 0033 Q_PROPERTY(QDateTime effectiveTime READ effectiveTime) 0034 Q_PROPERTY(QDateTime onsetTime READ onsetTime) 0035 Q_PROPERTY(QDateTime expireTime READ expireTime) 0036 Q_PROPERTY(Categories categories READ categories) 0037 Q_PROPERTY(Urgency urgency READ urgency) 0038 Q_PROPERTY(Severity severity READ severity) 0039 Q_PROPERTY(Certainty certainty READ certainty) 0040 Q_PROPERTY(QString sender READ sender) 0041 Q_PROPERTY(QString instruction READ instruction) 0042 Q_PROPERTY(QString language READ language) 0043 Q_PROPERTY(ResponseTypes responseTypes READ responseTypes) 0044 Q_PROPERTY(QString contact READ contact) 0045 Q_PROPERTY(QString web READ web) 0046 0047 public: 0048 enum class Category { 0049 Unknown = 0, 0050 Geophysical = 0b1, 0051 Meteorological = 0b10, 0052 Safety = 0b100, 0053 Security = 0b1000, 0054 Rescue = 0b10000, 0055 Fire = 0b100000, 0056 Health = 0b1000000, 0057 Environmental = 0b10000000, 0058 Transport = 0b100000000, 0059 Infrastructure = 0b1000000000, 0060 CBRNE = 0b10000000000, 0061 Other = 0b100000000000 0062 }; 0063 Q_DECLARE_FLAGS(Categories, Category) 0064 Q_FLAG(Categories) 0065 enum class Urgency { Immediate, Expected, Future, Past, UnknownUrgency }; 0066 Q_ENUM(Urgency) 0067 enum class Severity { Extreme, Severe, Moderate, Minor, UnknownSeverity }; 0068 Q_ENUM(Severity) 0069 enum class Certainty { Observed, Likely, Possible, Unlikely, UnknownCertainty }; 0070 Q_ENUM(Certainty) 0071 0072 enum class ResponseType { 0073 UnknownResponseType = 0, 0074 Shelter = 1 << 0, 0075 Evacuate = 1 << 1, 0076 Prepare = 1 << 2, 0077 Execute = 1 << 3, 0078 Avoid = 1 << 4, 0079 Monitor = 1 << 5, 0080 Assess = 1 << 6, 0081 AllClear = 1 << 7, 0082 None = 1 << 8, 0083 }; 0084 Q_DECLARE_FLAGS(ResponseTypes, ResponseType) 0085 Q_FLAG(ResponseTypes) 0086 0087 CAPAlertInfo(); 0088 CAPAlertInfo(const CAPAlertInfo &other); 0089 CAPAlertInfo(CAPAlertInfo &&other); 0090 ~CAPAlertInfo(); 0091 /** 0092 * The text denoting the type of the subject 0093 * event of the alert message 0094 */ 0095 QString event() const; 0096 /** 0097 * The effective time of the information of the alert message 0098 */ 0099 QDateTime effectiveTime() const; 0100 /** 0101 * The onset time of the information of the alert message 0102 */ 0103 QDateTime onsetTime() const; 0104 /** 0105 * The expire time of the information of the alert message 0106 */ 0107 QDateTime expireTime() const; 0108 /** 0109 * The text headline of the alert message 0110 */ 0111 QString headline() const; 0112 /** 0113 * The description of the alert message 0114 */ 0115 QString description() const; 0116 /** 0117 * The instruction of the alert message 0118 */ 0119 QString instruction() const; 0120 /** 0121 * The sender of the alert message 0122 */ 0123 QString sender() const; 0124 /** 0125 * The code denoting the language of the info 0126 * default to "en-US" 0127 * @return Natural language identifier per [RFC 3066]. 0128 */ 0129 QString language() const; 0130 /** 0131 * The category of the alert message 0132 * @return default to Unknown, value is bit or-ed 0133 */ 0134 Categories categories() const; 0135 /** 0136 * The urgency of the alert message 0137 * @return default to UnknownUrgency 0138 */ 0139 Urgency urgency() const; 0140 /** 0141 * The severity of the alert message 0142 * @return default to UnknownSeverity 0143 */ 0144 Severity severity() const; 0145 /** 0146 * The certainty of the alert message 0147 * @return default to UnknownCertainty 0148 */ 0149 Certainty certainty() const; 0150 /** 0151 * Type of action recommended for the target audience of the alert. 0152 */ 0153 ResponseTypes responseTypes() const; 0154 /** 0155 * Describing the contact for follow-up and confirmation of the alert message. 0156 */ 0157 QString contact() const; 0158 /** 0159 * Link associating additional information with the alert message. 0160 */ 0161 QString web() const; 0162 /** 0163 * The Parameter of the alert message 0164 * refer to CAP protocol v1.2 0165 */ 0166 const std::vector<CAPNamedValue> ¶meters() const; 0167 /** The areas targeted by this CAP alert message. */ 0168 const std::vector<CAPArea> &areas() const; 0169 /** System-specific codes for event typing. */ 0170 const std::vector<CAPNamedValue> &eventCodes() const; 0171 0172 ///@cond internal 0173 void setHeadline(const QString &headline); 0174 void setDescription(const QString &description); 0175 void setInstruction(const QString &instruction); 0176 void setSender(const QString &sender); 0177 void setLanguage(const QString &language); 0178 void addCategory(Category category); 0179 void setEvent(const QString &event); 0180 void setEffectiveTime(const QDateTime &time); 0181 void setOnsetTime(const QDateTime &time); 0182 void setExpireTime(const QDateTime &time); 0183 void setUrgency(Urgency urgency); 0184 void setSeverity(Severity severity); 0185 void setCertainty(Certainty certainty); 0186 void addResponseType(ResponseType responseType); 0187 void setContact(const QString &contact); 0188 void setWeb(const QString &web); 0189 void addParameter(CAPNamedValue &¶m); 0190 void addArea(CAPArea &&area); 0191 void addEventCode(CAPNamedValue &&code); 0192 ///@endcond 0193 0194 CAPAlertInfo &operator=(const CAPAlertInfo &other); 0195 CAPAlertInfo &operator=(CAPAlertInfo &&other); 0196 0197 private: 0198 QSharedDataPointer<CAPAlertInfoPrivate> d; 0199 }; 0200 } 0201 0202 Q_DECLARE_OPERATORS_FOR_FLAGS(KWeatherCore::CAPAlertInfo::Categories) 0203 Q_DECLARE_OPERATORS_FOR_FLAGS(KWeatherCore::CAPAlertInfo::ResponseTypes)