LeechCraft Azoth 0.6.70-18808-g3467692359
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 QString GetAccountId (const GlobalStrongestId& strongestId)
92 {
93 return std::visit ([] (const auto& id) { return id.AccountId_; }, strongestId.ToVariant ());
94 }
95
118
135 inline bool IsLess (State s1, State s2)
136 {
137 constexpr int order [] = { 7, 3, 4, 5, 6, 1, 2, 8, 9, 10 };
138 return order [s1] < order [s2];
139 }
140
147 {
151 ASNone = 0x00,
152
155 ASFrom = 0x01,
156
159 ASTo = 0x02,
160
163 ASBoth = 0x03,
164
168 };
169
174 enum ChatPartState : std::uint8_t
175 {
179
183
188
193
197
201 };
202
206 {
209 QString Name_;
210
214
217 QString Text_;
218 };
219
229 {
233
236 QString StatusString_ {};
237
238 bool operator== (const EntryStatus& es2) const = default;
239 };
240}
241}
242
243Q_DECLARE_METATYPE (LC::Azoth::ChatPartState)
244Q_DECLARE_METATYPE (LC::Azoth::EntryStatus)
245Q_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
bool IsLess(State s1, State s2)
Compares two states according to the implied desire to have a conversation.
@ ASContactRequested
StrongestId< EntryId > EntryStrongestId
Definition azothcommon.h:88
StrongestId< GlobalId > GlobalStrongestId
Definition azothcommon.h:89
EntryId< IdKind::Persistent > EntryPersistentId
Definition azothcommon.h:44
GlobalId< IdKind::Persistent > GlobalPersistentId
Definition azothcommon.h:60
QString GetAccountId(const GlobalStrongestId &strongestId)
Definition azothcommon.h:91
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