Prison

mecard.h
1/*
2 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
3 SPDX-FileCopyrightText: 2023 Kai Uwe Broulik <kde@broulik.de>
4 SPDX-License-Identifier: MIT
5*/
6
7#ifndef PRISON_MECARD_H
8#define PRISON_MECARD_H
9
10#include <QString>
11#include <QStringList>
12#include <QVariantMap>
13
14#include "prison_export.h"
15
16#include <memory>
17#include <optional>
18
19namespace Prison
20{
21
22/** Parser for the MeCard format.
23 * This was originally used for a more compact vCard representation, but today
24 * is mostly relevant for Wifi configuration QR codes.
25 * @see https://en.wikipedia.org/wiki/MeCard_(QR_code)
26 * @see https://github.com/zxing/zxing/wiki/Barcode-Contents#wi-fi-network-config-android-ios-11
27 * @since 5.101
28 */
29class PRISON_EXPORT MeCard
30{
31public:
32 /**
33 * Move constructor
34 */
35 MeCard(MeCard &&other) noexcept;
36 /**
37 * Move assignment
38 */
39 MeCard &operator=(MeCard &&other) noexcept;
40 /**
41 * Destructor
42 */
44
45 /**
46 * Parse the given string
47 * @param data The string to parse
48 * @return A MeCard, if parsing was successful, a nullopt otherwise.
49 */
50 static std::optional<MeCard> parse(const QString &data);
51
52 /**
53 * Get the MeCard header.
54 *
55 * If you just want to identify the card,
56 * use headerView() instead.
57 */
58 QString header() const;
59 /**
60 * Get the MeCard header as a string view.
61 *
62 * Useful for identifying the type of card.
63 */
64 QStringView headerView() const;
65 /**
66 * Get the value for a given key.
67 *
68 * Convenience method for getting the first value
69 * if only one value is expected.
70 */
71 QString value(QStringView key) const;
72 /**
73 * Get the list of values for a given key.
74 * @return The list of values for the given key
75 */
76 QStringList values(QStringView key) const;
77
78 /**
79 * Get the parsed data as QVariantMap.
80 */
81 QVariantMap toVariantMap() const;
82
83private:
84 explicit MeCard();
85
86 friend class MeCardPrivate;
87 std::unique_ptr<class MeCardPrivate> d;
88};
89
90} // namespace Prison
91
92#endif // PRISON_MECARD_H
Parser for the MeCard format.
Definition mecard.h:30
~MeCard()
Destructor.
Provides classes and methods for generating barcodes.
Definition barcode.h:24
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 10 2024 11:43:48 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.