-
Notifications
You must be signed in to change notification settings - Fork 1
/
privacylists.cpp
141 lines (126 loc) · 3.59 KB
/
privacylists.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "privacylists.h"
namespace Ireen {
class PrivacyListsPrivate
{
public:
Feedbag *feedbag;
};
static Visibility itemToVisibility(const FeedbagItem &item)
{
if (item.isNull())
return NoVisibility;
Visibility visibility = (Visibility)item.field<quint8>(0x00CA);
if (visibility >= NoVisibility && visibility <= AllowPermitList)
return visibility;
else
return NoVisibility;
}
PrivacyLists::PrivacyLists(Feedbag *feedbag) :
QObject(feedbag), d(new PrivacyListsPrivate)
{
d->feedbag = feedbag;
m_types << SsiPermit << SsiDeny << SsiIgnore << SsiVisibility;
feedbag->registerHandler(this);
}
PrivacyLists::~PrivacyLists()
{
}
Visibility PrivacyLists::visibility()
{
FeedbagItem item = d->feedbag->itemByType(SsiVisibility);
return itemToVisibility(item);
}
void PrivacyLists::setVisibility(Visibility visibility)
{
FeedbagItem item = d->feedbag->itemByType(SsiVisibility, Feedbag::CreateItem);
TLV data = item.field(0x00CA);
if (data.read<quint8>() != visibility) {
item.setField<quint8>(0x00CA, visibility);
item.updateOrAdd();
}
}
bool PrivacyLists::isInList(const QString &uin, PrivacyListType list)
{
Q_ASSERT(list == VisibleList || list == InvisibleList || list == IgnoreList);
return d->feedbag->containsItem(list, uin);
}
void PrivacyLists::addToList(const QString &uin, PrivacyListType list)
{
Q_ASSERT(list == VisibleList || list == InvisibleList || list == IgnoreList);
FeedbagItem item = d->feedbag->item(list, uin, 0, Feedbag::CreateItem);
if (!item.isInList())
item.add();
}
void PrivacyLists::removeFromList(const QString &uin, PrivacyListType list)
{
Q_ASSERT(list == VisibleList || list == InvisibleList || list == IgnoreList);
FeedbagItem item = d->feedbag->item(list, uin);
if (item.isInList())
item.remove();
}
QString PrivacyLists::visibilityToString(Visibility visibility)
{
switch (visibility) {
case AllowAllUsers:
return QT_TRANSLATE_NOOP("Privacy", "Visible for all");
case BlockAllUsers:
return QT_TRANSLATE_NOOP("Privacy", "Invisible for all");
case AllowPermitList:
return QT_TRANSLATE_NOOP("Privacy", "Visible only for visible list");
case BlockDenyList:
return QT_TRANSLATE_NOOP("Privacy", "Invisible only for invisible list");
case AllowContactList:
return QT_TRANSLATE_NOOP("Privacy", "Visible only for contact list");
default:
return QT_TRANSLATE_NOOP("Privacy", "Unknown privacy");
}
}
bool PrivacyLists::handleFeedbagItem(Feedbag *feedbag, const FeedbagItem &item, Feedbag::ModifyType type, FeedbagError error)
{
Q_UNUSED(feedbag);
if (error != FeedbagError::NoError)
return false;
bool isItemAdded = type != Feedbag::Remove;
PrivacyListType listType;
switch (item.type()) {
case SsiVisibility: {
Visibility newVisibility = isItemAdded
? itemToVisibility(item)
: NoVisibility;
emit visibilityChanged(newVisibility);
return true;
}
case SsiPermit: {
if (isItemAdded)
debug() << item.name() << "has been added to visible list";
else
debug() << item.name() << "has been removed from visible list";
listType = VisibleList;
break;
}
case SsiDeny: {
if (isItemAdded)
debug() << item.name() << "has been added to invisible list";
else
debug() << item.name() << "has been removed from invisible list";
listType = InvisibleList;
break;
}
case SsiIgnore: {
if (isItemAdded)
debug() << item.name() << "has been added to ignore list";
else
debug() << item.name() << "has been removed from ignore list";
listType = IgnoreList;
break;
default:
return false;
}
}
if (isItemAdded)
emit contactAdded(item.name(), listType);
else
emit contactRemoved(item.name(), listType);
return true;
}
} // namespace Ireen