diff options
Diffstat (limited to 'Swift/Controllers/Roster')
-rw-r--r-- | Swift/Controllers/Roster/ContactRosterItem.cpp | 1 | ||||
-rw-r--r-- | Swift/Controllers/Roster/RosterGroupExpandinessPersister.cpp | 3 | ||||
-rw-r--r-- | Swift/Controllers/Roster/TableRoster.cpp | 5 |
3 files changed, 3 insertions, 6 deletions
diff --git a/Swift/Controllers/Roster/ContactRosterItem.cpp b/Swift/Controllers/Roster/ContactRosterItem.cpp index 71c5f8e..8fdf183 100644 --- a/Swift/Controllers/Roster/ContactRosterItem.cpp +++ b/Swift/Controllers/Roster/ContactRosterItem.cpp @@ -1,42 +1,41 @@ /* * 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/Base/foreach.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; } diff --git a/Swift/Controllers/Roster/RosterGroupExpandinessPersister.cpp b/Swift/Controllers/Roster/RosterGroupExpandinessPersister.cpp index af89b54..0f07c0b 100644 --- a/Swift/Controllers/Roster/RosterGroupExpandinessPersister.cpp +++ b/Swift/Controllers/Roster/RosterGroupExpandinessPersister.cpp @@ -1,65 +1,64 @@ /* * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swift/Controllers/Roster/RosterGroupExpandinessPersister.h> #include <vector> #include <boost/bind.hpp> #include <Swiften/Base/String.h> -#include <Swiften/Base/foreach.h> #include <Swift/Controllers/Roster/GroupRosterItem.h> #include <Swift/Controllers/SettingConstants.h> namespace Swift { RosterGroupExpandinessPersister::RosterGroupExpandinessPersister(Roster* roster, SettingsProvider* settings) : roster_(roster), settings_(settings) { load(); roster_->onGroupAdded.connect(boost::bind(&RosterGroupExpandinessPersister::handleGroupAdded, this, _1)); } void RosterGroupExpandinessPersister::handleGroupAdded(GroupRosterItem* group) { if (collapsed_.find(group->getDisplayName()) != collapsed_.end()) { group->setExpanded(false); } else { group->setExpanded(true); } group->onExpandedChanged.connect(boost::bind(&RosterGroupExpandinessPersister::handleExpandedChanged, this, group, _1)); } void RosterGroupExpandinessPersister::handleExpandedChanged(GroupRosterItem* group, bool expanded) { if (expanded) { std::string displayName = group->getDisplayName(); //collapsed_.erase(std::remove(collapsed_.begin(), collapsed_.end(), displayName), collapsed_.end()); collapsed_.erase(displayName); } else { collapsed_.insert(group->getDisplayName()); } save(); } void RosterGroupExpandinessPersister::save() { std::string setting; - foreach (const std::string& group, collapsed_) { + for (const auto& group : collapsed_) { if (!setting.empty()) { setting += "\n"; } setting += group; } settings_->storeSetting(SettingConstants::EXPANDED_ROSTER_GROUPS, setting); } void RosterGroupExpandinessPersister::load() { std::string saved = settings_->getSetting(SettingConstants::EXPANDED_ROSTER_GROUPS); std::vector<std::string> collapsed = String::split(saved, '\n'); collapsed_.insert(collapsed.begin(), collapsed.end()); } } diff --git a/Swift/Controllers/Roster/TableRoster.cpp b/Swift/Controllers/Roster/TableRoster.cpp index f164a4d..713f390 100644 --- a/Swift/Controllers/Roster/TableRoster.cpp +++ b/Swift/Controllers/Roster/TableRoster.cpp @@ -1,45 +1,44 @@ /* * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swift/Controllers/Roster/TableRoster.h> #include <algorithm> #include <cassert> #include <boost/cast.hpp> #include <boost/numeric/conversion/cast.hpp> -#include <Swiften/Base/foreach.h> #include <Swiften/Network/Timer.h> #include <Swiften/Network/TimerFactory.h> #include <Swift/Controllers/Roster/GroupRosterItem.h> #include <Swift/Controllers/Roster/LeastCommonSubsequence.h> #include <Swift/Controllers/Roster/Roster.h> namespace Swift { struct SectionNameEquals { bool operator()(const TableRoster::Section& s1, const TableRoster::Section& s2) const { return s1.name == s2.name; } }; template<typename T> struct True { bool operator()(const T&, const T&) const { return true; } }; struct ItemEquals { bool operator()(const TableRoster::Item& i1, const TableRoster::Item& i2) const { return i1.jid == i2.jid; } }; struct ItemNeedsUpdate { bool operator()(const TableRoster::Item& i1, const TableRoster::Item& i2) const { @@ -77,65 +76,65 @@ TableRoster::~TableRoster() { if (model) { model->onDataChanged.disconnect(boost::bind(&TableRoster::scheduleUpdate, this)); model->onGroupAdded.disconnect(boost::bind(&TableRoster::scheduleUpdate, this)); model->onChildrenChanged.disconnect(boost::bind(&TableRoster::scheduleUpdate, this)); } } size_t TableRoster::getNumberOfSections() const { return sections.size(); } const std::string& TableRoster::getSectionTitle(size_t section) { return sections[section].name; } size_t TableRoster::getNumberOfRowsInSection(size_t section) const { return sections[section].items.size(); } const TableRoster::Item& TableRoster::getItem(const Index& index) const { return sections[index.section].items[index.row]; } void TableRoster::handleUpdateTimerTick() { updateTimer->stop(); updatePending = false; // Get a model for the new roster std::vector<Section> newSections; if (model) { - foreach(RosterItem* item, model->getRoot()->getDisplayedChildren()) { + for (auto item : model->getRoot()->getDisplayedChildren()) { if (GroupRosterItem* groupItem = boost::polymorphic_downcast<GroupRosterItem*>(item)) { //std::cerr << "* " << groupItem->getDisplayName() << std::endl; Section section(groupItem->getDisplayName()); - foreach(RosterItem* groupChildItem, groupItem->getDisplayedChildren()) { + for (auto groupChildItem : groupItem->getDisplayedChildren()) { if (ContactRosterItem* contact = boost::polymorphic_downcast<ContactRosterItem*>(groupChildItem)) { //std::cerr << " - " << contact->getDisplayJID() << std::endl; section.items.push_back(Item(contact->getDisplayName(), contact->getStatusText(), contact->getDisplayJID(), contact->getStatusShow(), contact->getAvatarPath())); } } newSections.push_back(section); } } } // Do a diff with the previous roster Update update; std::vector<size_t> sectionUpdates; std::vector<size_t> sectionPostUpdates; computeIndexDiff<Section,SectionNameEquals,True<Section> >(sections, newSections, sectionUpdates, sectionPostUpdates, update.deletedSections, update.insertedSections); assert(sectionUpdates.size() == sectionPostUpdates.size()); for (size_t i = 0; i < sectionUpdates.size(); ++i) { assert(sectionUpdates[i] < sections.size()); assert(sectionPostUpdates[i] < newSections.size()); std::vector<size_t> itemUpdates; std::vector<size_t> itemPostUpdates; std::vector<size_t> itemRemoves; std::vector<size_t> itemInserts; computeIndexDiff<Item, ItemEquals, ItemNeedsUpdate >(sections[sectionUpdates[i]].items, newSections[sectionPostUpdates[i]].items, itemUpdates, itemPostUpdates, itemRemoves, itemInserts); size_t end = update.insertedRows.size(); update.insertedRows.resize(update.insertedRows.size() + itemInserts.size()); std::transform(itemInserts.begin(), itemInserts.end(), update.insertedRows.begin() + boost::numeric_cast<long long>(end), CreateIndexForSection(sectionPostUpdates[i])); end = update.deletedRows.size(); update.deletedRows.resize(update.deletedRows.size() + itemRemoves.size()); std::transform(itemRemoves.begin(), itemRemoves.end(), update.deletedRows.begin() + boost::numeric_cast<long long>(end), CreateIndexForSection(sectionUpdates[i])); |