diff options
author | Remko Tronçon <git@el-tramo.be> | 2011-02-06 22:50:30 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2011-02-07 15:22:48 (GMT) |
commit | afcfa9dd33cfb5e36edf7d8148a7f8b24c976741 (patch) | |
tree | c16d40dbb089a9bcf70fafc2d50def34a9984e58 /Swiften/Roster/XMPPRosterImpl.cpp | |
parent | 90a511ed523cfaf500dd27316b12e128e0c70ce3 (diff) | |
download | swift-contrib-afcfa9dd33cfb5e36edf7d8148a7f8b24c976741.zip swift-contrib-afcfa9dd33cfb5e36edf7d8148a7f8b24c976741.tar.bz2 |
Reworking contact editing.
Collapsed rename, group edit, and remove into one dialog.
Moved contact editing logic to controllers.
Diffstat (limited to 'Swiften/Roster/XMPPRosterImpl.cpp')
-rw-r--r-- | Swiften/Roster/XMPPRosterImpl.cpp | 72 |
1 files changed, 53 insertions, 19 deletions
diff --git a/Swiften/Roster/XMPPRosterImpl.cpp b/Swiften/Roster/XMPPRosterImpl.cpp index 762ae29..3e9e312 100644 --- a/Swiften/Roster/XMPPRosterImpl.cpp +++ b/Swiften/Roster/XMPPRosterImpl.cpp @@ -4,7 +4,8 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swiften/Roster/XMPPRosterImpl.h" +#include <Swiften/Roster/XMPPRosterImpl.h> +#include <Swiften/Base/foreach.h> namespace Swift { @@ -13,21 +14,15 @@ XMPPRosterImpl::XMPPRosterImpl() { void XMPPRosterImpl::addContact(const JID& jid, const String& name, const std::vector<String>& groups, RosterItemPayload::Subscription subscription) { JID bareJID(jid.toBare()); - bool exists = containsJID(bareJID); - String oldName = getNameForJID(bareJID); - std::vector<String> oldGroups = entries_[bareJID].groups; - if (exists) { - entries_.erase(bareJID); - } - XMPPRosterItem item; - item.groups = groups; - item.name = name; - item.jid = jid; - item.subscription = subscription; - entries_[bareJID] = item; - if (exists) { + std::map<JID, XMPPRosterItem>::iterator i = entries_.find(bareJID); + if (i != entries_.end()) { + String oldName = i->second.getName(); + std::vector<String> oldGroups = i->second.getGroups(); + i->second = XMPPRosterItem(jid, name, groups, subscription); onJIDUpdated(bareJID, oldName, oldGroups); - } else { + } + else { + entries_.insert(std::make_pair(bareJID, XMPPRosterItem(jid, name, groups, subscription))); onJIDAdded(bareJID); } } @@ -49,19 +44,58 @@ bool XMPPRosterImpl::containsJID(const JID& jid) { String XMPPRosterImpl::getNameForJID(const JID& jid) const { std::map<JID, XMPPRosterItem>::const_iterator i = entries_.find(jid.toBare()); if (i != entries_.end()) { - return i->second.name; + return i->second.getName(); } else { return ""; } } -const std::vector<String>& XMPPRosterImpl::getGroupsForJID(const JID& jid) { - return entries_[JID(jid.toBare())].groups; +std::vector<String> XMPPRosterImpl::getGroupsForJID(const JID& jid) { + std::map<JID, XMPPRosterItem>::iterator i = entries_.find(jid.toBare()); + if (i != entries_.end()) { + return i->second.getGroups(); + } + else { + return std::vector<String>(); + } } RosterItemPayload::Subscription XMPPRosterImpl::getSubscriptionStateForJID(const JID& jid) { - return entries_[JID(jid.toBare())].subscription; + std::map<JID, XMPPRosterItem>::iterator i = entries_.find(jid.toBare()); + if (i != entries_.end()) { + return i->second.getSubscription(); + } + else { + return RosterItemPayload::None; + } +} + +std::vector<XMPPRosterItem> XMPPRosterImpl::getItems() const { + std::vector<XMPPRosterItem> result; + foreach(const RosterMap::value_type& entry, entries_) { + result.push_back(entry.second); + } + return result; +} + +boost::optional<XMPPRosterItem> XMPPRosterImpl::getItem(const JID& jid) const { + std::map<JID, XMPPRosterItem>::const_iterator i = entries_.find(jid.toBare()); + if (i != entries_.end()) { + return i->second; + } + else { + return boost::optional<XMPPRosterItem>(); + } +} + +std::set<String> XMPPRosterImpl::getGroups() const { + std::set<String> result; + foreach(const RosterMap::value_type& entry, entries_) { + std::vector<String> groups = entry.second.getGroups(); + result.insert(groups.begin(), groups.end()); + } + return result; } } |