LeechCraft Azoth
0.6.70-19214-g121e5318a7
Modular multiprotocol IM plugin for LeechCraft
Toggle main menu visibility
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>
14
#include <
interfaces/azoth/imessage.h
>
15
16
namespace
LC
17
{
18
namespace
Azoth
19
{
20
enum class
IdKind
: std::uint8_t
21
{
22
Persistent
,
23
Conventional
,
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
44
using
EntryPersistentId
=
EntryId<IdKind::Persistent>
;
45
using
EntryConventionalId
=
EntryId<IdKind::Conventional>
;
46
47
template
<IdKind K>
48
struct
GlobalId
49
{
50
QString
AccountId_
;
51
EntryId<K>
EntryId_
;
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
60
using
GlobalPersistentId
=
GlobalId<IdKind::Persistent>
;
61
using
GlobalConventionalId
=
GlobalId<IdKind::Conventional>
;
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
88
using
EntryStrongestId
=
StrongestId<EntryId>
;
89
using
GlobalStrongestId
=
StrongestId<GlobalId>
;
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
105
enum
State
: std::uint8_t
106
{
107
SOffline
,
108
SOnline
,
109
SAway
,
110
SXA
,
111
SDND
,
112
SChat
,
113
SInvisible
,
114
SProbe
,
115
SError
,
116
SInvalid
,
117
122
SConnecting
123
};
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
152
enum
AuthStatus
153
{
157
ASNone
= 0x00,
158
161
ASFrom
= 0x01,
162
165
ASTo
= 0x02,
166
169
ASBoth
= 0x03,
170
173
ASContactRequested
= 0x08
174
};
175
180
enum
ChatPartState
: std::uint8_t
181
{
184
CPSNone
,
185
188
CPSActive
,
189
193
CPSInactive
,
194
198
CPSGone
,
199
202
CPSComposing
,
203
206
CPSPaused
207
};
208
211
struct
CustomStatus
212
{
215
QString
Name_
;
216
219
State
State_
;
220
223
QString
Text_
;
224
};
225
234
struct
EntryStatus
235
{
238
State
State_
=
SOffline
;
239
242
QString
StatusString_
{};
243
244
bool
operator==
(
const
EntryStatus
& es2)
const
=
default
;
245
};
246
}
247
}
248
249
Q_DECLARE_METATYPE (
LC::Azoth::ChatPartState
)
250
Q_DECLARE_METATYPE (
LC::Azoth::EntryStatus
)
251
Q_DECLARE_METATYPE (
LC::Azoth::State
)
imessage.h
LC::Azoth
Definition
activityinfo.h:16
LC::Azoth::IdKind
IdKind
Definition
azothcommon.h:21
LC::Azoth::IdKind::Persistent
@ Persistent
Definition
azothcommon.h:22
LC::Azoth::IdKind::Conventional
@ Conventional
Definition
azothcommon.h:23
LC::Azoth::State
State
Describes possible presence states of an account or a contact.
Definition
azothcommon.h:106
LC::Azoth::SInvalid
@ SInvalid
Definition
azothcommon.h:116
LC::Azoth::SXA
@ SXA
Definition
azothcommon.h:110
LC::Azoth::SOnline
@ SOnline
Definition
azothcommon.h:108
LC::Azoth::SError
@ SError
Definition
azothcommon.h:115
LC::Azoth::SOffline
@ SOffline
Definition
azothcommon.h:107
LC::Azoth::SConnecting
@ SConnecting
Definition
azothcommon.h:122
LC::Azoth::SChat
@ SChat
Definition
azothcommon.h:112
LC::Azoth::SProbe
@ SProbe
Definition
azothcommon.h:114
LC::Azoth::SAway
@ SAway
Definition
azothcommon.h:109
LC::Azoth::SDND
@ SDND
Definition
azothcommon.h:111
LC::Azoth::SInvisible
@ SInvisible
Definition
azothcommon.h:113
LC::Azoth::GlobalConventionalId
GlobalId< IdKind::Conventional > GlobalConventionalId
Definition
azothcommon.h:61
LC::Azoth::EntryConventionalId
EntryId< IdKind::Conventional > EntryConventionalId
Definition
azothcommon.h:45
LC::Azoth::AuthStatus
AuthStatus
Definition
azothcommon.h:153
LC::Azoth::ASBoth
@ ASBoth
Definition
azothcommon.h:169
LC::Azoth::ASTo
@ ASTo
Definition
azothcommon.h:165
LC::Azoth::ASFrom
@ ASFrom
Definition
azothcommon.h:161
LC::Azoth::ASContactRequested
@ ASContactRequested
Definition
azothcommon.h:173
LC::Azoth::ASNone
@ ASNone
Definition
azothcommon.h:157
LC::Azoth::EntryStrongestId
StrongestId< EntryId > EntryStrongestId
Definition
azothcommon.h:88
LC::Azoth::GlobalStrongestId
StrongestId< GlobalId > GlobalStrongestId
Definition
azothcommon.h:89
LC::Azoth::EntryPersistentId
EntryId< IdKind::Persistent > EntryPersistentId
Definition
azothcommon.h:44
LC::Azoth::IsLess
constexpr bool IsLess(State s1, State s2)
Compares two states according to the implied desire to have a conversation.
Definition
azothcommon.h:141
LC::Azoth::ChatPartState
ChatPartState
Definition
azothcommon.h:181
LC::Azoth::CPSActive
@ CPSActive
Definition
azothcommon.h:188
LC::Azoth::CPSInactive
@ CPSInactive
Definition
azothcommon.h:193
LC::Azoth::CPSComposing
@ CPSComposing
Definition
azothcommon.h:202
LC::Azoth::CPSPaused
@ CPSPaused
Definition
azothcommon.h:206
LC::Azoth::CPSNone
@ CPSNone
Definition
azothcommon.h:184
LC::Azoth::CPSGone
@ CPSGone
Definition
azothcommon.h:198
LC::Azoth::AsGlobalId
GlobalStrongestId AsGlobalId(const QString &accountId, const EntryStrongestId &entryId)
Definition
azothcommon.h:91
LC::Azoth::GlobalPersistentId
GlobalId< IdKind::Persistent > GlobalPersistentId
Definition
azothcommon.h:60
LC::Azoth::GetAccountId
QString GetAccountId(const GlobalStrongestId &strongestId)
Definition
azothcommon.h:97
LC
Definition
activityinfo.h:14
LC::Azoth::CustomStatus
A custom saved named status.
Definition
azothcommon.h:212
LC::Azoth::CustomStatus::Name_
QString Name_
The name of this status.
Definition
azothcommon.h:215
LC::Azoth::CustomStatus::State_
State State_
The state associated with this status.
Definition
azothcommon.h:219
LC::Azoth::CustomStatus::Text_
QString Text_
The status text associated with this status.
Definition
azothcommon.h:223
LC::Azoth::EntryId
Definition
azothcommon.h:28
LC::Azoth::EntryId::ToString
QString ToString() const
Definition
azothcommon.h:39
LC::Azoth::EntryId::EntryId
EntryId()=default
LC::Azoth::EntryId< IdKind::Persistent >::Id_
QString Id_
Definition
azothcommon.h:29
LC::Azoth::EntryId::FromString
static EntryId FromString(const QString &id)
Definition
azothcommon.h:33
LC::Azoth::EntryId::operator==
bool operator==(const EntryId &) const =default
LC::Azoth::EntryId::qHash
friend size_t qHash(const EntryId &id, size_t seed=0)
Definition
azothcommon.h:37
LC::Azoth::EntryStatus
Describes an entry's status.
Definition
azothcommon.h:235
LC::Azoth::EntryStatus::State_
State State_
The general state of the entry.
Definition
azothcommon.h:238
LC::Azoth::EntryStatus::StatusString_
QString StatusString_
The string of the entry accompanying its state.
Definition
azothcommon.h:242
LC::Azoth::EntryStatus::operator==
bool operator==(const EntryStatus &es2) const =default
LC::Azoth::GlobalId
Definition
azothcommon.h:49
LC::Azoth::GlobalId::qHash
friend size_t qHash(const GlobalId &id, size_t seed=0)
Definition
azothcommon.h:55
LC::Azoth::GlobalId< IdKind::Persistent >::AccountId_
QString AccountId_
Definition
azothcommon.h:50
LC::Azoth::GlobalId::operator==
bool operator==(const GlobalId &) const =default
LC::Azoth::GlobalId::ToString
QString ToString() const
Definition
azothcommon.h:57
LC::Azoth::GlobalId< IdKind::Persistent >::EntryId_
EntryId< K > EntryId_
Definition
azothcommon.h:51
LC::Azoth::StrongestId
Definition
azothcommon.h:65
LC::Azoth::StrongestId::ToString
QString ToString() const
Definition
azothcommon.h:77
LC::Azoth::StrongestId::qHash
friend size_t qHash(const StrongestId &strongestId, size_t seed=0)
Definition
azothcommon.h:71
LC::Azoth::StrongestId::Base
std::variant< Id< IdKind::Persistent >, Id< IdKind::Conventional > > Base
Definition
azothcommon.h:66
LC::Azoth::StrongestId::ToVariant
const Base & ToVariant() const
Definition
azothcommon.h:82
LC::Azoth::StrongestId::operator==
bool operator==(const StrongestId &) const =default
src
plugins
azoth
interfaces
azoth
azothcommon.h
Generated by
1.18.0