diff options
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/QtUI/EventViewer/EventModel.cpp | 13 | ||||
-rw-r--r-- | Swift/QtUI/EventViewer/EventModel.h | 6 | ||||
-rw-r--r-- | Swift/QtUI/EventViewer/QtEventWindow.cpp | 5 |
3 files changed, 16 insertions, 8 deletions
diff --git a/Swift/QtUI/EventViewer/EventModel.cpp b/Swift/QtUI/EventViewer/EventModel.cpp index 1d1a378..889bcac 100644 --- a/Swift/QtUI/EventViewer/EventModel.cpp +++ b/Swift/QtUI/EventViewer/EventModel.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2014 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -9,6 +9,11 @@ #include <Swiften/Base/Log.h> namespace Swift { + +namespace { + const int inactiveEventsLimit = 50; +} + EventModel::EventModel() { } @@ -75,8 +80,8 @@ void EventModel::addEvent(boost::shared_ptr<StanzaEvent> event, bool active) { activeEvents_.push_front(new QtEvent(event, active)); } else { inactiveEvents_.push_front(new QtEvent(event, active)); - if (inactiveEvents_.size() > 50) { - removeEvent(inactiveEvents_[20]->getEvent()); + if (inactiveEvents_.size() > inactiveEventsLimit) { + removeEvent(inactiveEvents_[inactiveEventsLimit]->getEvent()); } } endResetModel(); @@ -87,6 +92,7 @@ void EventModel::removeEvent(boost::shared_ptr<StanzaEvent> event) { for (int i = inactiveEvents_.size() - 1; i >= 0; i--) { if (event == inactiveEvents_[i]->getEvent()) { inactiveEvents_.removeAt(i); + endResetModel(); return; } } @@ -94,6 +100,7 @@ void EventModel::removeEvent(boost::shared_ptr<StanzaEvent> event) { for (int i = 0; i < activeEvents_.size(); i++) { if (event == activeEvents_[i]->getEvent()) { activeEvents_.removeAt(i); + endResetModel(); return; } } diff --git a/Swift/QtUI/EventViewer/EventModel.h b/Swift/QtUI/EventViewer/EventModel.h index 50334da..cf259f2 100644 --- a/Swift/QtUI/EventViewer/EventModel.h +++ b/Swift/QtUI/EventViewer/EventModel.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -20,7 +20,7 @@ class EventModel : public QAbstractListModel { Q_OBJECT public: EventModel(); - ~EventModel(); + virtual ~EventModel(); void addEvent(boost::shared_ptr<StanzaEvent> event, bool active); void removeEvent(boost::shared_ptr<StanzaEvent> event); QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; @@ -28,7 +28,7 @@ class EventModel : public QAbstractListModel { QtEvent* getItem(int row) const; int getNewEventCount(); protected: - QModelIndex index ( int row, int column = 0, const QModelIndex & parent = QModelIndex() ) const; + QModelIndex index(int row, int column = 0, const QModelIndex & parent = QModelIndex()) const; private: QList<QtEvent*> activeEvents_; QList<QtEvent*> inactiveEvents_; diff --git a/Swift/QtUI/EventViewer/QtEventWindow.cpp b/Swift/QtUI/EventViewer/QtEventWindow.cpp index 06bfd98..3072497 100644 --- a/Swift/QtUI/EventViewer/QtEventWindow.cpp +++ b/Swift/QtUI/EventViewer/QtEventWindow.cpp @@ -1,6 +1,6 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -51,7 +51,6 @@ QtEventWindow::QtEventWindow(UIEventStream* eventStream) : EventWindow(false) { connect(readButton_, SIGNAL(clicked()), this, SLOT(handleReadClicked())); connect(view_, SIGNAL(clicked(const QModelIndex&)), this, SLOT(handleItemClicked(const QModelIndex&))); connect(view_, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleItemActivated(const QModelIndex&))); - } QtEventWindow::~QtEventWindow() { @@ -106,12 +105,14 @@ void QtEventWindow::addEvent(boost::shared_ptr<StanzaEvent> event, bool active) view_->clearSelection(); model_->addEvent(event, active); emit onNewEventCountUpdated(model_->getNewEventCount()); + readButton_->setEnabled(model_->rowCount() > 0); } void QtEventWindow::removeEvent(boost::shared_ptr<StanzaEvent> event) { view_->clearSelection(); model_->removeEvent(event); emit onNewEventCountUpdated(model_->getNewEventCount()); + readButton_->setEnabled(model_->rowCount() > 0); } } |