File indexing completed on 2024-04-28 04:42:41
0001 /* 0002 * SPDX-FileCopyrightText: 2021 Anjani Kumar <anjanik012@gmail.com> 0003 * SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 #pragma once 0007 #include "kweathercore/kweathercore_export.h" 0008 0009 #include <QDateTime> 0010 #include <QMetaType> 0011 #include <QSharedDataPointer> 0012 #include <vector> 0013 0014 namespace KWeatherCore 0015 { 0016 class CAPAlertInfo; 0017 class CAPAlertMessagePrivate; 0018 class CAPReference; 0019 /** 0020 * @short Represents a single CAP Alert Message 0021 * 0022 * This class contains the information of a parsed CAP alert message. 0023 * @see CAPAlertInfo 0024 * @see https://docs.oasis-open.org/emergency/cap/v1.2/CAP-v1.2.html $3.2.1 0025 * 0026 * @author Anjani Kumar <anjanik012@gmail.com> 0027 */ 0028 class KWEATHERCORE_EXPORT CAPAlertMessage 0029 { 0030 Q_GADGET 0031 Q_PROPERTY(QString identifier READ identifier) 0032 Q_PROPERTY(QString sender READ sender) 0033 Q_PROPERTY(QDateTime sentTime READ sentTime) 0034 Q_PROPERTY(QString note READ note) 0035 Q_PROPERTY(Status status READ status) 0036 Q_PROPERTY(MessageType messageType READ messageType) 0037 Q_PROPERTY(Scope scope READ scope) 0038 public: 0039 /** The code denoting the appropriate handling of the alert message. */ 0040 enum class Status { 0041 UnknownStatus, 0042 Actual, ///< Actionable by all targeted recipients 0043 Exercise, ///< Actionable only by designated exercise participants 0044 System, //< For messages that support alert network internal functions 0045 Test, ///< Technical testing only, all recipients disregard 0046 Draft, ///< A preliminary template or draft, not actionable in its current form 0047 }; 0048 Q_ENUM(Status) 0049 enum class MessageType { 0050 UnknownMessageType, 0051 Alert, ///< Initial information requiring attention by targeted recipients 0052 Update, ///< Updates and supercedes the earlier message(s) identified in references() 0053 Cancel, ///< Cancels the earlier message(s) identified in references() 0054 Acknowledge, ///< Acknowledges receipt and acceptance of the message(s) identified in references() 0055 Error, ///< Indicates rejection of the message(s) identified in references() 0056 }; 0057 Q_ENUM(MessageType) 0058 enum class Scope { 0059 UnknownScope, 0060 Public, ///< For general dissemination to unrestricted audiences 0061 Restricted, ///< For dissemination only to users with a known operational requirement 0062 Private, ///< For dissemination only to specified addresses 0063 }; 0064 Q_ENUM(Scope) 0065 0066 /** 0067 * Default constructor, Status, MsgType, Scope 0068 * are set to Unknown 0069 */ 0070 CAPAlertMessage(); 0071 CAPAlertMessage(const CAPAlertMessage &other); 0072 CAPAlertMessage(CAPAlertMessage &&other); 0073 ~CAPAlertMessage(); 0074 0075 /** 0076 * Unique alert message identifier. 0077 */ 0078 QString identifier() const; 0079 /** 0080 * The identifier of the sender of the alert message. 0081 */ 0082 QString sender() const; 0083 /** 0084 * The time and date of the origination of the alert message. 0085 */ 0086 QDateTime sentTime() const; 0087 /** 0088 * The code denoting the appropriate handling of the alert message. 0089 * Returns UnknownStatus if not set. 0090 */ 0091 Status status() const; 0092 /** 0093 * The code denoting the nature of the alert message. 0094 * Returns UnknownMsgType if not set. 0095 */ 0096 MessageType messageType() const; 0097 /** 0098 * The code denoting the intended distribution of the alert message. 0099 * Returns UnknownScope if not set. 0100 */ 0101 Scope scope() const; 0102 /** 0103 * The text describing the purpose or significance of the alert message. 0104 * Relevant for Exercise and Error status. 0105 */ 0106 QString note() const; 0107 /** 0108 * The alert info elements of this alert message. 0109 * @see CAPAlertInfo 0110 */ 0111 const std::vector<CAPAlertInfo> &alertInfos() const; 0112 /** 0113 * References to previous CAP alert messages. 0114 * Relevant for Update, Cancel and Ack message types. 0115 */ 0116 const std::vector<CAPReference> &references() const; 0117 /** 0118 * Reference of this CAP alert message. 0119 * @see references() 0120 */ 0121 CAPReference ownReference() const; 0122 0123 ///@cond internal 0124 // only for internal use by CAPParser 0125 void setIdentifier(const QString &identifier); 0126 void setSender(const QString &sender); 0127 void setSentTime(const QDateTime &dateTime); 0128 void setStatus(Status status); 0129 void setMessageType(MessageType msgType); 0130 void setScope(Scope scope); 0131 void setNote(const QString ¬e); 0132 void addInfo(CAPAlertInfo &&alertInfo); 0133 void setReferences(std::vector<CAPReference> &&references); 0134 ///@endcond 0135 0136 CAPAlertMessage &operator=(const CAPAlertMessage &other); 0137 CAPAlertMessage &operator=(CAPAlertMessage &&other); 0138 0139 private: 0140 QSharedDataPointer<CAPAlertMessagePrivate> d; 0141 }; 0142 } 0143 0144 Q_DECLARE_METATYPE(KWeatherCore::CAPAlertMessage)