KWeatherCore

capparser.h
1 /*
2  * SPDX-FileCopyrightText: 2021 Anjani Kumar <[email protected]>
3  * SPDX-FileCopyrightText: 2021 Han Young <[email protected]>
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 #pragma once
8 #include "alertentry.h"
9 #include "alertinfo.h"
10 
11 #include <QHash>
12 #include <QObject>
13 #include <QXmlStreamReader>
14 
15 #include <memory>
16 
17 namespace KWeatherCore
18 {
19 class CAPParser
20 {
21 public:
22  explicit CAPParser(const QByteArray &data = {});
23  void setData(const QByteArray &data);
24  std::unique_ptr<AlertEntry> parse();
25 
26 private:
27  AlertInfo parseInfo();
28  QXmlStreamReader m_xml;
29  enum class Tags { ALERT, IDENTIFIER, SENDER, SENT_TIME, STATUS, MSG_TYPE, SCOPE, NOTE, INFO };
30  inline const static QHash<QString, Tags> tags{{QStringLiteral("alert"), Tags::ALERT},
31  {QStringLiteral("identifier"), Tags::IDENTIFIER},
32  {QStringLiteral("sender"), Tags::SENDER},
33  {QStringLiteral("sent"), Tags::SENT_TIME},
34  {QStringLiteral("msgType"), Tags::MSG_TYPE},
35  {QStringLiteral("status"), Tags::STATUS},
36  {QStringLiteral("scope"), Tags::SCOPE},
37  {QStringLiteral("note"), Tags::NOTE},
38  {QStringLiteral("info"), Tags::INFO}};
39 
40  enum class InfoTags {
41  HEADLINE,
42  DESCRIPTION,
43  EVENT,
44  EFFECTIVE_TIME,
45  ONSET_TIME,
46  EXPIRE_TIME,
47  CATEGORY,
48  INSTRUCTION,
49  URGENCY,
50  SEVERITY,
51  CERTAINITY,
52  PARAMETER,
53  AREA,
54  SENDERNAME,
55  LANGUAGE
56  };
57 
58  inline const static QHash<QString, InfoTags> infoTags = {{QStringLiteral("category"), InfoTags::CATEGORY},
59  {QStringLiteral("event"), InfoTags::EVENT},
60  {QStringLiteral("urgency"), InfoTags::URGENCY},
61  {QStringLiteral("severity"), InfoTags::SEVERITY},
62  {QStringLiteral("certainty"), InfoTags::CERTAINITY},
63  {QStringLiteral("effective"), InfoTags::EFFECTIVE_TIME},
64  {QStringLiteral("onset"), InfoTags::ONSET_TIME},
65  {QStringLiteral("expires"), InfoTags::EXPIRE_TIME},
66  {QStringLiteral("headline"), InfoTags::HEADLINE},
67  {QStringLiteral("description"), InfoTags::DESCRIPTION},
68  {QStringLiteral("instruction"), InfoTags::INSTRUCTION},
69  {QStringLiteral("area"), InfoTags::AREA},
70  {QStringLiteral("senderName"), InfoTags::SENDERNAME},
71  {QStringLiteral("language"), InfoTags::LANGUAGE}};
72 
73  // constexpr hashmap when?
74  inline const static QHash<QString, AlertInfo::Category> categoryMap = {{QStringLiteral("Geo"), AlertInfo::Category::Geo},
75  {QStringLiteral("Met"), AlertInfo::Category::Met},
76  {QStringLiteral("Safety"), AlertInfo::Category::Safety},
77  {QStringLiteral("Security"), AlertInfo::Category::Security},
78  {QStringLiteral("Rescue"), AlertInfo::Category::Rescue},
79  {QStringLiteral("Fire"), AlertInfo::Category::Fire},
80  {QStringLiteral("Health"), AlertInfo::Category::Health},
81  {QStringLiteral("Env"), AlertInfo::Category::Env},
82  {QStringLiteral("Transport"), AlertInfo::Category::Transport},
83  {QStringLiteral("Infra"), AlertInfo::Category::Infra},
84  {QStringLiteral("CBRNE"), AlertInfo::Category::CBRNE},
85  {QStringLiteral("Other"), AlertInfo::Category::Other}};
86 };
87 }
KHEALTHCERTIFICATE_EXPORT QVariant parse(const QByteArray &data)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Oct 21 2021 23:05:33 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.