summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Maudsley <richard.maudsley@isode.com>2014-07-03 10:42:32 (GMT)
committerSwift Review <review@swift.im>2014-07-09 13:29:35 (GMT)
commit43fce94494307d1b3a866f5781528c94df7e5bca (patch)
tree13b26494ae618047e0eecd7aa35fad850a58f34c
parent8e0e67a24bfa8d3dcdeef2f177449c2a35901b99 (diff)
downloadswift-contrib-43fce94494307d1b3a866f5781528c94df7e5bca.zip
swift-contrib-43fce94494307d1b3a866f5781528c94df7e5bca.tar.bz2
Honour 'show offline contacts' toggle when exiting roster search filter
Test-Information: Enter search term and check that toggling "show offline contacts" resets the QtFilterWidget and that the roster list is representative of the "show offline contacts" state. Ensure that "show offline contacts" behaves normally when no search term has been entered. Toggle "show offline contacts" several times to make sure it remains in-sync. Change-Id: Id92a6a65b8f38cf6806f22c175514283e05affa9
-rw-r--r--Swift/Controllers/Roster/Roster.cpp9
-rw-r--r--Swift/Controllers/Roster/Roster.h6
-rw-r--r--Swift/QtUI/Roster/QtFilterWidget.cpp22
-rw-r--r--Swift/QtUI/Roster/QtFilterWidget.h3
4 files changed, 36 insertions, 4 deletions
diff --git a/Swift/Controllers/Roster/Roster.cpp b/Swift/Controllers/Roster/Roster.cpp
index 44cf03d..4dbc453 100644
--- a/Swift/Controllers/Roster/Roster.cpp
+++ b/Swift/Controllers/Roster/Roster.cpp
@@ -191,26 +191,33 @@ void Roster::applyOnAllItems(const RosterItemOperation& operation) {
operation(item);
GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item);
if (group) {
queue.insert(queue.begin(), group->getChildren().begin(), group->getChildren().end());
}
}
filterAll();
}
-void Roster::removeFilter(RosterFilter *filter) {
+void Roster::addFilter(RosterFilter* filter) {
+ filters_.push_back(filter);
+ filterAll();
+ onFilterAdded(filter);
+}
+
+void Roster::removeFilter(RosterFilter* filter) {
for (unsigned int i = 0; i < filters_.size(); i++) {
if (filters_[i] == filter) {
filters_.erase(filters_.begin() + i);
break;
}
}
filterAll();
+ onFilterRemoved(filter);
}
void Roster::filterContact(ContactRosterItem* contact, GroupRosterItem* group) {
size_t oldDisplayedSize = group->getDisplayedChildren().size();
bool hide = true;
foreach (RosterFilter *filter, filters_) {
hide &= (*filter)(contact);
}
group->setDisplayed(contact, filters_.empty() || !hide);
diff --git a/Swift/Controllers/Roster/Roster.h b/Swift/Controllers/Roster/Roster.h
index b60eafa..9956cb9 100644
--- a/Swift/Controllers/Roster/Roster.h
+++ b/Swift/Controllers/Roster/Roster.h
@@ -32,26 +32,28 @@ class Roster {
void addContact(const JID& jid, const JID& displayJID, const std::string& name, const std::string& group, const boost::filesystem::path& avatarPath);
void removeContact(const JID& jid);
void removeContactFromGroup(const JID& jid, const std::string& group);
void removeGroup(const std::string& group);
void removeAll();
void applyOnItems(const RosterItemOperation& operation);
void applyOnAllItems(const RosterItemOperation& operation);
void applyOnItem(const RosterItemOperation& operation, const JID& jid);
- void addFilter(RosterFilter *filter) {filters_.push_back(filter);filterAll();}
- void removeFilter(RosterFilter *filter);
+ void addFilter(RosterFilter* filter);
+ void removeFilter(RosterFilter* filter);
GroupRosterItem* getRoot();
std::vector<RosterFilter*> getFilters() {return filters_;}
boost::signal<void (GroupRosterItem*)> onChildrenChanged;
boost::signal<void (GroupRosterItem*)> onGroupAdded;
boost::signal<void (RosterItem*)> onDataChanged;
boost::signal<void (JID&)> onVCardUpdateRequested;
+ boost::signal<void (RosterFilter* filter)> onFilterAdded;
+ boost::signal<void (RosterFilter* filter)> onFilterRemoved;
GroupRosterItem* getGroup(const std::string& groupName);
void setBlockingSupported(bool isSupported);
private:
void handleDataChanged(RosterItem* item);
void handleChildrenChanged(GroupRosterItem* item);
void filterGroup(GroupRosterItem* item);
void filterContact(ContactRosterItem* contact, GroupRosterItem* group);
void filterAll();
diff --git a/Swift/QtUI/Roster/QtFilterWidget.cpp b/Swift/QtUI/Roster/QtFilterWidget.cpp
index a4c9449..64eb312 100644
--- a/Swift/QtUI/Roster/QtFilterWidget.cpp
+++ b/Swift/QtUI/Roster/QtFilterWidget.cpp
@@ -80,37 +80,40 @@ bool QtFilterWidget::eventFilter(QObject*, QEvent* event) {
updateRosterFilters();
} else if (keyEvent->key() == Qt::Key_Escape) {
filterLineEdit_->setText("");
} else {
isModifierSinglePressed_ = false;
}
}
filterLineEdit_->event(event);
- filterLineEdit_->setVisible(!filterLineEdit_->text().isEmpty());
if (event->type() == QEvent::KeyRelease) {
updateRosterFilters();
}
return true;
}
return false;
}
void QtFilterWidget::popAllFilters() {
std::vector<RosterFilter*> filters = treeView_->getRoster()->getFilters();
foreach(RosterFilter* filter, filters) {
filters_.push_back(filter);
treeView_->getRoster()->removeFilter(filter);
}
+ treeView_->getRoster()->onFilterAdded.connect(boost::bind(&QtFilterWidget::handleFilterAdded, this, _1));
+ treeView_->getRoster()->onFilterRemoved.connect(boost::bind(&QtFilterWidget::handleFilterRemoved, this, _1));
}
void QtFilterWidget::pushAllFilters() {
+ treeView_->getRoster()->onFilterAdded.disconnect(boost::bind(&QtFilterWidget::handleFilterAdded, this, _1));
+ treeView_->getRoster()->onFilterRemoved.disconnect(boost::bind(&QtFilterWidget::handleFilterRemoved, this, _1));
foreach(RosterFilter* filter, filters_) {
treeView_->getRoster()->addFilter(filter);
}
filters_.clear();
}
void QtFilterWidget::updateRosterFilters() {
if (fuzzyRosterFilter_) {
if (filterLineEdit_->text().isEmpty()) {
@@ -124,23 +127,40 @@ void QtFilterWidget::updateRosterFilters() {
updateSearchFilter();
}
} else {
if (!filterLineEdit_->text().isEmpty()) {
// remove currently installed filters and put a search filter in place
popAllFilters();
updateSearchFilter();
}
}
+ filterLineEdit_->setVisible(!filterLineEdit_->text().isEmpty());
}
void QtFilterWidget::updateSearchFilter() {
if (fuzzyRosterFilter_) {
treeView_->getRoster()->removeFilter(fuzzyRosterFilter_);
delete fuzzyRosterFilter_;
fuzzyRosterFilter_ = NULL;
}
fuzzyRosterFilter_ = new FuzzyRosterFilter(Q2PSTRING(filterLineEdit_->text()));
treeView_->getRoster()->addFilter(fuzzyRosterFilter_);
treeView_->setCurrentIndex(sourceModel_->index(0, 0, sourceModel_->index(0,0)));
}
+void QtFilterWidget::handleFilterAdded(RosterFilter* filter) {
+ if (filter != fuzzyRosterFilter_) {
+ filterLineEdit_->setText("");
+ updateRosterFilters();
+ }
+}
+
+void QtFilterWidget::handleFilterRemoved(RosterFilter* filter) {
+ /* make sure we don't end up adding this one back in later */
+ filters_.erase(std::remove(filters_.begin(), filters_.end(), filter), filters_.end());
+ if (filter != fuzzyRosterFilter_) {
+ filterLineEdit_->setText("");
+ updateRosterFilters();
+ }
+}
+
}
diff --git a/Swift/QtUI/Roster/QtFilterWidget.h b/Swift/QtUI/Roster/QtFilterWidget.h
index 3e17566..d0307ea 100644
--- a/Swift/QtUI/Roster/QtFilterWidget.h
+++ b/Swift/QtUI/Roster/QtFilterWidget.h
@@ -29,18 +29,21 @@ class QtFilterWidget : public QWidget {
bool eventFilter(QObject*, QEvent* event);
private:
void popAllFilters();
void pushAllFilters();
void updateRosterFilters();
void updateSearchFilter();
+ void handleFilterAdded(RosterFilter* filter);
+ void handleFilterRemoved(RosterFilter* filter);
+
private:
QtClosableLineEdit* filterLineEdit_;
QtTreeWidget* treeView_;
UIEventStream* eventStream_;
std::vector<RosterFilter*> filters_;
QAbstractItemModel* sourceModel_;
FuzzyRosterFilter* fuzzyRosterFilter_;
bool isModifierSinglePressed_;
};