diff options
| author | Kevin Smith <git@kismith.co.uk> | 2010-05-07 09:19:08 (GMT) | 
|---|---|---|
| committer | Kevin Smith <git@kismith.co.uk> | 2010-05-07 09:19:08 (GMT) | 
| commit | 2dd59db4ae815e2e6e487e4c0078d3dc495e95f0 (patch) | |
| tree | ccc8110e80071e743f5c536e4910886d2feef345 /Swiften/Roster/GroupRosterItem.cpp | |
| parent | 5409f27bbc3b32a65b2feed3259b1cc15da888a3 (diff) | |
| download | swift-2dd59db4ae815e2e6e487e4c0078d3dc495e95f0.zip swift-2dd59db4ae815e2e6e487e4c0078d3dc495e95f0.tar.bz2 | |
Sort the roster
Diffstat (limited to 'Swiften/Roster/GroupRosterItem.cpp')
| -rw-r--r-- | Swiften/Roster/GroupRosterItem.cpp | 23 | 
1 files changed, 21 insertions, 2 deletions
| diff --git a/Swiften/Roster/GroupRosterItem.cpp b/Swiften/Roster/GroupRosterItem.cpp index b55ce17..2632444 100644 --- a/Swiften/Roster/GroupRosterItem.cpp +++ b/Swiften/Roster/GroupRosterItem.cpp @@ -7,6 +7,7 @@  #include "Swiften/Roster/GroupRosterItem.h"  #include <boost/bind.hpp> +//#include <boost/algorithm.hpp>  #include <iostream>  namespace Swift { @@ -33,6 +34,8 @@ void GroupRosterItem::addChild(RosterItem* 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(); @@ -68,8 +71,17 @@ ContactRosterItem* GroupRosterItem::removeChild(const JID& jid) {  	return removed;  } -void GroupRosterItem::sortDisplayed() { -	std::stable_sort(displayedChildren_.begin(), displayedChildren_.end(), itemLessThan); +/** + * 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(), itemLessThan); +	return true;  }  bool GroupRosterItem::itemLessThan(const RosterItem* left, const RosterItem* right) { @@ -90,6 +102,7 @@ bool GroupRosterItem::itemLessThan(const RosterItem* left, const RosterItem* rig  		if (rightContact) {  			return true;  		} +//		std::cout << "Comparing groups " << left->getSortableDisplayName() << " and " << right->getSortableDisplayName() << std::endl;  		return left->getSortableDisplayName() < right->getSortableDisplayName();  	}  } @@ -114,6 +127,12 @@ void GroupRosterItem::setDisplayed(RosterItem* item, bool displayed) {  	onChildrenChanged();  } +void GroupRosterItem::handleDataChanged(RosterItem* /*item*/) { +	if (sortDisplayed()) { +		onChildrenChanged(); +	} +} +  void GroupRosterItem::handleChildrenChanged(GroupRosterItem* group) {  	size_t oldSize = getDisplayedChildren().size();  	if (group->getDisplayedChildren().size() > 0) { | 
 Swift
 Swift