1 | /****************************************************************************** |
2 | * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN |
3 | */ |
4 | |
5 | #pragma once |
6 | |
7 | #include <Quotient/converters.h> |
8 | |
9 | namespace Quotient { |
10 | /// Definition of valid values for a field. |
11 | struct FieldType { |
12 | /// A regular expression for validation of a field's value. This may be |
13 | /// relatively coarse to verify the value as the application service |
14 | /// providing this protocol may apply additional validation or filtering. |
15 | QString regexp; |
16 | |
17 | /// An placeholder serving as a valid example of the field value. |
18 | QString placeholder; |
19 | }; |
20 | |
21 | template <> |
22 | struct JsonObjectConverter<FieldType> { |
23 | static void dumpTo(QJsonObject& jo, const FieldType& pod) |
24 | { |
25 | addParam<>(container&: jo, QStringLiteral("regexp" ), value: pod.regexp); |
26 | addParam<>(container&: jo, QStringLiteral("placeholder" ), value: pod.placeholder); |
27 | } |
28 | static void fillFrom(const QJsonObject& jo, FieldType& pod) |
29 | { |
30 | fillFromJson(jv: jo.value(key: "regexp"_ls ), pod&: pod.regexp); |
31 | fillFromJson(jv: jo.value(key: "placeholder"_ls ), pod&: pod.placeholder); |
32 | } |
33 | }; |
34 | |
35 | struct ProtocolInstance { |
36 | /// A human-readable description for the protocol, such as the name. |
37 | QString desc; |
38 | |
39 | /// Preset values for `fields` the client may use to search by. |
40 | QJsonObject fields; |
41 | |
42 | /// A unique identifier across all instances. |
43 | QString networkId; |
44 | |
45 | /// An optional content URI representing the protocol. Overrides the one |
46 | /// provided at the higher level Protocol object. |
47 | QString icon{}; |
48 | }; |
49 | |
50 | template <> |
51 | struct JsonObjectConverter<ProtocolInstance> { |
52 | static void dumpTo(QJsonObject& jo, const ProtocolInstance& pod) |
53 | { |
54 | addParam<>(container&: jo, QStringLiteral("desc" ), value: pod.desc); |
55 | addParam<>(container&: jo, QStringLiteral("fields" ), value: pod.fields); |
56 | addParam<>(container&: jo, QStringLiteral("network_id" ), value: pod.networkId); |
57 | addParam<IfNotEmpty>(container&: jo, QStringLiteral("icon" ), value: pod.icon); |
58 | } |
59 | static void fillFrom(const QJsonObject& jo, ProtocolInstance& pod) |
60 | { |
61 | fillFromJson(jv: jo.value(key: "desc"_ls ), pod&: pod.desc); |
62 | fillFromJson(jv: jo.value(key: "fields"_ls ), pod&: pod.fields); |
63 | fillFromJson(jv: jo.value(key: "network_id"_ls ), pod&: pod.networkId); |
64 | fillFromJson(jv: jo.value(key: "icon"_ls ), pod&: pod.icon); |
65 | } |
66 | }; |
67 | |
68 | struct ThirdPartyProtocol { |
69 | /// Fields which may be used to identify a third-party user. These should be |
70 | /// ordered to suggest the way that entities may be grouped, where higher |
71 | /// groupings are ordered first. For example, the name of a network should |
72 | /// be searched before the nickname of a user. |
73 | QStringList userFields; |
74 | |
75 | /// Fields which may be used to identify a third-party location. These |
76 | /// should be ordered to suggest the way that entities may be grouped, where |
77 | /// higher groupings are ordered first. For example, the name of a network |
78 | /// should be searched before the name of a channel. |
79 | QStringList locationFields; |
80 | |
81 | /// A content URI representing an icon for the third-party protocol. |
82 | QString icon; |
83 | |
84 | /// The type definitions for the fields defined in the `user_fields` and |
85 | /// `location_fields`. Each entry in those arrays MUST have an entry here. |
86 | /// The `string` key for this object is field name itself. |
87 | /// |
88 | /// May be an empty object if no fields are defined. |
89 | QHash<QString, FieldType> fieldTypes; |
90 | |
91 | /// A list of objects representing independent instances of configuration. |
92 | /// For example, multiple networks on IRC if multiple are provided by the |
93 | /// same application service. |
94 | QVector<ProtocolInstance> instances; |
95 | }; |
96 | |
97 | template <> |
98 | struct JsonObjectConverter<ThirdPartyProtocol> { |
99 | static void dumpTo(QJsonObject& jo, const ThirdPartyProtocol& pod) |
100 | { |
101 | addParam<>(container&: jo, QStringLiteral("user_fields" ), value: pod.userFields); |
102 | addParam<>(container&: jo, QStringLiteral("location_fields" ), value: pod.locationFields); |
103 | addParam<>(container&: jo, QStringLiteral("icon" ), value: pod.icon); |
104 | addParam<>(container&: jo, QStringLiteral("field_types" ), value: pod.fieldTypes); |
105 | addParam<>(container&: jo, QStringLiteral("instances" ), value: pod.instances); |
106 | } |
107 | static void fillFrom(const QJsonObject& jo, ThirdPartyProtocol& pod) |
108 | { |
109 | fillFromJson(jv: jo.value(key: "user_fields"_ls ), pod&: pod.userFields); |
110 | fillFromJson(jv: jo.value(key: "location_fields"_ls ), pod&: pod.locationFields); |
111 | fillFromJson(jv: jo.value(key: "icon"_ls ), pod&: pod.icon); |
112 | fillFromJson(jv: jo.value(key: "field_types"_ls ), pod&: pod.fieldTypes); |
113 | fillFromJson(jv: jo.value(key: "instances"_ls ), pod&: pod.instances); |
114 | } |
115 | }; |
116 | |
117 | } // namespace Quotient |
118 | |