summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-03-21 22:33:09 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-03-22 14:54:54 (GMT)
commitf5c2750f56c78d115bb9e8a7c5d50316da98b6d5 (patch)
tree661c761e7ebb526e1d71848c127046605e036729 /Swift/QtUI
parent37a3ff6afe96c39bbf075d05da72e5f2c684dfa4 (diff)
downloadswift-contrib-f5c2750f56c78d115bb9e8a7c5d50316da98b6d5.zip
swift-contrib-f5c2750f56c78d115bb9e8a7c5d50316da98b6d5.tar.bz2
Lots of plumbing for event view.
This isn't ready yet, but clicking on a message in the event view will now cause the chat to pop up, and the plumbing is there for doing something with subscription requests - I just don't, yet.
Diffstat (limited to 'Swift/QtUI')
-rw-r--r--Swift/QtUI/EventViewer/EventModel.cpp13
-rw-r--r--Swift/QtUI/EventViewer/EventModel.h7
-rw-r--r--Swift/QtUI/EventViewer/QtEvent.cpp18
-rw-r--r--Swift/QtUI/EventViewer/QtEvent.h8
-rw-r--r--Swift/QtUI/EventViewer/QtEventWindow.cpp30
-rw-r--r--Swift/QtUI/EventViewer/QtEventWindow.h10
-rw-r--r--Swift/QtUI/QtMainWindow.cpp5
-rw-r--r--Swift/QtUI/QtMainWindow.h4
-rw-r--r--Swift/QtUI/QtMainWindowFactory.cpp4
-rw-r--r--Swift/QtUI/QtMainWindowFactory.h2
10 files changed, 72 insertions, 29 deletions
diff --git a/Swift/QtUI/EventViewer/EventModel.cpp b/Swift/QtUI/EventViewer/EventModel.cpp
index f75fe74..902004b 100644
--- a/Swift/QtUI/EventViewer/EventModel.cpp
+++ b/Swift/QtUI/EventViewer/EventModel.cpp
@@ -16,14 +16,16 @@ EventModel::~EventModel() {
}
}
+QtEvent* EventModel::getItem(int row) const {
+ return row < activeEvents_.size() ? activeEvents_[row] : inactiveEvents_[row - activeEvents_.size()];
+}
+
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()];
+ QtEvent* item = getItem(index.row());
QVariant result = item ? item->data(role) : QVariant();
- qDebug() << "Asked for data of " << index << ", " << role << " returning " << result;
return result;
}
@@ -33,8 +35,7 @@ int EventModel::rowCount(const QModelIndex& parent) const {
return count;
}
-void EventModel::addEvent(boost::shared_ptr<Event> event, bool active) {
- qDebug() << " Adding Event";
+void EventModel::addEvent(boost::shared_ptr<StanzaEvent> event, bool active) {
if (active) {
activeEvents_.push_front(new QtEvent(event, active));
emit dataChanged(createIndex(0, 0), createIndex(1, 0));
@@ -48,7 +49,7 @@ void EventModel::addEvent(boost::shared_ptr<Event> event, bool active) {
emit layoutChanged();
}
-void EventModel::removeEvent(boost::shared_ptr<Event> event) {
+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);
diff --git a/Swift/QtUI/EventViewer/EventModel.h b/Swift/QtUI/EventViewer/EventModel.h
index bc54cf4..7882c6b 100644
--- a/Swift/QtUI/EventViewer/EventModel.h
+++ b/Swift/QtUI/EventViewer/EventModel.h
@@ -5,7 +5,7 @@
#include <QAbstractListModel>
#include <QList>
-#include "Swiften/Events/Event.h"
+#include "Swiften/Events/StanzaEvent.h"
#include "Swift/QtUI/EventViewer/QtEvent.h"
@@ -15,10 +15,11 @@ Q_OBJECT
public:
EventModel();
~EventModel();
- void addEvent(boost::shared_ptr<Event> event, bool active);
- void removeEvent(boost::shared_ptr<Event> event);
+ 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;
private:
QList<QtEvent*> activeEvents_;
QList<QtEvent*> inactiveEvents_;
diff --git a/Swift/QtUI/EventViewer/QtEvent.cpp b/Swift/QtUI/EventViewer/QtEvent.cpp
index 2dc1fb0..3aae213 100644
--- a/Swift/QtUI/EventViewer/QtEvent.cpp
+++ b/Swift/QtUI/EventViewer/QtEvent.cpp
@@ -1,22 +1,23 @@
#include "Swift/QtUI/EventViewer/QtEvent.h"
#include "Swiften/Events/MessageEvent.h"
+#include "Swiften/Events/SubscriptionRequestEvent.h"
#include "Swift/QtUI/QtSwiftUtil.h"
namespace Swift {
-QtEvent::QtEvent(boost::shared_ptr<Event> event, bool active) : event_(event) {
+QtEvent::QtEvent(boost::shared_ptr<StanzaEvent> event, bool active) : event_(event) {
active_ = active;
}
QVariant QtEvent::data(int role) {
switch (role) {
+ case Qt::ToolTipRole:
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 StatusTextRole: return statusText_;
case AvatarRole: return avatar_;
case PresenceIconRole: return getPresenceIcon();*/
default: return QVariant();
@@ -25,7 +26,16 @@ QVariant QtEvent::data(int role) {
QString QtEvent::text() {
boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event_);
- return messageEvent ? P2QSTRING(messageEvent->getStanza()->getBody()) : "Bob: ";
+ if (messageEvent) {
+ return P2QSTRING(messageEvent->getStanza()->getBody());
+ }
+ boost::shared_ptr<SubscriptionRequestEvent> subscriptionRequestEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(event_);
+ if (subscriptionRequestEvent) {
+ String reason = subscriptionRequestEvent->getReason();
+ String message = subscriptionRequestEvent->getJID().toBare().toString() + " would like to add you to their roster" + (reason.isEmpty() ? "." : ", saying '" + reason + "'.");
+ return P2QSTRING(message);
+ }
+ return "";
}
}
diff --git a/Swift/QtUI/EventViewer/QtEvent.h b/Swift/QtUI/EventViewer/QtEvent.h
index 7083c6e..6dec858 100644
--- a/Swift/QtUI/EventViewer/QtEvent.h
+++ b/Swift/QtUI/EventViewer/QtEvent.h
@@ -4,17 +4,17 @@
#include <QVariant>
-#include "Swiften/Events/Event.h"
+#include "Swiften/Events/StanzaEvent.h"
namespace Swift {
class QtEvent {
public:
- QtEvent(boost::shared_ptr<Event> event, bool active);
+ QtEvent(boost::shared_ptr<StanzaEvent> event, bool active);
QVariant data(int role);
- boost::shared_ptr<Event> getEvent() { return event_; };
+ boost::shared_ptr<StanzaEvent> getEvent() { return event_; };
private:
QString text();
- boost::shared_ptr<Event> event_;
+ boost::shared_ptr<StanzaEvent> event_;
bool active_;
};
}
diff --git a/Swift/QtUI/EventViewer/QtEventWindow.cpp b/Swift/QtUI/EventViewer/QtEventWindow.cpp
index fda957d..91eb2c1 100644
--- a/Swift/QtUI/EventViewer/QtEventWindow.cpp
+++ b/Swift/QtUI/EventViewer/QtEventWindow.cpp
@@ -1,10 +1,17 @@
#include "Swift/QtUI/EventViewer/QtEventWindow.h"
+#include <qdebug>
+
+#include "Swiften/Events/MessageEvent.h"
+#include "Swiften/Events/SubscriptionRequestEvent.h"
+#include "Swift/Controllers/UIEvents/RequestChatUIEvent.h"
+
#include "Swiften/Base/Platform.h"
namespace Swift {
-QtEventWindow::QtEventWindow(QWidget* parent) : QTreeView(parent) {
+QtEventWindow::QtEventWindow(UIEventStream* eventStream, QWidget* parent) : QTreeView(parent) {
+ eventStream_ = eventStream;
model_ = new EventModel();
setModel(model_);
delegate_ = new EventDelegate();
@@ -16,6 +23,7 @@ QtEventWindow::QtEventWindow(QWidget* parent) : QTreeView(parent) {
setAnimated(true);
setIndentation(0);
setRootIsDecorated(true);
+ connect(this, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleItemActivated(const QModelIndex&)));
}
QtEventWindow::~QtEventWindow() {
@@ -23,11 +31,27 @@ QtEventWindow::~QtEventWindow() {
delete delegate_;
}
-void QtEventWindow::addEvent(boost::shared_ptr<Event> event, bool active) {
+void QtEventWindow::handleItemActivated(const QModelIndex& item) {
+ QtEvent* event = model_->getItem(item.row());
+ boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event->getEvent());
+ boost::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(event->getEvent());
+
+ if (messageEvent) {
+ eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(messageEvent->getStanza()->getFrom())));
+ } else if (subscriptionEvent) {
+ printf("Subscription activated\n");
+ //FIXME: do something
+ } else {
+ qWarning() << "Trying to activate an unexpected event";
+ }
+
+}
+
+void QtEventWindow::addEvent(boost::shared_ptr<StanzaEvent> event, bool active) {
model_->addEvent(event, active);
}
-void QtEventWindow::removeEvent(boost::shared_ptr<Event> event) {
+void QtEventWindow::removeEvent(boost::shared_ptr<StanzaEvent> event) {
model_->removeEvent(event);
}
diff --git a/Swift/QtUI/EventViewer/QtEventWindow.h b/Swift/QtUI/EventViewer/QtEventWindow.h
index cab50ef..283ba52 100644
--- a/Swift/QtUI/EventViewer/QtEventWindow.h
+++ b/Swift/QtUI/EventViewer/QtEventWindow.h
@@ -5,6 +5,7 @@
#include <QTreeView>
#include "Swift/Controllers/UIInterfaces/EventWindow.h"
+#include "Swift/Controllers/UIEvents/UIEventStream.h"
#include "Swift/QtUI/EventViewer/EventView.h"
#include "Swift/QtUI/EventViewer/EventModel.h"
#include "Swift/QtUI/EventViewer/EventDelegate.h"
@@ -13,13 +14,16 @@ namespace Swift {
class QtEventWindow : public QTreeView, public EventWindow {
Q_OBJECT
public:
- QtEventWindow(QWidget* parent = 0);
+ QtEventWindow(UIEventStream* eventStream, QWidget* parent = 0);
~QtEventWindow();
- void addEvent(boost::shared_ptr<Event> event, bool active);
- void removeEvent(boost::shared_ptr<Event> event);
+ void addEvent(boost::shared_ptr<StanzaEvent> event, bool active);
+ void removeEvent(boost::shared_ptr<StanzaEvent> event);
+ private slots:
+ void handleItemActivated(const QModelIndex& item);
private:
EventModel* model_;
EventDelegate* delegate_;
+ UIEventStream* eventStream_;
};
}
diff --git a/Swift/QtUI/QtMainWindow.cpp b/Swift/QtUI/QtMainWindow.cpp
index 10dcfa6..ebafaff 100644
--- a/Swift/QtUI/QtMainWindow.cpp
+++ b/Swift/QtUI/QtMainWindow.cpp
@@ -19,7 +19,8 @@
namespace Swift {
-QtMainWindow::QtMainWindow(QtTreeWidgetFactory *treeWidgetFactory) : QWidget() {
+QtMainWindow::QtMainWindow(UIEventStream* uiEventStream, QtTreeWidgetFactory *treeWidgetFactory) : QWidget() {
+ uiEventStream_ = uiEventStream;
setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
QBoxLayout *mainLayout = new QBoxLayout(QBoxLayout::TopToBottom, this);
mainLayout->setContentsMargins(0,0,0,0);
@@ -45,7 +46,7 @@ QtMainWindow::QtMainWindow(QtTreeWidgetFactory *treeWidgetFactory) : QWidget() {
tabs_->addTab(contactsTabWidget_, "Contacts");
- eventWindow_ = new QtEventWindow();
+ eventWindow_ = new QtEventWindow(uiEventStream_);
tabs_->addTab(eventWindow_, "Events");
diff --git a/Swift/QtUI/QtMainWindow.h b/Swift/QtUI/QtMainWindow.h
index ce3272a..1c862e6 100644
--- a/Swift/QtUI/QtMainWindow.h
+++ b/Swift/QtUI/QtMainWindow.h
@@ -21,11 +21,12 @@ namespace Swift {
class QtTreeWidget;
class QtTreeWidgetFactory;
class TreeWidget;
+ class UIEventStream;
class QtMainWindow : public QWidget, public MainWindow {
Q_OBJECT
public:
- QtMainWindow(QtTreeWidgetFactory *treeWidgetFactory);
+ QtMainWindow(UIEventStream* eventStream, QtTreeWidgetFactory *treeWidgetFactory);
TreeWidget* getTreeWidget();
std::vector<QMenu*> getMenus() {return menus_;}
void setMyName(const String& name);
@@ -53,6 +54,7 @@ namespace Swift {
QWidget* contactsTabWidget_;
QWidget* eventsTabWidget_;
QtEventWindow* eventWindow_;
+ UIEventStream* uiEventStream_;
};
}
diff --git a/Swift/QtUI/QtMainWindowFactory.cpp b/Swift/QtUI/QtMainWindowFactory.cpp
index 0794780..dc1949e 100644
--- a/Swift/QtUI/QtMainWindowFactory.cpp
+++ b/Swift/QtUI/QtMainWindowFactory.cpp
@@ -8,8 +8,8 @@ QtMainWindowFactory::QtMainWindowFactory(QtTreeWidgetFactory *treeWidgetFactory)
lastWindow_ = NULL;
}
-MainWindow* QtMainWindowFactory::createMainWindow() {
- QtMainWindow* window = new QtMainWindow(treeWidgetFactory_);
+MainWindow* QtMainWindowFactory::createMainWindow(UIEventStream* eventStream) {
+ QtMainWindow* window = new QtMainWindow(eventStream, treeWidgetFactory_);
lastWindow_ = window;
return window;
}
diff --git a/Swift/QtUI/QtMainWindowFactory.h b/Swift/QtUI/QtMainWindowFactory.h
index bd8342c..8567efd 100644
--- a/Swift/QtUI/QtMainWindowFactory.h
+++ b/Swift/QtUI/QtMainWindowFactory.h
@@ -8,7 +8,7 @@ namespace Swift {
class QtMainWindowFactory : public MainWindowFactory{
public:
QtMainWindowFactory(QtTreeWidgetFactory *treeWidgetFactory);
- MainWindow* createMainWindow();
+ MainWindow* createMainWindow(UIEventStream* eventStream);
MainWindow* getLastCreatedWindow();
private:
QtTreeWidgetFactory *treeWidgetFactory_;