1 /****************************************************************************** 2 * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN 3 */ 4 5 #pragma once 6 7 #include "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<>(jo, QStringLiteral("regexp"), pod.regexp); 26 addParam<>(jo, QStringLiteral("placeholder"), pod.placeholder); 27 } 28 static void fillFrom(const QJsonObject& jo, FieldType& pod) 29 { 30 fromJson(jo.value("regexp"_ls), pod.regexp); 31 fromJson(jo.value("placeholder"_ls), 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 /// An optional content URI representing the protocol. Overrides the one 40 /// provided at the higher level Protocol object. 41 QString icon; 42 43 /// Preset values for `fields` the client may use to search by. 44 QJsonObject fields; 45 46 /// A unique identifier across all instances. 47 QString networkId; 48 }; 49 50 template <> 51 struct JsonObjectConverter<ProtocolInstance> { 52 static void dumpTo(QJsonObject& jo, const ProtocolInstance& pod) 53 { 54 addParam<>(jo, QStringLiteral("desc"), pod.desc); 55 addParam<IfNotEmpty>(jo, QStringLiteral("icon"), pod.icon); 56 addParam<>(jo, QStringLiteral("fields"), pod.fields); 57 addParam<>(jo, QStringLiteral("network_id"), pod.networkId); 58 } 59 static void fillFrom(const QJsonObject& jo, ProtocolInstance& pod) 60 { 61 fromJson(jo.value("desc"_ls), pod.desc); 62 fromJson(jo.value("icon"_ls), pod.icon); 63 fromJson(jo.value("fields"_ls), pod.fields); 64 fromJson(jo.value("network_id"_ls), pod.networkId); 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<>(jo, QStringLiteral("user_fields"), pod.userFields); 102 addParam<>(jo, QStringLiteral("location_fields"), pod.locationFields); 103 addParam<>(jo, QStringLiteral("icon"), pod.icon); 104 addParam<>(jo, QStringLiteral("field_types"), pod.fieldTypes); 105 addParam<>(jo, QStringLiteral("instances"), pod.instances); 106 } 107 static void fillFrom(const QJsonObject& jo, ThirdPartyProtocol& pod) 108 { 109 fromJson(jo.value("user_fields"_ls), pod.userFields); 110 fromJson(jo.value("location_fields"_ls), pod.locationFields); 111 fromJson(jo.value("icon"_ls), pod.icon); 112 fromJson(jo.value("field_types"_ls), pod.fieldTypes); 113 fromJson(jo.value("instances"_ls), pod.instances); 114 } 115 }; 116 117 } // namespace Quotient 118