summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-02-07 18:18:59 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-02-07 18:19:27 (GMT)
commitd1837d06c5d655de759bbfcc66711a71c92296ad (patch)
tree31f93f55949efdc6047d707d5a32f14a392043e8 /Swiften/Roster
parent3db6fa2e985a286c3b53dc621ba164023272cb60 (diff)
downloadswift-contrib-d1837d06c5d655de759bbfcc66711a71c92296ad.zip
swift-contrib-d1837d06c5d655de759bbfcc66711a71c92296ad.tar.bz2
Moved Swift-specific roster code out of Swiften.
Diffstat (limited to 'Swiften/Roster')
-rw-r--r--Swiften/Roster/AppearOffline.h32
-rw-r--r--Swiften/Roster/ContactRosterItem.cpp116
-rw-r--r--Swiften/Roster/ContactRosterItem.h54
-rw-r--r--Swiften/Roster/GroupRosterItem.cpp201
-rw-r--r--Swiften/Roster/GroupRosterItem.h45
-rw-r--r--Swiften/Roster/OfflineRosterFilter.h30
-rw-r--r--Swiften/Roster/Roster.cpp209
-rw-r--r--Swiften/Roster/Roster.h60
-rw-r--r--Swiften/Roster/RosterFilter.h23
-rw-r--r--Swiften/Roster/RosterItem.cpp44
-rw-r--r--Swiften/Roster/RosterItem.h32
-rw-r--r--Swiften/Roster/RosterItemOperation.h33
-rw-r--r--Swiften/Roster/SetAvatar.h39
-rw-r--r--Swiften/Roster/SetName.h37
-rw-r--r--Swiften/Roster/SetPresence.h36
-rw-r--r--Swiften/Roster/UnitTest/RosterTest.cpp128
-rw-r--r--Swiften/Roster/XMPPRosterController.cpp3
17 files changed, 0 insertions, 1122 deletions
diff --git a/Swiften/Roster/AppearOffline.h b/Swiften/Roster/AppearOffline.h
deleted file mode 100644
index 8e14190..0000000
--- a/Swiften/Roster/AppearOffline.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (c) 2010 Remko Tronçon
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#pragma once
-
-#include "Swiften/Roster/RosterItemOperation.h"
-#include "Swiften/Roster/ContactRosterItem.h"
-
-namespace Swift {
-
-class RosterItem;
-
-class AppearOffline : public RosterItemOperation {
- public:
- AppearOffline() {
- }
-
- virtual void operator() (RosterItem* item) const {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
- if (contact) {
- contact->clearPresence();
- }
- }
-
-};
-
-}
-
-
diff --git a/Swiften/Roster/ContactRosterItem.cpp b/Swiften/Roster/ContactRosterItem.cpp
deleted file mode 100644
index 9c7af32..0000000
--- a/Swiften/Roster/ContactRosterItem.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright (c) 2010 Kevin Smith
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#include "Swiften/Roster/ContactRosterItem.h"
-#include "Swiften/Roster/GroupRosterItem.h"
-
-namespace Swift {
-
-
-ContactRosterItem::ContactRosterItem(const JID& jid, const JID& displayJID, const String& name, GroupRosterItem* parent) : RosterItem(name, parent), jid_(jid), displayJID_(displayJID) {
-}
-
-ContactRosterItem::~ContactRosterItem() {
-}
-
-StatusShow::Type ContactRosterItem::getStatusShow() const {
- return shownPresence_ ? shownPresence_->getShow() : StatusShow::None;
-}
-
-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);
- return StatusShow::None;
-}
-
-String ContactRosterItem::getStatusText() const {
- return shownPresence_ ? shownPresence_->getStatus() : "";
-}
-
-void ContactRosterItem::setAvatarPath(const String& path) {
- avatarPath_ = path;
- onDataChanged();
-}
-const String& 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<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();
- onDataChanged();
-}
-
-void ContactRosterItem::applyPresence(const String& resource, boost::shared_ptr<Presence> presence) {
- if (offlinePresence_) {
- offlinePresence_ = boost::shared_ptr<Presence>();
- }
- if (presence->getType() == Presence::Unavailable) {
- if (resource.isEmpty()) {
- /* Unavailable from the bare JID means all resources are offline.*/
- presences_.clear();
- } else {
- if (presences_.find(resource) != presences_.end()) {
- presences_.erase(resource);
- }
- }
- if (presences_.size() == 0) {
- offlinePresence_ = presence;
- }
- } else {
- presences_[resource] = presence;
- }
- calculateShownPresence();
- onDataChanged();
-}
-
-const std::vector<String> ContactRosterItem::getGroups() const {
- return groups_;
-}
-
-/** Only used so a contact can know about the groups it's in*/
-void ContactRosterItem::addGroup(const String& group) {
- groups_.push_back(group);
-}
-void ContactRosterItem::removeGroup(const String& group) {
- groups_.erase(std::remove(groups_.begin(), groups_.end(), group), groups_.end());
-}
-
-}
-
-
diff --git a/Swiften/Roster/ContactRosterItem.h b/Swiften/Roster/ContactRosterItem.h
deleted file mode 100644
index cb30989..0000000
--- a/Swiften/Roster/ContactRosterItem.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2010 Kevin Smith
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#pragma once
-
-#include "Swiften/Base/String.h"
-#include "Swiften/JID/JID.h"
-#include "Swiften/Roster/RosterItem.h"
-#include "Swiften/Elements/StatusShow.h"
-#include "Swiften/Elements/Presence.h"
-
-#include <map>
-#include <boost/bind.hpp>
-#include "Swiften/Base/boost_bsignals.h"
-#include <boost/shared_ptr.hpp>
-
-namespace Swift {
-
-class GroupRosterItem;
-class ContactRosterItem : public RosterItem {
- public:
- ContactRosterItem(const JID& jid, const JID& displayJID, const String& name, GroupRosterItem* parent);
- virtual ~ContactRosterItem();
-
- StatusShow::Type getStatusShow() const;
- StatusShow::Type getSimplifiedStatusShow() const;
- String getStatusText() const;
- void setAvatarPath(const String& path);
- const String& getAvatarPath() const;
- const JID& getJID() const;
- void setDisplayJID(const JID& jid);
- const JID& getDisplayJID() const;
- void applyPresence(const String& resource, boost::shared_ptr<Presence> presence);
- void clearPresence();
- void calculateShownPresence();
- const std::vector<String> getGroups() const;
- /** Only used so a contact can know about the groups it's in*/
- void addGroup(const String& group);
- void removeGroup(const String& group);
- private:
- JID jid_;
- JID displayJID_;
- String avatarPath_;
- std::map<String, boost::shared_ptr<Presence> > presences_;
- boost::shared_ptr<Presence> offlinePresence_;
- boost::shared_ptr<Presence> shownPresence_;
- std::vector<String> groups_;
-};
-
-}
-
diff --git a/Swiften/Roster/GroupRosterItem.cpp b/Swiften/Roster/GroupRosterItem.cpp
deleted file mode 100644
index 325c890..0000000
--- a/Swiften/Roster/GroupRosterItem.cpp
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * Copyright (c) 2010 Kevin Smith
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#include "Swiften/Roster/GroupRosterItem.h"
-
-#include <boost/bind.hpp>
-//#include <boost/algorithm.hpp>
-#include <iostream>
-
-namespace Swift {
-
-GroupRosterItem::GroupRosterItem(const String& name, GroupRosterItem* parent, bool sortByStatus) : RosterItem(name, parent), sortByStatus_(sortByStatus) {
- expanded_ = true;
-}
-
-GroupRosterItem::~GroupRosterItem() {
-
-}
-
-bool GroupRosterItem::isExpanded() const {
- return expanded_;
-}
-
-/**
- This has no effect, and is only used by the UI.
- If reTransmit is specified, dataChanged will be emitted on a change -
- This may be undesireable if called from the UI, so you can use reTransmit=false
- to avoid a loop in this case.
- */
-void GroupRosterItem::setExpanded(bool expanded) {
- bool old = expanded_;
- expanded_ = expanded;
- if (expanded != old) {
- onExpandedChanged(expanded);
- }
-}
-
-const std::vector<RosterItem*>& GroupRosterItem::getChildren() const {
- return children_;
-}
-
-const std::vector<RosterItem*>& GroupRosterItem::getDisplayedChildren() const {
- return displayedChildren_;
-}
-
-void GroupRosterItem::addChild(RosterItem* item) {
- children_.push_back(item);
- GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item);
- if (group) {
- group->onChildrenChanged.connect(boost::bind(&GroupRosterItem::handleChildrenChanged, this, group));
- } else {
- item->onDataChanged.connect(boost::bind(&GroupRosterItem::handleDataChanged, this, item));
- }
- onChildrenChanged();
- onDataChanged();
-}
-
-/**
- * Does not emit a changed signal.
- */
-void GroupRosterItem::removeAll() {
- std::vector<RosterItem*>::iterator it = children_.begin();
- displayedChildren_.clear();
- while (it != children_.end()) {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(*it);
- if (contact) {
- delete contact;
- } else {
- GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(*it);
- if (group) {
- group->removeAll();
- delete group;
- }
- }
- it++;
- }
- children_.clear();
-}
-
-/**
- * Returns the removed item - but only if it's the only one, otherwise
- * the return result is undefined.
- */
-ContactRosterItem* GroupRosterItem::removeChild(const JID& jid) {
- std::vector<RosterItem*>::iterator it = children_.begin();
- ContactRosterItem* removed = NULL;
- while (it != children_.end()) {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(*it);
- if (contact && contact->getJID() == jid) {
- displayedChildren_.erase(std::remove(displayedChildren_.begin(), displayedChildren_.end(), contact), displayedChildren_.end());
- removed = contact;
- delete contact;
- it = children_.erase(it);
- continue;
- }
- GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(*it);
- if (group) {
- ContactRosterItem* groupRemoved = group->removeChild(jid);
- if (groupRemoved) {
- removed = groupRemoved;
- }
- }
- it++;
- }
- onChildrenChanged();
- onDataChanged();
- return removed;
-}
-
-/**
- * Returns false if the list didn't need a resort
- */
-bool GroupRosterItem::sortDisplayed() {
- /* Not doing this until we import boost::algorithm*/
-// if (boost::is_sorted(displayedChildren_begin(), displayedChildren_.end(), itemLessThan)) {
-// return false;
-// }
- //Sholudn't need stable_sort here
- std::sort(displayedChildren_.begin(), displayedChildren_.end(), sortByStatus_? itemLessThanWithStatus : itemLessThanWithoutStatus);
- return true;
-}
-
-bool GroupRosterItem::itemLessThanWithoutStatus(const RosterItem* left, const RosterItem* right) {
- return left->getSortableDisplayName() < right->getSortableDisplayName();
-}
-
-bool GroupRosterItem::itemLessThanWithStatus(const RosterItem* left, const RosterItem* right) {
- const ContactRosterItem* leftContact = dynamic_cast<const ContactRosterItem*>(left);
- const ContactRosterItem* rightContact = dynamic_cast<const ContactRosterItem*>(right);
- if (leftContact) {
- if (!rightContact) {
- return false;
- }
- StatusShow::Type leftType = leftContact->getSimplifiedStatusShow();
- StatusShow::Type rightType = rightContact->getSimplifiedStatusShow();
- if (leftType == rightType) {
- return left->getSortableDisplayName() < right->getSortableDisplayName();
- } else {
- return leftType < rightType;
- }
- } else {
- if (rightContact) {
- return true;
- }
- return left->getSortableDisplayName() < right->getSortableDisplayName();
- }
-}
-
-void GroupRosterItem::setDisplayed(RosterItem* item, bool displayed) {
- bool found = false;
- for (size_t i = 0; i < displayedChildren_.size(); i++) {
- if (displayedChildren_[i] == item) {
- found = true;
- }
- }
- if (found == displayed) {
- return;
- }
- if (displayed) {
- displayedChildren_.push_back(item);
- sortDisplayed();
- } else {
- displayedChildren_.erase(std::remove(displayedChildren_.begin(), displayedChildren_.end(), item), displayedChildren_.end());
- }
- onChildrenChanged();
- onDataChanged();
-}
-
-void GroupRosterItem::handleDataChanged(RosterItem* /*item*/) {
- if (sortDisplayed()) {
- onChildrenChanged();
- }
-}
-
-void GroupRosterItem::handleChildrenChanged(GroupRosterItem* group) {
- size_t oldSize = getDisplayedChildren().size();
- if (group->getDisplayedChildren().size() > 0) {
- bool found = false;
- for (size_t i = 0; i < displayedChildren_.size(); i++) {
- if (displayedChildren_[i] == group) {
- found = true;
- }
- }
- if (!found) {
- displayedChildren_.push_back(group);
- sortDisplayed();
- }
- } else {
- displayedChildren_.erase(std::remove(displayedChildren_.begin(), displayedChildren_.end(), group), displayedChildren_.end());
- }
- if (oldSize != getDisplayedChildren().size()) {
- onChildrenChanged();
- onDataChanged();
- }
-}
-
-
-}
diff --git a/Swiften/Roster/GroupRosterItem.h b/Swiften/Roster/GroupRosterItem.h
deleted file mode 100644
index b306b59..0000000
--- a/Swiften/Roster/GroupRosterItem.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2010 Kevin Smith
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#pragma once
-
-#include "Swiften/Roster/RosterItem.h"
-#include "Swiften/Base/String.h"
-#include "Swiften/Roster/ContactRosterItem.h"
-
-#include <vector>
-
-namespace Swift {
-
-class GroupRosterItem : public RosterItem {
- public:
- GroupRosterItem(const String& name, GroupRosterItem* parent, bool sortByStatus);
- virtual ~GroupRosterItem();
- const std::vector<RosterItem*>& getChildren() const;
- const std::vector<RosterItem*>& getDisplayedChildren() const;
- void addChild(RosterItem* item);
- ContactRosterItem* removeChild(const JID& jid);
- void removeAll();
- void setDisplayed(RosterItem* item, bool displayed);
- boost::signal<void ()> onChildrenChanged;
- static bool itemLessThanWithStatus(const RosterItem* left, const RosterItem* right);
- static bool itemLessThanWithoutStatus(const RosterItem* left, const RosterItem* right);
- void setExpanded(bool expanded);
- bool isExpanded() const;
- boost::signal<void (bool)> onExpandedChanged;
- private:
- void handleChildrenChanged(GroupRosterItem* group);
- void handleDataChanged(RosterItem* item);
- bool sortDisplayed();
- String name_;
- bool expanded_;
- std::vector<RosterItem*> children_;
- std::vector<RosterItem*> displayedChildren_;
- bool sortByStatus_;
-};
-
-}
-
diff --git a/Swiften/Roster/OfflineRosterFilter.h b/Swiften/Roster/OfflineRosterFilter.h
deleted file mode 100644
index 2a71900..0000000
--- a/Swiften/Roster/OfflineRosterFilter.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (c) 2010 Remko Tronçon
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#ifndef SWIFTEN_OfflineRosterFilter_H
-#define SWIFTEN_OfflineRosterFilter_H
-
-#include "Swiften/Roster/ContactRosterItem.h"
-#include "Swiften/Roster/RosterItem.h"
-#include "Swiften/Roster/RosterFilter.h"
-#include "Swiften/Elements/StatusShow.h"
-
-namespace Swift {
-
-class OfflineRosterFilter : public RosterFilter {
- public:
- virtual ~OfflineRosterFilter() {}
- virtual bool operator() (RosterItem *item) const {
- ContactRosterItem *contactItem = dynamic_cast<ContactRosterItem*>(item);
- return contactItem && contactItem->getStatusShow() == StatusShow::None;
- }
-};
-
-}
-#endif
-
-
-
diff --git a/Swiften/Roster/Roster.cpp b/Swiften/Roster/Roster.cpp
deleted file mode 100644
index 68bac53..0000000
--- a/Swiften/Roster/Roster.cpp
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * Copyright (c) 2010 Remko Tronçon
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#include "Swiften/Roster/Roster.h"
-
-#include "Swiften/Base/foreach.h"
-#include "Swiften/Base/String.h"
-#include "Swiften/JID/JID.h"
-#include "Swiften/Roster/ContactRosterItem.h"
-#include "Swiften/Roster/RosterItem.h"
-#include "Swiften/Roster/GroupRosterItem.h"
-#include "Swiften/Roster/RosterItemOperation.h"
-
-#include <boost/bind.hpp>
-
-#include <iostream>
-#include <deque>
-
-namespace Swift {
-
-Roster::Roster(bool sortByStatus, bool fullJIDMapping) {
- sortByStatus_ = sortByStatus;
- fullJIDMapping_ = fullJIDMapping;
- root_ = new GroupRosterItem("Dummy-Root", NULL, sortByStatus_);
- root_->onChildrenChanged.connect(boost::bind(&Roster::handleChildrenChanged, this, root_));
-}
-
-Roster::~Roster() {
- std::deque<RosterItem*> queue;
- queue.push_back(root_);
- while (!queue.empty()) {
- RosterItem* item = *queue.begin();
- queue.pop_front();
- GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item);
- if (group) {
- queue.insert(queue.begin(), group->getChildren().begin(), group->getChildren().end());
- }
- delete item;
- }
-}
-
-GroupRosterItem* Roster::getRoot() {
- return root_;
-}
-
-GroupRosterItem* Roster::getGroup(const String& groupName) {
- foreach (RosterItem *item, root_->getChildren()) {
- GroupRosterItem *group = dynamic_cast<GroupRosterItem*>(item);
- if (group && group->getDisplayName() == groupName) {
- return group;
- }
- }
- GroupRosterItem* group = new GroupRosterItem(groupName, root_, sortByStatus_);
- root_->addChild(group);
- group->onChildrenChanged.connect(boost::bind(&Roster::handleChildrenChanged, this, group));
- group->onDataChanged.connect(boost::bind(&Roster::handleDataChanged, this, group));
- return group;
-}
-
-void Roster::handleDataChanged(RosterItem* item) {
- onDataChanged(item);
-}
-
-void Roster::handleChildrenChanged(GroupRosterItem* item) {
- onChildrenChanged(item);
-}
-
-void Roster::addContact(const JID& jid, const JID& displayJID, const String& name, const String& groupName, const String& avatarPath) {
- GroupRosterItem* group(getGroup(groupName));
- ContactRosterItem *item = new ContactRosterItem(jid, displayJID, name, group);
- item->setAvatarPath(avatarPath);
- group->addChild(item);
- if (itemMap_[fullJIDMapping_ ? jid : jid.toBare()].size() > 0) {
- foreach (String existingGroup, itemMap_[fullJIDMapping_ ? jid : jid.toBare()][0]->getGroups()) {
- item->addGroup(existingGroup);
- }
- }
- itemMap_[fullJIDMapping_ ? jid : jid.toBare()].push_back(item);
- item->onDataChanged.connect(boost::bind(&Roster::handleDataChanged, this, item));
- filterContact(item, group);
-
- foreach (ContactRosterItem* item, itemMap_[fullJIDMapping_ ? jid : jid.toBare()]) {
- item->addGroup(groupName);
- }
-}
-
-struct JIDEqualsTo {
- JIDEqualsTo(const JID& jid) : jid(jid) {}
- bool operator()(ContactRosterItem* i) const { return jid == i->getJID(); }
- JID jid;
-};
-
-void Roster::removeAll() {
- root_->removeAll();
- itemMap_.clear();
- onChildrenChanged(root_);
- onDataChanged(root_);
-}
-
-void Roster::removeContact(const JID& jid) {
- std::vector<ContactRosterItem*>* items = &itemMap_[fullJIDMapping_ ? jid : jid.toBare()];
- items->erase(std::remove_if(items->begin(), items->end(), JIDEqualsTo(jid)), items->end());
- if (items->size() == 0) {
- itemMap_.erase(fullJIDMapping_ ? jid : jid.toBare());
- }
- //Causes the delete
- root_->removeChild(jid);
-}
-
-void Roster::removeContactFromGroup(const JID& jid, const String& groupName) {
- std::vector<RosterItem*> children = root_->getChildren();
- std::vector<RosterItem*>::iterator it = children.begin();
- while (it != children.end()) {
- GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(*it);
- if (group && group->getDisplayName() == groupName) {
- ContactRosterItem* deleted = group->removeChild(jid);
- std::vector<ContactRosterItem*>* items = &itemMap_[fullJIDMapping_ ? jid : jid.toBare()];
- items->erase(std::remove(items->begin(), items->end(), deleted), items->end());
- }
- it++;
- }
- foreach (ContactRosterItem* item, itemMap_[fullJIDMapping_ ? jid : jid.toBare()]) {
- item->removeGroup(groupName);
- }
-}
-
-
-void Roster::applyOnItems(const RosterItemOperation& operation) {
- if (operation.requiresLookup()) {
- applyOnItem(operation, operation.lookupJID());
- } else {
- applyOnAllItems(operation);
- }
-}
-
-void Roster::applyOnItem(const RosterItemOperation& operation, const JID& jid) {
-
- foreach (ContactRosterItem* item, itemMap_[fullJIDMapping_ ? jid : jid.toBare()]) {
- operation(item);
- filterContact(item, item->getParent());
- }
-}
-
-void Roster::applyOnAllItems(const RosterItemOperation& operation) {
- std::deque<RosterItem*> queue;
- queue.push_back(root_);
- while (!queue.empty()) {
- RosterItem* item = *queue.begin();
- queue.pop_front();
- operation(item);
- GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item);
- if (group) {
- queue.insert(queue.begin(), group->getChildren().begin(), group->getChildren().end());
- }
- }
- filterAll();
-}
-
-void Roster::removeFilter(RosterFilter *filter) {
- for (unsigned int i = 0; i < filters_.size(); i++) {
- if (filters_[i] == filter) {
- filters_.erase(filters_.begin() + i);
- break;
- }
- }
- filterAll();
-}
-
-void Roster::filterContact(ContactRosterItem* contact, GroupRosterItem* group) {
- int oldDisplayedSize = group->getDisplayedChildren().size();
- bool hide = true;
- foreach (RosterFilter *filter, filters_) {
- hide &= (*filter)(contact);
- }
- group->setDisplayed(contact, filters_.size() == 0 || !hide);
- int newDisplayedSize = group->getDisplayedChildren().size();
- if (oldDisplayedSize == 0 && newDisplayedSize > 0) {
- onGroupAdded(group);
- }
-}
-
-void Roster::filterGroup(GroupRosterItem* group) {
- foreach (RosterItem* child, group->getChildren()) {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(child);
- if (contact) {
- filterContact(contact, group);
- }
- }
-}
-
-void Roster::filterAll() {
- std::deque<RosterItem*> queue;
- queue.push_back(root_);
- while (!queue.empty()) {
- RosterItem *item = *queue.begin();
- queue.pop_front();
- GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item);
- if (group) {
- queue.insert(queue.begin(), group->getChildren().begin(), group->getChildren().end());
- filterGroup(group);
- }
- }
-}
-
-}
-
diff --git a/Swiften/Roster/Roster.h b/Swiften/Roster/Roster.h
deleted file mode 100644
index 2f12b57..0000000
--- a/Swiften/Roster/Roster.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 2010 Remko Tronçon
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#ifndef SWIFTEN_Roster_H
-#define SWIFTEN_Roster_H
-
-#include "Swiften/Base/String.h"
-#include "Swiften/JID/JID.h"
-#include "Swiften/Roster/RosterItemOperation.h"
-#include "Swiften/Roster/RosterFilter.h"
-
-#include <vector>
-#include <map>
-#include "Swiften/Base/boost_bsignals.h"
-#include <boost/shared_ptr.hpp>
-
-namespace Swift {
-
-class RosterItem;
-class GroupRosterItem;
-class ContactRosterItem;
-
-class Roster {
- public:
- Roster(bool sortByStatus = true, bool fullJIDMapping = false);
- ~Roster();
-
- void addContact(const JID& jid, const JID& displayJID, const String& name, const String& group, const String& avatarPath);
- void removeContact(const JID& jid);
- void removeContactFromGroup(const JID& jid, const String& group);
- void removeAll();
- void applyOnItems(const RosterItemOperation& operation);
- void applyOnAllItems(const RosterItemOperation& operation);
- void applyOnItem(const RosterItemOperation& operation, const JID& jid);
- void addFilter(RosterFilter *filter) {filters_.push_back(filter);filterAll();};
- void removeFilter(RosterFilter *filter);
- GroupRosterItem* getRoot();
- std::vector<RosterFilter*> getFilters() {return filters_;};
- boost::signal<void (GroupRosterItem*)> onChildrenChanged;
- boost::signal<void (GroupRosterItem*)> onGroupAdded;
- boost::signal<void (RosterItem*)> onDataChanged;
- private:
- GroupRosterItem* getGroup(const String& groupName);
- void handleDataChanged(RosterItem* item);
- void handleChildrenChanged(GroupRosterItem* item);
- void filterGroup(GroupRosterItem* item);
- void filterContact(ContactRosterItem* contact, GroupRosterItem* group);
- void filterAll();
- GroupRosterItem* root_;
- std::vector<RosterFilter*> filters_;
- std::map<JID, std::vector<ContactRosterItem*> > itemMap_;
- bool fullJIDMapping_;
- bool sortByStatus_;
-};
-}
-
-#endif
diff --git a/Swiften/Roster/RosterFilter.h b/Swiften/Roster/RosterFilter.h
deleted file mode 100644
index 02e788c..0000000
--- a/Swiften/Roster/RosterFilter.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (c) 2010 Remko Tronçon
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#ifndef SWIFTEN_RosterFilter_H
-#define SWIFTEN_RosterFilter_H
-
-#include "Swiften/Roster/RosterItem.h"
-
-namespace Swift {
-
-class RosterFilter {
- public:
- virtual ~RosterFilter() {}
- virtual bool operator() (RosterItem* item) const = 0;
-};
-
-}
-#endif
-
-
diff --git a/Swiften/Roster/RosterItem.cpp b/Swiften/Roster/RosterItem.cpp
deleted file mode 100644
index 3ce13b4..0000000
--- a/Swiften/Roster/RosterItem.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2010 Kevin Smith
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#include "Swiften/Roster/RosterItem.h"
-
-#include "Swiften/Roster/GroupRosterItem.h"
-
-namespace Swift {
-
-RosterItem::RosterItem(const String& name, GroupRosterItem* parent) : name_(name), sortableDisplayName_(name_.getLowerCase()), parent_(parent) {
- /* The following would be good, but because of C++'s inheritance not working in constructors, it's not going to work. */
- //if (parent) {
- // parent_->addChild(this);
- //}
-}
-
-RosterItem::~RosterItem() {
-
-}
-
-GroupRosterItem* RosterItem::getParent() const {
- return parent_;
-}
-
-void RosterItem::setDisplayName(const String& name) {
- name_ = name;
- sortableDisplayName_ = name_.getLowerCase();
- onDataChanged();
-}
-
-String RosterItem::getDisplayName() const {
- return name_;
-}
-
-String RosterItem::getSortableDisplayName() const {
- return sortableDisplayName_;
-}
-
-
-}
-
diff --git a/Swiften/Roster/RosterItem.h b/Swiften/Roster/RosterItem.h
deleted file mode 100644
index 35dbe73..0000000
--- a/Swiften/Roster/RosterItem.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (c) 2010 Kevin Smith
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#pragma once
-
-#include "Swiften/Base/boost_bsignals.h"
-#include <boost/shared_ptr.hpp>
-
-#include "Swiften/Base/String.h"
-
-namespace Swift {
-class GroupRosterItem;
-class RosterItem {
- public:
- RosterItem(const String& name, GroupRosterItem* parent);
- virtual ~RosterItem();
- boost::signal<void ()> onDataChanged;
- GroupRosterItem* getParent() const;
- void setDisplayName(const String& name);
- String getDisplayName() const;
- String getSortableDisplayName() const;
- private:
- String name_;
- String sortableDisplayName_;
- GroupRosterItem* parent_;
-};
-
-}
-
diff --git a/Swiften/Roster/RosterItemOperation.h b/Swiften/Roster/RosterItemOperation.h
deleted file mode 100644
index e27e68b..0000000
--- a/Swiften/Roster/RosterItemOperation.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (c) 2010 Remko Tronçon
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#ifndef SWIFTEN_RosterItemOperation_H
-#define SWIFTEN_RosterItemOperation_H
-
-#include "Swiften/Roster/RosterItem.h"
-
-namespace Swift {
-
-class RosterItemOperation {
- public:
- RosterItemOperation(bool requiresLookup = false, const JID& lookupJID = JID()) : requiresLookup_(requiresLookup), lookupJID_(lookupJID) {};
- virtual ~RosterItemOperation() {};
- bool requiresLookup() const {return requiresLookup_;};
- const JID& lookupJID() const {return lookupJID_;};
- /**
- * This is called when iterating over possible subjects, so must check it's
- * applying to the right items - even if requiresLookup() is true an item
- * with the same bare JID but different full JID may be passed.
- */
- virtual void operator() (RosterItem*) const = 0;
- private:
- bool requiresLookup_;
- JID lookupJID_;
-};
-
-}
-#endif
-
diff --git a/Swiften/Roster/SetAvatar.h b/Swiften/Roster/SetAvatar.h
deleted file mode 100644
index 2b22188..0000000
--- a/Swiften/Roster/SetAvatar.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2010 Remko Tronçon
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#ifndef SWIFTEN_SetAvatar_H
-#define SWIFTEN_SetAvatar_H
-
-#include "Swiften/Elements/Presence.h"
-#include "Swiften/JID/JID.h"
-#include "Swiften/Roster/RosterItemOperation.h"
-#include "Swiften/Roster/ContactRosterItem.h"
-
-namespace Swift {
-
-class RosterItem;
-
-class SetAvatar : public RosterItemOperation {
- public:
- SetAvatar(const JID& jid, const String& path, JID::CompareType compareType = JID::WithoutResource) : RosterItemOperation(true, jid), jid_(jid), path_(path), compareType_(compareType) {
- }
-
- virtual void operator() (RosterItem* item) const {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
- if (contact && contact->getJID().equals(jid_, compareType_)) {
- contact->setAvatarPath(path_);
- }
- }
-
- private:
- JID jid_;
- String path_;
- JID::CompareType compareType_;
-};
-
-}
-#endif
-
diff --git a/Swiften/Roster/SetName.h b/Swiften/Roster/SetName.h
deleted file mode 100644
index d3f7749..0000000
--- a/Swiften/Roster/SetName.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2010 Kevin Smith
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#pragma once
-
-#include "Swiften/JID/JID.h"
-#include "Swiften/Roster/RosterItemOperation.h"
-#include "Swiften/Roster/ContactRosterItem.h"
-
-namespace Swift {
-
-class RosterItem;
-
-class SetName : public RosterItemOperation {
- public:
- SetName(const String& name, const JID& jid, JID::CompareType compareType = JID::WithoutResource) : RosterItemOperation(true, jid), name_(name), jid_(jid), compareType_(compareType) {
- }
-
- virtual void operator() (RosterItem* item) const {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
- if (contact && contact->getJID().equals(jid_, compareType_)) {
- contact->setDisplayName(name_);
- }
- }
-
- private:
- String name_;
- JID jid_;
- JID::CompareType compareType_;
-};
-
-}
-
-
diff --git a/Swiften/Roster/SetPresence.h b/Swiften/Roster/SetPresence.h
deleted file mode 100644
index e710931..0000000
--- a/Swiften/Roster/SetPresence.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2010 Remko Tronçon
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#pragma once
-
-#include "Swiften/Elements/Presence.h"
-#include "Swiften/JID/JID.h"
-#include "Swiften/Roster/RosterItemOperation.h"
-#include "Swiften/Roster/ContactRosterItem.h"
-
-namespace Swift {
-
-class RosterItem;
-
-class SetPresence : public RosterItemOperation {
- public:
- SetPresence(Presence::ref presence, JID::CompareType compareType = JID::WithoutResource) : RosterItemOperation(true, compareType == JID::WithoutResource ? presence->getFrom().toBare() : presence->getFrom()), presence_(presence), compareType_(compareType) {
- }
-
- virtual void operator() (RosterItem* item) const {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
- if (contact && contact->getJID().equals(presence_->getFrom(), compareType_)) {
- contact->applyPresence(presence_->getFrom().getResource(), presence_);
- }
- }
-
- private:
- Presence::ref presence_;
- JID::CompareType compareType_;
-};
-
-}
-
diff --git a/Swiften/Roster/UnitTest/RosterTest.cpp b/Swiften/Roster/UnitTest/RosterTest.cpp
deleted file mode 100644
index 0300188..0000000
--- a/Swiften/Roster/UnitTest/RosterTest.cpp
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright (c) 2010 Remko Tronçon
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#include <cppunit/extensions/HelperMacros.h>
-#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <boost/shared_ptr.hpp>
-
-#include "Swiften/Roster/Roster.h"
-#include "Swiften/Roster/GroupRosterItem.h"
-#include "Swiften/Roster/SetPresence.h"
-
-using namespace Swift;
-
-class RosterTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(RosterTest);
- CPPUNIT_TEST(testGetGroup);
- CPPUNIT_TEST(testRemoveContact);
- CPPUNIT_TEST(testRemoveSecondContact);
- CPPUNIT_TEST(testRemoveSecondContactSameBare);
- CPPUNIT_TEST(testApplyPresenceLikeMUC);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- void setUp() {
- jid1_ = JID("a@b.c");
- jid2_ = JID("b@c.d");
- jid3_ = JID("c@d.e");
- roster_ = new Roster();
- }
-
- void tearDown() {
- delete roster_;
- }
-
- void testGetGroup() {
- roster_->addContact(jid1_, JID(), "Bert", "group1", "");
- roster_->addContact(jid2_, JID(), "Ernie", "group2", "");
- roster_->addContact(jid3_, JID(), "Cookie", "group1", "");
-
- CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(roster_->getRoot()->getChildren().size()));
- CPPUNIT_ASSERT_EQUAL(String("group1"), roster_->getRoot()->getChildren()[0]->getDisplayName());
- CPPUNIT_ASSERT_EQUAL(String("group2"), roster_->getRoot()->getChildren()[1]->getDisplayName());
- CPPUNIT_ASSERT_EQUAL(String("Bert"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[0]->getDisplayName());
- CPPUNIT_ASSERT_EQUAL(String("Cookie"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[1]->getDisplayName());
- CPPUNIT_ASSERT_EQUAL(String("Ernie"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[1])->getChildren()[0]->getDisplayName());
-
- }
-
- void testRemoveContact() {
- roster_->addContact(jid1_, jid1_, "Bert", "group1", "");
- CPPUNIT_ASSERT_EQUAL(String("Bert"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[0]->getDisplayName());
-
- roster_->removeContact(jid1_);
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren().size()));
- }
-
- void testRemoveSecondContact() {
- roster_->addContact(jid1_, jid1_, "Bert", "group1", "");
- roster_->addContact(jid2_, jid2_, "Cookie", "group1", "");
- CPPUNIT_ASSERT_EQUAL(String("Cookie"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[1]->getDisplayName());
-
- roster_->removeContact(jid2_);
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren().size()));
- CPPUNIT_ASSERT_EQUAL(String("Bert"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[0]->getDisplayName());
- }
-
- void testRemoveSecondContactSameBare() {
- JID jid4a("a@b/c");
- JID jid4b("a@b/d");
- roster_->addContact(jid4a, JID(), "Bert", "group1", "");
- roster_->addContact(jid4b, JID(), "Cookie", "group1", "");
- CPPUNIT_ASSERT_EQUAL(String("Cookie"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[1]->getDisplayName());
-
- roster_->removeContact(jid4b);
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren().size()));
- CPPUNIT_ASSERT_EQUAL(String("Bert"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[0]->getDisplayName());
- }
-
- void testApplyPresenceLikeMUC() {
- JID jid4a("a@b/c");
- JID jid4b("a@b/d");
- JID jid4c("a@b/e");
- roster_->addContact(jid4a, JID(), "Bird", "group1", "");
- roster_->addContact(jid4b, JID(), "Cookie", "group1", "");
- roster_->removeContact(jid4b);
- roster_->addContact(jid4c, JID(), "Bert", "group1", "");
- roster_->addContact(jid4b, JID(), "Ernie", "group1", "");
- boost::shared_ptr<Presence> presence(new Presence());
- presence->setShow(StatusShow::DND);
- presence->setFrom(jid4a);
- roster_->applyOnItems(SetPresence(presence, JID::WithResource));
- presence->setFrom(jid4b);
- roster_->applyOnItems(SetPresence(presence, JID::WithResource));
- presence->setFrom(jid4c);
- roster_->applyOnItems(SetPresence(presence, JID::WithResource));
-
- presence = boost::shared_ptr<Presence>(new Presence());
- presence->setFrom(jid4b);
- presence->setShow(StatusShow::Online);
- roster_->applyOnItems(SetPresence(presence, JID::WithResource));
- std::vector<RosterItem*> children = static_cast<GroupRosterItem*>(roster_->getRoot()->getDisplayedChildren()[0])->getDisplayedChildren();
- CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(children.size()));
-
- /* Check order */
- CPPUNIT_ASSERT_EQUAL(String("Ernie"), children[0]->getDisplayName());
- CPPUNIT_ASSERT_EQUAL(String("Bert"), children[1]->getDisplayName());
- CPPUNIT_ASSERT_EQUAL(String("Bird"), children[2]->getDisplayName());
-
- presence = boost::shared_ptr<Presence>(new Presence());
- presence->setFrom(jid4c);
- presence->setType(Presence::Unavailable);
- roster_->removeContact(jid4c);
- roster_->applyOnItems(SetPresence(presence, JID::WithResource));
-
- }
-
- private:
- Roster *roster_;
- JID jid1_;
- JID jid2_;
- JID jid3_;
-};
-
-CPPUNIT_TEST_SUITE_REGISTRATION(RosterTest);
-
diff --git a/Swiften/Roster/XMPPRosterController.cpp b/Swiften/Roster/XMPPRosterController.cpp
index 909ef8e..3a1d11f 100644
--- a/Swiften/Roster/XMPPRosterController.cpp
+++ b/Swiften/Roster/XMPPRosterController.cpp
@@ -12,9 +12,6 @@
#include "Swiften/Elements/RosterItemPayload.h"
#include "Swiften/Queries/IQRouter.h"
#include "Swiften/Roster/GetRosterRequest.h"
-#include "Swiften/Roster/Roster.h"
-#include "Swiften/Roster/SetPresence.h"
-#include "Swiften/Roster/OfflineRosterFilter.h"
#include "Swiften/Roster/XMPPRosterImpl.h"
namespace Swift {