LeechCraft Azoth 0.6.70-19214-g121e5318a7
Modular multiprotocol IM plugin for LeechCraft
Loading...
Searching...
No Matches
azothcommon.h
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#pragma once
10
11#include <variant>
12#include <QHashFunctions>
13#include <QMetaType>
15
16namespace LC
17{
18namespace Azoth
19{
20 enum class IdKind : std::uint8_t
21 {
24 };
25
26 template<IdKind>
27 struct EntryId
28 {
29 QString Id_;
30
31 EntryId () = default;
32
33 static EntryId FromString (const QString& id) { return EntryId { id }; }
34
35 bool operator== (const EntryId&) const = default;
36
37 friend size_t qHash (const EntryId& id, size_t seed = 0) { return qHash (id.Id_, seed); }
38
39 [[nodiscard]] QString ToString () const { return Id_; }
40 private:
41 explicit EntryId (const QString& id) : Id_ { id } {}
42 };
43
46
47 template<IdKind K>
48 struct GlobalId
49 {
50 QString AccountId_;
52
53 bool operator== (const GlobalId&) const = default;
54
55 friend size_t qHash (const GlobalId& id, size_t seed = 0) { return qHashMulti (seed, id.AccountId_, id.EntryId_); }
56
57 [[nodiscard]] QString ToString () const { return AccountId_ + ':' + EntryId_.ToString (); }
58 };
59
62
63 template<template<IdKind> typename Id>
64 struct StrongestId : std::variant<Id<IdKind::Persistent>, Id<IdKind::Conventional>>
65 {
66 using Base = std::variant<Id<IdKind::Persistent>, Id<IdKind::Conventional>>;
67 using Base::Base;
68
69 bool operator== (const StrongestId&) const = default;
70
71 friend size_t qHash (const StrongestId& strongestId, size_t seed = 0)
72 {
73 const auto index = strongestId.index ();
74 return std::visit ([&] (const auto& id) { return qHashMulti (seed, index, id); }, strongestId.ToVariant ());
75 }
76
77 [[nodiscard]] QString ToString () const
78 {
79 return std::visit ([] (const auto& id) { return id.ToString (); }, *this);
80 }
81
82 [[nodiscard]] const Base& ToVariant () const
83 {
84 return *this;
85 }
86 };
87
90
91 inline GlobalStrongestId AsGlobalId (const QString& accountId, const EntryStrongestId& entryId)
92 {
93 return std::visit ([&accountId] (const auto& id) { return GlobalStrongestId { GlobalId { accountId, id } }; },
94 entryId);
95 }
96
97 inline QString GetAccountId (const GlobalStrongestId& strongestId)
98 {
99 return std::visit ([] (const auto& id) { return id.AccountId_; }, strongestId.ToVariant ());
100 }
101
124
141 constexpr bool IsLess (State s1, State s2)
142 {
143 constexpr int order [] = { 7, 3, 4, 5, 6, 1, 2, 8, 9, 10, 11 };
144 return order [s1] < order [s2];
145 }
146
153 {
157 ASNone = 0x00,
158
161 ASFrom = 0x01,
162
165 ASTo = 0x02,
166
169 ASBoth = 0x03,
170
174 };
175
180 enum ChatPartState : std::uint8_t
181 {
185
189
194
199
203
207 };
208
212 {
215 QString Name_;
216
220
223 QString Text_;
224 };
225
235 {
239
242 QString StatusString_ {};
243
244 bool operator== (const EntryStatus& es2) const = default;
245 };
246}
247}
248
249Q_DECLARE_METATYPE (LC::Azoth::ChatPartState)
250Q_DECLARE_METATYPE (LC::Azoth::EntryStatus)
251Q_DECLARE_METATYPE (LC::Azoth::State)
State
Describes possible presence states of an account or a contact.
GlobalId< IdKind::Conventional > GlobalConventionalId
Definition azothcommon.h:61
EntryId< IdKind::Conventional > EntryConventionalId
Definition azothcommon.h:45
@ ASContactRequested
StrongestId< EntryId > EntryStrongestId
Definition azothcommon.h:88
StrongestId< GlobalId > GlobalStrongestId
Definition azothcommon.h:89
EntryId< IdKind::Persistent > EntryPersistentId
Definition azothcommon.h:44
constexpr bool IsLess(State s1, State s2)
Compares two states according to the implied desire to have a conversation.
GlobalStrongestId AsGlobalId(const QString &accountId, const EntryStrongestId &entryId)
Definition azothcommon.h:91
GlobalId< IdKind::Persistent > GlobalPersistentId
Definition azothcommon.h:60
QString GetAccountId(const GlobalStrongestId &strongestId)
Definition azothcommon.h:97
A custom saved named status.
QString Name_
The name of this status.
State State_
The state associated with this status.
QString Text_
The status text associated with this status.
Definition azothcommon.h:28
QString ToString() const
Definition azothcommon.h:39
EntryId()=default
QString Id_
Definition azothcommon.h:29
static EntryId FromString(const QString &id)
Definition azothcommon.h:33
bool operator==(const EntryId &) const =default
friend size_t qHash(const EntryId &id, size_t seed=0)
Definition azothcommon.h:37
Describes an entry's status.
State State_
The general state of the entry.
QString StatusString_
The string of the entry accompanying its state.
bool operator==(const EntryStatus &es2) const =default
friend size_t qHash(const GlobalId &id, size_t seed=0)
Definition azothcommon.h:55
bool operator==(const GlobalId &) const =default
QString ToString() const
Definition azothcommon.h:57
QString ToString() const
Definition azothcommon.h:77
friend size_t qHash(const StrongestId &strongestId, size_t seed=0)
Definition azothcommon.h:71
std::variant< Id< IdKind::Persistent >, Id< IdKind::Conventional > > Base
Definition azothcommon.h:66
const Base & ToVariant() const
Definition azothcommon.h:82
bool operator==(const StrongestId &) const =default