summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-08-20 14:28:10 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-08-20 14:28:10 (GMT)
commit7e78cc2b173db39f12e92a929ad17b706877e33d (patch)
treefdebc18a100fe1d16e174262297dbd7a4016abe9
parentb3de442223a5b3281c159b34f047d715da8ca3c9 (diff)
downloadswift-7e78cc2b173db39f12e92a929ad17b706877e33d.zip
swift-7e78cc2b173db39f12e92a929ad17b706877e33d.tar.bz2
Don't include status in MUC roster sorting.
Resolves: #536
-rw-r--r--Swift/Controllers/Chat/MUCController.cpp2
-rw-r--r--Swiften/Roster/GroupRosterItem.cpp10
-rw-r--r--Swiften/Roster/GroupRosterItem.h6
-rw-r--r--Swiften/Roster/Roster.cpp7
-rw-r--r--Swiften/Roster/Roster.h3
5 files changed, 18 insertions, 10 deletions
diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp
index 1ea0ad1..d84c399 100644
--- a/Swift/Controllers/Chat/MUCController.cpp
+++ b/Swift/Controllers/Chat/MUCController.cpp
@@ -52,7 +52,7 @@ MUCController::MUCController (
joined_ = false;
events_ = uiEventStream;
- roster_ = new Roster(true);
+ roster_ = new Roster(false, true);
completer_ = new TabComplete();
chatWindow_->setRosterModel(roster_);
chatWindow_->setTabComplete(completer_);
diff --git a/Swiften/Roster/GroupRosterItem.cpp b/Swiften/Roster/GroupRosterItem.cpp
index bf4f838..aa9fdd4 100644
--- a/Swiften/Roster/GroupRosterItem.cpp
+++ b/Swiften/Roster/GroupRosterItem.cpp
@@ -12,7 +12,7 @@
namespace Swift {
-GroupRosterItem::GroupRosterItem(const String& name, GroupRosterItem* parent) : RosterItem(name, parent) {
+GroupRosterItem::GroupRosterItem(const String& name, GroupRosterItem* parent, bool sortByStatus) : RosterItem(name, parent), sortByStatus_(sortByStatus) {
expanded_ = true;
}
@@ -115,11 +115,15 @@ bool GroupRosterItem::sortDisplayed() {
// return false;
// }
//Sholudn't need stable_sort here
- std::sort(displayedChildren_.begin(), displayedChildren_.end(), itemLessThan);
+ std::sort(displayedChildren_.begin(), displayedChildren_.end(), sortByStatus_? itemLessThanWithStatus : itemLessThanWithoutStatus);
return true;
}
-bool GroupRosterItem::itemLessThan(const RosterItem* left, const RosterItem* right) {
+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) {
diff --git a/Swiften/Roster/GroupRosterItem.h b/Swiften/Roster/GroupRosterItem.h
index 096d053..67ced97 100644
--- a/Swiften/Roster/GroupRosterItem.h
+++ b/Swiften/Roster/GroupRosterItem.h
@@ -16,7 +16,7 @@ namespace Swift {
class GroupRosterItem : public RosterItem {
public:
- GroupRosterItem(const String& name, GroupRosterItem* parent);
+ GroupRosterItem(const String& name, GroupRosterItem* parent, bool sortByStatus);
virtual ~GroupRosterItem();
const std::vector<RosterItem*>& getChildren() const;
const std::vector<RosterItem*>& getDisplayedChildren() const;
@@ -25,7 +25,8 @@ class GroupRosterItem : public RosterItem {
void removeAll();
void setDisplayed(RosterItem* item, bool displayed);
boost::signal<void ()> onChildrenChanged;
- static bool itemLessThan(const RosterItem* left, const RosterItem* right);
+ 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;
private:
@@ -36,6 +37,7 @@ class GroupRosterItem : public RosterItem {
bool expanded_;
std::vector<RosterItem*> children_;
std::vector<RosterItem*> displayedChildren_;
+ bool sortByStatus_;
};
}
diff --git a/Swiften/Roster/Roster.cpp b/Swiften/Roster/Roster.cpp
index e91b843..64a7241 100644
--- a/Swiften/Roster/Roster.cpp
+++ b/Swiften/Roster/Roster.cpp
@@ -21,9 +21,10 @@
namespace Swift {
-Roster::Roster(bool fullJIDMapping) {
+Roster::Roster(bool sortByStatus, bool fullJIDMapping) {
+ sortByStatus_ = sortByStatus;
fullJIDMapping_ = fullJIDMapping;
- root_ = new GroupRosterItem("Dummy-Root", NULL);
+ root_ = new GroupRosterItem("Dummy-Root", NULL, sortByStatus_);
root_->onChildrenChanged.connect(boost::bind(&Roster::handleChildrenChanged, this, root_));
}
@@ -52,7 +53,7 @@ GroupRosterItem* Roster::getGroup(const String& groupName) {
return group;
}
}
- GroupRosterItem* group = new GroupRosterItem(groupName, root_);
+ 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));
diff --git a/Swiften/Roster/Roster.h b/Swiften/Roster/Roster.h
index d54a12e..aa117d7 100644
--- a/Swiften/Roster/Roster.h
+++ b/Swiften/Roster/Roster.h
@@ -25,7 +25,7 @@ class ContactRosterItem;
class Roster {
public:
- Roster(bool fullJIDMapping = false);
+ Roster(bool sortByStatus = true, bool fullJIDMapping = false);
~Roster();
void addContact(const JID& jid, const JID& displayJID, const String& name, const String& group);
@@ -53,6 +53,7 @@ class Roster {
std::vector<RosterFilter*> filters_;
std::map<JID, std::vector<ContactRosterItem*> > itemMap_;
bool fullJIDMapping_;
+ bool sortByStatus_;
};
}