libQuotient
A Qt library for building matrix clients
quotient_common.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2019 Kitsune Ral <Kitsune-Ral@users.sf.net>
2 // SPDX-License-Identifier: LGPL-2.1-or-later
3 
4 #pragma once
5 
6 #include "quotient_export.h"
7 
8 #include <qobjectdefs.h>
9 #include "util.h"
10 
11 #include <array>
12 
13 
14 //! \brief Quotient replacement for the Q_FLAG/Q_DECLARE_FLAGS combination
15 //!
16 //! Although the comment in QTBUG-82295 says that Q_FLAG[_NS] "should" be
17 //! applied to the enum type only, Qt then doesn't allow to wrap the
18 //! corresponding flag type (defined with Q_DECLARE_FLAGS) into a QVariant.
19 //! This macro defines Q_FLAG and on top of that adds Q_ENUM_IMPL which is
20 //! a part of Q_ENUM() macro that enables the metatype data but goes under
21 //! the moc radar to avoid double registration of the same data in the map
22 //! defined in moc_*.cpp.
23 //!
24 //! Simply put, instead of using Q_FLAG/Q_DECLARE_FLAGS combo (and struggling
25 //! to figure out what you should pass to Q_FLAG if you want to make it
26 //! wrappable in a QVariant) use the macro below, and things will just work.
27 //!
28 //! \sa https://bugreports.qt.io/browse/QTBUG-82295
29 #define QUO_DECLARE_FLAGS(Flags, Enum)
30  Q_DECLARE_FLAGS(Flags, Enum)
31  Q_ENUM_IMPL(Enum)
32  Q_FLAG(Flags)
33 
34 //! \brief Quotient replacement for the Q_FLAG_NS/Q_DECLARE_FLAGS combination
35 //!
36 //! This is the equivalent of QUO_DECLARE_FLAGS for enums declared at the
37 //! namespace level (be sure to provide Q_NAMESPACE _in the same file_
38 //! as the enum definition and this macro).
39 //! \sa QUO_DECLARE_FLAGS
40 #define QUO_DECLARE_FLAGS_NS(Flags, Enum)
41  Q_DECLARE_FLAGS(Flags, Enum)
42  Q_ENUM_NS_IMPL(Enum)
43  Q_FLAG_NS(Flags)
44 
45 namespace Quotient {
46 Q_NAMESPACE_EXPORT(QUOTIENT_API)
47 
48 // TODO: code like this should be generated from the CS API definition
49 
50 //! \brief Membership states
51 //!
52 //! These are used for member events. The names here are case-insensitively
53 //! equal to state names used on the wire.
54 //! \sa MemberEventContent, RoomMemberEvent
55 enum class Membership : uint16_t {
56  // Specific power-of-2 values (1,2,4,...) are important here as syncdata.cpp
57  // depends on that, as well as Join being the first in line
58  Invalid = 0x0,
59  Join = 0x1,
60  Leave = 0x2,
61  Invite = 0x4,
62  Knock = 0x8,
63  Ban = 0x10,
64  Undefined = Invalid
65 };
66 QUO_DECLARE_FLAGS_NS(MembershipMask, Membership)
67 
68 constexpr std::array MembershipStrings {
69  // The order MUST be the same as the order in the Membership enum
70  "join"_ls, "leave"_ls, "invite"_ls, "knock"_ls, "ban"_ls
71 };
72 
73 //! \brief Local user join-state names
74 //!
75 //! This represents a subset of Membership values that may arrive as the local
76 //! user's state grouping for the sync response.
77 //! \sa SyncData
78 enum class JoinState : std::underlying_type_t<Membership> {
79  Invalid = std::underlying_type_t<Membership>(Membership::Invalid),
80  Join = std::underlying_type_t<Membership>(Membership::Join),
81  Leave = std::underlying_type_t<Membership>(Membership::Leave),
82  Invite = std::underlying_type_t<Membership>(Membership::Invite),
83  Knock = std::underlying_type_t<Membership>(Membership::Knock),
84 };
85 QUO_DECLARE_FLAGS_NS(JoinStates, JoinState)
86 
87 [[maybe_unused]] constexpr std::array JoinStateStrings {
88  MembershipStrings[0], MembershipStrings[1], MembershipStrings[2],
89  MembershipStrings[3] /* same as MembershipStrings, sans "ban" */
90 };
91 
92 //! \brief Network job running policy flags
93 //!
94 //! So far only background/foreground flags are available.
95 //! \sa Connection::callApi, Connection::run
96 enum RunningPolicy { ForegroundRequest = 0x0, BackgroundRequest = 0x1 };
97 Q_ENUM_NS(RunningPolicy)
98 
99 //! \brief The result of URI resolution using UriResolver
100 //! \sa UriResolver
101 enum UriResolveResult : int8_t {
102  StillResolving = -1,
103  UriResolved = 0,
104  CouldNotResolve,
105  IncorrectAction,
106  InvalidUri,
107  NoAccount
108 };
109 Q_ENUM_NS(UriResolveResult)
110 
111 enum class RoomType : uint8_t {
112  Space = 0,
113  Undefined = 0xFF,
114 };
115 Q_ENUM_NS(RoomType)
116 
117 [[maybe_unused]] constexpr std::array RoomTypeStrings { "m.space"_ls };
118 
119 enum class EncryptionType : uint8_t {
120  MegolmV1AesSha2 = 0,
121  Undefined = 0xFF,
122 };
123 Q_ENUM_NS(EncryptionType)
124 
125 } // namespace Quotient
126 Q_DECLARE_OPERATORS_FOR_FLAGS(Quotient::MembershipMask)
127 Q_DECLARE_OPERATORS_FOR_FLAGS(Quotient::JoinStates)