summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-03-19 17:49:50 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-03-19 17:49:50 (GMT)
commitcd1801ca176553c2c1727745228cdd2f076b62a5 (patch)
tree4804f34a5a2fbba70e7487022ddf198a5af95db4
parent580d3d49ea3df7bb1c00cb1052203d17ccaa9a8e (diff)
downloadswift-contrib-cd1801ca176553c2c1727745228cdd2f076b62a5.zip
swift-contrib-cd1801ca176553c2c1727745228cdd2f076b62a5.tar.bz2
Don't show messages forever in the EventViewer.
-rw-r--r--Swift/Controllers/EventWindowController.cpp10
-rw-r--r--Swift/Controllers/EventWindowController.h2
-rw-r--r--Swift/Controllers/UIInterfaces/EventWindow.h1
-rw-r--r--Swift/QtUI/EventViewer/EventModel.cpp18
-rw-r--r--Swift/QtUI/EventViewer/main.cpp5
5 files changed, 27 insertions, 9 deletions
diff --git a/Swift/Controllers/EventWindowController.cpp b/Swift/Controllers/EventWindowController.cpp
index 4bc5c22..a6611fc 100644
--- a/Swift/Controllers/EventWindowController.cpp
+++ b/Swift/Controllers/EventWindowController.cpp
@@ -11,8 +11,18 @@ EventWindowController::EventWindowController(EventController* eventController, E
eventController_->onEventQueueEventAdded.connect(boost::bind(&EventWindowController::handleEventQueueEventAdded, this, _1));
}
+EventWindowController::~EventWindowController() {
+ delete window_;
+}
+
void EventWindowController::handleEventQueueEventAdded(boost::shared_ptr<Event> event) {
+ event->onConclusion.connect(boost::bind(&EventWindowController::handleEventConcluded, this, event));
window_->addEvent(event, true);
}
+void EventWindowController::handleEventConcluded(boost::shared_ptr<Event> event) {
+ window_->removeEvent(event);
+ window_->addEvent(event, false);
+}
+
}
diff --git a/Swift/Controllers/EventWindowController.h b/Swift/Controllers/EventWindowController.h
index 0c06f49..c612265 100644
--- a/Swift/Controllers/EventWindowController.h
+++ b/Swift/Controllers/EventWindowController.h
@@ -10,8 +10,10 @@ namespace Swift {
class EventWindowController {
public:
EventWindowController(EventController* eventController, EventWindowFactory* windowFactory);
+ ~EventWindowController();
private:
void handleEventQueueEventAdded(boost::shared_ptr<Event> event);
+ void handleEventConcluded(boost::shared_ptr<Event> event);
EventController* eventController_;
EventWindowFactory* windowFactory_;
diff --git a/Swift/Controllers/UIInterfaces/EventWindow.h b/Swift/Controllers/UIInterfaces/EventWindow.h
index 6cc5bbd..95bd7dd 100644
--- a/Swift/Controllers/UIInterfaces/EventWindow.h
+++ b/Swift/Controllers/UIInterfaces/EventWindow.h
@@ -6,6 +6,7 @@
namespace Swift {
class EventWindow {
public:
+ virtual ~EventWindow() {};
virtual void addEvent(boost::shared_ptr<Event> event, bool active) = 0;
virtual void removeEvent(boost::shared_ptr<Event> event) = 0;
};
diff --git a/Swift/QtUI/EventViewer/EventModel.cpp b/Swift/QtUI/EventViewer/EventModel.cpp
index ffe2110..f75fe74 100644
--- a/Swift/QtUI/EventViewer/EventModel.cpp
+++ b/Swift/QtUI/EventViewer/EventModel.cpp
@@ -41,11 +41,22 @@ void EventModel::addEvent(boost::shared_ptr<Event> event, bool active) {
} else {
inactiveEvents_.push_front(new QtEvent(event, active));
emit dataChanged(createIndex(activeEvents_.size() -1, 0), createIndex(activeEvents_.size(), 0));
+ if (inactiveEvents_.size() > 50) {
+ removeEvent(inactiveEvents_[20]->getEvent());
+ }
}
emit layoutChanged();
}
void EventModel::removeEvent(boost::shared_ptr<Event> event) {
+ for (int i = inactiveEvents_.size() - 1; i >= 0; i--) {
+ if (event == inactiveEvents_[i]->getEvent()) {
+ inactiveEvents_.removeAt(i);
+ emit dataChanged(createIndex(activeEvents_.size() + i - 1, 0), createIndex(activeEvents_.size() + i - 1, 0));
+ return;
+ }
+ }
+
for (int i = 0; i < activeEvents_.size(); i++) {
if (event == activeEvents_[i]->getEvent()) {
activeEvents_.removeAt(i);
@@ -53,13 +64,6 @@ void EventModel::removeEvent(boost::shared_ptr<Event> event) {
return;
}
}
- for (int i = 0; i < inactiveEvents_.size(); i++) {
- if (event == inactiveEvents_[i]->getEvent()) {
- inactiveEvents_.removeAt(i);
- emit dataChanged(createIndex(activeEvents_.size() + i - 1, 0), createIndex(activeEvents_.size() + i - 1, 0));
- return;
- }
- }
}
diff --git a/Swift/QtUI/EventViewer/main.cpp b/Swift/QtUI/EventViewer/main.cpp
index 647010d..1e8163b 100644
--- a/Swift/QtUI/EventViewer/main.cpp
+++ b/Swift/QtUI/EventViewer/main.cpp
@@ -14,7 +14,8 @@ int main(int argc, char *argv[])
message1->setBody("Oooh, shiny");
boost::shared_ptr<Swift::MessageEvent> event1(new Swift::MessageEvent(message1));
viewer->addEvent(boost::dynamic_pointer_cast<Swift::Event>(event1), true);
- viewer->addEvent(boost::dynamic_pointer_cast<Swift::Event>(event1), false);
- viewer->addEvent(boost::dynamic_pointer_cast<Swift::Event>(event1), false);
+ for (int i = 0; i < 100; i++) {
+ viewer->addEvent(boost::dynamic_pointer_cast<Swift::Event>(event1), false);
+ }
return app.exec();
}