summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-05-06 08:00:44 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-05-06 10:49:49 (GMT)
commit081fc03556708447610e9697a57235fa191a4f0d (patch)
tree505c8cc9129d2b44968d183a180f0ccddaa08810 /Swiften/Roster/ContactRosterItem.cpp
parent8c53236875d2ca77f1b463449918458f6b424ab1 (diff)
downloadswift-contrib-081fc03556708447610e9697a57235fa191a4f0d.zip
swift-contrib-081fc03556708447610e9697a57235fa191a4f0d.tar.bz2
Rewrite of large amounts of roster code.
Now keeps widgets out of Swiften, keeps sorting inside Swiften, and keeps track of presences to show the correct presence per roster item. Resolves: #316 Resolves: #81 Resolves: #239
Diffstat (limited to 'Swiften/Roster/ContactRosterItem.cpp')
-rw-r--r--Swiften/Roster/ContactRosterItem.cpp76
1 files changed, 52 insertions, 24 deletions
diff --git a/Swiften/Roster/ContactRosterItem.cpp b/Swiften/Roster/ContactRosterItem.cpp
index 39e96bd..2d5082c 100644
--- a/Swiften/Roster/ContactRosterItem.cpp
+++ b/Swiften/Roster/ContactRosterItem.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -10,49 +10,77 @@
namespace Swift {
-ContactRosterItem::ContactRosterItem(const JID& jid, const String& name, GroupRosterItem* parent, TreeWidgetFactory* factory) : jid_(jid), name_(name) {
- parent->addChild(this);
- widget_ = factory->createTreeWidgetItem(parent->getWidget());
- widget_->setText(name.isEmpty() ? jid.toString() : name);
- widget_->onUserAction.connect(boost::bind(&ContactRosterItem::handleUserAction, this, _1));
- setStatusShow(StatusShow::None);
+ContactRosterItem::ContactRosterItem(const JID& jid, const String& name, GroupRosterItem* parent) : RosterItem(name, parent), jid_(jid) {
}
ContactRosterItem::~ContactRosterItem() {
- delete widget_;
}
-void ContactRosterItem::setName(const String& name) {
- widget_->setText(name);
+StatusShow::Type ContactRosterItem::getStatusShow() const {
+ return shownPresence_ ? shownPresence_->getShow() : StatusShow::None;
}
-StatusShow::Type ContactRosterItem::getStatusShow() {
- return statusShow_;
+StatusShow::Type ContactRosterItem::getSimplifiedStatusShow() const {
+ switch (shownPresence_ ? shownPresence_->getShow() : StatusShow::None) {
+ case StatusShow::Online: return StatusShow::Online; break;
+ case StatusShow::Away: return StatusShow::Away; break;
+ case StatusShow::XA: return StatusShow::Away; break;
+ case StatusShow::FFC: return StatusShow::Online; break;
+ case StatusShow::DND: return StatusShow::DND; break;
+ case StatusShow::None: return StatusShow::None; break;
+ }
+ assert(false);
}
-void ContactRosterItem::setStatusShow(StatusShow::Type show) {
- statusShow_ = show;
- widget_->setStatusShow(show);
-}
-
-void ContactRosterItem::setStatusText(const String& status) {
- widget_->setStatusText(status);
+String ContactRosterItem::getStatusText() const {
+ return shownPresence_ ? shownPresence_->getStatus() : "";
}
void ContactRosterItem::setAvatarPath(const String& path) {
- widget_->setAvatarPath(path);
+ avatarPath_ = path;
+ onDataChanged();
+}
+const String& ContactRosterItem::getAvatarPath() const {
+ return avatarPath_;
}
const JID& ContactRosterItem::getJID() const {
return jid_;
}
-void ContactRosterItem::show() {
- widget_->show();
+typedef std::pair<String, boost::shared_ptr<Presence> > StringPresencePair;
+
+void ContactRosterItem::calculateShownPresence() {
+ shownPresence_ = offlinePresence_;
+ foreach (StringPresencePair presencePair, presences_) {
+ boost::shared_ptr<Presence> presence = presencePair.second;
+ if (!shownPresence_ || presence->getPriority() > shownPresence_->getPriority() || presence->getShow() < shownPresence_->getShow()) {
+ shownPresence_ = presence;
+ }
+ }
+}
+
+void ContactRosterItem::clearPresence() {
+ presences_.clear();
+ calculateShownPresence();
}
-void ContactRosterItem::hide() {
- widget_->hide();
+void ContactRosterItem::applyPresence(const String& resource, boost::shared_ptr<Presence> presence) {
+ if (offlinePresence_) {
+ offlinePresence_ = boost::shared_ptr<Presence>();
+ }
+ if (presence->getType() == Presence::Unavailable) {
+ if (presences_.find(resource) != presences_.end()) {
+ presences_.erase(resource);
+ }
+ if (presences_.size() > 0) {
+ offlinePresence_ = presence;
+ }
+ } else {
+ presences_[resource] = presence;
+ }
+ calculateShownPresence();
+ onDataChanged();
}
}