File indexing completed on 2024-05-12 04:01:32
0001 /* 0002 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org> 0003 SPDX-FileCopyrightText: 2023 Kai Uwe Broulik <kde@broulik.de> 0004 SPDX-License-Identifier: MIT 0005 */ 0006 0007 #ifndef PRISON_MECARD_H 0008 #define PRISON_MECARD_H 0009 0010 #include <QString> 0011 #include <QStringList> 0012 #include <QVariantMap> 0013 0014 #include "prison_export.h" 0015 0016 #include <memory> 0017 #include <optional> 0018 0019 namespace Prison 0020 { 0021 0022 /** Parser for the MeCard format. 0023 * This was originally used for a more compact vCard representation, but today 0024 * is mostly relevant for Wifi configuration QR codes. 0025 * @see https://en.wikipedia.org/wiki/MeCard_(QR_code) 0026 * @see https://github.com/zxing/zxing/wiki/Barcode-Contents#wi-fi-network-config-android-ios-11 0027 * @since 5.101 0028 */ 0029 class PRISON_EXPORT MeCard 0030 { 0031 public: 0032 /** 0033 * Move constructor 0034 */ 0035 MeCard(MeCard &&other) noexcept; 0036 /** 0037 * Move assignment 0038 */ 0039 MeCard &operator=(MeCard &&other) noexcept; 0040 /** 0041 * Destructor 0042 */ 0043 ~MeCard(); 0044 0045 /** 0046 * Parse the given string 0047 * @param data The string to parse 0048 * @return A MeCard, if parsing was successful, a nullopt otherwise. 0049 */ 0050 static std::optional<MeCard> parse(const QString &data); 0051 0052 /** 0053 * Get the MeCard header. 0054 * 0055 * If you just want to identify the card, 0056 * use headerView() instead. 0057 */ 0058 QString header() const; 0059 /** 0060 * Get the MeCard header as a string view. 0061 * 0062 * Useful for identifying the type of card. 0063 */ 0064 QStringView headerView() const; 0065 /** 0066 * Get the value for a given key. 0067 * 0068 * Convenience method for getting the first value 0069 * if only one value is expected. 0070 */ 0071 QString value(QStringView key) const; 0072 /** 0073 * Get the list of values for a given key. 0074 * @return The list of values for the given key 0075 */ 0076 QStringList values(QStringView key) const; 0077 0078 /** 0079 * Get the parsed data as QVariantMap. 0080 */ 0081 QVariantMap toVariantMap() const; 0082 0083 private: 0084 explicit MeCard(); 0085 0086 friend class MeCardPrivate; 0087 std::unique_ptr<class MeCardPrivate> d; 0088 }; 0089 0090 } // namespace Prison 0091 0092 #endif // PRISON_MECARD_H