diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-02-11 12:14:00 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-02-11 12:14:00 (GMT) |
commit | 0efa7c32aaf21a29b42b5926cc116007056843be (patch) | |
tree | 882f663a5dd0e65694bf6077b71086dd77fd7ff8 /Slimber/LinkLocalPresenceManager.cpp | |
parent | 1d20eabbc32274b491b4c2bedf73d19933d97bfd (diff) | |
download | swift-0efa7c32aaf21a29b42b5926cc116007056843be.zip swift-0efa7c32aaf21a29b42b5926cc116007056843be.tar.bz2 |
Moved some modules into separate git modules.
Diffstat (limited to 'Slimber/LinkLocalPresenceManager.cpp')
m--------- | Slimber | 0 | ||||
-rw-r--r-- | Slimber/LinkLocalPresenceManager.cpp | 103 |
2 files changed, 0 insertions, 103 deletions
diff --git a/Slimber b/Slimber new file mode 160000 +Subproject 723115ef8542c640580ea4751fca3c359a79dec diff --git a/Slimber/LinkLocalPresenceManager.cpp b/Slimber/LinkLocalPresenceManager.cpp deleted file mode 100644 index d5834c7..0000000 --- a/Slimber/LinkLocalPresenceManager.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include "Slimber/LinkLocalPresenceManager.h" - -#include <boost/bind.hpp> - -#include "Swiften/Base/foreach.h" -#include "Swiften/LinkLocal/LinkLocalServiceBrowser.h" -#include "Swiften/Elements/RosterPayload.h" -#include "Swiften/Elements/Presence.h" - -namespace Swift { - -LinkLocalPresenceManager::LinkLocalPresenceManager(LinkLocalServiceBrowser* browser) : browser(browser) { - browser->onServiceAdded.connect( - boost::bind(&LinkLocalPresenceManager::handleServiceAdded, this, _1)); - browser->onServiceChanged.connect( - boost::bind(&LinkLocalPresenceManager::handleServiceChanged, this, _1)); - browser->onServiceRemoved.connect( - boost::bind(&LinkLocalPresenceManager::handleServiceRemoved, this, _1)); -} - -boost::optional<LinkLocalService> LinkLocalPresenceManager::getServiceForJID(const JID& j) const { - foreach(const LinkLocalService& service, browser->getServices()) { - if (service.getJID() == j) { - return service; - } - } - return boost::optional<LinkLocalService>(); -} - -void LinkLocalPresenceManager::handleServiceAdded(const LinkLocalService& service) { - boost::shared_ptr<RosterPayload> roster(new RosterPayload()); - roster->addItem(getRosterItem(service)); - onRosterChanged(roster); - onPresenceChanged(getPresence(service)); -} - -void LinkLocalPresenceManager::handleServiceChanged(const LinkLocalService& service) { - onPresenceChanged(getPresence(service)); -} - -void LinkLocalPresenceManager::handleServiceRemoved(const LinkLocalService& service) { - boost::shared_ptr<RosterPayload> roster(new RosterPayload()); - roster->addItem(RosterItemPayload(service.getJID(), "", RosterItemPayload::Remove)); - onRosterChanged(roster); -} - -boost::shared_ptr<RosterPayload> LinkLocalPresenceManager::getRoster() const { - boost::shared_ptr<RosterPayload> roster(new RosterPayload()); - foreach(const LinkLocalService& service, browser->getServices()) { - roster->addItem(getRosterItem(service)); - } - return roster; -} - -std::vector<boost::shared_ptr<Presence> > LinkLocalPresenceManager::getAllPresence() const { - std::vector<boost::shared_ptr<Presence> > result; - foreach(const LinkLocalService& service, browser->getServices()) { - result.push_back(getPresence(service)); - } - return result; -} - -RosterItemPayload LinkLocalPresenceManager::getRosterItem(const LinkLocalService& service) const { - return RosterItemPayload(service.getJID(), getRosterName(service), RosterItemPayload::Both); -} - -String LinkLocalPresenceManager::getRosterName(const LinkLocalService& service) const { - LinkLocalServiceInfo info = service.getInfo(); - if (!info.getNick().isEmpty()) { - return info.getNick(); - } - else if (!info.getFirstName().isEmpty()) { - String result = info.getFirstName(); - if (!info.getLastName().isEmpty()) { - result += " " + info.getLastName(); - } - return result; - } - else if (!info.getLastName().isEmpty()) { - return info.getLastName(); - } - return ""; -} - -boost::shared_ptr<Presence> LinkLocalPresenceManager::getPresence(const LinkLocalService& service) const { - boost::shared_ptr<Presence> presence(new Presence()); - presence->setFrom(service.getJID()); - switch (service.getInfo().getStatus()) { - case LinkLocalServiceInfo::Available: - presence->setShow(StatusShow::Online); - break; - case LinkLocalServiceInfo::Away: - presence->setShow(StatusShow::Away); - break; - case LinkLocalServiceInfo::DND: - presence->setShow(StatusShow::DND); - break; - } - presence->setStatus(service.getInfo().getMessage()); - return presence; -} - -} |