summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2015-01-16 20:50:59 (GMT)
committerSwift Review <review@swift.im>2015-02-09 21:43:54 (GMT)
commit672e56cd731d1cbc08941bf98d76699cd9fc4514 (patch)
tree8b8464d2a036ba7b398152e12a00f35eb173f5f8 /Swift
parent4fa1338b324c5e11218cea29c474da42b9142651 (diff)
downloadswift-672e56cd731d1cbc08941bf98d76699cd9fc4514.zip
swift-672e56cd731d1cbc08941bf98d76699cd9fc4514.tar.bz2
Fix UI update issue and enabled state of "Display Notice" in Notices view
EventModel was missing calls to endResetModel() in two return-paths. In addition the limit for inactiveEvents was out-of-sync in different places. The "Display Notice" button is now disabled if there is no notice left to display. Test-Information: Tested on Mac OS X 10.9.5. Change-Id: I2b74b942f58e80a9c1a46f434ffcebf8e1ce64bf
Diffstat (limited to 'Swift')
-rw-r--r--Swift/QtUI/EventViewer/EventModel.cpp13
-rw-r--r--Swift/QtUI/EventViewer/EventModel.h6
-rw-r--r--Swift/QtUI/EventViewer/QtEventWindow.cpp5
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,17 +1,22 @@
/*
- * Copyright (c) 2010-2014 Isode Limited.
+ * Copyright (c) 2010-2015 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/QtUI/EventViewer/EventModel.h>
#include <Swiften/Base/Log.h>
namespace Swift {
+
+namespace {
+ const int inactiveEventsLimit = 50;
+}
+
EventModel::EventModel() {
}
EventModel::~EventModel() {
foreach (QtEvent* event, activeEvents_) {
@@ -72,31 +77,33 @@ int EventModel::rowCount(const QModelIndex& parent) const {
void EventModel::addEvent(boost::shared_ptr<StanzaEvent> event, bool active) {
beginResetModel();
if (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();
}
void EventModel::removeEvent(boost::shared_ptr<StanzaEvent> event) {
beginResetModel();
for (int i = inactiveEvents_.size() - 1; i >= 0; i--) {
if (event == inactiveEvents_[i]->getEvent()) {
inactiveEvents_.removeAt(i);
+ endResetModel();
return;
}
}
for (int i = 0; i < activeEvents_.size(); i++) {
if (event == activeEvents_[i]->getEvent()) {
activeEvents_.removeAt(i);
+ endResetModel();
return;
}
}
endResetModel();
}
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,8 +1,8 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2015 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
@@ -17,21 +17,21 @@
namespace Swift {
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;
int rowCount(const QModelIndex& parent = QModelIndex()) const;
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,9 +1,9 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2015 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include "Swift/QtUI/EventViewer/QtEventWindow.h"
@@ -48,13 +48,12 @@ QtEventWindow::QtEventWindow(UIEventStream* eventStream) : EventWindow(false) {
readButton_ = new QPushButton(tr("Display Notice"), this);
layout->addWidget(readButton_);
readButton_->setEnabled(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() {
delete model_;
delete delegate_;
/* Not view_ because this is the parent */
@@ -103,15 +102,17 @@ void QtEventWindow::handleItemActivated(const QModelIndex& item) {
}
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);
}
}