summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2012-11-06 20:32:22 (GMT)
committerKevin Smith <git@kismith.co.uk>2012-12-23 11:46:06 (GMT)
commit90e22d09c0e7131744c9e343622013547319daf7 (patch)
treedecacff80e04696d9b28e24453025c894fa3a66d /Swift
parent0c2cd2338ef77441e5b6b2a4cf1f5d6591c5f480 (diff)
downloadswift-90e22d09c0e7131744c9e343622013547319daf7.zip
swift-90e22d09c0e7131744c9e343622013547319daf7.tar.bz2
Avoid any duplicates in the status menu
Change-Id: I43ced9659bf16bce637f5f16f0987b2289d372a1
Diffstat (limited to 'Swift')
-rw-r--r--Swift/Controllers/StatusCache.cpp2
-rw-r--r--Swift/QtUI/QtStatusWidget.cpp28
-rw-r--r--Swift/QtUI/QtStatusWidget.h1
3 files changed, 22 insertions, 9 deletions
diff --git a/Swift/Controllers/StatusCache.cpp b/Swift/Controllers/StatusCache.cpp
index ce69440..d3c8be5 100644
--- a/Swift/Controllers/StatusCache.cpp
+++ b/Swift/Controllers/StatusCache.cpp
@@ -31,7 +31,7 @@ StatusCache::~StatusCache() {
std::vector<StatusCache::PreviousStatus> StatusCache::getMatches(const std::string& substring, size_t maxCount) const {
std::vector<PreviousStatus> matches;
foreach (const PreviousStatus& status, previousStatuses_) {
- if (substring.empty() || boost::algorithm::ifind_first(status.first, substring)) {
+ if (substring.empty() || (boost::algorithm::ifind_first(status.first, substring) && substring != status.first)) {
matches.push_back(status);
if (matches.size() == maxCount) {
break;
diff --git a/Swift/QtUI/QtStatusWidget.cpp b/Swift/QtUI/QtStatusWidget.cpp
index fc1e764..7c1c831 100644
--- a/Swift/QtUI/QtStatusWidget.cpp
+++ b/Swift/QtUI/QtStatusWidget.cpp
@@ -28,6 +28,13 @@
namespace Swift {
QtStatusWidget::QtStatusWidget(StatusCache* statusCache, QWidget *parent) : QWidget(parent), statusCache_(statusCache), editCursor_(Qt::IBeamCursor), viewCursor_(Qt::PointingHandCursor) {
+ allTypes_.push_back(StatusShow::Online);
+ allTypes_.push_back(StatusShow::FFC);
+ allTypes_.push_back(StatusShow::Away);
+ allTypes_.push_back(StatusShow::XA);
+ allTypes_.push_back(StatusShow::DND);
+ allTypes_.push_back(StatusShow::None);
+
isClicking_ = false;
connecting_ = false;
setMaximumHeight(24);
@@ -137,6 +144,15 @@ void QtStatusWidget::generateList() {
}
std::vector<StatusCache::PreviousStatus> previousStatuses = statusCache_->getMatches(Q2PSTRING(text), 8);
foreach (StatusCache::PreviousStatus savedStatus, previousStatuses) {
+ bool breakEarly = false;
+ foreach (StatusShow::Type type, allTypes_) {
+ if (savedStatus.first.empty() || (savedStatus.second == type && savedStatus.first == statusShowTypeToFriendlyName(type))) {
+ breakEarly = true;
+ }
+ }
+ if (breakEarly) {
+ continue;
+ }
QListWidgetItem* item = new QListWidgetItem(P2QSTRING(savedStatus.first), menu_);
item->setIcon(icons_[savedStatus.second]);
item->setToolTip(item->text());
@@ -144,6 +160,9 @@ void QtStatusWidget::generateList() {
item->setData(Qt::UserRole, QVariant(savedStatus.second));
}
foreach (StatusShow::Type type, icons_.keys()) {
+ if (Q2PSTRING(text) == statusShowTypeToFriendlyName(type)) {
+ continue;
+ }
QListWidgetItem* item = new QListWidgetItem(P2QSTRING(statusShowTypeToFriendlyName(type)), menu_);
item->setIcon(icons_[type]);
item->setToolTip(item->text());
@@ -180,14 +199,7 @@ void QtStatusWidget::handleClicked() {
if (x + width > screenWidth) {
x = screenWidth - width;
}
- std::vector<StatusShow::Type> types;
- types.push_back(StatusShow::Online);
- types.push_back(StatusShow::FFC);
- types.push_back(StatusShow::Away);
- types.push_back(StatusShow::XA);
- types.push_back(StatusShow::DND);
- types.push_back(StatusShow::None);
- foreach (StatusShow::Type type, types) {
+ foreach (StatusShow::Type type, allTypes_) {
if (statusEdit_->text() == P2QSTRING(statusShowTypeToFriendlyName(type))) {
statusEdit_->setText("");
}
diff --git a/Swift/QtUI/QtStatusWidget.h b/Swift/QtUI/QtStatusWidget.h
index 57f52c6..87e8d4a 100644
--- a/Swift/QtUI/QtStatusWidget.h
+++ b/Swift/QtUI/QtStatusWidget.h
@@ -68,6 +68,7 @@ namespace Swift {
QMovie* connectingMovie_;
bool connecting_;
static const QString NO_MESSAGE;
+ std::vector<StatusShow::Type> allTypes_;
};
}