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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/Controllers/Roster/ContactRosterItem.h>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <Swiften/Base/DateTime.h>
#include <Swiften/Elements/Idle.h>
#include <Swiften/Elements/Presence.h>
#include <Swift/Controllers/Intl.h>
#include <Swift/Controllers/Roster/GroupRosterItem.h>
namespace Swift {
ContactRosterItem::ContactRosterItem(const JID& jid, const JID& displayJID, const std::string& name, GroupRosterItem* parent)
: RosterItem(name, parent), jid_(jid), displayJID_(displayJID.toBare()), mucRole_(MUCOccupant::NoRole), mucAffiliation_(MUCOccupant::NoAffiliation), blockState_(BlockingNotSupported)
{
}
ContactRosterItem::~ContactRosterItem() {
}
StatusShow::Type ContactRosterItem::getStatusShow() const {
return presence_ ? presence_->getShow() : StatusShow::None;
}
StatusShow::Type ContactRosterItem::getSimplifiedStatusShow() const {
switch (presence_ ? presence_->getShow() : StatusShow::None) {
case StatusShow::Online: return StatusShow::Online;
case StatusShow::Away: return StatusShow::Away;
case StatusShow::XA: return StatusShow::Away;
case StatusShow::FFC: return StatusShow::Online;
case StatusShow::DND: return StatusShow::DND;
case StatusShow::None: return StatusShow::None;
}
assert(false);
return StatusShow::None;
}
std::string ContactRosterItem::getStatusText() const {
return presence_ ? presence_->getStatus() : "";
}
std::string ContactRosterItem::getIdleText() const {
boost::posix_time::ptime idleTime = getIdle();
if (idleTime.is_not_a_date_time()) {
return "";
} else {
return dateTimeToLocalString(idleTime);
}
}
boost::posix_time::ptime ContactRosterItem::getIdle() const {
Idle::ref idle = presence_ ? presence_->getPayload<Idle>() : Idle::ref();
if (idle) {
return idle->getSince();
}
else {
return boost::posix_time::not_a_date_time;
}
}
std::string ContactRosterItem::getOfflineSinceText() const {
boost::posix_time::ptime offlineSince = getOfflineSince();
if (!offlineSince.is_not_a_date_time()) {
return dateTimeToLocalString(offlineSince);
}
return "";
}
boost::posix_time::ptime ContactRosterItem::getOfflineSince() const {
boost::posix_time::ptime offlineSince = boost::posix_time::not_a_date_time;
if (presence_ && presence_->getType() == Presence::Unavailable) {
boost::optional<boost::posix_time::ptime> delay = presence_->getTimestamp();
if (delay) {
offlineSince = delay.get();
}
}
return offlineSince;
}
void ContactRosterItem::setAvatarPath(const boost::filesystem::path& path) {
avatarPath_ = path;
onDataChanged();
}
const boost::filesystem::path& ContactRosterItem::getAvatarPath() const {
return avatarPath_;
}
const JID& ContactRosterItem::getJID() const {
return jid_;
}
void ContactRosterItem::setDisplayJID(const JID& jid) {
displayJID_ = jid;
}
const JID& ContactRosterItem::getDisplayJID() const {
return displayJID_;
}
typedef std::pair<std::string, std::shared_ptr<Presence> > StringPresencePair;
void ContactRosterItem::clearPresence() {
presence_.reset();
onDataChanged();
}
void ContactRosterItem::applyPresence(std::shared_ptr<Presence> presence) {
presence_ = presence;
onDataChanged();
}
const std::vector<std::string>& ContactRosterItem::getGroups() const {
return groups_;
}
/** Only used so a contact can know about the groups it's in*/
void ContactRosterItem::addGroup(const std::string& group) {
groups_.push_back(group);
}
void ContactRosterItem::removeGroup(const std::string& group) {
groups_.erase(std::remove(groups_.begin(), groups_.end(), group), groups_.end());
}
MUCOccupant::Role ContactRosterItem::getMUCRole() const
{
return mucRole_;
}
void ContactRosterItem::setMUCRole(const MUCOccupant::Role& role)
{
mucRole_ = role;
}
MUCOccupant::Affiliation ContactRosterItem::getMUCAffiliation() const
{
return mucAffiliation_;
}
void ContactRosterItem::setMUCAffiliation(const MUCOccupant::Affiliation& affiliation)
{
mucAffiliation_ = affiliation;
}
std::string ContactRosterItem::getMUCAffiliationText() const
{
std::string affiliationString;
switch (mucAffiliation_) {
case MUCOccupant::Owner: affiliationString = QT_TRANSLATE_NOOP("", "Owner"); break;
case MUCOccupant::Admin: affiliationString = QT_TRANSLATE_NOOP("", "Admin"); break;
case MUCOccupant::Member: affiliationString = QT_TRANSLATE_NOOP("", "Member"); break;
case MUCOccupant::Outcast: affiliationString = QT_TRANSLATE_NOOP("", "Outcast"); break;
case MUCOccupant::NoAffiliation: affiliationString = ""; break;
}
return affiliationString;
}
void ContactRosterItem::setSupportedFeatures(const std::set<Feature>& features) {
features_ = features;
onDataChanged();
}
bool ContactRosterItem::supportsFeature(const Feature feature) const {
return features_.find(feature) != features_.end();
}
void ContactRosterItem::setBlockState(BlockState state) {
blockState_ = state;
onDataChanged();
}
ContactRosterItem::BlockState ContactRosterItem::blockState() const {
return blockState_;
}
VCard::ref ContactRosterItem::getVCard() const {
return vcard_;
}
void ContactRosterItem::setVCard(VCard::ref vcard) {
vcard_ = vcard;
onDataChanged();
}
}
|