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
parent5d9a6702c244eb4ab30ce96465d9deceedfe955a (diff)
downloadswift-contrib-580d3d49ea3df7bb1c00cb1052203d17ccaa9a8e.zip
swift-contrib-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')
-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
-rw-r--r--Swift/QtUI/QtMainWindow.cpp8
-rw-r--r--Swift/QtUI/QtMainWindow.h5
-rw-r--r--Swift/QtUI/QtMainWindowFactory.cpp7
-rw-r--r--Swift/QtUI/QtMainWindowFactory.h2
-rw-r--r--Swift/QtUI/QtSwift.cpp5
-rw-r--r--Swift/QtUI/QtSwift.h2
-rw-r--r--Swift/QtUI/SConscript4
20 files changed, 302 insertions, 12 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();
+}
diff --git a/Swift/QtUI/QtMainWindow.cpp b/Swift/QtUI/QtMainWindow.cpp
index 2dad2fd..10dcfa6 100644
--- a/Swift/QtUI/QtMainWindow.cpp
+++ b/Swift/QtUI/QtMainWindow.cpp
@@ -45,9 +45,9 @@ QtMainWindow::QtMainWindow(QtTreeWidgetFactory *treeWidgetFactory) : QWidget() {
tabs_->addTab(contactsTabWidget_, "Contacts");
- eventView_ = new EventView(this);
+ eventWindow_ = new QtEventWindow();
- tabs_->addTab(eventView_, "Events");
+ tabs_->addTab(eventWindow_, "Events");
this->setLayout(mainLayout);
@@ -72,6 +72,10 @@ QtMainWindow::QtMainWindow(QtTreeWidgetFactory *treeWidgetFactory) : QWidget() {
chatMenu->addAction(signOutAction);
}
+QtEventWindow* QtMainWindow::getEventWindow() {
+ return eventWindow_;
+}
+
void QtMainWindow::handleAddActionTriggered(bool checked) {
Q_UNUSED(checked);
QtAddContactDialog* addContact = new QtAddContactDialog(this);
diff --git a/Swift/QtUI/QtMainWindow.h b/Swift/QtUI/QtMainWindow.h
index 9f06dc8..ce3272a 100644
--- a/Swift/QtUI/QtMainWindow.h
+++ b/Swift/QtUI/QtMainWindow.h
@@ -5,7 +5,7 @@
#include <QMenu>
#include "Swift/Controllers/MainWindow.h"
#include "Swift/QtUI/QtRosterHeader.h"
-#include "Swift/QtUI/EventViewer/EventView.h"
+#include "Swift/QtUI/EventViewer/QtEventWindow.h"
#include <vector>
@@ -32,6 +32,7 @@ namespace Swift {
void setMyAvatarPath(const String& path);
void setMyStatusText(const String& status);
void setMyStatusType(const StatusShow::Type type);
+ QtEventWindow* getEventWindow();
private slots:
void handleStatusChanged(StatusShow::Type showType, const QString &statusMessage);
void handleShowOfflineToggled(bool);
@@ -51,7 +52,7 @@ namespace Swift {
QTabWidget* tabs_;
QWidget* contactsTabWidget_;
QWidget* eventsTabWidget_;
- EventView* eventView_;
+ QtEventWindow* eventWindow_;
};
}
diff --git a/Swift/QtUI/QtMainWindowFactory.cpp b/Swift/QtUI/QtMainWindowFactory.cpp
index 9594ade..0794780 100644
--- a/Swift/QtUI/QtMainWindowFactory.cpp
+++ b/Swift/QtUI/QtMainWindowFactory.cpp
@@ -5,12 +5,17 @@
namespace Swift {
QtMainWindowFactory::QtMainWindowFactory(QtTreeWidgetFactory *treeWidgetFactory) : treeWidgetFactory_(treeWidgetFactory) {
-
+ lastWindow_ = NULL;
}
MainWindow* QtMainWindowFactory::createMainWindow() {
QtMainWindow* window = new QtMainWindow(treeWidgetFactory_);
+ lastWindow_ = window;
return window;
}
+MainWindow* QtMainWindowFactory::getLastCreatedWindow() {
+ return lastWindow_;
+}
+
}
diff --git a/Swift/QtUI/QtMainWindowFactory.h b/Swift/QtUI/QtMainWindowFactory.h
index 1e45b23..bd8342c 100644
--- a/Swift/QtUI/QtMainWindowFactory.h
+++ b/Swift/QtUI/QtMainWindowFactory.h
@@ -9,8 +9,10 @@ namespace Swift {
public:
QtMainWindowFactory(QtTreeWidgetFactory *treeWidgetFactory);
MainWindow* createMainWindow();
+ MainWindow* getLastCreatedWindow();
private:
QtTreeWidgetFactory *treeWidgetFactory_;
+ MainWindow* lastWindow_;
};
}
diff --git a/Swift/QtUI/QtSwift.cpp b/Swift/QtUI/QtSwift.cpp
index be2d291..6c9dc11 100644
--- a/Swift/QtUI/QtSwift.cpp
+++ b/Swift/QtUI/QtSwift.cpp
@@ -9,6 +9,7 @@
#include "QtSystemTray.h"
#include "QtSoundPlayer.h"
#include "QtXMLConsoleWidgetFactory.h"
+#include "EventViewer/QtEventWindowFactory.h"
#include <boost/bind.hpp>
#include <QSplitter>
@@ -51,12 +52,13 @@ QtSwift::QtSwift(bool netbookMode) : autoUpdater_(NULL) {
loginWindowFactory_ = new QtLoginWindowFactory(splitter_, systemTray_, settings_);
chatWindowFactory_ = new QtChatWindowFactory(treeWidgetFactory_, splitter_, settings_, tabs_);
rosterWindowFactory_ = new QtMainWindowFactory(treeWidgetFactory_);
+ eventWindowFactory_ = new QtEventWindowFactory(rosterWindowFactory_);
xmlConsoleWidgetFactory_ = new QtXMLConsoleWidgetFactory(tabs_);
soundPlayer_ = new QtSoundPlayer();
if (splitter_) {
splitter_->show();
}
- mainController_ = new MainController(chatWindowFactory_, rosterWindowFactory_, loginWindowFactory_, treeWidgetFactory_, settings_, application_, systemTray_, soundPlayer_, xmlConsoleWidgetFactory_);
+ mainController_ = new MainController(chatWindowFactory_, rosterWindowFactory_, loginWindowFactory_, treeWidgetFactory_, eventWindowFactory_, settings_, application_, systemTray_, soundPlayer_, xmlConsoleWidgetFactory_);
PlatformAutoUpdaterFactory autoUpdaterFactory;
if (autoUpdaterFactory.isSupported()) {
@@ -79,6 +81,7 @@ QtSwift::~QtSwift() {
delete soundPlayer_;
delete tabs_;
delete xmlConsoleWidgetFactory_;
+ delete eventWindowFactory_;
}
}
diff --git a/Swift/QtUI/QtSwift.h b/Swift/QtUI/QtSwift.h
index 0ba9926..5a3f9b3 100644
--- a/Swift/QtUI/QtSwift.h
+++ b/Swift/QtUI/QtSwift.h
@@ -21,6 +21,7 @@ namespace Swift {
class QtXMLConsoleWidgetFactory;
class QtSystemTray;
class QtSoundPlayer;
+ class QtEventWindowFactory;
class QtSwift : public QObject {
Q_OBJECT
@@ -40,6 +41,7 @@ namespace Swift {
QSplitter* splitter_;
QtSoundPlayer* soundPlayer_;
QtChatTabs* tabs_;
+ QtEventWindowFactory* eventWindowFactory_;
Application* application_;
AutoUpdater* autoUpdater_;
};
diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript
index 49c45ea..f1a229a 100644
--- a/Swift/QtUI/SConscript
+++ b/Swift/QtUI/SConscript
@@ -79,9 +79,11 @@ sources = [
"Roster/QtTreeWidget.cpp",
"Roster/QtTreeWidgetItem.cpp",
"Roster/RosterDelegate.cpp",
- "EventViewer/EventView.cpp",
"EventViewer/EventModel.cpp",
"EventViewer/EventDelegate.cpp",
+ "EventViewer/QtEventWindowFactory.cpp",
+ "EventViewer/QtEventWindow.cpp",
+ "EventViewer/QtEvent.cpp",
"QtRosterHeader.cpp",
"qrc_DefaultTheme.cc",
"qrc_Swift.cc",