diff options
| -rw-r--r-- | Swift/Controllers/StatusCache.cpp | 2 | ||||
| -rw-r--r-- | Swift/QtUI/QtStatusWidget.cpp | 28 | ||||
| -rw-r--r-- | Swift/QtUI/QtStatusWidget.h | 1 |
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 @@ -22,25 +22,25 @@ StatusCache::StatusCache(ApplicationPathProvider* paths) { paths_ = paths; path_ = paths_->getDataDir() / "StatusCache"; loadRecents(); } 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; } } } return matches; } void StatusCache::addRecent(const std::string& text, StatusShow::Type type) { if (text.empty()) { return; 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 @@ -19,24 +19,31 @@ #include <QListWidgetItem> #include <QMovie> #include "Swift/QtUI/QtElidingLabel.h" #include "Swift/QtUI/QtLineEdit.h" #include "Swift/QtUI/QtSwiftUtil.h" #include <Swift/Controllers/StatusUtil.h> #include <Swift/Controllers/StatusCache.h> 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); connectingMovie_ = new QMovie(":/icons/connecting.mng"); QHBoxLayout* mainLayout = new QHBoxLayout(this); mainLayout->setSpacing(0); mainLayout->setContentsMargins(0,0,0,0); stack_ = new QStackedWidget(this); stack_->setLineWidth(2); @@ -128,31 +135,43 @@ void QtStatusWidget::generateList() { QString text = statusEdit_->text(); newStatusText_ = text; menu_->clear(); foreach (StatusShow::Type type, icons_.keys()) { QListWidgetItem* item = new QListWidgetItem(text == "" ? getNoMessage() : text, menu_); item->setIcon(icons_[type]); item->setToolTip(P2QSTRING(statusShowTypeToFriendlyName(type)) + ": " + item->text()); item->setStatusTip(item->toolTip()); item->setData(Qt::UserRole, QVariant(type)); } 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()); item->setStatusTip(item->toolTip()); 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()); item->setStatusTip(item->toolTip()); item->setData(Qt::UserRole, QVariant(type)); } resizeMenu(); } void QtStatusWidget::resizeMenu() { int height = menu_->sizeHintForRow(0) * menu_->count(); int marginLeft; @@ -171,32 +190,25 @@ void QtStatusWidget::handleClicked() { int screen = desktop->screenNumber(this); QPoint point = mapToGlobal(QPoint(0, height())); QRect geometry = desktop->availableGeometry(screen); int x = point.x(); int y = point.y(); int width = 200; int height = 80; int screenWidth = geometry.x() + geometry.width(); 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(""); } } generateList(); height = menu_->sizeHintForRow(0) * menu_->count(); int marginLeft; int marginTop; int marginRight; int marginBottom; menu_->getContentsMargins(&marginLeft, &marginTop, &marginRight, &marginBottom); 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 @@ -59,15 +59,16 @@ namespace Swift { QString statusText_; QString newStatusText_; QMap<StatusShow::Type, QIcon> icons_; StatusShow::Type selectedStatusType_; bool isClicking_; QListWidget* menu_; QCursor editCursor_; QCursor viewCursor_; bool editing_; QMovie* connectingMovie_; bool connecting_; static const QString NO_MESSAGE; + std::vector<StatusShow::Type> allTypes_; }; } |
Swift