summaryrefslogtreecommitdiffstats
blob: 91eb2c1c1dc034547aa7e63670e3e8ebcd55341c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#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(UIEventStream* eventStream, QWidget* parent) : QTreeView(parent) {
	eventStream_ = eventStream;
	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);
	connect(this, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleItemActivated(const QModelIndex&)));
}

QtEventWindow::~QtEventWindow() {
	delete model_;
	delete delegate_;
}

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<StanzaEvent> event) {
	model_->removeEvent(event);
}

}