summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-03-19 09:17:18 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-03-19 15:10:33 (GMT)
commit580d3d49ea3df7bb1c00cb1052203d17ccaa9a8e (patch)
treec823ef404a7a70c261248c41530827caab07fc52 /Swift/QtUI/EventViewer
parent5d9a6702c244eb4ab30ce96465d9deceedfe955a (diff)
downloadswift-580d3d49ea3df7bb1c00cb1052203d17ccaa9a8e.zip
swift-580d3d49ea3df7bb1c00cb1052203d17ccaa9a8e.tar.bz2
Start of event viewer.
Creates a basic event viewer framework, and plugs it into the Swift controllers, so that messages are displayed (in a very ugly way). Still a long way to go.
Diffstat (limited to 'Swift/QtUI/EventViewer')
-rw-r--r--Swift/QtUI/EventViewer/EventDelegate.cpp9
-rw-r--r--Swift/QtUI/EventViewer/EventDelegate.h11
-rw-r--r--Swift/QtUI/EventViewer/EventModel.cpp56
-rw-r--r--Swift/QtUI/EventViewer/EventModel.h11
-rw-r--r--Swift/QtUI/EventViewer/EventView.pri11
-rw-r--r--Swift/QtUI/EventViewer/EventView.pro20
-rw-r--r--Swift/QtUI/EventViewer/QtEvent.cpp31
-rw-r--r--Swift/QtUI/EventViewer/QtEvent.h20
-rw-r--r--Swift/QtUI/EventViewer/QtEventWindow.cpp34
-rw-r--r--Swift/QtUI/EventViewer/QtEventWindow.h26
-rw-r--r--Swift/QtUI/EventViewer/QtEventWindowFactory.cpp16
-rw-r--r--Swift/QtUI/EventViewer/QtEventWindowFactory.h16
-rw-r--r--Swift/QtUI/EventViewer/main.cpp20
13 files changed, 276 insertions, 5 deletions
diff --git a/Swift/QtUI/EventViewer/EventDelegate.cpp b/Swift/QtUI/EventViewer/EventDelegate.cpp
index 8b13789..fe8f70c 100644
--- a/Swift/QtUI/EventViewer/EventDelegate.cpp
+++ b/Swift/QtUI/EventViewer/EventDelegate.cpp
@@ -1 +1,10 @@
+#include "EventDelegate.h"
+
+namespace Swift {
+
+EventDelegate::EventDelegate() : QStyledItemDelegate() {
+
+}
+
+}
diff --git a/Swift/QtUI/EventViewer/EventDelegate.h b/Swift/QtUI/EventViewer/EventDelegate.h
index 8b13789..cae49af 100644
--- a/Swift/QtUI/EventViewer/EventDelegate.h
+++ b/Swift/QtUI/EventViewer/EventDelegate.h
@@ -1 +1,12 @@
+#pragma once
+
+#include <QStyledItemDelegate>
+
+namespace Swift {
+ class EventDelegate : public QStyledItemDelegate {
+ Q_OBJECT
+ public:
+ EventDelegate();
+ };
+}
diff --git a/Swift/QtUI/EventViewer/EventModel.cpp b/Swift/QtUI/EventViewer/EventModel.cpp
index a3d5406..ffe2110 100644
--- a/Swift/QtUI/EventViewer/EventModel.cpp
+++ b/Swift/QtUI/EventViewer/EventModel.cpp
@@ -1,20 +1,66 @@
#include "EventModel.h"
+#include <qdebug>
+
namespace Swift {
EventModel::EventModel() {
}
EventModel::~EventModel() {
-
+ foreach (QtEvent* event, activeEvents_) {
+ delete event;
+ }
+ foreach (QtEvent* event, inactiveEvents_) {
+ delete event;
+ }
+}
+
+QVariant EventModel::data(const QModelIndex& index, int role) const {
+ if (!index.isValid()) {
+ return QVariant();
+ }
+ int row = index.row();
+ QtEvent* item = index.row() < activeEvents_.size() ? activeEvents_[row] : inactiveEvents_[row - activeEvents_.size()];
+ QVariant result = item ? item->data(role) : QVariant();
+ qDebug() << "Asked for data of " << index << ", " << role << " returning " << result;
+ return result;
}
-QVariant EventModel::data(const QModelIndex& /*index*/, int /*role*/) const {
- return QVariant();
+int EventModel::rowCount(const QModelIndex& parent) const {
+ /* Invalid parent = root, valid parent = child, and we're a list not a tree.*/
+ int count = parent.isValid() ? 0 : activeEvents_.size() + inactiveEvents_.size();
+ return count;
}
-int EventModel::rowCount(const QModelIndex& /*parent*/) const {
- return 0;
+void EventModel::addEvent(boost::shared_ptr<Event> event, bool active) {
+ qDebug() << " Adding Event";
+ if (active) {
+ activeEvents_.push_front(new QtEvent(event, active));
+ emit dataChanged(createIndex(0, 0), createIndex(1, 0));
+ } else {
+ inactiveEvents_.push_front(new QtEvent(event, active));
+ emit dataChanged(createIndex(activeEvents_.size() -1, 0), createIndex(activeEvents_.size(), 0));
+ }
+ emit layoutChanged();
+}
+
+void EventModel::removeEvent(boost::shared_ptr<Event> event) {
+ for (int i = 0; i < activeEvents_.size(); i++) {
+ if (event == activeEvents_[i]->getEvent()) {
+ activeEvents_.removeAt(i);
+ emit dataChanged(createIndex(i - 1, 0), createIndex(i - 1, 0));
+ 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/EventModel.h b/Swift/QtUI/EventViewer/EventModel.h
index 18195f1..bc54cf4 100644
--- a/Swift/QtUI/EventViewer/EventModel.h
+++ b/Swift/QtUI/EventViewer/EventModel.h
@@ -1,16 +1,27 @@
#pragma once
+#include <boost/shared_ptr.hpp>
+
#include <QAbstractListModel>
#include <QList>
+#include "Swiften/Events/Event.h"
+
+#include "Swift/QtUI/EventViewer/QtEvent.h"
+
namespace Swift {
class EventModel : public QAbstractListModel {
Q_OBJECT
public:
EventModel();
~EventModel();
+ void addEvent(boost::shared_ptr<Event> event, bool active);
+ void removeEvent(boost::shared_ptr<Event> event);
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
int rowCount(const QModelIndex& parent = QModelIndex()) const;
+private:
+ QList<QtEvent*> activeEvents_;
+ QList<QtEvent*> inactiveEvents_;
};
}
diff --git a/Swift/QtUI/EventViewer/EventView.pri b/Swift/QtUI/EventViewer/EventView.pri
new file mode 100644
index 0000000..017f498
--- /dev/null
+++ b/Swift/QtUI/EventViewer/EventView.pri
@@ -0,0 +1,11 @@
+SOURCES += $$PWD/EventDelegate.cpp \
+ $$PWD/EventModel.cpp \
+ $$PWD/EventView.cpp \
+ $$PWD/QtEventWindow.cpp \
+ $$PWD/QtEvent.cpp
+
+HEADERS += $$PWD/EventDelegate.h \
+ $$PWD/EventModel.h \
+ $$PWD/EventView.h \
+ $$PWD/QtEventWindow.h \
+ $$PWD/QtEvent.h
diff --git a/Swift/QtUI/EventViewer/EventView.pro b/Swift/QtUI/EventViewer/EventView.pro
new file mode 100644
index 0000000..942f0ba
--- /dev/null
+++ b/Swift/QtUI/EventViewer/EventView.pro
@@ -0,0 +1,20 @@
+CONFIG -= app_bundle
+
+include(EventView.pri)
+SOURCES += main.cpp
+
+DEPENDPATH += ../. ../../.. ../../../3rdParty/Boost/src
+INCLUDEPATH += ../. ../../.. ../../../3rdParty/Boost/src
+
+DEFINES += BOOST_SIGNALS_NAMESPACE=bsignals BOOST_ALL_NO_LIB
+
+#LIBS += ../../Controllers/Controllers.a
+LIBS += ../../../Swiften/libSwiften.a
+LIBS += ../../../3rdParty/Boost/libBoost.a
+LIBS += ../../../3rdParty/LibIDN/libIDN.a
+
+mac {
+ DEFINES += SWIFT_PLATFORM_MACOSX
+}
+
+RESOURCES += ../Swift.qrc
diff --git a/Swift/QtUI/EventViewer/QtEvent.cpp b/Swift/QtUI/EventViewer/QtEvent.cpp
new file mode 100644
index 0000000..2dc1fb0
--- /dev/null
+++ b/Swift/QtUI/EventViewer/QtEvent.cpp
@@ -0,0 +1,31 @@
+#include "Swift/QtUI/EventViewer/QtEvent.h"
+
+#include "Swiften/Events/MessageEvent.h"
+
+#include "Swift/QtUI/QtSwiftUtil.h"
+
+namespace Swift {
+
+QtEvent::QtEvent(boost::shared_ptr<Event> event, bool active) : event_(event) {
+ active_ = active;
+}
+
+QVariant QtEvent::data(int role) {
+ switch (role) {
+ case Qt::DisplayRole: return QVariant(text());
+ case Qt::TextColorRole: return active_ ? Qt::black : Qt::darkGray;
+ case Qt::BackgroundColorRole: return active_ ? Qt::white : Qt::lightGray;
+ /*case Qt::ToolTipRole: return isContact() ? toolTipString() : QVariant();
+ case StatusTextRole: return statusText_;
+ case AvatarRole: return avatar_;
+ case PresenceIconRole: return getPresenceIcon();*/
+ default: return QVariant();
+ }
+}
+
+QString QtEvent::text() {
+ boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event_);
+ return messageEvent ? P2QSTRING(messageEvent->getStanza()->getBody()) : "Bob: ";
+}
+
+}
diff --git a/Swift/QtUI/EventViewer/QtEvent.h b/Swift/QtUI/EventViewer/QtEvent.h
new file mode 100644
index 0000000..7083c6e
--- /dev/null
+++ b/Swift/QtUI/EventViewer/QtEvent.h
@@ -0,0 +1,20 @@
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <QVariant>
+
+#include "Swiften/Events/Event.h"
+
+namespace Swift {
+ class QtEvent {
+ public:
+ QtEvent(boost::shared_ptr<Event> event, bool active);
+ QVariant data(int role);
+ boost::shared_ptr<Event> getEvent() { return event_; };
+ private:
+ QString text();
+ boost::shared_ptr<Event> event_;
+ bool active_;
+ };
+}
diff --git a/Swift/QtUI/EventViewer/QtEventWindow.cpp b/Swift/QtUI/EventViewer/QtEventWindow.cpp
new file mode 100644
index 0000000..fda957d
--- /dev/null
+++ b/Swift/QtUI/EventViewer/QtEventWindow.cpp
@@ -0,0 +1,34 @@
+#include "Swift/QtUI/EventViewer/QtEventWindow.h"
+
+#include "Swiften/Base/Platform.h"
+
+namespace Swift {
+
+QtEventWindow::QtEventWindow(QWidget* parent) : QTreeView(parent) {
+ model_ = new EventModel();
+ setModel(model_);
+ delegate_ = new EventDelegate();
+ setItemDelegate(delegate_);
+ setHeaderHidden(true);
+#ifdef SWIFT_PLATFORM_MACOSX
+ setAlternatingRowColors(true);
+#endif
+ setAnimated(true);
+ setIndentation(0);
+ setRootIsDecorated(true);
+}
+
+QtEventWindow::~QtEventWindow() {
+ delete model_;
+ delete delegate_;
+}
+
+void QtEventWindow::addEvent(boost::shared_ptr<Event> event, bool active) {
+ model_->addEvent(event, active);
+}
+
+void QtEventWindow::removeEvent(boost::shared_ptr<Event> event) {
+ model_->removeEvent(event);
+}
+
+}
diff --git a/Swift/QtUI/EventViewer/QtEventWindow.h b/Swift/QtUI/EventViewer/QtEventWindow.h
new file mode 100644
index 0000000..cab50ef
--- /dev/null
+++ b/Swift/QtUI/EventViewer/QtEventWindow.h
@@ -0,0 +1,26 @@
+#pragma once
+
+#include "boost/shared_ptr.hpp"
+
+#include <QTreeView>
+
+#include "Swift/Controllers/UIInterfaces/EventWindow.h"
+#include "Swift/QtUI/EventViewer/EventView.h"
+#include "Swift/QtUI/EventViewer/EventModel.h"
+#include "Swift/QtUI/EventViewer/EventDelegate.h"
+
+namespace Swift {
+ class QtEventWindow : public QTreeView, public EventWindow {
+ Q_OBJECT
+ public:
+ QtEventWindow(QWidget* parent = 0);
+ ~QtEventWindow();
+ void addEvent(boost::shared_ptr<Event> event, bool active);
+ void removeEvent(boost::shared_ptr<Event> event);
+ private:
+ EventModel* model_;
+ EventDelegate* delegate_;
+ };
+
+}
+
diff --git a/Swift/QtUI/EventViewer/QtEventWindowFactory.cpp b/Swift/QtUI/EventViewer/QtEventWindowFactory.cpp
new file mode 100644
index 0000000..11c630b
--- /dev/null
+++ b/Swift/QtUI/EventViewer/QtEventWindowFactory.cpp
@@ -0,0 +1,16 @@
+#include "Swift/QtUI/EventViewer/QtEventWindowFactory.h"
+
+#include "Swift/QtUI/QtMainWindowFactory.h"
+#include "Swift/QtUI/QtMainWindow.h"
+
+namespace Swift {
+
+QtEventWindowFactory::QtEventWindowFactory(QtMainWindowFactory* mainWindowFactory) {
+ mainWindowFactory_ = mainWindowFactory;
+}
+
+EventWindow* QtEventWindowFactory::createEventWindow() {
+ return ((QtMainWindow*)mainWindowFactory_->getLastCreatedWindow())->getEventWindow();
+}
+
+}
diff --git a/Swift/QtUI/EventViewer/QtEventWindowFactory.h b/Swift/QtUI/EventViewer/QtEventWindowFactory.h
new file mode 100644
index 0000000..6e41a86
--- /dev/null
+++ b/Swift/QtUI/EventViewer/QtEventWindowFactory.h
@@ -0,0 +1,16 @@
+#pragma once
+
+#include "Swift/Controllers/UIInterfaces/EventWindowFactory.h"
+
+namespace Swift {
+ class QtMainWindowFactory;
+ class QtEventWindowFactory : public EventWindowFactory {
+ public:
+ QtEventWindowFactory(QtMainWindowFactory* mainWindowFactory);
+ virtual EventWindow* createEventWindow();
+ private:
+ QtMainWindowFactory* mainWindowFactory_;
+ };
+}
+
+
diff --git a/Swift/QtUI/EventViewer/main.cpp b/Swift/QtUI/EventViewer/main.cpp
new file mode 100644
index 0000000..647010d
--- /dev/null
+++ b/Swift/QtUI/EventViewer/main.cpp
@@ -0,0 +1,20 @@
+#include <QtGui>
+#include "EventView.h"
+#include "EventModel.h"
+#include "QtEventWindow.h"
+
+#include "Swiften/Events/MessageEvent.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Swift::QtEventWindow* viewer = new Swift::QtEventWindow();
+ viewer->show();
+ boost::shared_ptr<Swift::Message> message1(new Swift::Message());
+ 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);
+ return app.exec();
+}